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 Free Software Foundation, Inc.
6 ;; Authors: Reto Zimmermann <reto@gnu.org>
7 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
8 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
9 ;; Keywords: languages vhdl
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
12 (defconst vhdl-version
"3.33.6"
13 "VHDL Mode version number.")
15 (defconst vhdl-time-stamp
"2005-08-30"
16 "VHDL Mode time stamp for last update.")
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 3, or (at your option)
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the
32 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 ;; Boston, MA 02110-1301, USA.
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; This package provides an Emacs major mode for editing VHDL code.
40 ;; It includes the following features:
42 ;; - Syntax highlighting
44 ;; - Template insertion (electrification)
45 ;; - Insertion of file headers
46 ;; - Insertion of user-specified models
47 ;; - Port translation / testbench generation
48 ;; - Structural composition
49 ;; - Configuration generation
50 ;; - Sensitivity list updating
52 ;; - Design hierarchy browser
53 ;; - Source file compilation (syntax analysis)
54 ;; - Makefile generation
56 ;; - Word/keyword completion
58 ;; - Code fixing/alignment/beautification
59 ;; - Postscript printing
60 ;; - VHDL'87/'93 and VHDL-AMS supported
61 ;; - Comprehensive menu
62 ;; - Fully customizable
63 ;; - Works under GNU Emacs (recommended) and XEmacs
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
74 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
81 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
82 ;; or into an arbitrary directory that is added to the load path by the
83 ;; following line in your Emacs start-up file `.emacs':
85 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
87 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
88 ;; directory. Otherwise, byte-compile the source file:
89 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
90 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
92 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
93 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
94 ;; (not required in Emacs 20.X):
96 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
97 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
99 ;; More detailed installation instructions are included in the official
100 ;; VHDL Mode distribution.
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
108 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
109 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
111 ;; Many thanks to all the users who sent me bug reports and enhancement
113 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
114 ;; enhancement suggestions and the fruitful discussions.
115 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
116 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
118 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
119 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
120 ;; giving me the opportunity to develop this code.
121 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
122 ;; of the Swiss Government.
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 ;; Emacs 21+ handling
129 (defconst vhdl-emacs-21
(and (<= 21 emacs-major-version
) (not (featurep 'xemacs
)))
130 "Non-nil if GNU Emacs 21, 22, ... is used.")
131 (defconst vhdl-emacs-22
(and (<= 22 emacs-major-version
) (not (featurep 'xemacs
)))
132 "Non-nil if GNU Emacs 22, ... is used.")
134 (defvar compilation-file-regexp-alist
)
139 (defvar itimer-version
)
140 (defvar lazy-lock-defer-contextually
)
141 (defvar lazy-lock-defer-on-scrolling
)
142 (defvar lazy-lock-defer-on-the-fly
)
143 (defvar speedbar-attached-frame
)
146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;; help function for user options
151 (defun vhdl-custom-set (variable value
&rest functions
)
152 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
153 (if (fboundp 'custom-set-default
)
154 (custom-set-default variable value
)
155 (set-default variable value
))
157 (when (fboundp (car functions
)) (funcall (car functions
)))
158 (setq functions
(cdr functions
))))
160 (defun vhdl-widget-directory-validate (widget)
161 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
163 (let ((val (widget-value widget
)))
164 (unless (string-match "^\\(\\|.*/\\)$" val
)
165 (widget-put widget
:error
"Invalid directory entry: must end with '/'")
168 ;; help string for user options
169 (defconst vhdl-name-doc-string
"
171 FROM REGEXP is a regular expression matching the original name:
172 \".*\" matches the entire string
173 \"\\(...\\)\" matches a substring
174 TO STRING specifies the string to be inserted as new name:
175 \"\\&\" means substitute entire matched text
176 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
178 \".*\" \"\\&\" inserts original string
179 \".*\" \"\\&_i\" attaches \"_i\" to original string
180 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
181 \".*\" \"foo\" inserts constant string \"foo\"
182 \".*\" \"\" inserts empty string")
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 "Customizations for VHDL Mode."
191 ; :version "21.2" ; comment out for XEmacs
194 (defgroup vhdl-mode nil
195 "Customizations for modes."
198 (defcustom vhdl-electric-mode t
199 "*Non-nil enables electrification (automatic template generation).
200 If nil, template generators can still be invoked through key bindings and
201 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
202 toggled by `\\[vhdl-electric-mode]'."
206 (defcustom vhdl-stutter-mode t
207 "*Non-nil enables stuttering.
208 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
209 by `\\[vhdl-stutter-mode]'."
213 (defcustom vhdl-indent-tabs-mode nil
214 "*Non-nil means indentation can insert tabs.
215 Overrides local variable `indent-tabs-mode'."
220 (defgroup vhdl-compile nil
221 "Customizations for compilation."
224 (defcustom vhdl-compiler-alist
226 ;; Cadence Leapfrog: cv -file test.vhd
227 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
228 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
229 nil
"mkdir \\1" "./" "work/" "Makefile" "leapfrog"
230 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
231 ("\\1/entity" "\\2/\\1" "\\1/configuration"
232 "\\1/package" "\\1/body" downcase
))
233 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
234 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
235 ;; (PLL_400X_TOP) is not declared [10.3].
236 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
237 nil
"mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
238 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
239 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
240 "\\1/package/pc.db" "\\1/body/pc.db" downcase
))
241 ;; Ikos Voyager: analyze test.vhd
243 ;; E L4/C5: this library unit is inaccessible
244 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
245 nil
"mkdir \\1" "./" "work/" "Makefile" "ikos"
246 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
247 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
249 ;; ModelSim, Model Technology: vcom test.vhd
250 ;; ERROR: test.vhd(14): Unknown identifier: positiv
251 ;; WARNING[2]: test.vhd(85): Possible infinite loop
252 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
253 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
254 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
255 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
256 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
257 "\\1/_primary.dat" "\\1/body.dat" downcase
))
258 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
259 ;; test.vhd:34: error message
260 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
261 nil
"mkdir \\1" "./" "work/" "Makefile" "provhdl"
262 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
263 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
264 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase
))
265 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
266 ;; ERROR: test.vhd(24): near "dnd": expecting: END
267 ;; WARNING[4]: test.vhd(30): A space is required between ...
268 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
269 nil
"mkdir \\1" "./" "work/" "Makefile" "quickhdl"
270 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
271 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
272 "\\1/_primary.dat" "\\1/body.dat" downcase
))
273 ;; Savant: scram -publish-cc test.vhd
274 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
275 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
276 nil
"mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
277 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
278 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
279 "\\1_config.vhdl" "\\1_package.vhdl"
280 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase
))
281 ;; Simili: vhdlp -work test.vhd
282 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
283 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
284 nil
"mkdir \\1" "./" "work/" "Makefile" "simili"
285 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
286 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
287 "\\1/prim.var" "\\1/_body.var" downcase
))
288 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
289 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
290 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
291 nil
"mkdir \\1" "./" "work/" "Makefile" "speedwave"
292 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
294 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
295 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
296 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
297 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys"
298 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
299 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase
))
300 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
301 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
302 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
303 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
304 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
305 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase
))
307 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
308 ("Synplify" "n/a" "n/a" "make" "-f \\1"
309 nil
"mkdir \\1" "./" "work/" "Makefile" "synplify"
310 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
312 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
313 ;; Compiling "test.vhd" line 1...
314 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
315 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
316 nil
"mkdir \\1" "./" "work/" "Makefile" "vantage"
317 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
318 ("^ *Compiling \"\\(.+\\)\" " 1)
320 ;; VeriBest: vc vhdl test.vhd
321 ;; (no file name printed out!)
322 ;; 32: Z <= A and BitA ;
324 ;; [Error] Name BITA is unknown
325 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
326 nil
"mkdir \\1" "./" "work/" "Makefile" "veribest"
327 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
329 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
330 ;; Compiling "test.vhd" line 1...
331 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
332 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
333 nil
"mkdir \\1" "./" "work/" "Makefile" "viewlogic"
334 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
335 ("^ *Compiling \"\\(.+\\)\" " 1)
338 "*List of available VHDL compilers and their properties.
339 Each list entry specifies the following items for a compiler:
341 Compiler name : name used in option `vhdl-compiler' to choose compiler
342 Compile command : command used for source file compilation
343 Compile options : compile options (\"\\1\" inserts library name)
344 Make command : command used for compilation using a Makefile
345 Make options : make options (\"\\1\" inserts Makefile name)
346 Generate Makefile: use built-in function or command to generate a Makefile
347 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
348 Library command : command to create library directory \(\"\\1\" inserts
349 library directory, \"\\2\" inserts library name)
350 Compile directory: where compilation is run and the Makefile is placed
351 Library directory: directory of default library
352 Makefile name : name of Makefile (default is \"Makefile\")
353 ID string : compiler identification string (see `vhdl-project-alist')
355 Regexp : regular expression to match error messages (*)
356 File subexp index: index of subexpression that matches the file name
357 Line subexp index: index of subexpression that matches the line number
358 Column subexp idx: index of subexpression that matches the column number
360 Regexp : regular expression to match a file name message
361 File subexp index: index of subexpression that matches the file name
362 Unit-to-file name mapping: mapping of library unit names to names of files
363 generated by the compiler (used for Makefile generation)
364 To string : string a name is mapped to (\"\\1\" inserts the unit name,
365 \"\\2\" inserts the entity name for architectures)
366 Case adjustment : adjust case of inserted unit names
368 \(*) The regular expression must match the error message starting from the
369 beginning of the line (but not necessarily to the end of the line).
371 Compile options allows insertion of the library name (see `vhdl-project-alist')
372 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
374 For Makefile generation, the built-in function can be used (requires
375 specification of the unit-to-file name mapping). Alternatively, an
376 external command can be specified. Work directory allows specification of
377 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
378 used for Makefile generation). To use another library name than \"work\",
379 customize `vhdl-project-alist'. The library command is inserted in Makefiles
380 to automatically create the library directory if not existent.
382 Compile options, compile directory, library directory, and Makefile name are
383 overwritten by the project settings if a project is defined (see
384 `vhdl-project-alist'). Directory paths are relative to the source file
387 Some compilers do not include the file name in the error message, but print
388 out a file name message in advance. In this case, set \"File Subexp Index\"
389 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
390 If no file name at all is printed out, set both \"File Message\" entries to 0
391 \(a default file name message will be printed out instead, does not work in
394 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
395 assigning its name to option `vhdl-compiler'.
397 Please send any missing or erroneous compiler properties to the maintainer for
400 NOTE: Activate new error and file message regexps and reflect the new setting
401 in the choice list of option `vhdl-compiler' by restarting Emacs."
403 (list :tag
"Compiler" :indent
2
404 (string :tag
"Compiler name ")
405 (string :tag
"Compile command ")
406 (string :tag
"Compile options " "-work \\1")
407 (string :tag
"Make command " "make")
408 (string :tag
"Make options " "-f \\1")
409 (choice :tag
"Generate Makefile "
410 (const :tag
"Built-in function" nil
)
411 (string :tag
"Command" "vmake \\2 > \\1"))
412 (string :tag
"Library command " "mkdir \\1")
413 (directory :tag
"Compile directory "
414 :validate vhdl-widget-directory-validate
"./")
415 (directory :tag
"Library directory "
416 :validate vhdl-widget-directory-validate
"work/")
417 (file :tag
"Makefile name " "Makefile")
418 (string :tag
"ID string ")
419 (list :tag
"Error message" :indent
4
420 (regexp :tag
"Regexp ")
421 (integer :tag
"File subexp index")
422 (integer :tag
"Line subexp index")
423 (integer :tag
"Column subexp idx"))
424 (list :tag
"File message" :indent
4
425 (regexp :tag
"Regexp ")
426 (integer :tag
"File subexp index"))
427 (choice :tag
"Unit-to-file name mapping"
428 :format
"%t: %[Value Menu%] %v\n"
429 (const :tag
"Not defined" nil
)
430 (list :tag
"To string" :indent
4
431 (string :tag
"Entity " "\\1.vhd")
432 (string :tag
"Architecture " "\\2_\\1.vhd")
433 (string :tag
"Configuration " "\\1.vhd")
434 (string :tag
"Package " "\\1.vhd")
435 (string :tag
"Package Body " "\\1_body.vhd")
436 (choice :tag
"Case adjustment "
437 (const :tag
"None" identity
)
438 (const :tag
"Upcase" upcase
)
439 (const :tag
"Downcase" downcase
))))))
440 :set
(lambda (variable value
)
441 (vhdl-custom-set variable value
'vhdl-update-mode-menu
))
442 :group
'vhdl-compile
)
444 (defcustom vhdl-compiler
"ModelSim"
445 "*Specifies the VHDL compiler to be used for syntax analysis.
446 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
447 :type
(let ((alist vhdl-compiler-alist
) list
)
449 (setq list
(cons (list 'const
(caar alist
)) list
))
450 (setq alist
(cdr alist
)))
451 (append '(choice) (nreverse list
)))
452 :group
'vhdl-compile
)
454 (defcustom vhdl-compile-use-local-error-regexp t
455 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
456 In this case, only error message regexps for VHDL compilers are active if
457 compilation is started from a VHDL buffer. Otherwise, the error message
458 regexps are appended to the predefined global regexps, and all regexps are
459 active all the time. Note that by doing that, the predefined global regexps
460 might result in erroneous parsing of error messages for some VHDL compilers.
462 NOTE: Activate the new setting by restarting Emacs."
464 :group
'vhdl-compile
)
466 (defcustom vhdl-makefile-generation-hook nil
467 "*Functions to run at the end of Makefile generation.
468 Allows to insert user specific parts into a Makefile.
472 \(re-search-backward \"^# Rule for compiling entire design\")
473 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
475 :group
'vhdl-compile
)
477 (defcustom vhdl-default-library
"work"
478 "*Name of default library.
479 Is overwritten by project settings if a project is active."
481 :group
'vhdl-compile
)
484 (defgroup vhdl-project nil
485 "Customizations for projects."
488 (defcustom vhdl-project-alist
489 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
490 "~/example1/" ("src/system/" "src/components/") ""
491 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil
)
492 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" .
"-optimize \\3") (".*_tb\\.vhd" . nil
))))
493 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
494 ("Example 2" "Individual source files, multiple compilers in different directories"
495 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
496 nil
"\\1/" "work" "\\1/work/" "Makefile" "")
497 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
498 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
499 nil
"./" "work" "work-\\1/" "Makefile-\\1" "\
500 -------------------------------------------------------------------------------
501 -- This is a multi-line project description
502 -- that can be used as a project dependent part of the file header.
504 "*List of projects and their properties.
505 Name : name used in option `vhdl-project' to choose project
506 Title : title of project (single-line string)
507 Default directory: default project directory (absolute path)
508 Sources : a) source files : path + \"/\" + file name
509 b) directory : path + \"/\"
510 c) directory tree: \"-r \" + path + \"/\"
511 Exclude regexp : matches file/directory names to be excluded as sources
512 Compile options : project-specific options for each compiler
513 Compiler name : name of compiler for which these options are valid
514 Compile options: project-specific compiler options
515 (\"\\1\" inserts library name, \"\\2\" default options)
516 Make options: project-specific make options
517 (\"\\1\" inserts Makefile name, \"\\2\" default options)
518 Exceptions : file-specific exceptions
519 File name regexp: matches file names for which exceptions are valid
520 - Options : file-specific compiler options string
521 (\"\\1\" inserts library name, \"\\2\" default options,
522 \"\\3\" project-specific options)
523 - Do not compile: do not compile this file (in Makefile)
524 Compile directory: where compilation is run and the Makefile is placed
525 \(\"\\1\" inserts compiler ID string)
526 Library name : name of library (default is \"work\")
527 Library directory: path to library (\"\\1\" inserts compiler ID string)
528 Makefile name : name of Makefile
529 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
530 Description : description of project (multi-line string)
532 Project title and description are used to insert into the file header (see
533 option `vhdl-file-header').
535 The default directory must have an absolute path (use `M-TAB' for completion).
536 All other paths can be absolute or relative to the default directory. All
537 paths must end with '/'.
539 The design units found in the sources (files and directories) are shown in the
540 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
541 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
542 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
543 specified, the default directory is taken as source directory. Otherwise,
544 the default directory is only taken as source directory if there is a sources
545 entry with the empty string or \"./\". Exclude regexp allows to filter out
546 specific file and directory names from the list of sources (e.g. CVS
549 Files are compiled in the compile directory. Makefiles are also placed into
550 the compile directory. Library directory specifies which directory the
551 compiler compiles into (used to generate the Makefile).
553 Since different compile/library directories and Makefiles may exist for
554 different compilers within one project, these paths and names allow the
555 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
556 Compile options, compile directory, library directory, and Makefile name
557 overwrite the settings of the current compiler.
559 File-specific compiler options (highest priority) overwrite project-specific
560 options which overwrite default options (lowest priority). Lower priority
561 options can be inserted in higher priority options. This allows to reuse
562 default options (e.g. \"-file\") in project- or file-specific options (e.g.
565 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
566 by restarting Emacs."
568 (list :tag
"Project" :indent
2
569 (string :tag
"Name ")
570 (string :tag
"Title ")
571 (directory :tag
"Default directory"
572 :validate vhdl-widget-directory-validate
573 ,(abbreviate-file-name default-directory
))
574 (repeat :tag
"Sources " :indent
4
575 (directory :format
" %v" "./"))
576 (regexp :tag
"Exclude regexp ")
578 :tag
"Compile options " :indent
4
579 (list :tag
"Compiler" :indent
6
580 ,(let ((alist vhdl-compiler-alist
) list
)
582 (setq list
(cons (list 'const
(caar alist
)) list
))
583 (setq alist
(cdr alist
)))
584 (append '(choice :tag
"Compiler name")
586 (string :tag
"Compile options" "\\2")
587 (string :tag
"Make options " "\\2")
589 :tag
"Exceptions " :indent
8
591 (regexp :tag
"File name regexp ")
592 (choice :format
"%[Value Menu%] %v"
593 (string :tag
"Options" "\\3")
594 (const :tag
"Do not compile" nil
))))))
595 (directory :tag
"Compile directory"
596 :validate vhdl-widget-directory-validate
"./")
597 (string :tag
"Library name " "work")
598 (directory :tag
"Library directory"
599 :validate vhdl-widget-directory-validate
"work/")
600 (file :tag
"Makefile name " "Makefile")
601 (string :tag
"Description: (type `C-j' for newline)"
602 :format
"%t\n%v\n")))
603 :set
(lambda (variable value
)
604 (vhdl-custom-set variable value
605 'vhdl-update-mode-menu
606 'vhdl-speedbar-refresh
))
607 :group
'vhdl-project
)
609 (defcustom vhdl-project nil
610 "*Specifies the default for the current project.
611 Select a project name from the ones defined in option `vhdl-project-alist'.
612 Is used to determine the project title and description to be inserted in file
613 headers and the source files/directories to be scanned in the hierarchy
614 browser. The current project can also be changed temporarily in the menu."
615 :type
(let ((alist vhdl-project-alist
) list
)
617 (setq list
(cons (list 'const
(caar alist
)) list
))
618 (setq alist
(cdr alist
)))
619 (append '(choice (const :tag
"None" nil
) (const :tag
"--"))
621 :group
'vhdl-project
)
623 (defcustom vhdl-project-file-name
'("\\1.prj")
624 "*List of file names/paths for importing/exporting project setups.
625 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
626 replaced by the user name (allows to have user-specific project setups).
627 The first entry is used as file name to import/export individual project
628 setups. All entries are used to automatically import project setups at
629 startup (see option `vhdl-project-auto-load'). Projects loaded from the
630 first entry are automatically made current. Hint: specify local project
631 setups in first entry, global setups in following entries; loading a local
632 project setup will make it current, while loading the global setups
633 is done without changing the current project.
634 Names can also have an absolute path (i.e. project setups can be stored
635 in global directories)."
636 :type
'(repeat (string :tag
"File name" "\\1.prj"))
637 :group
'vhdl-project
)
639 (defcustom vhdl-project-auto-load
'(startup)
640 "*Automatically load project setups from files.
641 All project setup files that match the file names specified in option
642 `vhdl-project-file-name' are automatically loaded. The project of the
643 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
645 A project setup file can be obtained by exporting a project (see menu).
646 At startup: project setup file is loaded at Emacs startup"
647 :type
'(set (const :tag
"At startup" startup
))
648 :group
'vhdl-project
)
650 (defcustom vhdl-project-sort t
651 "*Non-nil means projects are displayed in alphabetical order."
653 :group
'vhdl-project
)
656 (defgroup vhdl-style nil
657 "Customizations for coding styles."
659 :group
'vhdl-template
661 :group
'vhdl-compose
)
663 (defcustom vhdl-standard
'(87 nil
)
664 "*VHDL standards used.
666 VHDL'87 : IEEE Std 1076-1987
667 VHDL'93 : IEEE Std 1076-1993
668 Additional standards:
669 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
670 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
672 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
673 \"Activate Options\"."
674 :type
'(list (choice :tag
"Basic standard"
675 (const :tag
"VHDL'87" 87)
676 (const :tag
"VHDL'93" 93))
677 (set :tag
"Additional standards" :indent
2
678 (const :tag
"VHDL-AMS" ams
)
679 (const :tag
"Math packages" math
)))
680 :set
(lambda (variable value
)
681 (vhdl-custom-set variable value
682 'vhdl-template-map-init
683 'vhdl-mode-abbrev-table-init
684 'vhdl-template-construct-alist-init
685 'vhdl-template-package-alist-init
686 'vhdl-update-mode-menu
687 'vhdl-words-init
'vhdl-font-lock-init
))
690 (defcustom vhdl-basic-offset
2
691 "*Amount of basic offset used for indentation.
692 This value is used by + and - symbols in `vhdl-offsets-alist'."
696 (defcustom vhdl-upper-case-keywords nil
697 "*Non-nil means convert keywords to upper case.
698 This is done when typed or expanded or by the fix case functions."
700 :set
(lambda (variable value
)
701 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
704 (defcustom vhdl-upper-case-types nil
705 "*Non-nil means convert standardized types to upper case.
706 This is done when expanded or by the fix case functions."
708 :set
(lambda (variable value
)
709 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
712 (defcustom vhdl-upper-case-attributes nil
713 "*Non-nil means convert standardized attributes to upper case.
714 This is done when expanded or by the fix case functions."
716 :set
(lambda (variable value
)
717 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
720 (defcustom vhdl-upper-case-enum-values nil
721 "*Non-nil means convert standardized enumeration values to upper case.
722 This is done when expanded or by the fix case functions."
724 :set
(lambda (variable value
)
725 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
728 (defcustom vhdl-upper-case-constants t
729 "*Non-nil means convert standardized constants to upper case.
730 This is done when expanded."
732 :set
(lambda (variable value
)
733 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
736 (defcustom vhdl-use-direct-instantiation
'standard
737 "*Non-nil means use VHDL'93 direct component instantiation.
739 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
741 :type
'(choice (const :tag
"Never" never
)
742 (const :tag
"Standard" standard
)
743 (const :tag
"Always" always
))
747 (defgroup vhdl-naming nil
748 "Customizations for naming conventions."
751 (defcustom vhdl-entity-file-name
'(".*" .
"\\&")
753 "*Specifies how the entity file name is obtained.
754 The entity file name can be obtained by modifying the entity name (e.g.
755 attaching or stripping off a substring). The file extension is automatically
756 taken from the file name of the current buffer."
757 vhdl-name-doc-string
)
758 :type
'(cons (regexp :tag
"From regexp")
759 (string :tag
"To string "))
761 :group
'vhdl-compose
)
763 (defcustom vhdl-architecture-file-name
'("\\(.*\\) \\(.*\\)" .
"\\1_\\2")
765 "*Specifies how the architecture file name is obtained.
766 The architecture file name can be obtained by modifying the entity
767 and/or architecture name (e.g. attaching or stripping off a substring). The
768 file extension is automatically taken from the file name of the current
769 buffer. The string that is matched against the regexp is the concatenation
770 of the entity and the architecture name separated by a space. This gives
771 access to both names (see default setting as example)."
772 vhdl-name-doc-string
)
773 :type
'(cons (regexp :tag
"From regexp")
774 (string :tag
"To string "))
776 :group
'vhdl-compose
)
778 (defcustom vhdl-configuration-file-name
'(".*" .
"\\&")
780 "*Specifies how the configuration file name is obtained.
781 The configuration file name can be obtained by modifying the configuration
782 name (e.g. attaching or stripping off a substring). The file extension is
783 automatically taken from the file name of the current buffer."
784 vhdl-name-doc-string
)
785 :type
'(cons (regexp :tag
"From regexp")
786 (string :tag
"To string "))
788 :group
'vhdl-compose
)
790 (defcustom vhdl-package-file-name
'(".*" .
"\\&")
792 "*Specifies how the package file name is obtained.
793 The package file name can be obtained by modifying the package name (e.g.
794 attaching or stripping off a substring). The file extension is automatically
795 taken from the file name of the current buffer. Package files can be created
796 in a different directory by prepending a relative or absolute path to the
798 vhdl-name-doc-string
)
799 :type
'(cons (regexp :tag
"From regexp")
800 (string :tag
"To string "))
802 :group
'vhdl-compose
)
804 (defcustom vhdl-file-name-case
'identity
805 "*Specifies how to change case for obtaining file names.
806 When deriving a file name from a VHDL unit name, case can be changed as
808 As Is: case is not changed (taken as is)
809 Lower Case: whole name is changed to lower case
810 Upper Case: whole name is changed to upper case
811 Capitalize: first letter of each word in name is capitalized"
812 :type
'(choice (const :tag
"As Is" identity
)
813 (const :tag
"Lower Case" downcase
)
814 (const :tag
"Upper Case" upcase
)
815 (const :tag
"Capitalize" capitalize
))
817 :group
'vhdl-compose
)
820 (defgroup vhdl-template nil
821 "Customizations for electrification."
824 (defcustom vhdl-electric-keywords
'(vhdl user
)
825 "*Type of keywords for which electrification is enabled.
826 VHDL keywords: invoke built-in templates
827 User keywords: invoke user models (see option `vhdl-model-alist')"
828 :type
'(set (const :tag
"VHDL keywords" vhdl
)
829 (const :tag
"User model keywords" user
))
830 :set
(lambda (variable value
)
831 (vhdl-custom-set variable value
'vhdl-mode-abbrev-table-init
))
832 :group
'vhdl-template
)
834 (defcustom vhdl-optional-labels
'process
835 "*Constructs for which labels are to be queried.
836 Template generators prompt for optional labels for:
838 Processes only: processes only (also procedurals in VHDL-AMS)
839 All constructs: all constructs with optional labels and keyword END"
840 :type
'(choice (const :tag
"None" none
)
841 (const :tag
"Processes only" process
)
842 (const :tag
"All constructs" all
))
843 :group
'vhdl-template
)
845 (defcustom vhdl-insert-empty-lines
'unit
846 "*Specifies whether to insert empty lines in some templates.
847 This improves readability of code. Empty lines are inserted in:
849 Design units only: entities, architectures, configurations, packages only
850 All constructs : also all constructs with BEGIN...END parts
852 Replaces option `vhdl-additional-empty-lines'."
853 :type
'(choice (const :tag
"None" none
)
854 (const :tag
"Design units only" unit
)
855 (const :tag
"All constructs" all
))
856 :group
'vhdl-template
858 :group
'vhdl-compose
)
860 (defcustom vhdl-argument-list-indent nil
861 "*Non-nil means indent argument lists relative to opening parenthesis.
862 That is, argument, association, and port lists start on the same line as the
863 opening parenthesis and subsequent lines are indented accordingly.
864 Otherwise, lists start on a new line and are indented as normal code."
866 :group
'vhdl-template
868 :group
'vhdl-compose
)
870 (defcustom vhdl-association-list-with-formals t
871 "*Non-nil means write association lists with formal parameters.
872 Templates prompt for formal and actual parameters (ports/generics).
873 When pasting component instantiations, formals are included.
874 If nil, only a list of actual parameters is entered."
876 :group
'vhdl-template
878 :group
'vhdl-compose
)
880 (defcustom vhdl-conditions-in-parenthesis nil
881 "*Non-nil means place parenthesis around condition expressions."
883 :group
'vhdl-template
)
885 (defcustom vhdl-zero-string
"'0'"
886 "*String to use for a logic zero."
888 :group
'vhdl-template
)
890 (defcustom vhdl-one-string
"'1'"
891 "*String to use for a logic one."
893 :group
'vhdl-template
)
896 (defgroup vhdl-header nil
897 "Customizations for file header."
898 :group
'vhdl-template
899 :group
'vhdl-compose
)
901 (defcustom vhdl-file-header
"\
902 -------------------------------------------------------------------------------
903 -- Title : <title string>
904 -- Project : <project>
905 -------------------------------------------------------------------------------
908 -- Company : <company>
910 -- Last update: <date>
911 -- Platform : <platform>
912 -- Standard : <standard>
913 <projectdesc>-------------------------------------------------------------------------------
914 -- Description: <cursor>
915 <copyright>-------------------------------------------------------------------------------
917 -- Date Version Author Description
918 -- <date> 1.0 <login>\tCreated
919 -------------------------------------------------------------------------------
922 "*String or file to insert as file header.
923 If the string specifies an existing file name, the contents of the file is
924 inserted, otherwise the string itself is inserted as file header.
925 Type `C-j' for newlines.
926 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
927 if the header needs to be version controlled.
929 The following keywords for template generation are supported:
930 <filename> : replaced by the name of the buffer
931 <author> : replaced by the user name and email address
932 \(`user-full-name',`mail-host-address', `user-mail-address')
933 <login> : replaced by user login name (`user-login-name')
934 <company> : replaced by contents of option `vhdl-company-name'
935 <date> : replaced by the current date
936 <year> : replaced by the current year
937 <project> : replaced by title of current project (`vhdl-project')
938 <projectdesc> : replaced by description of current project (`vhdl-project')
939 <copyright> : replaced by copyright string (`vhdl-copyright-string')
940 <platform> : replaced by contents of option `vhdl-platform-spec'
941 <standard> : replaced by the VHDL language standard(s) used
942 <... string> : replaced by a queried string (\"...\" is the prompt word)
943 <title string>: replaced by file title in automatically generated files
944 <cursor> : final cursor position
946 The (multi-line) project description <projectdesc> can be used as a project
947 dependent part of the file header and can also contain the above keywords."
951 (defcustom vhdl-file-footer
""
952 "*String or file to insert as file footer.
953 If the string specifies an existing file name, the contents of the file is
954 inserted, otherwise the string itself is inserted as file footer (i.e. at
955 the end of the file).
956 Type `C-j' for newlines.
957 The same keywords as in option `vhdl-file-header' can be used."
961 (defcustom vhdl-company-name
""
962 "*Name of company to insert in file header.
963 See option `vhdl-file-header'."
967 (defcustom vhdl-copyright-string
"\
968 -------------------------------------------------------------------------------
969 -- Copyright (c) <year> <company>
971 "*Copyright string to insert in file header.
972 Can be multi-line string (type `C-j' for newline) and contain other file
973 header keywords (see option `vhdl-file-header')."
977 (defcustom vhdl-platform-spec
""
978 "*Specification of VHDL platform to insert in file header.
979 The platform specification should contain names and versions of the
980 simulation and synthesis tools used.
981 See option `vhdl-file-header'."
985 (defcustom vhdl-date-format
"%Y-%m-%d"
986 "*Specifies the date format to use in the header.
987 This string is passed as argument to the command `format-time-string'.
988 For more information on format strings, see the documentation for the
989 `format-time-string' command (C-h f `format-time-string')."
993 (defcustom vhdl-modify-date-prefix-string
"-- Last update: "
994 "*Prefix string of modification date in VHDL file header.
995 If actualization of the modification date is called (menu,
996 `\\[vhdl-template-modify]'), this string is searched and the rest
997 of the line replaced by the current date."
1001 (defcustom vhdl-modify-date-on-saving t
1002 "*Non-nil means update the modification date when the buffer is saved.
1003 Calls function `\\[vhdl-template-modify]').
1005 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1006 \"Activate Options\"."
1008 :group
'vhdl-header
)
1011 (defgroup vhdl-sequential-process nil
1012 "Customizations for sequential processes."
1013 :group
'vhdl-template
)
1015 (defcustom vhdl-reset-kind
'async
1016 "*Specifies which kind of reset to use in sequential processes."
1017 :type
'(choice (const :tag
"None" none
)
1018 (const :tag
"Synchronous" sync
)
1019 (const :tag
"Asynchronous" async
))
1020 :group
'vhdl-sequential-process
)
1022 (defcustom vhdl-reset-active-high nil
1023 "*Non-nil means reset in sequential processes is active high.
1024 Otherwise, reset is active low."
1026 :group
'vhdl-sequential-process
)
1028 (defcustom vhdl-clock-rising-edge t
1029 "*Non-nil means rising edge of clock triggers sequential processes.
1030 Otherwise, falling edge triggers."
1032 :group
'vhdl-sequential-process
)
1034 (defcustom vhdl-clock-edge-condition
'standard
1035 "*Syntax of the clock edge condition.
1036 Standard: \"clk'event and clk = '1'\"
1037 Function: \"rising_edge(clk)\""
1038 :type
'(choice (const :tag
"Standard" standard
)
1039 (const :tag
"Function" function
))
1040 :group
'vhdl-sequential-process
)
1042 (defcustom vhdl-clock-name
""
1043 "*Name of clock signal to use in templates."
1045 :group
'vhdl-sequential-process
)
1047 (defcustom vhdl-reset-name
""
1048 "*Name of reset signal to use in templates."
1050 :group
'vhdl-sequential-process
)
1053 (defgroup vhdl-model nil
1054 "Customizations for user models."
1057 (defcustom vhdl-model-alist
1059 "<label> : process (<clock>, <reset>)
1060 begin -- process <label>
1061 if <reset> = '0' then -- asynchronous reset (active low)
1063 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1064 if <enable> = '1' then -- synchronous load
1068 end process <label>;"
1070 "*List of user models.
1071 VHDL models (templates) can be specified by the user in this list. They can be
1072 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1073 electrification (i.e. overriding existing or creating new keywords, see
1074 option `vhdl-electric-keywords').
1075 Name : name of model (string of words and spaces)
1076 String : string or name of file to be inserted as model (newline: `C-j')
1077 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1078 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1079 Keyword : keyword to invoke model
1081 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1082 A prompt that appears several times is queried once and replaced throughout
1083 the model. Special prompts are:
1084 <clock> : name specified in `vhdl-clock-name' (if not empty)
1085 <reset> : name specified in `vhdl-reset-name' (if not empty)
1086 <cursor>: final cursor position
1087 File header prompts (see variable `vhdl-file-header') are automatically
1088 replaced, so that user models can also be used to insert different types of
1091 If the string specifies an existing file name, the contents of the file is
1092 inserted, otherwise the string itself is inserted.
1093 The code within the models should be correctly indented.
1094 Type `C-j' for newlines.
1096 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1097 \"Activate Options\"."
1098 :type
'(repeat (list :tag
"Model" :indent
2
1099 (string :tag
"Name ")
1100 (string :tag
"String : (type `C-j' for newline)"
1102 (sexp :tag
"Key binding" x
)
1103 (string :tag
"Keyword " :format
"%t: %v\n")))
1104 :set
(lambda (variable value
)
1105 (vhdl-custom-set variable value
1106 'vhdl-model-map-init
1108 'vhdl-mode-abbrev-table-init
1109 'vhdl-update-mode-menu
))
1113 (defgroup vhdl-compose nil
1114 "Customizations for structural composition."
1117 (defcustom vhdl-compose-architecture-name
'(".*" .
"str")
1119 "*Specifies how the component architecture name is obtained.
1120 The component architecture name can be obtained by modifying the entity name
1121 \(e.g. attaching or stripping off a substring).
1122 If TO STRING is empty, the architecture name is queried."
1123 vhdl-name-doc-string
)
1124 :type
'(cons (regexp :tag
"From regexp")
1125 (string :tag
"To string "))
1126 :group
'vhdl-compose
)
1128 (defcustom vhdl-compose-configuration-name
1129 '("\\(.*\\) \\(.*\\)" .
"\\1_\\2_cfg")
1131 "*Specifies how the configuration name is obtained.
1132 The configuration name can be obtained by modifying the entity and/or
1133 architecture name (e.g. attaching or stripping off a substring). The string
1134 that is matched against the regexp is the concatenation of the entity and the
1135 architecture name separated by a space. This gives access to both names (see
1136 default setting as example)."
1137 vhdl-name-doc-string
)
1138 :type
'(cons (regexp :tag
"From regexp")
1139 (string :tag
"To string "))
1140 :group
'vhdl-compose
)
1142 (defcustom vhdl-components-package-name
1143 '((".*" .
"\\&_components") .
"components")
1145 "*Specifies how the name for the components package is obtained.
1146 The components package is a package containing all component declarations for
1147 the current design. Its name can be obtained by modifying the project name
1148 \(e.g. attaching or stripping off a substring). If no project is defined, the
1149 DIRECTORY entry is chosen."
1150 vhdl-name-doc-string
)
1151 :type
'(cons (cons :tag
"Project" :indent
2
1152 (regexp :tag
"From regexp")
1153 (string :tag
"To string "))
1154 (string :tag
"Directory:\n String "))
1155 :group
'vhdl-compose
)
1157 (defcustom vhdl-use-components-package nil
1158 "*Non-nil means use a separate components package for component declarations.
1159 Otherwise, component declarations are inserted and searched for in the
1160 architecture declarative parts."
1162 :group
'vhdl-compose
)
1164 (defcustom vhdl-compose-include-header t
1165 "*Non-nil means include a header in automatically generated files."
1167 :group
'vhdl-compose
)
1169 (defcustom vhdl-compose-create-files
'single
1170 "*Specifies whether new files should be created for the new component.
1171 The component's entity and architecture are inserted:
1172 None : in current buffer
1173 Single file : in new single file
1174 Separate files: in two separate files
1175 The file names are obtained from variables `vhdl-entity-file-name' and
1176 `vhdl-architecture-file-name'."
1177 :type
'(choice (const :tag
"None" none
)
1178 (const :tag
"Single file" single
)
1179 (const :tag
"Separate files" separate
))
1180 :group
'vhdl-compose
)
1182 (defcustom vhdl-compose-configuration-create-file nil
1183 "*Specifies whether a new file should be created for the configuration.
1184 If non-nil, a new file is created for the configuration.
1185 The file name is obtained from variable `vhdl-configuration-file-name'."
1187 :group
'vhdl-compose
)
1189 (defcustom vhdl-compose-configuration-hierarchical t
1190 "*Specifies whether hierarchical configurations should be created.
1191 If non-nil, automatically created configurations are hierarchical and include
1192 the whole hierarchy of subcomponents. Otherwise the configuration only
1193 includes one level of subcomponents."
1195 :group
'vhdl-compose
)
1197 (defcustom vhdl-compose-configuration-use-subconfiguration t
1198 "*Specifies whether subconfigurations should be used inside configurations.
1199 If non-nil, automatically created configurations use configurations in binding
1200 indications for subcomponents, if such configurations exist. Otherwise,
1201 entities are used in binding indications for subcomponents."
1203 :group
'vhdl-compose
)
1206 (defgroup vhdl-port nil
1207 "Customizations for port translation functions."
1209 :group
'vhdl-compose
)
1211 (defcustom vhdl-include-port-comments nil
1212 "*Non-nil means include port comments when a port is pasted."
1216 (defcustom vhdl-include-direction-comments nil
1217 "*Non-nil means include port direction in instantiations as comments."
1221 (defcustom vhdl-include-type-comments nil
1222 "*Non-nil means include generic/port type in instantiations as comments."
1226 (defcustom vhdl-include-group-comments
'never
1227 "*Specifies whether to include group comments and spacings.
1228 The comments and empty lines between groups of ports are pasted:
1230 Declarations: in entity/component/constant/signal declarations only
1231 Always : also in generic/port maps"
1232 :type
'(choice (const :tag
"Never" never
)
1233 (const :tag
"Declarations" decl
)
1234 (const :tag
"Always" always
))
1237 (defcustom vhdl-actual-port-name
'(".*" .
"\\&")
1239 "*Specifies how actual port names are obtained from formal port names.
1240 In a component instantiation, an actual port name can be obtained by
1241 modifying the formal port name (e.g. attaching or stripping off a substring)."
1242 vhdl-name-doc-string
)
1243 :type
'(cons (regexp :tag
"From regexp")
1244 (string :tag
"To string "))
1247 (defcustom vhdl-instance-name
'(".*" .
"\\&_%d")
1249 "*Specifies how an instance name is obtained.
1250 The instance name can be obtained by modifying the name of the component to be
1251 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1252 by a unique number (starting with 1).
1253 If TO STRING is empty, the instance name is queried."
1254 vhdl-name-doc-string
)
1255 :type
'(cons (regexp :tag
"From regexp")
1256 (string :tag
"To string "))
1260 (defgroup vhdl-testbench nil
1261 "Customizations for testbench generation."
1264 (defcustom vhdl-testbench-entity-name
'(".*" .
"\\&_tb")
1266 "*Specifies how the testbench entity name is obtained.
1267 The entity name of a testbench can be obtained by modifying the name of
1268 the component to be tested (e.g. attaching or stripping off a substring)."
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-architecture-name
'(".*" .
"")
1276 "*Specifies how the testbench architecture name is obtained.
1277 The testbench architecture name can be obtained by modifying the name of
1278 the component to be tested (e.g. attaching or stripping off a substring).
1279 If TO STRING is empty, the architecture name is queried."
1280 vhdl-name-doc-string
)
1281 :type
'(cons (regexp :tag
"From regexp")
1282 (string :tag
"To string "))
1283 :group
'vhdl-testbench
)
1285 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1287 "*Specifies how the testbench configuration name is obtained.
1288 The configuration name of a testbench can be obtained by modifying the entity
1289 and/or architecture name (e.g. attaching or stripping off a substring). The
1290 string that is matched against the regexp is the concatenation of the entity
1291 and the architecture name separated by a space. This gives access to both
1292 names (see default setting as example)."
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-dut-name
'(".*" .
"DUT")
1300 "*Specifies how a DUT instance name is obtained.
1301 The design-under-test instance name (i.e. the component instantiated in the
1302 testbench) can be obtained by modifying the component name (e.g. attaching
1303 or stripping off a substring)."
1304 vhdl-name-doc-string
)
1305 :type
'(cons (regexp :tag
"From regexp")
1306 (string :tag
"To string "))
1307 :group
'vhdl-testbench
)
1309 (defcustom vhdl-testbench-include-header t
1310 "*Non-nil means include a header in automatically generated files."
1312 :group
'vhdl-testbench
)
1314 (defcustom vhdl-testbench-declarations
"\
1316 signal Clk : std_logic := '1';
1318 "*String or file to be inserted in the testbench declarative part.
1319 If the string specifies an existing file name, the contents of the file is
1320 inserted, otherwise the string itself is inserted in the testbench
1321 architecture before the BEGIN keyword.
1322 Type `C-j' for newlines."
1324 :group
'vhdl-testbench
)
1326 (defcustom vhdl-testbench-statements
"\
1328 Clk <= not Clk after 10 ns;
1330 -- waveform generation
1331 WaveGen_Proc: process
1333 -- insert signal assignments here
1335 wait until Clk = '1';
1336 end process WaveGen_Proc;
1338 "*String or file to be inserted in the testbench statement part.
1339 If the string specifies an existing file name, the contents of the file is
1340 inserted, otherwise the string itself is inserted in the testbench
1341 architecture before the END keyword.
1342 Type `C-j' for newlines."
1344 :group
'vhdl-testbench
)
1346 (defcustom vhdl-testbench-initialize-signals nil
1347 "*Non-nil means initialize signals with `0' when declared in testbench."
1349 :group
'vhdl-testbench
)
1351 (defcustom vhdl-testbench-include-library t
1352 "*Non-nil means a library/use clause for std_logic_1164 is included."
1354 :group
'vhdl-testbench
)
1356 (defcustom vhdl-testbench-include-configuration t
1357 "*Non-nil means a testbench configuration is attached at the end."
1359 :group
'vhdl-testbench
)
1361 (defcustom vhdl-testbench-create-files
'single
1362 "*Specifies whether new files should be created for the testbench.
1363 testbench entity and architecture are inserted:
1364 None : in current buffer
1365 Single file : in new single file
1366 Separate files: in two separate files
1367 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1368 and `vhdl-testbench-architecture-file-name'."
1369 :type
'(choice (const :tag
"None" none
)
1370 (const :tag
"Single file" single
)
1371 (const :tag
"Separate files" separate
))
1372 :group
'vhdl-testbench
)
1374 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1376 "*Specifies how the testbench entity file name is obtained.
1377 The entity file name can be obtained by modifying the testbench entity name
1378 \(e.g. attaching or stripping off a substring). The file extension is
1379 automatically taken from the file name of the current buffer. Testbench
1380 files can be created in a different directory by prepending a relative or
1381 absolute path to the file name."
1382 vhdl-name-doc-string
)
1383 :type
'(cons (regexp :tag
"From regexp")
1384 (string :tag
"To string "))
1385 :group
'vhdl-testbench
)
1387 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1389 "*Specifies how the testbench architecture file name is obtained.
1390 The architecture file name can be obtained by modifying the testbench entity
1391 and/or architecture name (e.g. attaching or stripping off a substring). The
1392 string that is matched against the regexp is the concatenation of the entity
1393 and the architecture name separated by a space. This gives access to both
1394 names (see default setting as example). Testbench files can be created in
1395 a different directory by prepending a relative or absolute path to the file
1397 vhdl-name-doc-string
)
1398 :type
'(cons (regexp :tag
"From regexp")
1399 (string :tag
"To string "))
1400 :group
'vhdl-testbench
)
1403 (defgroup vhdl-comment nil
1404 "Customizations for comments."
1407 (defcustom vhdl-self-insert-comments t
1408 "*Non-nil means various templates automatically insert help comments."
1410 :group
'vhdl-comment
)
1412 (defcustom vhdl-prompt-for-comments t
1413 "*Non-nil means various templates prompt for user definable comments."
1415 :group
'vhdl-comment
)
1417 (defcustom vhdl-inline-comment-column
40
1418 "*Column to indent and align inline comments to.
1419 Overrides local option `comment-column'.
1421 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1422 \"Activate Options\"."
1424 :group
'vhdl-comment
)
1426 (defcustom vhdl-end-comment-column
79
1427 "*End of comment column.
1428 Comments that exceed this column number are wrapped.
1430 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1431 \"Activate Options\"."
1433 :group
'vhdl-comment
)
1435 (defvar end-comment-column
)
1438 (defgroup vhdl-align nil
1439 "Customizations for alignment."
1442 (defcustom vhdl-auto-align t
1443 "*Non-nil means align some templates automatically after generation."
1447 (defcustom vhdl-align-groups t
1448 "*Non-nil means align groups of code lines separately.
1449 A group of code lines is a region of consecutive lines between two lines that
1450 match the regexp in option `vhdl-align-group-separate'."
1454 (defcustom vhdl-align-group-separate
"^\\s-*$"
1455 "*Regexp for matching a line that separates groups of lines for alignment.
1457 \"^\\s-*$\": matches an empty line
1458 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1462 (defcustom vhdl-align-same-indent t
1463 "*Non-nil means align blocks with same indent separately.
1464 When a region or the entire buffer is aligned, the code is divided into
1465 blocks of same indent which are aligned separately (except for argument/port
1466 lists). This gives nicer alignment in most cases.
1467 Option `vhdl-align-groups' still applies within these blocks."
1472 (defgroup vhdl-highlight nil
1473 "Customizations for highlighting."
1476 (defcustom vhdl-highlight-keywords t
1477 "*Non-nil means highlight VHDL keywords and other standardized words.
1478 The following faces are used:
1479 `font-lock-keyword-face' : keywords
1480 `font-lock-type-face' : standardized types
1481 `vhdl-font-lock-attribute-face': standardized attributes
1482 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1483 `vhdl-font-lock-function-face' : standardized function and package names
1485 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1486 entry \"Fontify Buffer\")."
1488 :set
(lambda (variable value
)
1489 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1490 :group
'vhdl-highlight
)
1492 (defcustom vhdl-highlight-names t
1493 "*Non-nil means highlight declaration names and construct labels.
1494 The following faces are used:
1495 `font-lock-function-name-face' : names in declarations of units,
1496 subprograms, components, as well as labels of VHDL constructs
1497 `font-lock-type-face' : names in type/nature declarations
1498 `vhdl-font-lock-attribute-face': names in attribute declarations
1499 `font-lock-variable-name-face' : names in declarations of signals,
1500 variables, constants, subprogram parameters, generics, and ports
1502 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1503 entry \"Fontify Buffer\")."
1505 :set
(lambda (variable value
)
1506 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1507 :group
'vhdl-highlight
)
1509 (defcustom vhdl-highlight-special-words nil
1510 "*Non-nil means highlight words with special syntax.
1511 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1512 are highlighted accordingly.
1513 Can be used for visual support of naming conventions.
1515 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1516 entry \"Fontify Buffer\")."
1518 :set
(lambda (variable value
)
1519 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1520 :group
'vhdl-highlight
)
1522 (defcustom vhdl-highlight-forbidden-words nil
1523 "*Non-nil means highlight forbidden words.
1524 The reserved words specified in option `vhdl-forbidden-words' or having the
1525 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1526 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1529 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1530 entry \"Fontify Buffer\")."
1532 :set
(lambda (variable value
)
1533 (vhdl-custom-set variable value
1534 'vhdl-words-init
'vhdl-font-lock-init
))
1535 :group
'vhdl-highlight
)
1537 (defcustom vhdl-highlight-verilog-keywords nil
1538 "*Non-nil means highlight Verilog keywords as reserved words.
1539 Verilog keywords are highlighted in a warning color (face
1540 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1542 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1543 entry \"Fontify Buffer\")."
1545 :set
(lambda (variable value
)
1546 (vhdl-custom-set variable value
1547 'vhdl-words-init
'vhdl-font-lock-init
))
1548 :group
'vhdl-highlight
)
1550 (defcustom vhdl-highlight-translate-off nil
1551 "*Non-nil means background-highlight code excluded from translation.
1552 That is, all code between \"-- pragma translate_off\" and
1553 \"-- pragma translate_on\" is highlighted using a different background color
1554 \(face `vhdl-font-lock-translate-off-face').
1555 Note: this might slow down on-the-fly fontification (and thus editing).
1557 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1558 entry \"Fontify Buffer\")."
1560 :set
(lambda (variable value
)
1561 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1562 :group
'vhdl-highlight
)
1564 (defcustom vhdl-highlight-case-sensitive nil
1565 "*Non-nil means consider case for highlighting.
1567 non-nil also upper-case VHDL words are highlighted, but case of words with
1568 special syntax is not considered
1569 nil only lower-case VHDL words are highlighted, but case of words with
1570 special syntax is considered
1571 Overrides local option `font-lock-keywords-case-fold-search'.
1573 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1574 entry \"Fontify Buffer\")."
1576 :group
'vhdl-highlight
)
1578 (defcustom vhdl-special-syntax-alist
1579 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1580 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1581 ("variable" "\\w+_v" "Grey50" "Grey80"))
1582 "*List of special syntax to be highlighted.
1583 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1584 syntax (as regular expression) are highlighted in the corresponding color.
1586 Name : string of words and spaces
1587 Regexp : regular expression describing word syntax
1588 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1589 Color (light): foreground color for light background
1590 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1591 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1592 Color (dark) : foreground color for dark background
1593 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1594 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1596 Can be used for visual support of naming conventions, such as highlighting
1597 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1598 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1599 common substrings or name suffices.
1600 For each entry, a new face is generated with the specified colors and name
1601 \"vhdl-font-lock-\" + name + \"-face\".
1603 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1604 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1605 :type
'(repeat (list :tag
"Face" :indent
2
1606 (string :tag
"Name ")
1607 (regexp :tag
"Regexp " "\\w+_")
1608 (string :tag
"Color (light)")
1609 (string :tag
"Color (dark) ")))
1610 :set
(lambda (variable value
)
1611 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1612 :group
'vhdl-highlight
)
1614 (defcustom vhdl-forbidden-words
'()
1615 "*List of forbidden words to be highlighted.
1616 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1617 words are highlighted in a warning color to indicate not to use them.
1619 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1620 entry \"Fontify Buffer\")."
1621 :type
'(repeat (string :format
"%v"))
1622 :set
(lambda (variable value
)
1623 (vhdl-custom-set variable value
1624 'vhdl-words-init
'vhdl-font-lock-init
))
1625 :group
'vhdl-highlight
)
1627 (defcustom vhdl-forbidden-syntax
""
1628 "*Syntax of forbidden words to be highlighted.
1629 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1630 syntax are highlighted in a warning color to indicate not to use them.
1631 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1632 highlights identifiers with 10 or more characters).
1634 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1635 entry \"Fontify Buffer\")."
1637 :set
(lambda (variable value
)
1638 (vhdl-custom-set variable value
1639 'vhdl-words-init
'vhdl-font-lock-init
))
1640 :group
'vhdl-highlight
)
1642 (defcustom vhdl-directive-keywords
'("pragma" "synopsys")
1643 "*List of compiler directive keywords recognized for highlighting.
1645 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1646 entry \"Fontify Buffer\")."
1647 :type
'(repeat (string :format
"%v"))
1648 :set
(lambda (variable value
)
1649 (vhdl-custom-set variable value
1650 'vhdl-words-init
'vhdl-font-lock-init
))
1651 :group
'vhdl-highlight
)
1654 (defgroup vhdl-speedbar nil
1655 "Customizations for speedbar."
1658 (defcustom vhdl-speedbar-auto-open nil
1659 "*Non-nil means automatically open speedbar at startup.
1660 Alternatively, the speedbar can be opened from the VHDL menu."
1662 :group
'vhdl-speedbar
)
1664 (defcustom vhdl-speedbar-display-mode
'files
1665 "*Specifies the default displaying mode when opening speedbar.
1666 Alternatively, the displaying mode can be selected from the speedbar menu or
1667 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1668 :type
'(choice (const :tag
"Files" files
)
1669 (const :tag
"Directory hierarchy" directory
)
1670 (const :tag
"Project hierarchy" project
))
1671 :group
'vhdl-speedbar
)
1673 (defcustom vhdl-speedbar-scan-limit
'(10000000 (1000000 50))
1674 "*Limits scanning of large files and netlists.
1675 Design units: maximum file size to scan for design units
1676 Hierarchy (instances of subcomponents):
1677 File size: maximum file size to scan for instances (in bytes)
1678 Instances per arch: maximum number of instances to scan per architecture
1680 \"None\" always means that there is no limit.
1681 In case of files not or incompletely scanned, a warning message and the file
1682 names are printed out.
1683 Background: scanning for instances is considerably slower than scanning for
1684 design units, especially when there are many instances. These limits should
1685 prevent the scanning of large netlists."
1686 :type
'(list (choice :tag
"Design units"
1687 :format
"%t : %[Value Menu%] %v"
1688 (const :tag
"None" nil
)
1689 (integer :tag
"File size"))
1690 (list :tag
"Hierarchy" :indent
2
1691 (choice :tag
"File size"
1692 :format
"%t : %[Value Menu%] %v"
1693 (const :tag
"None" nil
)
1694 (integer :tag
"Size "))
1695 (choice :tag
"Instances per arch"
1696 (const :tag
"None" nil
)
1697 (integer :tag
"Number "))))
1698 :group
'vhdl-speedbar
)
1700 (defcustom vhdl-speedbar-jump-to-unit t
1701 "*Non-nil means jump to the design unit code when opened in a buffer.
1702 The buffer cursor position is left unchanged otherwise."
1704 :group
'vhdl-speedbar
)
1706 (defcustom vhdl-speedbar-update-on-saving t
1707 "*Automatically update design hierarchy when buffer is saved."
1709 :group
'vhdl-speedbar
)
1711 (defcustom vhdl-speedbar-save-cache
'(hierarchy display
)
1712 "*Automatically save modified hierarchy caches when exiting Emacs.
1713 Hierarchy: design hierarchy information
1714 Display: displaying information (which design units to expand)"
1715 :type
'(set (const :tag
"Hierarchy" hierarchy
)
1716 (const :tag
"Display" display
))
1717 :group
'vhdl-speedbar
)
1719 (defcustom vhdl-speedbar-cache-file-name
".emacs-vhdl-cache-\\1-\\2"
1720 "*Name of file for saving hierarchy cache.
1721 \"\\1\" is replaced by the project name if a project is specified,
1722 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1723 different users to have cache files in the same directory). Can also have
1724 an absolute path (i.e. all caches can be stored in one global directory)."
1726 :group
'vhdl-speedbar
)
1729 (defgroup vhdl-menu nil
1730 "Customizations for menues."
1733 (defcustom vhdl-index-menu nil
1734 "*Non-nil means add an index menu for a source file when loading.
1735 Alternatively, the speedbar can be used. Note that the index menu scans a file
1736 when it is opened, while speedbar only scans the file upon request."
1740 (defcustom vhdl-source-file-menu nil
1741 "*Non-nil means add a menu of all source files in current directory.
1742 Alternatively, the speedbar can be used."
1746 (defcustom vhdl-hideshow-menu nil
1747 "*Non-nil means add hideshow menu and functionality at startup.
1748 Hideshow can also be enabled from the VHDL Mode menu.
1749 Hideshow allows hiding code of various VHDL constructs.
1751 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1752 \"Activate Options\"."
1756 (defcustom vhdl-hide-all-init nil
1757 "*Non-nil means hide all design units initially after a file is loaded."
1762 (defgroup vhdl-print nil
1763 "Customizations for printing."
1766 (defcustom vhdl-print-two-column t
1767 "*Non-nil means print code in two columns and landscape format.
1768 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1769 prints VHDL files in a nice two-column landscape style.
1771 NOTE: Activate the new setting by restarting Emacs.
1772 Overrides `ps-print' settings locally."
1776 (defcustom vhdl-print-customize-faces t
1777 "*Non-nil means use an optimized set of faces for postscript printing.
1779 NOTE: Activate the new setting by restarting Emacs.
1780 Overrides `ps-print' settings locally."
1785 (defgroup vhdl-misc nil
1786 "Miscellaneous customizations."
1789 (defcustom vhdl-intelligent-tab t
1790 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1791 That is, if preceeding character is part of a word then complete word,
1792 else if not at beginning of line then insert tab,
1793 else if last command was a `TAB' or `RET' then dedent one step,
1794 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1795 If nil, TAB always indents current line (i.e. `TAB' is bound to
1796 `indent-according-to-mode').
1798 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1799 \"Activate Options\"."
1803 (defcustom vhdl-indent-syntax-based t
1804 "*Non-nil means indent lines of code based on their syntactic context.
1805 Otherwise, a line is indented like the previous nonblank line. This can be
1806 useful in large files where syntax-based indentation gets very slow."
1810 (defcustom vhdl-word-completion-case-sensitive nil
1811 "*Non-nil means word completion using `TAB' is case sensitive.
1812 That is, `TAB' completes words that start with the same letters and case.
1813 Otherwise, case is ignored."
1817 (defcustom vhdl-word-completion-in-minibuffer t
1818 "*Non-nil enables word completion in minibuffer (for template prompts).
1820 NOTE: Activate the new setting by restarting Emacs."
1824 (defcustom vhdl-underscore-is-part-of-word nil
1825 "*Non-nil means consider the underscore character `_' as part of word.
1826 An identifier containing underscores is then treated as a single word in
1827 select and move operations. All parts of an identifier separated by underscore
1828 are treated as single words otherwise.
1830 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1831 \"Activate Options\"."
1833 :set
(lambda (variable value
)
1834 (vhdl-custom-set variable value
'vhdl-mode-syntax-table-init
))
1838 (defgroup vhdl-related nil
1839 "Related general customizations."
1842 ;; add related general customizations
1843 (custom-add-to-group 'vhdl-related
'hideshow
'custom-group
)
1844 (if (featurep 'xemacs
)
1845 (custom-add-to-group 'vhdl-related
'paren-mode
'custom-variable
)
1846 (custom-add-to-group 'vhdl-related
'paren-showing
'custom-group
))
1847 (custom-add-to-group 'vhdl-related
'ps-print
'custom-group
)
1848 (custom-add-to-group 'vhdl-related
'speedbar
'custom-group
)
1849 (custom-add-to-group 'vhdl-related
'line-number-mode
'custom-variable
)
1850 (unless (featurep 'xemacs
)
1851 (custom-add-to-group 'vhdl-related
'transient-mark-mode
'custom-variable
))
1852 (custom-add-to-group 'vhdl-related
'user-full-name
'custom-variable
)
1853 (custom-add-to-group 'vhdl-related
'mail-host-address
'custom-variable
)
1854 (custom-add-to-group 'vhdl-related
'user-mail-address
'custom-variable
)
1856 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1857 ;; Internal variables
1859 (defvar vhdl-menu-max-size
20
1860 "*Specifies the maximum size of a menu before splitting it into submenues.")
1862 (defvar vhdl-progress-interval
1
1863 "*Interval used to update progress status during long operations.
1864 If a number, percentage complete gets updated after each interval of
1865 that many seconds. To inhibit all messages, set this option to nil.")
1867 (defvar vhdl-inhibit-startup-warnings-p nil
1868 "*If non-nil, inhibits start up compatibility warnings.")
1870 (defvar vhdl-strict-syntax-p nil
1871 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1872 If the syntactic symbol for a particular line does not match a symbol
1873 in the offsets alist, an error is generated, otherwise no error is
1874 reported and the syntactic symbol is ignored.")
1876 (defvar vhdl-echo-syntactic-information-p nil
1877 "*If non-nil, syntactic info is echoed when the line is indented.")
1879 (defconst vhdl-offsets-alist-default
1885 (statement-cont . vhdl-lineup-statement-cont
)
1886 (statement-block-intro .
+)
1887 (statement-case-intro .
+)
1888 (case-alternative .
+)
1889 (comment . vhdl-lineup-comment
)
1892 (arglist-cont-nonempty . vhdl-lineup-arglist
)
1893 (arglist-close . vhdl-lineup-arglist
)
1900 "Default settings for offsets of syntactic elements.
1901 Do not change this constant! See the variable `vhdl-offsets-alist' for
1904 (defvar vhdl-offsets-alist
(copy-alist vhdl-offsets-alist-default
)
1905 "*Association list of syntactic element symbols and indentation offsets.
1906 As described below, each cons cell in this list has the form:
1908 (SYNTACTIC-SYMBOL . OFFSET)
1910 When a line is indented, `vhdl-mode' first determines the syntactic
1911 context of the line by generating a list of symbols called syntactic
1912 elements. This list can contain more than one syntactic element and
1913 the global variable `vhdl-syntactic-context' contains the context list
1914 for the line being indented. Each element in this list is actually a
1915 cons cell of the syntactic symbol and a buffer position. This buffer
1916 position is call the relative indent point for the line. Some
1917 syntactic symbols may not have a relative indent point associated with
1920 After the syntactic context list for a line is generated, `vhdl-mode'
1921 calculates the absolute indentation for the line by looking at each
1922 syntactic element in the list. First, it compares the syntactic
1923 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1924 finds a match, it adds the OFFSET to the column of the relative indent
1925 point. The sum of this calculation for each element in the syntactic
1926 list is the absolute offset for line being indented.
1928 If the syntactic element does not match any in the `vhdl-offsets-alist',
1929 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1930 the element is ignored.
1932 Actually, OFFSET can be an integer, a function, a variable, or one of
1933 the following symbols: `+', `-', `++', or `--'. These latter
1934 designate positive or negative multiples of `vhdl-basic-offset',
1935 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1936 called with a single argument containing the cons of the syntactic
1937 element symbol and the relative indent point. The function should
1938 return an integer offset.
1940 Here is the current list of valid syntactic element symbols:
1942 string -- inside multi-line string
1943 block-open -- statement block open
1944 block-close -- statement block close
1945 statement -- a VHDL statement
1946 statement-cont -- a continuation of a VHDL statement
1947 statement-block-intro -- the first line in a new statement block
1948 statement-case-intro -- the first line in a case alternative block
1949 case-alternative -- a case statement alternative clause
1950 comment -- a line containing only a comment
1951 arglist-intro -- the first line in an argument list
1952 arglist-cont -- subsequent argument list lines when no
1953 arguments follow on the same line as the
1954 the arglist opening paren
1955 arglist-cont-nonempty -- subsequent argument list lines when at
1956 least one argument follows on the same
1957 line as the arglist opening paren
1958 arglist-close -- the solo close paren of an argument list
1959 entity -- inside an entity declaration
1960 configuration -- inside a configuration declaration
1961 package -- inside a package declaration
1962 architecture -- inside an architecture body
1963 package-body -- inside a package body")
1965 (defvar vhdl-comment-only-line-offset
0
1966 "*Extra offset for line which contains only the start of a comment.
1967 Can contain an integer or a cons cell of the form:
1969 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1971 Where NON-ANCHORED-OFFSET is the amount of offset given to
1972 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1973 the amount of offset to give column-zero anchored comment-only lines.
1974 Just an integer as value is equivalent to (<val> . 0)")
1976 (defvar vhdl-special-indent-hook nil
1977 "*Hook for user defined special indentation adjustments.
1978 This hook gets called after a line is indented by the mode.")
1980 (defvar vhdl-style-alist
1982 (vhdl-basic-offset .
4)
1983 (vhdl-offsets-alist .
())))
1984 "Styles of Indentation.
1985 Elements of this alist are of the form:
1987 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1989 where STYLE-STRING is a short descriptive string used to select a
1990 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1991 value for that variable when using the selected style.
1993 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1994 case, the VALUE is a list containing elements of the form:
1996 (SYNTACTIC-SYMBOL . VALUE)
1998 as described in `vhdl-offsets-alist'. These are passed directly to
1999 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2000 your style, only those that are different from the default.")
2002 ;; dynamically append the default value of most variables
2003 (or (assoc "Default" vhdl-style-alist
)
2004 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2005 vhdl-strict-syntax-p
2006 vhdl-echo-syntactic-information-p
2009 vhdl-comment-only-line-offset
))
2010 (default (cons "Default"
2014 (cons var
(symbol-value var
))))
2016 (setq vhdl-style-alist
(cons default vhdl-style-alist
))))
2018 (defvar vhdl-mode-hook nil
2019 "*Hook called by `vhdl-mode'.")
2022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2023 ;;; Required packages
2024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2028 (require 'compile
) ; XEmacs
2030 (require 'hippie-exp
)
2032 ;; optional (minimize warning messages during compile)
2034 (require 'font-lock
)
2036 (require 'speedbar
))
2039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2044 ;; XEmacs compatibility
2047 (defun vhdl-keep-region-active ()
2048 "Do whatever is necessary to keep the region active in XEmacs.
2049 Ignore byte-compiler warnings you might see."
2050 (and (featurep 'xemacs
)
2051 (setq zmacs-region-stays t
)))
2053 ;; `wildcard-to-regexp' is included only in XEmacs 21
2054 (unless (fboundp 'wildcard-to-regexp
)
2055 (defun wildcard-to-regexp (wildcard)
2056 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2057 (let* ((i (string-match "[*?]" wildcard
))
2058 (result (substring wildcard
0 i
))
2059 (len (length wildcard
)))
2062 (let ((ch (aref wildcard i
)))
2063 (setq result
(concat result
2064 (cond ((eq ch ?
*) "[^\000]*")
2065 ((eq ch ??
) "[^\000]")
2066 (t (char-to-string ch
)))))
2068 (concat "\\`" result
"\\'"))))
2070 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2071 ;; `regexp-opt' accelerates fontification by 10-20%
2072 (unless (fboundp 'regexp-opt
)
2073 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2074 (defun regexp-opt (strings &optional paren
)
2075 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
2076 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
))))
2078 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2079 (unless (fboundp 'match-string-no-properties
)
2080 (defalias 'match-string-no-properties
'match-string
))
2082 ;; `subst-char-in-string' undefined (XEmacs)
2083 (unless (fboundp 'subst-char-in-string
)
2084 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
2085 (let ((i (length string
))
2086 (newstr (if inplace string
(copy-sequence string
))))
2089 (if (eq (aref newstr i
) fromchar
) (aset newstr i tochar
)))
2092 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2093 (when (and (featurep 'xemacs
) (string< itimer-version
"1.09")
2094 (not noninteractive
))
2096 (when (string< itimer-version
"1.09")
2097 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2098 (beep) (sit-for 5)))
2100 ;; `file-expand-wildcards' undefined (XEmacs)
2101 (unless (fboundp 'file-expand-wildcards
)
2102 (defun file-expand-wildcards (pattern &optional full
)
2103 "Taken from Emacs' `files.el'."
2104 (let* ((nondir (file-name-nondirectory pattern
))
2105 (dirpart (file-name-directory pattern
))
2106 (dirs (if (and dirpart
(string-match "[[*?]" dirpart
))
2107 (mapcar 'file-name-as-directory
2108 (file-expand-wildcards (directory-file-name dirpart
)))
2112 (when (or (null (car dirs
)) ; Possible if DIRPART is not wild.
2113 (file-directory-p (directory-file-name (car dirs
))))
2114 (let ((this-dir-contents
2116 (mapcar #'(lambda (name)
2117 (unless (string-match "\\`\\.\\.?\\'"
2118 (file-name-nondirectory name
))
2120 (directory-files (or (car dirs
) ".") full
2121 (wildcard-to-regexp nondir
))))))
2124 (if (and (car dirs
) (not full
))
2125 (mapcar (function (lambda (name) (concat (car dirs
) name
)))
2129 (setq dirs
(cdr dirs
)))
2132 ;; `member-ignore-case' undefined (XEmacs)
2133 (unless (fboundp 'member-ignore-case
)
2134 (defalias 'member-ignore-case
'member
))
2136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2137 ;; Compatibility with older VHDL Mode versions
2139 (defvar vhdl-warnings nil
2140 "Warnings to tell the user during start up.")
2142 (defun vhdl-run-when-idle (secs repeat function
)
2143 "Wait until idle, then run FUNCTION."
2144 (if (fboundp 'start-itimer
)
2145 (start-itimer "vhdl-mode" function secs repeat t
)
2146 ; (run-with-idle-timer secs repeat function)))
2147 ;; explicitely activate timer (necessary when Emacs is already idle)
2148 (aset (run-with-idle-timer secs repeat function
) 0 nil
)))
2150 (defun vhdl-warning-when-idle (&rest args
)
2151 "Wait until idle, then print out warning STRING and beep."
2153 (vhdl-warning (apply 'format args
) t
)
2154 (unless vhdl-warnings
2155 (vhdl-run-when-idle .1 nil
'vhdl-print-warnings
))
2156 (setq vhdl-warnings
(cons (apply 'format args
) vhdl-warnings
))))
2158 (defun vhdl-warning (string &optional nobeep
)
2159 "Print out warning STRING and beep."
2160 (message "WARNING: %s" string
)
2161 (unless (or nobeep noninteractive
) (beep)))
2163 (defun vhdl-print-warnings ()
2164 "Print out messages in variable `vhdl-warnings'."
2165 (let ((no-warnings (length vhdl-warnings
)))
2166 (setq vhdl-warnings
(nreverse vhdl-warnings
))
2167 (while vhdl-warnings
2168 (message "WARNING: %s" (car vhdl-warnings
))
2169 (setq vhdl-warnings
(cdr vhdl-warnings
)))
2171 (when (> no-warnings
1)
2172 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2174 ;; Backward compatibility checks and fixes
2175 ;; option `vhdl-compiler' changed format
2176 (unless (stringp vhdl-compiler
)
2177 (setq vhdl-compiler
"ModelSim")
2178 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2180 ;; option `vhdl-standard' changed format
2181 (unless (listp vhdl-standard
)
2182 (setq vhdl-standard
'(87 nil
))
2183 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2185 ;; option `vhdl-model-alist' changed format
2186 (when (= (length (car vhdl-model-alist
)) 3)
2187 (let ((old-alist vhdl-model-alist
)
2190 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2191 (setq old-alist
(cdr old-alist
)))
2192 (setq vhdl-model-alist
(nreverse new-alist
)))
2193 (customize-save-variable 'vhdl-model-alist vhdl-model-alist
))
2195 ;; option `vhdl-project-alist' changed format
2196 (when (= (length (car vhdl-project-alist
)) 3)
2197 (let ((old-alist vhdl-project-alist
)
2200 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2201 (setq old-alist
(cdr old-alist
)))
2202 (setq vhdl-project-alist
(nreverse new-alist
)))
2203 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2205 ;; option `vhdl-project-alist' changed format (3.31.1)
2206 (when (= (length (car vhdl-project-alist
)) 4)
2207 (let ((old-alist vhdl-project-alist
)
2210 (setq elem
(car old-alist
))
2212 (cons (list (nth 0 elem
) (nth 1 elem
) "" (nth 2 elem
)
2213 nil
"./" "work" "work/" "Makefile" (nth 3 elem
))
2215 (setq old-alist
(cdr old-alist
)))
2216 (setq vhdl-project-alist
(nreverse new-alist
)))
2217 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2219 ;; option `vhdl-project-alist' changed format (3.31.12)
2220 (when (= (length (car vhdl-project-alist
)) 10)
2221 (let ((tmp-alist vhdl-project-alist
))
2223 (setcdr (nthcdr 3 (car tmp-alist
))
2224 (cons "" (nthcdr 4 (car tmp-alist
))))
2225 (setq tmp-alist
(cdr tmp-alist
))))
2226 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2228 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2229 (when (= (length (car vhdl-compiler-alist
)) 7)
2230 (let ((old-alist vhdl-compiler-alist
)
2233 (setq elem
(car old-alist
))
2235 (cons (list (nth 0 elem
) (nth 1 elem
) "" "make -f \\1"
2236 (if (equal (nth 3 elem
) "") nil
(nth 3 elem
))
2237 (nth 4 elem
) "work/" "Makefile" (downcase (nth 0 elem
))
2238 (nth 5 elem
) (nth 6 elem
) nil
)
2240 (setq old-alist
(cdr old-alist
)))
2241 (setq vhdl-compiler-alist
(nreverse new-alist
)))
2242 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2244 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2245 (when (= (length (car vhdl-compiler-alist
)) 12)
2246 (let ((tmp-alist vhdl-compiler-alist
))
2248 (setcdr (nthcdr 4 (car tmp-alist
))
2249 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist
))))
2250 (setq tmp-alist
(cdr tmp-alist
))))
2251 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2253 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2254 (when (= (length (car vhdl-compiler-alist
)) 13)
2255 (let ((tmp-alist vhdl-compiler-alist
))
2257 (setcdr (nthcdr 3 (car tmp-alist
))
2258 (cons "" (nthcdr 4 (car tmp-alist
))))
2259 (setq tmp-alist
(cdr tmp-alist
))))
2260 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2262 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2263 (when (= (length (nth 11 (car vhdl-compiler-alist
))) 3)
2264 (let ((tmp-alist vhdl-compiler-alist
))
2266 (setcdr (nthcdr 2 (nth 11 (car tmp-alist
)))
2268 (setq tmp-alist
(cdr tmp-alist
))))
2269 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2271 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2272 (when (equal vhdl-project
"")
2273 (setq vhdl-project nil
)
2274 (customize-save-variable 'vhdl-project vhdl-project
))
2276 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2277 (when (stringp vhdl-project-file-name
)
2278 (setq vhdl-project-file-name
(list vhdl-project-file-name
))
2279 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name
))
2281 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2282 (if (not (boundp 'speedbar-indentation-width
))
2283 (defvar speedbar-indentation-width
2)
2284 ;; set default to 2 if not already customized
2285 (unless (get 'speedbar-indentation-width
'saved-value
)
2286 (setq speedbar-indentation-width
2)))
2289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2290 ;;; Help functions / inline substitutions / macros
2291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2293 (defun vhdl-standard-p (standard)
2294 "Check if STANDARD is specified as used standard."
2295 (or (eq standard
(car vhdl-standard
))
2296 (memq standard
(cadr vhdl-standard
))))
2298 (defun vhdl-project-p (&optional warning
)
2299 "Return non-nil if a project is displayed, i.e. directories or files are
2301 (if (assoc vhdl-project vhdl-project-alist
)
2303 (when (and vhdl-project warning
)
2304 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project
))
2307 (defun vhdl-resolve-env-variable (string)
2308 "Resolve environment variables in STRING."
2309 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string
)
2310 (setq string
(concat (match-string 1 string
)
2311 (getenv (match-string 2 string
))
2312 (match-string 4 string
))))
2315 (defun vhdl-default-directory ()
2316 "Return the default directory of the current project or the directory of the
2317 current buffer if no project is defined."
2318 (if (vhdl-project-p)
2319 (expand-file-name (vhdl-resolve-env-variable
2320 (nth 1 (aget vhdl-project-alist vhdl-project
))))
2323 (defmacro vhdl-prepare-search-1
(&rest body
)
2324 "Enable case insensitive search and switch to syntax table that includes '_',
2325 then execute BODY, and finally restore the old environment. Used for
2326 consistent searching."
2327 `(let ((case-fold-search t
) ; case insensitive search
2328 (current-syntax-table (syntax-table))
2330 (restore-prog ; program to restore enviroment
2332 ;; restore syntax table
2333 (set-syntax-table current-syntax-table
))))
2334 ;; use extended syntax table
2335 (set-syntax-table vhdl-mode-ext-syntax-table
)
2336 ;; execute BODY safely
2338 (condition-case info
2340 (error (eval restore-prog
) ; restore environment on error
2341 (error (cadr info
))))) ; pass error up
2342 ;; restore environment
2346 (defmacro vhdl-prepare-search-2
(&rest body
)
2347 "Enable case insensitive search, switch to syntax table that includes '_',
2348 and remove `intangible' overlays, then execute BODY, and finally restore the
2349 old environment. Used for consistent searching."
2350 `(let ((case-fold-search t
) ; case insensitive search
2351 (current-syntax-table (syntax-table))
2352 result overlay-all-list overlay-intangible-list overlay
2353 (restore-prog ; program to restore enviroment
2355 ;; restore syntax table
2356 (set-syntax-table current-syntax-table
)
2357 ;; restore `intangible' overlays
2358 (when (fboundp 'overlay-lists
)
2359 (while overlay-intangible-list
2360 (overlay-put (car overlay-intangible-list
) 'intangible t
)
2361 (setq overlay-intangible-list
2362 (cdr overlay-intangible-list
)))))))
2363 ;; use extended syntax table
2364 (set-syntax-table vhdl-mode-ext-syntax-table
)
2365 ;; remove `intangible' overlays
2366 (when (fboundp 'overlay-lists
)
2367 (setq overlay-all-list
(overlay-lists))
2368 (setq overlay-all-list
2369 (append (car overlay-all-list
) (cdr overlay-all-list
)))
2370 (while overlay-all-list
2371 (setq overlay
(car overlay-all-list
))
2372 (when (memq 'intangible
(overlay-properties overlay
))
2373 (setq overlay-intangible-list
2374 (cons overlay overlay-intangible-list
))
2375 (overlay-put overlay
'intangible nil
))
2376 (setq overlay-all-list
(cdr overlay-all-list
))))
2377 ;; execute BODY safely
2379 (condition-case info
2381 (error (eval restore-prog
) ; restore environment on error
2382 (error (cadr info
))))) ; pass error up
2383 ;; restore environment
2387 (defmacro vhdl-visit-file
(file-name issue-error
&rest body
)
2388 "Visit file FILE-NAME and execute BODY."
2389 `(if (null ,file-name
)
2391 (unless (file-directory-p ,file-name
)
2392 (let ((source-buffer (current-buffer))
2393 (visiting-buffer (find-buffer-visiting ,file-name
))
2395 (when (or (and visiting-buffer
(set-buffer visiting-buffer
))
2397 (progn (set-buffer (create-file-buffer ,file-name
))
2398 (setq file-opened t
)
2399 (vhdl-insert-file-contents ,file-name
)
2400 (modify-syntax-entry ?\-
". 12" (syntax-table))
2401 (modify-syntax-entry ?
\n ">" (syntax-table))
2402 (modify-syntax-entry ?\^M
">" (syntax-table))
2403 (modify-syntax-entry ?_
"w" (syntax-table))
2408 (when file-opened
(kill-buffer (current-buffer)))
2409 (set-buffer source-buffer
)
2410 (error "ERROR: File cannot be opened: \"%s\"" ,file-name
))
2411 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name
) t
)
2413 (condition-case info
2418 (when file-opened
(kill-buffer (current-buffer)))
2419 (set-buffer source-buffer
)
2420 (error (cadr info
)))
2421 (vhdl-warning (cadr info
))))))
2422 (when file-opened
(kill-buffer (current-buffer)))
2423 (set-buffer source-buffer
)))))
2425 (defun vhdl-insert-file-contents (filename)
2426 "Nicked from `insert-file-contents-literally', but allow coding system
2428 (let ((format-alist nil
)
2429 (after-insert-file-functions nil
)
2430 (jka-compr-compression-info-list nil
))
2431 (insert-file-contents filename t
)))
2433 (defun vhdl-sort-alist (alist)
2435 (sort alist
(function (lambda (a b
) (string< (car a
) (car b
))))))
2437 (defun vhdl-get-subdirs (directory)
2438 "Recursively get subdirectories of DIRECTORY."
2439 (let ((dir-list (list (file-name-as-directory directory
)))
2441 (setq file-list
(vhdl-directory-files directory t
"\\w.*"))
2443 (when (file-directory-p (car file-list
))
2444 (setq dir-list
(append dir-list
(vhdl-get-subdirs (car file-list
)))))
2445 (setq file-list
(cdr file-list
)))
2448 (defun vhdl-aput (alist-symbol key
&optional value
)
2449 "As `aput', but delete key-value pair if VALUE is nil."
2451 (aput alist-symbol key value
)
2452 (adelete alist-symbol key
)))
2454 (defun vhdl-delete (elt list
)
2455 "Delete by side effect the first occurrence of ELT as a member of LIST."
2456 (setq list
(cons nil list
))
2458 (while (and (cdr list1
) (not (equal elt
(cadr list1
))))
2459 (setq list1
(cdr list1
)))
2461 (setcdr list1
(cddr list1
))))
2464 (defun vhdl-speedbar-refresh (&optional key
)
2465 "Refresh directory or project with name KEY."
2466 (when (and (boundp 'speedbar-frame
)
2467 (frame-live-p speedbar-frame
))
2469 (last-frame (selected-frame)))
2472 (select-frame speedbar-frame
)
2473 (when (save-excursion
2474 (goto-char (point-min))
2475 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key
"$") nil t
))
2476 (goto-char (match-end 1))
2477 (speedbar-do-function-pointer)
2479 (speedbar-do-function-pointer)
2480 (message "Refreshing speedbar...done"))
2481 (select-frame last-frame
)))))
2483 (defun vhdl-show-messages ()
2484 "Get *Messages* buffer to show recent messages."
2486 (display-buffer (if (featurep 'xemacs
) " *Message-Log*" "*Messages*")))
2488 (defun vhdl-use-direct-instantiation ()
2489 "Return whether direct instantiation is used."
2490 (or (eq vhdl-use-direct-instantiation
'always
)
2491 (and (eq vhdl-use-direct-instantiation
'standard
)
2492 (not (vhdl-standard-p '87)))))
2494 (defun vhdl-max-marker (marker1 marker2
)
2495 "Return larger marker."
2496 (if (> marker1 marker2
) marker1 marker2
))
2498 (defun vhdl-goto-marker (marker)
2499 "Goto marker in appropriate buffer."
2500 (when (markerp marker
)
2501 (set-buffer (marker-buffer marker
)))
2504 (defun vhdl-menu-split (list title
)
2505 "Split menu LIST into several submenues, if number of
2506 elements > `vhdl-menu-max-size'."
2507 (if (> (length list
) vhdl-menu-max-size
)
2514 (setq sublist
(cons (car remain
) sublist
))
2515 (setq remain
(cdr remain
))
2517 (if (= i vhdl-menu-max-size
)
2519 (setq result
(cons (cons (format "%s %s" title menuno
)
2520 (nreverse sublist
)) result
))
2522 (setq menuno
(+ menuno
1))
2523 (setq sublist
'()))))
2525 (setq result
(cons (cons (format "%s %s" title menuno
)
2526 (nreverse sublist
)) result
)))
2531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2538 (defvar vhdl-template-map nil
2539 "Keymap for VHDL templates.")
2541 (defun vhdl-template-map-init ()
2542 "Initialize `vhdl-template-map'."
2543 (setq vhdl-template-map
(make-sparse-keymap))
2544 ;; key bindings for VHDL templates
2545 (define-key vhdl-template-map
"al" 'vhdl-template-alias
)
2546 (define-key vhdl-template-map
"ar" 'vhdl-template-architecture
)
2547 (define-key vhdl-template-map
"at" 'vhdl-template-assert
)
2548 (define-key vhdl-template-map
"ad" 'vhdl-template-attribute-decl
)
2549 (define-key vhdl-template-map
"as" 'vhdl-template-attribute-spec
)
2550 (define-key vhdl-template-map
"bl" 'vhdl-template-block
)
2551 (define-key vhdl-template-map
"ca" 'vhdl-template-case-is
)
2552 (define-key vhdl-template-map
"cd" 'vhdl-template-component-decl
)
2553 (define-key vhdl-template-map
"ci" 'vhdl-template-component-inst
)
2554 (define-key vhdl-template-map
"cs" 'vhdl-template-conditional-signal-asst
)
2555 (define-key vhdl-template-map
"Cb" 'vhdl-template-block-configuration
)
2556 (define-key vhdl-template-map
"Cc" 'vhdl-template-component-conf
)
2557 (define-key vhdl-template-map
"Cd" 'vhdl-template-configuration-decl
)
2558 (define-key vhdl-template-map
"Cs" 'vhdl-template-configuration-spec
)
2559 (define-key vhdl-template-map
"co" 'vhdl-template-constant
)
2560 (define-key vhdl-template-map
"di" 'vhdl-template-disconnect
)
2561 (define-key vhdl-template-map
"el" 'vhdl-template-else
)
2562 (define-key vhdl-template-map
"ei" 'vhdl-template-elsif
)
2563 (define-key vhdl-template-map
"en" 'vhdl-template-entity
)
2564 (define-key vhdl-template-map
"ex" 'vhdl-template-exit
)
2565 (define-key vhdl-template-map
"fi" 'vhdl-template-file
)
2566 (define-key vhdl-template-map
"fg" 'vhdl-template-for-generate
)
2567 (define-key vhdl-template-map
"fl" 'vhdl-template-for-loop
)
2568 (define-key vhdl-template-map
"\C-f" 'vhdl-template-footer
)
2569 (define-key vhdl-template-map
"fb" 'vhdl-template-function-body
)
2570 (define-key vhdl-template-map
"fd" 'vhdl-template-function-decl
)
2571 (define-key vhdl-template-map
"ge" 'vhdl-template-generic
)
2572 (define-key vhdl-template-map
"gd" 'vhdl-template-group-decl
)
2573 (define-key vhdl-template-map
"gt" 'vhdl-template-group-template
)
2574 (define-key vhdl-template-map
"\C-h" 'vhdl-template-header
)
2575 (define-key vhdl-template-map
"ig" 'vhdl-template-if-generate
)
2576 (define-key vhdl-template-map
"it" 'vhdl-template-if-then
)
2577 (define-key vhdl-template-map
"li" 'vhdl-template-library
)
2578 (define-key vhdl-template-map
"lo" 'vhdl-template-bare-loop
)
2579 (define-key vhdl-template-map
"\C-m" 'vhdl-template-modify
)
2580 (define-key vhdl-template-map
"\C-t" 'vhdl-template-insert-date
)
2581 (define-key vhdl-template-map
"ma" 'vhdl-template-map
)
2582 (define-key vhdl-template-map
"ne" 'vhdl-template-next
)
2583 (define-key vhdl-template-map
"ot" 'vhdl-template-others
)
2584 (define-key vhdl-template-map
"Pd" 'vhdl-template-package-decl
)
2585 (define-key vhdl-template-map
"Pb" 'vhdl-template-package-body
)
2586 (define-key vhdl-template-map
"(" 'vhdl-template-paired-parens
)
2587 (define-key vhdl-template-map
"po" 'vhdl-template-port
)
2588 (define-key vhdl-template-map
"pb" 'vhdl-template-procedure-body
)
2589 (define-key vhdl-template-map
"pd" 'vhdl-template-procedure-decl
)
2590 (define-key vhdl-template-map
"pc" 'vhdl-template-process-comb
)
2591 (define-key vhdl-template-map
"ps" 'vhdl-template-process-seq
)
2592 (define-key vhdl-template-map
"rp" 'vhdl-template-report
)
2593 (define-key vhdl-template-map
"rt" 'vhdl-template-return
)
2594 (define-key vhdl-template-map
"ss" 'vhdl-template-selected-signal-asst
)
2595 (define-key vhdl-template-map
"si" 'vhdl-template-signal
)
2596 (define-key vhdl-template-map
"su" 'vhdl-template-subtype
)
2597 (define-key vhdl-template-map
"ty" 'vhdl-template-type
)
2598 (define-key vhdl-template-map
"us" 'vhdl-template-use
)
2599 (define-key vhdl-template-map
"va" 'vhdl-template-variable
)
2600 (define-key vhdl-template-map
"wa" 'vhdl-template-wait
)
2601 (define-key vhdl-template-map
"wl" 'vhdl-template-while-loop
)
2602 (define-key vhdl-template-map
"wi" 'vhdl-template-with
)
2603 (define-key vhdl-template-map
"wc" 'vhdl-template-clocked-wait
)
2604 (define-key vhdl-template-map
"\C-pb" 'vhdl-template-package-numeric-bit
)
2605 (define-key vhdl-template-map
"\C-pn" 'vhdl-template-package-numeric-std
)
2606 (define-key vhdl-template-map
"\C-ps" 'vhdl-template-package-std-logic-1164
)
2607 (define-key vhdl-template-map
"\C-pA" 'vhdl-template-package-std-logic-arith
)
2608 (define-key vhdl-template-map
"\C-pM" 'vhdl-template-package-std-logic-misc
)
2609 (define-key vhdl-template-map
"\C-pS" 'vhdl-template-package-std-logic-signed
)
2610 (define-key vhdl-template-map
"\C-pT" 'vhdl-template-package-std-logic-textio
)
2611 (define-key vhdl-template-map
"\C-pU" 'vhdl-template-package-std-logic-unsigned
)
2612 (define-key vhdl-template-map
"\C-pt" 'vhdl-template-package-textio
)
2613 (define-key vhdl-template-map
"\C-dn" 'vhdl-template-directive-translate-on
)
2614 (define-key vhdl-template-map
"\C-df" 'vhdl-template-directive-translate-off
)
2615 (define-key vhdl-template-map
"\C-dN" 'vhdl-template-directive-synthesis-on
)
2616 (define-key vhdl-template-map
"\C-dF" 'vhdl-template-directive-synthesis-off
)
2617 (define-key vhdl-template-map
"\C-q" 'vhdl-template-search-prompt
)
2618 (when (vhdl-standard-p 'ams
)
2619 (define-key vhdl-template-map
"br" 'vhdl-template-break
)
2620 (define-key vhdl-template-map
"cu" 'vhdl-template-case-use
)
2621 (define-key vhdl-template-map
"iu" 'vhdl-template-if-use
)
2622 (define-key vhdl-template-map
"lm" 'vhdl-template-limit
)
2623 (define-key vhdl-template-map
"na" 'vhdl-template-nature
)
2624 (define-key vhdl-template-map
"pa" 'vhdl-template-procedural
)
2625 (define-key vhdl-template-map
"qf" 'vhdl-template-quantity-free
)
2626 (define-key vhdl-template-map
"qb" 'vhdl-template-quantity-branch
)
2627 (define-key vhdl-template-map
"qs" 'vhdl-template-quantity-source
)
2628 (define-key vhdl-template-map
"sn" 'vhdl-template-subnature
)
2629 (define-key vhdl-template-map
"te" 'vhdl-template-terminal
)
2631 (when (vhdl-standard-p 'math
)
2632 (define-key vhdl-template-map
"\C-pc" 'vhdl-template-package-math-complex
)
2633 (define-key vhdl-template-map
"\C-pr" 'vhdl-template-package-math-real
)
2636 ;; initialize template map for VHDL Mode
2637 (vhdl-template-map-init)
2639 (defun vhdl-function-name (prefix string
&optional postfix
)
2640 "Generate a Lisp function name.
2641 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2642 STRING are replaced by `-' and substrings are converted to lower case."
2643 (let ((name prefix
))
2644 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string
)
2646 (concat name
"-" (downcase (substring string
0 (match-end 1)))))
2647 (setq string
(substring string
(match-beginning 2))))
2648 (when postfix
(setq name
(concat name
"-" postfix
)))
2651 (defvar vhdl-model-map nil
2652 "Keymap for VHDL models.")
2654 (defun vhdl-model-map-init ()
2655 "Initialize `vhdl-model-map'."
2656 (setq vhdl-model-map
(make-sparse-keymap))
2657 ;; key bindings for VHDL models
2658 (let ((model-alist vhdl-model-alist
) model
)
2660 (setq model
(car model-alist
))
2661 (define-key vhdl-model-map
(nth 2 model
)
2662 (vhdl-function-name "vhdl-model" (nth 0 model
)))
2663 (setq model-alist
(cdr model-alist
)))))
2665 ;; initialize user model map for VHDL Mode
2666 (vhdl-model-map-init)
2668 (defvar vhdl-mode-map nil
2669 "Keymap for VHDL Mode.")
2671 (defun vhdl-mode-map-init ()
2672 "Initialize `vhdl-mode-map'."
2673 (setq vhdl-mode-map
(make-sparse-keymap))
2674 ;; template key bindings
2675 (define-key vhdl-mode-map
"\C-c\C-t" vhdl-template-map
)
2676 ;; model key bindings
2677 (define-key vhdl-mode-map
"\C-c\C-m" vhdl-model-map
)
2678 ;; standard key bindings
2679 (define-key vhdl-mode-map
"\M-a" 'vhdl-beginning-of-statement
)
2680 (define-key vhdl-mode-map
"\M-e" 'vhdl-end-of-statement
)
2681 (define-key vhdl-mode-map
"\M-\C-f" 'vhdl-forward-sexp
)
2682 (define-key vhdl-mode-map
"\M-\C-b" 'vhdl-backward-sexp
)
2683 (define-key vhdl-mode-map
"\M-\C-u" 'vhdl-backward-up-list
)
2684 (define-key vhdl-mode-map
"\M-\C-a" 'vhdl-backward-same-indent
)
2685 (define-key vhdl-mode-map
"\M-\C-e" 'vhdl-forward-same-indent
)
2686 (unless (featurep 'xemacs
) ; would override `M-backspace' in XEmacs
2687 (define-key vhdl-mode-map
"\M-\C-h" 'vhdl-mark-defun
))
2688 (define-key vhdl-mode-map
"\M-\C-q" 'vhdl-indent-sexp
)
2689 (define-key vhdl-mode-map
"\M-^" 'vhdl-delete-indentation
)
2690 ;; backspace/delete key bindings
2691 (define-key vhdl-mode-map
[backspace] 'backward-delete-char-untabify)
2692 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2693 (define-key vhdl-mode-map [delete] 'delete-char)
2694 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2695 ;; mode specific key bindings
2696 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2698 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2699 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2700 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2701 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2702 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2703 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2704 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2705 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2706 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2707 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2708 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2709 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2710 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2711 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2712 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2713 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2714 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2715 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2716 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2717 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2718 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2719 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2720 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2721 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2722 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2723 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2724 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2725 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2726 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2727 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2728 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2729 (define-key vhdl-mode-map "\C-c\C-c\C-f" 'vhdl-compose-configuration)
2730 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2731 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
2732 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2733 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2734 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2735 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2736 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2737 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2739 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2740 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2741 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2743 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2746 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2747 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2748 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2749 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2750 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2751 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2752 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2753 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2754 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2755 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2756 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2757 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2758 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2759 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2761 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2762 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2763 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2764 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2765 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2766 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2767 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2768 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2769 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2770 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2771 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2772 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2773 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2774 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2775 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2776 ;; insert commands bindings
2777 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2778 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2779 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2780 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2781 ;; electric key bindings
2782 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2783 (when vhdl-intelligent-tab
2784 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2785 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2786 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2787 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2788 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2789 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2790 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2791 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2792 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2793 (when (vhdl-standard-p 'ams)
2794 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2796 ;; initialize mode map for VHDL Mode
2797 (vhdl-mode-map-init)
2799 ;; define special minibuffer keymap for enabling word completion in minibuffer
2800 ;; (useful in template generator prompts)
2801 (defvar vhdl-minibuffer-local-map
2802 (let ((map (make-sparse-keymap)))
2803 (set-keymap-parent map minibuffer-local-map)
2804 (when vhdl-word-completion-in-minibuffer
2805 (define-key map "\t" 'vhdl-minibuffer-tab))
2807 "Keymap for minibuffer used in VHDL Mode.")
2809 ;; set up electric character functions to work with
2810 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2814 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2815 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2816 '(vhdl-electric-space
2818 vhdl-electric-return
2820 vhdl-electric-open-bracket
2821 vhdl-electric-close-bracket
2823 vhdl-electric-semicolon
2825 vhdl-electric-period
2826 vhdl-electric-equal))
2828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2831 (defvar vhdl-mode-syntax-table nil
2832 "Syntax table used in `vhdl-mode' buffers.")
2834 (defvar vhdl-mode-ext-syntax-table nil
2835 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2837 (defun vhdl-mode-syntax-table-init ()
2838 "Initialize `vhdl-mode-syntax-table'."
2839 (setq vhdl-mode-syntax-table (make-syntax-table))
2840 ;; define punctuation
2841 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2842 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2843 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2844 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2845 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2846 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2859 ;; define underscore
2860 (when vhdl-underscore-is-part-of-word
2861 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2862 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2863 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2864 ;; and \n and \^M end a comment
2865 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2866 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2867 ;; define parentheses to match
2868 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2869 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2870 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2871 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2872 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2873 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2874 ;; extended syntax table including '_' (for simpler search regexps)
2875 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2876 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2878 ;; initialize syntax table for VHDL Mode
2879 (vhdl-mode-syntax-table-init)
2881 (defvar vhdl-syntactic-context nil
2882 "Buffer local variable containing syntactic analysis list.")
2883 (make-variable-buffer-local 'vhdl-syntactic-context)
2885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2886 ;; Abbrev ook bindings
2888 (defvar vhdl-mode-abbrev-table nil
2889 "Abbrev table to use in `vhdl-mode' buffers.")
2891 (defun vhdl-mode-abbrev-table-init ()
2892 "Initialize `vhdl-mode-abbrev-table'."
2893 (define-abbrev-table 'vhdl-mode-abbrev-table
2895 (when (memq 'vhdl vhdl-electric-keywords)
2898 ("--" "" vhdl-template-display-comment-hook 0)
2899 ("abs" "" vhdl-template-default-hook 0)
2900 ("access" "" vhdl-template-default-hook 0)
2901 ("after" "" vhdl-template-default-hook 0)
2902 ("alias" "" vhdl-template-alias-hook 0)
2903 ("all" "" vhdl-template-default-hook 0)
2904 ("and" "" vhdl-template-default-hook 0)
2905 ("arch" "" vhdl-template-architecture-hook 0)
2906 ("architecture" "" vhdl-template-architecture-hook 0)
2907 ("array" "" vhdl-template-default-hook 0)
2908 ("assert" "" vhdl-template-assert-hook 0)
2909 ("attr" "" vhdl-template-attribute-hook 0)
2910 ("attribute" "" vhdl-template-attribute-hook 0)
2911 ("begin" "" vhdl-template-default-indent-hook 0)
2912 ("block" "" vhdl-template-block-hook 0)
2913 ("body" "" vhdl-template-default-hook 0)
2914 ("buffer" "" vhdl-template-default-hook 0)
2915 ("bus" "" vhdl-template-default-hook 0)
2916 ("case" "" vhdl-template-case-hook 0)
2917 ("comp" "" vhdl-template-component-hook 0)
2918 ("component" "" vhdl-template-component-hook 0)
2919 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2920 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2921 ("conf" "" vhdl-template-configuration-hook 0)
2922 ("configuration" "" vhdl-template-configuration-hook 0)
2923 ("cons" "" vhdl-template-constant-hook 0)
2924 ("constant" "" vhdl-template-constant-hook 0)
2925 ("disconnect" "" vhdl-template-disconnect-hook 0)
2926 ("downto" "" vhdl-template-default-hook 0)
2927 ("else" "" vhdl-template-else-hook 0)
2928 ("elseif" "" vhdl-template-elsif-hook 0)
2929 ("elsif" "" vhdl-template-elsif-hook 0)
2930 ("end" "" vhdl-template-default-indent-hook 0)
2931 ("entity" "" vhdl-template-entity-hook 0)
2932 ("exit" "" vhdl-template-exit-hook 0)
2933 ("file" "" vhdl-template-file-hook 0)
2934 ("for" "" vhdl-template-for-hook 0)
2935 ("func" "" vhdl-template-function-hook 0)
2936 ("function" "" vhdl-template-function-hook 0)
2937 ("generic" "" vhdl-template-generic-hook 0)
2938 ("group" "" vhdl-template-group-hook 0)
2939 ("guarded" "" vhdl-template-default-hook 0)
2940 ("if" "" vhdl-template-if-hook 0)
2941 ("impure" "" vhdl-template-default-hook 0)
2942 ("in" "" vhdl-template-default-hook 0)
2943 ("inertial" "" vhdl-template-default-hook 0)
2944 ("inout" "" vhdl-template-default-hook 0)
2945 ("inst" "" vhdl-template-instance-hook 0)
2946 ("instance" "" vhdl-template-instance-hook 0)
2947 ("is" "" vhdl-template-default-hook 0)
2948 ("label" "" vhdl-template-default-hook 0)
2949 ("library" "" vhdl-template-library-hook 0)
2950 ("linkage" "" vhdl-template-default-hook 0)
2951 ("literal" "" vhdl-template-default-hook 0)
2952 ("loop" "" vhdl-template-bare-loop-hook 0)
2953 ("map" "" vhdl-template-map-hook 0)
2954 ("mod" "" vhdl-template-default-hook 0)
2955 ("nand" "" vhdl-template-default-hook 0)
2956 ("new" "" vhdl-template-default-hook 0)
2957 ("next" "" vhdl-template-next-hook 0)
2958 ("nor" "" vhdl-template-default-hook 0)
2959 ("not" "" vhdl-template-default-hook 0)
2960 ("null" "" vhdl-template-default-hook 0)
2961 ("of" "" vhdl-template-default-hook 0)
2962 ("on" "" vhdl-template-default-hook 0)
2963 ("open" "" vhdl-template-default-hook 0)
2964 ("or" "" vhdl-template-default-hook 0)
2965 ("others" "" vhdl-template-others-hook 0)
2966 ("out" "" vhdl-template-default-hook 0)
2967 ("pack" "" vhdl-template-package-hook 0)
2968 ("package" "" vhdl-template-package-hook 0)
2969 ("port" "" vhdl-template-port-hook 0)
2970 ("postponed" "" vhdl-template-default-hook 0)
2971 ("procedure" "" vhdl-template-procedure-hook 0)
2972 ("process" "" vhdl-template-process-hook 0)
2973 ("pure" "" vhdl-template-default-hook 0)
2974 ("range" "" vhdl-template-default-hook 0)
2975 ("record" "" vhdl-template-default-hook 0)
2976 ("register" "" vhdl-template-default-hook 0)
2977 ("reject" "" vhdl-template-default-hook 0)
2978 ("rem" "" vhdl-template-default-hook 0)
2979 ("report" "" vhdl-template-report-hook 0)
2980 ("return" "" vhdl-template-return-hook 0)
2981 ("rol" "" vhdl-template-default-hook 0)
2982 ("ror" "" vhdl-template-default-hook 0)
2983 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2984 ("severity" "" vhdl-template-default-hook 0)
2985 ("shared" "" vhdl-template-default-hook 0)
2986 ("sig" "" vhdl-template-signal-hook 0)
2987 ("signal" "" vhdl-template-signal-hook 0)
2988 ("sla" "" vhdl-template-default-hook 0)
2989 ("sll" "" vhdl-template-default-hook 0)
2990 ("sra" "" vhdl-template-default-hook 0)
2991 ("srl" "" vhdl-template-default-hook 0)
2992 ("subtype" "" vhdl-template-subtype-hook 0)
2993 ("then" "" vhdl-template-default-hook 0)
2994 ("to" "" vhdl-template-default-hook 0)
2995 ("transport" "" vhdl-template-default-hook 0)
2996 ("type" "" vhdl-template-type-hook 0)
2997 ("unaffected" "" vhdl-template-default-hook 0)
2998 ("units" "" vhdl-template-default-hook 0)
2999 ("until" "" vhdl-template-default-hook 0)
3000 ("use" "" vhdl-template-use-hook 0)
3001 ("var" "" vhdl-template-variable-hook 0)
3002 ("variable" "" vhdl-template-variable-hook 0)
3003 ("wait" "" vhdl-template-wait-hook 0)
3004 ("when" "" vhdl-template-when-hook 0)
3005 ("while" "" vhdl-template-while-loop-hook 0)
3006 ("with" "" vhdl-template-with-hook 0)
3007 ("xnor" "" vhdl-template-default-hook 0)
3008 ("xor" "" vhdl-template-default-hook 0)
3010 ;; VHDL-AMS keywords
3011 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3013 ("across" "" vhdl-template-default-hook 0)
3014 ("break" "" vhdl-template-break-hook 0)
3015 ("limit" "" vhdl-template-limit-hook 0)
3016 ("nature" "" vhdl-template-nature-hook 0)
3017 ("noise" "" vhdl-template-default-hook 0)
3018 ("procedural" "" vhdl-template-procedural-hook 0)
3019 ("quantity" "" vhdl-template-quantity-hook 0)
3020 ("reference" "" vhdl-template-default-hook 0)
3021 ("spectrum" "" vhdl-template-default-hook 0)
3022 ("subnature" "" vhdl-template-subnature-hook 0)
3023 ("terminal" "" vhdl-template-terminal-hook 0)
3024 ("through" "" vhdl-template-default-hook 0)
3025 ("tolerance" "" vhdl-template-default-hook 0)
3027 ;; user model keywords
3028 (when (memq 'user vhdl-electric-keywords)
3029 (let ((alist vhdl-model-alist)
3030 abbrev-list keyword)
3032 (setq keyword (nth 3 (car alist)))
3033 (unless (equal keyword "")
3035 (cons (list keyword ""
3037 "vhdl-model" (nth 0 (car alist)) "hook") 0)
3039 (setq alist (cdr alist)))
3042 ;; initialize abbrev table for VHDL Mode
3043 (vhdl-mode-abbrev-table-init)
3045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3046 ;; Template completion lists
3048 (defvar vhdl-template-construct-alist nil
3049 "List of built-in construct templates.")
3051 (defun vhdl-template-construct-alist-init ()
3052 "Initialize `vhdl-template-construct-alist'."
3054 vhdl-template-construct-alist
3057 ("alias declaration" vhdl-template-alias)
3058 ("architecture body" vhdl-template-architecture)
3059 ("assertion" vhdl-template-assert)
3060 ("attribute declaration" vhdl-template-attribute-decl)
3061 ("attribute specification" vhdl-template-attribute-spec)
3062 ("block configuration" vhdl-template-block-configuration)
3063 ("block statement" vhdl-template-block)
3064 ("case statement" vhdl-template-case-is)
3065 ("component configuration" vhdl-template-component-conf)
3066 ("component declaration" vhdl-template-component-decl)
3067 ("component instantiation statement" vhdl-template-component-inst)
3068 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3069 ("configuration declaration" vhdl-template-configuration-decl)
3070 ("configuration specification" vhdl-template-configuration-spec)
3071 ("constant declaration" vhdl-template-constant)
3072 ("disconnection specification" vhdl-template-disconnect)
3073 ("entity declaration" vhdl-template-entity)
3074 ("exit statement" vhdl-template-exit)
3075 ("file declaration" vhdl-template-file)
3076 ("generate statement" vhdl-template-generate)
3077 ("generic clause" vhdl-template-generic)
3078 ("group declaration" vhdl-template-group-decl)
3079 ("group template declaration" vhdl-template-group-template)
3080 ("if statement" vhdl-template-if-then)
3081 ("library clause" vhdl-template-library)
3082 ("loop statement" vhdl-template-loop)
3083 ("next statement" vhdl-template-next)
3084 ("package declaration" vhdl-template-package-decl)
3085 ("package body" vhdl-template-package-body)
3086 ("port clause" vhdl-template-port)
3087 ("process statement" vhdl-template-process)
3088 ("report statement" vhdl-template-report)
3089 ("return statement" vhdl-template-return)
3090 ("selected signal assignment" vhdl-template-selected-signal-asst)
3091 ("signal declaration" vhdl-template-signal)
3092 ("subprogram declaration" vhdl-template-subprogram-decl)
3093 ("subprogram body" vhdl-template-subprogram-body)
3094 ("subtype declaration" vhdl-template-subtype)
3095 ("type declaration" vhdl-template-type)
3096 ("use clause" vhdl-template-use)
3097 ("variable declaration" vhdl-template-variable)
3098 ("wait statement" vhdl-template-wait)
3100 (when (vhdl-standard-p 'ams)
3102 ("break statement" vhdl-template-break)
3103 ("nature declaration" vhdl-template-nature)
3104 ("quantity declaration" vhdl-template-quantity)
3105 ("simultaneous case statement" vhdl-template-case-use)
3106 ("simultaneous if statement" vhdl-template-if-use)
3107 ("simultaneous procedural statement" vhdl-template-procedural)
3108 ("step limit specification" vhdl-template-limit)
3109 ("subnature declaration" vhdl-template-subnature)
3110 ("terminal declaration" vhdl-template-terminal)
3113 ;; initialize for VHDL Mode
3114 (vhdl-template-construct-alist-init)
3116 (defvar vhdl-template-package-alist nil
3117 "List of built-in package templates.")
3119 (defun vhdl-template-package-alist-init ()
3120 "Initialize `vhdl-template-package-alist'."
3122 vhdl-template-package-alist
3125 ("numeric_bit" vhdl-template-package-numeric-bit)
3126 ("numeric_std" vhdl-template-package-numeric-std)
3127 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3128 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3129 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3130 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3131 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3132 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3133 ("textio" vhdl-template-package-textio)
3135 (when (vhdl-standard-p 'math)
3137 ("math_complex" vhdl-template-package-math-complex)
3138 ("math_real" vhdl-template-package-math-real)
3141 ;; initialize for VHDL Mode
3142 (vhdl-template-package-alist-init)
3144 (defvar vhdl-template-directive-alist
3146 ("translate_on" vhdl-template-directive-translate-on)
3147 ("translate_off" vhdl-template-directive-translate-off)
3148 ("synthesis_on" vhdl-template-directive-synthesis-on)
3149 ("synthesis_off" vhdl-template-directive-synthesis-off)
3151 "List of built-in directive templates.")
3154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3159 ;; VHDL menu (using `easy-menu.el')
3161 (defun vhdl-customize ()
3162 "Call the customize function with `vhdl' as argument."
3164 (customize-browse 'vhdl))
3166 (defun vhdl-create-mode-menu ()
3167 "Create VHDL Mode menu."
3171 ["None" (vhdl-set-project "")
3172 :style radio :selected (null vhdl-project)]
3174 ;; add menu entries for defined projects
3175 (let ((project-alist vhdl-project-alist) menu-list name)
3176 (while project-alist
3177 (setq name (caar project-alist))
3179 (cons `[,name (vhdl-set-project ,name)
3180 :style radio :selected (equal ,name vhdl-project)]
3182 (setq project-alist (cdr project-alist)))
3184 (if vhdl-project-sort
3186 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3187 (nreverse menu-list)))
3188 (vhdl-menu-split menu-list "Project"))
3190 ["Select Project..." vhdl-set-project t]
3191 ["Set As Default Project" vhdl-set-default-project t]
3193 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3194 ["Import Project..." vhdl-import-project
3195 :keys "C-c C-p C-m" :active t]
3196 ["Export Project" vhdl-export-project vhdl-project]
3198 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3201 ["Compile Buffer" vhdl-compile t]
3202 ["Stop Compilation" kill-compilation t]
3204 ["Make" vhdl-make t]
3205 ["Generate Makefile" vhdl-generate-makefile t]
3207 ["Next Error" next-error t]
3208 ["Previous Error" previous-error t]
3209 ["First Error" first-error t]
3213 ;; add menu entries for defined compilers
3214 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3216 (setq name (caar comp-alist))
3218 (cons `[,name (setq vhdl-compiler ,name)
3219 :style radio :selected (equal ,name vhdl-compiler)]
3221 (setq comp-alist (cdr comp-alist)))
3222 (setq menu-list (nreverse menu-list))
3223 (vhdl-menu-split menu-list "Compiler"))
3225 ["Select Compiler..." vhdl-set-compiler t]
3227 ["Customize Compiler..."
3228 (customize-option 'vhdl-compiler-alist) t])))
3233 ["Alias" vhdl-template-alias t]
3234 ["Architecture" vhdl-template-architecture t]
3235 ["Assert" vhdl-template-assert t]
3236 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3237 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3238 ["Block" vhdl-template-block t]
3239 ["Case" vhdl-template-case-is t]
3240 ["Component (Decl)" vhdl-template-component-decl t]
3241 ["(Component) Instance" vhdl-template-component-inst t]
3242 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3243 ["Configuration (Block)" vhdl-template-block-configuration t]
3244 ["Configuration (Comp)" vhdl-template-component-conf t]
3245 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3246 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3247 ["Constant" vhdl-template-constant t]
3248 ["Disconnect" vhdl-template-disconnect t]
3249 ["Else" vhdl-template-else t]
3250 ["Elsif" vhdl-template-elsif t]
3251 ["Entity" vhdl-template-entity t]
3252 ["Exit" vhdl-template-exit t]
3253 ["File" vhdl-template-file t]
3254 ["For (Generate)" vhdl-template-for-generate t]
3255 ["For (Loop)" vhdl-template-for-loop t]
3256 ["Function (Body)" vhdl-template-function-body t]
3257 ["Function (Decl)" vhdl-template-function-decl t]
3258 ["Generic" vhdl-template-generic t]
3259 ["Group (Decl)" vhdl-template-group-decl t]
3260 ["Group (Template)" vhdl-template-group-template t])
3262 ["If (Generate)" vhdl-template-if-generate t]
3263 ["If (Then)" vhdl-template-if-then t]
3264 ["Library" vhdl-template-library t]
3265 ["Loop" vhdl-template-bare-loop t]
3266 ["Map" vhdl-template-map t]
3267 ["Next" vhdl-template-next t]
3268 ["Others (Aggregate)" vhdl-template-others t]
3269 ["Package (Decl)" vhdl-template-package-decl t]
3270 ["Package (Body)" vhdl-template-package-body t]
3271 ["Port" vhdl-template-port t]
3272 ["Procedure (Body)" vhdl-template-procedure-body t]
3273 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3274 ["Process (Comb)" vhdl-template-process-comb t]
3275 ["Process (Seq)" vhdl-template-process-seq t]
3276 ["Report" vhdl-template-report t]
3277 ["Return" vhdl-template-return t]
3278 ["Select" vhdl-template-selected-signal-asst t]
3279 ["Signal" vhdl-template-signal t]
3280 ["Subtype" vhdl-template-subtype t]
3281 ["Type" vhdl-template-type t]
3282 ["Use" vhdl-template-use t]
3283 ["Variable" vhdl-template-variable t]
3284 ["Wait" vhdl-template-wait t]
3285 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3286 ["When" vhdl-template-when t]
3287 ["While (Loop)" vhdl-template-while-loop t]
3288 ["With" vhdl-template-with t]))
3289 (when (vhdl-standard-p 'ams)
3290 '(("VHDL-AMS Construct"
3291 ["Break" vhdl-template-break t]
3292 ["Case (Use)" vhdl-template-case-use t]
3293 ["If (Use)" vhdl-template-if-use t]
3294 ["Limit" vhdl-template-limit t]
3295 ["Nature" vhdl-template-nature t]
3296 ["Procedural" vhdl-template-procedural t]
3297 ["Quantity (Free)" vhdl-template-quantity-free t]
3298 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3299 ["Quantity (Source)" vhdl-template-quantity-source t]
3300 ["Subnature" vhdl-template-subnature t]
3301 ["Terminal" vhdl-template-terminal t])))
3302 '(["Insert Construct..." vhdl-template-insert-construct
3303 :keys "C-c C-i C-t"]
3308 (when (vhdl-standard-p 'math)
3309 '(["math_complex" vhdl-template-package-math-complex t]
3310 ["math_real" vhdl-template-package-math-real t]))
3311 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3312 ["numeric_std" vhdl-template-package-numeric-std t]
3313 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3314 ["textio" vhdl-template-package-textio t]
3316 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3317 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3318 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3319 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3320 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3322 ["Insert Package..." vhdl-template-insert-package
3323 :keys "C-c C-i C-p"])))
3325 ["translate_on" vhdl-template-directive-translate-on t]
3326 ["translate_off" vhdl-template-directive-translate-off t]
3327 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3328 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3330 ["Insert Directive..." vhdl-template-insert-directive
3331 :keys "C-c C-i C-d"])
3333 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3334 ["Insert Footer" vhdl-template-footer t]
3335 ["Insert Date" vhdl-template-insert-date t]
3336 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3338 ["Query Next Prompt" vhdl-template-search-prompt t]))
3341 ;; add menu entries for defined models
3342 (let ((model-alist vhdl-model-alist) menu-list model)
3344 (setq model (car model-alist))
3349 (vhdl-function-name "vhdl-model" (nth 0 model))
3350 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3352 (setq model-alist (cdr model-alist)))
3353 (setq menu-list (nreverse menu-list))
3354 (vhdl-menu-split menu-list "Model"))
3356 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3357 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3359 ["Copy" vhdl-port-copy t]
3361 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3362 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3363 ["Paste As Instance" vhdl-port-paste-instance
3364 :keys "C-c C-p C-i" :active vhdl-port-list]
3365 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3366 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3367 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3368 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3370 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3372 ["Flatten" vhdl-port-flatten
3373 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3374 ["Reverse Direction" vhdl-port-reverse-direction
3375 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3377 ["New Component" vhdl-compose-new-component t]
3378 ["Copy Component" vhdl-port-copy t]
3379 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3380 ["Wire Components" vhdl-compose-wire-components t]
3382 ["Generate Configuration" vhdl-compose-configuration t]
3383 ["Generate Components Package" vhdl-compose-components-package t])
3385 ["Copy" vhdl-subprog-copy t]
3387 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3388 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3389 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3391 ["Flatten" vhdl-subprog-flatten
3392 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3395 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3397 ["Insert Inline Comment" vhdl-comment-append-inline t]
3398 ["Insert Horizontal Line" vhdl-comment-display-line t]
3399 ["Insert Display Comment" vhdl-comment-display t]
3401 ["Fill Comment" fill-paragraph t]
3402 ["Fill Comment Region" fill-region (mark)]
3403 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3404 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3406 ["Kill" vhdl-line-kill t]
3407 ["Copy" vhdl-line-copy t]
3408 ["Yank" vhdl-line-yank t]
3409 ["Expand" vhdl-line-expand t]
3411 ["Transpose Next" vhdl-line-transpose-next t]
3412 ["Transpose Prev" vhdl-line-transpose-previous t]
3413 ["Open" vhdl-line-open t]
3414 ["Join" vhdl-delete-indentation t]
3416 ["Goto" goto-line t]
3417 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3419 ["Forward Statement" vhdl-end-of-statement t]
3420 ["Backward Statement" vhdl-beginning-of-statement t]
3421 ["Forward Expression" vhdl-forward-sexp t]
3422 ["Backward Expression" vhdl-backward-sexp t]
3423 ["Forward Same Indent" vhdl-forward-same-indent t]
3424 ["Backward Same Indent" vhdl-backward-same-indent t]
3425 ["Forward Function" vhdl-end-of-defun t]
3426 ["Backward Function" vhdl-beginning-of-defun t]
3427 ["Mark Function" vhdl-mark-defun t])
3430 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3431 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3432 ["Region" vhdl-indent-region (mark)]
3433 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3435 ["Group" vhdl-align-group t]
3436 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3437 ["List" vhdl-align-list t]
3438 ["Declarations" vhdl-align-declarations t]
3439 ["Region" vhdl-align-region (mark)]
3440 ["Buffer" vhdl-align-buffer t]
3442 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3443 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3444 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3446 ["List" vhdl-fill-list t]
3447 ["Group" vhdl-fill-group t]
3448 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3449 ["Region" vhdl-fill-region (mark)])
3451 ["Region" vhdl-beautify-region (mark)]
3452 ["Buffer" vhdl-beautify-buffer t])
3454 ["Generic/Port Clause" vhdl-fix-clause t]
3456 ["Case Region" vhdl-fix-case-region (mark)]
3457 ["Case Buffer" vhdl-fix-case-buffer t]
3459 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3460 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3462 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3464 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3465 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3467 ["Fontify Buffer" vhdl-fontify-buffer t]
3468 ["Statistics Buffer" vhdl-statistics-buffer t]
3469 ["Show Messages" vhdl-show-messages t]
3470 ["Syntactic Info" vhdl-show-syntactic-information t]
3472 ["Speedbar" vhdl-speedbar t]
3473 ["Hide/Show" vhdl-hs-minor-mode t]
3476 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3477 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3478 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3479 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3480 ["Version" vhdl-version t]
3481 ["Bug Report..." vhdl-submit-bug-report t]
3486 (progn (customize-set-variable 'vhdl-electric-mode
3487 (not vhdl-electric-mode))
3488 (vhdl-mode-line-update))
3489 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3491 (progn (customize-set-variable 'vhdl-stutter-mode
3492 (not vhdl-stutter-mode))
3493 (vhdl-mode-line-update))
3494 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3496 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3497 (not vhdl-indent-tabs-mode))
3498 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3499 :style toggle :selected vhdl-indent-tabs-mode]
3501 ["Customize Group..." (customize-group 'vhdl-mode) t])
3503 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3505 '("Selected Project at Startup"
3506 ["None" (progn (customize-set-variable 'vhdl-project nil)
3507 (vhdl-set-project ""))
3508 :style radio :selected (null vhdl-project)]
3510 ;; add menu entries for defined projects
3511 (let ((project-alist vhdl-project-alist) menu-list name)
3512 (while project-alist
3513 (setq name (caar project-alist))
3515 (cons `[,name (progn (customize-set-variable
3516 'vhdl-project ,name)
3517 (vhdl-set-project ,name))
3518 :style radio :selected (equal ,name vhdl-project)]
3520 (setq project-alist (cdr project-alist)))
3521 (setq menu-list (nreverse menu-list))
3522 (vhdl-menu-split menu-list "Project")))
3523 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3524 ("Auto Load Setup File"
3526 (customize-set-variable 'vhdl-project-auto-load
3527 (if (memq 'startup vhdl-project-auto-load)
3528 (delq 'startup vhdl-project-auto-load)
3529 (cons 'startup vhdl-project-auto-load)))
3530 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3532 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3533 :style toggle :selected vhdl-project-sort]
3535 ["Customize Group..." (customize-group 'vhdl-project) t])
3537 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3539 '("Selected Compiler at Startup")
3540 ;; add menu entries for defined compilers
3541 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3543 (setq name (caar comp-alist))
3545 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3546 :style radio :selected (equal ,name vhdl-compiler)]
3548 (setq comp-alist (cdr comp-alist)))
3549 (setq menu-list (nreverse menu-list))
3550 (vhdl-menu-split menu-list "Compler")))
3551 ["Use Local Error Regexp"
3552 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3553 (not vhdl-compile-use-local-error-regexp))
3554 :style toggle :selected vhdl-compile-use-local-error-regexp]
3555 ["Makefile Generation Hook..."
3556 (customize-option 'vhdl-makefile-generation-hook) t]
3557 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3559 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3563 (progn (customize-set-variable 'vhdl-standard
3564 (list '87 (cadr vhdl-standard)))
3565 (vhdl-activate-customizations))
3566 :style radio :selected (eq '87 (car vhdl-standard))]
3568 (progn (customize-set-variable 'vhdl-standard
3569 (list '93 (cadr vhdl-standard)))
3570 (vhdl-activate-customizations))
3571 :style radio :selected (eq '93 (car vhdl-standard))]
3574 (progn (customize-set-variable
3575 'vhdl-standard (list (car vhdl-standard)
3576 (if (memq 'ams (cadr vhdl-standard))
3577 (delq 'ams (cadr vhdl-standard))
3578 (cons 'ams (cadr vhdl-standard)))))
3579 (vhdl-activate-customizations))
3580 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3582 (progn (customize-set-variable
3583 'vhdl-standard (list (car vhdl-standard)
3584 (if (memq 'math (cadr vhdl-standard))
3585 (delq 'math (cadr vhdl-standard))
3586 (cons 'math (cadr vhdl-standard)))))
3587 (vhdl-activate-customizations))
3588 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3589 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3590 ["Upper Case Keywords"
3591 (customize-set-variable 'vhdl-upper-case-keywords
3592 (not vhdl-upper-case-keywords))
3593 :style toggle :selected vhdl-upper-case-keywords]
3595 (customize-set-variable 'vhdl-upper-case-types
3596 (not vhdl-upper-case-types))
3597 :style toggle :selected vhdl-upper-case-types]
3598 ["Upper Case Attributes"
3599 (customize-set-variable 'vhdl-upper-case-attributes
3600 (not vhdl-upper-case-attributes))
3601 :style toggle :selected vhdl-upper-case-attributes]
3602 ["Upper Case Enumeration Values"
3603 (customize-set-variable 'vhdl-upper-case-enum-values
3604 (not vhdl-upper-case-enum-values))
3605 :style toggle :selected vhdl-upper-case-enum-values]
3606 ["Upper Case Constants"
3607 (customize-set-variable 'vhdl-upper-case-constants
3608 (not vhdl-upper-case-constants))
3609 :style toggle :selected vhdl-upper-case-constants]
3610 ("Use Direct Instantiation"
3612 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3613 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3615 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3616 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3618 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3619 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3621 ["Customize Group..." (customize-group 'vhdl-style) t])
3623 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3624 ["Architecture File Name..."
3625 (customize-option 'vhdl-architecture-file-name) t]
3626 ["Configuration File Name..."
3627 (customize-option 'vhdl-configuration-file-name) t]
3628 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3631 (customize-set-variable 'vhdl-file-name-case 'identity)
3632 :style radio :selected (eq 'identity vhdl-file-name-case)]
3634 (customize-set-variable 'vhdl-file-name-case 'downcase)
3635 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3637 (customize-set-variable 'vhdl-file-name-case 'upcase)
3638 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3640 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3641 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3643 ["Customize Group..." (customize-group 'vhdl-naming) t])
3645 ("Electric Keywords"
3647 (customize-set-variable 'vhdl-electric-keywords
3648 (if (memq 'vhdl vhdl-electric-keywords)
3649 (delq 'vhdl vhdl-electric-keywords)
3650 (cons 'vhdl vhdl-electric-keywords)))
3651 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3652 ["User Model Keywords"
3653 (customize-set-variable 'vhdl-electric-keywords
3654 (if (memq 'user vhdl-electric-keywords)
3655 (delq 'user vhdl-electric-keywords)
3656 (cons 'user vhdl-electric-keywords)))
3657 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3658 ("Insert Optional Labels"
3660 (customize-set-variable 'vhdl-optional-labels 'none)
3661 :style radio :selected (eq 'none vhdl-optional-labels)]
3663 (customize-set-variable 'vhdl-optional-labels 'process)
3664 :style radio :selected (eq 'process vhdl-optional-labels)]
3666 (customize-set-variable 'vhdl-optional-labels 'all)
3667 :style radio :selected (eq 'all vhdl-optional-labels)])
3668 ("Insert Empty Lines"
3670 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3671 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3672 ["Design Units Only"
3673 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3674 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3676 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3677 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3678 ["Argument List Indent"
3679 (customize-set-variable 'vhdl-argument-list-indent
3680 (not vhdl-argument-list-indent))
3681 :style toggle :selected vhdl-argument-list-indent]
3682 ["Association List with Formals"
3683 (customize-set-variable 'vhdl-association-list-with-formals
3684 (not vhdl-association-list-with-formals))
3685 :style toggle :selected vhdl-association-list-with-formals]
3686 ["Conditions in Parenthesis"
3687 (customize-set-variable 'vhdl-conditions-in-parenthesis
3688 (not vhdl-conditions-in-parenthesis))
3689 :style toggle :selected vhdl-conditions-in-parenthesis]
3690 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3691 ["One String..." (customize-option 'vhdl-one-string) t]
3693 ["Header String..." (customize-option 'vhdl-file-header) t]
3694 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3695 ["Company Name..." (customize-option 'vhdl-company-name) t]
3696 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3697 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3698 ["Date Format..." (customize-option 'vhdl-date-format) t]
3699 ["Modify Date Prefix String..."
3700 (customize-option 'vhdl-modify-date-prefix-string) t]
3701 ["Modify Date on Saving"
3702 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3703 (not vhdl-modify-date-on-saving))
3704 (vhdl-activate-customizations))
3705 :style toggle :selected vhdl-modify-date-on-saving])
3706 ("Sequential Process"
3709 (customize-set-variable 'vhdl-reset-kind 'none)
3710 :style radio :selected (eq 'none vhdl-reset-kind)]
3712 (customize-set-variable 'vhdl-reset-kind 'sync)
3713 :style radio :selected (eq 'sync vhdl-reset-kind)]
3715 (customize-set-variable 'vhdl-reset-kind 'async)
3716 :style radio :selected (eq 'async vhdl-reset-kind)])
3717 ["Reset is Active High"
3718 (customize-set-variable 'vhdl-reset-active-high
3719 (not vhdl-reset-active-high))
3720 :style toggle :selected vhdl-reset-active-high]
3721 ["Use Rising Clock Edge"
3722 (customize-set-variable 'vhdl-clock-rising-edge
3723 (not vhdl-clock-rising-edge))
3724 :style toggle :selected vhdl-clock-rising-edge]
3725 ("Clock Edge Condition"
3727 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3728 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3729 ["Function \"rising_edge\""
3730 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3731 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3732 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3733 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3735 ["Customize Group..." (customize-group 'vhdl-template) t])
3737 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3739 ["Include Port Comments"
3740 (customize-set-variable 'vhdl-include-port-comments
3741 (not vhdl-include-port-comments))
3742 :style toggle :selected vhdl-include-port-comments]
3743 ["Include Direction Comments"
3744 (customize-set-variable 'vhdl-include-direction-comments
3745 (not vhdl-include-direction-comments))
3746 :style toggle :selected vhdl-include-direction-comments]
3747 ["Include Type Comments"
3748 (customize-set-variable 'vhdl-include-type-comments
3749 (not vhdl-include-type-comments))
3750 :style toggle :selected vhdl-include-type-comments]
3751 ("Include Group Comments"
3753 (customize-set-variable 'vhdl-include-group-comments 'never)
3754 :style radio :selected (eq 'never vhdl-include-group-comments)]
3756 (customize-set-variable 'vhdl-include-group-comments 'decl)
3757 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3759 (customize-set-variable 'vhdl-include-group-comments 'always)
3760 :style radio :selected (eq 'always vhdl-include-group-comments)])
3761 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3762 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3764 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3765 ["Architecture Name..."
3766 (customize-option 'vhdl-testbench-architecture-name) t]
3767 ["Configuration Name..."
3768 (customize-option 'vhdl-testbench-configuration-name) t]
3769 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3771 (customize-set-variable 'vhdl-testbench-include-header
3772 (not vhdl-testbench-include-header))
3773 :style toggle :selected vhdl-testbench-include-header]
3774 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3775 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3776 ["Initialize Signals"
3777 (customize-set-variable 'vhdl-testbench-initialize-signals
3778 (not vhdl-testbench-initialize-signals))
3779 :style toggle :selected vhdl-testbench-initialize-signals]
3780 ["Include Library Clause"
3781 (customize-set-variable 'vhdl-testbench-include-library
3782 (not vhdl-testbench-include-library))
3783 :style toggle :selected vhdl-testbench-include-library]
3784 ["Include Configuration"
3785 (customize-set-variable 'vhdl-testbench-include-configuration
3786 (not vhdl-testbench-include-configuration))
3787 :style toggle :selected vhdl-testbench-include-configuration]
3790 (customize-set-variable 'vhdl-testbench-create-files 'none)
3791 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3793 (customize-set-variable 'vhdl-testbench-create-files 'single)
3794 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3796 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3797 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3798 ["Testbench Entity File Name..."
3799 (customize-option 'vhdl-testbench-entity-file-name) t]
3800 ["Testbench Architecture File Name..."
3801 (customize-option 'vhdl-testbench-architecture-file-name) t])
3803 ["Customize Group..." (customize-group 'vhdl-port) t])
3805 ["Architecture Name..."
3806 (customize-option 'vhdl-compose-architecture-name) t]
3807 ["Configuration Name..."
3808 (customize-option 'vhdl-compose-configuration-name) t]
3809 ["Components Package Name..."
3810 (customize-option 'vhdl-components-package-name) t]
3811 ["Use Components Package"
3812 (customize-set-variable 'vhdl-use-components-package
3813 (not vhdl-use-components-package))
3814 :style toggle :selected vhdl-use-components-package]
3816 (customize-set-variable 'vhdl-compose-include-header
3817 (not vhdl-compose-include-header))
3818 :style toggle :selected vhdl-compose-include-header]
3819 ("Create Entity/Architecture Files"
3821 (customize-set-variable 'vhdl-compose-create-files 'none)
3822 :style radio :selected (eq 'none vhdl-compose-create-files)]
3824 (customize-set-variable 'vhdl-compose-create-files 'single)
3825 :style radio :selected (eq 'single vhdl-compose-create-files)]
3827 (customize-set-variable 'vhdl-compose-create-files 'separate)
3828 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3829 ["Create Configuration File"
3830 (customize-set-variable 'vhdl-compose-configuration-create-file
3831 (not vhdl-compose-configuration-create-file))
3832 :style toggle :selected vhdl-compose-configuration-create-file]
3833 ["Hierarchical Configuration"
3834 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3835 (not vhdl-compose-configuration-hierarchical))
3836 :style toggle :selected vhdl-compose-configuration-hierarchical]
3837 ["Use Subconfiguration"
3838 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3839 (not vhdl-compose-configuration-use-subconfiguration))
3840 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3842 ["Customize Group..." (customize-group 'vhdl-compose) t])
3844 ["Self Insert Comments"
3845 (customize-set-variable 'vhdl-self-insert-comments
3846 (not vhdl-self-insert-comments))
3847 :style toggle :selected vhdl-self-insert-comments]
3848 ["Prompt for Comments"
3849 (customize-set-variable 'vhdl-prompt-for-comments
3850 (not vhdl-prompt-for-comments))
3851 :style toggle :selected vhdl-prompt-for-comments]
3852 ["Inline Comment Column..."
3853 (customize-option 'vhdl-inline-comment-column) t]
3854 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3856 ["Customize Group..." (customize-group 'vhdl-comment) t])
3858 ["Auto Align Templates"
3859 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3860 :style toggle :selected vhdl-auto-align]
3861 ["Align Line Groups"
3862 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3863 :style toggle :selected vhdl-align-groups]
3864 ["Group Separation String..."
3865 (customize-set-variable 'vhdl-align-group-separate) t]
3866 ["Align Lines with Same Indent"
3867 (customize-set-variable 'vhdl-align-same-indent
3868 (not vhdl-align-same-indent))
3869 :style toggle :selected vhdl-align-same-indent]
3871 ["Customize Group..." (customize-group 'vhdl-align) t])
3873 ["Highlighting On/Off..."
3875 (if (fboundp 'global-font-lock-mode)
3876 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3877 ["Highlight Keywords"
3878 (progn (customize-set-variable 'vhdl-highlight-keywords
3879 (not vhdl-highlight-keywords))
3880 (vhdl-fontify-buffer))
3881 :style toggle :selected vhdl-highlight-keywords]
3883 (progn (customize-set-variable 'vhdl-highlight-names
3884 (not vhdl-highlight-names))
3885 (vhdl-fontify-buffer))
3886 :style toggle :selected vhdl-highlight-names]
3887 ["Highlight Special Words"
3888 (progn (customize-set-variable 'vhdl-highlight-special-words
3889 (not vhdl-highlight-special-words))
3890 (vhdl-fontify-buffer))
3891 :style toggle :selected vhdl-highlight-special-words]
3892 ["Highlight Forbidden Words"
3893 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3894 (not vhdl-highlight-forbidden-words))
3895 (vhdl-fontify-buffer))
3896 :style toggle :selected vhdl-highlight-forbidden-words]
3897 ["Highlight Verilog Keywords"
3898 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3899 (not vhdl-highlight-verilog-keywords))
3900 (vhdl-fontify-buffer))
3901 :style toggle :selected vhdl-highlight-verilog-keywords]
3902 ["Highlight \"translate_off\""
3903 (progn (customize-set-variable 'vhdl-highlight-translate-off
3904 (not vhdl-highlight-translate-off))
3905 (vhdl-fontify-buffer))
3906 :style toggle :selected vhdl-highlight-translate-off]
3907 ["Case Sensitive Highlighting"
3908 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3909 (not vhdl-highlight-case-sensitive))
3910 (vhdl-fontify-buffer))
3911 :style toggle :selected vhdl-highlight-case-sensitive]
3912 ["Special Syntax Definition..."
3913 (customize-option 'vhdl-special-syntax-alist) t]
3914 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3915 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3916 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3917 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3919 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3921 ["Auto Open at Startup"
3922 (customize-set-variable 'vhdl-speedbar-auto-open
3923 (not vhdl-speedbar-auto-open))
3924 :style toggle :selected vhdl-speedbar-auto-open]
3925 ("Default Displaying Mode"
3927 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3928 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3929 ["Directory Hierarchy"
3930 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3931 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3932 ["Project Hierarchy"
3933 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3934 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3935 ["Indentation Offset..."
3936 (customize-option 'speedbar-indentation-width) t]
3937 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3938 ["Jump to Unit when Opening"
3939 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3940 (not vhdl-speedbar-jump-to-unit))
3941 :style toggle :selected vhdl-speedbar-jump-to-unit]
3942 ["Update Hierarchy on File Saving"
3943 (customize-set-variable 'vhdl-speedbar-update-on-saving
3944 (not vhdl-speedbar-update-on-saving))
3945 :style toggle :selected vhdl-speedbar-update-on-saving]
3946 ("Save in Cache File"
3947 ["Hierarchy Information"
3948 (customize-set-variable 'vhdl-speedbar-save-cache
3949 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3950 (delq 'hierarchy vhdl-speedbar-save-cache)
3951 (cons 'hierarchy vhdl-speedbar-save-cache)))
3952 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3953 ["Displaying Status"
3954 (customize-set-variable 'vhdl-speedbar-save-cache
3955 (if (memq 'display vhdl-speedbar-save-cache)
3956 (delq 'display vhdl-speedbar-save-cache)
3957 (cons 'display vhdl-speedbar-save-cache)))
3958 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3959 ["Cache File Name..."
3960 (customize-option 'vhdl-speedbar-cache-file-name) t]
3962 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3964 ["Add Index Menu when Loading File"
3965 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3966 (vhdl-index-menu-init))
3967 :style toggle :selected vhdl-index-menu]
3968 ["Add Source File Menu when Loading File"
3969 (progn (customize-set-variable 'vhdl-source-file-menu
3970 (not vhdl-source-file-menu))
3971 (vhdl-add-source-files-menu))
3972 :style toggle :selected vhdl-source-file-menu]
3973 ["Add Hideshow Menu at Startup"
3974 (progn (customize-set-variable 'vhdl-hideshow-menu
3975 (not vhdl-hideshow-menu))
3976 (vhdl-activate-customizations))
3977 :style toggle :selected vhdl-hideshow-menu]
3978 ["Hide Everything Initially"
3979 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3980 :style toggle :selected vhdl-hide-all-init]
3982 ["Customize Group..." (customize-group 'vhdl-menu) t])
3984 ["In Two Column Format"
3985 (progn (customize-set-variable 'vhdl-print-two-column
3986 (not vhdl-print-two-column))
3987 (message "Activate new setting by saving options and restarting Emacs"))
3988 :style toggle :selected vhdl-print-two-column]
3989 ["Use Customized Faces"
3990 (progn (customize-set-variable 'vhdl-print-customize-faces
3991 (not vhdl-print-customize-faces))
3992 (message "Activate new setting by saving options and restarting Emacs"))
3993 :style toggle :selected vhdl-print-customize-faces]
3995 ["Customize Group..." (customize-group 'vhdl-print) t])
3997 ["Use Intelligent Tab"
3998 (progn (customize-set-variable 'vhdl-intelligent-tab
3999 (not vhdl-intelligent-tab))
4000 (vhdl-activate-customizations))
4001 :style toggle :selected vhdl-intelligent-tab]
4002 ["Indent Syntax-Based"
4003 (customize-set-variable 'vhdl-indent-syntax-based
4004 (not vhdl-indent-syntax-based))
4005 :style toggle :selected vhdl-indent-syntax-based]
4006 ["Word Completion is Case Sensitive"
4007 (customize-set-variable 'vhdl-word-completion-case-sensitive
4008 (not vhdl-word-completion-case-sensitive))
4009 :style toggle :selected vhdl-word-completion-case-sensitive]
4010 ["Word Completion in Minibuffer"
4011 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4012 (not vhdl-word-completion-in-minibuffer))
4013 (message "Activate new setting by saving options and restarting Emacs"))
4014 :style toggle :selected vhdl-word-completion-in-minibuffer]
4015 ["Underscore is Part of Word"
4016 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4017 (not vhdl-underscore-is-part-of-word))
4018 (vhdl-activate-customizations))
4019 :style toggle :selected vhdl-underscore-is-part-of-word]
4021 ["Customize Group..." (customize-group 'vhdl-misc) t])
4022 ["Related..." (customize-browse 'vhdl-related) t]
4024 ["Save Options" customize-save-customized t]
4025 ["Activate Options" vhdl-activate-customizations t]
4026 ["Browse Options..." vhdl-customize t])))
4028 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4031 (defun vhdl-update-mode-menu ()
4032 "Update VHDL Mode menu."
4034 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4035 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4036 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4037 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4038 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4041 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4043 (defconst vhdl-imenu-generic-expression
4046 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4049 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4052 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4055 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4058 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4061 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4064 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4067 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4070 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4073 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4076 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4078 (defun vhdl-index-menu-init ()
4079 "Initialize index menu."
4080 (set (make-local-variable 'imenu-case-fold-search) t)
4081 (set (make-local-variable 'imenu-generic-expression)
4082 vhdl-imenu-generic-expression)
4083 (when (and vhdl-index-menu (fboundp 'imenu))
4084 (if (or (not (boundp 'font-lock-maximum-size))
4085 (> font-lock-maximum-size (buffer-size)))
4086 (imenu-add-to-menubar "Index")
4087 (message "Scanning buffer for index...buffer too big"))))
4089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4090 ;; Source file menu (using `easy-menu.el')
4092 (defvar vhdl-sources-menu nil)
4094 (defun vhdl-directory-files (directory &optional full match)
4095 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4097 (if (not (file-directory-p directory))
4098 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4099 (let ((dir (directory-files directory full match)))
4100 (setq dir (delete "." dir))
4101 (setq dir (delete ".." dir))
4104 (defun vhdl-get-source-files (&optional full directory)
4105 "Get list of VHDL source files in DIRECTORY or current directory."
4106 (let ((mode-alist auto-mode-alist)
4108 ;; create regular expressions for matching file names
4109 (setq filename-regexp "\\`[^.].*\\(")
4111 (when (eq (cdar mode-alist) 'vhdl-mode)
4112 (setq filename-regexp
4113 (concat filename-regexp (caar mode-alist) "\\|")))
4114 (setq mode-alist (cdr mode-alist)))
4115 (setq filename-regexp
4116 (concat (substring filename-regexp 0
4117 (string-match "\\\\|$" filename-regexp)) "\\)"))
4119 (vhdl-directory-files
4120 (or directory default-directory) full filename-regexp)))
4122 (defun vhdl-add-source-files-menu ()
4123 "Scan directory for all VHDL source files and generate menu.
4124 The directory of the current source file is scanned."
4126 (message "Scanning directory for source files ...")
4127 (let ((newmap (current-local-map))
4128 (file-list (vhdl-get-source-files))
4130 ;; Create list for menu
4134 (setq menu-list (cons (vector (car file-list)
4135 (list 'find-file (car file-list)) t)
4137 (setq file-list (cdr file-list)))
4138 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4139 (when found (setq menu-list (cons "--" menu-list)))
4140 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4141 (setq menu-list (cons "Sources" menu-list))
4143 (easy-menu-add menu-list)
4144 (easy-menu-define vhdl-sources-menu newmap
4145 "VHDL source files menu" menu-list))
4149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4152 ;; performs all buffer local initializations
4156 "Major mode for editing VHDL code.
4161 TEMPLATE INSERTION (electrification):
4162 After typing a VHDL keyword and entering `SPC', you are prompted for
4163 arguments while a template is generated for that VHDL construct. Typing
4164 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4165 template generation. Optional arguments are indicated by square
4166 brackets and removed if the queried string is left empty. Prompts for
4167 mandatory arguments remain in the code if the queried string is left
4168 empty. They can be queried again by `C-c C-t C-q'. Enabled
4169 electrification is indicated by `/e' in the modeline.
4171 Typing `M-SPC' after a keyword inserts a space without calling the
4172 template generator. Automatic template generation (i.e.
4173 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4174 setting option `vhdl-electric-mode' (see OPTIONS).
4176 Template generators can be invoked from the VHDL menu, by key
4177 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4178 the keyword (i.e. first word of menu entry not in parenthesis) and
4179 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4180 conf, comp, cons, func, inst, pack, sig, var.
4182 Template styles can be customized in customization group
4183 `vhdl-template' \(see OPTIONS).
4187 A file header can be inserted by `C-c C-t C-h'. A file footer
4188 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4189 See customization group `vhdl-header'.
4193 Double striking of some keys inserts cumbersome VHDL syntax elements.
4194 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4195 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4196 the modeline. The stuttering keys and their effects are:
4198 ;; --> \" : \" [ --> ( -- --> comment
4199 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4200 .. --> \" => \" ] --> ) --- --> horizontal line
4201 ,, --> \" <= \" ]] --> ] ---- --> display comment
4202 == --> \" == \" '' --> \\\"
4206 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4207 word in the buffer that starts alike, inserts it and adjusts case.
4208 Re-typing `TAB' toggles through alternative word completions. This also
4209 works in the minibuffer (i.e. in template generator prompts).
4211 Typing `TAB' after `(' looks for and inserts complete parenthesized
4212 expressions (e.g. for array index ranges). All keywords as well as
4213 standard types and subprograms of VHDL have predefined abbreviations
4214 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4215 beginning with \"std\").
4217 Typing `TAB' after a non-word character indents the line if at the
4218 beginning of a line (i.e. no preceding non-blank characters), and
4219 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4224 `--' puts a single comment.
4225 `---' draws a horizontal line for separating code segments.
4226 `----' inserts a display comment, i.e. two horizontal lines
4227 with a comment in between.
4228 `--CR' comments out code on that line. Re-hitting CR comments
4229 out following lines.
4230 `C-c c' comments out a region if not commented out,
4231 uncomments a region if already commented out.
4233 You are prompted for comments after object definitions (i.e. signals,
4234 variables, constants, ports) and after subprogram and process
4235 specifications if option `vhdl-prompt-for-comments' is non-nil.
4236 Comments are automatically inserted as additional labels (e.g. after
4237 begin statements) and as help comments if `vhdl-self-insert-comments' is
4240 Inline comments (i.e. comments after a piece of code on the same line)
4241 are indented at least to `vhdl-inline-comment-column'. Comments go at
4242 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4243 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4244 in a comment automatically opens a new comment line. `M-q' re-fills
4245 multi-line comments.
4249 `TAB' indents a line if at the beginning of the line. The amount of
4250 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4251 always indents the current line (is bound to `TAB' if option
4252 `vhdl-intelligent-tab' is nil).
4254 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4255 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4256 indented normally (nil) or relative to the opening parenthesis (non-nil)
4257 according to option `vhdl-argument-list-indent'.
4259 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4260 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4263 Syntax-based indentation can be very slow in large files. Option
4264 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4268 The alignment functions align operators, keywords, and inline comments
4269 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4270 separated by blank lines, `C-c C-a C-i' a block of lines with same
4271 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4272 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4273 C-a C-d' all lines within the declarative part of a design unit. `C-c
4274 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4275 for a group of lines, and `C-c C-a M-c' for a region.
4277 If option `vhdl-align-groups' is non-nil, groups of code lines
4278 separated by special lines (see option `vhdl-align-group-separate') are
4279 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4280 blocks of lines with same indent are aligned separately. Some templates
4281 are automatically aligned after generation if option `vhdl-auto-align'
4284 Alignment tries to align inline comments at
4285 `vhdl-inline-comment-column' and tries inline comment not to exceed
4286 `vhdl-end-comment-column'.
4288 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4289 symbols are surrounded by one space, and multiple spaces are eliminated.
4293 Code filling allows to condense code (e.g. sensitivity lists or port
4294 maps) by removing comments and newlines and re-wrapping so that all
4295 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4296 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4297 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4298 `C-c C-f M-f' an entire region.
4301 CODE BEAUTIFICATION:
4302 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4303 buffer respectively. This inludes indentation, alignment, and case
4304 fixing. Code beautification can also be run non-interactively using the
4307 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4311 Generic and port clauses from entity or component declarations can be
4312 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4313 as component instantiations and corresponding internal constants and
4314 signals, as a generic map with constants as actual generics, and as
4315 internal signal initializations (menu).
4317 To include formals in component instantiations, see option
4318 `vhdl-association-list-with-formals'. To include comments in pasting,
4319 see options `vhdl-include-...-comments'.
4321 A clause with several generic/port names on the same line can be
4322 flattened (`C-c C-p C-f') so that only one name per line exists. The
4323 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4324 outputs and vice versa, which can be useful in testbenches. (This
4325 reversion is done on the internal data structure and is only reflected
4326 in subsequent paste operations.)
4328 Names for actual ports, instances, testbenches, and
4329 design-under-test instances can be derived from existing names according
4330 to options `vhdl-...-name'. See customization group `vhdl-port'.
4333 SUBPROGRAM TRANSLATION:
4334 Similar functionality exists for copying/pasting the interface of
4335 subprograms (function/procedure). A subprogram interface can be copied
4336 and then pasted as a subprogram declaration, body or call (uses
4337 association list with formals).
4340 TESTBENCH GENERATION:
4341 A copied port can also be pasted as a testbench. The generated
4342 testbench includes an entity, an architecture, and an optional
4343 configuration. The architecture contains the component declaration and
4344 instantiation of the DUT as well as internal constant and signal
4345 declarations. Additional user-defined templates can be inserted. The
4346 names used for entity/architecture/configuration/DUT as well as the file
4347 structure to be generated can be customized. See customization group
4352 Key bindings (`C-c ...') exist for most commands (see in menu).
4356 All commands can be found in the VHDL menu including their key bindings.
4360 The speedbar allows browsing of directories and file contents. It can
4361 be accessed from the VHDL menu and is automatically opened if option
4362 `vhdl-speedbar-auto-open' is non-nil.
4364 In speedbar, open files and directories with `mouse-2' on the name and
4365 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4368 DESIGN HIERARCHY BROWSER:
4369 The speedbar can also be used for browsing the hierarchy of design units
4370 contained in the source files of the current directory or the specified
4371 projects (see option `vhdl-project-alist').
4373 The speedbar can be switched between file, directory hierarchy and
4374 project hierarchy browsing mode in the speedbar menu or by typing `f',
4375 `h' or `H' in speedbar.
4377 In speedbar, open design units with `mouse-2' on the name and browse
4378 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4379 from entities and components (in packages). Individual design units and
4380 complete designs can directly be compiled (\"Make\" menu entry).
4382 The hierarchy is automatically updated upon saving a modified source
4383 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4384 hierarchy is only updated for projects that have been opened once in the
4385 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4386 options in group `vhdl-speedbar').
4388 Simple design consistency checks are done during scanning, such as
4389 multiple declarations of the same unit or missing primary units that are
4390 required by secondary units.
4393 STRUCTURAL COMPOSITION:
4394 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4395 for a new component. Subcomponents (i.e. component declaration and
4396 instantiation) can be automatically placed from a previously read port
4397 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4398 all subcomponents can be automatically connected using internal signals
4399 and ports (`C-c C-c C-w') following these rules:
4400 - subcomponent actual ports with same name are considered to be
4401 connected by a signal (internal signal or port)
4402 - signals that are only inputs to subcomponents are considered as
4403 inputs to this component -> input port created
4404 - signals that are only outputs from subcomponents are considered as
4405 outputs from this component -> output port created
4406 - signals that are inputs to AND outputs from subcomponents are
4407 considered as internal connections -> internal signal created
4409 Purpose: With appropriate naming conventions it is possible to
4410 create higher design levels with only a few mouse clicks or key
4411 strokes. A new design level can be created by simply generating a new
4412 component, placing the required subcomponents from the hierarchy
4413 browser, and wiring everything automatically.
4415 Note: Automatic wiring only works reliably on templates of new
4416 components and component instantiations that were created by VHDL mode.
4418 Component declarations can be placed in a components package (option
4419 `vhdl-use-components-package') which can be automatically generated for
4420 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4421 component instantiation is also supported (option
4422 `vhdl-use-direct-instantiation').
4424 | Configuration declarations can automatically be generated either from
4425 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4426 | the speedbar menu (for the architecture under the cursor). The
4427 | configurations can optionally be hierarchical (i.e. include all
4428 | component levels of a hierarchical design, option
4429 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4430 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4431 | subcomponents in hierarchical configurations, the most-recently-analyzed
4432 | (mra) architecture is selected. If another architecture is desired, it
4433 | can be marked as most-recently-analyzed (speedbar menu) before
4434 | generating the configuration.
4436 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4437 | declarations) are currently not considered when displaying
4438 | configurations in speedbar.
4440 See the options group `vhdl-compose' for all relevant user options.
4443 SOURCE FILE COMPILATION:
4444 The syntax of the current buffer can be analyzed by calling a VHDL
4445 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4446 option `vhdl-compiler'. The available compilers are listed in option
4447 `vhdl-compiler-alist' including all required compilation command,
4448 command options, compilation directory, and error message syntax
4449 information. New compilers can be added.
4451 All the source files of an entire design can be compiled by the `make'
4452 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4455 MAKEFILE GENERATION:
4456 Makefiles can be generated automatically by an internal generation
4457 routine (`C-c M-k'). The library unit dependency information is
4458 obtained from the hierarchy browser. Makefile generation can be
4459 customized for each compiler in option `vhdl-compiler-alist'.
4461 Makefile generation can also be run non-interactively using the
4464 emacs -batch -l ~/.emacs -l vhdl-mode
4465 [-compiler compilername] [-project projectname]
4466 -f vhdl-generate-makefile
4468 The Makefile's default target \"all\" compiles the entire design, the
4469 target \"clean\" removes it and the target \"library\" creates the
4470 library directory if not existent. The Makefile also includes a target
4471 for each primary library unit which allows selective compilation of this
4472 unit, its secondary units and its subhierarchy (example: compilation of
4473 a design specified by a configuration). User specific parts can be
4474 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4477 - Only library units and dependencies within the current library are
4478 considered. Makefiles for designs that span multiple libraries are
4479 not (yet) supported.
4480 - Only one-level configurations are supported (also hierarchical),
4481 but configurations that go down several levels are not.
4482 - The \"others\" keyword in configurations is not supported.
4486 Projects can be defined in option `vhdl-project-alist' and a current
4487 project be selected using option `vhdl-project' (permanently) or from
4488 the menu or speedbar (temporarily). For each project, title and
4489 description strings (for the file headers), source files/directories
4490 (for the hierarchy browser and Makefile generation), library name, and
4491 compiler-dependent options, exceptions and compilation directory can be
4492 specified. Compilation settings overwrite the settings of option
4493 `vhdl-compiler-alist'.
4495 Project setups can be exported (i.e. written to a file) and imported.
4496 Imported setups are not automatically saved in `vhdl-project-alist' but
4497 can be saved afterwards in its customization buffer. When starting
4498 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4499 vhdl-mode\") in a directory with an existing project setup file, it is
4500 automatically loaded and its project activated if option
4501 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4502 files can be specified in option `vhdl-project-file-name'. Multiple
4503 project setups can be automatically loaded from global directories.
4504 This is an alternative to specifying project setups with option
4505 `vhdl-project-alist'.
4509 As an alternative to the speedbar, an index menu can be added (set
4510 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4511 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4512 file) for browsing the file contents (is not populated if buffer is
4513 larger than `font-lock-maximum-size'). Also, a source file menu can be
4514 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4515 current directory for VHDL source files.
4519 The VHDL standards to be used are specified in option `vhdl-standard'.
4520 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4524 Lower and upper case for keywords and standardized types, attributes,
4525 and enumeration values is supported. If the option
4526 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4527 lower case and are converted into upper case automatically (not for
4528 types, attributes, and enumeration values). The case of keywords,
4529 types, attributes,and enumeration values can be fixed for an entire
4530 region (menu) or buffer (`C-c C-x C-c') according to the options
4531 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4534 HIGHLIGHTING (fontification):
4535 Keywords and standardized types, attributes, enumeration values, and
4536 function names (controlled by option `vhdl-highlight-keywords'), as well
4537 as comments, strings, and template prompts are highlighted using
4538 different colors. Unit, subprogram, signal, variable, constant,
4539 parameter and generic/port names in declarations as well as labels are
4540 highlighted if option `vhdl-highlight-names' is non-nil.
4542 Additional reserved words or words with a forbidden syntax (e.g. words
4543 that should be avoided) can be specified in option
4544 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4545 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4546 keywords are highlighted as forbidden words if option
4547 `vhdl-highlight-verilog-keywords' is non-nil.
4549 Words with special syntax can be highlighted by specifying their
4550 syntax and color in option `vhdl-special-syntax-alist' and by setting
4551 option `vhdl-highlight-special-words' to non-nil. This allows to
4552 establish some naming conventions (e.g. to distinguish different kinds
4553 of signals or other objects by using name suffices) and to support them
4556 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4557 to support case-sensitive highlighting. However, keywords are then only
4558 highlighted if written in lower case.
4560 Code between \"translate_off\" and \"translate_on\" pragmas is
4561 highlighted using a different background color if option
4562 `vhdl-highlight-translate-off' is non-nil.
4564 For documentation and customization of the used colors see
4565 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4566 highlighting of matching parenthesis, see customization group
4567 `paren-showing'. Automatic buffer highlighting is turned on/off by
4568 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4572 VHDL models (templates) can be specified by the user and made accessible
4573 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4574 electrification. See option `vhdl-model-alist'.
4578 The code of blocks, processes, subprograms, component declarations and
4579 instantiations, generic/port clauses, and configuration declarations can
4580 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4581 the code (see customization group `vhdl-menu'). XEmacs: limited
4582 functionality due to old `hideshow.el' package.
4586 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4587 current process, `C-c C-u M-s' of all processes in the current buffer.
4589 - Only declared local signals (ports, signals declared in
4590 architecture and blocks) are automatically inserted.
4591 - Global signals declared in packages are not automatically inserted.
4592 Insert them once manually (will be kept afterwards).
4593 - Out parameters of procedures are considered to be read.
4594 Use option `vhdl-entity-file-name' to specify the entity file name
4595 \(used to obtain the port names).
4599 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4600 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4604 Postscript printing with different faces (an optimized set of faces is
4605 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4606 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4607 postscript printing commands. Option `vhdl-print-two-column' defines
4608 appropriate default settings for nice landscape two-column printing.
4609 The paper format can be set by option `ps-paper-type'. Do not forget to
4610 switch `ps-print-color-p' to nil for printing on black-and-white
4615 User options allow customization of VHDL Mode. All options are
4616 accessible from the \"Options\" menu entry. Simple options (switches
4617 and choices) can directly be changed, while for complex options a
4618 customization buffer is opened. Changed options can be saved for future
4619 sessions using the \"Save Options\" menu entry.
4621 Options and their detailed descriptions can also be accessed by using
4622 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4623 customize-group' for groups). Some customizations only take effect
4624 after some action (read the NOTE in the option documentation).
4625 Customization can also be done globally (i.e. site-wide, read the
4628 Not all options are described in this documentation, so go and see
4629 what other useful user options there are (`M-x vhdl-customize' or menu)!
4633 As default, files with extensions \".vhd\" and \".vhdl\" are
4634 automatically recognized as VHDL source files. To add an extension
4635 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4637 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4641 - To start Emacs with open VHDL hierarchy browser without having to load
4642 a VHDL file first, use the command:
4644 emacs -l vhdl-mode -f speedbar-frame-mode
4646 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4648 - Some features only work on properly indented code.
4652 See also the release notes (menu) for added features in new releases.
4658 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4659 Add a description of the problem and include a reproducible test case.
4661 Questions and enhancement requests can be sent to <reto@gnu.org>.
4663 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4664 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4665 releases. You are kindly invited to participate in beta testing. Subscribe
4666 to above mailing lists by sending an email to <reto@gnu.org>.
4668 VHDL Mode is officially distributed at
4669 http://opensource.ethz.ch/emacs/vhdl-mode.html
4670 where the latest version can be found.
4676 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4677 - XEmacs: Incorrect start-up when automatically opening speedbar.
4678 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4681 The VHDL Mode Authors
4682 Reto Zimmermann and Rod Whitby
4689 (kill-all-local-variables)
4690 (setq major-mode 'vhdl-mode)
4691 (setq mode-name "VHDL")
4693 ;; set maps and tables
4694 (use-local-map vhdl-mode-map)
4695 (set-syntax-table vhdl-mode-syntax-table)
4696 (setq local-abbrev-table vhdl-mode-abbrev-table)
4698 ;; set local variables
4699 (set (make-local-variable 'paragraph-start)
4700 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4701 (set (make-local-variable 'paragraph-separate) paragraph-start)
4702 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4703 (set (make-local-variable 'require-final-newline)
4704 (if vhdl-emacs-22 mode-require-final-newline t))
4705 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4706 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4707 (set (make-local-variable 'comment-start) "--")
4708 (set (make-local-variable 'comment-end) "")
4710 (set (make-local-variable 'comment-padding) ""))
4711 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4712 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4713 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4714 (set (make-local-variable 'comment-multi-line) nil)
4715 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4716 (set (make-local-variable 'hippie-expand-verbose) nil)
4718 ;; setup the comment indent variable in a Emacs version portable way
4719 ;; ignore any byte compiler warnings you might get here
4720 (when (boundp 'comment-indent-function)
4721 (make-local-variable 'comment-indent-function)
4722 (setq comment-indent-function 'vhdl-comment-indent))
4724 ;; initialize font locking
4725 (set (make-local-variable 'font-lock-defaults)
4727 '(nil vhdl-font-lock-keywords) nil
4728 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4729 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4730 (unless vhdl-emacs-21
4731 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4732 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4733 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4734 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4735 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4736 ; (turn-on-font-lock)
4738 ;; variables for source file compilation
4739 (when vhdl-compile-use-local-error-regexp
4740 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4741 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4744 (vhdl-index-menu-init)
4745 ;; add source file menu
4746 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4748 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4749 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4750 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4751 ;; initialize hideshow and add menu
4752 (vhdl-hideshow-init)
4753 (run-hooks 'menu-bar-update-hook)
4756 (vhdl-ps-print-init)
4757 (vhdl-write-file-hooks-init)
4758 (vhdl-mode-line-update)
4759 (message "VHDL Mode %s.%s" vhdl-version
4760 (if noninteractive "" " See menu for documentation and release notes."))
4764 (run-mode-hooks 'vhdl-mode-hook)
4765 (run-hooks 'vhdl-mode-hook)))
4767 (defun vhdl-activate-customizations ()
4768 "Activate all customizations on local variables."
4770 (vhdl-mode-map-init)
4771 (use-local-map vhdl-mode-map)
4772 (set-syntax-table vhdl-mode-syntax-table)
4773 (setq comment-column vhdl-inline-comment-column)
4774 (setq end-comment-column vhdl-end-comment-column)
4775 (vhdl-write-file-hooks-init)
4776 (vhdl-update-mode-menu)
4777 (vhdl-hideshow-init)
4778 (run-hooks 'menu-bar-update-hook)
4779 (vhdl-mode-line-update))
4781 (defun vhdl-write-file-hooks-init ()
4782 "Add/remove hooks when buffer is saved."
4783 (if vhdl-modify-date-on-saving
4784 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4785 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4786 (make-local-variable 'after-save-hook)
4787 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4789 (defun vhdl-process-command-line-option (option)
4790 "Process command line options for VHDL Mode."
4793 ((equal option "-compiler")
4794 (vhdl-set-compiler (car command-line-args-left))
4795 (setq command-line-args-left (cdr command-line-args-left)))
4797 ((equal option "-project")
4798 (vhdl-set-project (car command-line-args-left))
4799 (setq command-line-args-left (cdr command-line-args-left)))))
4801 ;; make Emacs process VHDL Mode options
4802 (setq command-switch-alist
4803 (append command-switch-alist
4804 '(("-compiler" . vhdl-process-command-line-option)
4805 ("-project" . vhdl-process-command-line-option))))
4808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4809 ;;; Keywords and standardized words
4810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4812 (defconst vhdl-93-keywords
4814 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4815 "assert" "attribute"
4816 "begin" "block" "body" "buffer" "bus"
4817 "case" "component" "configuration" "constant"
4818 "disconnect" "downto"
4819 "else" "elsif" "end" "entity" "exit"
4820 "file" "for" "function"
4821 "generate" "generic" "group" "guarded"
4822 "if" "impure" "in" "inertial" "inout" "is"
4823 "label" "library" "linkage" "literal" "loop"
4825 "nand" "new" "next" "nor" "not" "null"
4826 "of" "on" "open" "or" "others" "out"
4827 "package" "port" "postponed" "procedure" "process" "pure"
4828 "range" "record" "register" "reject" "rem" "report" "return"
4830 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4831 "then" "to" "transport" "type"
4832 "unaffected" "units" "until" "use"
4834 "wait" "when" "while" "with"
4837 "List of VHDL'93 keywords.")
4839 (defconst vhdl-ams-keywords
4841 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4842 "reference" "spectrum" "subnature" "terminal" "through"
4845 "List of VHDL-AMS keywords.")
4847 (defconst vhdl-verilog-keywords
4849 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4850 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4851 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4852 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4853 "endprimitive" "endspecify" "endtable" "endtask" "event"
4854 "for" "force" "forever" "fork" "function"
4855 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4856 "macromodule" "makefile" "medium" "module"
4857 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4858 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4860 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4861 "rtranif0" "rtranif1"
4862 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4863 "strong1" "supply" "supply0" "supply1"
4864 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4865 "triand" "trior" "trireg"
4866 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4868 "List of Verilog keywords as candidate for additional reserved words.")
4870 (defconst vhdl-93-types
4872 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4873 "real" "time" "natural" "positive" "string" "line" "text" "side"
4874 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4875 "std_logic" "std_logic_vector"
4876 "std_ulogic" "std_ulogic_vector"
4878 "List of VHDL'93 standardized types.")
4880 (defconst vhdl-ams-types
4882 "domain_type" "real_vector"
4883 ;; from `nature_pkg' package
4884 "voltage" "current" "electrical" "position" "velocity" "force"
4885 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4886 "pressure" "flowrate" "fluid"
4888 "List of VHDL-AMS standardized types.")
4890 (defconst vhdl-math-types
4892 "complex" "complex_polar"
4894 "List of Math Packages standardized types.")
4896 (defconst vhdl-93-attributes
4898 "base" "left" "right" "high" "low" "pos" "val" "succ"
4899 "pred" "leftof" "rightof" "range" "reverse_range"
4900 "length" "delayed" "stable" "quiet" "transaction"
4901 "event" "active" "last_event" "last_active" "last_value"
4902 "driving" "driving_value" "ascending" "value" "image"
4903 "simple_name" "instance_name" "path_name"
4906 "List of VHDL'93 standardized attributes.")
4908 (defconst vhdl-ams-attributes
4911 "reference" "contribution" "tolerance"
4912 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4915 "List of VHDL-AMS standardized attributes.")
4917 (defconst vhdl-93-enum-values
4920 "note" "warning" "error" "failure"
4921 "read_mode" "write_mode" "append_mode"
4922 "open_ok" "status_error" "name_error" "mode_error"
4923 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4926 "List of VHDL'93 standardized enumeration values.")
4928 (defconst vhdl-ams-enum-values
4930 "quiescent_domain" "time_domain" "frequency_domain"
4931 ;; from `nature_pkg' package
4932 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4934 "List of VHDL-AMS standardized enumeration values.")
4936 (defconst vhdl-math-constants
4938 "math_e" "math_1_over_e"
4939 "math_pi" "math_two_pi" "math_1_over_pi"
4940 "math_half_pi" "math_q_pi" "math_3_half_pi"
4941 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4942 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4943 "math_deg_to_rad" "math_rad_to_deg"
4944 "cbase_1" "cbase_j" "czero"
4946 "List of Math Packages standardized constants.")
4948 (defconst vhdl-93-functions
4950 "now" "resolved" "rising_edge" "falling_edge"
4951 "read" "readline" "write" "writeline" "endfile"
4952 "resize" "is_X" "std_match"
4953 "shift_left" "shift_right" "rotate_left" "rotate_right"
4954 "to_unsigned" "to_signed" "to_integer"
4955 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4956 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4957 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4958 "shl" "shr" "ext" "sxt"
4961 "List of VHDL'93 standardized functions.")
4963 (defconst vhdl-ams-functions
4967 "List of VHDL-AMS standardized functions.")
4969 (defconst vhdl-math-functions
4971 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4972 "sqrt" "cbrt" "exp" "log"
4973 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4974 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4975 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4977 "List of Math Packages standardized functions.")
4979 (defconst vhdl-93-packages
4981 "std_logic_1164" "numeric_std" "numeric_bit"
4983 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4984 "std_logic_misc" "std_logic_textio"
4987 "List of VHDL'93 standardized packages and libraries.")
4989 (defconst vhdl-ams-packages
4991 ;; from `nature_pkg' package
4994 "List of VHDL-AMS standardized packages and libraries.")
4996 (defconst vhdl-math-packages
4998 "math_real" "math_complex"
5000 "List of Math Packages standardized packages and libraries.")
5002 (defvar vhdl-keywords nil
5003 "List of VHDL keywords.")
5005 (defvar vhdl-types nil
5006 "List of VHDL standardized types.")
5008 (defvar vhdl-attributes nil
5009 "List of VHDL standardized attributes.")
5011 (defvar vhdl-enum-values nil
5012 "List of VHDL standardized enumeration values.")
5014 (defvar vhdl-constants nil
5015 "List of VHDL standardized constants.")
5017 (defvar vhdl-functions nil
5018 "List of VHDL standardized functions.")
5020 (defvar vhdl-packages nil
5021 "List of VHDL standardized packages and libraries.")
5023 (defvar vhdl-reserved-words nil
5024 "List of additional reserved words.")
5026 (defvar vhdl-keywords-regexp nil
5027 "Regexp for VHDL keywords.")
5029 (defvar vhdl-types-regexp nil
5030 "Regexp for VHDL standardized types.")
5032 (defvar vhdl-attributes-regexp nil
5033 "Regexp for VHDL standardized attributes.")
5035 (defvar vhdl-enum-values-regexp nil
5036 "Regexp for VHDL standardized enumeration values.")
5038 (defvar vhdl-functions-regexp nil
5039 "Regexp for VHDL standardized functions.")
5041 (defvar vhdl-packages-regexp nil
5042 "Regexp for VHDL standardized packages and libraries.")
5044 (defvar vhdl-reserved-words-regexp nil
5045 "Regexp for additional reserved words.")
5047 (defvar vhdl-directive-keywords-regexp nil
5048 "Regexp for compiler directive keywords.")
5050 (defun vhdl-words-init ()
5051 "Initialize reserved words."
5053 (append vhdl-93-keywords
5054 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5056 (append vhdl-93-types
5057 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5058 (when (vhdl-standard-p 'math) vhdl-math-types)))
5059 (setq vhdl-attributes
5060 (append vhdl-93-attributes
5061 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5062 (setq vhdl-enum-values
5063 (append vhdl-93-enum-values
5064 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5065 (setq vhdl-constants
5066 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5067 (setq vhdl-functions
5068 (append vhdl-93-functions
5069 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5070 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5072 (append vhdl-93-packages
5073 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5074 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5075 (setq vhdl-reserved-words
5076 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5077 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5079 (setq vhdl-keywords-regexp
5080 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5081 (setq vhdl-types-regexp
5082 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5083 (setq vhdl-attributes-regexp
5084 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5085 (setq vhdl-enum-values-regexp
5086 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5087 (setq vhdl-functions-regexp
5088 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5089 (setq vhdl-packages-regexp
5090 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5091 (setq vhdl-reserved-words-regexp
5093 (unless (equal vhdl-forbidden-syntax "")
5094 (concat vhdl-forbidden-syntax "\\|"))
5095 (regexp-opt vhdl-reserved-words)
5097 (setq vhdl-directive-keywords-regexp
5098 (concat "\\<\\(" (mapconcat 'regexp-quote
5099 vhdl-directive-keywords "\\|") "\\)\\>"))
5100 (vhdl-abbrev-list-init))
5102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5105 (defvar vhdl-abbrev-list nil
5106 "Predefined abbreviations for VHDL.")
5108 (defun vhdl-abbrev-list-init ()
5109 (setq vhdl-abbrev-list
5111 (list vhdl-upper-case-keywords) vhdl-keywords
5112 (list vhdl-upper-case-types) vhdl-types
5113 (list vhdl-upper-case-attributes) vhdl-attributes
5114 (list vhdl-upper-case-enum-values) vhdl-enum-values
5115 (list vhdl-upper-case-constants) vhdl-constants
5116 (list nil) vhdl-functions
5117 (list nil) vhdl-packages)))
5119 ;; initialize reserved words for VHDL Mode
5123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5130 ;; constant regular expressions for looking at various constructs
5132 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5133 "Regexp describing a VHDL symbol.
5134 We cannot use just `word' syntax class since `_' cannot be in word
5135 class. Putting underscore in word class breaks forward word movement
5136 behavior that users are familiar with.")
5138 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5139 "Regexp describing a case statement header key.")
5141 (defconst vhdl-label-key
5142 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5143 "Regexp describing a VHDL label.")
5145 ;; Macro definitions:
5147 (defmacro vhdl-point (position)
5148 "Return the value of point at certain commonly referenced POSITIONs.
5149 POSITION can be one of the following symbols:
5151 bol -- beginning of line
5153 bod -- beginning of defun
5154 boi -- back to indentation
5155 eoi -- last whitespace on line
5156 ionl -- indentation of next line
5157 iopl -- indentation of previous line
5158 bonl -- beginning of next line
5159 bopl -- beginning of previous line
5161 This function does not modify point or mark."
5162 (or (and (eq 'quote (car-safe position))
5163 (null (cddr position)))
5164 (error "ERROR: Bad buffer position requested: %s" position))
5165 (setq position (nth 1 position))
5166 `(let ((here (point)))
5168 ((eq position 'bol) '((beginning-of-line)))
5169 ((eq position 'eol) '((end-of-line)))
5170 ((eq position 'bod) '((save-match-data
5171 (vhdl-beginning-of-defun))))
5172 ((eq position 'boi) '((back-to-indentation)))
5173 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5174 ((eq position 'bonl) '((forward-line 1)))
5175 ((eq position 'bopl) '((forward-line -1)))
5176 ((eq position 'iopl)
5178 (back-to-indentation)))
5179 ((eq position 'ionl)
5181 (back-to-indentation)))
5182 (t (error "ERROR: Unknown buffer position requested: %s" position))
5187 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5188 ;; doesn't hurt for v19
5192 (defmacro vhdl-safe (&rest body)
5193 "Safely execute BODY, return nil if an error occurred."
5194 `(condition-case nil
5198 (defmacro vhdl-add-syntax (symbol &optional relpos)
5199 "A simple macro to append the syntax in SYMBOL to the syntax list.
5200 Try to increase performance by using this macro."
5201 `(setq vhdl-syntactic-context
5202 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5204 (defmacro vhdl-has-syntax (symbol)
5205 "A simple macro to return check the syntax list.
5206 Try to increase performance by using this macro."
5207 `(assoc ,symbol vhdl-syntactic-context))
5209 ;; Syntactic element offset manipulation:
5211 (defun vhdl-read-offset (langelem)
5212 "Read new offset value for LANGELEM from minibuffer.
5213 Return a valid value only."
5214 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5215 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5217 offset input interned)
5219 (setq input (read-string prompt oldoff)
5220 offset (cond ((string-equal "+" input) '+)
5221 ((string-equal "-" input) '-)
5222 ((string-equal "++" input) '++)
5223 ((string-equal "--" input) '--)
5224 ((string-match "^-?[0-9]+$" input)
5225 (string-to-number input))
5226 ((fboundp (setq interned (intern input)))
5228 ((boundp interned) interned)
5229 ;; error, but don't signal one, keep trying
5230 ;; to read an input value
5232 (setq prompt errmsg)
5236 (defun vhdl-set-offset (symbol offset &optional add-p)
5237 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5238 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5239 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5240 `vhdl-offsets-alist' if it doesn't already appear there."
5243 (intern (completing-read
5244 (concat "Syntactic symbol to change"
5245 (if current-prefix-arg " or add" "")
5250 (cons (format "%s" (car langelem)) nil)))
5252 nil (not current-prefix-arg)
5253 ;; initial contents tries to be the last element
5254 ;; on the syntactic analysis list for the current
5256 (let* ((syntax (vhdl-get-syntactic-context))
5257 (len (length syntax))
5258 (ic (format "%s" (car (nth (1- len) syntax)))))
5261 (offset (vhdl-read-offset langelem)))
5262 (list langelem offset current-prefix-arg)))
5263 ;; sanity check offset
5271 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5273 (let ((entry (assq symbol vhdl-offsets-alist)))
5275 (setcdr entry offset)
5277 (setq vhdl-offsets-alist
5278 (cons (cons symbol offset) vhdl-offsets-alist))
5279 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5280 (vhdl-keep-region-active))
5282 (defun vhdl-set-style (style &optional local)
5283 "Set `vhdl-mode' variables to use one of several different indentation styles.
5284 STYLE is a string representing the desired style and optional LOCAL is
5285 a flag which, if non-nil, means to make the style variables being
5286 changed buffer local, instead of the default, which is to set the
5287 global variables. Interactively, the flag comes from the prefix
5288 argument. The styles are chosen from the `vhdl-style-alist' variable."
5289 (interactive (list (completing-read "Use which VHDL indentation style? "
5290 vhdl-style-alist nil t)
5291 current-prefix-arg))
5292 (let ((vars (cdr (assoc style vhdl-style-alist))))
5294 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5295 ;; set all the variables
5299 (let ((var (car varentry))
5300 (val (cdr varentry)))
5302 (make-local-variable var))
5303 ;; special case for vhdl-offsets-alist
5304 (if (not (eq var 'vhdl-offsets-alist))
5306 ;; reset vhdl-offsets-alist to the default value first
5307 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5308 ;; now set the langelems that are different
5312 (let ((langelem (car langentry))
5313 (offset (cdr langentry)))
5314 (vhdl-set-offset langelem offset)
5319 (vhdl-keep-region-active))
5321 (defun vhdl-get-offset (langelem)
5322 "Get offset from LANGELEM which is a cons cell of the form:
5323 \(SYMBOL . RELPOS). The symbol is matched against
5324 vhdl-offsets-alist and the offset found there is either returned,
5325 or added to the indentation at RELPOS. If RELPOS is nil, then
5326 the offset is simply returned."
5327 (let* ((symbol (car langelem))
5328 (relpos (cdr langelem))
5329 (match (assq symbol vhdl-offsets-alist))
5330 (offset (cdr-safe match)))
5331 ;; offset can be a number, a function, a variable, or one of the
5335 (if vhdl-strict-syntax-p
5336 (error "ERROR: Don't know how to indent a %s" symbol)
5339 ((eq offset '+) (setq offset vhdl-basic-offset))
5340 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5341 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5342 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5343 ((and (not (numberp offset))
5345 (setq offset (funcall offset langelem)))
5346 ((not (numberp offset))
5347 (setq offset (eval offset)))
5350 (< relpos (vhdl-point 'bol)))
5357 ;; Syntactic support functions:
5359 (defun vhdl-in-comment-p ()
5360 "Check if point is in a comment."
5361 (eq (vhdl-in-literal) 'comment))
5363 (defun vhdl-in-string-p ()
5364 "Check if point is in a string."
5365 (eq (vhdl-in-literal) 'string))
5367 (defun vhdl-in-literal ()
5368 "Determine if point is in a VHDL literal."
5370 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5372 ((nth 3 state) 'string)
5373 ((nth 4 state) 'comment)
5374 ((vhdl-beginning-of-macro) 'pound)
5377 (defun vhdl-forward-comment (&optional direction)
5378 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5379 negative, skip forward otherwise."
5381 (if (and direction (< direction 0))
5384 (skip-chars-backward " \t\n")
5385 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5386 (goto-char (match-beginning 3))
5387 (skip-chars-backward " \t\n")))
5389 (skip-chars-forward " \t\n")
5390 (while (looking-at "--.*")
5391 (goto-char (match-end 0))
5392 (skip-chars-forward " \t\n"))))
5394 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5395 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5396 (defalias 'vhdl-forward-comment 'forward-comment))
5398 ;; This is the best we can do in Win-Emacs.
5399 (defun vhdl-win-il (&optional lim)
5400 "Determine if point is in a VHDL literal."
5402 (let* ((here (point))
5405 (lim (or lim (vhdl-point 'bod))))
5407 (while (< (point) here)
5409 (and (re-search-forward "--\\|[\"']"
5411 (buffer-substring (match-beginning 0) (match-end 0))))
5416 ;; looking at the opening of a VHDL style comment
5417 ((string= "--" match)
5418 (if (<= here (progn (end-of-line) (point))) 'comment))
5419 ;; looking at the opening of a double quote string
5420 ((string= "\"" match)
5421 (if (not (save-restriction
5422 ;; this seems to be necessary since the
5423 ;; re-search-forward will not work without it
5424 (narrow-to-region (point) here)
5426 ;; this regexp matches a double quote
5427 ;; which is preceded by an even number
5428 ;; of backslashes, including zero
5429 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5431 ;; looking at the opening of a single quote string
5432 ((string= "'" match)
5433 (if (not (save-restriction
5434 ;; see comments from above
5435 (narrow-to-region (point) here)
5437 ;; this matches a single quote which is
5438 ;; preceded by zero or two backslashes.
5439 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5446 (and (string-match "Win-Emacs" emacs-version)
5447 (fset 'vhdl-in-literal 'vhdl-win-il))
5449 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5450 ;; defined as lexical whitespace or comments. Search no farther back
5451 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5452 ;; used for backward skipping, (point-max) is used for forward
5455 (defun vhdl-forward-syntactic-ws (&optional lim)
5456 "Forward skip of syntactic whitespace."
5457 (let* ((here (point-max))
5458 (hugenum (point-max)))
5459 (while (/= here (point))
5461 (vhdl-forward-comment hugenum)
5462 ;; skip preprocessor directives
5463 (when (and (eq (char-after) ?#)
5464 (= (vhdl-point 'boi) (point)))
5465 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5466 (= (forward-line 1) 0)))
5468 (if lim (goto-char (min (point) lim)))))
5471 ;; This is the best we can do in Win-Emacs.
5472 (defun vhdl-win-fsws (&optional lim)
5473 "Forward skip syntactic whitespace for Win-Emacs."
5474 (let ((lim (or lim (point-max)))
5477 (skip-chars-forward " \t\n\r\f" lim)
5480 ((looking-at "--") (end-of-line))
5481 ;; none of the above
5482 (t (setq stop t))))))
5484 (and (string-match "Win-Emacs" emacs-version)
5485 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5487 (defun vhdl-beginning-of-macro (&optional lim)
5488 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5489 (let ((here (point)))
5491 (while (eq (char-before (1- (point))) ?\\)
5493 (back-to-indentation)
5494 (if (and (<= (point) here)
5495 (eq (char-after) ?#))
5500 (defun vhdl-backward-syntactic-ws (&optional lim)
5501 "Backward skip over syntactic whitespace."
5502 (let* ((here (point-min))
5503 (hugenum (- (point-max))))
5504 (while (/= here (point))
5506 (vhdl-forward-comment hugenum)
5507 (vhdl-beginning-of-macro))
5508 (if lim (goto-char (max (point) lim)))))
5510 ;; This is the best we can do in Win-Emacs.
5511 (defun vhdl-win-bsws (&optional lim)
5512 "Backward skip syntactic whitespace for Win-Emacs."
5513 (let ((lim (or lim (vhdl-point 'bod)))
5516 (skip-chars-backward " \t\n\r\f" lim)
5519 ((eq (vhdl-in-literal) 'comment)
5520 (skip-chars-backward "^-" lim)
5521 (skip-chars-backward "-" lim)
5522 (while (not (or (and (= (following-char) ?-)
5523 (= (char-after (1+ (point))) ?-))
5525 (skip-chars-backward "^-" lim)
5526 (skip-chars-backward "-" lim)))
5527 ;; none of the above
5528 (t (setq stop t))))))
5530 (and (string-match "Win-Emacs" emacs-version)
5531 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5533 ;; Functions to help finding the correct indentation column:
5535 (defun vhdl-first-word (point)
5536 "If the keyword at POINT is at boi, then return (current-column) at
5537 that point, else nil."
5539 (and (goto-char point)
5540 (eq (point) (vhdl-point 'boi))
5543 (defun vhdl-last-word (point)
5544 "If the keyword at POINT is at eoi, then return (current-column) at
5545 that point, else nil."
5547 (and (goto-char point)
5548 (save-excursion (or (eq (progn (forward-sexp) (point))
5550 (looking-at "\\s-*\\(--\\)?")))
5553 ;; Core syntactic evaluation functions:
5555 (defconst vhdl-libunit-re
5556 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5558 (defun vhdl-libunit-p ()
5562 (skip-chars-forward " \t\n")
5563 (not (looking-at "is\\b[^_]")))
5566 (and (not (looking-at "use\\b[^_]"))
5569 (vhdl-forward-syntactic-ws)
5570 (/= (following-char) ?:))))
5573 (defconst vhdl-defun-re
5574 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5576 (defun vhdl-defun-p ()
5578 (if (looking-at "block\\|process\\|procedural")
5579 ;; "block", "process", "procedural":
5582 (not (looking-at "end\\s-+\\w")))
5583 ;; "architecture", "configuration", "entity",
5584 ;; "package", "procedure", "function":
5587 (defun vhdl-corresponding-defun ()
5588 "If the word at the current position corresponds to a \"defun\"
5589 keyword, then return a string that can be used to find the
5590 corresponding \"begin\" keyword, else return nil."
5592 (and (looking-at vhdl-defun-re)
5594 (if (looking-at "block\\|process\\|procedural")
5595 ;; "block", "process". "procedural:
5596 (buffer-substring (match-beginning 0) (match-end 0))
5597 ;; "architecture", "configuration", "entity", "package",
5598 ;; "procedure", "function":
5601 (defconst vhdl-begin-fwd-re
5602 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5603 "A regular expression for searching forward that matches all known
5604 \"begin\" keywords.")
5606 (defconst vhdl-begin-bwd-re
5607 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5608 "A regular expression for searching backward that matches all known
5609 \"begin\" keywords.")
5611 (defun vhdl-begin-p (&optional lim)
5612 "Return t if we are looking at a real \"begin\" keyword.
5613 Assumes that the caller will make sure that we are looking at
5614 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5615 the middle of an identifier that just happens to contain a \"begin\"
5618 ;; "[architecture|case|configuration|entity|package|
5619 ;; procedure|function] ... is":
5620 ((and (looking-at "i")
5622 ;; Skip backward over first sexp (needed to skip over a
5623 ;; procedure interface list, and is harmless in other
5624 ;; situations). Note that we need "return" in the
5625 ;; following search list so that we don't run into
5626 ;; semicolons in the function interface list.
5629 (while (and (not foundp)
5631 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5633 (if (or (= (preceding-char) ?_)
5637 (and (/= (following-char) ?\;)
5638 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5641 ((looking-at "be\\|t")
5644 ((and (looking-at "e")
5645 ;; make sure that the "else" isn't inside a
5646 ;; conditional signal assignment.
5648 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5649 (or (eq (following-char) ?\;)
5652 ;; "block", "generate", "loop", "process", "procedural",
5653 ;; "units", "record":
5654 ((and (looking-at "bl\\|[glpur]")
5657 (not (looking-at "end\\s-+\\w"))))
5660 ((and (looking-at "c")
5663 (not (looking-at "end\\s-+\\w")))
5664 ;; look out for the dreaded entity class in an attribute
5666 (vhdl-backward-syntactic-ws lim)
5667 (/= (preceding-char) ?:)))
5669 ;; "for" (inside configuration declaration):
5670 ((and (looking-at "f")
5673 (not (looking-at "end\\s-+\\w")))
5674 (vhdl-has-syntax 'configuration))
5678 (defun vhdl-corresponding-mid (&optional lim)
5680 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5682 ((looking-at "then")
5687 (defun vhdl-corresponding-end (&optional lim)
5688 "If the word at the current position corresponds to a \"begin\"
5689 keyword, then return a vector containing enough information to find
5690 the corresponding \"end\" keyword, else return nil. The keyword to
5691 search forward for is aref 0. The column in which the keyword must
5692 appear is aref 1 or nil if any column is suitable.
5693 Assumes that the caller will make sure that we are not in the middle
5694 of an identifier that just happens to contain a \"begin\" keyword."
5696 (and (looking-at vhdl-begin-fwd-re)
5697 (/= (preceding-char) ?_)
5698 (not (vhdl-in-literal))
5701 ;; "is", "generate", "loop":
5702 ((looking-at "[igl]")
5704 (and (vhdl-last-word (point))
5705 (or (vhdl-first-word (point))
5707 (vhdl-beginning-of-statement-1 lim)
5708 (vhdl-backward-skip-label lim)
5709 (vhdl-first-word (point)))))))
5710 ;; "begin", "else", "for":
5711 ((looking-at "be\\|[ef]")
5713 (and (vhdl-last-word (point))
5714 (or (vhdl-first-word (point))
5716 (vhdl-beginning-of-statement-1 lim)
5717 (vhdl-backward-skip-label lim)
5718 (vhdl-first-word (point)))))))
5719 ;; "component", "units", "record":
5720 ((looking-at "[cur]")
5721 ;; The first end found will close the block
5723 ;; "block", "process", "procedural":
5724 ((looking-at "bl\\|p")
5726 (or (vhdl-first-word (point))
5728 (vhdl-beginning-of-statement-1 lim)
5729 (vhdl-backward-skip-label lim)
5730 (vhdl-first-word (point))))))
5733 (vector "elsif\\|else\\|end\\s-+if"
5734 (and (vhdl-last-word (point))
5735 (or (vhdl-first-word (point))
5737 (vhdl-beginning-of-statement-1 lim)
5738 (vhdl-backward-skip-label lim)
5739 (vhdl-first-word (point)))))))
5742 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5744 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5746 (defun vhdl-end-p (&optional lim)
5747 "Return t if we are looking at a real \"end\" keyword.
5748 Assumes that the caller will make sure that we are looking at
5749 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5750 the middle of an identifier that just happens to contain an \"end\"
5752 (or (not (looking-at "else"))
5753 ;; make sure that the "else" isn't inside a conditional signal
5756 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5757 (or (eq (following-char) ?\;)
5759 (vhdl-in-literal)))))
5761 (defun vhdl-corresponding-begin (&optional lim)
5762 "If the word at the current position corresponds to an \"end\"
5763 keyword, then return a vector containing enough information to find
5764 the corresponding \"begin\" keyword, else return nil. The keyword to
5765 search backward for is aref 0. The column in which the keyword must
5766 appear is aref 1 or nil if any column is suitable. The supplementary
5767 keyword to search forward for is aref 2 or nil if this is not
5768 required. If aref 3 is t, then the \"begin\" keyword may be found in
5769 the middle of a statement.
5770 Assumes that the caller will make sure that we are not in the middle
5771 of an identifier that just happens to contain an \"end\" keyword."
5774 (if (and (looking-at vhdl-end-fwd-re)
5775 (not (vhdl-in-literal))
5777 (if (looking-at "el")
5779 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5783 (skip-chars-forward " \t\n")
5786 ((looking-at "if\\b[^_]")
5787 (vector "else\\|elsif\\|if"
5788 (vhdl-first-word pos)
5791 ((looking-at "component\\b[^_]")
5792 (vector (buffer-substring (match-beginning 1)
5794 (vhdl-first-word pos)
5796 ;; "end units", "end record":
5797 ((looking-at "\\(units\\|record\\)\\b[^_]")
5798 (vector (buffer-substring (match-beginning 1)
5800 (vhdl-first-word pos)
5802 ;; "end block", "end process", "end procedural":
5803 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5804 (vector "begin" (vhdl-first-word pos) nil nil))
5806 ((looking-at "case\\b[^_]")
5807 (vector "case" (vhdl-first-word pos) "is" nil))
5809 ((looking-at "generate\\b[^_]")
5810 (vector "generate\\|for\\|if"
5811 (vhdl-first-word pos)
5814 ((looking-at "loop\\b[^_]")
5815 (vector "loop\\|while\\|for"
5816 (vhdl-first-word pos)
5818 ;; "end for" (inside configuration declaration):
5819 ((looking-at "for\\b[^_]")
5820 (vector "for" (vhdl-first-word pos) nil nil))
5823 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5824 (vhdl-first-word pos)
5825 ;; return an alist of (statement . keyword) mappings
5827 ;; "begin ... end [id]":
5829 ;; "architecture ... is ... begin ... end [id]":
5830 ("architecture" . "is")
5831 ;; "configuration ... is ... end [id]":
5832 ("configuration" . "is")
5833 ;; "entity ... is ... end [id]":
5835 ;; "package ... is ... end [id]":
5837 ;; "procedure ... is ... begin ... end [id]":
5838 ("procedure" . "is")
5839 ;; "function ... is ... begin ... end [id]":
5846 (defconst vhdl-leader-re
5847 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5849 (defun vhdl-end-of-leader ()
5851 (cond ((looking-at "block\\|process\\|procedural")
5854 (skip-chars-forward " \t\n")
5855 (= (following-char) ?\())
5858 (when (looking-at "[ \t\n]*is")
5859 (goto-char (match-end 0)))
5861 ((looking-at "component")
5863 (when (looking-at "[ \t\n]*is")
5864 (goto-char (match-end 0)))
5868 (skip-chars-forward " \t\n")
5869 (while (looking-at "[,:(]")
5871 (skip-chars-forward " \t\n"))
5876 (defconst vhdl-trailer-re
5877 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5879 (defconst vhdl-statement-fwd-re
5880 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5881 "A regular expression for searching forward that matches all known
5882 \"statement\" keywords.")
5884 (defconst vhdl-statement-bwd-re
5885 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5886 "A regular expression for searching backward that matches all known
5887 \"statement\" keywords.")
5889 (defun vhdl-statement-p (&optional lim)
5890 "Return t if we are looking at a real \"statement\" keyword.
5891 Assumes that the caller will make sure that we are looking at
5892 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5893 in the middle of an identifier that just happens to contain a
5894 \"statement\" keyword."
5896 ;; "for" ... "generate":
5897 ((and (looking-at "f")
5898 ;; Make sure it's the start of a parameter specification.
5901 (skip-chars-forward " \t\n")
5902 (looking-at "in\\b[^_]"))
5903 ;; Make sure it's not an "end for".
5906 (not (looking-at "end\\s-+\\w"))))
5908 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5909 ((and (looking-at "i")
5910 ;; Make sure it's not an "end if".
5913 (not (looking-at "end\\s-+\\w"))))
5915 ;; "while" ... "loop":
5920 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5921 "Regexp describing a case statement alternative key.")
5923 (defun vhdl-case-alternative-p (&optional lim)
5924 "Return t if we are looking at a real case alternative.
5925 Assumes that the caller will make sure that we are looking at
5926 vhdl-case-alternative-re, and are not inside a literal, and that
5927 we are not in the middle of an identifier that just happens to
5928 contain a \"when\" keyword."
5931 (while (and (not foundp)
5932 (re-search-backward ";\\|<=" lim 'move))
5933 (if (or (= (preceding-char) ?_)
5937 (or (eq (following-char) ?\;)
5941 ;; Core syntactic movement functions:
5943 (defconst vhdl-b-t-b-re
5944 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5946 (defun vhdl-backward-to-block (&optional lim)
5947 "Move backward to the previous \"begin\" or \"end\" keyword."
5949 (while (and (not foundp)
5950 (re-search-backward vhdl-b-t-b-re lim 'move))
5951 (if (or (= (preceding-char) ?_)
5956 ((and (looking-at vhdl-begin-fwd-re)
5957 (/= (preceding-char) ?_)
5959 (setq foundp 'begin))
5961 ((and (looking-at vhdl-end-fwd-re)
5962 (/= (preceding-char) ?_)
5970 (defun vhdl-forward-sexp (&optional count lim)
5971 "Move forward across one balanced expression (sexp).
5972 With COUNT, do it that many times."
5974 (let ((count (or count 1))
5975 (case-fold-search t)
5980 (skip-chars-forward " \t\n")
5981 ;; Check for an unbalanced "end" keyword
5982 (if (and (looking-at vhdl-end-fwd-re)
5983 (/= (preceding-char) ?_)
5984 (not (vhdl-in-literal))
5986 (not (looking-at "else")))
5988 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5989 ;; If the current keyword is a "begin" keyword, then find the
5990 ;; corresponding "end" keyword.
5991 (if (setq end-vec (vhdl-corresponding-end lim))
5993 ;; end-re is the statement keyword to search for
5995 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5996 ;; column is either the statement keyword target column
5998 (column (aref end-vec 1))
5999 (eol (vhdl-point 'eol))
6000 foundp literal placeholder)
6001 ;; Look for the statement keyword.
6002 (while (and (not foundp)
6003 (re-search-forward end-re nil t)
6004 (setq placeholder (match-end 1))
6005 (goto-char (match-beginning 0)))
6006 ;; If we are in a literal, or not in the right target
6007 ;; column and not on the same line as the begin, then
6010 (/= (current-indentation) column)
6012 (= (preceding-char) ?_)
6013 (setq literal (vhdl-in-literal)))
6014 (if (eq literal 'comment)
6017 ;; An "else" keyword corresponds to both the opening brace
6018 ;; of the following sexp and the closing brace of the
6020 (if (not (looking-at "else"))
6021 (goto-char placeholder))
6025 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6027 ;; If the current keyword is not a "begin" keyword, then just
6028 ;; perform the normal forward-sexp.
6031 (setq count (1- count))
6033 (setq target (point)))
6037 (defun vhdl-backward-sexp (&optional count lim)
6038 "Move backward across one balanced expression (sexp).
6039 With COUNT, do it that many times. LIM bounds any required backward
6042 (let ((count (or count 1))
6043 (case-fold-search t)
6047 ;; Perform the normal backward-sexp, unless we are looking at
6048 ;; "else" - an "else" keyword corresponds to both the opening brace
6049 ;; of the following sexp and the closing brace of the previous sexp.
6050 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6051 (/= (preceding-char) ?_)
6052 (not (vhdl-in-literal)))
6055 (if (and (looking-at vhdl-begin-fwd-re)
6056 (/= (preceding-char) ?_)
6057 (not (vhdl-in-literal))
6059 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6060 ;; If the current keyword is an "end" keyword, then find the
6061 ;; corresponding "begin" keyword.
6062 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6063 (/= (preceding-char) ?_))
6065 ;; begin-re is the statement keyword to search for
6067 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6068 ;; column is either the statement keyword target column
6070 (column (aref begin-vec 1))
6071 ;; internal-p controls where the statement keyword can
6073 (internal-p (aref begin-vec 3))
6074 (last-backward (point)) last-forward
6075 foundp literal keyword)
6076 ;; Look for the statement keyword.
6077 (while (and (not foundp)
6078 (re-search-backward begin-re lim t)
6080 (buffer-substring (match-beginning 1)
6082 ;; If we are in a literal or in the wrong column,
6085 (and (/= (current-indentation) column)
6086 ;; possibly accept current-column as
6087 ;; well as current-indentation.
6088 (or (not internal-p)
6089 (/= (current-column) column))))
6090 (= (preceding-char) ?_)
6093 ;; If there is a supplementary keyword, then
6094 ;; search forward for it.
6095 (if (and (setq begin-re (aref begin-vec 2))
6096 (or (not (listp begin-re))
6097 ;; If begin-re is an alist, then find the
6098 ;; element corresponding to the actual
6099 ;; keyword that we found.
6102 (assoc keyword begin-re))
6104 (setq begin-re (cdr begin-re))))))
6107 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6109 (setq last-forward (point))
6110 ;; Look for the supplementary keyword
6111 ;; (bounded by the backward search start
6113 (while (and (not foundp)
6114 (re-search-forward begin-re
6116 (goto-char (match-beginning 1)))
6117 ;; If we are in a literal, then try again.
6118 (if (or (= (preceding-char) ?_)
6121 (if (eq literal 'comment)
6123 (min (vhdl-point 'eol) last-backward))
6125 ;; We have found the supplementary keyword.
6126 ;; Save the position of the keyword in foundp.
6127 (setq foundp (point)))
6130 ;; If the supplementary keyword was found, then
6131 ;; move point to the supplementary keyword.
6133 ;; If there was no supplementary keyword, then
6134 ;; point is already at the statement keyword.
6136 ) ; end of the search for the statement keyword
6138 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6140 (setq count (1- count))
6142 (setq target (point)))
6146 (defun vhdl-backward-up-list (&optional count limit)
6147 "Move backward out of one level of blocks.
6148 With argument, do this that many times."
6150 (let ((count (or count 1))
6154 (if (looking-at vhdl-defun-re)
6155 (error "ERROR: Unbalanced blocks"))
6156 (vhdl-backward-to-block limit)
6157 (setq count (1- count)))
6158 (setq target (point)))
6159 (goto-char target)))
6161 (defun vhdl-end-of-defun (&optional count)
6162 "Move forward to the end of a VHDL defun."
6164 (let ((case-fold-search t))
6165 (vhdl-beginning-of-defun)
6166 (if (not (looking-at "block\\|process\\|procedural"))
6167 (re-search-forward "\\bis\\b"))
6168 (vhdl-forward-sexp)))
6170 (defun vhdl-mark-defun ()
6171 "Put mark at end of this \"defun\", point at beginning."
6173 (let ((case-fold-search t))
6175 (vhdl-beginning-of-defun)
6177 (if (not (looking-at "block\\|process\\|procedural"))
6178 (re-search-forward "\\bis\\b"))
6180 (exchange-point-and-mark)))
6182 (defun vhdl-beginning-of-libunit ()
6183 "Move backward to the beginning of a VHDL library unit.
6184 Returns the location of the corresponding begin keyword, unless search
6185 stops due to beginning or end of buffer.
6186 Note that if point is between the \"libunit\" keyword and the
6187 corresponding \"begin\" keyword, then that libunit will not be
6188 recognized, and the search will continue backwards. If point is
6189 at the \"begin\" keyword, then the defun will be recognized. The
6190 returned point is at the first character of the \"libunit\" keyword."
6191 (let ((last-forward (point))
6193 ;; Just in case we are actually sitting on the "begin"
6194 ;; keyword, allow for the keyword and an extra character,
6195 ;; as this will be used when looking forward for the
6197 (save-excursion (forward-word 1) (1+ (point))))
6198 foundp literal placeholder)
6199 ;; Find the "libunit" keyword.
6200 (while (and (not foundp)
6201 (re-search-backward vhdl-libunit-re nil 'move))
6202 ;; If we are in a literal, or not at a real libunit, then try again.
6203 (if (or (= (preceding-char) ?_)
6205 (not (vhdl-libunit-p)))
6207 ;; Find the corresponding "begin" keyword.
6208 (setq last-forward (point))
6209 (while (and (not foundp)
6210 (re-search-forward "\\bis\\b[^_]" last-backward t)
6211 (setq placeholder (match-beginning 0)))
6212 (if (or (= (preceding-char) ?_)
6213 (setq literal (vhdl-in-literal)))
6214 ;; It wasn't a real keyword, so keep searching.
6215 (if (eq literal 'comment)
6217 (min (vhdl-point 'eol) last-backward))
6219 ;; We have found the begin keyword, loop will exit.
6220 (setq foundp placeholder)))
6221 ;; Go back to the libunit keyword
6222 (goto-char last-forward)))
6225 (defun vhdl-beginning-of-defun (&optional count)
6226 "Move backward to the beginning of a VHDL defun.
6227 With argument, do it that many times.
6228 Returns the location of the corresponding begin keyword, unless search
6229 stops due to beginning or end of buffer."
6230 ;; Note that if point is between the "defun" keyword and the
6231 ;; corresponding "begin" keyword, then that defun will not be
6232 ;; recognized, and the search will continue backwards. If point is
6233 ;; at the "begin" keyword, then the defun will be recognized. The
6234 ;; returned point is at the first character of the "defun" keyword.
6236 (let ((count (or count 1))
6237 (case-fold-search t)
6238 (last-forward (point))
6242 (goto-char last-forward)
6243 (let ((last-backward
6244 ;; Just in case we are actually sitting on the "begin"
6245 ;; keyword, allow for the keyword and an extra character,
6246 ;; as this will be used when looking forward for the
6248 (save-excursion (forward-word 1) (1+ (point))))
6249 begin-string literal)
6250 (while (and (not foundp)
6251 (re-search-backward vhdl-defun-re nil 'move))
6252 ;; If we are in a literal, then try again.
6253 (if (or (= (preceding-char) ?_)
6256 (if (setq begin-string (vhdl-corresponding-defun))
6257 ;; This is a real defun keyword.
6258 ;; Find the corresponding "begin" keyword.
6259 ;; Look for the begin keyword.
6261 ;; Save the search start point.
6262 (setq last-forward (point))
6263 (while (and (not foundp)
6264 (search-forward begin-string last-backward t))
6265 (if (or (= (preceding-char) ?_)
6267 (setq literal (vhdl-in-literal))))
6268 ;; It wasn't a real keyword, so keep searching.
6269 (if (eq literal 'comment)
6271 (min (vhdl-point 'eol) last-backward))
6273 ;; We have found the begin keyword, loop will exit.
6274 (setq foundp (match-beginning 0)))
6276 ;; Go back to the defun keyword
6277 (goto-char last-forward)) ; end search for begin keyword
6279 ) ; end of the search for the defun keyword
6281 (setq count (1- count))
6283 (vhdl-keep-region-active)
6286 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6287 "Go to the beginning of the innermost VHDL statement.
6288 With prefix arg, go back N - 1 statements. If already at the
6289 beginning of a statement then go to the beginning of the preceding
6290 one. If within a string or comment, or next to a comment (only
6291 whitespace between), move by sentences instead of statements.
6293 When called from a program, this function takes 3 optional args: the
6294 prefix arg, a buffer position limit which is the farthest back to
6295 search, and an argument indicating an interactive call."
6296 (interactive "p\np")
6297 (let ((count (or count 1))
6298 (case-fold-search t)
6299 (lim (or lim (point-min)))
6304 (setq state (parse-partial-sexp (point) here nil nil)))
6305 (if (and interactive
6308 (looking-at (concat "[ \t]*" comment-start-skip))))
6309 (forward-sentence (- count))
6311 (vhdl-beginning-of-statement-1 lim)
6312 (setq count (1- count))))
6313 ;; its possible we've been left up-buf of lim
6314 (goto-char (max (point) lim))
6316 (vhdl-keep-region-active))
6318 (defconst vhdl-e-o-s-re
6319 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6321 (defun vhdl-end-of-statement ()
6322 "Very simple implementation."
6324 (re-search-forward vhdl-e-o-s-re))
6326 (defconst vhdl-b-o-s-re
6327 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6328 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6330 (defun vhdl-beginning-of-statement-1 (&optional lim)
6331 "Move to the start of the current statement, or the previous
6332 statement if already at the beginning of one."
6333 (let ((lim (or lim (point-min)))
6337 ;; go backwards one balanced expression, but be careful of
6338 ;; unbalanced paren being reached
6339 (if (not (vhdl-safe (progn (backward-sexp) t)))
6341 (backward-up-list 1)
6343 (vhdl-forward-syntactic-ws here)
6345 (while (and (not donep)
6347 ;; look backwards for a statement boundary
6348 (re-search-backward vhdl-b-o-s-re lim 'move))
6349 (if (or (= (preceding-char) ?_)
6353 ;; If we are looking at an open paren, then stop after it
6354 ((eq (following-char) ?\()
6356 (vhdl-forward-syntactic-ws here)
6358 ;; If we are looking at a close paren, then skip it
6359 ((eq (following-char) ?\))
6364 (progn (goto-char pos)
6365 (vhdl-forward-syntactic-ws here)
6367 ;; If we are looking at a semicolon, then stop
6368 ((eq (following-char) ?\;)
6371 (vhdl-forward-syntactic-ws here)
6373 ;; If we are looking at a "begin", then stop
6374 ((and (looking-at vhdl-begin-fwd-re)
6375 (/= (preceding-char) ?_)
6377 ;; If it's a leader "begin", then find the
6379 (if (looking-at vhdl-leader-re)
6381 ;; set a default stop point at the begin
6383 ;; is the start point inside the leader area ?
6384 (goto-char (vhdl-end-of-leader))
6385 (vhdl-forward-syntactic-ws here)
6386 (if (< (point) here)
6387 ;; start point was not inside leader area
6388 ;; set stop point at word after leader
6389 (setq pos (point))))
6391 (vhdl-forward-syntactic-ws here)
6395 ;; If we are looking at a "statement", then stop
6396 ((and (looking-at vhdl-statement-fwd-re)
6397 (/= (preceding-char) ?_)
6398 (vhdl-statement-p nil))
6400 ;; If we are looking at a case alternative key, then stop
6401 ((and (looking-at vhdl-case-alternative-re)
6402 (vhdl-case-alternative-p lim))
6404 ;; set a default stop point at the when
6406 ;; is the start point inside the case alternative key ?
6407 (looking-at vhdl-case-alternative-re)
6408 (goto-char (match-end 0))
6409 (vhdl-forward-syntactic-ws here)
6410 (if (< (point) here)
6411 ;; start point was not inside the case alternative key
6412 ;; set stop point at word after case alternative keyleader
6413 (setq pos (point))))
6416 ;; Bogus find, continue
6421 ;; Defuns for calculating the current syntactic state:
6423 (defun vhdl-get-library-unit (bod placeholder)
6424 "If there is an enclosing library unit at BOD, with its \"begin\"
6425 keyword at PLACEHOLDER, then return the library unit type."
6426 (let ((here (vhdl-point 'bol)))
6428 (goto-char placeholder)
6429 (vhdl-safe (vhdl-forward-sexp 1 bod))
6434 ((looking-at "e") 'entity)
6435 ((looking-at "a") 'architecture)
6436 ((looking-at "c") 'configuration)
6441 (vhdl-forward-syntactic-ws here)
6442 (if (looking-at "body\\b[^_]")
6443 'package-body 'package))))))
6446 (defun vhdl-get-block-state (&optional lim)
6447 "Finds and records all the closest opens.
6448 LIM is the furthest back we need to search (it should be the
6449 previous libunit keyword)."
6450 (let ((here (point))
6451 (lim (or lim (point-min)))
6452 keyword sexp-start sexp-mid sexp-end
6453 preceding-sexp containing-sexp
6454 containing-begin containing-mid containing-paren)
6456 ;; Find the containing-paren, and use that as the limit
6457 (if (setq containing-paren
6459 (narrow-to-region lim (point))
6460 (vhdl-safe (scan-lists (point) -1 1))))
6461 (setq lim containing-paren))
6462 ;; Look backwards for "begin" and "end" keywords.
6463 (while (and (> (point) lim)
6464 (not containing-sexp))
6465 (setq keyword (vhdl-backward-to-block lim))
6467 ((eq keyword 'begin)
6468 ;; Found a "begin" keyword
6469 (setq sexp-start (point))
6470 (setq sexp-mid (vhdl-corresponding-mid lim))
6471 (setq sexp-end (vhdl-safe
6473 (vhdl-forward-sexp 1 lim) (point))))
6474 (if (and sexp-end (<= sexp-end here))
6475 ;; we want to record this sexp, but we only want to
6476 ;; record the last-most of any of them before here
6478 (setq preceding-sexp sexp-start))
6479 ;; we're contained in this sexp so put sexp-start on
6481 (setq containing-sexp sexp-start)
6482 (setq containing-mid sexp-mid)
6483 (setq containing-begin t)))
6485 ;; Found an "end" keyword
6487 (setq sexp-end (point))
6490 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6491 (progn (backward-sexp) (point))))
6492 ;; we want to record this sexp, but we only want to
6493 ;; record the last-most of any of them before here
6495 (setq preceding-sexp sexp-start)))
6497 ;; Check if the containing-paren should be the containing-sexp
6498 (if (and containing-paren
6499 (or (null containing-sexp)
6500 (< containing-sexp containing-paren)))
6501 (setq containing-sexp containing-paren
6503 containing-begin nil
6504 containing-mid nil))
6505 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6509 (defconst vhdl-s-c-a-re
6510 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6512 (defun vhdl-skip-case-alternative (&optional lim)
6513 "Skip forward over case/when bodies, with optional maximal
6514 limit. If no next case alternative is found, nil is returned and
6515 point is not moved."
6516 (let ((lim (or lim (point-max)))
6519 (while (and (< (point) lim)
6521 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6523 (not (vhdl-in-literal)))
6524 (/= (match-beginning 0) here))
6526 (goto-char (match-beginning 0))
6528 ((and (looking-at "case")
6529 (re-search-forward "\\bis[^_]" lim t))
6531 (vhdl-forward-sexp))
6539 (defun vhdl-backward-skip-label (&optional lim)
6540 "Skip backward over a label, with optional maximal
6541 limit. If label is not found, nil is returned and point
6543 (let ((lim (or lim (point-min)))
6546 (vhdl-backward-syntactic-ws lim)
6547 (and (eq (preceding-char) ?:)
6550 (setq placeholder (point))
6551 (looking-at vhdl-label-key))))
6552 (goto-char placeholder))
6555 (defun vhdl-forward-skip-label (&optional lim)
6556 "Skip forward over a label, with optional maximal
6557 limit. If label is not found, nil is returned and point
6559 (let ((lim (or lim (point-max))))
6560 (if (looking-at vhdl-label-key)
6562 (goto-char (match-end 0))
6563 (vhdl-forward-syntactic-ws lim)))
6566 (defun vhdl-get-syntactic-context ()
6567 "Guess the syntactic description of the current line of VHDL code."
6571 (let* ((indent-point (point))
6572 (case-fold-search t)
6573 vec literal containing-sexp preceding-sexp
6574 containing-begin containing-mid containing-leader
6575 char-before-ip char-after-ip begin-after-ip end-after-ip
6576 placeholder lim library-unit
6579 ;; Reset the syntactic context
6580 (setq vhdl-syntactic-context nil)
6583 ;; Move to the start of the previous library unit, and
6584 ;; record the position of the "begin" keyword.
6585 (setq placeholder (vhdl-beginning-of-libunit))
6586 ;; The position of the "libunit" keyword gives us a gross
6591 ;; If there is a previous library unit, and we are enclosed by
6592 ;; it, then set the syntax accordingly.
6594 (setq library-unit (vhdl-get-library-unit lim placeholder))
6595 (vhdl-add-syntax library-unit lim))
6597 ;; Find the surrounding state.
6598 (if (setq vec (vhdl-get-block-state lim))
6600 (setq containing-sexp (aref vec 0))
6601 (setq preceding-sexp (aref vec 1))
6602 (setq containing-begin (aref vec 2))
6603 (setq containing-mid (aref vec 3))
6606 ;; set the limit on the farthest back we need to search
6607 (setq lim (if containing-sexp
6609 (goto-char containing-sexp)
6610 ;; set containing-leader if required
6611 (if (looking-at vhdl-leader-re)
6612 (setq containing-leader (vhdl-end-of-leader)))
6616 ;; cache char before and after indent point, and move point to
6617 ;; the most likely position to perform the majority of tests
6618 (goto-char indent-point)
6619 (skip-chars-forward " \t")
6620 (setq literal (vhdl-in-literal))
6621 (setq char-after-ip (following-char))
6622 (setq begin-after-ip (and
6624 (looking-at vhdl-begin-fwd-re)
6626 (setq end-after-ip (and
6628 (looking-at vhdl-end-fwd-re)
6630 (vhdl-backward-syntactic-ws lim)
6631 (setq char-before-ip (preceding-char))
6632 (goto-char indent-point)
6633 (skip-chars-forward " \t")
6635 ;; now figure out syntactic qualities of the current line
6637 ;; CASE 1: in a string or comment.
6638 ((memq literal '(string comment))
6639 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6640 ;; CASE 2: Line is at top level.
6641 ((null containing-sexp)
6642 ;; Find the point to which indentation will be relative
6644 (if (null preceding-sexp)
6646 ;; no preceding-sexp -> use the preceding statement
6647 (vhdl-beginning-of-statement-1 lim)
6649 ;; if there is a preceding-sexp then indent relative to it
6650 (goto-char preceding-sexp)
6651 ;; if not at boi, then the block-opening keyword is
6652 ;; probably following a label, so we need a different
6654 (if (/= (point) (vhdl-point 'boi))
6656 (vhdl-beginning-of-statement-1 lim)))
6657 ;; v-b-o-s could have left us at point-min
6660 (vhdl-forward-syntactic-ws indent-point))
6661 (setq placeholder (point)))
6663 ;; CASE 2A : we are looking at a block-open
6665 (vhdl-add-syntax 'block-open placeholder))
6666 ;; CASE 2B: we are looking at a block-close
6668 (vhdl-add-syntax 'block-close placeholder))
6669 ;; CASE 2C: we are looking at a top-level statement
6671 (vhdl-backward-syntactic-ws lim)
6673 (= (preceding-char) ?\;)))
6674 (vhdl-add-syntax 'statement placeholder))
6675 ;; CASE 2D: we are looking at a top-level statement-cont
6677 (vhdl-beginning-of-statement-1 lim)
6678 ;; v-b-o-s could have left us at point-min
6681 (vhdl-forward-syntactic-ws indent-point))
6682 (vhdl-add-syntax 'statement-cont (point)))
6684 ;; CASE 3: line is inside parentheses. Most likely we are
6685 ;; either in a subprogram argument (interface) list, or a
6686 ;; continued expression containing parentheses.
6687 ((null containing-begin)
6688 (vhdl-backward-syntactic-ws containing-sexp)
6690 ;; CASE 3A: we are looking at the arglist closing paren
6691 ((eq char-after-ip ?\))
6692 (goto-char containing-sexp)
6693 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6694 ;; CASE 3B: we are looking at the first argument in an empty
6696 ((eq char-before-ip ?\()
6697 (goto-char containing-sexp)
6698 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6699 ;; CASE 3C: we are looking at an arglist continuation line,
6700 ;; but the preceding argument is on the same line as the
6701 ;; opening paren. This case includes multi-line
6702 ;; expression paren groupings.
6703 ((and (save-excursion
6704 (goto-char (1+ containing-sexp))
6705 (skip-chars-forward " \t")
6707 (not (looking-at "--")))
6709 (vhdl-beginning-of-statement-1 containing-sexp)
6710 (skip-chars-backward " \t(")
6711 (<= (point) containing-sexp)))
6712 (goto-char containing-sexp)
6713 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6714 ;; CASE 3D: we are looking at just a normal arglist
6715 ;; continuation line
6716 (t (vhdl-beginning-of-statement-1 containing-sexp)
6717 (vhdl-forward-syntactic-ws indent-point)
6718 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6720 ;; CASE 4: A block mid open
6721 ((and begin-after-ip
6722 (looking-at containing-mid))
6723 (goto-char containing-sexp)
6724 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6725 (if (looking-at vhdl-trailer-re)
6727 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6728 (vhdl-backward-skip-label (vhdl-point 'boi))
6729 (vhdl-add-syntax 'block-open (point)))
6730 ;; CASE 5: block close brace
6732 (goto-char containing-sexp)
6733 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6734 (if (looking-at vhdl-trailer-re)
6736 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6737 (vhdl-backward-skip-label (vhdl-point 'boi))
6738 (vhdl-add-syntax 'block-close (point)))
6739 ;; CASE 6: A continued statement
6740 ((and (/= char-before-ip ?\;)
6741 ;; check it's not a trailer begin keyword, or a begin
6742 ;; keyword immediately following a label.
6743 (not (and begin-after-ip
6744 (or (looking-at vhdl-trailer-re)
6746 (vhdl-backward-skip-label containing-sexp)))))
6747 ;; check it's not a statement keyword
6748 (not (and (looking-at vhdl-statement-fwd-re)
6749 (vhdl-statement-p)))
6750 ;; see if the b-o-s is before the indent point
6753 (vhdl-beginning-of-statement-1 containing-sexp)
6754 ;; If we ended up after a leader, then this will
6755 ;; move us forward to the start of the first
6756 ;; statement. Note that a containing sexp here is
6757 ;; always a keyword, not a paren, so this will
6758 ;; have no effect if we hit the containing-sexp.
6759 (vhdl-forward-syntactic-ws indent-point)
6760 (setq placeholder (point))))
6761 ;; check it's not a block-intro
6762 (/= placeholder containing-sexp)
6763 ;; check it's not a case block-intro
6765 (goto-char placeholder)
6766 (or (not (looking-at vhdl-case-alternative-re))
6767 (> (match-end 0) indent-point))))
6768 ;; Make placeholder skip a label, but only if it puts us
6769 ;; before the indent point at the start of a line.
6770 (let ((new placeholder))
6771 (if (and (> indent-point
6773 (goto-char placeholder)
6774 (vhdl-forward-skip-label indent-point)
6775 (setq new (point))))
6778 (eq new (progn (back-to-indentation) (point)))))
6779 (setq placeholder new)))
6780 (vhdl-add-syntax 'statement-cont placeholder)
6782 (vhdl-add-syntax 'block-open)))
6783 ;; Statement. But what kind?
6784 ;; CASE 7: A case alternative key
6785 ((and (looking-at vhdl-case-alternative-re)
6786 (vhdl-case-alternative-p containing-sexp))
6787 ;; for a case alternative key, we set relpos to the first
6788 ;; non-whitespace char on the line containing the "case"
6790 (goto-char containing-sexp)
6791 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6792 (if (looking-at vhdl-trailer-re)
6793 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6794 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6795 ;; CASE 8: statement catchall
6797 ;; we know its a statement, but we need to find out if it is
6798 ;; the first statement in a block
6799 (if containing-leader
6800 (goto-char containing-leader)
6801 (goto-char containing-sexp)
6802 ;; Note that a containing sexp here is always a keyword,
6803 ;; not a paren, so skip over the keyword.
6805 ;; move to the start of the first statement
6806 (vhdl-forward-syntactic-ws indent-point)
6807 (setq placeholder (point))
6808 ;; we want to ignore case alternatives keys when skipping forward
6810 (while (looking-at vhdl-case-alternative-re)
6811 (setq incase-p (point))
6812 ;; we also want to skip over the body of the
6813 ;; case/when statement if that doesn't put us at
6814 ;; after the indent-point
6815 (while (vhdl-skip-case-alternative indent-point))
6816 ;; set up the match end
6817 (looking-at vhdl-case-alternative-re)
6818 (goto-char (match-end 0))
6819 ;; move to the start of the first case alternative statement
6820 (vhdl-forward-syntactic-ws indent-point)
6821 (setq placeholder (point)))
6823 ;; CASE 8A: we saw a case/when statement so we must be
6824 ;; in a switch statement. find out if we are at the
6825 ;; statement just after a case alternative key
6827 (= (point) indent-point))
6828 ;; relpos is the "when" keyword
6829 (vhdl-add-syntax 'statement-case-intro incase-p))
6830 ;; CASE 8B: any old statement
6831 ((< (point) indent-point)
6832 ;; relpos is the first statement of the block
6833 (vhdl-add-syntax 'statement placeholder)
6835 (vhdl-add-syntax 'block-open)))
6836 ;; CASE 8C: first statement in a block
6838 (goto-char containing-sexp)
6839 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6840 (if (looking-at vhdl-trailer-re)
6841 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6842 (vhdl-backward-skip-label (vhdl-point 'boi))
6843 (vhdl-add-syntax 'statement-block-intro (point))
6845 (vhdl-add-syntax 'block-open)))
6849 ;; now we need to look at any modifiers
6850 (goto-char indent-point)
6851 (skip-chars-forward " \t")
6852 (if (looking-at "--")
6853 (vhdl-add-syntax 'comment))
6854 (if (eq literal 'pound)
6855 (vhdl-add-syntax 'cpp-macro))
6856 ;; return the syntax
6857 vhdl-syntactic-context))))
6859 ;; Standard indentation line-ups:
6861 (defun vhdl-lineup-arglist (langelem)
6862 "Lineup the current arglist line with the arglist appearing just
6863 after the containing paren which starts the arglist."
6865 (let* ((containing-sexp
6867 ;; arglist-cont-nonempty gives relpos ==
6868 ;; to boi of containing-sexp paren. This
6869 ;; is good when offset is +, but bad
6870 ;; when it is vhdl-lineup-arglist, so we
6871 ;; have to special case a kludge here.
6872 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6875 (backward-up-list 1)
6876 (skip-chars-forward " \t" (vhdl-point 'eol)))
6877 (goto-char (cdr langelem)))
6879 (cs-curcol (save-excursion
6880 (goto-char (cdr langelem))
6884 (looking-at "[ \t]*)"))
6885 (progn (goto-char (match-end 0))
6888 (vhdl-forward-syntactic-ws)
6889 (- (current-column) cs-curcol))
6890 (goto-char containing-sexp)
6892 (let ((eol (vhdl-point 'eol))
6895 (skip-chars-forward " \t")
6897 (vhdl-forward-syntactic-ws)
6900 (- (current-column) cs-curcol)
6903 (defun vhdl-lineup-arglist-intro (langelem)
6904 "Lineup an arglist-intro line to just after the open paren."
6906 (let ((cs-curcol (save-excursion
6907 (goto-char (cdr langelem))
6909 (ce-curcol (save-excursion
6911 (backward-up-list 1)
6912 (skip-chars-forward " \t" (vhdl-point 'eol))
6914 (- ce-curcol cs-curcol -1))))
6916 (defun vhdl-lineup-comment (langelem)
6917 "Support old behavior for comment indentation. We look at
6918 vhdl-comment-only-line-offset to decide how to indent comment
6921 (back-to-indentation)
6922 ;; at or to the right of comment-column
6923 (if (>= (current-column) comment-column)
6924 (vhdl-comment-indent)
6925 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6927 (or (car-safe vhdl-comment-only-line-offset)
6928 vhdl-comment-only-line-offset)
6929 (or (cdr-safe vhdl-comment-only-line-offset)
6930 (car-safe vhdl-comment-only-line-offset)
6931 -1000 ;jam it against the left side
6934 (defun vhdl-lineup-statement-cont (langelem)
6935 "Line up statement-cont after the assignment operator."
6937 (let* ((relpos (cdr langelem))
6938 (assignp (save-excursion
6939 (goto-char (vhdl-point 'boi))
6940 (and (re-search-forward "\\(<\\|:\\)="
6941 (vhdl-point 'eol) t)
6942 (- (point) (vhdl-point 'boi)))))
6947 (while (and (not foundp)
6948 (< (point) (vhdl-point 'eol)))
6949 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6950 (if (vhdl-in-literal)
6952 (if (= (preceding-char) ?\()
6953 ;; skip over any parenthesized expressions
6954 (goto-char (min (vhdl-point 'eol)
6955 (scan-lists (point) 1 1)))
6956 ;; found an assignment operator (not at eol)
6957 (setq foundp (not (looking-at "\\s-*$"))))))
6959 ;; there's no assignment operator on the line
6961 ;; calculate indentation column after assign and ws, unless
6962 ;; our line contains an assignment operator
6966 (skip-chars-forward " \t")
6968 (- (current-column) assignp curcol))
6971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6972 ;; Progress reporting
6974 (defvar vhdl-progress-info nil
6975 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6977 (defun vhdl-update-progress-info (string pos)
6978 "Update progress information."
6979 (when (and vhdl-progress-info (not noninteractive)
6980 (< vhdl-progress-interval
6981 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6982 (let ((delta (- (aref vhdl-progress-info 1)
6983 (aref vhdl-progress-info 0))))
6985 (message (concat string "... (100%s)") "%")
6986 (message (concat string "... (%2d%s)")
6987 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6989 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6992 ;; Indentation commands
6994 (defun vhdl-electric-tab (&optional prefix-arg)
6995 "If preceeding character is part of a word or a paren then hippie-expand,
6996 else if right of non whitespace on line then insert tab,
6997 else if last command was a tab or return then dedent one step or if a comment
6998 toggle between normal indent and inline comment indent,
6999 else indent `correctly'."
7001 (vhdl-prepare-search-2
7004 ((= (char-syntax (preceding-char)) ?w)
7005 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7007 (hippie-expand-only-buffers
7008 (or (and (boundp 'hippie-expand-only-buffers)
7009 hippie-expand-only-buffers)
7011 (vhdl-expand-abbrev prefix-arg)))
7012 ;; expand parenthesis
7013 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7014 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7016 (vhdl-expand-paren prefix-arg)))
7018 ((> (current-column) (current-indentation))
7020 ;; toggle comment indent
7021 ((and (looking-at "--")
7022 (or (eq last-command 'vhdl-electric-tab)
7023 (eq last-command 'vhdl-electric-return)))
7024 (cond ((= (current-indentation) 0) ; no indent
7026 (indent-according-to-mode))
7027 ((< (current-indentation) comment-column) ; normal indent
7028 (indent-to comment-column)
7029 (indent-according-to-mode))
7030 (t ; inline comment indent
7031 (delete-region (line-beginning-position) (point)))))
7033 ((and (>= (current-indentation) vhdl-basic-offset)
7034 (or (eq last-command 'vhdl-electric-tab)
7035 (eq last-command 'vhdl-electric-return)))
7036 (backward-delete-char-untabify vhdl-basic-offset nil))
7038 (t (indent-according-to-mode)))
7039 (setq this-command 'vhdl-electric-tab)))
7041 (defun vhdl-electric-return ()
7042 "newline-and-indent or indent-new-comment-line if in comment and preceding
7043 character is a space."
7045 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7046 (indent-new-comment-line)
7047 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7048 (vhdl-fix-case-word -1))
7049 (newline-and-indent)))
7051 (defun vhdl-indent-line ()
7052 "Indent the current line as VHDL code. Returns the amount of
7053 indentation change."
7055 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7056 (pos (- (point-max) (point)))
7059 ;; indent syntax-based
7060 (if (and (eq (caar syntax) 'comment)
7061 (>= (vhdl-get-offset (car syntax)) comment-column))
7062 ;; special case: comments at or right of comment-column
7063 (vhdl-get-offset (car syntax))
7064 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7065 ;; indent like previous nonblank line
7066 (save-excursion (beginning-of-line)
7067 (re-search-backward "^[^\n]" nil t)
7068 (current-indentation))))
7069 (shift-amt (- indent (current-indentation))))
7070 (and vhdl-echo-syntactic-information-p
7071 (message "syntax: %s, indent= %d" syntax indent))
7072 (unless (zerop shift-amt)
7073 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7076 (if (< (point) (vhdl-point 'boi))
7077 (back-to-indentation)
7078 ;; If initial point was within line's indentation, position after
7079 ;; the indentation. Else stay at same point in text.
7080 (when (> (- (point-max) pos) (point))
7081 (goto-char (- (point-max) pos))))
7082 (run-hooks 'vhdl-special-indent-hook)
7083 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7086 (defun vhdl-indent-region (beg end column)
7087 "Indent region as VHDL code.
7088 Adds progress reporting to `indent-region'."
7089 (interactive "r\nP")
7090 (when vhdl-progress-interval
7091 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7092 (count-lines (point-min) end) 0)))
7093 (indent-region beg end column)
7094 (when vhdl-progress-interval (message "Indenting...done"))
7095 (setq vhdl-progress-info nil))
7097 (defun vhdl-indent-buffer ()
7098 "Indent whole buffer as VHDL code.
7099 Calls `indent-region' for whole buffer and adds progress reporting."
7101 (vhdl-indent-region (point-min) (point-max) nil))
7103 (defun vhdl-indent-group ()
7104 "Indent group of lines between empty lines."
7106 (let ((beg (save-excursion
7107 (if (re-search-backward vhdl-align-group-separate nil t)
7109 (point-min-marker))))
7110 (end (save-excursion
7111 (if (re-search-forward vhdl-align-group-separate nil t)
7113 (point-max-marker)))))
7114 (vhdl-indent-region beg end nil)))
7116 (defun vhdl-indent-sexp (&optional endpos)
7117 "Indent each line of the list starting just after point.
7118 If optional arg ENDPOS is given, indent each line, stopping when
7119 ENDPOS is encountered."
7123 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7124 (indent-region beg end nil))))
7126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7127 ;; Miscellaneous commands
7129 (defun vhdl-show-syntactic-information ()
7130 "Show syntactic information for current line."
7132 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7133 (vhdl-keep-region-active))
7135 ;; Verification and regression functions:
7137 (defun vhdl-regress-line (&optional arg)
7138 "Check syntactic information for current line."
7140 (let ((expected (save-excursion
7142 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7144 (read (current-buffer)))))
7145 (actual (vhdl-get-syntactic-context))
7147 ;; remove the library unit symbols
7151 (if (memq (car elt) '(entity configuration package
7152 package-body architecture))
7154 (setq expurgated (append expurgated (list elt))))))
7156 (if (and (not arg) expected (listp expected))
7157 (if (not (equal expected expurgated))
7158 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7161 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7163 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7164 (delete-region (point) (line-end-position)))
7166 (insert (format "%s" expurgated))))))
7167 (vhdl-keep-region-active))
7170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7171 ;;; Alignment, whitespace fixup, beautifying
7172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7174 (defconst vhdl-align-alist
7176 ;; after some keywords
7177 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7178 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7180 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7181 ;; after direction specifications
7182 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7183 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7184 ;; before "==", ":=", "=>", and "<="
7185 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7186 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7187 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7188 ;; before some keywords
7189 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7190 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7191 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7192 ;; before "=>" since "when/else ... =>" can occur
7193 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7195 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7196 It is searched in order. If REGEXP is found anywhere in the first
7197 line of a region to be aligned, ALIGN-PATTERN will be used for that
7198 region. ALIGN-PATTERN must include the whitespace to be expanded or
7199 contracted. It may also provide regexps for the text surrounding the
7200 whitespace. SUBEXP specifies which sub-expression of
7201 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7206 (defvar vhdl-align-try-all-clauses t
7207 "If REGEXP is not found on the first line of the region that clause
7208 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7210 (defun vhdl-do-group (function &optional spacing)
7211 "Apply FUNCTION on group of lines between empty lines."
7213 ;; search for group beginning
7214 ((beg (save-excursion
7215 (if (re-search-backward vhdl-align-group-separate nil t)
7216 (progn (beginning-of-line 2) (back-to-indentation) (point))
7218 ;; search for group end
7219 (end (save-excursion
7220 (if (re-search-forward vhdl-align-group-separate nil t)
7221 (progn (beginning-of-line) (point))
7224 (funcall function beg end spacing)))
7226 (defun vhdl-do-list (function &optional spacing)
7227 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7231 ;; search for beginning of balanced group of parentheses
7232 (setq beg (vhdl-re-search-backward "[()]" nil t))
7233 (while (looking-at ")")
7234 (forward-char) (backward-sexp)
7235 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7236 ;; search for end of balanced group of parentheses
7240 (goto-char (1+ beg))
7241 (skip-chars-forward " \t\n")
7242 (setq beg (point))))
7245 (funcall function beg end spacing)
7246 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7248 (defun vhdl-do-same-indent (function &optional spacing)
7249 "Apply FUNCTION to block of lines with same indent."
7250 (let ((indent (current-indentation))
7252 ;; search for first line with same indent
7254 (while (and (not (bobp))
7255 (or (looking-at "^\\s-*\\(--.*\\)?$")
7256 (= (current-indentation) indent)))
7257 (unless (looking-at "^\\s-*$")
7258 (back-to-indentation) (setq beg (point)))
7259 (beginning-of-line -0)))
7260 ;; search for last line with same indent
7262 (while (and (not (eobp))
7263 (or (looking-at "^\\s-*\\(--.*\\)?$")
7264 (= (current-indentation) indent)))
7265 (if (looking-at "^\\s-*$")
7266 (beginning-of-line 2)
7267 (beginning-of-line 2)
7268 (setq end (point)))))
7270 (funcall function beg end spacing)))
7272 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7273 "Attempt to align a range of lines based on the content of the
7274 lines. The definition of `alignment-list' determines the matching
7275 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7276 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7277 indentation is done before aligning."
7278 (interactive "r\np")
7279 (setq alignment-list (or alignment-list vhdl-align-alist))
7280 (setq spacing (or spacing 1))
7284 (setq end (point-marker))
7286 (setq bol (setq begin (progn (beginning-of-line) (point))))
7287 ; (untabify bol end)
7289 (indent-region bol end nil))))
7290 (let ((copy (copy-alist alignment-list)))
7291 (vhdl-prepare-search-2
7296 (eol (save-excursion (progn (end-of-line) (point)))))
7297 (setq element (nth 0 copy))
7298 (when (and (or (and (listp (car element))
7299 (memq major-mode (car element)))
7300 (eq major-mode (car element)))
7301 (or vhdl-align-try-all-clauses
7302 (re-search-forward (car (cdr element)) eol t)))
7303 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7304 (car (cdr (cdr (cdr element)))) spacing))
7305 (setq copy (cdr copy))))))))
7307 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7308 "Align a range of lines from BEGIN to END. The regular expression
7309 MATCH must match exactly one field: the whitespace to be
7310 contracted/expanded. The alignment column will equal the
7311 rightmost column of the widest whitespace block. SPACING is
7312 the amount of extra spaces to add to the calculated maximum required.
7313 SPACING defaults to 1 so that at least one space is inserted after
7314 the token in MATCH."
7315 (setq spacing (or spacing 1))
7316 (setq substr (or substr 1))
7318 (let (distance (max 0) (lines 0) bol eol width)
7319 ;; Determine the greatest whitespace distance to the alignment
7322 (setq eol (progn (end-of-line) (point))
7323 bol (setq begin (progn (beginning-of-line) (point))))
7326 (when (and (re-search-forward match eol t)
7327 (not (vhdl-in-literal)))
7328 (setq distance (- (match-beginning substr) bol))
7329 (when (> distance max)
7330 (setq max distance))))
7333 eol (save-excursion (end-of-line) (point)))
7334 (setq lines (1+ lines)))
7335 ;; Now insert enough maxs to push each assignment operator to
7336 ;; the same column. We need to use 'lines' as a counter, since
7337 ;; the location of the mark may change
7338 (goto-char (setq bol begin))
7339 (setq eol (save-excursion (end-of-line) (point)))
7341 (when (and (re-search-forward match eol t)
7342 (not (vhdl-in-literal)))
7343 (setq width (- (match-end substr) (match-beginning substr)))
7344 (setq distance (- (match-beginning substr) bol))
7345 (goto-char (match-beginning substr))
7347 (insert-char ? (+ (- max distance) spacing)))
7351 eol (save-excursion (end-of-line) (point)))
7352 (setq lines (1- lines))))))
7354 (defun vhdl-align-region-groups (beg end &optional spacing
7355 no-message no-comments)
7356 "Align region, treat groups of lines separately."
7357 (interactive "r\nP")
7362 (setq orig (point-marker))
7365 (setq end (point-marker))
7368 (when vhdl-progress-interval
7369 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7370 (count-lines (point-min) end) 0))))
7371 (vhdl-fixup-whitespace-region beg end t)
7373 (if (not vhdl-align-groups)
7374 ;; align entire region
7375 (progn (vhdl-align-region-1 beg end spacing)
7377 (vhdl-align-inline-comment-region-1 beg end)))
7379 (while (and (< beg end)
7380 (re-search-forward vhdl-align-group-separate end t))
7381 (setq pos (point-marker))
7382 (vhdl-align-region-1 beg pos spacing)
7383 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7384 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7389 (vhdl-align-region-1 beg end spacing)
7390 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7391 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7392 (when vhdl-indent-tabs-mode
7395 (when vhdl-progress-interval (message "Aligning...done"))
7396 (setq vhdl-progress-info nil)))))
7398 (defun vhdl-align-region (beg end &optional spacing)
7399 "Align region, treat blocks with same indent and argument lists separately."
7400 (interactive "r\nP")
7401 (if (not vhdl-align-same-indent)
7402 ;; align entire region
7403 (vhdl-align-region-groups beg end spacing)
7404 ;; align blocks with same indent and argument lists
7408 (when vhdl-progress-interval
7409 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7410 (count-lines (point-min) end) 0)))
7412 (setq end (point-marker))
7414 (while (< (point) end)
7415 ;; is argument list opening?
7416 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7417 (point) (vhdl-point 'eol)))))
7418 ;; determine region for argument list
7419 (progn (goto-char cur-beg)
7421 (setq cur-end (point))
7422 (beginning-of-line 2))
7423 ;; determine region with same indent
7424 (setq indent (current-indentation))
7425 (setq cur-beg (point))
7426 (setq cur-end (vhdl-point 'bonl))
7427 (beginning-of-line 2)
7428 (while (and (< (point) end)
7429 (or (looking-at "^\\s-*\\(--.*\\)?$")
7430 (= (current-indentation) indent))
7432 (nth 0 (parse-partial-sexp
7433 (point) (vhdl-point 'eol)))) 0))
7434 (unless (looking-at "^\\s-*$")
7435 (setq cur-end (vhdl-point 'bonl)))
7436 (beginning-of-line 2)))
7438 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7439 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7440 (when vhdl-progress-interval (message "Aligning...done"))
7441 (setq vhdl-progress-info nil)))))
7443 (defun vhdl-align-group (&optional spacing)
7444 "Align group of lines between empty lines."
7446 (vhdl-do-group 'vhdl-align-region spacing))
7448 (defun vhdl-align-list (&optional spacing)
7449 "Align the lines of a list surrounded by a balanced group of parentheses."
7451 (vhdl-do-list 'vhdl-align-region-groups spacing))
7453 (defun vhdl-align-same-indent (&optional spacing)
7454 "Align block of lines with same indent."
7456 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7458 (defun vhdl-align-declarations (&optional spacing)
7459 "Align the lines within the declarative part of a design unit."
7462 (vhdl-prepare-search-2
7464 ;; search for declarative part
7465 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7466 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7468 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7469 (setq end (point)))))
7471 (vhdl-align-region-groups beg end spacing)
7472 (error "ERROR: Not within the declarative part of a design unit"))))
7474 (defun vhdl-align-buffer ()
7477 (vhdl-align-region (point-min) (point-max)))
7479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7480 ;; Align inline comments
7482 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7483 "Align inline comments in region."
7485 (let ((start-max comment-column)
7487 comment-list start-list tmp-list start length
7488 cur-start prev-start no-code)
7489 (setq spacing (or spacing 2))
7490 (vhdl-prepare-search-2
7492 ;; search for comment start positions and lengths
7493 (while (< (point) end)
7494 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7495 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7496 (not (save-excursion (goto-char (match-beginning 2))
7497 (vhdl-in-literal))))
7498 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7499 (setq length (- (match-end 2) (match-beginning 2)))
7500 (setq start-max (max start start-max))
7501 (setq length-max (max length length-max))
7502 (setq comment-list (cons (cons start length) comment-list)))
7503 (beginning-of-line 2))
7505 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7506 ;; reduce start positions
7507 (setq start-list (list (caar comment-list)))
7508 (setq comment-list (cdr comment-list))
7510 (unless (or (= (caar comment-list) (car start-list))
7511 (<= (+ (car start-list) (cdar comment-list))
7512 end-comment-column))
7513 (setq start-list (cons (caar comment-list) start-list)))
7514 (setq comment-list (cdr comment-list)))
7515 ;; align lines as nicely as possible
7517 (while (< (point) end)
7518 (setq cur-start nil)
7519 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7520 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7521 (not (save-excursion
7522 (goto-char (match-beginning 3))
7523 (vhdl-in-literal))))
7524 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7525 (>= (- (match-end 2) (match-beginning 2))
7527 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7528 (setq length (- (match-end 3) (match-beginning 3)))
7529 (setq no-code (= (match-beginning 1) (match-end 1)))
7530 ;; insert minimum whitespace
7531 (goto-char (match-end 2))
7532 (delete-region (match-beginning 2) (match-end 2))
7533 (insert-char ?\ spacing)
7534 (setq tmp-list start-list)
7535 ;; insert additional whitespace to align
7538 ;; align comment-only line to inline comment of previous line
7539 ((and no-code prev-start
7540 (<= length (- end-comment-column prev-start)))
7542 ;; align all comments at `start-max' if this is possible
7543 ((<= (+ start-max length-max) end-comment-column)
7545 ;; align at `comment-column' if possible
7546 ((and (<= start comment-column)
7547 (<= length (- end-comment-column comment-column)))
7549 ;; align at left-most possible start position otherwise
7551 (while (and tmp-list (< (car tmp-list) start))
7552 (setq tmp-list (cdr tmp-list)))
7554 (indent-to cur-start))
7555 (setq prev-start cur-start)
7556 (beginning-of-line 2))))))
7558 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7559 "Align inline comments within a region. Groups of code lines separated by
7560 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7561 (interactive "r\nP")
7566 (setq orig (point-marker))
7569 (setq end (point-marker))
7571 (unless no-message (message "Aligning inline comments..."))
7573 (if (not vhdl-align-groups)
7574 ;; align entire region
7575 (vhdl-align-inline-comment-region-1 beg end spacing)
7577 (while (and (< beg end)
7578 (re-search-forward vhdl-align-group-separate end t))
7579 (setq pos (point-marker))
7580 (vhdl-align-inline-comment-region-1 beg pos spacing)
7585 (vhdl-align-inline-comment-region-1 beg end spacing)))
7586 (when vhdl-indent-tabs-mode
7588 (unless no-message (message "Aligning inline comments...done")))))
7590 (defun vhdl-align-inline-comment-group (&optional spacing)
7591 "Align inline comments within a group of lines between empty lines."
7594 (let ((start (point))
7596 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7597 (point-marker) (point-max)))
7599 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7600 (point) (point-min)))
7602 (message "Aligning inline comments...")
7603 (vhdl-align-inline-comment-region-1 beg end)
7604 (when vhdl-indent-tabs-mode
7606 (message "Aligning inline comments...done"))))
7608 (defun vhdl-align-inline-comment-buffer ()
7609 "Align inline comments within buffer. Groups of code lines separated by
7610 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7612 (vhdl-align-inline-comment-region (point-min) (point-max)))
7614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7617 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7618 "Fixup whitespace in region. Surround operator symbols by one space,
7619 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7620 end of line, do nothing in comments and strings."
7622 (unless no-message (message "Fixing up whitespace..."))
7625 (setq end (point-marker))
7626 ;; have no space before and one space after `,' and ';'
7628 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7629 (if (match-string 1)
7630 (goto-char (match-end 1))
7631 (replace-match "\\3 " nil nil nil 3)))
7632 ;; have no space after `('
7634 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7635 (if (match-string 1)
7636 (goto-char (match-end 1))
7637 (replace-match "\\2")))
7638 ;; have no space before `)'
7640 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7641 (if (match-string 1)
7642 (goto-char (match-end 1))
7643 (replace-match "\\2")))
7644 ;; surround operator symbols by one space
7646 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7647 (if (match-string 1)
7648 (goto-char (match-end 1))
7649 (replace-match "\\3 \\4 \\5")
7650 (goto-char (match-end 2))))
7651 ;; eliminate multiple spaces and spaces at end of line
7653 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7654 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7655 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7656 (progn (replace-match "" nil nil) t))
7657 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7658 (progn (replace-match ";" nil nil) t))
7659 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7660 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7661 (progn (replace-match " " nil nil) t))
7662 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7663 (progn (replace-match " " nil nil) t))
7664 ; (re-search-forward "[^ \t-]+" end t))))
7665 (re-search-forward "[^ \t\"-]+" end t))))
7666 (unless no-message (message "Fixing up whitespace...done")))
7668 (defun vhdl-fixup-whitespace-buffer ()
7669 "Fixup whitespace in buffer. Surround operator symbols by one space,
7670 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7671 end of line, do nothing in comments."
7673 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7678 (defun vhdl-beautify-region (beg end)
7679 "Beautify region by applying indentation, whitespace fixup, alignment, and
7680 case fixing to a region. Calls functions `vhdl-indent-buffer',
7681 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7682 `vhdl-fix-case-buffer'."
7684 (setq end (save-excursion (goto-char end) (point-marker)))
7685 (vhdl-indent-region beg end nil)
7686 (let ((vhdl-align-groups t))
7687 (vhdl-align-region beg end))
7688 (vhdl-fix-case-region beg end))
7690 (defun vhdl-beautify-buffer ()
7691 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7692 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7695 (vhdl-beautify-region (point-min) (point-max))
7696 (when noninteractive (save-buffer)))
7698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7701 (defun vhdl-fill-region (beg end &optional arg)
7702 "Fill lines for a region of code."
7703 (interactive "r\np")
7706 (let ((margin (if arg (current-indentation) (current-column))))
7708 (setq end (point-marker))
7709 ;; remove inline comments, newlines and whitespace
7710 (vhdl-comment-kill-region beg end)
7711 (vhdl-comment-kill-inline-region beg end)
7712 (subst-char-in-region beg (1- end) ?\n ?\ )
7713 (vhdl-fixup-whitespace-region beg end)
7714 ;; wrap and end-comment-column
7716 (while (re-search-forward "\\s-" end t)
7717 (when(> (current-column) vhdl-end-comment-column)
7719 (when (re-search-backward "\\s-" beg t)
7720 (replace-match "\n")
7721 (indent-to margin)))))))
7723 (defun vhdl-fill-group ()
7724 "Fill group of lines between empty lines."
7726 (vhdl-do-group 'vhdl-fill-region))
7728 (defun vhdl-fill-list ()
7729 "Fill the lines of a list surrounded by a balanced group of parentheses."
7731 (vhdl-do-list 'vhdl-fill-region))
7733 (defun vhdl-fill-same-indent ()
7734 "Fill the lines of block of lines with same indent."
7736 (vhdl-do-same-indent 'vhdl-fill-region))
7739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7740 ;;; Code updating/fixing
7741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7744 ;; Sensitivity list update
7747 ;; - no sensitivity list is generated for processes with wait statements
7748 ;; - otherwise, do the following:
7749 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7750 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7751 ;; manually entered global signals)
7752 ;; 3. signals from 1. and 2. form the list of visible signals
7753 ;; 4. search for if/elsif conditions containing an event (sequential code)
7754 ;; 5. scan for strings that are within syntactical regions where signals are
7755 ;; read but not within sequential code, and that correspond to visible
7757 ;; 6. replace sensitivity list by list of signals from 5.
7759 (defun vhdl-update-sensitivity-list-process ()
7760 "Update sensitivity list of current process."
7763 (vhdl-prepare-search-2
7765 ;; look whether in process
7766 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7767 (equal (upcase (match-string 2)) "PROCESS")
7768 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7769 (error "ERROR: Not within a process")
7770 (message "Updating sensitivity list...")
7771 (vhdl-update-sensitivity-list)
7772 (message "Updating sensitivity list...done")))))
7774 (defun vhdl-update-sensitivity-list-buffer ()
7775 "Update sensitivity list of all processes in current buffer."
7778 (vhdl-prepare-search-2
7779 (goto-char (point-min))
7780 (message "Updating sensitivity lists...")
7781 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7782 (goto-char (match-beginning 0))
7783 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7784 (message "Updating sensitivity lists...done"))))
7786 (defun vhdl-update-sensitivity-list ()
7787 "Update sensitivity list."
7788 (let ((proc-beg (point))
7789 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7790 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7793 ;; search for wait statement (no sensitivity list allowed)
7794 ((progn (goto-char proc-mid)
7795 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7796 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7797 ;; combinational process (update sensitivity list)
7800 ;; scan for visible signals
7801 ((visible-list (vhdl-get-visible-signals))
7802 ;; define syntactic regions where signals are read
7804 '(;; right-hand side of signal/variable assignment
7805 ;; (special case: "<=" is relational operator in a condition)
7806 ((re-search-forward "[<:]=" proc-end t)
7807 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7809 ((re-search-forward "^\\s-*if\\>" proc-end t)
7810 (re-search-forward "\\<then\\>" proc-end t))
7812 ((re-search-forward "\\<elsif\\>" proc-end t)
7813 (re-search-forward "\\<then\\>" proc-end t))
7814 ;; while loop condition
7815 ((re-search-forward "^\\s-*while\\>" proc-end t)
7816 (re-search-forward "\\<loop\\>" proc-end t))
7817 ;; exit/next condition
7818 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7819 (re-search-forward ";" proc-end t))
7821 ((re-search-forward "\\<assert\\>" proc-end t)
7822 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7824 ((re-search-forward "^\\s-*case\\>" proc-end t)
7825 (re-search-forward "\\<is\\>" proc-end t))
7826 ;; parameter list of procedure call
7827 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7829 (progn (backward-char) (forward-sexp)
7830 (while (looking-at "(") (forward-sexp)) (point)))))
7831 name read-list sens-list signal-list
7832 sens-beg sens-end beg end margin)
7833 ;; scan for signals in old sensitivity list
7834 (goto-char proc-beg)
7835 (re-search-forward "\\<process\\>" proc-mid t)
7836 (if (not (looking-at "[ \t\n]*("))
7837 (setq sens-beg (point))
7838 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7839 (goto-char (match-end 1))
7841 (setq sens-end (1- (point)))
7842 (goto-char sens-beg)
7843 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7845 (cons (downcase (match-string 0)) sens-list))
7846 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7847 (setq signal-list (append visible-list sens-list))
7848 ;; search for sequential parts
7849 (goto-char proc-mid)
7850 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7851 (setq end (re-search-forward "\\<then\\>" proc-end t))
7852 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7856 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7857 (beginning-of-line)))
7858 ;; scan for signals read in process
7859 (while scan-regions-list
7860 (goto-char proc-mid)
7861 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7862 (setq end (eval (nth 1 (car scan-regions-list)))))
7864 (unless (or (vhdl-in-literal)
7865 (and seq-region-list
7866 (let ((tmp-list seq-region-list))
7867 (while (and tmp-list
7868 (< (point) (caar tmp-list)))
7869 (setq tmp-list (cdr tmp-list)))
7870 (and tmp-list (< (point) (cdar tmp-list))))))
7871 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7872 (setq name (match-string 1))
7873 (when (and (not (match-string 4)) ; not when formal parameter
7874 (not (and (match-string 3) ; not event attribute
7875 (not (member (downcase (match-string 3))
7876 '("event" "last_event" "transaction")))))
7877 (member (downcase name) signal-list))
7878 (unless (member-ignore-case name read-list)
7879 (setq read-list (cons name read-list))))
7880 (goto-char (match-end 1)))))
7881 (setq scan-regions-list (cdr scan-regions-list)))
7882 ;; update sensitivity list
7883 (goto-char sens-beg)
7885 (delete-region sens-beg sens-end)
7887 (insert " ()") (backward-char)))
7888 (setq read-list (sort read-list 'string<))
7890 (setq margin (current-column))
7891 (insert (car read-list))
7892 (setq read-list (cdr read-list))
7895 (if (<= (+ (current-column) (length (car read-list)) 2)
7898 (insert "\n") (indent-to margin))
7899 (insert (car read-list))
7900 (setq read-list (cdr read-list)))))))))
7902 (defun vhdl-get-visible-signals ()
7903 "Get all signals visible in the current block."
7904 (let (beg end signal-list entity-name file-name)
7905 (vhdl-prepare-search-2
7908 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7909 (not (equal "END" (upcase (match-string 1))))
7910 (setq entity-name (match-string 2)))
7911 (error "ERROR: Not within an architecture")))
7912 ;; search for signals declared in entity port clause
7914 (goto-char (point-min))
7915 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7917 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7918 "." (file-name-extension (buffer-file-name)))))
7921 (vhdl-prepare-search-2
7922 (goto-char (point-min))
7923 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7924 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7925 (when (setq beg (re-search-forward
7926 "^\\s-*port[ \t\n]*("
7928 (re-search-forward "^end\\>" nil t)) t))
7929 (setq end (save-excursion
7930 (backward-char) (forward-sexp) (point)))
7931 (vhdl-forward-syntactic-ws)
7932 (while (< (point) end)
7933 (when (looking-at "signal[ \t\n]+")
7934 (goto-char (match-end 0)))
7935 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7937 (cons (downcase (match-string 1)) signal-list))
7938 (goto-char (match-end 0))
7939 (vhdl-forward-syntactic-ws))
7940 (re-search-forward ";" end 1)
7941 (vhdl-forward-syntactic-ws)))))))
7942 ;; search for signals declared in architecture declarative part
7944 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7945 (not (equal "END" (upcase (match-string 1))))
7946 (setq end (re-search-forward "^begin\\>" nil t))))
7947 (error "ERROR: No architecture declarative part found")
7948 ;; scan for all declared signal and alias names
7950 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7951 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7952 (if (match-string 2)
7954 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7956 (cons (downcase (match-string 1)) signal-list))
7957 (goto-char (match-end 0)))
7958 ;; scan alias name, check is alias of (declared) signal
7959 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7960 (member (downcase (match-string 2)) signal-list))
7962 (cons (downcase (match-string 1)) signal-list))
7963 (goto-char (match-end 0))))
7964 (setq beg (point))))))
7965 ;; search for signals declared in surrounding block declarative parts
7967 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7969 (goto-char (match-end 2))
7970 (vhdl-backward-sexp)
7971 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7973 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7974 ;; scan for all declared signal names
7976 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7977 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7978 (if (match-string 2)
7980 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7982 (cons (downcase (match-string 1)) signal-list))
7983 (goto-char (match-end 0)))
7984 ;; scan alias name, check is alias of (declared) signal
7985 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7986 (member (downcase (match-string 2)) signal-list))
7988 (cons (downcase (match-string 1)) signal-list))
7989 (goto-char (match-end 0))))))
7993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7994 ;; Generic/port clause fixing
7996 (defun vhdl-fix-clause ()
7997 "Fix closing parenthesis within generic/port clause."
8000 (vhdl-prepare-search-2
8003 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8004 (error "ERROR: Not within a generic/port clause")
8005 ;; search for end of clause
8006 (goto-char (match-end 0))
8007 (setq beg (1- (point)))
8008 (vhdl-forward-syntactic-ws)
8009 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8010 (goto-char (1- (match-end 0)))
8011 (setq end (point-marker))
8013 (vhdl-forward-syntactic-ws))
8015 (when (> pos (save-excursion (end-of-line) (point)))
8016 (error "ERROR: Not within a generic/port clause"))
8017 ;; delete closing parenthesis on separate line (not supported style)
8018 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8020 (vhdl-backward-syntactic-ws)
8021 (setq end (point-marker))
8023 ;; delete superfluous parentheses
8024 (while (progn (goto-char beg)
8025 (condition-case () (forward-sexp)
8026 (error (goto-char (point-max))))
8028 (delete-backward-char 1))
8029 ;; add closing parenthesis
8030 (when (> (point) end)
8034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8037 (defun vhdl-remove-trailing-spaces ()
8038 "Remove trailing spaces in the whole buffer."
8042 (goto-char (point-min))
8043 (while (re-search-forward "[ \t]+$" (point-max) t)
8044 (unless (vhdl-in-literal)
8045 (replace-match "" nil nil))))))
8048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8052 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8053 "Syntax of prompt inserted by template generators.")
8055 (defvar vhdl-template-invoked-by-hook nil
8056 "Indicates whether a template has been invoked by a hook or by key or menu.
8057 Used for undoing after template abortion.")
8059 ;; correct different behavior of function `unread-command-events' in XEmacs
8060 (defun vhdl-character-to-event (arg))
8061 (defalias 'vhdl-character-to-event
8062 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8064 (defun vhdl-work-library ()
8065 "Return the working library name of the current project or \"work\" if no
8066 project is defined."
8067 (vhdl-resolve-env-variable
8068 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8071 ;; Enabling/disabling
8073 (defun vhdl-mode-line-update ()
8074 "Update the modeline string for VHDL major mode."
8075 (setq mode-name (concat "VHDL"
8076 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8077 (and vhdl-electric-mode "e")
8078 (and vhdl-stutter-mode "s")))
8079 (force-mode-line-update t))
8081 (defun vhdl-electric-mode (arg)
8082 "Toggle VHDL electric mode.
8083 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8085 (setq vhdl-electric-mode
8086 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8087 ((> arg 0) t) (t nil)))
8088 (vhdl-mode-line-update))
8090 (defun vhdl-stutter-mode (arg)
8091 "Toggle VHDL stuttering mode.
8092 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8094 (setq vhdl-stutter-mode
8095 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8096 ((> arg 0) t) (t nil)))
8097 (vhdl-mode-line-update))
8099 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8102 (defun vhdl-electric-dash (count)
8103 "-- starts a comment, --- draws a horizontal line,
8104 ---- starts a display comment."
8106 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8108 ((and abbrev-start-location (= abbrev-start-location (point)))
8109 (setq abbrev-start-location nil)
8110 (goto-char last-abbrev-location)
8111 (beginning-of-line nil)
8112 (vhdl-comment-display))
8113 ((/= (preceding-char) ?-) ; standard dash (minus)
8114 (self-insert-command count))
8115 (t (self-insert-command count)
8116 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8117 (let ((next-input (read-char)))
8118 (if (= next-input ?-) ; triple dash
8120 (vhdl-comment-display-line)
8122 "Enter '-' for display comment, else continue coding")
8123 (let ((next-input (read-char)))
8124 (if (= next-input ?-) ; four dashes
8125 (vhdl-comment-display t)
8126 (setq unread-command-events ; pushback the char
8127 (list (vhdl-character-to-event next-input))))))
8128 (setq unread-command-events ; pushback the char
8129 (list (vhdl-character-to-event next-input)))
8130 (vhdl-comment-insert)))))
8131 (self-insert-command count)))
8133 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8135 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8136 (if (= (preceding-char) ?\()
8137 (progn (delete-char -1) (insert-char ?\[ 1))
8138 (insert-char ?\( 1))
8139 (self-insert-command count)))
8141 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8143 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8145 (if (= (preceding-char) ?\))
8146 (progn (delete-char -1) (insert-char ?\] 1))
8147 (insert-char ?\) 1))
8148 (blink-matching-open))
8149 (self-insert-command count)))
8151 (defun vhdl-electric-quote (count) "'' --> \""
8153 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8154 (if (= (preceding-char) last-input-char)
8155 (progn (delete-backward-char 1) (insert-char ?\" 1))
8156 (insert-char ?\' 1))
8157 (self-insert-command count)))
8159 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8161 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8162 (cond ((= (preceding-char) last-input-char)
8163 (progn (delete-char -1)
8164 (unless (eq (preceding-char) ? ) (insert " "))
8166 (setq this-command 'vhdl-electric-colon)))
8168 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8169 (progn (delete-char -1) (insert "= ")))
8170 (t (insert-char ?\; 1)))
8171 (self-insert-command count)))
8173 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8175 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8176 (cond ((= (preceding-char) last-input-char)
8177 (progn (delete-char -1)
8178 (unless (eq (preceding-char) ? ) (insert " "))
8180 (t (insert-char ?\, 1)))
8181 (self-insert-command count)))
8183 (defun vhdl-electric-period (count) "'..' --> ' => '"
8185 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8186 (cond ((= (preceding-char) last-input-char)
8187 (progn (delete-char -1)
8188 (unless (eq (preceding-char) ? ) (insert " "))
8190 (t (insert-char ?\. 1)))
8191 (self-insert-command count)))
8193 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8195 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8196 (cond ((= (preceding-char) last-input-char)
8197 (progn (delete-char -1)
8198 (unless (eq (preceding-char) ? ) (insert " "))
8200 (t (insert-char ?\= 1)))
8201 (self-insert-command count)))
8203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8206 (defun vhdl-template-paired-parens ()
8207 "Insert a pair of round parentheses, placing point between them."
8212 (defun vhdl-template-alias ()
8213 "Insert alias declaration."
8215 (let ((start (point)))
8216 (vhdl-insert-keyword "ALIAS ")
8217 (when (vhdl-template-field "name" nil t start (point))
8219 (unless (vhdl-template-field
8220 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8222 (delete-backward-char 3))
8223 (vhdl-insert-keyword " IS ")
8224 (vhdl-template-field "name" ";")
8225 (vhdl-comment-insert-inline))))
8227 (defun vhdl-template-architecture ()
8228 "Insert architecture."
8230 (let ((margin (current-indentation))
8233 (vhdl-insert-keyword "ARCHITECTURE ")
8234 (when (setq arch-name
8235 (vhdl-template-field "name" nil t start (point)))
8236 (vhdl-insert-keyword " OF ")
8238 (vhdl-prepare-search-1
8239 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8240 (insert (match-string 1))
8241 (vhdl-template-field "entity name"))
8242 (vhdl-insert-keyword " IS\n")
8243 (vhdl-template-begin-end
8244 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8245 (memq vhdl-insert-empty-lines '(unit all))))))
8247 (defun vhdl-template-array (kind &optional secondary)
8248 "Insert array type definition."
8250 (let ((start (point)))
8251 (vhdl-insert-keyword "ARRAY (")
8252 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8254 (vhdl-insert-keyword ") OF ")
8255 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8256 (vhdl-insert-keyword ";"))))
8258 (defun vhdl-template-assert ()
8259 "Insert an assertion statement."
8261 (let ((start (point)))
8262 (vhdl-insert-keyword "ASSERT ")
8263 (when vhdl-conditions-in-parenthesis (insert "("))
8264 (when (vhdl-template-field "condition (negated)" nil t start (point))
8265 (when vhdl-conditions-in-parenthesis (insert ")"))
8266 (setq start (point))
8267 (vhdl-insert-keyword " REPORT ")
8268 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8269 (delete-region start (point)))
8270 (setq start (point))
8271 (vhdl-insert-keyword " SEVERITY ")
8272 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8273 (delete-region start (point)))
8276 (defun vhdl-template-attribute ()
8277 "Insert an attribute declaration or specification."
8279 (if (eq (vhdl-decision-query
8280 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8281 (vhdl-template-attribute-spec)
8282 (vhdl-template-attribute-decl)))
8284 (defun vhdl-template-attribute-decl ()
8285 "Insert an attribute declaration."
8287 (let ((start (point)))
8288 (vhdl-insert-keyword "ATTRIBUTE ")
8289 (when (vhdl-template-field "name" " : " t start (point))
8290 (vhdl-template-field "type" ";")
8291 (vhdl-comment-insert-inline))))
8293 (defun vhdl-template-attribute-spec ()
8294 "Insert an attribute specification."
8296 (let ((start (point)))
8297 (vhdl-insert-keyword "ATTRIBUTE ")
8298 (when (vhdl-template-field "name" nil t start (point))
8299 (vhdl-insert-keyword " OF ")
8300 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8301 (vhdl-template-field "entity class")
8302 (vhdl-insert-keyword " IS ")
8303 (vhdl-template-field "expression" ";"))))
8305 (defun vhdl-template-block ()
8308 (let ((margin (current-indentation))
8311 (vhdl-insert-keyword ": BLOCK ")
8313 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8317 (if (vhdl-template-field "[guard expression]" nil t)
8320 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8322 (vhdl-template-begin-end "BLOCK" label margin)
8323 (vhdl-comment-block))))
8325 (defun vhdl-template-block-configuration ()
8326 "Insert a block configuration statement."
8328 (let ((margin (current-indentation))
8330 (vhdl-insert-keyword "FOR ")
8331 (when (vhdl-template-field "block name" nil t start (point))
8332 (vhdl-insert-keyword "\n\n")
8334 (vhdl-insert-keyword "END FOR;")
8336 (indent-to (+ margin vhdl-basic-offset)))))
8338 (defun vhdl-template-break ()
8339 "Insert a break statement."
8342 (vhdl-insert-keyword "BREAK")
8343 (setq position (point))
8346 (progn (vhdl-insert-keyword "FOR ")
8347 (if (vhdl-template-field "[quantity name]" " USE " t)
8348 (progn (vhdl-template-field "quantity name" " => ") t)
8349 (delete-region (point)
8350 (progn (forward-word -1) (point)))
8352 (vhdl-template-field "[quantity name]" " => " t))
8353 (vhdl-template-field "expression")
8354 (setq position (point))
8356 (delete-region position (point))
8357 (unless (vhdl-sequential-statement-p)
8358 (vhdl-insert-keyword " ON ")
8359 (if (vhdl-template-field "[sensitivity list]" nil t)
8360 (setq position (point))
8361 (delete-region position (point))))
8362 (vhdl-insert-keyword " WHEN ")
8363 (when vhdl-conditions-in-parenthesis (insert "("))
8364 (if (vhdl-template-field "[condition]" nil t)
8365 (when vhdl-conditions-in-parenthesis (insert ")"))
8366 (delete-region position (point)))
8369 (defun vhdl-template-case (&optional kind)
8370 "Insert a case statement."
8372 (let ((margin (current-indentation))
8375 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8376 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8377 (vhdl-insert-keyword "CASE ")
8378 (vhdl-insert-keyword ": CASE ")
8380 (setq label (vhdl-template-field "[label]" nil t))
8381 (unless label (delete-char 2))
8384 (when (vhdl-template-field "expression" nil t start (point))
8385 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8387 (vhdl-insert-keyword "END CASE")
8388 (when label (insert " " label))
8391 (indent-to (+ margin vhdl-basic-offset))
8392 (vhdl-insert-keyword "WHEN ")
8393 (let ((position (point)))
8395 (indent-to (+ margin vhdl-basic-offset))
8396 (vhdl-insert-keyword "WHEN OTHERS => null;")
8397 (goto-char position)))))
8399 (defun vhdl-template-case-is ()
8400 "Insert a sequential case statement."
8402 (vhdl-template-case 'is))
8404 (defun vhdl-template-case-use ()
8405 "Insert a simultaneous case statement."
8407 (vhdl-template-case 'use))
8409 (defun vhdl-template-component ()
8410 "Insert a component declaration."
8412 (vhdl-template-component-decl))
8414 (defun vhdl-template-component-conf ()
8415 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8416 since these are almost equivalent)."
8418 (let ((margin (current-indentation))
8419 (result (vhdl-template-configuration-spec t)))
8423 (vhdl-insert-keyword "END FOR;")
8424 (when (eq result 'no-use)
8425 (end-of-line -0)))))
8427 (defun vhdl-template-component-decl ()
8428 "Insert a component declaration."
8430 (let ((margin (current-indentation))
8433 (vhdl-insert-keyword "COMPONENT ")
8434 (when (setq name (vhdl-template-field "name" nil t start (point)))
8435 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8438 (vhdl-insert-keyword "END COMPONENT")
8439 (unless (vhdl-standard-p '87) (insert " " name))
8441 (setq end-column (current-column))
8443 (indent-to (+ margin vhdl-basic-offset))
8444 (vhdl-template-generic-list t t)
8446 (indent-to (+ margin vhdl-basic-offset))
8447 (vhdl-template-port-list t)
8448 (beginning-of-line 2)
8449 (forward-char end-column))))
8451 (defun vhdl-template-component-inst ()
8452 "Insert a component instantiation statement."
8454 (let ((margin (current-indentation))
8457 (when (vhdl-template-field "instance label" nil t start (point))
8459 (if (not (vhdl-use-direct-instantiation))
8460 (vhdl-template-field "component name")
8461 ;; direct instantiation
8462 (setq unit (vhdl-template-field
8463 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8464 (setq unit (upcase (or unit "")))
8465 (cond ((equal unit "ENTITY")
8466 (vhdl-template-field "library name" "." nil nil nil nil
8467 (vhdl-work-library))
8468 (vhdl-template-field "entity name" "(")
8469 (if (vhdl-template-field "[architecture name]" nil t)
8472 ((equal unit "CONFIGURATION")
8473 (vhdl-template-field "library name" "." nil nil nil nil
8474 (vhdl-work-library))
8475 (vhdl-template-field "configuration name"))
8476 (t (vhdl-template-field "component name"))))
8478 (indent-to (+ margin vhdl-basic-offset))
8479 (setq position (point))
8480 (vhdl-insert-keyword "GENERIC ")
8481 (when (vhdl-template-map position t t)
8483 (indent-to (+ margin vhdl-basic-offset)))
8484 (setq position (point))
8485 (vhdl-insert-keyword "PORT ")
8486 (unless (vhdl-template-map position t t)
8487 (delete-region (line-beginning-position) (point))
8491 (defun vhdl-template-conditional-signal-asst ()
8492 "Insert a conditional signal assignment."
8494 (when (vhdl-template-field "target signal")
8496 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8498 (let ((margin (current-column))
8501 (vhdl-template-field "waveform")
8502 (setq position (point))
8503 (vhdl-insert-keyword " WHEN ")
8504 (when vhdl-conditions-in-parenthesis (insert "("))
8505 (while (and (vhdl-template-field "[condition]" nil t)
8507 (when vhdl-conditions-in-parenthesis (insert ")"))
8508 (setq position (point))
8509 (vhdl-insert-keyword " ELSE")
8512 (vhdl-template-field "[waveform]" nil t)))
8513 (setq position (point))
8514 (vhdl-insert-keyword " WHEN ")
8515 (when vhdl-conditions-in-parenthesis (insert "(")))
8516 (delete-region position (point))
8518 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8520 (defun vhdl-template-configuration ()
8521 "Insert a configuration specification if within an architecture,
8522 a block or component configuration if within a configuration declaration,
8523 a configuration declaration if not within a design unit."
8525 (vhdl-prepare-search-1
8527 ((and (save-excursion ; architecture body
8528 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8529 (equal "ARCHITECTURE" (upcase (match-string 1))))
8530 (vhdl-template-configuration-spec))
8531 ((and (save-excursion ; configuration declaration
8532 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8533 (equal "CONFIGURATION" (upcase (match-string 1))))
8534 (if (eq (vhdl-decision-query
8535 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8536 (vhdl-template-component-conf)
8537 (vhdl-template-block-configuration)))
8538 (t (vhdl-template-configuration-decl))))) ; otherwise
8540 (defun vhdl-template-configuration-spec (&optional optional-use)
8541 "Insert a configuration specification."
8543 (let ((margin (current-indentation))
8546 (vhdl-insert-keyword "FOR ")
8547 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8549 (vhdl-template-field "component name" "\n")
8550 (indent-to (+ margin vhdl-basic-offset))
8551 (setq start (point))
8552 (vhdl-insert-keyword "USE ")
8553 (if (and optional-use
8554 (not (setq aspect (vhdl-template-field
8555 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8556 (progn (delete-region start (point)) 'no-use)
8557 (unless optional-use
8558 (setq aspect (vhdl-template-field
8559 "ENTITY | CONFIGURATION | OPEN" " ")))
8560 (setq aspect (upcase (or aspect "")))
8561 (cond ((equal aspect "ENTITY")
8562 (vhdl-template-field "library name" "." nil nil nil nil
8563 (vhdl-work-library))
8564 (vhdl-template-field "entity name" "(")
8565 (if (vhdl-template-field "[architecture name]" nil t)
8569 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8570 (setq position (point))
8571 (vhdl-insert-keyword "GENERIC ")
8572 (when (vhdl-template-map position t t)
8574 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8575 (setq position (point))
8576 (vhdl-insert-keyword "PORT ")
8577 (unless (vhdl-template-map position t t)
8578 (delete-region (line-beginning-position) (point))
8582 ((equal aspect "CONFIGURATION")
8583 (vhdl-template-field "library name" "." nil nil nil nil
8584 (vhdl-work-library))
8585 (vhdl-template-field "configuration name" ";"))
8586 (t (delete-backward-char 1) (insert ";") t))))))
8589 (defun vhdl-template-configuration-decl ()
8590 "Insert a configuration declaration."
8592 (let ((margin (current-indentation))
8594 entity-exists string name position)
8595 (vhdl-insert-keyword "CONFIGURATION ")
8596 (when (setq name (vhdl-template-field "name" nil t start (point)))
8597 (vhdl-insert-keyword " OF ")
8599 (vhdl-prepare-search-1
8600 (setq entity-exists (vhdl-re-search-backward
8601 "\\<entity \\(\\w*\\) is\\>" nil t))
8602 (setq string (match-string 1))))
8603 (if (and entity-exists (not (equal string "")))
8605 (vhdl-template-field "entity name"))
8606 (vhdl-insert-keyword " IS\n")
8607 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8608 (indent-to (+ margin vhdl-basic-offset))
8609 (setq position (point))
8611 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8613 (vhdl-insert-keyword "END ")
8614 (unless (vhdl-standard-p '87)
8615 (vhdl-insert-keyword "CONFIGURATION "))
8617 (goto-char position))))
8619 (defun vhdl-template-constant ()
8620 "Insert a constant declaration."
8622 (let ((start (point))
8623 (in-arglist (vhdl-in-argument-list-p)))
8624 (vhdl-insert-keyword "CONSTANT ")
8625 (when (vhdl-template-field "name" nil t start (point))
8627 (when in-arglist (vhdl-insert-keyword "IN "))
8628 (vhdl-template-field "type")
8631 (vhdl-comment-insert-inline))
8632 (let ((position (point)))
8634 (unless (vhdl-template-field "[initialization]" nil t)
8635 (delete-region position (point)))
8637 (vhdl-comment-insert-inline))))))
8639 (defun vhdl-template-default ()
8648 (defun vhdl-template-default-indent ()
8649 "Insert nothing and indent."
8656 (indent-according-to-mode))
8658 (defun vhdl-template-disconnect ()
8659 "Insert a disconnect statement."
8661 (let ((start (point)))
8662 (vhdl-insert-keyword "DISCONNECT ")
8663 (when (vhdl-template-field "signal names | OTHERS | ALL"
8664 " : " t start (point))
8665 (vhdl-template-field "type")
8666 (vhdl-insert-keyword " AFTER ")
8667 (vhdl-template-field "time expression" ";"))))
8669 (defun vhdl-template-else ()
8670 "Insert an else statement."
8673 (vhdl-prepare-search-1
8674 (vhdl-insert-keyword "ELSE")
8675 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8676 (equal "WHEN" (upcase (match-string 1))))
8678 (indent-according-to-mode)
8679 (setq margin (current-indentation))
8681 (indent-to (+ margin vhdl-basic-offset))))))
8683 (defun vhdl-template-elsif ()
8684 "Insert an elsif statement."
8686 (let ((start (point))
8688 (vhdl-insert-keyword "ELSIF ")
8689 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8690 (when vhdl-conditions-in-parenthesis (insert "("))
8691 (when (vhdl-template-field "condition" nil t start (point))
8692 (when vhdl-conditions-in-parenthesis (insert ")"))
8693 (indent-according-to-mode)
8694 (setq margin (current-indentation))
8695 (vhdl-insert-keyword
8696 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8697 (indent-to (+ margin vhdl-basic-offset))))))
8699 (defun vhdl-template-entity ()
8702 (let ((margin (current-indentation))
8705 (vhdl-insert-keyword "ENTITY ")
8706 (when (setq name (vhdl-template-field "name" nil t start (point)))
8707 (vhdl-insert-keyword " IS\n\n")
8709 (vhdl-insert-keyword "END ")
8710 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8712 (setq end-column (current-column))
8714 (indent-to (+ margin vhdl-basic-offset))
8715 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8716 (indent-to (+ margin vhdl-basic-offset))
8717 (when (vhdl-template-generic-list t)
8718 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8720 (indent-to (+ margin vhdl-basic-offset))
8721 (when (vhdl-template-port-list t)
8722 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8723 (beginning-of-line 2)
8724 (forward-char end-column))))
8726 (defun vhdl-template-exit ()
8727 "Insert an exit statement."
8729 (let ((start (point)))
8730 (vhdl-insert-keyword "EXIT ")
8731 (if (vhdl-template-field "[loop label]" nil t start (point))
8732 (let ((position (point)))
8733 (vhdl-insert-keyword " WHEN ")
8734 (when vhdl-conditions-in-parenthesis (insert "("))
8735 (if (vhdl-template-field "[condition]" nil t)
8736 (when vhdl-conditions-in-parenthesis (insert ")"))
8737 (delete-region position (point))))
8741 (defun vhdl-template-file ()
8742 "Insert a file declaration."
8744 (let ((start (point)))
8745 (vhdl-insert-keyword "FILE ")
8746 (when (vhdl-template-field "name" nil t start (point))
8748 (vhdl-template-field "type")
8749 (unless (vhdl-standard-p '87)
8750 (vhdl-insert-keyword " OPEN ")
8751 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8753 (delete-backward-char 6)))
8754 (vhdl-insert-keyword " IS ")
8755 (when (vhdl-standard-p '87)
8756 (vhdl-template-field "[IN | OUT]" " " t))
8757 (vhdl-template-field "filename-string" nil nil nil nil t)
8759 (vhdl-comment-insert-inline))))
8761 (defun vhdl-template-for ()
8762 "Insert a block or component configuration if within a configuration
8763 declaration, a configuration specification if within an architecture
8764 declarative part (and not within a subprogram), a for-loop if within a
8765 sequential statement part (subprogram or process), and a for-generate
8768 (vhdl-prepare-search-1
8770 ((vhdl-sequential-statement-p) ; sequential statement
8771 (vhdl-template-for-loop))
8772 ((and (save-excursion ; configuration declaration
8773 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8774 (equal "CONFIGURATION" (upcase (match-string 1))))
8775 (if (eq (vhdl-decision-query
8776 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8777 (vhdl-template-component-conf)
8778 (vhdl-template-block-configuration)))
8779 ((and (save-excursion
8780 (re-search-backward ; architecture declarative part
8781 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8782 (equal "ARCHITECTURE" (upcase (match-string 1))))
8783 (vhdl-template-configuration-spec))
8784 (t (vhdl-template-for-generate))))) ; concurrent statement
8786 (defun vhdl-template-for-generate ()
8787 "Insert a for-generate."
8789 (let ((margin (current-indentation))
8792 (vhdl-insert-keyword ": FOR ")
8793 (setq position (point-marker))
8795 (when (setq label (vhdl-template-field "label" nil t start position))
8796 (goto-char position)
8797 (vhdl-template-field "loop variable")
8798 (vhdl-insert-keyword " IN ")
8799 (vhdl-template-field "range")
8800 (vhdl-template-generate-body margin label))))
8802 (defun vhdl-template-for-loop ()
8803 "Insert a for loop."
8805 (let ((margin (current-indentation))
8808 (if (not (eq vhdl-optional-labels 'all))
8809 (vhdl-insert-keyword "FOR ")
8810 (vhdl-insert-keyword ": FOR ")
8812 (setq label (vhdl-template-field "[label]" nil t))
8813 (unless label (delete-char 2))
8816 (when (setq index (vhdl-template-field "loop variable"
8817 nil t start (point)))
8818 (vhdl-insert-keyword " IN ")
8819 (vhdl-template-field "range")
8820 (vhdl-insert-keyword " LOOP\n\n")
8822 (vhdl-insert-keyword "END LOOP")
8824 (insert " " label ";")
8826 (when vhdl-self-insert-comments (insert " -- " index)))
8828 (indent-to (+ margin vhdl-basic-offset)))))
8830 (defun vhdl-template-function (&optional kind)
8831 "Insert a function declaration or body."
8833 (let ((margin (current-indentation))
8836 (vhdl-insert-keyword "FUNCTION ")
8837 (when (setq name (vhdl-template-field "name" nil t start (point)))
8838 (vhdl-template-argument-list t)
8839 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8842 (indent-to (+ margin vhdl-basic-offset))
8843 (vhdl-insert-keyword "RETURN ")
8844 (vhdl-template-field "type")
8845 (if (if kind (eq kind 'body)
8846 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8847 (progn (vhdl-insert-keyword " IS\n")
8848 (vhdl-template-begin-end
8849 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8850 (vhdl-comment-block))
8853 (defun vhdl-template-function-decl ()
8854 "Insert a function declaration."
8856 (vhdl-template-function 'decl))
8858 (defun vhdl-template-function-body ()
8859 "Insert a function declaration."
8861 (vhdl-template-function 'body))
8863 (defun vhdl-template-generate ()
8864 "Insert a generation scheme."
8866 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8867 (vhdl-template-if-generate)
8868 (vhdl-template-for-generate)))
8870 (defun vhdl-template-generic ()
8871 "Insert generic declaration, or generic map in instantiation statements."
8873 (let ((start (point)))
8874 (vhdl-prepare-search-1
8876 ((and (save-excursion ; entity declaration
8877 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8878 (equal "ENTITY" (upcase (match-string 1))))
8879 (vhdl-template-generic-list nil))
8880 ((or (save-excursion
8881 (or (beginning-of-line)
8882 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8883 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8884 (vhdl-insert-keyword "GENERIC ")
8885 (vhdl-template-map start))
8886 (t (vhdl-template-generic-list nil t))))))
8888 (defun vhdl-template-group ()
8889 "Insert group or group template declaration."
8891 (let ((start (point)))
8892 (if (eq (vhdl-decision-query
8893 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8894 (vhdl-template-group-template)
8895 (vhdl-template-group-decl))))
8897 (defun vhdl-template-group-decl ()
8898 "Insert group declaration."
8900 (let ((start (point)))
8901 (vhdl-insert-keyword "GROUP ")
8902 (when (vhdl-template-field "name" " : " t start (point))
8903 (vhdl-template-field "template name" " (")
8904 (vhdl-template-field "constituent list" ");")
8905 (vhdl-comment-insert-inline))))
8907 (defun vhdl-template-group-template ()
8908 "Insert group template declaration."
8910 (let ((start (point)))
8911 (vhdl-insert-keyword "GROUP ")
8912 (when (vhdl-template-field "template name" nil t start (point))
8913 (vhdl-insert-keyword " IS (")
8914 (vhdl-template-field "entity class list" ");")
8915 (vhdl-comment-insert-inline))))
8917 (defun vhdl-template-if ()
8918 "Insert a sequential if statement or an if-generate statement."
8920 (if (vhdl-sequential-statement-p)
8921 (vhdl-template-if-then)
8922 (if (and (vhdl-standard-p 'ams)
8923 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8924 (vhdl-template-if-use)
8925 (vhdl-template-if-generate))))
8927 (defun vhdl-template-if-generate ()
8928 "Insert an if-generate."
8930 (let ((margin (current-indentation))
8933 (vhdl-insert-keyword ": IF ")
8934 (setq position (point-marker))
8936 (when (setq label (vhdl-template-field "label" nil t start position))
8937 (goto-char position)
8938 (when vhdl-conditions-in-parenthesis (insert "("))
8939 (vhdl-template-field "condition")
8940 (when vhdl-conditions-in-parenthesis (insert ")"))
8941 (vhdl-template-generate-body margin label))))
8943 (defun vhdl-template-if-then-use (kind)
8944 "Insert a sequential if statement."
8946 (let ((margin (current-indentation))
8949 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8950 (vhdl-insert-keyword "IF ")
8951 (vhdl-insert-keyword ": IF ")
8953 (setq label (vhdl-template-field "[label]" nil t))
8954 (unless label (delete-char 2))
8957 (when vhdl-conditions-in-parenthesis (insert "("))
8958 (when (vhdl-template-field "condition" nil t start (point))
8959 (when vhdl-conditions-in-parenthesis (insert ")"))
8960 (vhdl-insert-keyword
8961 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8963 (vhdl-insert-keyword "END IF")
8964 (when label (insert " " label))
8967 (indent-to (+ margin vhdl-basic-offset)))))
8969 (defun vhdl-template-if-then ()
8970 "Insert a sequential if statement."
8972 (vhdl-template-if-then-use 'then))
8974 (defun vhdl-template-if-use ()
8975 "Insert a simultaneous if statement."
8977 (vhdl-template-if-then-use 'use))
8979 (defun vhdl-template-instance ()
8980 "Insert a component instantiation statement."
8982 (vhdl-template-component-inst))
8984 (defun vhdl-template-library ()
8985 "Insert a library specification."
8987 (let ((margin (current-indentation))
8990 (vhdl-insert-keyword "LIBRARY ")
8991 (when (setq name (vhdl-template-field "names" nil t start (point)))
8993 (unless (string-match "," name)
8994 (setq end-pos (point))
8997 (vhdl-insert-keyword "USE ")
8999 (vhdl-insert-keyword "..ALL;")
9001 (if (vhdl-template-field "package name")
9003 (delete-region end-pos (+ (point) 5)))))))
9005 (defun vhdl-template-limit ()
9008 (let ((start (point)))
9009 (vhdl-insert-keyword "LIMIT ")
9010 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9012 (vhdl-template-field "type")
9013 (vhdl-insert-keyword " WITH ")
9014 (vhdl-template-field "real expression" ";"))))
9016 (defun vhdl-template-loop ()
9019 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9021 (vhdl-template-while-loop))
9023 (vhdl-template-for-loop))
9024 (t (vhdl-template-bare-loop)))))
9026 (defun vhdl-template-bare-loop ()
9029 (let ((margin (current-indentation))
9032 (if (not (eq vhdl-optional-labels 'all))
9033 (vhdl-insert-keyword "LOOP ")
9034 (vhdl-insert-keyword ": LOOP ")
9036 (setq label (vhdl-template-field "[label]" nil t))
9037 (unless label (delete-char 2))
9042 (vhdl-insert-keyword "END LOOP")
9043 (insert (if label (concat " " label ";") ";"))
9045 (indent-to (+ margin vhdl-basic-offset))))
9047 (defun vhdl-template-map (&optional start optional secondary)
9048 "Insert a map specification with association list."
9050 (let ((start (or start (point)))
9052 (vhdl-insert-keyword "MAP (")
9053 (if (not vhdl-association-list-with-formals)
9054 (if (vhdl-template-field
9055 (concat (and optional "[") "association list" (and optional "]"))
9056 ")" (or (not secondary) optional)
9057 (and (not secondary) start) (point))
9059 (if (and optional secondary) (delete-region start (point)))
9061 (if vhdl-argument-list-indent
9062 (setq margin (current-column))
9063 (setq margin (+ (current-indentation) vhdl-basic-offset))
9066 (if (vhdl-template-field
9067 (concat (and optional "[") "formal" (and optional "]"))
9068 " => " (or (not secondary) optional)
9069 (and (not secondary) start) (point))
9071 (vhdl-template-field "actual" ",")
9072 (setq end-pos (point))
9075 (while (vhdl-template-field "[formal]" " => " t)
9076 (vhdl-template-field "actual" ",")
9077 (setq end-pos (point))
9080 (delete-region end-pos (point))
9081 (delete-backward-char 1)
9083 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9085 (when (and optional secondary) (delete-region start (point)))
9088 (defun vhdl-template-modify (&optional noerror)
9089 "Actualize modification date."
9091 (vhdl-prepare-search-2
9093 (goto-char (point-min))
9094 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9095 (progn (delete-region (point) (progn (end-of-line) (point)))
9096 (vhdl-template-insert-date))
9098 (error "ERROR: Modification date prefix string \"%s\" not found"
9099 vhdl-modify-date-prefix-string))))))
9102 (defun vhdl-template-modify-noerror ()
9103 "Call `vhdl-template-modify' with NOERROR non-nil."
9104 (vhdl-template-modify t))
9106 (defun vhdl-template-nature ()
9107 "Insert a nature declaration."
9109 (let ((start (point))
9110 name mid-pos end-pos)
9111 (vhdl-insert-keyword "NATURE ")
9112 (when (setq name (vhdl-template-field "name" nil t start (point)))
9113 (vhdl-insert-keyword " IS ")
9116 (or (vhdl-template-field
9117 "across type | ARRAY | RECORD")
9119 (cond ((equal definition "")
9121 ((equal definition "ARRAY")
9122 (delete-region (point) (progn (forward-word -1) (point)))
9123 (vhdl-template-array 'nature t))
9124 ((equal definition "RECORD")
9125 (setq mid-pos (point-marker))
9126 (delete-region (point) (progn (forward-word -1) (point)))
9127 (vhdl-template-record 'nature name t))
9129 (vhdl-insert-keyword " ACROSS ")
9130 (vhdl-template-field "through type")
9131 (vhdl-insert-keyword " THROUGH ")
9132 (vhdl-template-field "reference name")
9133 (vhdl-insert-keyword " REFERENCE;")))
9135 (setq end-pos (point-marker))
9138 (vhdl-comment-insert-inline)
9139 (when end-pos (goto-char end-pos))))))
9141 (defun vhdl-template-next ()
9142 "Insert a next statement."
9144 (let ((start (point)))
9145 (vhdl-insert-keyword "NEXT ")
9146 (if (vhdl-template-field "[loop label]" nil t start (point))
9147 (let ((position (point)))
9148 (vhdl-insert-keyword " WHEN ")
9149 (when vhdl-conditions-in-parenthesis (insert "("))
9150 (if (vhdl-template-field "[condition]" nil t)
9151 (when vhdl-conditions-in-parenthesis (insert ")"))
9152 (delete-region position (point))))
9156 (defun vhdl-template-others ()
9157 "Insert an others aggregate."
9159 (let ((start (point)))
9160 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9161 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9162 (vhdl-insert-keyword "OTHERS => '")
9163 (when (vhdl-template-field "value" nil t start (point))
9165 (vhdl-insert-keyword "OTHERS "))))
9167 (defun vhdl-template-package (&optional kind)
9168 "Insert a package specification or body."
9170 (let ((margin (current-indentation))
9173 (vhdl-insert-keyword "PACKAGE ")
9174 (setq body (if kind (eq kind 'body)
9175 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9177 (vhdl-insert-keyword "BODY ")
9178 (when (save-excursion
9179 (vhdl-prepare-search-1
9180 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9181 (insert (setq name (match-string 1)))))
9183 (setq name (vhdl-template-field "name" nil t start (point))))
9184 (vhdl-insert-keyword " IS\n")
9185 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9186 (indent-to (+ margin vhdl-basic-offset))
9187 (setq position (point))
9189 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9191 (vhdl-insert-keyword "END ")
9192 (unless (vhdl-standard-p '87)
9193 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9194 (insert (or name "") ";")
9195 (goto-char position))))
9197 (defun vhdl-template-package-decl ()
9198 "Insert a package specification."
9200 (vhdl-template-package 'decl))
9202 (defun vhdl-template-package-body ()
9203 "Insert a package body."
9205 (vhdl-template-package 'body))
9207 (defun vhdl-template-port ()
9208 "Insert a port declaration, or port map in instantiation statements."
9210 (let ((start (point)))
9211 (vhdl-prepare-search-1
9213 ((and (save-excursion ; entity declaration
9214 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9215 (equal "ENTITY" (upcase (match-string 1))))
9216 (vhdl-template-port-list nil))
9217 ((or (save-excursion
9218 (or (beginning-of-line)
9219 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9220 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9221 (vhdl-insert-keyword "PORT ")
9222 (vhdl-template-map start))
9223 (t (vhdl-template-port-list nil))))))
9225 (defun vhdl-template-procedural ()
9226 "Insert a procedural."
9228 (let ((margin (current-indentation))
9230 (case-fold-search t)
9232 (vhdl-insert-keyword "PROCEDURAL ")
9233 (when (memq vhdl-optional-labels '(process all))
9237 (setq label (vhdl-template-field "[label]" nil t))
9238 (unless label (delete-char 2))
9241 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9243 (vhdl-template-begin-end "PROCEDURAL" label margin)
9244 (vhdl-comment-block)))
9246 (defun vhdl-template-procedure (&optional kind)
9247 "Insert a procedure declaration or body."
9249 (let ((margin (current-indentation))
9252 (vhdl-insert-keyword "PROCEDURE ")
9253 (when (setq name (vhdl-template-field "name" nil t start (point)))
9254 (vhdl-template-argument-list)
9255 (if (if kind (eq kind 'body)
9256 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9257 (progn (vhdl-insert-keyword " IS")
9258 (when vhdl-auto-align
9259 (vhdl-align-region-groups start (point) 1))
9260 (end-of-line) (insert "\n")
9261 (vhdl-template-begin-end
9262 (unless (vhdl-standard-p '87) "PROCEDURE")
9264 (vhdl-comment-block))
9266 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9269 (defun vhdl-template-procedure-decl ()
9270 "Insert a procedure declaration."
9272 (vhdl-template-procedure 'decl))
9274 (defun vhdl-template-procedure-body ()
9275 "Insert a procedure body."
9277 (vhdl-template-procedure 'body))
9279 (defun vhdl-template-process (&optional kind)
9282 (let ((margin (current-indentation))
9284 label seq input-signals clock reset final-pos)
9285 (setq seq (if kind (eq kind 'seq)
9286 (eq (vhdl-decision-query
9287 "process" "(c)ombinational or (s)equential?" t) ?s)))
9288 (vhdl-insert-keyword "PROCESS ")
9289 (when (memq vhdl-optional-labels '(process all))
9293 (setq label (vhdl-template-field "[label]" nil t))
9294 (unless label (delete-char 2))
9299 (unless (setq input-signals
9300 (vhdl-template-field "[sensitivity list]" ")" t))
9301 (setq input-signals "")
9303 (setq clock (or (and (not (equal "" vhdl-clock-name))
9304 (progn (insert vhdl-clock-name) vhdl-clock-name))
9305 (vhdl-template-field "clock name") "<clock>"))
9306 (when (eq vhdl-reset-kind 'async)
9308 (setq reset (or (and (not (equal "" vhdl-reset-name))
9309 (progn (insert vhdl-reset-name) vhdl-reset-name))
9310 (vhdl-template-field "reset name") "<reset>")))
9312 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9314 (vhdl-template-begin-end "PROCESS" label margin)
9315 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9316 (when vhdl-prompt-for-comments
9317 (setq final-pos (point-marker))
9318 (vhdl-prepare-search-2
9319 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9320 (vhdl-re-search-backward "\\<process\\>" nil t))
9323 (progn (insert "\n") (forward-line -1))
9326 (insert "-- purpose: ")
9327 (if (not (vhdl-template-field "[description]" nil t))
9328 (vhdl-line-kill-entire)
9331 (insert "-- type : ")
9332 (insert (if seq "sequential" "combinational") "\n")
9334 (insert "-- inputs : ")
9336 (insert input-signals)
9338 (when reset (insert reset ", "))
9339 (unless (vhdl-template-field "[signal names]" nil t)
9343 (insert "-- outputs: ")
9344 (vhdl-template-field "[signal names]" nil t))))
9345 (goto-char final-pos))))
9347 (defun vhdl-template-process-comb ()
9348 "Insert a combinational process."
9350 (vhdl-template-process 'comb))
9352 (defun vhdl-template-process-seq ()
9353 "Insert a sequential process."
9355 (vhdl-template-process 'seq))
9357 (defun vhdl-template-quantity ()
9358 "Insert a quantity declaration."
9360 (if (vhdl-in-argument-list-p)
9361 (let ((start (point)))
9362 (vhdl-insert-keyword "QUANTITY ")
9363 (when (vhdl-template-field "names" nil t start (point))
9365 (vhdl-template-field "[IN | OUT]" " " t)
9366 (vhdl-template-field "type")
9368 (vhdl-comment-insert-inline)))
9369 (let ((char (vhdl-decision-query
9370 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9371 (cond ((eq char ?f) (vhdl-template-quantity-free))
9372 ((eq char ?b) (vhdl-template-quantity-branch))
9373 ((eq char ?s) (vhdl-template-quantity-source))
9374 (t (vhdl-template-undo (point) (point)))))))
9376 (defun vhdl-template-quantity-free ()
9377 "Insert a free quantity declaration."
9379 (vhdl-insert-keyword "QUANTITY ")
9380 (vhdl-template-field "names")
9382 (vhdl-template-field "type")
9383 (let ((position (point)))
9385 (unless (vhdl-template-field "[initialization]" nil t)
9386 (delete-region position (point)))
9388 (vhdl-comment-insert-inline)))
9390 (defun vhdl-template-quantity-branch ()
9391 "Insert a branch quantity declaration."
9394 (vhdl-insert-keyword "QUANTITY ")
9395 (when (vhdl-template-field "[across names]" " " t)
9396 (vhdl-insert-keyword "ACROSS "))
9397 (when (vhdl-template-field "[through names]" " " t)
9398 (vhdl-insert-keyword "THROUGH "))
9399 (vhdl-template-field "plus terminal name")
9400 (setq position (point))
9401 (vhdl-insert-keyword " TO ")
9402 (unless (vhdl-template-field "[minus terminal name]" nil t)
9403 (delete-region position (point)))
9405 (vhdl-comment-insert-inline)))
9407 (defun vhdl-template-quantity-source ()
9408 "Insert a source quantity declaration."
9410 (vhdl-insert-keyword "QUANTITY ")
9411 (vhdl-template-field "names")
9413 (vhdl-template-field "type" " ")
9414 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9415 (progn (vhdl-insert-keyword "NOISE ")
9416 (vhdl-template-field "power expression"))
9417 (vhdl-insert-keyword "SPECTRUM ")
9418 (vhdl-template-field "magnitude expression" ", ")
9419 (vhdl-template-field "phase expression"))
9421 (vhdl-comment-insert-inline))
9423 (defun vhdl-template-record (kind &optional name secondary)
9424 "Insert a record type declaration."
9426 (let ((margin (current-column))
9429 (vhdl-insert-keyword "RECORD\n")
9430 (indent-to (+ margin vhdl-basic-offset))
9431 (when (or (vhdl-template-field "element names"
9432 nil (not secondary) start (point))
9434 (while (or first (vhdl-template-field "[element names]" nil t))
9436 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9437 (vhdl-comment-insert-inline)
9439 (indent-to (+ margin vhdl-basic-offset))
9441 (delete-region (line-beginning-position) (point))
9443 (vhdl-insert-keyword "END RECORD")
9444 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9446 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9448 (defun vhdl-template-report ()
9449 "Insert a report statement."
9451 (let ((start (point)))
9452 (vhdl-insert-keyword "REPORT ")
9453 (if (equal "\"\"" (vhdl-template-field
9454 "string expression" nil t start (point) t))
9455 (delete-backward-char 2)
9456 (setq start (point))
9457 (vhdl-insert-keyword " SEVERITY ")
9458 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9459 (delete-region start (point)))
9462 (defun vhdl-template-return ()
9463 "Insert a return statement."
9465 (let ((start (point)))
9466 (vhdl-insert-keyword "RETURN ")
9467 (unless (vhdl-template-field "[expression]" nil t start (point))
9471 (defun vhdl-template-selected-signal-asst ()
9472 "Insert a selected signal assignment."
9474 (let ((margin (current-indentation))
9477 (let ((position (point)))
9478 (vhdl-insert-keyword " SELECT ")
9479 (goto-char position))
9480 (vhdl-insert-keyword "WITH ")
9481 (when (vhdl-template-field "selector expression"
9482 nil t start (+ (point) 7))
9486 (indent-to (+ margin vhdl-basic-offset))
9487 (vhdl-template-field "target signal" " <= ")
9488 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9490 (indent-to (+ margin vhdl-basic-offset))
9491 (vhdl-template-field "waveform")
9492 (vhdl-insert-keyword " WHEN ")
9493 (vhdl-template-field "choices" ",")
9495 (indent-to (+ margin vhdl-basic-offset))
9496 (while (and choices (vhdl-template-field "[waveform]" nil t))
9497 (vhdl-insert-keyword " WHEN ")
9498 (if (setq choices (vhdl-template-field "[choices]" "," t))
9499 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9500 (vhdl-insert-keyword "OTHERS")))
9505 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9507 (defun vhdl-template-signal ()
9508 "Insert a signal declaration."
9510 (let ((start (point))
9511 (in-arglist (vhdl-in-argument-list-p)))
9512 (vhdl-insert-keyword "SIGNAL ")
9513 (when (vhdl-template-field "names" nil t start (point))
9515 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9516 (vhdl-template-field "type")
9519 (vhdl-comment-insert-inline))
9520 (let ((position (point)))
9522 (unless (vhdl-template-field "[initialization]" nil t)
9523 (delete-region position (point)))
9525 (vhdl-comment-insert-inline))))))
9527 (defun vhdl-template-subnature ()
9528 "Insert a subnature declaration."
9530 (let ((start (point))
9532 (vhdl-insert-keyword "SUBNATURE ")
9533 (when (vhdl-template-field "name" nil t start (point))
9534 (vhdl-insert-keyword " IS ")
9535 (vhdl-template-field "nature" " (")
9536 (if (vhdl-template-field "[index range]" nil t)
9539 (setq position (point))
9540 (vhdl-insert-keyword " TOLERANCE ")
9541 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9543 (delete-region position (point))
9544 (vhdl-insert-keyword " ACROSS ")
9545 (vhdl-template-field "string expression" nil nil nil nil t)
9546 (vhdl-insert-keyword " THROUGH"))
9548 (vhdl-comment-insert-inline))))
9550 (defun vhdl-template-subprogram-body ()
9551 "Insert a subprogram body."
9553 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9554 (vhdl-template-function-body)
9555 (vhdl-template-procedure-body)))
9557 (defun vhdl-template-subprogram-decl ()
9558 "Insert a subprogram declaration."
9560 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9561 (vhdl-template-function-decl)
9562 (vhdl-template-procedure-decl)))
9564 (defun vhdl-template-subtype ()
9565 "Insert a subtype declaration."
9567 (let ((start (point)))
9568 (vhdl-insert-keyword "SUBTYPE ")
9569 (when (vhdl-template-field "name" nil t start (point))
9570 (vhdl-insert-keyword " IS ")
9571 (vhdl-template-field "type" " ")
9573 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9576 (vhdl-comment-insert-inline))))
9578 (defun vhdl-template-terminal ()
9579 "Insert a terminal declaration."
9581 (let ((start (point)))
9582 (vhdl-insert-keyword "TERMINAL ")
9583 (when (vhdl-template-field "names" nil t start (point))
9585 (vhdl-template-field "nature")
9587 (vhdl-comment-insert-inline))))
9589 (defun vhdl-template-type ()
9590 "Insert a type declaration."
9592 (let ((start (point))
9593 name mid-pos end-pos)
9594 (vhdl-insert-keyword "TYPE ")
9595 (when (setq name (vhdl-template-field "name" nil t start (point)))
9596 (vhdl-insert-keyword " IS ")
9599 (or (vhdl-template-field
9600 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9602 (cond ((equal definition "")
9603 (delete-backward-char 4)
9605 ((equal definition "ARRAY")
9606 (delete-region (point) (progn (forward-word -1) (point)))
9607 (vhdl-template-array 'type t))
9608 ((equal definition "RECORD")
9609 (setq mid-pos (point-marker))
9610 (delete-region (point) (progn (forward-word -1) (point)))
9611 (vhdl-template-record 'type name t))
9612 ((equal definition "ACCESS")
9614 (vhdl-template-field "type" ";"))
9615 ((equal definition "FILE")
9616 (vhdl-insert-keyword " OF ")
9617 (vhdl-template-field "type" ";"))
9620 (setq end-pos (point-marker))
9623 (vhdl-comment-insert-inline)
9624 (when end-pos (goto-char end-pos))))))
9626 (defun vhdl-template-use ()
9627 "Insert a use clause."
9629 (let ((start (point)))
9630 (vhdl-prepare-search-1
9631 (vhdl-insert-keyword "USE ")
9632 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9633 (vhdl-insert-keyword "..ALL;")
9635 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9637 (vhdl-template-field "package name")
9638 (forward-char 5))))))
9640 (defun vhdl-template-variable ()
9641 "Insert a variable declaration."
9643 (let ((start (point))
9644 (in-arglist (vhdl-in-argument-list-p)))
9645 (vhdl-prepare-search-2
9646 (if (or (save-excursion
9647 (and (vhdl-re-search-backward
9648 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9650 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9651 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9652 (vhdl-insert-keyword "VARIABLE ")
9653 (vhdl-insert-keyword "SHARED VARIABLE ")))
9654 (when (vhdl-template-field "names" nil t start (point))
9656 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9657 (vhdl-template-field "type")
9660 (vhdl-comment-insert-inline))
9661 (let ((position (point)))
9663 (unless (vhdl-template-field "[initialization]" nil t)
9664 (delete-region position (point)))
9666 (vhdl-comment-insert-inline))))))
9668 (defun vhdl-template-wait ()
9669 "Insert a wait statement."
9671 (vhdl-insert-keyword "WAIT ")
9672 (unless (vhdl-template-field
9673 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9678 (defun vhdl-template-when ()
9679 "Indent correctly if within a case statement."
9681 (let ((position (point))
9683 (vhdl-prepare-search-2
9684 (if (and (= (current-column) (current-indentation))
9685 (vhdl-re-search-forward "\\<end\\>" nil t)
9686 (looking-at "\\s-*\\<case\\>"))
9688 (setq margin (current-indentation))
9689 (goto-char position)
9690 (delete-horizontal-space)
9691 (indent-to (+ margin vhdl-basic-offset)))
9692 (goto-char position)))
9693 (vhdl-insert-keyword "WHEN ")))
9695 (defun vhdl-template-while-loop ()
9696 "Insert a while loop."
9698 (let* ((margin (current-indentation))
9701 (if (not (eq vhdl-optional-labels 'all))
9702 (vhdl-insert-keyword "WHILE ")
9703 (vhdl-insert-keyword ": WHILE ")
9705 (setq label (vhdl-template-field "[label]" nil t))
9706 (unless label (delete-char 2))
9709 (when vhdl-conditions-in-parenthesis (insert "("))
9710 (when (vhdl-template-field "condition" nil t start (point))
9711 (when vhdl-conditions-in-parenthesis (insert ")"))
9712 (vhdl-insert-keyword " LOOP\n\n")
9714 (vhdl-insert-keyword "END LOOP")
9715 (insert (if label (concat " " label ";") ";"))
9717 (indent-to (+ margin vhdl-basic-offset)))))
9719 (defun vhdl-template-with ()
9720 "Insert a with statement (i.e. selected signal assignment)."
9722 (vhdl-prepare-search-1
9723 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9724 (equal ";" (match-string 1)))
9725 (vhdl-template-selected-signal-asst)
9726 (vhdl-insert-keyword "WITH "))))
9728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9729 ;; Special templates
9731 (defun vhdl-template-clocked-wait ()
9732 "Insert a wait statement for rising/falling clock edge."
9734 (let ((start (point))
9736 (vhdl-insert-keyword "WAIT UNTIL ")
9738 (or (and (not (equal "" vhdl-clock-name))
9739 (progn (insert vhdl-clock-name) vhdl-clock-name))
9740 (vhdl-template-field "clock name" nil t start (point))))
9742 (vhdl-insert-keyword " AND ")
9745 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9746 (vhdl-comment-insert-inline
9747 (concat (if vhdl-clock-rising-edge "rising" "falling")
9750 (defun vhdl-template-seq-process (clock reset)
9751 "Insert a template for the body of a sequential process."
9752 (let ((margin (current-indentation))
9754 (vhdl-insert-keyword "IF ")
9755 (when (eq vhdl-reset-kind 'async)
9757 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9758 (vhdl-insert-keyword " THEN")
9759 (vhdl-comment-insert-inline
9760 (concat "asynchronous reset (active "
9761 (if vhdl-reset-active-high "high" "low") ")"))
9762 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9763 (setq position (point))
9764 (insert "\n") (indent-to margin)
9765 (vhdl-insert-keyword "ELSIF "))
9766 (if (eq vhdl-clock-edge-condition 'function)
9767 (insert (if vhdl-clock-rising-edge "rising" "falling")
9769 (insert clock "'event")
9770 (vhdl-insert-keyword " AND ")
9772 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9773 (vhdl-insert-keyword " THEN")
9774 (vhdl-comment-insert-inline
9775 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9776 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9777 (when (eq vhdl-reset-kind 'sync)
9778 (vhdl-insert-keyword "IF ")
9779 (setq reset (or (and (not (equal "" vhdl-reset-name))
9780 (progn (insert vhdl-reset-name) vhdl-reset-name))
9781 (vhdl-template-field "reset name") "<reset>"))
9783 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9784 (vhdl-insert-keyword " THEN")
9785 (vhdl-comment-insert-inline
9786 (concat "synchronous reset (active "
9787 (if vhdl-reset-active-high "high" "low") ")"))
9788 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9789 (setq position (point))
9790 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9791 (vhdl-insert-keyword "ELSE")
9792 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9793 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9794 (vhdl-insert-keyword "END IF;"))
9795 (when (eq vhdl-reset-kind 'none)
9796 (setq position (point)))
9797 (insert "\n") (indent-to margin)
9798 (vhdl-insert-keyword "END IF;")
9799 (goto-char position)
9802 (defun vhdl-template-standard-package (library package)
9803 "Insert specification of a standard package. Include a library
9804 specification, if not already there."
9805 (let ((margin (current-indentation)))
9806 (unless (equal library "std")
9807 (unless (or (save-excursion
9808 (vhdl-prepare-search-1
9811 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9812 library "\\|end\\)\\>") nil t)
9814 (equal (downcase library) "work"))
9815 (vhdl-insert-keyword "LIBRARY ")
9816 (insert library ";")
9819 (indent-to margin)))
9821 (vhdl-insert-keyword "USE ")
9822 (insert library "." package)
9823 (vhdl-insert-keyword ".ALL;")))))
9825 (defun vhdl-template-package-math-complex ()
9826 "Insert specification of `math_complex' package."
9828 (vhdl-template-standard-package "ieee" "math_complex"))
9830 (defun vhdl-template-package-math-real ()
9831 "Insert specification of `math_real' package."
9833 (vhdl-template-standard-package "ieee" "math_real"))
9835 (defun vhdl-template-package-numeric-bit ()
9836 "Insert specification of `numeric_bit' package."
9838 (vhdl-template-standard-package "ieee" "numeric_bit"))
9840 (defun vhdl-template-package-numeric-std ()
9841 "Insert specification of `numeric_std' package."
9843 (vhdl-template-standard-package "ieee" "numeric_std"))
9845 (defun vhdl-template-package-std-logic-1164 ()
9846 "Insert specification of `std_logic_1164' package."
9848 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9850 (defun vhdl-template-package-std-logic-arith ()
9851 "Insert specification of `std_logic_arith' package."
9853 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9855 (defun vhdl-template-package-std-logic-misc ()
9856 "Insert specification of `std_logic_misc' package."
9858 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9860 (defun vhdl-template-package-std-logic-signed ()
9861 "Insert specification of `std_logic_signed' package."
9863 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9865 (defun vhdl-template-package-std-logic-textio ()
9866 "Insert specification of `std_logic_textio' package."
9868 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9870 (defun vhdl-template-package-std-logic-unsigned ()
9871 "Insert specification of `std_logic_unsigned' package."
9873 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9875 (defun vhdl-template-package-textio ()
9876 "Insert specification of `textio' package."
9878 (vhdl-template-standard-package "std" "textio"))
9880 (defun vhdl-template-directive (directive)
9882 (unless (= (current-indentation) (current-column))
9883 (delete-horizontal-space)
9885 (insert "-- pragma " directive))
9887 (defun vhdl-template-directive-translate-on ()
9888 "Insert directive 'translate_on'."
9890 (vhdl-template-directive "translate_on"))
9892 (defun vhdl-template-directive-translate-off ()
9893 "Insert directive 'translate_off'."
9895 (vhdl-template-directive "translate_off"))
9897 (defun vhdl-template-directive-synthesis-on ()
9898 "Insert directive 'synthesis_on'."
9900 (vhdl-template-directive "synthesis_on"))
9902 (defun vhdl-template-directive-synthesis-off ()
9903 "Insert directive 'synthesis_off'."
9905 (vhdl-template-directive "synthesis_off"))
9907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9908 ;; Header and footer templates
9910 (defun vhdl-template-header (&optional file-title)
9911 "Insert a VHDL file header."
9913 (unless (equal vhdl-file-header "")
9916 (goto-char (point-min))
9917 (vhdl-insert-string-or-file vhdl-file-header)
9918 (setq pos (point-marker)))
9919 (vhdl-template-replace-header-keywords
9920 (point-min-marker) pos file-title))))
9922 (defun vhdl-template-footer ()
9923 "Insert a VHDL file footer."
9925 (unless (equal vhdl-file-footer "")
9928 (goto-char (point-max))
9929 (setq pos (point-marker))
9930 (vhdl-insert-string-or-file vhdl-file-footer)
9931 (unless (= (preceding-char) ?\n)
9933 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9935 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9937 "Replace keywords in header and footer."
9938 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9939 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9941 (vhdl-prepare-search-2
9944 (while (search-forward "<projectdesc>" end t)
9945 (replace-match project-desc t t))
9947 (while (search-forward "<filename>" end t)
9948 (replace-match (buffer-name) t t))
9950 (while (search-forward "<copyright>" end t)
9951 (replace-match vhdl-copyright-string t t))
9953 (while (search-forward "<author>" end t)
9954 (replace-match "" t t)
9955 (insert (user-full-name))
9956 (when user-mail-address (insert " <" user-mail-address ">")))
9958 (while (search-forward "<login>" end t)
9959 (replace-match (user-login-name) t t))
9961 (while (search-forward "<project>" end t)
9962 (replace-match project-title t t))
9964 (while (search-forward "<company>" end t)
9965 (replace-match vhdl-company-name t t))
9967 (while (search-forward "<platform>" end t)
9968 (replace-match vhdl-platform-spec t t))
9970 (while (search-forward "<standard>" end t)
9972 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9973 ((vhdl-standard-p '93) "'93"))
9974 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9975 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9977 ;; Replace <RCS> with $, so that RCS for the source is
9978 ;; not over-enthusiastic with replacements
9979 (while (search-forward "<RCS>" end t)
9980 (replace-match "$" nil t))
9982 (while (search-forward "<date>" end t)
9983 (replace-match "" t t)
9984 (vhdl-template-insert-date))
9986 (while (search-forward "<year>" end t)
9987 (replace-match (format-time-string "%Y" nil) t t))
9990 (while (search-forward "<title string>" end t)
9991 (replace-match file-title t t))
9995 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9996 (setq string (read-string (concat (match-string 1) ": ")))
9997 (replace-match string t t)))
9999 (when (and (not is-model) (search-forward "<cursor>" end t))
10000 (replace-match "" t t)
10001 (setq pos (point))))
10002 (when pos (goto-char pos))
10004 (when (or (not project-title) (equal project-title ""))
10005 (message "You can specify a project title in user option `vhdl-project-alist'"))
10006 (when (or (not project-desc) (equal project-desc ""))
10007 (message "You can specify a project description in user option `vhdl-project-alist'"))
10008 (when (equal vhdl-platform-spec "")
10009 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10010 (when (equal vhdl-company-name "")
10011 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10014 ;; Comment templates and functions
10016 (defun vhdl-comment-indent ()
10018 (let* ((position (point))
10022 (if (re-search-forward "--" position t)
10023 (- (current-column) 2) ; existing comment at bol stays there
10024 (goto-char position)
10025 (skip-chars-backward " \t")
10026 (max comment-column ; else indent to comment column
10027 (1+ (current-column))))))) ; except leave at least one space
10028 (goto-char position)
10031 (defun vhdl-comment-insert ()
10032 "Start a comment at the end of the line.
10033 If on line with code, indent at least `comment-column'.
10034 If starting after end-comment-column, start a new line."
10036 (when (> (current-column) end-comment-column) (newline-and-indent))
10037 (if (or (looking-at "\\s-*$") ; end of line
10038 (and (not unread-command-events) ; called with key binding or menu
10039 (not (end-of-line))))
10041 (while (= (preceding-char) ?-) (delete-char -1))
10042 (setq margin (current-column))
10043 (delete-horizontal-space)
10045 (progn (indent-to margin) (insert "--"))
10047 (indent-to comment-column)
10049 (if (not unread-command-events) (insert " ")))
10050 ;; else code following current point implies commenting out code
10051 (let (next-input code)
10052 (while (= (preceding-char) ?-) (delete-char -2))
10053 (while (= (setq next-input (read-char)) 13) ; CR
10054 (insert "--") ; or have a space after it?
10057 (message "Enter CR if commenting out a line of code.")
10060 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10061 (setq unread-command-events
10062 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10064 (defun vhdl-comment-display (&optional line-exists)
10065 "Add 2 comment lines at the current indent, making a display comment."
10067 (let ((margin (current-indentation)))
10068 (unless line-exists (vhdl-comment-display-line))
10069 (insert "\n") (indent-to margin)
10070 (insert "\n") (indent-to margin)
10071 (vhdl-comment-display-line)
10075 (defun vhdl-comment-display-line ()
10076 "Displays one line of dashes."
10078 (while (= (preceding-char) ?-) (delete-char -2))
10079 (let* ((col (current-column))
10080 (len (- end-comment-column col)))
10081 (insert-char ?- len)))
10083 (defun vhdl-comment-append-inline ()
10084 "Append empty inline comment to current line."
10087 (delete-horizontal-space)
10089 (indent-to comment-column)
10092 (defun vhdl-comment-insert-inline (&optional string always-insert)
10093 "Insert inline comment."
10094 (when (or (and string (or vhdl-self-insert-comments always-insert))
10095 (and (not string) vhdl-prompt-for-comments))
10096 (let ((position (point)))
10098 (indent-to comment-column)
10100 (if (not (or (and string (progn (insert string) t))
10101 (vhdl-template-field "[comment]" nil t)))
10102 (delete-region position (point))
10103 (while (= (preceding-char) ? ) (delete-backward-char 1))
10104 ; (when (> (current-column) end-comment-column)
10105 ; (setq position (point-marker))
10106 ; (re-search-backward "-- ")
10108 ; (indent-to comment-column)
10109 ; (goto-char position))
10112 (defun vhdl-comment-block ()
10113 "Insert comment for code block."
10114 (when vhdl-prompt-for-comments
10115 (let ((final-pos (point-marker)))
10116 (vhdl-prepare-search-2
10117 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10118 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10120 (back-to-indentation)
10121 (setq margin (current-column))
10124 (progn (insert "\n") (forward-line -1))
10127 (insert "-- purpose: ")
10128 (unless (vhdl-template-field "[description]" nil t)
10129 (vhdl-line-kill-entire)))))
10130 (goto-char final-pos))))
10132 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10133 "Comment out region if not commented out, uncomment otherwise."
10134 (interactive "r\nP")
10136 (goto-char (1- end))
10138 (setq end (point-marker))
10140 (beginning-of-line)
10142 (if (looking-at comment-start)
10143 (comment-region beg end '(4))
10144 (comment-region beg end))))
10146 (defun vhdl-comment-uncomment-line (&optional arg)
10147 "Comment out line if not commented out, uncomment otherwise."
10150 (beginning-of-line)
10151 (let ((position (point)))
10152 (forward-line (or arg 1))
10153 (vhdl-comment-uncomment-region position (point)))))
10155 (defun vhdl-comment-kill-region (beg end)
10156 "Kill comments in region."
10160 (setq end (point-marker))
10162 (beginning-of-line)
10163 (while (< (point) end)
10164 (if (looking-at "^\\(\\s-*--.*\n\\)")
10165 (progn (delete-region (match-beginning 1) (match-end 1)))
10166 (beginning-of-line 2)))))
10168 (defun vhdl-comment-kill-inline-region (beg end)
10169 "Kill inline comments in region."
10173 (setq end (point-marker))
10175 (beginning-of-line)
10176 (while (< (point) end)
10177 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10178 (delete-region (match-beginning 1) (match-end 1)))
10179 (beginning-of-line 2))))
10181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10184 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10185 "Insert a begin ... end pair with optional name after the end.
10186 Point is left between them."
10188 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10190 (vhdl-insert-keyword "BEGIN")
10191 (when (and (or construct name) vhdl-self-insert-comments)
10193 (when construct (insert " ") (vhdl-insert-keyword construct))
10194 (when name (insert " " name)))
10196 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10197 (indent-to (+ margin vhdl-basic-offset))
10198 (setq position (point))
10200 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10202 (vhdl-insert-keyword "END")
10203 (when construct (insert " ") (vhdl-insert-keyword construct))
10204 (insert (if name (concat " " name) "") ";")
10205 (goto-char position)))
10207 (defun vhdl-template-argument-list (&optional is-function)
10208 "Read from user a procedure or function argument list."
10210 (let ((margin (current-column))
10213 not-empty interface semicolon-pos)
10214 (unless vhdl-argument-list-indent
10215 (setq margin (+ (current-indentation) vhdl-basic-offset))
10217 (indent-to margin))
10218 (setq interface (vhdl-template-field
10219 (concat "[CONSTANT | SIGNAL"
10220 (unless is-function " | VARIABLE") "]") " " t))
10221 (while (vhdl-template-field "[names]" nil t)
10224 (unless is-function
10225 (if (and interface (equal (upcase interface) "CONSTANT"))
10226 (vhdl-insert-keyword "IN ")
10227 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10228 (vhdl-template-field "type")
10229 (setq semicolon-pos (point))
10231 (vhdl-comment-insert-inline)
10232 (setq end-pos (point))
10235 (setq interface (vhdl-template-field
10236 (concat "[CONSTANT | SIGNAL"
10237 (unless is-function " | VARIABLE") "]") " " t)))
10238 (delete-region end-pos (point))
10239 (when semicolon-pos (goto-char semicolon-pos))
10241 (progn (delete-char 1) (insert ")"))
10242 (delete-backward-char 2))))
10244 (defun vhdl-template-generic-list (optional &optional no-value)
10245 "Read from user a generic spec argument list."
10248 (vhdl-insert-keyword "GENERIC (")
10249 (setq margin (current-column))
10250 (unless vhdl-argument-list-indent
10251 (let ((position (point)))
10252 (back-to-indentation)
10253 (setq margin (+ (current-column) vhdl-basic-offset))
10254 (goto-char position)
10256 (indent-to margin)))
10257 (let ((vhdl-generics (vhdl-template-field
10258 (concat (and optional "[") "name"
10259 (and no-value "s") (and optional "]"))
10261 (if (not vhdl-generics)
10263 (progn (vhdl-line-kill-entire) (end-of-line -0)
10264 (unless vhdl-argument-list-indent
10265 (vhdl-line-kill-entire) (end-of-line -0)))
10266 (vhdl-template-undo start (point))
10269 (let (semicolon-pos end-pos)
10270 (while vhdl-generics
10271 (vhdl-template-field "type")
10273 (progn (setq semicolon-pos (point))
10276 (unless (vhdl-template-field "[value]" nil t)
10278 (setq semicolon-pos (point))
10280 (vhdl-comment-insert-inline)
10281 (setq end-pos (point))
10284 (setq vhdl-generics (vhdl-template-field
10285 (concat "[name" (and no-value "s") "]")
10287 (delete-region end-pos (point))
10288 (goto-char semicolon-pos)
10291 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10294 (defun vhdl-template-port-list (optional)
10295 "Read from user a port spec argument list."
10296 (let ((start (point))
10297 margin vhdl-ports object)
10298 (vhdl-insert-keyword "PORT (")
10299 (setq margin (current-column))
10300 (unless vhdl-argument-list-indent
10301 (let ((position (point)))
10302 (back-to-indentation)
10303 (setq margin (+ (current-column) vhdl-basic-offset))
10304 (goto-char position)
10306 (indent-to margin)))
10307 (when (vhdl-standard-p 'ams)
10308 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10310 (setq vhdl-ports (vhdl-template-field
10311 (concat (and optional "[") "names" (and optional "]"))
10313 (if (not vhdl-ports)
10315 (progn (vhdl-line-kill-entire) (end-of-line -0)
10316 (unless vhdl-argument-list-indent
10317 (vhdl-line-kill-entire) (end-of-line -0)))
10318 (vhdl-template-undo start (point))
10321 (let (semicolon-pos end-pos)
10323 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10324 (vhdl-template-field "IN | OUT | INOUT" " "))
10325 ((equal "QUANTITY" (upcase object))
10326 (vhdl-template-field "[IN | OUT]" " " t)))
10327 (vhdl-template-field
10328 (if (and object (equal "TERMINAL" (upcase object)))
10330 (setq semicolon-pos (point))
10332 (vhdl-comment-insert-inline)
10333 (setq end-pos (point))
10336 (when (vhdl-standard-p 'ams)
10337 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10339 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10340 (delete-region end-pos (point))
10341 (goto-char semicolon-pos)
10344 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10347 (defun vhdl-template-generate-body (margin label)
10348 "Insert body for generate template."
10349 (vhdl-insert-keyword " GENERATE")
10350 ; (if (not (vhdl-standard-p '87))
10351 ; (vhdl-template-begin-end "GENERATE" label margin)
10354 (vhdl-insert-keyword "END GENERATE ")
10357 (indent-to (+ margin vhdl-basic-offset)))
10359 (defun vhdl-template-insert-date ()
10360 "Insert date in appropriate format."
10364 ;; 'american, 'european, 'scientific kept for backward compatibility
10365 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10366 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10367 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10368 (t (format-time-string vhdl-date-format nil)))))
10370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10373 (defun vhdl-electric-space (count)
10374 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10375 if in comment and past end-comment-column."
10377 (cond ((vhdl-in-comment-p)
10378 (self-insert-command count)
10379 (cond ((>= (current-column) (+ 2 end-comment-column))
10381 (skip-chars-backward "^ \t\n")
10382 (indent-new-comment-line)
10383 (skip-chars-forward "^ \t\n")
10385 ((>= (current-column) end-comment-column)
10386 (indent-new-comment-line))
10388 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10389 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10390 (vhdl-prepare-search-1
10391 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10392 (self-insert-command count))
10393 (t (self-insert-command count))))
10395 (defun vhdl-template-field (prompt &optional follow-string optional
10396 begin end is-string default)
10397 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10398 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10399 an empty string is inserted, return nil and call `vhdl-template-undo' for
10400 the region between BEGIN and END. IS-STRING indicates whether a string
10401 with double-quotes is to be inserted. DEFAULT specifies a default string."
10402 (let ((position (point))
10404 (insert "<" prompt ">")
10407 (read-from-minibuffer (concat prompt ": ")
10408 (or (and is-string '("\"\"" . 2)) default)
10409 vhdl-minibuffer-local-map)
10410 (quit (if (and optional begin end)
10412 (keyboard-quit)))))
10413 (when (or (not (equal string "")) optional)
10414 (delete-region position (point)))
10415 (when (and (equal string "") optional begin end)
10416 (vhdl-template-undo begin end)
10417 (message "Template aborted"))
10418 (unless (equal string "")
10420 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10421 vhdl-keywords-regexp)
10422 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10424 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10425 (concat "'" vhdl-attributes-regexp))
10426 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10427 vhdl-enum-values-regexp))
10428 (when (or (not (equal string "")) (not optional))
10429 (insert (or follow-string "")))
10430 (if (equal string "") nil string)))
10432 (defun vhdl-decision-query (string prompt &optional optional)
10433 "Query a decision from the user."
10434 (let ((start (point)))
10435 (when string (vhdl-insert-keyword (concat string " ")))
10436 (message "%s" (or prompt ""))
10437 (let ((char (read-char)))
10438 (delete-region start (point))
10439 (if (and optional (eq char ?\r))
10440 (progn (insert " ")
10442 (throw 'abort "ERROR: Template aborted"))
10445 (defun vhdl-insert-keyword (keyword)
10446 "Insert KEYWORD and adjust case."
10447 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10449 (defun vhdl-case-keyword (keyword)
10450 "Adjust case of KEYWORD."
10451 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10453 (defun vhdl-case-word (num)
10454 "Adjust case of following NUM words."
10455 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10457 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10458 "If preceeding character is part of a word or a paren then hippie-expand,
10459 else insert tab (used for word completion in VHDL minibuffer)."
10463 ((= (char-syntax (preceding-char)) ?w)
10464 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10466 (hippie-expand-only-buffers
10467 (or (and (boundp 'hippie-expand-only-buffers)
10468 hippie-expand-only-buffers)
10470 (vhdl-expand-abbrev prefix-arg)))
10471 ;; expand parenthesis
10472 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10473 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10474 (case-replace nil))
10475 (vhdl-expand-paren prefix-arg)))
10479 (defun vhdl-template-search-prompt ()
10480 "Search for left out template prompts and query again."
10482 (vhdl-prepare-search-2
10483 (when (or (re-search-forward
10484 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10485 (re-search-backward
10486 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10487 (let ((string (match-string 1)))
10489 (vhdl-template-field string)))))
10491 (defun vhdl-template-undo (begin end)
10492 "Undo aborted template by deleting region and unexpanding the keyword."
10493 (cond (vhdl-template-invoked-by-hook
10496 (delete-region begin end)
10498 (t (delete-region begin end))))
10500 (defun vhdl-insert-string-or-file (string)
10501 "Insert STRING or file contents if STRING is an existing file name."
10502 (unless (equal string "")
10504 (progn (string-match "^\\([^\n]+\\)" string)
10505 (vhdl-resolve-env-variable (match-string 1 string)))))
10506 (if (file-exists-p file-name)
10507 (forward-char (cadr (insert-file-contents file-name)))
10508 (insert string)))))
10510 (defun vhdl-beginning-of-block ()
10511 "Move cursor to the beginning of the enclosing block."
10514 (beginning-of-line)
10515 ;; search backward for block beginning or end
10516 (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))
10517 ;; not consider subprogram declarations
10518 (or (and (match-string 5)
10521 (goto-char (match-end 5))
10523 (vhdl-forward-syntactic-ws)
10524 (when (looking-at "(")
10526 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10528 ;; not consider configuration specifications
10529 (and (match-string 6)
10532 (vhdl-end-of-block)
10533 (beginning-of-line)
10534 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10536 ;; skip subblock if block end found
10537 (vhdl-beginning-of-block)))
10538 (when pos (goto-char pos))))
10540 (defun vhdl-end-of-block ()
10541 "Move cursor to the end of the enclosing block."
10545 ;; search forward for block beginning or end
10546 (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))
10547 ;; not consider subprogram declarations
10548 (or (and (match-string 5)
10550 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10552 ;; not consider configuration specifications
10553 (and (match-string 6)
10556 (vhdl-end-of-block)
10557 (beginning-of-line)
10558 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10559 (not (match-string 2)))
10560 ;; skip subblock if block beginning found
10561 (vhdl-end-of-block)))
10562 (when pos (goto-char pos))))
10564 (defun vhdl-sequential-statement-p ()
10565 "Check if point is within sequential statement part."
10566 (let ((start (point)))
10568 (vhdl-prepare-search-2
10569 ;; is sequential statement if ...
10570 (and (re-search-backward "^\\s-*begin\\>" nil t)
10571 ;; ... point is between "begin" and "end" of ...
10572 (progn (vhdl-end-of-block)
10574 ;; ... a sequential block
10575 (progn (vhdl-beginning-of-block)
10576 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10578 (defun vhdl-in-argument-list-p ()
10579 "Check if within an argument list."
10581 (vhdl-prepare-search-2
10582 (or (string-match "arglist"
10583 (format "%s" (caar (vhdl-get-syntactic-context))))
10584 (progn (beginning-of-line)
10585 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10590 (defun vhdl-hooked-abbrev (func)
10591 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10592 but not if inside a comment or quote."
10593 (if (or (vhdl-in-literal)
10596 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10601 (if (not vhdl-electric-mode)
10608 (let ((invoke-char last-command-char)
10610 (vhdl-template-invoked-by-hook t))
10611 (let ((caught (catch 'abort
10613 (when (stringp caught) (message "%s" caught)))
10614 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10615 ;; delete CR which is still in event queue
10616 (if (fboundp 'enqueue-eval-event)
10617 (enqueue-eval-event 'delete-char -1)
10618 (setq unread-command-events ; push back a delete char
10619 (list (vhdl-character-to-event ?\177))))))))
10621 (defun vhdl-template-alias-hook ()
10622 (vhdl-hooked-abbrev 'vhdl-template-alias))
10623 (defun vhdl-template-architecture-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10625 (defun vhdl-template-assert-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-assert))
10627 (defun vhdl-template-attribute-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10629 (defun vhdl-template-block-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-block))
10631 (defun vhdl-template-break-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-break))
10633 (defun vhdl-template-case-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-case))
10635 (defun vhdl-template-component-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-component))
10637 (defun vhdl-template-instance-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-instance))
10639 (defun vhdl-template-conditional-signal-asst-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10641 (defun vhdl-template-configuration-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10643 (defun vhdl-template-constant-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-constant))
10645 (defun vhdl-template-disconnect-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10647 (defun vhdl-template-display-comment-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-comment-display))
10649 (defun vhdl-template-else-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-else))
10651 (defun vhdl-template-elsif-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10653 (defun vhdl-template-entity-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-entity))
10655 (defun vhdl-template-exit-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-exit))
10657 (defun vhdl-template-file-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-file))
10659 (defun vhdl-template-for-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-for))
10661 (defun vhdl-template-function-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-function))
10663 (defun vhdl-template-generic-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-generic))
10665 (defun vhdl-template-group-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-group))
10667 (defun vhdl-template-library-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-library))
10669 (defun vhdl-template-limit-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-limit))
10671 (defun vhdl-template-if-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-if))
10673 (defun vhdl-template-bare-loop-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10675 (defun vhdl-template-map-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-map))
10677 (defun vhdl-template-nature-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-nature))
10679 (defun vhdl-template-next-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-next))
10681 (defun vhdl-template-others-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-others))
10683 (defun vhdl-template-package-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-package))
10685 (defun vhdl-template-port-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-port))
10687 (defun vhdl-template-procedural-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10689 (defun vhdl-template-procedure-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10691 (defun vhdl-template-process-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-process))
10693 (defun vhdl-template-quantity-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10695 (defun vhdl-template-report-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-report))
10697 (defun vhdl-template-return-hook ()
10698 (vhdl-hooked-abbrev 'vhdl-template-return))
10699 (defun vhdl-template-selected-signal-asst-hook ()
10700 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10701 (defun vhdl-template-signal-hook ()
10702 (vhdl-hooked-abbrev 'vhdl-template-signal))
10703 (defun vhdl-template-subnature-hook ()
10704 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10705 (defun vhdl-template-subtype-hook ()
10706 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10707 (defun vhdl-template-terminal-hook ()
10708 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10709 (defun vhdl-template-type-hook ()
10710 (vhdl-hooked-abbrev 'vhdl-template-type))
10711 (defun vhdl-template-use-hook ()
10712 (vhdl-hooked-abbrev 'vhdl-template-use))
10713 (defun vhdl-template-variable-hook ()
10714 (vhdl-hooked-abbrev 'vhdl-template-variable))
10715 (defun vhdl-template-wait-hook ()
10716 (vhdl-hooked-abbrev 'vhdl-template-wait))
10717 (defun vhdl-template-when-hook ()
10718 (vhdl-hooked-abbrev 'vhdl-template-when))
10719 (defun vhdl-template-while-loop-hook ()
10720 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10721 (defun vhdl-template-with-hook ()
10722 (vhdl-hooked-abbrev 'vhdl-template-with))
10723 (defun vhdl-template-and-hook ()
10724 (vhdl-hooked-abbrev 'vhdl-template-and))
10725 (defun vhdl-template-or-hook ()
10726 (vhdl-hooked-abbrev 'vhdl-template-or))
10727 (defun vhdl-template-nand-hook ()
10728 (vhdl-hooked-abbrev 'vhdl-template-nand))
10729 (defun vhdl-template-nor-hook ()
10730 (vhdl-hooked-abbrev 'vhdl-template-nor))
10731 (defun vhdl-template-xor-hook ()
10732 (vhdl-hooked-abbrev 'vhdl-template-xor))
10733 (defun vhdl-template-xnor-hook ()
10734 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10735 (defun vhdl-template-not-hook ()
10736 (vhdl-hooked-abbrev 'vhdl-template-not))
10738 (defun vhdl-template-default-hook ()
10739 (vhdl-hooked-abbrev 'vhdl-template-default))
10740 (defun vhdl-template-default-indent-hook ()
10741 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10744 ;; Template insertion from completion list
10746 (defun vhdl-template-insert-construct (name)
10747 "Insert the built-in construct template with NAME."
10749 (list (let ((completion-ignore-case t))
10750 (completing-read "Construct name: "
10751 vhdl-template-construct-alist nil t))))
10752 (vhdl-template-insert-fun
10753 (cadr (assoc name vhdl-template-construct-alist))))
10755 (defun vhdl-template-insert-package (name)
10756 "Insert the built-in package template with NAME."
10758 (list (let ((completion-ignore-case t))
10759 (completing-read "Package name: "
10760 vhdl-template-package-alist nil t))))
10761 (vhdl-template-insert-fun
10762 (cadr (assoc name vhdl-template-package-alist))))
10764 (defun vhdl-template-insert-directive (name)
10765 "Insert the built-in directive template with NAME."
10767 (list (let ((completion-ignore-case t))
10768 (completing-read "Directive name: "
10769 vhdl-template-directive-alist nil t))))
10770 (vhdl-template-insert-fun
10771 (cadr (assoc name vhdl-template-directive-alist))))
10773 (defun vhdl-template-insert-fun (fun)
10774 "Call FUN to insert a built-in template."
10775 (let ((caught (catch 'abort (when fun (funcall fun)))))
10776 (when (stringp caught) (message "%s" caught))))
10779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10783 (defun vhdl-model-insert (model-name)
10784 "Insert the user model with name MODEL-NAME."
10786 (let ((completion-ignore-case t))
10787 (list (completing-read "Model name: " vhdl-model-alist))))
10788 (indent-according-to-mode)
10789 (let ((start (point-marker))
10790 (margin (current-indentation))
10791 model position prompt string end)
10792 (vhdl-prepare-search-2
10793 (when (setq model (assoc model-name vhdl-model-alist))
10795 (beginning-of-line)
10796 (delete-horizontal-space)
10798 (vhdl-insert-string-or-file (nth 1 model))
10799 (setq end (point-marker))
10802 (beginning-of-line)
10803 (while (< (point) end)
10804 (unless (looking-at "^$")
10805 (insert-char ? margin))
10806 (beginning-of-line 2))
10809 (unless (equal "" vhdl-clock-name)
10810 (while (re-search-forward "<clock>" end t)
10811 (replace-match vhdl-clock-name)))
10814 (unless (equal "" vhdl-reset-name)
10815 (while (re-search-forward "<reset>" end t)
10816 (replace-match vhdl-reset-name)))
10817 ;; replace header prompts
10818 (vhdl-template-replace-header-keywords start end nil t)
10820 ;; query other prompts
10821 (while (re-search-forward
10822 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10823 (unless (equal "cursor" (match-string 1))
10824 (setq position (match-beginning 1))
10825 (setq prompt (match-string 1))
10827 (setq string (vhdl-template-field prompt nil t))
10828 ;; replace occurrences of same prompt
10829 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10830 (replace-match (or string "")))
10831 (goto-char position)))
10833 ;; goto final position
10834 (if (re-search-forward "<cursor>" end t)
10836 (goto-char end))))))
10838 (defun vhdl-model-defun ()
10839 "Define help and hook functions for user models."
10840 (let ((model-alist vhdl-model-alist)
10841 model-name model-keyword)
10843 ;; define functions for user models that can be invoked from menu and key
10844 ;; bindings and which themselves call `vhdl-model-insert' with the model
10845 ;; name as argument
10846 (setq model-name (nth 0 (car model-alist)))
10847 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10848 ,(concat "Insert model for \"" model-name "\".")
10850 (vhdl-model-insert ,model-name)))
10851 ;; define hooks for user models that are invoked from keyword abbrevs
10852 (setq model-keyword (nth 3 (car model-alist)))
10853 (unless (equal model-keyword "")
10855 ,(vhdl-function-name
10856 "vhdl-model" model-name "hook") ()
10857 (vhdl-hooked-abbrev
10858 ',(vhdl-function-name "vhdl-model" model-name)))))
10859 (setq model-alist (cdr model-alist)))))
10864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10865 ;;; Port translation
10866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10868 (defvar vhdl-port-list nil
10869 "Variable to hold last port map parsed.")
10870 ;; structure: (parenthesised expression means list of such entries)
10872 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10873 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10874 ;; (lib-name pack-key))
10876 (defun vhdl-parse-string (string &optional optional)
10877 "Check that the text following point matches the regexp in STRING."
10878 (if (looking-at string)
10879 (goto-char (match-end 0))
10881 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10882 (vhdl-current-line) string)))
10885 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10886 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10887 (vhdl-prepare-search-1
10888 (if (string-match (car regexp-cons) string)
10890 (funcall vhdl-file-name-case
10891 (replace-match (cdr regexp-cons) t nil string))
10892 (replace-match (cdr regexp-cons) t nil string))
10895 (defun vhdl-parse-group-comment ()
10896 "Parse comment and empty lines between groups of lines."
10897 (let ((start (point))
10899 (vhdl-forward-comment (point-max))
10900 (setq string (buffer-substring-no-properties start (point)))
10901 (vhdl-forward-syntactic-ws)
10902 ;; strip off leading blanks and first newline
10903 (while (string-match "^\\(\\s-+\\)" string)
10904 (setq string (concat (substring string 0 (match-beginning 1))
10905 (substring string (match-end 1)))))
10906 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10907 (substring string 1)
10910 (defun vhdl-paste-group-comment (string indent)
10911 "Paste comment and empty lines from STRING between groups of lines
10913 (let ((pos (point-marker)))
10915 (while (string-match "^\\(--\\)" string)
10916 (setq string (concat (substring string 0 (match-beginning 1))
10917 (make-string indent ? )
10918 (substring string (match-beginning 1))))))
10919 (beginning-of-line)
10923 (defvar vhdl-port-flattened nil
10924 "Indicates whether a port has been flattened.")
10926 (defun vhdl-port-flatten (&optional as-alist)
10927 "Flatten port list so that only one generic/port exists per line.
10928 This operation is performed on an internally stored port and is only
10929 reflected in a subsequent paste operation."
10931 (if (not vhdl-port-list)
10932 (error "ERROR: No port has been read")
10933 (message "Flattening port for next paste...")
10934 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10935 (old-vhdl-port-list (cdr vhdl-port-list))
10936 old-port-list new-port-list old-port new-port names)
10937 ;; traverse port list and flatten entries
10938 (while (cdr old-vhdl-port-list)
10939 (setq old-port-list (car old-vhdl-port-list))
10940 (setq new-port-list nil)
10941 (while old-port-list
10942 (setq old-port (car old-port-list))
10943 (setq names (car old-port))
10945 (setq new-port (cons (if as-alist (car names) (list (car names)))
10947 (setq new-port-list (append new-port-list (list new-port)))
10948 (setq names (cdr names)))
10949 (setq old-port-list (cdr old-port-list)))
10950 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10951 (setq new-vhdl-port-list (append new-vhdl-port-list
10952 (list new-port-list))))
10953 (setq vhdl-port-list
10954 (append new-vhdl-port-list (list old-vhdl-port-list))
10955 vhdl-port-flattened t)
10956 (message "Flattening port for next paste...done"))))
10958 (defvar vhdl-port-reversed-direction nil
10959 "Indicates whether port directions are reversed.")
10961 (defun vhdl-port-reverse-direction ()
10962 "Reverse direction for all ports (useful in testbenches).
10963 This operation is performed on an internally stored port and is only
10964 reflected in a subsequent paste operation."
10966 (if (not vhdl-port-list)
10967 (error "ERROR: No port has been read")
10968 (message "Reversing port directions for next paste...")
10969 (let ((port-list (nth 2 vhdl-port-list))
10970 port-dir-car port-dir)
10971 ;; traverse port list and reverse directions
10973 (setq port-dir-car (cddr (car port-list))
10974 port-dir (car port-dir-car))
10975 (setcar port-dir-car
10976 (cond ((equal port-dir "in") "out")
10977 ((equal port-dir "out") "in")
10979 (setq port-list (cdr port-list)))
10980 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10981 (message "Reversing port directions for next paste...done"))))
10983 (defun vhdl-port-copy ()
10984 "Get generic and port information from an entity or component declaration."
10987 (let (parse-error end-of-list
10988 decl-type name generic-list port-list context-clause
10989 object names direct type init comment group-comment)
10990 (vhdl-prepare-search-2
10994 ;; check if within entity or component declaration
10996 (when (or (not (re-search-backward
10997 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10998 (equal "END" (upcase (match-string 1))))
10999 (throw 'parse "ERROR: Not within an entity or component declaration"))
11000 (setq decl-type (downcase (match-string-no-properties 1)))
11002 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11003 (setq name (match-string-no-properties 1))
11004 (message "Reading port of %s \"%s\"..." decl-type name)
11005 (vhdl-forward-syntactic-ws)
11006 ;; parse generic clause
11007 (when (vhdl-parse-string "generic[ \t\n]*(" t)
11008 ;; parse group comment and spacing
11009 (setq group-comment (vhdl-parse-group-comment))
11010 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11011 (while (not end-of-list)
11012 ;; parse names (accept extended identifiers)
11013 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11014 (setq names (list (match-string-no-properties 1)))
11015 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11017 (append names (list (match-string-no-properties 1)))))
11019 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11020 (setq type (match-string-no-properties 1))
11022 (while (looking-at "(")
11025 (buffer-substring-no-properties
11026 (point) (progn (forward-sexp) (point)))
11027 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11028 (match-string-no-properties 1)))))
11029 ;; special case: closing parenthesis is on separate line
11030 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11031 (setq comment (substring type (match-beginning 2)))
11032 (setq type (substring type 0 (match-beginning 1))))
11033 ;; strip of trailing group-comment
11034 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11035 (setq type (substring type 0 (match-end 1)))
11036 ;; parse initialization expression
11038 (when (vhdl-parse-string ":=[ \t\n]*" t)
11039 (vhdl-parse-string "\\([^();\n]*\\)")
11040 (setq init (match-string-no-properties 1))
11041 (while (looking-at "(")
11044 (buffer-substring-no-properties
11045 (point) (progn (forward-sexp) (point)))
11046 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11047 (match-string-no-properties 1))))))
11048 ;; special case: closing parenthesis is on separate line
11049 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11050 (setq comment (substring init (match-beginning 2)))
11051 (setq init (substring init 0 (match-beginning 1)))
11052 (vhdl-forward-syntactic-ws))
11053 (skip-chars-forward " \t")
11054 ;; parse inline comment, special case: as above, no initial.
11056 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11057 (match-string-no-properties 1))))
11058 (vhdl-forward-syntactic-ws)
11059 (setq end-of-list (vhdl-parse-string ")" t))
11060 (vhdl-parse-string "\\s-*;\\s-*")
11061 ;; parse inline comment
11063 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11064 (match-string-no-properties 1))))
11065 ;; save everything in list
11066 (setq generic-list (append generic-list
11067 (list (list names type init
11068 comment group-comment))))
11069 ;; parse group comment and spacing
11070 (setq group-comment (vhdl-parse-group-comment))))
11071 ;; parse port clause
11072 (when (vhdl-parse-string "port[ \t\n]*(" t)
11073 ;; parse group comment and spacing
11074 (setq group-comment (vhdl-parse-group-comment))
11075 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11076 (while (not end-of-list)
11079 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11080 (match-string-no-properties 1)))
11081 ;; parse names (accept extended identifiers)
11082 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11083 (setq names (list (match-string-no-properties 1)))
11084 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11085 (setq names (append names (list (match-string-no-properties 1)))))
11087 (vhdl-parse-string ":[ \t\n]*")
11089 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11090 (match-string-no-properties 1)))
11092 (vhdl-parse-string "\\([^();\n]+\\)")
11093 (setq type (match-string-no-properties 1))
11095 (while (looking-at "(")
11096 (setq type (concat type
11097 (buffer-substring-no-properties
11098 (point) (progn (forward-sexp) (point)))
11099 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11100 (match-string-no-properties 1)))))
11101 ;; special case: closing parenthesis is on separate line
11102 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11103 (setq comment (substring type (match-beginning 2)))
11104 (setq type (substring type 0 (match-beginning 1))))
11105 ;; strip of trailing group-comment
11106 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11107 (setq type (substring type 0 (match-end 1)))
11108 (vhdl-forward-syntactic-ws)
11109 (setq end-of-list (vhdl-parse-string ")" t))
11110 (vhdl-parse-string "\\s-*;\\s-*")
11111 ;; parse inline comment
11113 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11114 (match-string-no-properties 1))))
11115 ;; save everything in list
11116 (setq port-list (append port-list
11117 (list (list names object direct type
11118 comment group-comment))))
11119 ;; parse group comment and spacing
11120 (setq group-comment (vhdl-parse-group-comment))))
11121 ; (vhdl-parse-string "end\\>")
11122 ;; parse context clause
11123 (setq context-clause (vhdl-scan-context-clause))
11124 ; ;; add surrounding package to context clause
11125 ; (when (and (equal decl-type "component")
11126 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11127 ; (setq context-clause
11128 ; (append context-clause
11129 ; (list (cons (vhdl-work-library)
11130 ; (match-string-no-properties 1))))))
11131 (message "Reading port of %s \"%s\"...done" decl-type name)
11135 (error parse-error)
11136 (setq vhdl-port-list (list name generic-list port-list context-clause)
11137 vhdl-port-reversed-direction nil
11138 vhdl-port-flattened nil)))))
11140 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11141 "Paste a context clause."
11142 (let ((margin (current-indentation))
11143 (clause-list (nth 3 vhdl-port-list))
11146 (setq clause (car clause-list))
11147 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11148 (downcase exclude-pack-name)))
11150 (re-search-backward
11151 (concat "^\\s-*use\\s-+" (car clause)
11152 "\." (cdr clause) "\\>") nil t)))
11153 (vhdl-template-standard-package (car clause) (cdr clause))
11155 (setq clause-list (cdr clause-list)))))
11157 (defun vhdl-port-paste-generic (&optional no-init)
11158 "Paste a generic clause."
11159 (let ((margin (current-indentation))
11160 (generic-list (nth 1 vhdl-port-list))
11161 list-margin start names generic)
11162 ;; paste generic clause
11164 (setq start (point))
11165 (vhdl-insert-keyword "GENERIC (")
11166 (unless vhdl-argument-list-indent
11167 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11168 (setq list-margin (current-column))
11169 (while generic-list
11170 (setq generic (car generic-list))
11171 ;; paste group comment and spacing
11172 (when (memq vhdl-include-group-comments '(decl always))
11173 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11175 (setq names (nth 0 generic))
11177 (insert (car names))
11178 (setq names (cdr names))
11179 (when names (insert ", ")))
11181 (insert " : " (nth 1 generic))
11182 ;; paste initialization
11183 (when (and (not no-init) (nth 2 generic))
11184 (insert " := " (nth 2 generic)))
11185 (unless (cdr generic-list) (insert ")"))
11188 (when (and vhdl-include-port-comments (nth 3 generic))
11189 (vhdl-comment-insert-inline (nth 3 generic) t))
11190 (setq generic-list (cdr generic-list))
11191 (when generic-list (insert "\n") (indent-to list-margin)))
11192 ;; align generic clause
11193 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11195 (defun vhdl-port-paste-port ()
11196 "Paste a port clause."
11197 (let ((margin (current-indentation))
11198 (port-list (nth 2 vhdl-port-list))
11199 list-margin start names port)
11200 ;; paste port clause
11202 (setq start (point))
11203 (vhdl-insert-keyword "PORT (")
11204 (unless vhdl-argument-list-indent
11205 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11206 (setq list-margin (current-column))
11208 (setq port (car port-list))
11209 ;; paste group comment and spacing
11210 (when (memq vhdl-include-group-comments '(decl always))
11211 (vhdl-paste-group-comment (nth 5 port) list-margin))
11213 (when (nth 1 port) (insert (nth 1 port) " "))
11215 (setq names (nth 0 port))
11217 (insert (car names))
11218 (setq names (cdr names))
11219 (when names (insert ", ")))
11222 (when (nth 2 port) (insert (nth 2 port) " "))
11224 (insert (nth 3 port))
11225 (unless (cdr port-list) (insert ")"))
11228 (when (and vhdl-include-port-comments (nth 4 port))
11229 (vhdl-comment-insert-inline (nth 4 port) t))
11230 (setq port-list (cdr port-list))
11231 (when port-list (insert "\n") (indent-to list-margin)))
11232 ;; align port clause
11233 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11235 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11236 "Paste as an entity or component declaration."
11237 (unless no-indent (indent-according-to-mode))
11238 (let ((margin (current-indentation))
11239 (name (nth 0 vhdl-port-list)))
11240 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11242 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11243 (vhdl-insert-keyword " IS"))
11244 ;; paste generic and port clause
11245 (when (nth 1 vhdl-port-list)
11247 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11249 (indent-to (+ margin vhdl-basic-offset))
11250 (vhdl-port-paste-generic (eq kind 'component)))
11251 (when (nth 2 vhdl-port-list)
11253 (when (and (memq vhdl-insert-empty-lines '(unit all))
11256 (indent-to (+ margin vhdl-basic-offset)))
11257 (vhdl-port-paste-port)
11259 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11262 (vhdl-insert-keyword "END")
11263 (if (eq kind 'entity)
11265 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11267 (vhdl-insert-keyword " COMPONENT")
11268 (unless (vhdl-standard-p '87) (insert " " name)))
11271 (defun vhdl-port-paste-entity (&optional no-indent)
11272 "Paste as an entity declaration."
11274 (if (not vhdl-port-list)
11275 (error "ERROR: No port read")
11276 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11277 (vhdl-port-paste-declaration 'entity no-indent)
11278 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11280 (defun vhdl-port-paste-component (&optional no-indent)
11281 "Paste as a component declaration."
11283 (if (not vhdl-port-list)
11284 (error "ERROR: No port read")
11285 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11286 (vhdl-port-paste-declaration 'component no-indent)
11287 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11289 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11290 "Paste as a generic map."
11292 (unless secondary (indent-according-to-mode))
11293 (let ((margin (current-indentation))
11294 list-margin start generic
11295 (generic-list (nth 1 vhdl-port-list)))
11297 (setq start (point))
11298 (vhdl-insert-keyword "GENERIC MAP (")
11299 (if (not vhdl-association-list-with-formals)
11300 ;; paste list of actual generics
11301 (while generic-list
11302 (insert (if no-constants
11303 (car (nth 0 (car generic-list)))
11304 (or (nth 2 (car generic-list)) " ")))
11305 (setq generic-list (cdr generic-list))
11306 (insert (if generic-list ", " ")"))
11307 (when (and (not generic-list) secondary
11308 (null (nth 2 vhdl-port-list)))
11310 (unless vhdl-argument-list-indent
11311 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11312 (setq list-margin (current-column))
11313 (while generic-list
11314 (setq generic (car generic-list))
11315 ;; paste group comment and spacing
11316 (when (eq vhdl-include-group-comments 'always)
11317 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11318 ;; paste formal and actual generic
11319 (insert (car (nth 0 generic)) " => "
11321 (car (nth 0 generic))
11322 (or (nth 2 generic) "")))
11323 (setq generic-list (cdr generic-list))
11324 (insert (if generic-list "," ")"))
11325 (when (and (not generic-list) secondary
11326 (null (nth 2 vhdl-port-list)))
11329 (when (or vhdl-include-type-comments
11330 (and vhdl-include-port-comments (nth 3 generic)))
11331 (vhdl-comment-insert-inline
11333 (when vhdl-include-type-comments
11334 (concat "[" (nth 1 generic) "] "))
11335 (when vhdl-include-port-comments (nth 3 generic))) t))
11336 (when generic-list (insert "\n") (indent-to list-margin)))
11337 ;; align generic map
11338 (when vhdl-auto-align
11339 (vhdl-align-region-groups start (point) 1 t))))))
11341 (defun vhdl-port-paste-port-map ()
11342 "Paste as a port map."
11343 (let ((margin (current-indentation))
11344 list-margin start port
11345 (port-list (nth 2 vhdl-port-list)))
11347 (setq start (point))
11348 (vhdl-insert-keyword "PORT MAP (")
11349 (if (not vhdl-association-list-with-formals)
11350 ;; paste list of actual ports
11352 (insert (vhdl-replace-string vhdl-actual-port-name
11353 (car (nth 0 (car port-list)))))
11354 (setq port-list (cdr port-list))
11355 (insert (if port-list ", " ")")))
11356 (unless vhdl-argument-list-indent
11357 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11358 (setq list-margin (current-column))
11360 (setq port (car port-list))
11361 ;; paste group comment and spacing
11362 (when (eq vhdl-include-group-comments 'always)
11363 (vhdl-paste-group-comment (nth 5 port) list-margin))
11364 ;; paste formal and actual port
11365 (insert (car (nth 0 port)) " => ")
11366 (insert (vhdl-replace-string vhdl-actual-port-name
11367 (car (nth 0 port))))
11368 (setq port-list (cdr port-list))
11369 (insert (if port-list "," ");"))
11371 (when (or vhdl-include-direction-comments
11372 vhdl-include-type-comments
11373 (and vhdl-include-port-comments (nth 4 port)))
11374 (vhdl-comment-insert-inline
11376 (cond ((and vhdl-include-direction-comments
11377 vhdl-include-type-comments)
11378 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11379 (nth 3 port) "] "))
11380 ((and vhdl-include-direction-comments (nth 2 port))
11381 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11382 (vhdl-include-direction-comments " ")
11383 (vhdl-include-type-comments
11384 (concat "[" (nth 3 port) "] ")))
11385 (when vhdl-include-port-comments (nth 4 port))) t))
11386 (when port-list (insert "\n") (indent-to list-margin)))
11387 ;; align port clause
11388 (when vhdl-auto-align
11389 (vhdl-align-region-groups start (point) 1))))))
11391 (defun vhdl-port-paste-instance (&optional name no-indent title)
11392 "Paste as an instantiation."
11394 (if (not vhdl-port-list)
11395 (error "ERROR: No port read")
11396 (let ((orig-vhdl-port-list vhdl-port-list))
11397 ;; flatten local copy of port list (must be flat for port mapping)
11398 (vhdl-port-flatten)
11399 (unless no-indent (indent-according-to-mode))
11400 (let ((margin (current-indentation)))
11401 ;; paste instantiation
11404 ((equal (cdr vhdl-instance-name) "")
11405 (setq name (vhdl-template-field "instance name")))
11406 ((string-match "\%d" (cdr vhdl-instance-name))
11408 (while (save-excursion
11409 (setq name (format (vhdl-replace-string
11411 (nth 0 vhdl-port-list)) n))
11412 (goto-char (point-min))
11413 (vhdl-re-search-forward name nil t))
11416 (t (insert (vhdl-replace-string vhdl-instance-name
11417 (nth 0 vhdl-port-list)))))
11418 (message "Pasting port as instantiation \"%s\"..." name)
11422 (beginning-of-line)
11423 (indent-to vhdl-basic-offset)
11424 (insert "-- instance \"" name "\"\n")))
11425 (if (not (vhdl-use-direct-instantiation))
11426 (insert (nth 0 vhdl-port-list))
11427 (vhdl-insert-keyword "ENTITY ")
11428 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11429 (when (nth 1 vhdl-port-list)
11430 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11431 (vhdl-port-paste-generic-map t t))
11432 (when (nth 2 vhdl-port-list)
11433 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11434 (vhdl-port-paste-port-map))
11435 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11437 (message "Pasting port as instantiation \"%s\"...done" name))
11438 (setq vhdl-port-list orig-vhdl-port-list))))
11440 (defun vhdl-port-paste-constants (&optional no-indent)
11441 "Paste generics as constants."
11443 (if (not vhdl-port-list)
11444 (error "ERROR: No port read")
11445 (let ((orig-vhdl-port-list vhdl-port-list))
11446 (message "Pasting port as constants...")
11447 ;; flatten local copy of port list (must be flat for constant initial.)
11448 (vhdl-port-flatten)
11449 (unless no-indent (indent-according-to-mode))
11450 (let ((margin (current-indentation))
11452 (generic-list (nth 1 vhdl-port-list)))
11454 (setq start (point))
11455 (while generic-list
11456 (setq generic (car generic-list))
11457 ;; paste group comment and spacing
11458 (when (memq vhdl-include-group-comments '(decl always))
11459 (vhdl-paste-group-comment (nth 4 generic) margin))
11460 (vhdl-insert-keyword "CONSTANT ")
11461 ;; paste generic constants
11462 (setq name (nth 0 generic))
11464 (insert (car name))
11466 (insert " : " (nth 1 generic))
11467 ;; paste initialization
11468 (when (nth 2 generic)
11469 (insert " := " (nth 2 generic)))
11472 (when (and vhdl-include-port-comments (nth 3 generic))
11473 (vhdl-comment-insert-inline (nth 3 generic) t))
11474 (setq generic-list (cdr generic-list))
11475 (when generic-list (insert "\n") (indent-to margin))))
11476 ;; align signal list
11477 (when vhdl-auto-align
11478 (vhdl-align-region-groups start (point) 1))))
11479 (message "Pasting port as constants...done")
11480 (setq vhdl-port-list orig-vhdl-port-list))))
11482 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11483 "Paste ports as internal signals."
11485 (if (not vhdl-port-list)
11486 (error "ERROR: No port read")
11487 (message "Pasting port as signals...")
11488 (unless no-indent (indent-according-to-mode))
11489 (let ((margin (current-indentation))
11491 (port-list (nth 2 vhdl-port-list)))
11493 (setq start (point))
11495 (setq port (car port-list))
11496 ;; paste group comment and spacing
11497 (when (memq vhdl-include-group-comments '(decl always))
11498 (vhdl-paste-group-comment (nth 5 port) margin))
11501 (insert (nth 1 port) " ")
11502 (vhdl-insert-keyword "SIGNAL "))
11503 ;; paste actual port signals
11504 (setq names (nth 0 port))
11506 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11507 (setq names (cdr names))
11508 (when names (insert ", ")))
11510 (insert " : " (nth 3 port))
11511 ;; paste initialization (inputs only)
11512 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11513 (insert " := " (if (string-match "(.+)" (nth 3 port))
11514 "(others => '0')" "'0'")))
11517 (when (or vhdl-include-direction-comments
11518 (and vhdl-include-port-comments (nth 4 port)))
11519 (vhdl-comment-insert-inline
11521 (cond ((and vhdl-include-direction-comments (nth 2 port))
11522 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11523 (vhdl-include-direction-comments " "))
11524 (when vhdl-include-port-comments (nth 4 port))) t))
11525 (setq port-list (cdr port-list))
11526 (when port-list (insert "\n") (indent-to margin)))
11527 ;; align signal list
11528 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11529 (message "Pasting port as signals...done")))
11531 (defun vhdl-port-paste-initializations (&optional no-indent)
11532 "Paste ports as signal initializations."
11534 (if (not vhdl-port-list)
11535 (error "ERROR: No port read")
11536 (let ((orig-vhdl-port-list vhdl-port-list))
11537 (message "Pasting port as initializations...")
11538 ;; flatten local copy of port list (must be flat for signal initial.)
11539 (vhdl-port-flatten)
11540 (unless no-indent (indent-according-to-mode))
11541 (let ((margin (current-indentation))
11543 (port-list (nth 2 vhdl-port-list)))
11545 (setq start (point))
11547 (setq port (car port-list))
11548 ;; paste actual port signal (inputs only)
11549 (when (equal "IN" (upcase (nth 2 port)))
11550 (setq name (car (nth 0 port)))
11551 (insert (vhdl-replace-string vhdl-actual-port-name name))
11552 ;; paste initialization
11553 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11554 "(others => '0')" "'0'") ";"))
11555 (setq port-list (cdr port-list))
11556 (when (and port-list
11557 (equal "IN" (upcase (nth 2 (car port-list)))))
11558 (insert "\n") (indent-to margin)))
11559 ;; align signal list
11560 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11561 (message "Pasting port as initializations...done")
11562 (setq vhdl-port-list orig-vhdl-port-list))))
11564 (defun vhdl-port-paste-testbench ()
11565 "Paste as a bare-bones testbench."
11567 (if (not vhdl-port-list)
11568 (error "ERROR: No port read")
11569 (let ((case-fold-search t)
11570 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11571 (nth 0 vhdl-port-list)))
11572 (source-buffer (current-buffer))
11573 arch-name config-name ent-file-name arch-file-name
11574 ent-buffer arch-buffer position)
11575 ;; open entity file
11576 (unless (eq vhdl-testbench-create-files 'none)
11577 (setq ent-file-name
11578 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11580 "." (file-name-extension (buffer-file-name))))
11581 (if (file-exists-p ent-file-name)
11583 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11584 (progn (find-file ent-file-name)
11586 (set-buffer-modified-p nil))
11587 (if (eq vhdl-testbench-create-files 'separate)
11588 (setq ent-file-name nil)
11589 (error "ERROR: Pasting port as testbench...aborted")))
11590 (find-file ent-file-name)))
11591 (unless (and (eq vhdl-testbench-create-files 'separate)
11592 (null ent-file-name))
11593 ;; paste entity header
11594 (if vhdl-testbench-include-header
11595 (progn (vhdl-template-header
11596 (concat "Testbench for design \""
11597 (nth 0 vhdl-port-list) "\""))
11598 (goto-char (point-max)))
11599 (vhdl-comment-display-line) (insert "\n\n"))
11600 ;; paste std_logic_1164 package
11601 (when vhdl-testbench-include-library
11602 (vhdl-template-package-std-logic-1164)
11603 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11604 ;; paste entity declaration
11605 (vhdl-insert-keyword "ENTITY ")
11607 (vhdl-insert-keyword " IS")
11608 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11610 (vhdl-insert-keyword "END ")
11611 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11612 (insert ent-name ";")
11614 (vhdl-comment-display-line) (insert "\n"))
11615 ;; get architecture name
11616 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11617 (read-from-minibuffer "architecture name: "
11618 nil vhdl-minibuffer-local-map)
11619 (vhdl-replace-string vhdl-testbench-architecture-name
11620 (nth 0 vhdl-port-list))))
11621 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11622 ;; open architecture file
11623 (if (not (eq vhdl-testbench-create-files 'separate))
11625 (setq ent-buffer (current-buffer))
11626 (setq arch-file-name
11627 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11628 (concat ent-name " " arch-name) t)
11629 "." (file-name-extension (buffer-file-name))))
11630 (when (and (file-exists-p arch-file-name)
11631 (not (y-or-n-p (concat "File \"" arch-file-name
11632 "\" exists; overwrite? "))))
11633 (error "ERROR: Pasting port as testbench...aborted"))
11634 (find-file arch-file-name)
11636 (set-buffer-modified-p nil)
11637 ;; paste architecture header
11638 (if vhdl-testbench-include-header
11639 (progn (vhdl-template-header
11640 (concat "Testbench architecture for design \""
11641 (nth 0 vhdl-port-list) "\""))
11642 (goto-char (point-max)))
11643 (vhdl-comment-display-line) (insert "\n\n")))
11644 ;; paste architecture body
11645 (vhdl-insert-keyword "ARCHITECTURE ")
11647 (vhdl-insert-keyword " OF ")
11649 (vhdl-insert-keyword " IS")
11650 (insert "\n\n") (indent-to vhdl-basic-offset)
11651 ;; paste component declaration
11652 (unless (vhdl-use-direct-instantiation)
11653 (vhdl-port-paste-component t)
11654 (insert "\n\n") (indent-to vhdl-basic-offset))
11656 (when (nth 1 vhdl-port-list)
11657 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11658 (vhdl-port-paste-constants t)
11659 (insert "\n\n") (indent-to vhdl-basic-offset))
11660 ;; paste internal signals
11661 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11662 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11664 ;; paste custom declarations
11665 (unless (equal "" vhdl-testbench-declarations)
11667 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11668 (setq position (point))
11670 (vhdl-comment-display-line) (insert "\n")
11671 (when vhdl-testbench-include-configuration
11672 (setq config-name (vhdl-replace-string
11673 vhdl-testbench-configuration-name
11674 (concat ent-name " " arch-name)))
11676 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11677 (vhdl-insert-keyword " OF ") (insert ent-name)
11678 (vhdl-insert-keyword " IS\n")
11679 (indent-to vhdl-basic-offset)
11680 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11681 (indent-to vhdl-basic-offset)
11682 (vhdl-insert-keyword "END FOR;\n")
11683 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11684 (vhdl-comment-display-line) (insert "\n"))
11685 (goto-char position)
11686 (vhdl-template-begin-end
11687 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11688 ;; paste instantiation
11689 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11690 (vhdl-port-paste-instance
11691 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11693 ;; paste custom statements
11694 (unless (equal "" vhdl-testbench-statements)
11696 (vhdl-insert-string-or-file vhdl-testbench-statements))
11698 (indent-to vhdl-basic-offset)
11699 (unless (eq vhdl-testbench-create-files 'none)
11700 (setq arch-buffer (current-buffer))
11701 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11702 (set-buffer arch-buffer) (save-buffer))
11704 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11705 ent-name arch-name)
11707 (format "\n File created: \"%s\"" ent-file-name))
11708 (and arch-file-name
11709 (format "\n File created: \"%s\"" arch-file-name)))))))
11712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11713 ;;; Subprogram interface translation
11714 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11716 (defvar vhdl-subprog-list nil
11717 "Variable to hold last subprogram interface parsed.")
11718 ;; structure: (parenthesised expression means list of such entries)
11719 ;; (subprog-name kind
11720 ;; ((names) object direct type init comment group-comment)
11721 ;; return-type return-comment group-comment)
11723 (defvar vhdl-subprog-flattened nil
11724 "Indicates whether an subprogram interface has been flattened.")
11726 (defun vhdl-subprog-flatten ()
11727 "Flatten interface list so that only one parameter exists per line."
11729 (if (not vhdl-subprog-list)
11730 (error "ERROR: No subprogram interface has been read")
11731 (message "Flattening subprogram interface...")
11732 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11733 new-subprog-list old-subprog new-subprog names)
11734 ;; traverse parameter list and flatten entries
11735 (while old-subprog-list
11736 (setq old-subprog (car old-subprog-list))
11737 (setq names (car old-subprog))
11739 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11740 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11741 (setq names (cdr names)))
11742 (setq old-subprog-list (cdr old-subprog-list)))
11743 (setq vhdl-subprog-list
11744 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11745 new-subprog-list (nth 3 vhdl-subprog-list)
11746 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11747 vhdl-subprog-flattened t)
11748 (message "Flattening subprogram interface...done"))))
11750 (defun vhdl-subprog-copy ()
11751 "Get interface information from a subprogram specification."
11754 (let (parse-error pos end-of-list
11755 name kind param-list object names direct type init
11756 comment group-comment
11757 return-type return-comment return-group-comment)
11758 (vhdl-prepare-search-2
11762 ;; check if within function declaration
11765 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11766 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11767 (goto-char (match-end 0))
11768 (save-excursion (backward-char)
11771 (throw 'parse "ERROR: Not within a subprogram specification"))
11772 (setq name (match-string-no-properties 5))
11773 (setq kind (if (match-string 2) 'procedure 'function))
11774 (setq end-of-list (not (match-string 7)))
11775 (message "Reading interface of subprogram \"%s\"..." name)
11776 ;; parse parameter list
11777 (setq group-comment (vhdl-parse-group-comment))
11778 (setq end-of-list (or end-of-list
11779 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11780 (while (not end-of-list)
11783 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11784 (match-string-no-properties 1)))
11785 ;; parse names (accept extended identifiers)
11786 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11787 (setq names (list (match-string-no-properties 1)))
11788 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11789 (setq names (append names (list (match-string-no-properties 1)))))
11791 (vhdl-parse-string ":[ \t\n]*")
11793 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11794 (match-string-no-properties 1)))
11796 (vhdl-parse-string "\\([^():;\n]+\\)")
11797 (setq type (match-string-no-properties 1))
11799 (while (looking-at "(")
11802 (buffer-substring-no-properties
11803 (point) (progn (forward-sexp) (point)))
11804 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11805 (match-string-no-properties 1)))))
11806 ;; special case: closing parenthesis is on separate line
11807 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11808 (setq comment (substring type (match-beginning 2)))
11809 (setq type (substring type 0 (match-beginning 1))))
11810 ;; strip off trailing group-comment
11811 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11812 (setq type (substring type 0 (match-end 1)))
11813 ;; parse initialization expression
11815 (when (vhdl-parse-string ":=[ \t\n]*" t)
11816 (vhdl-parse-string "\\([^();\n]*\\)")
11817 (setq init (match-string-no-properties 1))
11818 (while (looking-at "(")
11821 (buffer-substring-no-properties
11822 (point) (progn (forward-sexp) (point)))
11823 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11824 (match-string-no-properties 1))))))
11825 ;; special case: closing parenthesis is on separate line
11826 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11827 (setq comment (substring init (match-beginning 2)))
11828 (setq init (substring init 0 (match-beginning 1)))
11829 (vhdl-forward-syntactic-ws))
11830 (skip-chars-forward " \t")
11831 ;; parse inline comment, special case: as above, no initial.
11833 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11834 (match-string-no-properties 1))))
11835 (vhdl-forward-syntactic-ws)
11836 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11837 ;; parse inline comment
11839 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11840 (match-string-no-properties 1))))
11841 (setq return-group-comment (vhdl-parse-group-comment))
11842 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11843 ;; parse return type
11844 (when (match-string 3)
11845 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11846 (setq return-type (match-string-no-properties 1))
11847 (when (and return-type
11848 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11849 (setq return-comment (substring return-type (match-beginning 2)))
11850 (setq return-type (substring return-type 0 (match-beginning 1))))
11851 ;; strip of trailing group-comment
11852 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11853 (setq return-type (substring return-type 0 (match-end 1)))
11854 ;; parse return comment
11855 (unless return-comment
11856 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11857 (match-string-no-properties 1)))))
11858 ;; parse inline comment
11860 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11861 (match-string-no-properties 1))))
11862 ;; save everything in list
11863 (setq param-list (append param-list
11864 (list (list names object direct type init
11865 comment group-comment))))
11866 ;; parse group comment and spacing
11867 (setq group-comment (vhdl-parse-group-comment)))
11868 (message "Reading interface of subprogram \"%s\"...done" name)
11872 (error parse-error)
11873 (setq vhdl-subprog-list
11874 (list name kind param-list return-type return-comment
11875 return-group-comment)
11876 vhdl-subprog-flattened nil)))))
11878 (defun vhdl-subprog-paste-specification (kind)
11879 "Paste as a subprogram specification."
11880 (indent-according-to-mode)
11881 (let ((margin (current-column))
11882 (param-list (nth 2 vhdl-subprog-list))
11883 list-margin start names param)
11884 ;; paste keyword and name
11885 (vhdl-insert-keyword
11886 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11887 (insert (nth 0 vhdl-subprog-list))
11888 (if (not param-list)
11889 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11890 (setq start (point))
11891 ;; paste parameter list
11893 (unless vhdl-argument-list-indent
11894 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11895 (setq list-margin (current-column))
11897 (setq param (car param-list))
11898 ;; paste group comment and spacing
11899 (when (memq vhdl-include-group-comments (list kind 'always))
11900 (vhdl-paste-group-comment (nth 6 param) list-margin))
11902 (when (nth 1 param) (insert (nth 1 param) " "))
11904 (setq names (nth 0 param))
11906 (insert (car names))
11907 (setq names (cdr names))
11908 (when names (insert ", ")))
11911 (when (nth 2 param) (insert (nth 2 param) " "))
11913 (insert (nth 3 param))
11914 ;; paste initialization
11915 (when (nth 4 param) (insert " := " (nth 4 param)))
11917 (if (cdr param-list)
11920 (when (null (nth 3 vhdl-subprog-list))
11921 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11923 (when (and vhdl-include-port-comments (nth 5 param))
11924 (vhdl-comment-insert-inline (nth 5 param) t))
11925 (setq param-list (cdr param-list))
11926 (when param-list (insert "\n") (indent-to list-margin)))
11927 (when (nth 3 vhdl-subprog-list)
11928 (insert "\n") (indent-to list-margin)
11929 ;; paste group comment and spacing
11930 (when (memq vhdl-include-group-comments (list kind 'always))
11931 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11932 ;; paste return type
11933 (insert "return " (nth 3 vhdl-subprog-list))
11934 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11935 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11936 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11937 ;; align parameter list
11938 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11940 (when (eq kind 'body)
11942 (vhdl-template-begin-end
11943 (unless (vhdl-standard-p '87)
11944 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11945 (nth 0 vhdl-subprog-list) margin))))
11947 (defun vhdl-subprog-paste-declaration ()
11948 "Paste as a subprogram declaration."
11950 (if (not vhdl-subprog-list)
11951 (error "ERROR: No subprogram interface read")
11952 (message "Pasting interface as subprogram declaration \"%s\"..."
11953 (car vhdl-subprog-list))
11954 ;; paste specification
11955 (vhdl-subprog-paste-specification 'decl)
11956 (message "Pasting interface as subprogram declaration \"%s\"...done"
11957 (car vhdl-subprog-list))))
11959 (defun vhdl-subprog-paste-body ()
11960 "Paste as a subprogram body."
11962 (if (not vhdl-subprog-list)
11963 (error "ERROR: No subprogram interface read")
11964 (message "Pasting interface as subprogram body \"%s\"..."
11965 (car vhdl-subprog-list))
11966 ;; paste specification and body
11967 (vhdl-subprog-paste-specification 'body)
11968 (message "Pasting interface as subprogram body \"%s\"...done"
11969 (car vhdl-subprog-list))))
11971 (defun vhdl-subprog-paste-call ()
11972 "Paste as a subprogram call."
11974 (if (not vhdl-subprog-list)
11975 (error "ERROR: No subprogram interface read")
11976 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11977 param-list margin list-margin param start)
11978 ;; flatten local copy of interface list (must be flat for parameter mapping)
11979 (vhdl-subprog-flatten)
11980 (setq param-list (nth 2 vhdl-subprog-list))
11981 (indent-according-to-mode)
11982 (setq margin (current-indentation))
11983 (message "Pasting interface as subprogram call \"%s\"..."
11984 (car vhdl-subprog-list))
11986 (insert (nth 0 vhdl-subprog-list))
11987 (if (not param-list)
11989 (setq start (point))
11990 ;; paste parameter list
11992 (unless vhdl-argument-list-indent
11993 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11994 (setq list-margin (current-column))
11996 (setq param (car param-list))
11997 ;; paste group comment and spacing
11998 (when (eq vhdl-include-group-comments 'always)
11999 (vhdl-paste-group-comment (nth 6 param) list-margin))
12000 ;; paste formal port
12001 (insert (car (nth 0 param)) " => ")
12002 (setq param-list (cdr param-list))
12003 (insert (if param-list "," ");"))
12005 (when (and vhdl-include-port-comments (nth 5 param))
12006 (vhdl-comment-insert-inline (nth 5 param)))
12007 (when param-list (insert "\n") (indent-to list-margin)))
12008 ;; align parameter list
12009 (when vhdl-auto-align
12010 (vhdl-align-region-groups start (point) 1)))
12011 (message "Pasting interface as subprogram call \"%s\"...done"
12012 (car vhdl-subprog-list))
12013 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12021 ;; Hippie expand customization
12023 (defvar vhdl-expand-upper-case nil)
12025 (defun vhdl-try-expand-abbrev (old)
12026 "Try expanding abbreviations from `vhdl-abbrev-list'."
12028 (he-init-string (he-dabbrev-beg) (point))
12029 (setq he-expand-list
12030 (let ((abbrev-list vhdl-abbrev-list)
12031 (sel-abbrev-list '()))
12033 (when (or (not (stringp (car abbrev-list)))
12035 (concat "^" he-search-string) (car abbrev-list)))
12036 (setq sel-abbrev-list
12037 (cons (car abbrev-list) sel-abbrev-list)))
12038 (setq abbrev-list (cdr abbrev-list)))
12039 (nreverse sel-abbrev-list))))
12040 (while (and he-expand-list
12041 (or (not (stringp (car he-expand-list)))
12042 (he-string-member (car he-expand-list) he-tried-table t)))
12043 ; (equal (car he-expand-list) he-search-string)))
12044 (unless (stringp (car he-expand-list))
12045 (setq vhdl-expand-upper-case (car he-expand-list)))
12046 (setq he-expand-list (cdr he-expand-list)))
12047 (if (null he-expand-list)
12048 (progn (when old (he-reset-string))
12050 (he-substitute-string
12051 (if vhdl-expand-upper-case
12052 (upcase (car he-expand-list))
12053 (car he-expand-list))
12055 (setq he-expand-list (cdr he-expand-list))
12058 (defun vhdl-he-list-beg ()
12059 "Also looks at the word before `(' in order to better match parenthesized
12060 expressions (e.g. for index ranges of types and signals)."
12063 (progn (backward-up-list 1)
12064 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12068 ;; override `he-list-beg' from `hippie-exp'
12069 (unless (and (boundp 'viper-mode) viper-mode)
12070 (defalias 'he-list-beg 'vhdl-he-list-beg))
12072 ;; function for expanding abbrevs and dabbrevs
12073 (defun vhdl-expand-abbrev (arg))
12074 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12075 '(try-expand-dabbrev
12076 try-expand-dabbrev-all-buffers
12077 vhdl-try-expand-abbrev)))
12079 ;; function for expanding parenthesis
12080 (defun vhdl-expand-paren (arg))
12081 (fset 'vhdl-expand-paren (make-hippie-expand-function
12083 try-expand-list-all-buffers)))
12085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12088 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12089 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12090 depending on parameter UPPER-CASE."
12091 (let ((case-replace nil)
12093 (vhdl-prepare-search-2
12096 (setq end (point-marker))
12098 (while (re-search-forward word-regexp end t)
12099 (or (vhdl-in-literal)
12102 (downcase-word -1)))
12103 (when (and count vhdl-progress-interval (not noninteractive)
12104 (< vhdl-progress-interval
12105 (- (nth 1 (current-time)) last-update)))
12106 (message "Fixing case... (%2d%s)"
12107 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12109 (setq last-update (nth 1 (current-time)))))
12110 (goto-char end)))))
12112 (defun vhdl-fix-case-region (beg end &optional arg)
12113 "Convert all VHDL words in region to lower or upper case, depending on
12114 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12115 (interactive "r\nP")
12116 (vhdl-fix-case-region-1
12117 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12118 (vhdl-fix-case-region-1
12119 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12120 (vhdl-fix-case-region-1
12121 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12122 (vhdl-fix-case-region-1
12123 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12124 (when vhdl-progress-interval (message "Fixing case...done")))
12126 (defun vhdl-fix-case-buffer ()
12127 "Convert all VHDL words in buffer to lower or upper case, depending on
12128 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12130 (vhdl-fix-case-region (point-min) (point-max)))
12132 (defun vhdl-fix-case-word (&optional arg)
12133 "Convert word after cursor to upper case if necessary."
12136 (when arg (backward-word 1))
12137 (vhdl-prepare-search-1
12138 (when (and vhdl-upper-case-keywords
12139 (looking-at vhdl-keywords-regexp))
12141 (when (and vhdl-upper-case-types
12142 (looking-at vhdl-types-regexp))
12144 (when (and vhdl-upper-case-attributes
12145 (looking-at vhdl-attributes-regexp))
12147 (when (and vhdl-upper-case-enum-values
12148 (looking-at vhdl-enum-values-regexp))
12149 (upcase-word 1)))))
12151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12152 ;; Line handling functions
12154 (defun vhdl-current-line ()
12155 "Return the line number of the line containing point."
12159 (beginning-of-line)
12160 (1+ (count-lines 1 (point))))))
12162 (defun vhdl-line-kill-entire (&optional arg)
12163 "Delete entire line."
12165 (beginning-of-line)
12166 (kill-line (or arg 1)))
12168 (defun vhdl-line-kill (&optional arg)
12169 "Kill current line."
12171 (vhdl-line-kill-entire arg))
12173 (defun vhdl-line-copy (&optional arg)
12174 "Copy current line."
12177 (beginning-of-line)
12178 (let ((position (point)))
12179 (forward-line (or arg 1))
12180 (copy-region-as-kill position (point)))))
12182 (defun vhdl-line-yank ()
12183 "Yank entire line."
12185 (beginning-of-line)
12188 (defun vhdl-line-expand (&optional prefix-arg)
12189 "Hippie-expand current line."
12191 (let ((case-fold-search t) (case-replace nil)
12192 (hippie-expand-try-functions-list
12193 '(try-expand-line try-expand-line-all-buffers)))
12194 (hippie-expand prefix-arg)))
12196 (defun vhdl-line-transpose-next (&optional arg)
12197 "Interchange this line with next line."
12200 (transpose-lines (or arg 1))
12203 (defun vhdl-line-transpose-previous (&optional arg)
12204 "Interchange this line with previous line."
12207 (transpose-lines (- 0 (or arg 0)))
12210 (defun vhdl-line-open ()
12211 "Open a new line and indent."
12214 (newline-and-indent))
12216 (defun vhdl-delete-indentation ()
12217 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12218 it works within comments too."
12220 (let ((fill-prefix "-- "))
12221 (delete-indentation)))
12223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12226 (defun vhdl-forward-same-indent ()
12227 "Move forward to next line with same indent."
12229 (let ((pos (point))
12230 (indent (current-indentation)))
12231 (beginning-of-line 2)
12232 (while (and (not (eobp))
12233 (or (looking-at "^\\s-*\\(--.*\\)?$")
12234 (> (current-indentation) indent)))
12235 (beginning-of-line 2))
12236 (if (= (current-indentation) indent)
12237 (back-to-indentation)
12238 (message "No following line with same indent found in this block")
12242 (defun vhdl-backward-same-indent ()
12243 "Move backward to previous line with same indent."
12245 (let ((pos (point))
12246 (indent (current-indentation)))
12247 (beginning-of-line -0)
12248 (while (and (not (bobp))
12249 (or (looking-at "^\\s-*\\(--.*\\)?$")
12250 (> (current-indentation) indent)))
12251 (beginning-of-line -0))
12252 (if (= (current-indentation) indent)
12253 (back-to-indentation)
12254 (message "No preceding line with same indent found in this block")
12258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12261 (defun vhdl-statistics-buffer ()
12262 "Get some file statistics."
12266 (no-lines (count-lines (point-min) (point-max))))
12268 ;; count statements
12269 (goto-char (point-min))
12270 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12271 (if (match-string 1)
12272 (goto-char (match-end 1))
12273 (setq no-stats (1+ no-stats))))
12274 ;; count code lines
12275 (goto-char (point-min))
12276 (while (not (eobp))
12277 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12278 (setq no-code-lines (1+ no-code-lines)))
12279 (beginning-of-line 2)))
12282 File statistics: \"%s\"\n\
12283 ---------------------\n\
12284 # statements : %5d\n\
12285 # code lines : %5d\n\
12286 # total lines : %5d\n\ "
12287 (buffer-file-name) no-stats no-code-lines no-lines)
12288 (unless vhdl-emacs-21 (vhdl-show-messages))))
12290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12293 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12294 "Like `re-search-forward', but does not match within literals."
12297 (while (and (setq pos (re-search-forward regexp bound noerror count))
12298 (vhdl-in-literal))))
12299 (when pos (goto-char pos))
12302 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12303 "Like `re-search-backward', but does not match within literals."
12306 (while (and (setq pos (re-search-backward regexp bound noerror count))
12307 (vhdl-in-literal))))
12308 (when pos (goto-char pos))
12312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12316 (defun vhdl-set-project (name)
12317 "Set current project to NAME."
12319 (list (let ((completion-ignore-case t))
12320 (completing-read "Project name: " vhdl-project-alist nil t))))
12321 (cond ((equal name "")
12322 (setq vhdl-project nil)
12323 (message "Current VHDL project: None"))
12324 ((assoc name vhdl-project-alist)
12325 (setq vhdl-project name)
12326 (message "Current VHDL project: \"%s\"" name))
12328 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12329 (vhdl-speedbar-update-current-project))
12331 (defun vhdl-set-default-project ()
12332 "Set current project as default on startup."
12334 (customize-set-variable 'vhdl-project vhdl-project)
12335 (customize-save-customized))
12337 (defun vhdl-toggle-project (name token indent)
12338 "Set current project to NAME or unset if NAME is current project."
12339 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12341 (defun vhdl-export-project (file-name)
12342 "Write project setup for current project."
12344 (let ((name (vhdl-resolve-env-variable
12345 (vhdl-replace-string
12346 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12347 (concat (subst-char-in-string
12348 ? ?_ (or (vhdl-project-p)
12349 (error "ERROR: No current project")))
12350 " " (user-login-name))))))
12351 (list (read-file-name
12352 "Write project file: "
12353 (when (file-name-absolute-p name) "") nil nil name))))
12354 (setq file-name (abbreviate-file-name file-name))
12355 (let ((orig-buffer (current-buffer)))
12356 (unless (file-exists-p (file-name-directory file-name))
12357 (make-directory (file-name-directory file-name) t))
12358 (if (not (file-writable-p file-name))
12359 (error "ERROR: File not writable: \"%s\"" file-name)
12360 (set-buffer (find-file-noselect file-name t t))
12362 (insert ";; -*- Emacs-Lisp -*-\n\n"
12363 ";;; " (file-name-nondirectory file-name)
12364 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12365 ";; Project : " vhdl-project "\n"
12366 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12367 (user-login-name) "\n\n\n"
12368 ";; project name\n"
12369 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12370 ";; project setup\n"
12371 "(aput 'vhdl-project-alist vhdl-project\n'")
12372 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12375 (kill-buffer (current-buffer))
12376 (set-buffer orig-buffer))))
12378 (defun vhdl-import-project (file-name &optional auto not-make-current)
12379 "Read project setup and set current project."
12381 (let ((name (vhdl-resolve-env-variable
12382 (vhdl-replace-string
12383 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12384 (concat "" " " (user-login-name))))))
12385 (list (read-file-name
12386 "Read project file: " (when (file-name-absolute-p name) "") nil t
12387 (file-name-directory name)))))
12388 (when (file-exists-p file-name)
12390 (let ((current-project vhdl-project))
12391 (load-file file-name)
12392 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12393 (adelete 'vhdl-project-alist vhdl-project)
12395 (when not-make-current
12396 (setq vhdl-project current-project))
12397 (vhdl-update-mode-menu)
12398 (vhdl-speedbar-refresh)
12399 (unless not-make-current
12400 (message "Current VHDL project: \"%s\"%s"
12401 vhdl-project (if auto " (auto-loaded)" ""))))
12402 (error (vhdl-warning
12403 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12405 (defun vhdl-duplicate-project ()
12406 "Duplicate setup of current project."
12408 (let ((new-name (read-from-minibuffer "New project name: "))
12409 (project-entry (aget vhdl-project-alist vhdl-project t)))
12410 (setq vhdl-project-alist
12411 (append vhdl-project-alist
12412 (list (cons new-name project-entry))))
12413 (vhdl-update-mode-menu)))
12415 (defun vhdl-auto-load-project ()
12416 "Automatically load project setup at startup."
12417 (let ((file-name-list vhdl-project-file-name)
12418 file-list list-length)
12419 (while file-name-list
12422 (file-expand-wildcards
12423 (vhdl-resolve-env-variable
12424 (vhdl-replace-string
12425 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12426 (concat "\*" " " (user-login-name)))))))
12427 (setq list-length (or list-length (length file-list)))
12428 (setq file-name-list (cdr file-name-list)))
12430 (vhdl-import-project (expand-file-name (car file-list)) t
12431 (not (> list-length 0)))
12432 (setq list-length (1- list-length))
12433 (setq file-list (cdr file-list)))))
12435 ;; automatically load project setup when idle after startup
12436 (when (memq 'startup vhdl-project-auto-load)
12438 (vhdl-auto-load-project)
12439 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12442 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12445 ;; (using `hideshow.el')
12447 (defconst vhdl-hs-start-regexp
12450 ;; generic/port clause
12451 "\\(generic\\|port\\)[ \t\n]*(\\|"
12454 ;; component instantiation
12455 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12456 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12457 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12458 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12460 "\\(function\\|procedure\\)\\>\\|"
12462 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12463 ;; configuration declaration
12466 "Regexp to match start of construct to hide.")
12468 (defun vhdl-hs-forward-sexp-func (count)
12469 "Find end of construct to hide (for hideshow). Only searches forward."
12470 (let ((pos (point)))
12471 (vhdl-prepare-search-2
12472 (beginning-of-line)
12474 ;; generic/port clause
12475 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12476 (goto-char (match-end 0))
12479 ;; component declaration
12480 ((looking-at "^\\s-*component\\>")
12481 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12482 ;; component instantiation
12485 "^\\s-*\\w+\\s-*:[ \t\n]*"
12486 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12487 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12488 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12489 (goto-char (match-end 0))
12493 (vhdl-forward-syntactic-ws)
12494 (when (looking-at "port\\s-+map[ \t\n]*(")
12495 (goto-char (match-end 0))
12498 (setq pos (point)))
12500 ;; subprogram declaration/body
12501 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12502 (goto-char (match-end 0))
12503 (vhdl-forward-syntactic-ws)
12504 (when (looking-at "(")
12506 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12507 (vhdl-in-literal)))
12509 (when (match-string 2)
12510 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12512 (vhdl-forward-sexp)))
12513 ;; block (recursive)
12514 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12515 (goto-char (match-end 0))
12516 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12517 (match-beginning 2))
12518 (vhdl-hs-forward-sexp-func count)))
12520 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12521 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12522 ;; configuration declaration
12523 ((looking-at "^\\s-*configuration\\>")
12525 (vhdl-forward-sexp))
12526 (t (goto-char pos))))))
12528 (defun vhdl-hideshow-init ()
12529 "Initialize `hideshow'."
12530 (when vhdl-hideshow-menu
12531 (vhdl-hs-minor-mode 1)))
12533 (defun vhdl-hs-minor-mode (&optional arg)
12534 "Toggle hideshow minor mode and update menu bar."
12536 (require 'hideshow)
12537 ;; check for hideshow version 5.x
12538 (if (not (boundp 'hs-block-start-mdata-select))
12539 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12540 ;; initialize hideshow
12541 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12542 (setq hs-special-modes-alist
12543 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12544 'vhdl-hs-forward-sexp-func nil)
12545 hs-special-modes-alist)))
12546 (make-local-variable 'hs-minor-mode-hook)
12547 (if vhdl-hide-all-init
12548 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12549 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12550 (hs-minor-mode arg)
12551 (vhdl-mode-line-update))) ; hack to update menu bar
12554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12557 ;; (using `font-lock.el')
12559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12562 (defun vhdl-within-translate-off ()
12563 "Return point if within translate-off region, else nil."
12564 (and (save-excursion
12565 (re-search-backward
12566 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12567 (equal "off" (match-string 1))
12570 (defun vhdl-start-translate-off (limit)
12571 "Return point before translate-off pragma if before LIMIT, else nil."
12572 (when (re-search-forward
12573 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12574 (match-beginning 0)))
12576 (defun vhdl-end-translate-off (limit)
12577 "Return point after translate-on pragma if before LIMIT, else nil."
12578 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12580 (defun vhdl-match-translate-off (limit)
12581 "Match a translate-off block, setting match-data and returning t, else nil."
12582 (when (< (point) limit)
12583 (let ((start (or (vhdl-within-translate-off)
12584 (vhdl-start-translate-off limit)))
12585 (case-fold-search t))
12587 (let ((end (or (vhdl-end-translate-off limit) limit)))
12588 (set-match-data (list start end))
12589 (goto-char end))))))
12591 (defun vhdl-font-lock-match-item (limit)
12592 "Match, and move over, any declaration item after point. Adapted from
12593 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12594 (condition-case nil
12596 (narrow-to-region (point-min) limit)
12598 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12600 (goto-char (match-end 1))
12601 ;; move to next item
12602 (if (looking-at "\\(\\s-*,\\)")
12603 (goto-char (match-end 1))
12604 (end-of-line) t))))
12607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12608 ;; Syntax definitions
12610 (defconst vhdl-font-lock-syntactic-keywords
12611 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12612 "Mark single quotes as having string quote syntax in 'c' instances.")
12614 (defvar vhdl-font-lock-keywords nil
12615 "Regular expressions to highlight in VHDL Mode.")
12617 (defvar vhdl-font-lock-keywords-0
12618 ;; set in `vhdl-font-lock-init' because dependent on user options
12619 "For consideration as a value of `vhdl-font-lock-keywords'.
12620 This does highlighting of template prompts and directives (pragmas).")
12622 (defvar vhdl-font-lock-keywords-1 nil
12623 ;; set in `vhdl-font-lock-init' because dependent on user options
12624 "For consideration as a value of `vhdl-font-lock-keywords'.
12625 This does highlighting of keywords and standard identifiers.")
12627 (defconst vhdl-font-lock-keywords-2
12629 ;; highlight names of units, subprograms, and components when declared
12633 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12634 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12635 "\\)\\s-+\\(\\w+\\)")
12636 5 'font-lock-function-name-face)
12638 ;; highlight entity names of architectures and configurations
12640 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12641 2 'font-lock-function-name-face)
12643 ;; highlight labels of common constructs
12646 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12647 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12648 "postponed\\|process\\|"
12649 (when (vhdl-standard-p 'ams) "procedural\\|")
12651 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12652 1 'font-lock-function-name-face)
12654 ;; highlight label and component name of component instantiations
12657 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12658 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12659 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12661 ;; highlight label and instantiated unit of component instantiations
12664 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12665 "\\(component\\|configuration\\|entity\\)\\s-+"
12666 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12667 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12668 '(5 font-lock-function-name-face nil t)
12669 '(7 font-lock-function-name-face nil t))
12671 ;; highlight names and labels at end of constructs
12674 "^\\s-*end\\s-+\\(\\("
12675 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12676 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12677 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12678 (when (vhdl-standard-p 'ams) "procedural\\|")
12680 "\\)\\s-+\\)?\\(\\w*\\)")
12681 5 'font-lock-function-name-face)
12683 ;; highlight labels in exit and next statements
12686 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12687 3 'font-lock-function-name-face)
12689 ;; highlight entity name in attribute specifications
12692 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12693 1 'font-lock-function-name-face)
12695 ;; highlight labels in block and component specifications
12698 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12699 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12700 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12702 ;; highlight names in library clauses
12703 (list "^\\s-*library\\>"
12704 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12706 ;; highlight names in use clauses
12709 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12710 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12711 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12712 '(7 font-lock-function-name-face nil t))
12714 ;; highlight attribute name in attribute declarations/specifications
12717 "^\\s-*attribute\\s-+\\(\\w+\\)")
12718 1 'vhdl-font-lock-attribute-face)
12720 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12723 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12724 3 'font-lock-type-face)
12726 ;; highlight signal/variable/constant declaration names
12727 (list "\\(:[^=]\\)"
12728 '(vhdl-font-lock-match-item
12729 (progn (goto-char (match-beginning 1))
12730 (skip-syntax-backward " ")
12731 (skip-syntax-backward "w_")
12732 (skip-syntax-backward " ")
12733 (while (= (preceding-char) ?,)
12735 (skip-syntax-backward " ")
12736 (skip-syntax-backward "w_")
12737 (skip-syntax-backward " ")))
12738 ; (skip-chars-backward "^-(\n\";")
12739 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12741 ;; highlight formal parameters in component instantiations and subprogram
12744 '(vhdl-font-lock-match-item
12745 (progn (goto-char (match-beginning 1))
12746 (skip-syntax-backward " ")
12747 (while (= (preceding-char) ?\)) (backward-sexp))
12748 (skip-syntax-backward "w_")
12749 (skip-syntax-backward " ")
12750 (when (memq (preceding-char) '(?n ?N ?|))
12751 (goto-char (point-max))))
12752 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12754 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12756 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12757 '(vhdl-font-lock-match-item
12758 (progn (goto-char (match-end 1)) (match-beginning 2))
12759 nil (1 font-lock-variable-name-face)))
12761 "For consideration as a value of `vhdl-font-lock-keywords'.
12762 This does context sensitive highlighting of names and labels.")
12764 (defvar vhdl-font-lock-keywords-3 nil
12765 ;; set in `vhdl-font-lock-init' because dependent on user options
12766 "For consideration as a value of `vhdl-font-lock-keywords'.
12767 This does highlighting of words with special syntax.")
12769 (defvar vhdl-font-lock-keywords-4 nil
12770 ;; set in `vhdl-font-lock-init' because dependent on user options
12771 "For consideration as a value of `vhdl-font-lock-keywords'.
12772 This does highlighting of additional reserved words.")
12774 (defconst vhdl-font-lock-keywords-5
12775 ;; background highlight translate-off regions
12776 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12777 "For consideration as a value of `vhdl-font-lock-keywords'.
12778 This does background highlighting of translate-off regions.")
12780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12781 ;; Font and color definitions
12783 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12784 "Face name to use for prompts.")
12786 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12787 "Face name to use for standardized attributes.")
12789 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12790 "Face name to use for standardized enumeration values.")
12792 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12793 "Face name to use for standardized functions and packages.")
12795 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12796 "Face name to use for directives.")
12798 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12799 "Face name to use for additional reserved words.")
12801 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12802 "Face name to use for translate-off regions.")
12804 ;; face names to use for words with special syntax.
12805 (let ((syntax-alist vhdl-special-syntax-alist)
12807 (while syntax-alist
12808 (setq name (vhdl-function-name
12809 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12810 (eval `(defvar ,name ',name
12811 ,(concat "Face name to use for "
12812 (nth 0 (car syntax-alist)) ".")))
12813 (setq syntax-alist (cdr syntax-alist))))
12815 (defgroup vhdl-highlight-faces nil
12816 "Faces for highlighting."
12817 :group 'vhdl-highlight)
12819 ;; add faces used from `font-lock'
12820 (custom-add-to-group
12821 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12822 (custom-add-to-group
12823 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12824 (custom-add-to-group
12825 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12826 (custom-add-to-group
12827 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12828 (custom-add-to-group
12829 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12830 (custom-add-to-group
12831 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12833 (defface vhdl-font-lock-prompt-face
12834 '((((min-colors 88) (class color) (background light))
12835 (:foreground "Red1" :bold t))
12836 (((class color) (background light)) (:foreground "Red" :bold t))
12837 (((class color) (background dark)) (:foreground "Pink" :bold t))
12838 (t (:inverse-video t)))
12839 "Font lock mode face used to highlight prompts."
12840 :group 'vhdl-highlight-faces)
12842 (defface vhdl-font-lock-attribute-face
12843 '((((class color) (background light)) (:foreground "Orchid"))
12844 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12845 (t (:italic t :bold t)))
12846 "Font lock mode face used to highlight standardized attributes."
12847 :group 'vhdl-highlight-faces)
12849 (defface vhdl-font-lock-enumvalue-face
12850 '((((class color) (background light)) (:foreground "SaddleBrown"))
12851 (((class color) (background dark)) (:foreground "BurlyWood"))
12852 (t (:italic t :bold t)))
12853 "Font lock mode face used to highlight standardized enumeration values."
12854 :group 'vhdl-highlight-faces)
12856 (defface vhdl-font-lock-function-face
12857 '((((class color) (background light)) (:foreground "Cyan4"))
12858 (((class color) (background dark)) (:foreground "Orchid1"))
12859 (t (:italic t :bold t)))
12860 "Font lock mode face used to highlight standardized functions and packages."
12861 :group 'vhdl-highlight-faces)
12863 (defface vhdl-font-lock-directive-face
12864 '((((class color) (background light)) (:foreground "CadetBlue"))
12865 (((class color) (background dark)) (:foreground "Aquamarine"))
12866 (t (:italic t :bold t)))
12867 "Font lock mode face used to highlight directives."
12868 :group 'vhdl-highlight-faces)
12870 (defface vhdl-font-lock-reserved-words-face
12871 '((((class color) (background light)) (:foreground "Orange" :bold t))
12872 (((min-colors 88) (class color) (background dark))
12873 (:foreground "Yellow1" :bold t))
12874 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12876 "Font lock mode face used to highlight additional reserved words."
12877 :group 'vhdl-highlight-faces)
12879 (defface vhdl-font-lock-translate-off-face
12880 '((((class color) (background light)) (:background "LightGray"))
12881 (((class color) (background dark)) (:background "DimGray"))
12883 "Font lock mode face used to background highlight translate-off regions."
12884 :group 'vhdl-highlight-faces)
12886 ;; font lock mode faces used to highlight words with special syntax.
12887 (let ((syntax-alist vhdl-special-syntax-alist))
12888 (while syntax-alist
12889 (eval `(defface ,(vhdl-function-name
12890 "vhdl-font-lock" (caar syntax-alist) "face")
12891 '((((class color) (background light))
12892 (:foreground ,(nth 2 (car syntax-alist))))
12893 (((class color) (background dark))
12894 (:foreground ,(nth 3 (car syntax-alist))))
12896 ,(concat "Font lock mode face used to highlight "
12897 (nth 0 (car syntax-alist)) ".")
12898 :group 'vhdl-highlight-faces))
12899 (setq syntax-alist (cdr syntax-alist))))
12901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12902 ;; Font lock initialization
12904 (defun vhdl-font-lock-init ()
12905 "Initialize fontification."
12906 ;; highlight template prompts and directives
12907 (setq vhdl-font-lock-keywords-0
12908 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12909 vhdl-template-prompt-syntax ">\\)")
12910 2 'vhdl-font-lock-prompt-face t)
12911 (list (concat "--\\s-*"
12912 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12913 2 'vhdl-font-lock-directive-face t)
12914 ;; highlight c-preprocessor directives
12915 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12916 '(1 font-lock-builtin-face)
12917 '(3 font-lock-variable-name-face nil t))))
12918 ;; highlight keywords and standardized types, attributes, enumeration
12919 ;; values, and subprograms
12920 (setq vhdl-font-lock-keywords-1
12922 (list (concat "'" vhdl-attributes-regexp)
12923 1 'vhdl-font-lock-attribute-face)
12924 (list vhdl-types-regexp 1 'font-lock-type-face)
12925 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12926 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12927 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12928 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12929 ;; highlight words with special syntax.
12930 (setq vhdl-font-lock-keywords-3
12931 (let ((syntax-alist vhdl-special-syntax-alist)
12933 (while syntax-alist
12936 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12937 (vhdl-function-name
12938 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12940 (setq syntax-alist (cdr syntax-alist)))
12942 ;; highlight additional reserved words
12943 (setq vhdl-font-lock-keywords-4
12944 (list (list vhdl-reserved-words-regexp 1
12945 'vhdl-font-lock-reserved-words-face)))
12946 ;; highlight everything together
12947 (setq vhdl-font-lock-keywords
12949 vhdl-font-lock-keywords-0
12950 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12951 (when (or vhdl-highlight-forbidden-words
12952 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12953 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12954 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12955 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12957 ;; initialize fontification for VHDL Mode
12958 (vhdl-font-lock-init)
12960 (defun vhdl-fontify-buffer ()
12961 "Re-initialize fontification and fontify buffer."
12963 (setq font-lock-defaults
12965 'vhdl-font-lock-keywords nil
12966 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12967 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12968 (when (fboundp 'font-lock-unset-defaults)
12969 (font-lock-unset-defaults)) ; not implemented in XEmacs
12970 (font-lock-set-defaults)
12971 (font-lock-mode nil)
12972 (font-lock-mode t))
12974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12975 ;; Initialization for postscript printing
12977 (defun vhdl-ps-print-settings ()
12978 "Initialize custom face and page settings for postscript printing."
12979 ;; define custom face settings
12980 (unless (or (not vhdl-print-customize-faces)
12982 (set (make-local-variable 'ps-bold-faces)
12983 '(font-lock-keyword-face
12984 font-lock-type-face
12985 vhdl-font-lock-attribute-face
12986 vhdl-font-lock-enumvalue-face
12987 vhdl-font-lock-directive-face))
12988 (set (make-local-variable 'ps-italic-faces)
12989 '(font-lock-comment-face
12990 font-lock-function-name-face
12991 font-lock-type-face
12992 vhdl-font-lock-attribute-face
12993 vhdl-font-lock-enumvalue-face
12994 vhdl-font-lock-directive-face))
12995 (set (make-local-variable 'ps-underlined-faces)
12996 '(font-lock-string-face))
12997 (setq ps-always-build-face-reference t))
12998 ;; define page settings, so that a line containing 79 characters (default)
12999 ;; fits into one column
13000 (when vhdl-print-two-column
13001 (set (make-local-variable 'ps-landscape-mode) t)
13002 (set (make-local-variable 'ps-number-of-columns) 2)
13003 (set (make-local-variable 'ps-font-size) 7.0)
13004 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13005 (set (make-local-variable 'ps-header-font-size) 9.0)
13006 (set (make-local-variable 'ps-header-offset) 12.0)
13007 (when (eq ps-paper-type 'letter)
13008 (set (make-local-variable 'ps-inter-column) 40.0)
13009 (set (make-local-variable 'ps-left-margin) 40.0)
13010 (set (make-local-variable 'ps-right-margin) 40.0))))
13012 (defun vhdl-ps-print-init ()
13013 "Initialize postscript printing."
13014 (if (featurep 'xemacs)
13015 (when (boundp 'ps-print-color-p)
13016 (vhdl-ps-print-settings))
13017 (make-local-variable 'ps-print-hook)
13018 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13022 ;;; Hierarchy browser (using `speedbar.el')
13023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13024 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13025 ;; directory by using the speedbar.
13027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13030 (defvar vhdl-entity-alist nil
13031 "Cache with entities and corresponding architectures for each
13032 project/directory.")
13033 ;; structure: (parenthesised expression means list of such entries)
13035 ;; (ent-key ent-name ent-file ent-line
13036 ;; (arch-key arch-name arch-file arch-line
13037 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13038 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13039 ;; (lib-name pack-key))
13040 ;; mra-key (lib-name pack-key))
13042 (defvar vhdl-config-alist nil
13043 "Cache with configurations for each project/directory.")
13044 ;; structure: (parenthesised expression means list of such entries)
13046 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13047 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13048 ;; inst-conf-key inst-lib-key)
13049 ;; (lib-name pack-key)))
13051 (defvar vhdl-package-alist nil
13052 "Cache with packages for each project/directory.")
13053 ;; structure: (parenthesised expression means list of such entries)
13055 ;; (pack-key pack-name pack-file pack-line
13056 ;; (comp-key comp-name comp-file comp-line)
13057 ;; (func-key func-name func-file func-line)
13058 ;; (lib-name pack-key)
13059 ;; pack-body-file pack-body-line
13060 ;; (func-key func-name func-body-file func-body-line)
13061 ;; (lib-name pack-key)))
13063 (defvar vhdl-ent-inst-alist nil
13064 "Cache with instantiated entities for each project/directory.")
13065 ;; structure: (parenthesised expression means list of such entries)
13066 ;; (cache-key (inst-ent-key))
13068 (defvar vhdl-file-alist nil
13069 "Cache with design units in each file for each project/directory.")
13070 ;; structure: (parenthesised expression means list of such entries)
13072 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13073 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13075 (defvar vhdl-directory-alist nil
13076 "Cache with source directories for each project.")
13077 ;; structure: (parenthesised expression means list of such entries)
13078 ;; (cache-key (directory))
13080 (defvar vhdl-speedbar-shown-unit-alist nil
13081 "Alist of design units simultaneously open in the current speedbar for each
13082 directory and project.")
13084 (defvar vhdl-speedbar-shown-project-list nil
13085 "List of projects simultaneously open in the current speedbar.")
13087 (defvar vhdl-updated-project-list nil
13088 "List of projects and directories with updated files.")
13090 (defvar vhdl-modified-file-list nil
13091 "List of modified files to be rescanned for hierarchy updating.")
13093 (defvar vhdl-speedbar-hierarchy-depth 0
13094 "Depth of instantiation hierarchy to display.")
13096 (defvar vhdl-speedbar-show-projects nil
13097 "Non-nil means project hierarchy is displayed in speedbar, directory
13098 hierarchy otherwise.")
13100 (defun vhdl-get-end-of-unit ()
13101 "Return position of end of current unit."
13102 (let ((pos (point)))
13104 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13106 (goto-char (match-beginning 0))
13107 (vhdl-backward-syntactic-ws)
13108 (and (/= (preceding-char) ?\;) (not (bobp))))))
13109 (re-search-backward "^[ \t]*end\\>" pos 1)
13112 (defun vhdl-match-string-downcase (num &optional string)
13113 "Like `match-string-no-properties' with down-casing."
13114 (let ((match (match-string-no-properties num string)))
13115 (and match (downcase match))))
13118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13121 (defun vhdl-scan-context-clause ()
13122 "Scan the context clause that preceeds a design unit."
13125 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13126 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13127 (equal "USE" (upcase (match-string 1))))
13128 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13129 (setq lib-alist (cons (cons (match-string-no-properties 1)
13130 (vhdl-match-string-downcase 2))
13134 (defun vhdl-scan-directory-contents (name &optional project update num-string
13136 "Scan contents of VHDL files in directory or file pattern NAME."
13137 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13138 ; (unless (file-directory-p (match-string 1 name))
13139 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13140 (let* ((dir-name (match-string 1 name))
13141 (file-pattern (match-string 2 name))
13142 (is-directory (= 0 (length file-pattern)))
13147 (vhdl-get-source-files t dir-name)
13148 (vhdl-directory-files
13149 dir-name t (wildcard-to-regexp file-pattern)))))
13150 (key (or project dir-name))
13151 (file-exclude-regexp
13152 (or (nth 3 (aget vhdl-project-alist project)) ""))
13153 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13154 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13155 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13156 ent-alist conf-alist pack-alist ent-inst-list file-alist
13157 tmp-list tmp-entry no-files files-exist big-files)
13158 (when (or project update)
13159 (setq ent-alist (aget vhdl-entity-alist key t)
13160 conf-alist (aget vhdl-config-alist key t)
13161 pack-alist (aget vhdl-package-alist key t)
13162 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13163 file-alist (aget vhdl-file-alist key t)))
13164 (when (and (not is-directory) (null file-list))
13165 (message "No such file: \"%s\"" name))
13166 (setq files-exist file-list)
13168 (setq no-files (length file-list))
13169 (message "Scanning %s %s\"%s\"..."
13170 (if is-directory "directory" "files") (or num-string "") name)
13172 (unless (equal file-exclude-regexp "")
13173 (let ((case-fold-search nil)
13176 (unless (string-match file-exclude-regexp (car file-list))
13177 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13178 (setq file-list (cdr file-list)))
13179 (setq file-list (nreverse file-tmp-list))))
13180 ;; do for all files
13182 (unless noninteractive
13183 (message "Scanning %s %s\"%s\"... (%2d%s)"
13184 (if is-directory "directory" "files")
13185 (or num-string "") name
13186 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13187 (let ((file-name (abbreviate-file-name (car file-list)))
13188 ent-list arch-list arch-ent-list conf-list
13189 pack-list pack-body-list inst-list inst-ent-list)
13193 (vhdl-prepare-search-2
13195 ;; scan for design units
13196 (if (and limit-design-file-size
13197 (< limit-design-file-size (buffer-size)))
13198 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13199 (setq big-files t))
13200 ;; scan for entities
13201 (goto-char (point-min))
13202 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13203 (let* ((ent-name (match-string-no-properties 1))
13204 (ent-key (downcase ent-name))
13205 (ent-entry (aget ent-alist ent-key t))
13206 (lib-alist (vhdl-scan-context-clause)))
13207 (if (nth 1 ent-entry)
13208 (vhdl-warning-when-idle
13209 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13210 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13211 file-name (vhdl-current-line))
13212 (setq ent-list (cons ent-key ent-list))
13213 (aput 'ent-alist ent-key
13214 (list ent-name file-name (vhdl-current-line)
13215 (nth 3 ent-entry) (nth 4 ent-entry)
13217 ;; scan for architectures
13218 (goto-char (point-min))
13219 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13220 (let* ((arch-name (match-string-no-properties 1))
13221 (arch-key (downcase arch-name))
13222 (ent-name (match-string-no-properties 2))
13223 (ent-key (downcase ent-name))
13224 (ent-entry (aget ent-alist ent-key t))
13225 (arch-alist (nth 3 ent-entry))
13226 (arch-entry (aget arch-alist arch-key t))
13227 (lib-arch-alist (vhdl-scan-context-clause)))
13229 (vhdl-warning-when-idle
13230 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13231 arch-name ent-name (nth 1 arch-entry)
13232 (nth 2 arch-entry) file-name (vhdl-current-line))
13233 (setq arch-list (cons arch-key arch-list)
13234 arch-ent-list (cons ent-key arch-ent-list))
13235 (aput 'arch-alist arch-key
13236 (list arch-name file-name (vhdl-current-line) nil
13238 (aput 'ent-alist ent-key
13239 (list (or (nth 0 ent-entry) ent-name)
13240 (nth 1 ent-entry) (nth 2 ent-entry)
13241 (vhdl-sort-alist arch-alist)
13242 arch-key (nth 5 ent-entry))))))
13243 ;; scan for configurations
13244 (goto-char (point-min))
13245 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13246 (let* ((conf-name (match-string-no-properties 1))
13247 (conf-key (downcase conf-name))
13248 (conf-entry (aget conf-alist conf-key t))
13249 (ent-name (match-string-no-properties 2))
13250 (ent-key (downcase ent-name))
13251 (lib-alist (vhdl-scan-context-clause))
13252 (conf-line (vhdl-current-line))
13253 (end-of-unit (vhdl-get-end-of-unit))
13254 arch-key comp-conf-list inst-key-list
13255 inst-comp-key inst-ent-key inst-arch-key
13256 inst-conf-key inst-lib-key)
13257 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13258 (setq arch-key (vhdl-match-string-downcase 1)))
13260 (vhdl-warning-when-idle
13261 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13262 conf-name ent-name (nth 1 conf-entry)
13263 (nth 2 conf-entry) file-name conf-line)
13264 (setq conf-list (cons conf-key conf-list))
13265 ;; scan for subconfigurations and subentities
13266 (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)
13267 (setq inst-comp-key (vhdl-match-string-downcase 3)
13268 inst-key-list (split-string
13269 (vhdl-match-string-downcase 1)
13270 "[ \t\n]*,[ \t\n]*"))
13271 (vhdl-forward-syntactic-ws)
13272 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13274 inst-lib-key (vhdl-match-string-downcase 3)
13275 inst-ent-key (and (match-string 2)
13276 (vhdl-match-string-downcase 4))
13277 inst-arch-key (and (match-string 2)
13278 (vhdl-match-string-downcase 6))
13279 inst-conf-key (and (not (match-string 2))
13280 (vhdl-match-string-downcase 4)))
13281 (while inst-key-list
13282 (setq comp-conf-list
13283 (cons (list (car inst-key-list)
13284 inst-comp-key inst-ent-key
13285 inst-arch-key inst-conf-key
13288 (setq inst-key-list (cdr inst-key-list)))))
13289 (aput 'conf-alist conf-key
13290 (list conf-name file-name conf-line ent-key
13291 arch-key comp-conf-list lib-alist)))))
13292 ;; scan for packages
13293 (goto-char (point-min))
13294 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13295 (let* ((pack-name (match-string-no-properties 2))
13296 (pack-key (downcase pack-name))
13297 (is-body (match-string-no-properties 1))
13298 (pack-entry (aget pack-alist pack-key t))
13299 (pack-line (vhdl-current-line))
13300 (end-of-unit (vhdl-get-end-of-unit))
13301 comp-name func-name comp-alist func-alist lib-alist)
13302 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13303 (vhdl-warning-when-idle
13304 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13305 (if is-body " body" "") pack-name
13306 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13307 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13308 file-name (vhdl-current-line))
13309 ;; scan for context clauses
13310 (setq lib-alist (vhdl-scan-context-clause))
13311 ;; scan for component and subprogram declarations/bodies
13312 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13313 (if (equal (upcase (match-string 1)) "COMPONENT")
13314 (setq comp-name (match-string-no-properties 2)
13316 (cons (list (downcase comp-name) comp-name
13317 file-name (vhdl-current-line))
13319 (setq func-name (match-string-no-properties 2)
13321 (cons (list (downcase func-name) func-name
13322 file-name (vhdl-current-line))
13324 (setq func-alist (nreverse func-alist))
13325 (setq comp-alist (nreverse comp-alist))
13327 (setq pack-body-list (cons pack-key pack-body-list))
13328 (setq pack-list (cons pack-key pack-list)))
13330 'pack-alist pack-key
13332 (list (or (nth 0 pack-entry) pack-name)
13333 (nth 1 pack-entry) (nth 2 pack-entry)
13334 (nth 3 pack-entry) (nth 4 pack-entry)
13336 file-name pack-line func-alist lib-alist)
13337 (list pack-name file-name pack-line
13338 comp-alist func-alist lib-alist
13339 (nth 6 pack-entry) (nth 7 pack-entry)
13340 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13341 ;; scan for hierarchy
13342 (if (and limit-hier-file-size
13343 (< limit-hier-file-size (buffer-size)))
13344 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13345 (setq big-files t))
13346 ;; scan for architectures
13347 (goto-char (point-min))
13348 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13349 (let* ((ent-name (match-string-no-properties 2))
13350 (ent-key (downcase ent-name))
13351 (arch-name (match-string-no-properties 1))
13352 (arch-key (downcase arch-name))
13353 (ent-entry (aget ent-alist ent-key t))
13354 (arch-alist (nth 3 ent-entry))
13355 (arch-entry (aget arch-alist arch-key t))
13356 (beg-of-unit (point))
13357 (end-of-unit (vhdl-get-end-of-unit))
13359 inst-alist inst-path)
13360 ;; scan for contained instantiations
13361 (while (and (re-search-forward
13362 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13363 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13364 "component[ \t\n]+\\(\\w+\\)\\|"
13365 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13366 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13367 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13368 (or (not limit-hier-inst-no)
13369 (<= (setq inst-no (1+ inst-no))
13370 limit-hier-inst-no)))
13372 ;; block/generate beginning found
13375 (cons (match-string-no-properties 1) inst-path)))
13376 ;; block/generate end found
13378 (setq inst-path (cdr inst-path)))
13379 ;; instantiation found
13381 (let* ((inst-name (match-string-no-properties 1))
13382 (inst-key (downcase inst-name))
13384 (or (match-string-no-properties 3)
13385 (match-string-no-properties 6)))
13387 (or (and (match-string 8)
13388 (vhdl-match-string-downcase 11))
13389 (and inst-comp-name
13390 (downcase inst-comp-name))))
13391 (inst-arch-key (vhdl-match-string-downcase 13))
13393 (and (not (match-string 8))
13394 (vhdl-match-string-downcase 11)))
13395 (inst-lib-key (vhdl-match-string-downcase 10)))
13396 (goto-char (match-end 1))
13397 (setq inst-list (cons inst-key inst-list)
13399 (cons inst-ent-key inst-ent-list))
13403 (list (list inst-key inst-name file-name
13404 (vhdl-current-line) inst-comp-name
13405 inst-ent-key inst-arch-key
13406 inst-conf-key inst-lib-key
13407 (reverse inst-path)))))))))
13408 ;; scan for contained configuration specifications
13409 (goto-char beg-of-unit)
13410 (while (re-search-forward
13411 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13412 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13413 (let* ((inst-comp-name (match-string-no-properties 3))
13415 (and (match-string 6)
13416 (vhdl-match-string-downcase 9)))
13417 (inst-arch-key (vhdl-match-string-downcase 11))
13419 (and (not (match-string 6))
13420 (vhdl-match-string-downcase 9)))
13421 (inst-lib-key (vhdl-match-string-downcase 8))
13423 (split-string (vhdl-match-string-downcase 1)
13424 "[ \t\n]*,[ \t\n]*"))
13425 (tmp-inst-alist inst-alist)
13427 (while tmp-inst-alist
13428 (when (and (or (equal "all" (car inst-key-list))
13429 (member (nth 0 (car tmp-inst-alist))
13433 (or (nth 4 (car tmp-inst-alist)) ""))
13434 (downcase inst-comp-name)))
13435 (setq inst-entry (car tmp-inst-alist))
13436 (setq inst-ent-list
13437 (cons (or inst-ent-key (nth 5 inst-entry))
13439 (nth 5 inst-entry) inst-ent-list)))
13441 (list (nth 0 inst-entry) (nth 1 inst-entry)
13442 (nth 2 inst-entry) (nth 3 inst-entry)
13444 (or inst-ent-key (nth 5 inst-entry))
13445 (or inst-arch-key (nth 6 inst-entry))
13446 inst-conf-key inst-lib-key))
13447 (setcar tmp-inst-alist inst-entry))
13448 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13450 (aput 'arch-alist arch-key
13451 (list (nth 0 arch-entry) (nth 1 arch-entry)
13452 (nth 2 arch-entry) inst-alist
13453 (nth 4 arch-entry)))
13454 (aput 'ent-alist ent-key
13455 (list (nth 0 ent-entry) (nth 1 ent-entry)
13456 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13457 (nth 4 ent-entry) (nth 5 ent-entry)))
13458 (when (and limit-hier-inst-no
13459 (> inst-no limit-hier-inst-no))
13460 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13461 (setq big-files t))
13462 (goto-char end-of-unit))))
13463 ;; remember design units for this file
13464 (aput 'file-alist file-name
13465 (list ent-list arch-list arch-ent-list conf-list
13466 pack-list pack-body-list inst-list inst-ent-list))
13467 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13468 (setq file-list (cdr file-list))))
13469 (when (or (and (not project) files-exist)
13470 (and project (not non-final)))
13471 ;; consistency checks:
13472 ;; check whether each architecture has a corresponding entity
13473 (setq tmp-list ent-alist)
13475 (when (null (nth 2 (car tmp-list)))
13476 (setq tmp-entry (car (nth 4 (car tmp-list))))
13477 (vhdl-warning-when-idle
13478 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13479 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13480 (nth 3 tmp-entry)))
13481 (setq tmp-list (cdr tmp-list)))
13482 ;; check whether configuration has a corresponding entity/architecture
13483 (setq tmp-list conf-alist)
13485 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13486 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13487 (setq tmp-entry (car tmp-list))
13488 (vhdl-warning-when-idle
13489 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13490 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13491 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13492 (setq tmp-entry (car tmp-list))
13493 (vhdl-warning-when-idle
13494 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13495 (nth 1 tmp-entry) (nth 4 tmp-entry)
13496 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13497 (setq tmp-list (cdr tmp-list)))
13498 ;; check whether each package body has a package declaration
13499 (setq tmp-list pack-alist)
13501 (when (null (nth 2 (car tmp-list)))
13502 (setq tmp-entry (car tmp-list))
13503 (vhdl-warning-when-idle
13504 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13505 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13506 (setq tmp-list (cdr tmp-list)))
13508 (setq ent-alist (vhdl-sort-alist ent-alist))
13509 (setq conf-alist (vhdl-sort-alist conf-alist))
13510 (setq pack-alist (vhdl-sort-alist pack-alist))
13511 ;; remember updated directory/project
13512 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13513 ;; clear directory alists
13515 (adelete 'vhdl-entity-alist key)
13516 (adelete 'vhdl-config-alist key)
13517 (adelete 'vhdl-package-alist key)
13518 (adelete 'vhdl-ent-inst-alist key)
13519 (adelete 'vhdl-file-alist key))
13520 ;; put directory contents into cache
13521 (aput 'vhdl-entity-alist key ent-alist)
13522 (aput 'vhdl-config-alist key conf-alist)
13523 (aput 'vhdl-package-alist key pack-alist)
13524 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13525 (aput 'vhdl-file-alist key file-alist)
13527 (message "Scanning %s %s\"%s\"...done"
13528 (if is-directory "directory" "files") (or num-string "") name)
13529 (unless project (message "Scanning directory...done"))
13531 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13532 ;; save cache when scanned non-interactively
13533 (when (or (not project) (not non-final))
13534 (when (and noninteractive vhdl-speedbar-save-cache)
13535 (vhdl-save-cache key)))
13538 (defun vhdl-scan-project-contents (project)
13539 "Scan the contents of all VHDL files found in the directories and files
13541 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13542 (default-dir (vhdl-resolve-env-variable
13543 (nth 1 (aget vhdl-project-alist project))))
13544 (file-exclude-regexp
13545 (or (nth 3 (aget vhdl-project-alist project)) ""))
13546 dir-list-tmp dir dir-name num-dir act-dir recursive)
13547 ;; clear project alists
13548 (adelete 'vhdl-entity-alist project)
13549 (adelete 'vhdl-config-alist project)
13550 (adelete 'vhdl-package-alist project)
13551 (adelete 'vhdl-ent-inst-alist project)
13552 (adelete 'vhdl-file-alist project)
13553 ;; expand directory names by default-directory
13554 (message "Collecting source files...")
13556 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13557 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13558 (setq recursive (match-string 1 dir)
13559 dir-name (match-string 3 dir))
13561 (cons (concat recursive
13562 (if (file-name-absolute-p dir-name) "" default-dir)
13565 (setq dir-list (cdr dir-list)))
13566 ;; resolve path wildcards
13567 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13568 ;; expand directories
13569 (while dir-list-tmp
13570 (setq dir (car dir-list-tmp))
13571 ;; get subdirectories
13572 (if (string-match "-r \\(.*[/\\]\\)" dir)
13573 (setq dir-list (append dir-list (vhdl-get-subdirs
13574 (match-string 1 dir))))
13575 (setq dir-list (append dir-list (list dir))))
13576 (setq dir-list-tmp (cdr dir-list-tmp)))
13578 (unless (equal file-exclude-regexp "")
13579 (let ((case-fold-search nil))
13581 (unless (string-match file-exclude-regexp (car dir-list))
13582 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13583 (setq dir-list (cdr dir-list)))
13584 (setq dir-list (nreverse dir-list-tmp))))
13585 (message "Collecting source files...done")
13586 ;; scan for design units for each directory in DIR-LIST
13587 (setq dir-list-tmp nil
13588 num-dir (length dir-list)
13591 (setq dir-name (abbreviate-file-name
13592 (expand-file-name (car dir-list))))
13593 (vhdl-scan-directory-contents dir-name project nil
13594 (format "(%s/%s) " act-dir num-dir)
13596 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13597 (setq dir-list (cdr dir-list)
13598 act-dir (1+ act-dir)))
13599 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13600 (message "Scanning project \"%s\"...done" project)))
13602 (defun vhdl-update-file-contents (file-name)
13603 "Update hierarchy information by contents of current buffer."
13604 (setq file-name (abbreviate-file-name file-name))
13605 (let* ((dir-name (file-name-directory file-name))
13606 (directory-alist vhdl-directory-alist)
13608 (while directory-alist
13609 (when (member dir-name (nth 1 (car directory-alist)))
13610 (let* ((vhdl-project (nth 0 (car directory-alist)))
13611 (project (vhdl-project-p))
13612 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13613 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13614 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13615 (ent-inst-list (car (aget vhdl-ent-inst-alist
13616 (or project dir-name) t)))
13617 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13618 (file-entry (aget file-alist file-name t))
13619 (ent-list (nth 0 file-entry))
13620 (arch-list (nth 1 file-entry))
13621 (arch-ent-list (nth 2 file-entry))
13622 (conf-list (nth 3 file-entry))
13623 (pack-list (nth 4 file-entry))
13624 (pack-body-list (nth 5 file-entry))
13625 (inst-ent-list (nth 7 file-entry))
13626 (cache-key (or project dir-name))
13627 arch-alist key ent-key entry)
13628 ;; delete design units previously contained in this file:
13631 (setq key (car ent-list)
13632 entry (aget ent-alist key t))
13633 (when (equal file-name (nth 1 entry))
13635 (aput 'ent-alist key
13636 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13637 (adelete 'ent-alist key)))
13638 (setq ent-list (cdr ent-list)))
13641 (setq key (car arch-list)
13642 ent-key (car arch-ent-list)
13643 entry (aget ent-alist ent-key t)
13644 arch-alist (nth 3 entry))
13645 (when (equal file-name (nth 1 (aget arch-alist key t)))
13646 (adelete 'arch-alist key)
13647 (if (or (nth 1 entry) arch-alist)
13648 (aput 'ent-alist ent-key
13649 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13650 arch-alist (nth 4 entry) (nth 5 entry)))
13651 (adelete 'ent-alist ent-key)))
13652 (setq arch-list (cdr arch-list)
13653 arch-ent-list (cdr arch-ent-list)))
13656 (setq key (car conf-list))
13657 (when (equal file-name (nth 1 (aget conf-alist key t)))
13658 (adelete 'conf-alist key))
13659 (setq conf-list (cdr conf-list)))
13660 ;; package declarations
13662 (setq key (car pack-list)
13663 entry (aget pack-alist key t))
13664 (when (equal file-name (nth 1 entry))
13666 (aput 'pack-alist key
13667 (list (nth 0 entry) nil nil nil nil nil
13668 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13670 (adelete 'pack-alist key)))
13671 (setq pack-list (cdr pack-list)))
13673 (while pack-body-list
13674 (setq key (car pack-body-list)
13675 entry (aget pack-alist key t))
13676 (when (equal file-name (nth 6 entry))
13678 (aput 'pack-alist key
13679 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13680 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13682 (adelete 'pack-alist key)))
13683 (setq pack-body-list (cdr pack-body-list)))
13684 ;; instantiated entities
13685 (while inst-ent-list
13686 (setq ent-inst-list
13687 (vhdl-delete (car inst-ent-list) ent-inst-list))
13688 (setq inst-ent-list (cdr inst-ent-list)))
13690 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13691 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13692 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13693 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13695 (vhdl-scan-directory-contents file-name project t)
13696 (when (or (and vhdl-speedbar-show-projects project)
13697 (and (not vhdl-speedbar-show-projects) (not project)))
13698 (vhdl-speedbar-refresh project))
13700 (setq directory-alist (cdr directory-alist)))
13703 (defun vhdl-update-hierarchy ()
13704 "Update directory and hierarchy information in speedbar."
13705 (let ((file-list (reverse vhdl-modified-file-list))
13707 (when (and vhdl-speedbar-update-on-saving file-list)
13710 (or (vhdl-update-file-contents (car file-list))
13712 (setq file-list (cdr file-list)))
13713 (setq vhdl-modified-file-list nil)
13714 (vhdl-speedbar-update-current-unit)
13715 (when updated (message "Updating hierarchy...done")))))
13717 ;; structure (parenthesised expression means list of such entries)
13718 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13719 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13720 ;; comp-lib-name level)
13721 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13722 conf-inst-alist level indent
13723 &optional include-top ent-hier)
13724 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13726 (let* ((ent-entry (aget ent-alist ent-key t))
13727 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13728 (cdar (last (nth 3 ent-entry)))))
13729 (inst-alist (nth 3 arch-entry))
13730 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13731 hier-list subcomp-list tmp-list inst-key inst-comp-name
13732 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13733 (when (= level 0) (message "Extract design hierarchy..."))
13735 (setq level (1+ level)))
13736 (when (member ent-key ent-hier)
13737 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13738 ;; check configured architecture (already checked during scanning)
13739 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13740 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13741 ;; process all instances
13743 (setq inst-entry (car inst-alist)
13744 inst-key (nth 0 inst-entry)
13745 inst-comp-name (nth 4 inst-entry)
13746 inst-conf-key (nth 7 inst-entry))
13747 ;; search entry in configuration's instantiations list
13748 (setq tmp-list conf-inst-alist)
13749 (while (and tmp-list
13750 (not (and (member (nth 0 (car tmp-list))
13751 (list "all" inst-key))
13752 (equal (nth 1 (car tmp-list))
13753 (downcase (or inst-comp-name ""))))))
13754 (setq tmp-list (cdr tmp-list)))
13755 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13756 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13757 (when (and inst-conf-key (not inst-conf-entry))
13758 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13759 ;; determine entity
13761 (or (nth 2 (car tmp-list)) ; from configuration
13762 (nth 3 inst-conf-entry) ; from subconfiguration
13763 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13764 ; from configuration spec.
13765 (nth 5 inst-entry))) ; from direct instantiation
13766 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13767 ;; determine architecture
13768 (setq inst-arch-key
13769 (or (nth 3 (car tmp-list)) ; from configuration
13770 (nth 4 inst-conf-entry) ; from subconfiguration
13771 (nth 6 inst-entry) ; from direct instantiation
13772 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13773 ; from configuration spec.
13774 (nth 4 inst-ent-entry) ; MRA
13775 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13776 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13779 (or (nth 5 (car tmp-list)) ; from configuration
13780 (nth 8 inst-entry))) ; from direct instantiation
13781 ;; gather information for this instance
13783 (list (nth 1 inst-entry)
13784 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13785 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13786 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13787 (or (nth 0 inst-arch-entry) inst-arch-key)
13788 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13789 (or (nth 0 inst-conf-entry) inst-conf-key)
13790 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13791 inst-lib-key level))
13792 ;; get subcomponent hierarchy
13793 (setq subcomp-list (vhdl-get-hierarchy
13794 ent-alist conf-alist
13795 inst-ent-key inst-arch-key inst-conf-key
13796 (nth 5 inst-conf-entry)
13797 (1+ level) indent nil (cons ent-key ent-hier)))
13799 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13800 (setq inst-alist (cdr inst-alist)))
13803 (cons (list nil nil (nth 0 ent-entry)
13804 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13806 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13810 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13813 (defun vhdl-get-instantiations (ent-key indent)
13814 "Get all instantiations of entity ENT-KEY."
13815 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13816 arch-alist inst-alist ent-inst-list
13817 ent-entry arch-entry inst-entry)
13819 (setq ent-entry (car ent-alist))
13820 (setq arch-alist (nth 4 ent-entry))
13822 (setq arch-entry (car arch-alist))
13823 (setq inst-alist (nth 4 arch-entry))
13825 (setq inst-entry (car inst-alist))
13826 (when (equal ent-key (nth 5 inst-entry))
13827 (setq ent-inst-list
13828 (cons (list (nth 1 inst-entry)
13829 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13831 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13833 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13835 (setq inst-alist (cdr inst-alist)))
13836 (setq arch-alist (cdr arch-alist)))
13837 (setq ent-alist (cdr ent-alist)))
13838 (nreverse ent-inst-list)))
13840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13843 (defun vhdl-save-caches ()
13844 "Save all updated hierarchy caches to file."
13846 (condition-case nil
13847 (when vhdl-speedbar-save-cache
13848 ;; update hierarchy
13849 (vhdl-update-hierarchy)
13850 (let ((project-list vhdl-updated-project-list))
13851 (message "Saving hierarchy caches...")
13852 ;; write updated project caches
13853 (while project-list
13854 (vhdl-save-cache (car project-list))
13855 (setq project-list (cdr project-list)))
13856 (message "Saving hierarchy caches...done")))
13857 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13860 (defun vhdl-save-cache (key)
13861 "Save current hierarchy cache to file."
13862 (let* ((orig-buffer (current-buffer))
13864 (project (vhdl-project-p))
13865 (default-directory key)
13866 (directory (abbreviate-file-name (vhdl-default-directory)))
13867 (file-name (vhdl-resolve-env-variable
13868 (vhdl-replace-string
13869 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13871 (subst-char-in-string ? ?_ (or project "dir"))
13872 " " (user-login-name)))))
13873 (file-dir-name (expand-file-name file-name directory))
13874 (cache-key (or project directory))
13875 (key (if project "project" "directory")))
13876 (unless (file-exists-p (file-name-directory file-dir-name))
13877 (make-directory (file-name-directory file-dir-name) t))
13878 (if (not (file-writable-p file-dir-name))
13879 (progn (vhdl-warning (format "File not writable: \"%s\""
13880 (abbreviate-file-name file-dir-name)))
13882 (message "Saving cache: \"%s\"" file-dir-name)
13883 (set-buffer (find-file-noselect file-dir-name t t))
13885 (insert ";; -*- Emacs-Lisp -*-\n\n"
13886 ";;; " (file-name-nondirectory file-name)
13887 " - design hierarchy cache file for Emacs VHDL Mode "
13889 (insert "\n;; " (if project "Project " "Directory") " : ")
13890 (if project (insert project) (prin1 directory (current-buffer)))
13891 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13892 (user-login-name) "\n\n"
13893 "\n;; version number\n"
13894 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13895 "\n;; " (if project "project" "directory") " name"
13896 "\n(setq " key " ")
13897 (prin1 (or project directory) (current-buffer))
13899 (when (member 'hierarchy vhdl-speedbar-save-cache)
13900 (insert "\n;; entity and architecture cache\n"
13901 "(aput 'vhdl-entity-alist " key " '")
13902 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13903 (insert ")\n\n;; configuration cache\n"
13904 "(aput 'vhdl-config-alist " key " '")
13905 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13906 (insert ")\n\n;; package cache\n"
13907 "(aput 'vhdl-package-alist " key " '")
13908 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13909 (insert ")\n\n;; instantiated entities cache\n"
13910 "(aput 'vhdl-ent-inst-alist " key " '")
13911 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13912 (insert ")\n\n;; design units per file cache\n"
13913 "(aput 'vhdl-file-alist " key " '")
13914 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13916 (insert ")\n\n;; source directories in project cache\n"
13917 "(aput 'vhdl-directory-alist " key " '")
13918 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13920 (when (member 'display vhdl-speedbar-save-cache)
13921 (insert "\n;; shown design units cache\n"
13922 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13923 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13926 (setq vhdl-updated-project-list
13927 (delete cache-key vhdl-updated-project-list))
13929 (kill-buffer (current-buffer))
13930 (set-buffer orig-buffer))))
13932 (defun vhdl-load-cache (key)
13933 "Load hierarchy cache information from file."
13934 (let* ((vhdl-project key)
13935 (default-directory key)
13936 (directory (vhdl-default-directory))
13937 (file-name (vhdl-resolve-env-variable
13938 (vhdl-replace-string
13939 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13941 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13942 " " (user-login-name)))))
13943 (file-dir-name (expand-file-name file-name directory))
13944 vhdl-cache-version)
13945 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13946 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13947 (when (file-exists-p file-dir-name)
13949 (progn (load-file file-dir-name)
13950 (string< (mapconcat
13951 (lambda (a) (format "%3d" (string-to-number a)))
13952 (split-string "3.33" "\\.") "")
13954 (lambda (a) (format "%3d" (string-to-number a)))
13955 (split-string vhdl-cache-version "\\.") "")))
13956 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13959 (defun vhdl-require-hierarchy-info ()
13960 "Make sure that hierarchy information is available. Load cache or scan files
13962 (if (vhdl-project-p)
13963 (unless (or (assoc vhdl-project vhdl-file-alist)
13964 (vhdl-load-cache vhdl-project))
13965 (vhdl-scan-project-contents vhdl-project))
13966 (let ((directory (abbreviate-file-name default-directory)))
13967 (unless (or (assoc directory vhdl-file-alist)
13968 (vhdl-load-cache directory))
13969 (vhdl-scan-directory-contents directory)))))
13971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13972 ;; Add hierarchy browser functionality to speedbar
13974 (defvar vhdl-speedbar-key-map nil
13975 "Keymap used when in the VHDL hierarchy browser mode.")
13977 (defvar vhdl-speedbar-menu-items nil
13978 "Additional menu-items to add to speedbar frame.")
13980 (defun vhdl-speedbar-initialize ()
13981 "Initialize speedbar."
13982 ;; general settings
13983 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13984 ;; VHDL file extensions (extracted from `auto-mode-alist')
13985 (let ((mode-alist auto-mode-alist))
13987 (when (eq (cdar mode-alist) 'vhdl-mode)
13988 (speedbar-add-supported-extension (caar mode-alist)))
13989 (setq mode-alist (cdr mode-alist))))
13990 ;; hierarchy browser settings
13991 (when (boundp 'speedbar-mode-functions-list)
13992 ;; special functions
13993 (speedbar-add-mode-functions-list
13995 (speedbar-item-info . vhdl-speedbar-item-info)
13996 (speedbar-line-directory . speedbar-files-line-path)))
13997 (speedbar-add-mode-functions-list
13999 (speedbar-item-info . vhdl-speedbar-item-info)
14000 (speedbar-line-directory . vhdl-speedbar-line-project)))
14002 (unless vhdl-speedbar-key-map
14003 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14004 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14005 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14006 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14007 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14008 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14009 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14010 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14011 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14012 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14013 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14014 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14015 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14016 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14019 (define-key vhdl-speedbar-key-map (int-to-string key)
14020 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14021 (setq key (1+ key)))))
14022 (define-key speedbar-key-map "h"
14023 (lambda () (interactive)
14024 (speedbar-change-initial-expansion-list "vhdl directory")))
14025 (define-key speedbar-key-map "H"
14026 (lambda () (interactive)
14027 (speedbar-change-initial-expansion-list "vhdl project")))
14029 (unless vhdl-speedbar-menu-items
14031 vhdl-speedbar-menu-items
14032 `(["Edit" speedbar-edit-line t]
14033 ["Expand" speedbar-expand-line
14034 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14035 ["Contract" vhdl-speedbar-contract-level t]
14036 ["Expand All" vhdl-speedbar-expand-all t]
14037 ["Contract All" vhdl-speedbar-contract-all t]
14038 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14041 (cons `[,(if (= key 0) "All" (int-to-string key))
14042 (vhdl-speedbar-set-depth ,key)
14044 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14045 :keys ,(int-to-string key)]
14047 (setq key (1+ key)))
14048 (nreverse menu-list))
14050 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14051 (or (vhdl-speedbar-check-unit 'entity)
14052 (vhdl-speedbar-check-unit 'subprogram))]
14053 ["Place Component" vhdl-speedbar-place-component
14054 (vhdl-speedbar-check-unit 'entity)]
14055 ["Generate Configuration" vhdl-speedbar-configuration
14056 (vhdl-speedbar-check-unit 'architecture)]
14057 ["Select as MRA" vhdl-speedbar-select-mra
14058 (vhdl-speedbar-check-unit 'architecture)]
14059 ["Make" vhdl-speedbar-make-design
14060 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14061 ["Generate Makefile" vhdl-speedbar-generate-makefile
14062 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14063 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14064 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14065 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14066 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14067 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14068 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14069 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14071 (speedbar-add-expansion-list
14072 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14073 vhdl-speedbar-display-directory))
14074 (speedbar-add-expansion-list
14075 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14076 vhdl-speedbar-display-projects))
14077 (setq speedbar-stealthy-function-list
14079 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14080 ("vhdl project" vhdl-speedbar-update-current-project
14081 vhdl-speedbar-update-current-unit)
14082 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14083 ; (speedbar-extension-list-to-regex
14084 ; speedbar-ignored-path-expressions))))
14086 speedbar-stealthy-function-list))
14087 (when (eq vhdl-speedbar-display-mode 'directory)
14088 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14089 (when (eq vhdl-speedbar-display-mode 'project)
14090 (setq speedbar-initial-expansion-list-name "vhdl project"))
14091 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14093 (defun vhdl-speedbar (&optional arg)
14094 "Open/close speedbar."
14096 (if (not (fboundp 'speedbar))
14097 (error "WARNING: Speedbar is not available or not installed")
14099 (speedbar-frame-mode arg)
14100 (error (error "WARNING: An error occurred while opening speedbar")))))
14102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14103 ;; Display functions
14105 (defvar vhdl-speedbar-last-selected-project nil
14106 "Name of last selected project.")
14108 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14109 (defmacro speedbar-with-writable (&rest forms)
14110 "Allow the buffer to be writable and evaluate FORMS."
14111 (list 'let '((inhibit-read-only t))
14112 (cons 'progn forms)))
14113 (put 'speedbar-with-writable 'lisp-indent-function 0)
14115 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14116 "Display directory and hierarchy information in speedbar."
14117 (setq vhdl-speedbar-show-projects nil)
14118 (setq speedbar-ignored-directory-regexp
14119 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14120 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14121 (setq speedbar-last-selected-file nil)
14122 (speedbar-with-writable
14123 (condition-case nil
14125 ;; insert directory path
14126 (speedbar-directory-buttons directory depth)
14127 ;; insert subdirectories
14128 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14129 ;; scan and insert hierarchy of current directory
14130 (vhdl-speedbar-insert-dir-hierarchy directory depth
14131 speedbar-power-click)
14132 ;; expand subdirectories
14133 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14134 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14136 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14137 "Display projects and hierarchy information in speedbar."
14138 (setq vhdl-speedbar-show-projects t)
14139 (setq speedbar-ignored-directory-regexp ".")
14140 (setq speedbar-last-selected-file nil)
14141 (setq vhdl-speedbar-last-selected-project nil)
14142 (speedbar-with-writable
14143 (condition-case nil
14145 (vhdl-speedbar-insert-projects)
14146 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14147 (setq speedbar-full-text-cache nil)) ; prevent caching
14149 (defun vhdl-speedbar-insert-projects ()
14150 "Insert all projects in speedbar."
14151 (vhdl-speedbar-make-title-line "Projects:")
14152 (let ((project-alist (if vhdl-project-sort
14153 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14154 vhdl-project-alist))
14155 (vhdl-speedbar-update-current-unit nil))
14157 (while project-alist
14158 (speedbar-make-tag-line
14159 'angle ?+ 'vhdl-speedbar-expand-project
14160 (caar project-alist) (caar project-alist)
14161 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14162 (setq project-alist (cdr project-alist)))
14163 (setq project-alist vhdl-project-alist)
14165 (while project-alist
14166 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14167 (goto-char (point-min))
14168 (when (re-search-forward
14169 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14170 (goto-char (match-end 1))
14171 (speedbar-do-function-pointer)))
14172 (setq project-alist (cdr project-alist))))
14173 ; (vhdl-speedbar-update-current-project)
14174 ; (vhdl-speedbar-update-current-unit nil t)
14177 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14178 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14179 otherwise use cached data."
14180 (when (or rescan (and (not (assoc project vhdl-file-alist))
14181 (not (vhdl-load-cache project))))
14182 (vhdl-scan-project-contents project))
14183 ;; insert design hierarchy
14184 (vhdl-speedbar-insert-hierarchy
14185 (aget vhdl-entity-alist project t)
14186 (aget vhdl-config-alist project t)
14187 (aget vhdl-package-alist project t)
14188 (car (aget vhdl-ent-inst-alist project t)) indent)
14189 (insert (int-to-string indent) ":\n")
14190 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14191 (put-text-property (1- (point)) (point) 'invisible nil)
14192 ;; expand design units
14193 (vhdl-speedbar-expand-units project))
14195 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14196 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14197 otherwise use cached data."
14198 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14199 (not (vhdl-load-cache directory))))
14200 (vhdl-scan-directory-contents directory))
14201 ;; insert design hierarchy
14202 (vhdl-speedbar-insert-hierarchy
14203 (aget vhdl-entity-alist directory t)
14204 (aget vhdl-config-alist directory t)
14205 (aget vhdl-package-alist directory t)
14206 (car (aget vhdl-ent-inst-alist directory t)) depth)
14207 ;; expand design units
14208 (vhdl-speedbar-expand-units directory)
14209 (aput 'vhdl-directory-alist directory (list (list directory))))
14211 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14212 ent-inst-list depth)
14213 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14214 (if (not (or ent-alist conf-alist pack-alist))
14215 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14216 (let (ent-entry conf-entry pack-entry)
14218 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14220 (setq ent-entry (car ent-alist))
14221 (speedbar-make-tag-line
14222 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14223 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14224 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14225 'vhdl-speedbar-entity-face depth)
14226 (unless (nth 2 ent-entry)
14227 (end-of-line 0) (insert "!") (forward-char 1))
14228 (unless (member (nth 0 ent-entry) ent-inst-list)
14229 (end-of-line 0) (insert " (top)") (forward-char 1))
14230 (setq ent-alist (cdr ent-alist)))
14231 ;; insert configurations
14232 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14234 (setq conf-entry (car conf-alist))
14235 (speedbar-make-tag-line
14236 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14237 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14238 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14239 'vhdl-speedbar-configuration-face depth)
14240 (setq conf-alist (cdr conf-alist)))
14242 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14244 (setq pack-entry (car pack-alist))
14245 (vhdl-speedbar-make-pack-line
14246 (nth 0 pack-entry) (nth 1 pack-entry)
14247 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14248 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14250 (setq pack-alist (cdr pack-alist))))))
14252 (defun vhdl-speedbar-rescan-hierarchy ()
14253 "Rescan hierarchy for the directory or project under the cursor."
14258 (vhdl-speedbar-show-projects
14259 (setq key (vhdl-speedbar-line-project))
14260 (vhdl-scan-project-contents key))
14261 ;; top-level directory
14262 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14263 (re-search-forward "[0-9]+:" nil t)
14264 (vhdl-scan-directory-contents
14265 (abbreviate-file-name (speedbar-line-directory))))
14266 ;; current directory
14267 (t (setq path (speedbar-line-directory))
14268 (string-match "^\\(.+[/\\]\\)" path)
14269 (vhdl-scan-directory-contents
14270 (abbreviate-file-name (match-string 1 path)))))
14271 (vhdl-speedbar-refresh key)))
14273 (defun vhdl-speedbar-expand-dirs (directory)
14274 "Expand subdirectories in DIRECTORY according to
14275 `speedbar-shown-directories'."
14276 ;; (nicked from `speedbar-default-directory-list')
14277 (let ((sf (cdr (reverse speedbar-shown-directories)))
14278 (vhdl-speedbar-update-current-unit nil))
14279 (setq speedbar-shown-directories
14280 (list (expand-file-name default-directory)))
14282 (when (speedbar-goto-this-file (car sf))
14283 (beginning-of-line)
14284 (when (looking-at "[0-9]+:\\s-*<")
14285 (goto-char (match-end 0))
14286 (speedbar-do-function-pointer)))
14287 (setq sf (cdr sf))))
14288 (vhdl-speedbar-update-current-unit nil t))
14290 (defun vhdl-speedbar-expand-units (key)
14291 "Expand design units in directory/project KEY according to
14292 `vhdl-speedbar-shown-unit-alist'."
14293 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14294 (vhdl-speedbar-update-current-unit nil)
14295 vhdl-updated-project-list)
14296 (adelete 'vhdl-speedbar-shown-unit-alist key)
14297 (vhdl-prepare-search-1
14298 (while unit-alist ; expand units
14299 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14300 (beginning-of-line)
14301 (let ((arch-alist (nth 1 (car unit-alist)))
14303 (when (looking-at "^[0-9]+:\\s-*\\[")
14304 (goto-char (match-end 0))
14305 (setq position (point))
14306 (speedbar-do-function-pointer)
14307 (select-frame speedbar-frame)
14308 (while arch-alist ; expand architectures
14309 (goto-char position)
14310 (when (re-search-forward
14311 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14312 (car arch-alist) "\\>\\)") nil t)
14313 (beginning-of-line)
14314 (when (looking-at "^[0-9]+:\\s-*{")
14315 (goto-char (match-end 0))
14316 (speedbar-do-function-pointer)
14317 (select-frame speedbar-frame)))
14318 (setq arch-alist (cdr arch-alist))))
14319 (setq unit-alist (cdr unit-alist))))))
14320 (vhdl-speedbar-update-current-unit nil t))
14322 (defun vhdl-speedbar-contract-level ()
14323 "Contract current level in current directory/project."
14325 (when (or (save-excursion
14326 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14327 (and (save-excursion
14328 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14329 (re-search-backward
14330 (format "^[0-%d]:\\s-*[[{<]-"
14331 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14332 (goto-char (match-end 0))
14333 (speedbar-do-function-pointer)
14334 (speedbar-center-buffer-smartly)))
14336 (defun vhdl-speedbar-contract-all ()
14337 "Contract all expanded design units in current directory/project."
14339 (if (and vhdl-speedbar-show-projects
14340 (save-excursion (beginning-of-line) (looking-at "^0:")))
14341 (progn (setq vhdl-speedbar-shown-project-list nil)
14342 (vhdl-speedbar-refresh))
14343 (let ((key (vhdl-speedbar-line-key)))
14344 (adelete 'vhdl-speedbar-shown-unit-alist key)
14345 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14346 (when (memq 'display vhdl-speedbar-save-cache)
14347 (add-to-list 'vhdl-updated-project-list key)))))
14349 (defun vhdl-speedbar-expand-all ()
14350 "Expand all design units in current directory/project."
14352 (let* ((key (vhdl-speedbar-line-key))
14353 (ent-alist (aget vhdl-entity-alist key t))
14354 (conf-alist (aget vhdl-config-alist key t))
14355 (pack-alist (aget vhdl-package-alist key t))
14356 arch-alist unit-alist subunit-alist)
14357 (add-to-list 'vhdl-speedbar-shown-project-list key)
14359 (setq arch-alist (nth 4 (car ent-alist)))
14360 (setq subunit-alist nil)
14362 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14363 (setq arch-alist (cdr arch-alist)))
14364 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14365 (setq ent-alist (cdr ent-alist)))
14367 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14368 (setq conf-alist (cdr conf-alist)))
14370 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14371 (setq pack-alist (cdr pack-alist)))
14372 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14373 (vhdl-speedbar-refresh)
14374 (when (memq 'display vhdl-speedbar-save-cache)
14375 (add-to-list 'vhdl-updated-project-list key))))
14377 (defun vhdl-speedbar-expand-project (text token indent)
14378 "Expand/contract the project under the cursor."
14380 ((string-match "+" text) ; expand project
14381 (speedbar-change-expand-button-char ?-)
14382 (unless (member token vhdl-speedbar-shown-project-list)
14383 (setq vhdl-speedbar-shown-project-list
14384 (cons token vhdl-speedbar-shown-project-list)))
14385 (speedbar-with-writable
14387 (end-of-line) (forward-char 1)
14388 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14389 speedbar-power-click))))
14390 ((string-match "-" text) ; contract project
14391 (speedbar-change-expand-button-char ?+)
14392 (setq vhdl-speedbar-shown-project-list
14393 (delete token vhdl-speedbar-shown-project-list))
14394 (speedbar-delete-subblock indent))
14395 (t (error "Nothing to display")))
14396 (when (equal (selected-frame) speedbar-frame)
14397 (speedbar-center-buffer-smartly)))
14399 (defun vhdl-speedbar-expand-entity (text token indent)
14400 "Expand/contract the entity under the cursor."
14402 ((string-match "+" text) ; expand entity
14403 (let* ((key (vhdl-speedbar-line-key indent))
14404 (ent-alist (aget vhdl-entity-alist key t))
14405 (ent-entry (aget ent-alist token t))
14406 (arch-alist (nth 3 ent-entry))
14407 (inst-alist (vhdl-get-instantiations token indent))
14408 (subpack-alist (nth 5 ent-entry))
14409 (multiple-arch (> (length arch-alist) 1))
14410 arch-entry inst-entry)
14411 (if (not (or arch-alist inst-alist subpack-alist))
14412 (speedbar-change-expand-button-char ??)
14413 (speedbar-change-expand-button-char ?-)
14414 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14415 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14416 (aput 'unit-alist token nil)
14417 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14418 (speedbar-with-writable
14420 (end-of-line) (forward-char 1)
14421 ;; insert architectures
14423 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14425 (setq arch-entry (car arch-alist))
14426 (speedbar-make-tag-line
14427 'curly ?+ 'vhdl-speedbar-expand-architecture
14428 (cons token (nth 0 arch-entry))
14429 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14430 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14431 'vhdl-speedbar-architecture-face (1+ indent))
14432 (when (and multiple-arch
14433 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14434 (end-of-line 0) (insert " (mra)") (forward-char 1))
14435 (setq arch-alist (cdr arch-alist)))
14436 ;; insert instantiations
14438 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14440 (setq inst-entry (car inst-alist))
14441 (vhdl-speedbar-make-inst-line
14442 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14443 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14444 nil nil nil (1+ indent) 0 " in ")
14445 (setq inst-alist (cdr inst-alist)))
14446 ;; insert required packages
14447 (vhdl-speedbar-insert-subpackages
14448 subpack-alist (1+ indent) indent)))
14449 (when (memq 'display vhdl-speedbar-save-cache)
14450 (add-to-list 'vhdl-updated-project-list key))
14451 (vhdl-speedbar-update-current-unit t t))))
14452 ((string-match "-" text) ; contract entity
14453 (speedbar-change-expand-button-char ?+)
14454 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14455 (let* ((key (vhdl-speedbar-line-key indent))
14456 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14457 (adelete 'unit-alist token)
14459 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14460 (adelete 'vhdl-speedbar-shown-unit-alist key))
14461 (speedbar-delete-subblock indent)
14462 (when (memq 'display vhdl-speedbar-save-cache)
14463 (add-to-list 'vhdl-updated-project-list key))))
14464 (t (error "Nothing to display")))
14465 (when (equal (selected-frame) speedbar-frame)
14466 (speedbar-center-buffer-smartly)))
14468 (defun vhdl-speedbar-expand-architecture (text token indent)
14469 "Expand/contract the architecture under the cursor."
14471 ((string-match "+" text) ; expand architecture
14472 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14473 (ent-alist (aget vhdl-entity-alist key t))
14474 (conf-alist (aget vhdl-config-alist key t))
14475 (hier-alist (vhdl-get-hierarchy
14476 ent-alist conf-alist (car token) (cdr token) nil nil
14478 (ent-entry (aget ent-alist (car token) t))
14479 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14480 (subpack-alist (nth 4 arch-entry))
14482 (if (not (or hier-alist subpack-alist))
14483 (speedbar-change-expand-button-char ??)
14484 (speedbar-change-expand-button-char ?-)
14485 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14486 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14487 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14488 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14489 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14490 (speedbar-with-writable
14492 (end-of-line) (forward-char 1)
14493 ;; insert instance hierarchy
14495 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14498 (setq entry (car hier-alist))
14499 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14500 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14501 (vhdl-speedbar-make-inst-line
14502 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14503 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14504 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14505 (setq hier-alist (cdr hier-alist)))
14506 ;; insert required packages
14507 (vhdl-speedbar-insert-subpackages
14508 subpack-alist (1+ indent) (1- indent))))
14509 (when (memq 'display vhdl-speedbar-save-cache)
14510 (add-to-list 'vhdl-updated-project-list key))
14511 (vhdl-speedbar-update-current-unit t t))))
14512 ((string-match "-" text) ; contract architecture
14513 (speedbar-change-expand-button-char ?+)
14514 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14515 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14516 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14517 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14518 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14519 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14520 (speedbar-delete-subblock indent)
14521 (when (memq 'display vhdl-speedbar-save-cache)
14522 (add-to-list 'vhdl-updated-project-list key))))
14523 (t (error "Nothing to display")))
14524 (when (equal (selected-frame) speedbar-frame)
14525 (speedbar-center-buffer-smartly)))
14527 (defun vhdl-speedbar-expand-config (text token indent)
14528 "Expand/contract the configuration under the cursor."
14530 ((string-match "+" text) ; expand configuration
14531 (let* ((key (vhdl-speedbar-line-key indent))
14532 (conf-alist (aget vhdl-config-alist key t))
14533 (conf-entry (aget conf-alist token))
14534 (ent-alist (aget vhdl-entity-alist key t))
14535 (hier-alist (vhdl-get-hierarchy
14536 ent-alist conf-alist (nth 3 conf-entry)
14537 (nth 4 conf-entry) token (nth 5 conf-entry)
14539 (subpack-alist (nth 6 conf-entry))
14541 (if (not (or hier-alist subpack-alist))
14542 (speedbar-change-expand-button-char ??)
14543 (speedbar-change-expand-button-char ?-)
14544 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14545 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14546 (aput 'unit-alist token nil)
14547 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14548 (speedbar-with-writable
14550 (end-of-line) (forward-char 1)
14551 ;; insert instance hierarchy
14553 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14555 (setq entry (car hier-alist))
14556 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14557 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14558 (vhdl-speedbar-make-inst-line
14559 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14560 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14561 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14562 (setq hier-alist (cdr hier-alist)))
14563 ;; insert required packages
14564 (vhdl-speedbar-insert-subpackages
14565 subpack-alist (1+ indent) indent)))
14566 (when (memq 'display vhdl-speedbar-save-cache)
14567 (add-to-list 'vhdl-updated-project-list key))
14568 (vhdl-speedbar-update-current-unit t t))))
14569 ((string-match "-" text) ; contract configuration
14570 (speedbar-change-expand-button-char ?+)
14571 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14572 (let* ((key (vhdl-speedbar-line-key indent))
14573 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14574 (adelete 'unit-alist token)
14576 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14577 (adelete 'vhdl-speedbar-shown-unit-alist key))
14578 (speedbar-delete-subblock indent)
14579 (when (memq 'display vhdl-speedbar-save-cache)
14580 (add-to-list 'vhdl-updated-project-list key))))
14581 (t (error "Nothing to display")))
14582 (when (equal (selected-frame) speedbar-frame)
14583 (speedbar-center-buffer-smartly)))
14585 (defun vhdl-speedbar-expand-package (text token indent)
14586 "Expand/contract the package under the cursor."
14588 ((string-match "+" text) ; expand package
14589 (let* ((key (vhdl-speedbar-line-key indent))
14590 (pack-alist (aget vhdl-package-alist key t))
14591 (pack-entry (aget pack-alist token t))
14592 (comp-alist (nth 3 pack-entry))
14593 (func-alist (nth 4 pack-entry))
14594 (func-body-alist (nth 8 pack-entry))
14595 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14596 comp-entry func-entry func-body-entry)
14597 (if (not (or comp-alist func-alist subpack-alist))
14598 (speedbar-change-expand-button-char ??)
14599 (speedbar-change-expand-button-char ?-)
14600 ;; add package to `vhdl-speedbar-shown-unit-alist'
14601 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14602 (aput 'unit-alist token nil)
14603 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14604 (speedbar-with-writable
14606 (end-of-line) (forward-char 1)
14607 ;; insert components
14609 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14611 (setq comp-entry (car comp-alist))
14612 (speedbar-make-tag-line
14614 (cons token (nth 0 comp-entry))
14615 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14616 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14617 'vhdl-speedbar-entity-face (1+ indent))
14618 (setq comp-alist (cdr comp-alist)))
14619 ;; insert subprograms
14621 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14623 (setq func-entry (car func-alist)
14624 func-body-entry (aget func-body-alist (car func-entry) t))
14625 (when (nth 2 func-entry)
14626 (vhdl-speedbar-make-subprogram-line
14628 (cons (nth 2 func-entry) (nth 3 func-entry))
14629 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14631 (setq func-alist (cdr func-alist)))
14632 ;; insert required packages
14633 (vhdl-speedbar-insert-subpackages
14634 subpack-alist (1+ indent) indent)))
14635 (when (memq 'display vhdl-speedbar-save-cache)
14636 (add-to-list 'vhdl-updated-project-list key))
14637 (vhdl-speedbar-update-current-unit t t))))
14638 ((string-match "-" text) ; contract package
14639 (speedbar-change-expand-button-char ?+)
14640 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14641 (let* ((key (vhdl-speedbar-line-key indent))
14642 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14643 (adelete 'unit-alist token)
14645 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14646 (adelete 'vhdl-speedbar-shown-unit-alist key))
14647 (speedbar-delete-subblock indent)
14648 (when (memq 'display vhdl-speedbar-save-cache)
14649 (add-to-list 'vhdl-updated-project-list key))))
14650 (t (error "Nothing to display")))
14651 (when (equal (selected-frame) speedbar-frame)
14652 (speedbar-center-buffer-smartly)))
14654 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14655 "Insert required packages."
14656 (let* ((pack-alist (aget vhdl-package-alist
14657 (vhdl-speedbar-line-key dir-indent) t))
14658 pack-key lib-name pack-entry)
14659 (when subpack-alist
14660 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14661 (while subpack-alist
14662 (setq pack-key (cdar subpack-alist)
14663 lib-name (caar subpack-alist))
14664 (setq pack-entry (aget pack-alist pack-key t))
14665 (vhdl-speedbar-make-subpack-line
14666 (or (nth 0 pack-entry) pack-key) lib-name
14667 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14668 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14669 (setq subpack-alist (cdr subpack-alist)))))
14671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14672 ;; Display help functions
14674 (defvar vhdl-speedbar-update-current-unit t
14675 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14677 (defun vhdl-speedbar-update-current-project ()
14678 "Highlight project that is currently active."
14679 (when (and vhdl-speedbar-show-projects
14680 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14681 (and (boundp 'speedbar-frame)
14682 (frame-live-p speedbar-frame)))
14683 (let ((last-frame (selected-frame))
14684 (project-alist vhdl-project-alist)
14686 (select-frame speedbar-frame)
14687 (speedbar-with-writable
14689 (while project-alist
14690 (goto-char (point-min))
14691 (when (re-search-forward
14692 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14693 (put-text-property (match-beginning 1) (match-end 1) 'face
14694 (if (equal (caar project-alist) vhdl-project)
14695 'speedbar-selected-face
14696 'speedbar-directory-face))
14697 (when (equal (caar project-alist) vhdl-project)
14698 (setq pos (1- (match-beginning 1)))))
14699 (setq project-alist (cdr project-alist))))
14700 (when pos (goto-char pos)))
14701 (select-frame last-frame)
14702 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14705 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14706 "Highlight all design units that are contained in the current file.
14707 NO-POSITION non-nil means do not re-position cursor."
14708 (let ((last-frame (selected-frame))
14709 (project-list vhdl-speedbar-shown-project-list)
14710 file-alist pos file-name)
14711 ;; get current file name
14712 (if (fboundp 'speedbar-select-attached-frame)
14713 (speedbar-select-attached-frame)
14714 (select-frame speedbar-attached-frame))
14715 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14716 (when (and vhdl-speedbar-update-current-unit
14717 (or always (not (equal file-name speedbar-last-selected-file))))
14718 (if vhdl-speedbar-show-projects
14719 (while project-list
14720 (setq file-alist (append file-alist (aget vhdl-file-alist
14721 (car project-list) t)))
14722 (setq project-list (cdr project-list)))
14723 (setq file-alist (aget vhdl-file-alist
14724 (abbreviate-file-name default-directory) t)))
14725 (select-frame speedbar-frame)
14726 (set-buffer speedbar-buffer)
14727 (speedbar-with-writable
14728 (vhdl-prepare-search-1
14730 ;; unhighlight last units
14731 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14732 (vhdl-speedbar-update-units
14733 "\\[.\\] " (nth 0 file-entry)
14734 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14735 (vhdl-speedbar-update-units
14736 "{.} " (nth 1 file-entry)
14737 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14738 (vhdl-speedbar-update-units
14739 "\\[.\\] " (nth 3 file-entry)
14740 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14741 (vhdl-speedbar-update-units
14742 "[]>] " (nth 4 file-entry)
14743 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14744 (vhdl-speedbar-update-units
14745 "\\[.\\].+(" '("body")
14746 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14747 (vhdl-speedbar-update-units
14748 "> " (nth 6 file-entry)
14749 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14750 ;; highlight current units
14751 (let* ((file-entry (aget file-alist file-name t)))
14753 pos (vhdl-speedbar-update-units
14754 "\\[.\\] " (nth 0 file-entry)
14755 file-name 'vhdl-speedbar-entity-selected-face pos)
14756 pos (vhdl-speedbar-update-units
14757 "{.} " (nth 1 file-entry)
14758 file-name 'vhdl-speedbar-architecture-selected-face pos)
14759 pos (vhdl-speedbar-update-units
14760 "\\[.\\] " (nth 3 file-entry)
14761 file-name 'vhdl-speedbar-configuration-selected-face pos)
14762 pos (vhdl-speedbar-update-units
14763 "[]>] " (nth 4 file-entry)
14764 file-name 'vhdl-speedbar-package-selected-face pos)
14765 pos (vhdl-speedbar-update-units
14766 "\\[.\\].+(" '("body")
14767 file-name 'vhdl-speedbar-package-selected-face pos)
14768 pos (vhdl-speedbar-update-units
14769 "> " (nth 6 file-entry)
14770 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14771 ;; move speedbar so the first highlighted unit is visible
14772 (when (and pos (not no-position))
14774 (speedbar-center-buffer-smartly)
14775 (speedbar-position-cursor-on-line))
14776 (setq speedbar-last-selected-file file-name))
14777 (select-frame last-frame)
14780 (defun vhdl-speedbar-update-units (text unit-list file-name face
14782 "Help function to highlight design units."
14784 (goto-char (point-min))
14785 (while (re-search-forward
14786 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14787 (when (equal file-name (car (get-text-property
14788 (match-beginning 1) 'speedbar-token)))
14789 (setq pos (or pos (point-marker)))
14790 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14791 (setq unit-list (cdr unit-list)))
14794 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14795 ent-name ent-file-marker
14796 arch-name arch-file-marker
14797 conf-name conf-file-marker
14798 lib-name depth offset delimiter)
14799 "Insert instantiation entry."
14800 (let ((start (point))
14802 (insert (int-to-string depth) ":")
14803 (put-text-property start (point) 'invisible t)
14804 (setq visible-start (point))
14805 (insert-char ? (* depth speedbar-indentation-width))
14806 (while (> offset 0)
14808 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14809 (setq offset (1- offset)))
14810 (put-text-property visible-start (point) 'invisible nil)
14811 (setq start (point))
14813 (speedbar-make-button start (point) nil nil nil)
14814 (setq visible-start (point))
14816 (setq start (point))
14817 (if (not inst-name)
14820 (speedbar-make-button
14821 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14822 'vhdl-speedbar-find-file inst-file-marker))
14825 (setq start (point))
14827 (speedbar-make-button
14828 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14829 'vhdl-speedbar-find-file ent-file-marker)
14832 (setq start (point))
14834 (speedbar-make-button
14835 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14836 'vhdl-speedbar-find-file arch-file-marker)
14840 (setq start (point))
14842 (speedbar-make-button
14843 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14844 'vhdl-speedbar-find-file conf-file-marker)
14846 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14847 (setq start (point))
14848 (insert " (" lib-name ")")
14849 (put-text-property (+ 2 start) (1- (point)) 'face
14850 'vhdl-speedbar-library-face))
14851 (insert-char ?\n 1)
14852 (put-text-property visible-start (point) 'invisible nil)))
14854 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14855 body-file-marker depth)
14856 "Insert package entry."
14857 (let ((start (point))
14859 (insert (int-to-string depth) ":")
14860 (put-text-property start (point) 'invisible t)
14861 (setq visible-start (point))
14862 (insert-char ? (* depth speedbar-indentation-width))
14863 (put-text-property visible-start (point) 'invisible nil)
14864 (setq start (point))
14866 (speedbar-make-button
14867 start (point) 'speedbar-button-face 'speedbar-highlight-face
14868 'vhdl-speedbar-expand-package pack-key)
14869 (setq visible-start (point))
14870 (insert-char ? 1 nil)
14871 (setq start (point))
14873 (speedbar-make-button
14874 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14875 'vhdl-speedbar-find-file pack-file-marker)
14876 (unless (car pack-file-marker)
14878 (when (car body-file-marker)
14880 (setq start (point))
14882 (speedbar-make-button
14883 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14884 'vhdl-speedbar-find-file body-file-marker)
14886 (insert-char ?\n 1)
14887 (put-text-property visible-start (point) 'invisible nil)))
14889 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14890 pack-body-file-marker depth)
14891 "Insert used package entry."
14892 (let ((start (point))
14894 (insert (int-to-string depth) ":")
14895 (put-text-property start (point) 'invisible t)
14896 (setq visible-start (point))
14897 (insert-char ? (* depth speedbar-indentation-width))
14898 (put-text-property visible-start (point) 'invisible nil)
14899 (setq start (point))
14901 (speedbar-make-button start (point) nil nil nil)
14902 (setq visible-start (point))
14904 (setq start (point))
14906 (speedbar-make-button
14907 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14908 'vhdl-speedbar-find-file pack-file-marker)
14909 (when (car pack-body-file-marker)
14911 (setq start (point))
14913 (speedbar-make-button
14914 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14915 'vhdl-speedbar-find-file pack-body-file-marker)
14917 (setq start (point))
14918 (insert " (" lib-name ")")
14919 (put-text-property (+ 2 start) (1- (point)) 'face
14920 'vhdl-speedbar-library-face)
14921 (insert-char ?\n 1)
14922 (put-text-property visible-start (point) 'invisible nil)))
14924 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14925 func-body-file-marker
14927 "Insert subprogram entry."
14928 (let ((start (point))
14930 (insert (int-to-string depth) ":")
14931 (put-text-property start (point) 'invisible t)
14932 (setq visible-start (point))
14933 (insert-char ? (* depth speedbar-indentation-width))
14934 (put-text-property visible-start (point) 'invisible nil)
14935 (setq start (point))
14937 (speedbar-make-button start (point) nil nil nil)
14938 (setq visible-start (point))
14940 (setq start (point))
14942 (speedbar-make-button
14943 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14944 'vhdl-speedbar-find-file func-file-marker)
14945 (when (car func-body-file-marker)
14947 (setq start (point))
14949 (speedbar-make-button
14950 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14951 'vhdl-speedbar-find-file func-body-file-marker)
14953 (insert-char ?\n 1)
14954 (put-text-property visible-start (point) 'invisible nil)))
14956 (defun vhdl-speedbar-make-title-line (text &optional depth)
14957 "Insert design unit title entry."
14958 (let ((start (point))
14961 (insert (int-to-string depth) ":")
14962 (put-text-property start (point) 'invisible t))
14963 (setq visible-start (point))
14964 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14965 (setq start (point))
14967 (speedbar-make-button start (point) nil nil nil nil)
14968 (insert-char ?\n 1)
14969 (put-text-property visible-start (point) 'invisible nil)))
14971 (defun vhdl-speedbar-insert-dirs (files level)
14972 "Insert subdirectories."
14973 (let ((dirs (car files)))
14975 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14976 (car dirs) 'speedbar-dir-follow nil
14977 'speedbar-directory-face level)
14978 (setq dirs (cdr dirs)))))
14980 (defun vhdl-speedbar-dired (text token indent)
14981 "Speedbar click handler for directory expand button in hierarchy mode."
14982 (cond ((string-match "+" text) ; we have to expand this dir
14983 (setq speedbar-shown-directories
14984 (cons (expand-file-name
14985 (concat (speedbar-line-directory indent) token "/"))
14986 speedbar-shown-directories))
14987 (speedbar-change-expand-button-char ?-)
14988 (speedbar-reset-scanners)
14989 (speedbar-with-writable
14991 (end-of-line) (forward-char 1)
14992 (vhdl-speedbar-insert-dirs
14993 (speedbar-file-lists
14994 (concat (speedbar-line-directory indent) token "/"))
14996 (speedbar-reset-scanners)
14997 (vhdl-speedbar-insert-dir-hierarchy
14998 (abbreviate-file-name
14999 (concat (speedbar-line-directory indent) token "/"))
15000 (1+ indent) speedbar-power-click)))
15001 (vhdl-speedbar-update-current-unit t t))
15002 ((string-match "-" text) ; we have to contract this node
15003 (speedbar-reset-scanners)
15004 (let ((oldl speedbar-shown-directories)
15006 (td (expand-file-name
15007 (concat (speedbar-line-directory indent) token))))
15009 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15010 (setq newl (cons (car oldl) newl)))
15011 (setq oldl (cdr oldl)))
15012 (setq speedbar-shown-directories (nreverse newl)))
15013 (speedbar-change-expand-button-char ?+)
15014 (speedbar-delete-subblock indent))
15015 (t (error "Nothing to display")))
15016 (when (equal (selected-frame) speedbar-frame)
15017 (speedbar-center-buffer-smartly)))
15019 (defun vhdl-speedbar-item-info ()
15020 "Derive and display information about this line item."
15022 (beginning-of-line)
15023 ;; skip invisible number info
15024 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15026 ;; project/directory entry
15027 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15028 (if vhdl-speedbar-show-projects
15029 (message "Project \"%s\"" (match-string-no-properties 1))
15030 (speedbar-files-item-info)))
15031 ;; design unit entry
15032 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15033 (goto-char (match-end 1))
15034 (let ((face (get-text-property (point) 'face)))
15036 "%s \"%s\" in \"%s\""
15037 ;; design unit kind
15038 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15039 (eq face 'vhdl-speedbar-entity-selected-face))
15040 (if (equal (match-string 2) ">") "Component" "Entity"))
15041 ((or (eq face 'vhdl-speedbar-architecture-face)
15042 (eq face 'vhdl-speedbar-architecture-selected-face))
15044 ((or (eq face 'vhdl-speedbar-configuration-face)
15045 (eq face 'vhdl-speedbar-configuration-selected-face))
15047 ((or (eq face 'vhdl-speedbar-package-face)
15048 (eq face 'vhdl-speedbar-package-selected-face))
15050 ((or (eq face 'vhdl-speedbar-instantiation-face)
15051 (eq face 'vhdl-speedbar-instantiation-selected-face))
15053 ((eq face 'vhdl-speedbar-subprogram-face)
15056 ;; design unit name
15057 (buffer-substring-no-properties
15058 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15061 (file-relative-name
15062 (or (car (get-text-property (point) 'speedbar-token))
15064 (vhdl-default-directory)))))
15065 (t (message "")))))
15067 (defun vhdl-speedbar-line-text ()
15068 "Calls `speedbar-line-text' and removes text properties."
15069 (let ((string (speedbar-line-text)))
15070 (set-text-properties 0 (length string) nil string)
15073 (defun vhdl-speedbar-higher-text ()
15074 "Get speedbar-line-text of higher level."
15075 (let (depth string)
15077 (beginning-of-line)
15078 (looking-at "^\\([0-9]+\\):")
15079 (setq depth (string-to-number (match-string 1)))
15080 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15081 (setq string (match-string 1))
15082 (set-text-properties 0 (length string) nil string)
15085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15088 (defun vhdl-speedbar-line-key (&optional indent)
15089 "Get currently displayed directory of project name."
15090 (if vhdl-speedbar-show-projects
15091 (vhdl-speedbar-line-project)
15092 (abbreviate-file-name
15093 (file-name-as-directory (speedbar-line-directory indent)))))
15095 (defun vhdl-speedbar-line-project (&optional indent)
15096 "Get currently displayed project name."
15097 (and vhdl-speedbar-show-projects
15100 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15101 (match-string-no-properties 1))))
15103 (defun vhdl-add-modified-file ()
15104 "Add file to `vhdl-modified-file-list'."
15105 (when vhdl-file-alist
15106 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15109 (defun vhdl-resolve-paths (path-list)
15110 "Resolve path wildcards in PATH-LIST."
15111 (let (path-list-1 path-list-2 path-beg path-end dir)
15112 ;; eliminate non-existent directories
15114 (setq dir (car path-list))
15115 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15116 (if (file-directory-p (match-string 2 dir))
15117 (setq path-list-1 (cons dir path-list-1))
15118 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15119 (setq path-list (cdr path-list)))
15120 ;; resolve path wildcards
15122 (setq dir (car path-list-1))
15123 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15125 (setq path-beg (match-string 1 dir)
15126 path-end (match-string 5 dir))
15131 (lambda (var) (concat path-beg var path-end)))
15132 (let ((all-list (vhdl-directory-files
15133 (match-string 2 dir) t
15134 (concat "\\<" (wildcard-to-regexp
15135 (match-string 4 dir)))))
15138 (when (file-directory-p (car all-list))
15139 (setq dir-list (cons (car all-list) dir-list)))
15140 (setq all-list (cdr all-list)))
15142 (cdr path-list-1))))
15143 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15144 (when (file-directory-p (match-string 2 dir))
15145 (setq path-list-2 (cons dir path-list-2)))
15146 (setq path-list-1 (cdr path-list-1))))
15147 (nreverse path-list-2)))
15149 (defun vhdl-speedbar-goto-this-unit (directory unit)
15150 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15151 (let ((dest (point)))
15152 (if (and (if vhdl-speedbar-show-projects
15153 (progn (goto-char (point-min)) t)
15154 (speedbar-goto-this-file directory))
15155 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15156 (progn (speedbar-position-cursor-on-line)
15161 (defun vhdl-speedbar-find-file (text token indent)
15162 "When user clicks on TEXT, load file with name and position in TOKEN.
15163 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15164 is already shown in a buffer."
15165 (if (not (car token))
15166 (error "ERROR: File cannot be found")
15167 (let ((buffer (get-file-buffer (car token))))
15168 (speedbar-find-file-in-frame (car token))
15169 (when (or vhdl-speedbar-jump-to-unit buffer)
15170 (goto-line (cdr token))
15172 (vhdl-speedbar-update-current-unit t t)
15173 (speedbar-set-timer speedbar-update-speed)
15174 (speedbar-maybee-jump-to-attached-frame))))
15176 (defun vhdl-speedbar-port-copy ()
15177 "Copy the port of the entity/component or subprogram under the cursor."
15179 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15180 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15181 (error "ERROR: No entity/component or subprogram under cursor")
15182 (beginning-of-line)
15183 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15184 (condition-case info
15185 (let ((token (get-text-property
15186 (match-beginning 3) 'speedbar-token)))
15187 (vhdl-visit-file (car token) t
15188 (progn (goto-line (cdr token))
15192 (vhdl-subprog-copy)))))
15193 (error (error "ERROR: %s not scanned successfully\n (%s)"
15194 (if is-entity "Port" "Interface") (cadr info))))
15195 (error "ERROR: No entity/component or subprogram on current line")))))
15197 (defun vhdl-speedbar-place-component ()
15198 "Place the entity/component under the cursor as component."
15200 (if (not (vhdl-speedbar-check-unit 'entity))
15201 (error "ERROR: No entity/component under cursor")
15202 (vhdl-speedbar-port-copy)
15203 (if (fboundp 'speedbar-select-attached-frame)
15204 (speedbar-select-attached-frame)
15205 (select-frame speedbar-attached-frame))
15206 (vhdl-compose-place-component)
15207 (select-frame speedbar-frame)))
15209 (defun vhdl-speedbar-configuration ()
15210 "Generate configuration for the architecture under the cursor."
15212 (if (not (vhdl-speedbar-check-unit 'architecture))
15213 (error "ERROR: No architecture under cursor")
15214 (let ((arch-name (vhdl-speedbar-line-text))
15215 (ent-name (vhdl-speedbar-higher-text)))
15216 (if (fboundp 'speedbar-select-attached-frame)
15217 (speedbar-select-attached-frame)
15218 (select-frame speedbar-attached-frame))
15219 (vhdl-compose-configuration ent-name arch-name))))
15221 (defun vhdl-speedbar-select-mra ()
15222 "Select the architecture under the cursor as MRA."
15224 (if (not (vhdl-speedbar-check-unit 'architecture))
15225 (error "ERROR: No architecture under cursor")
15226 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15227 (ent-key (downcase (vhdl-speedbar-higher-text)))
15228 (ent-alist (aget vhdl-entity-alist
15229 (or (vhdl-project-p) default-directory) t))
15230 (ent-entry (aget ent-alist ent-key t)))
15231 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15232 (speedbar-refresh))))
15234 (defun vhdl-speedbar-make-design ()
15235 "Make (compile) design unit or directory/project under the cursor."
15237 (if (not (save-excursion (beginning-of-line)
15238 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15239 (error "ERROR: No primary design unit or directory/project under cursor")
15240 (let ((is-unit (match-string 2))
15241 (unit-name (vhdl-speedbar-line-text))
15242 (vhdl-project (vhdl-speedbar-line-project))
15243 (directory (file-name-as-directory
15244 (or (speedbar-line-file) (speedbar-line-directory)))))
15245 (if (fboundp 'speedbar-select-attached-frame)
15246 (speedbar-select-attached-frame)
15247 (select-frame speedbar-attached-frame))
15248 (let ((default-directory directory))
15249 (vhdl-make (and is-unit unit-name))))))
15251 (defun vhdl-speedbar-generate-makefile ()
15252 "Generate Makefile for directory/project under the cursor."
15254 (let ((vhdl-project (vhdl-speedbar-line-project))
15255 (default-directory (file-name-as-directory
15256 (or (speedbar-line-file) (speedbar-line-directory)))))
15257 (vhdl-generate-makefile)))
15259 (defun vhdl-speedbar-check-unit (design-unit)
15260 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15261 expansion function)."
15263 (speedbar-position-cursor-on-line)
15264 (cond ((eq design-unit 'entity)
15265 (memq (get-text-property (match-end 0) 'face)
15266 '(vhdl-speedbar-entity-face
15267 vhdl-speedbar-entity-selected-face)))
15268 ((eq design-unit 'architecture)
15269 (memq (get-text-property (match-end 0) 'face)
15270 '(vhdl-speedbar-architecture-face
15271 vhdl-speedbar-architecture-selected-face)))
15272 ((eq design-unit 'subprogram)
15273 (eq (get-text-property (match-end 0) 'face)
15274 'vhdl-speedbar-subprogram-face))
15277 (defun vhdl-speedbar-set-depth (depth)
15278 "Set hierarchy display depth to DEPTH and refresh speedbar."
15279 (setq vhdl-speedbar-hierarchy-depth depth)
15280 (speedbar-refresh))
15282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15285 (defface vhdl-speedbar-entity-face
15286 '((((class color) (background light)) (:foreground "ForestGreen"))
15287 (((class color) (background dark)) (:foreground "PaleGreen")))
15288 "Face used for displaying entity names."
15289 :group 'speedbar-faces)
15291 (defface vhdl-speedbar-architecture-face
15292 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15293 (((class color) (background light)) (:foreground "Blue"))
15295 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15296 "Face used for displaying architecture names."
15297 :group 'speedbar-faces)
15299 (defface vhdl-speedbar-configuration-face
15300 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15301 (((class color) (background dark)) (:foreground "Salmon")))
15302 "Face used for displaying configuration names."
15303 :group 'speedbar-faces)
15305 (defface vhdl-speedbar-package-face
15306 '((((class color) (background light)) (:foreground "Grey50"))
15307 (((class color) (background dark)) (:foreground "Grey80")))
15308 "Face used for displaying package names."
15309 :group 'speedbar-faces)
15311 (defface vhdl-speedbar-library-face
15312 '((((class color) (background light)) (:foreground "Purple"))
15313 (((class color) (background dark)) (:foreground "Orchid1")))
15314 "Face used for displaying library names."
15315 :group 'speedbar-faces)
15317 (defface vhdl-speedbar-instantiation-face
15318 '((((class color) (background light)) (:foreground "Brown"))
15319 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15320 (((class color) (background dark)) (:foreground "Yellow")))
15321 "Face used for displaying instantiation names."
15322 :group 'speedbar-faces)
15324 (defface vhdl-speedbar-subprogram-face
15325 '((((class color) (background light)) (:foreground "Orchid4"))
15326 (((class color) (background dark)) (:foreground "BurlyWood2")))
15327 "Face used for displaying subprogram names."
15328 :group 'speedbar-faces)
15330 (defface vhdl-speedbar-entity-selected-face
15331 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15332 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15333 "Face used for displaying entity names."
15334 :group 'speedbar-faces)
15336 (defface vhdl-speedbar-architecture-selected-face
15337 '((((min-colors 88) (class color) (background light)) (:foreground
15338 "Blue1" :underline t))
15339 (((class color) (background light)) (:foreground "Blue" :underline t))
15340 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15341 "Face used for displaying architecture names."
15342 :group 'speedbar-faces)
15344 (defface vhdl-speedbar-configuration-selected-face
15345 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15346 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15347 "Face used for displaying configuration names."
15348 :group 'speedbar-faces)
15350 (defface vhdl-speedbar-package-selected-face
15351 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15352 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15353 "Face used for displaying package names."
15354 :group 'speedbar-faces)
15356 (defface vhdl-speedbar-instantiation-selected-face
15357 '((((class color) (background light)) (:foreground "Brown" :underline t))
15358 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15359 "Face used for displaying instantiation names."
15360 :group 'speedbar-faces)
15362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15366 (when (fboundp 'speedbar)
15368 (when (and vhdl-speedbar-auto-open
15369 (not (and (boundp 'speedbar-frame)
15370 (frame-live-p speedbar-frame))))
15371 (speedbar-frame-mode 1)
15372 (if (fboundp 'speedbar-select-attached-frame)
15373 (speedbar-select-attached-frame)
15374 (select-frame speedbar-attached-frame)))
15375 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15377 ;; initialize speedbar
15378 (if (not (boundp 'speedbar-frame))
15379 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15380 (vhdl-speedbar-initialize)
15381 (when speedbar-frame (vhdl-speedbar-refresh)))
15384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15385 ;;; Structural composition
15386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15388 (defun vhdl-get-components-package-name ()
15389 "Return the name of the components package."
15390 (let ((project (vhdl-project-p)))
15392 (vhdl-replace-string (car vhdl-components-package-name)
15393 (subst-char-in-string ? ?_ project))
15394 (cdr vhdl-components-package-name))))
15396 (defun vhdl-compose-new-component ()
15397 "Create entity and architecture for new component."
15399 (let* ((case-fold-search t)
15400 (ent-name (read-from-minibuffer "entity name: "
15401 nil vhdl-minibuffer-local-map))
15403 (if (equal (cdr vhdl-compose-architecture-name) "")
15404 (read-from-minibuffer "architecture name: "
15405 nil vhdl-minibuffer-local-map)
15406 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15407 ent-file-name arch-file-name ent-buffer arch-buffer project)
15408 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15409 ;; open entity file
15410 (unless (eq vhdl-compose-create-files 'none)
15411 (setq ent-file-name
15412 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15413 "." (file-name-extension (buffer-file-name))))
15414 (when (and (file-exists-p ent-file-name)
15415 (not (y-or-n-p (concat "File \"" ent-file-name
15416 "\" exists; overwrite? "))))
15417 (error "ERROR: Creating component...aborted"))
15418 (find-file ent-file-name)
15420 (set-buffer-modified-p nil))
15422 (if vhdl-compose-include-header
15423 (progn (vhdl-template-header)
15424 (goto-char (point-max)))
15425 (vhdl-comment-display-line) (insert "\n\n"))
15426 ;; insert library clause
15427 (vhdl-template-package-std-logic-1164)
15428 (when vhdl-use-components-package
15430 (vhdl-template-standard-package (vhdl-work-library)
15431 (vhdl-get-components-package-name)))
15432 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15433 ;; insert entity declaration
15434 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15435 (vhdl-insert-keyword " IS\n")
15436 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15437 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15438 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15439 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15440 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15441 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15442 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15443 (vhdl-insert-keyword "END ")
15444 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15445 (insert ent-name ";\n\n")
15446 (vhdl-comment-display-line) (insert "\n")
15447 ;; open architecture file
15448 (if (not (eq vhdl-compose-create-files 'separate))
15450 (setq ent-buffer (current-buffer))
15451 (setq arch-file-name
15452 (concat (vhdl-replace-string vhdl-architecture-file-name
15453 (concat ent-name " " arch-name) t)
15454 "." (file-name-extension (buffer-file-name))))
15455 (when (and (file-exists-p arch-file-name)
15456 (not (y-or-n-p (concat "File \"" arch-file-name
15457 "\" exists; overwrite? "))))
15458 (error "ERROR: Creating component...aborted"))
15459 (find-file arch-file-name)
15461 (set-buffer-modified-p nil)
15463 (if vhdl-compose-include-header
15464 (progn (vhdl-template-header)
15465 (goto-char (point-max)))
15466 (vhdl-comment-display-line) (insert "\n\n")))
15467 ;; insert architecture body
15468 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15469 (vhdl-insert-keyword " OF ") (insert ent-name)
15470 (vhdl-insert-keyword " IS\n\n")
15471 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15472 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15473 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15474 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15475 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15476 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15477 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15478 (vhdl-insert-keyword "BEGIN")
15479 (when vhdl-self-insert-comments
15481 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15482 (insert arch-name))
15484 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15485 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15486 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15487 (vhdl-insert-keyword "END ")
15488 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15489 (insert arch-name ";\n\n")
15490 ;; insert footer and save
15491 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15492 (vhdl-template-footer)
15493 (vhdl-comment-display-line) (insert "\n"))
15494 (goto-char (point-min))
15495 (setq arch-buffer (current-buffer))
15496 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15497 (set-buffer arch-buffer) (save-buffer)
15499 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15501 (format "\n File created: \"%s\"" ent-file-name))
15502 (and arch-file-name
15503 (format "\n File created: \"%s\"" arch-file-name))))))
15505 (defun vhdl-compose-place-component ()
15506 "Place new component by pasting current port as component declaration and
15507 component instantiation."
15509 (if (not vhdl-port-list)
15510 (error "ERROR: No port has been read")
15512 (vhdl-prepare-search-2
15513 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15514 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15515 (error "ERROR: No architecture found"))
15516 (let* ((ent-name (match-string 1))
15518 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15519 "." (file-name-extension (buffer-file-name))))
15520 (orig-buffer (current-buffer)))
15521 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15522 ;; place component declaration
15523 (unless (or vhdl-use-components-package
15524 (vhdl-use-direct-instantiation)
15527 (concat "^\\s-*component\\s-+"
15528 (car vhdl-port-list) "\\>") nil t)))
15529 (re-search-forward "^begin\\>" nil)
15530 (beginning-of-line)
15531 (skip-chars-backward " \t\n")
15532 (insert "\n\n") (indent-to vhdl-basic-offset)
15533 (vhdl-port-paste-component t))
15534 ;; place component instantiation
15535 (re-search-forward "^end\\>" nil)
15536 (beginning-of-line)
15537 (skip-chars-backward " \t\n")
15538 (insert "\n\n") (indent-to vhdl-basic-offset)
15539 (vhdl-port-paste-instance nil t t)
15540 ;; place use clause for used packages
15541 (when (nth 3 vhdl-port-list)
15542 ;; open entity file
15543 (when (file-exists-p ent-file-name)
15544 (find-file ent-file-name))
15545 (goto-char (point-min))
15546 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15547 (error "ERROR: Entity not found: \"%s\"" ent-name))
15548 (goto-char (match-beginning 0))
15549 (if (and (save-excursion
15550 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15552 (progn (goto-char (match-end 0))
15553 (beginning-of-line 2))
15556 (vhdl-port-paste-context-clause)
15557 (switch-to-buffer orig-buffer))
15558 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15560 (defun vhdl-compose-wire-components ()
15561 "Connect components."
15564 (vhdl-prepare-search-2
15565 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15566 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15567 (error "ERROR: No architecture found"))
15568 (let* ((ent-name (match-string 1))
15570 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15571 "." (file-name-extension (buffer-file-name))))
15572 (arch-decl-pos (point-marker))
15573 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15574 (arch-end-pos (re-search-forward "^end\\>" nil))
15575 (pack-name (vhdl-get-components-package-name))
15577 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15578 "." (file-name-extension (buffer-file-name))))
15579 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15580 port-alist generic-alist inst-alist
15581 signal-name signal-entry signal-alist local-list written-list
15582 single-in-list multi-in-list single-out-list multi-out-list
15583 constant-name constant-entry constant-alist single-list multi-list
15584 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15585 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15586 signal-beg-pos signal-pos
15587 constant-temp-pos port-temp-pos signal-temp-pos)
15588 (message "Wiring components...")
15589 ;; process all instances
15590 (goto-char arch-stat-pos)
15591 (while (re-search-forward
15592 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15593 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15594 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15595 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15596 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15597 (setq inst-name (match-string-no-properties 1)
15598 comp-name (match-string-no-properties 4)
15599 comp-ent-name (match-string-no-properties 12)
15600 has-generic (or (match-string 7) (match-string 17)))
15603 ;; ... from component declaration
15605 (when vhdl-use-components-package pack-file-name) t
15607 (goto-char (point-min))
15608 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15609 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15611 ;; ... from entity declaration (direct instantiation)
15612 (setq comp-ent-file-name
15613 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15614 "." (file-name-extension (buffer-file-name))))
15616 comp-ent-file-name t
15618 (goto-char (point-min))
15619 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15620 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15621 (vhdl-port-copy))))
15622 (vhdl-port-flatten t)
15623 (setq generic-alist (nth 1 vhdl-port-list)
15624 port-alist (nth 2 vhdl-port-list)
15625 vhdl-port-list nil)
15626 (setq constant-alist nil
15629 ;; process all constants in generic map
15630 (vhdl-forward-syntactic-ws)
15631 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15632 (setq constant-name (match-string-no-properties 3))
15633 (setq constant-entry
15634 (cons constant-name
15635 (if (match-string 1)
15636 (or (aget generic-alist (match-string 2) t)
15637 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15638 (cdar generic-alist))))
15639 (setq constant-alist (cons constant-entry constant-alist))
15640 (setq constant-name (downcase constant-name))
15641 (if (or (member constant-name single-list)
15642 (member constant-name multi-list))
15643 (progn (setq single-list (delete constant-name single-list))
15644 (add-to-list 'multi-list constant-name))
15645 (add-to-list 'single-list constant-name))
15646 (unless (match-string 1)
15647 (setq generic-alist (cdr generic-alist)))
15648 (vhdl-forward-syntactic-ws))
15649 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15650 ;; process all signals in port map
15651 (vhdl-forward-syntactic-ws)
15652 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15653 (setq signal-name (match-string-no-properties 3))
15654 (setq signal-entry (cons signal-name
15655 (if (match-string 1)
15656 (or (aget port-alist (match-string 2) t)
15657 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15658 (cdar port-alist))))
15659 (setq signal-alist (cons signal-entry signal-alist))
15660 (setq signal-name (downcase signal-name))
15661 (if (equal (upcase (nth 2 signal-entry)) "IN")
15664 ((member signal-name local-list)
15666 ((or (member signal-name single-out-list)
15667 (member signal-name multi-out-list))
15668 (setq single-out-list (delete signal-name single-out-list))
15669 (setq multi-out-list (delete signal-name multi-out-list))
15670 (add-to-list 'local-list signal-name))
15671 ((member signal-name single-in-list)
15672 (setq single-in-list (delete signal-name single-in-list))
15673 (add-to-list 'multi-in-list signal-name))
15674 ((not (member signal-name multi-in-list))
15675 (add-to-list 'single-in-list signal-name)))
15678 ((member signal-name local-list)
15680 ((or (member signal-name single-in-list)
15681 (member signal-name multi-in-list))
15682 (setq single-in-list (delete signal-name single-in-list))
15683 (setq multi-in-list (delete signal-name multi-in-list))
15684 (add-to-list 'local-list signal-name))
15685 ((member signal-name single-out-list)
15686 (setq single-out-list (delete signal-name single-out-list))
15687 (add-to-list 'multi-out-list signal-name))
15688 ((not (member signal-name multi-out-list))
15689 (add-to-list 'single-out-list signal-name))))
15690 (unless (match-string 1)
15691 (setq port-alist (cdr port-alist)))
15692 (vhdl-forward-syntactic-ws))
15693 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15694 (nreverse signal-alist)) inst-alist)))
15695 ;; prepare signal insertion
15696 (vhdl-goto-marker arch-decl-pos)
15698 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15699 (setq signal-pos (point-marker))
15700 (while (progn (vhdl-forward-syntactic-ws)
15701 (looking-at "signal\\>"))
15702 (beginning-of-line 2)
15703 (delete-region signal-pos (point)))
15704 (setq signal-beg-pos signal-pos)
15705 ;; open entity file
15706 (when (file-exists-p ent-file-name)
15707 (find-file ent-file-name))
15708 (goto-char (point-min))
15709 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15710 (error "ERROR: Entity not found: \"%s\"" ent-name))
15711 ;; prepare generic clause insertion
15712 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15714 (goto-char (match-beginning 0))
15715 (indent-to vhdl-basic-offset)
15716 (insert "generic ();\n\n")
15719 (setq generic-pos (point-marker))
15720 (forward-sexp) (end-of-line)
15721 (delete-region generic-pos (point)) (delete-char 1)
15725 (indent-to (* 2 vhdl-basic-offset))
15726 (insert "-- global generics\n"))
15727 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15728 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15729 ;; prepare port clause insertion
15730 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15732 (goto-char (match-beginning 0))
15733 (indent-to vhdl-basic-offset)
15734 (insert "port ();\n\n")
15737 (setq port-in-pos (point-marker))
15738 (forward-sexp) (end-of-line)
15739 (delete-region port-in-pos (point)) (delete-char 1)
15741 (when (or multi-in-list multi-out-list)
15743 (indent-to (* 2 vhdl-basic-offset))
15744 (insert "-- global ports\n"))
15745 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15746 port-out-pos (point-marker) port-inst-pos (point-marker)
15747 port-end-pos (point-marker))
15748 ;; insert generics, ports and signals
15749 (setq inst-alist (nreverse inst-alist))
15751 (setq inst-name (nth 0 (car inst-alist))
15752 constant-alist (nth 1 (car inst-alist))
15753 signal-alist (nth 2 (car inst-alist))
15754 constant-temp-pos generic-inst-pos
15755 port-temp-pos port-inst-pos
15756 signal-temp-pos signal-pos)
15758 (while constant-alist
15759 (setq constant-name (downcase (caar constant-alist))
15760 constant-entry (car constant-alist))
15761 (cond ((member constant-name written-list)
15763 ((member constant-name multi-list)
15764 (vhdl-goto-marker generic-pos)
15765 (setq generic-end-pos
15768 (vhdl-compose-insert-generic constant-entry)))
15769 (setq generic-pos (point-marker))
15770 (add-to-list 'written-list constant-name))
15773 (vhdl-max-marker generic-inst-pos generic-pos))
15774 (setq generic-end-pos
15775 (vhdl-compose-insert-generic constant-entry))
15776 (setq generic-inst-pos (point-marker))
15777 (add-to-list 'written-list constant-name)))
15778 (setq constant-alist (cdr constant-alist)))
15779 (when (/= constant-temp-pos generic-inst-pos)
15780 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15781 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15782 (insert "-- generics for \"" inst-name "\"\n")
15783 (vhdl-goto-marker generic-inst-pos))
15784 ;; ports and signals
15785 (while signal-alist
15786 (setq signal-name (downcase (caar signal-alist))
15787 signal-entry (car signal-alist))
15788 (cond ((member signal-name written-list)
15790 ((member signal-name multi-in-list)
15791 (vhdl-goto-marker port-in-pos)
15794 port-end-pos (vhdl-compose-insert-port signal-entry)))
15795 (setq port-in-pos (point-marker))
15796 (add-to-list 'written-list signal-name))
15797 ((member signal-name multi-out-list)
15798 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15801 port-end-pos (vhdl-compose-insert-port signal-entry)))
15802 (setq port-out-pos (point-marker))
15803 (add-to-list 'written-list signal-name))
15804 ((or (member signal-name single-in-list)
15805 (member signal-name single-out-list))
15809 (vhdl-max-marker port-out-pos port-in-pos)))
15810 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15811 (setq port-inst-pos (point-marker))
15812 (add-to-list 'written-list signal-name))
15813 ((equal (upcase (nth 2 signal-entry)) "OUT")
15814 (vhdl-goto-marker signal-pos)
15815 (vhdl-compose-insert-signal signal-entry)
15816 (setq signal-pos (point-marker))
15817 (add-to-list 'written-list signal-name)))
15818 (setq signal-alist (cdr signal-alist)))
15819 (when (/= port-temp-pos port-inst-pos)
15821 (vhdl-max-marker port-temp-pos
15822 (vhdl-max-marker port-in-pos port-out-pos)))
15823 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15824 (insert "-- ports to \"" inst-name "\"\n")
15825 (vhdl-goto-marker port-inst-pos))
15826 (when (/= signal-temp-pos signal-pos)
15827 (vhdl-goto-marker signal-temp-pos)
15828 (insert "\n") (indent-to vhdl-basic-offset)
15829 (insert "-- outputs of \"" inst-name "\"\n")
15830 (vhdl-goto-marker signal-pos))
15831 (setq inst-alist (cdr inst-alist)))
15832 ;; finalize generic/port clause
15833 (vhdl-goto-marker generic-end-pos) (backward-char)
15834 (when (= generic-beg-pos generic-end-pos)
15835 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15836 (insert ";") (backward-char))
15838 (vhdl-goto-marker port-end-pos) (backward-char)
15839 (when (= port-beg-pos port-end-pos)
15840 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15841 (insert ";") (backward-char))
15843 ;; align everything
15844 (when vhdl-auto-align
15845 (vhdl-goto-marker generic-beg-pos)
15846 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15847 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15848 (vhdl-goto-marker signal-beg-pos)
15849 (vhdl-align-region-groups signal-beg-pos signal-pos))
15850 (switch-to-buffer (marker-buffer signal-beg-pos))
15851 (message "Wiring components...done")))))
15853 (defun vhdl-compose-insert-generic (entry)
15854 "Insert ENTRY as generic declaration."
15856 (indent-to (* 2 vhdl-basic-offset))
15857 (insert (nth 0 entry) " : " (nth 1 entry))
15858 (when (nth 2 entry)
15859 (insert " := " (nth 2 entry)))
15861 (setq pos (point-marker))
15862 (when (and vhdl-include-port-comments (nth 3 entry))
15863 (vhdl-comment-insert-inline (nth 3 entry) t))
15867 (defun vhdl-compose-insert-port (entry)
15868 "Insert ENTRY as port declaration."
15870 (indent-to (* 2 vhdl-basic-offset))
15871 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15872 (setq pos (point-marker))
15873 (when (and vhdl-include-port-comments (nth 4 entry))
15874 (vhdl-comment-insert-inline (nth 4 entry) t))
15878 (defun vhdl-compose-insert-signal (entry)
15879 "Insert ENTRY as signal declaration."
15880 (indent-to vhdl-basic-offset)
15881 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15882 (when (and vhdl-include-port-comments (nth 4 entry))
15883 (vhdl-comment-insert-inline (nth 4 entry) t))
15886 (defun vhdl-compose-components-package ()
15887 "Generate a package containing component declarations for all entities in the
15888 current project/directory."
15890 (vhdl-require-hierarchy-info)
15891 (let* ((project (vhdl-project-p))
15892 (pack-name (vhdl-get-components-package-name))
15894 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15895 "." (file-name-extension (buffer-file-name))))
15896 (ent-alist (aget vhdl-entity-alist
15897 (or project default-directory) t))
15898 (lazy-lock-minimum-size 0)
15899 clause-pos component-pos)
15900 (message "Generating components package \"%s\"..." pack-name)
15901 ;; open package file
15902 (when (and (file-exists-p pack-file-name)
15903 (not (y-or-n-p (concat "File \"" pack-file-name
15904 "\" exists; overwrite? "))))
15905 (error "ERROR: Generating components package...aborted"))
15906 (find-file pack-file-name)
15909 (if vhdl-compose-include-header
15910 (progn (vhdl-template-header
15911 (concat "Components package (generated by Emacs VHDL Mode "
15913 (goto-char (point-max)))
15914 (vhdl-comment-display-line) (insert "\n\n"))
15915 ;; insert std_logic_1164 package
15916 (vhdl-template-package-std-logic-1164)
15917 (insert "\n") (setq clause-pos (point-marker))
15918 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15919 ;; insert package declaration
15920 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15921 (vhdl-insert-keyword " IS\n\n")
15922 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15923 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15924 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15925 (indent-to vhdl-basic-offset)
15926 (setq component-pos (point-marker))
15927 (insert "\n\n") (vhdl-insert-keyword "END ")
15928 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15929 (insert pack-name ";\n\n")
15931 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15932 (vhdl-template-footer)
15933 (vhdl-comment-display-line) (insert "\n"))
15934 ;; insert component declarations
15936 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15937 (progn (goto-line (nth 3 (car ent-alist)))
15940 (goto-char component-pos)
15941 (vhdl-port-paste-component t)
15942 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15943 (setq component-pos (point-marker))
15944 (goto-char clause-pos)
15945 (vhdl-port-paste-context-clause pack-name)
15946 (setq clause-pos (point-marker))
15947 (setq ent-alist (cdr ent-alist)))
15948 (goto-char (point-min))
15950 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15951 pack-name pack-file-name)))
15953 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15954 &optional insert-conf)
15955 "Generate block configuration for architecture."
15956 (let ((margin (current-indentation))
15957 (beg (save-excursion (beginning-of-line) (point)))
15958 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15959 ;; insert block configuration (for architecture)
15960 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15961 (setq margin (+ margin vhdl-basic-offset))
15962 ;; process all instances
15964 (setq inst-entry (car inst-alist))
15966 (when (nth 4 inst-entry)
15967 (setq insert-conf t)
15968 (setq inst-path (nth 9 inst-entry))
15969 ;; skip common path with previous instance
15970 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15971 (setq inst-path (cdr inst-path)
15972 inst-prev-path (cdr inst-prev-path)))
15973 ;; insert block configuration end (for previous block/generate)
15974 (while inst-prev-path
15975 (setq margin (- margin vhdl-basic-offset))
15977 (vhdl-insert-keyword "END FOR;\n")
15978 (setq inst-prev-path (cdr inst-prev-path)))
15979 ;; insert block configuration beginning (for current block/generate)
15982 (setq margin (+ margin vhdl-basic-offset))
15983 (vhdl-insert-keyword "FOR ")
15984 (insert (car inst-path) "\n")
15986 (setq inst-path (cdr inst-path)))
15987 ;; insert component configuration beginning
15988 (vhdl-insert-keyword "FOR ")
15989 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15990 ;; find subconfiguration
15991 (setq conf-key (nth 7 inst-entry))
15992 (setq tmp-alist conf-alist)
15993 ;; use first configuration found for instance's entity
15994 (while (and tmp-alist (null conf-key))
15995 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15996 (setq conf-key (nth 0 (car tmp-alist))))
15997 (setq tmp-alist (cdr tmp-alist)))
15998 (setq conf-entry (aget conf-alist conf-key t))
15999 ;; insert binding indication ...
16000 ;; ... with subconfiguration (if exists)
16001 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16003 (indent-to (+ margin vhdl-basic-offset))
16004 (vhdl-insert-keyword "USE CONFIGURATION ")
16005 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16007 ;; ... with entity (if exists)
16008 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16010 (indent-to (+ margin vhdl-basic-offset))
16011 (vhdl-insert-keyword "USE ENTITY ")
16012 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16013 ;; insert architecture name (if architecture exists)
16014 (when (nth 3 ent-entry)
16016 ;; choose architecture name a) from configuration,
16017 ;; b) from mra, or c) from first architecture
16018 (or (nth 0 (aget (nth 3 ent-entry)
16019 (or (nth 6 inst-entry)
16020 (nth 4 ent-entry)) t))
16021 (nth 1 (car (nth 3 ent-entry)))))
16022 (insert "(" arch-name ")"))
16024 ;; insert block configuration (for architecture of subcomponent)
16025 (when (and vhdl-compose-configuration-hierarchical
16027 (indent-to (+ margin vhdl-basic-offset))
16028 (vhdl-compose-configuration-architecture
16029 (nth 0 ent-entry) arch-name
16030 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16031 ;; insert component configuration end
16033 (vhdl-insert-keyword "END FOR;\n")
16034 (setq inst-prev-path (nth 9 inst-entry)))
16035 (setq inst-alist (cdr inst-alist)))
16036 ;; insert block configuration end (for block/generate)
16037 (while inst-prev-path
16038 (setq margin (- margin vhdl-basic-offset))
16040 (vhdl-insert-keyword "END FOR;\n")
16041 (setq inst-prev-path (cdr inst-prev-path)))
16042 (indent-to (- margin vhdl-basic-offset))
16043 ;; insert block configuration end or remove beginning (for architecture)
16045 (vhdl-insert-keyword "END FOR;\n")
16046 (delete-region beg (point)))))
16048 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16049 "Generate configuration declaration."
16051 (vhdl-require-hierarchy-info)
16052 (let ((ent-alist (aget vhdl-entity-alist
16053 (or (vhdl-project-p) default-directory) t))
16054 (conf-alist (aget vhdl-config-alist
16055 (or (vhdl-project-p) default-directory) t))
16056 (from-speedbar ent-name)
16057 inst-alist conf-name conf-file-name pos)
16058 (vhdl-prepare-search-2
16059 ;; get entity and architecture name
16062 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16063 (not (equal "END" (upcase (match-string 1))))
16064 (setq ent-name (match-string-no-properties 3))
16065 (setq arch-name (match-string-no-properties 2)))
16066 (error "ERROR: Not within an architecture"))))
16067 (setq conf-name (vhdl-replace-string
16068 vhdl-compose-configuration-name
16069 (concat ent-name " " arch-name)))
16071 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16072 (downcase arch-name) t))))
16073 (message "Generating configuration \"%s\"..." conf-name)
16074 (if vhdl-compose-configuration-create-file
16075 ;; open configuration file
16077 (setq conf-file-name
16078 (concat (vhdl-replace-string vhdl-configuration-file-name
16080 "." (file-name-extension (buffer-file-name))))
16081 (when (and (file-exists-p conf-file-name)
16082 (not (y-or-n-p (concat "File \"" conf-file-name
16083 "\" exists; overwrite? "))))
16084 (error "ERROR: Creating configuration...aborted"))
16085 (find-file conf-file-name)
16087 (set-buffer-modified-p nil)
16089 (if vhdl-compose-include-header
16090 (progn (vhdl-template-header
16091 (concat "Configuration declaration for design \""
16092 ent-name "(" arch-name ")\""))
16093 (goto-char (point-max)))
16094 (vhdl-comment-display-line) (insert "\n\n")))
16095 ;; goto end of architecture
16096 (unless from-speedbar
16097 (re-search-forward "^end\\>" nil)
16098 (end-of-line) (insert "\n\n")
16099 (vhdl-comment-display-line) (insert "\n\n")))
16100 ;; insert library clause
16102 (vhdl-template-standard-package (vhdl-work-library) nil)
16103 (when (/= pos (point))
16105 ;; insert configuration
16106 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16107 (vhdl-insert-keyword " OF ") (insert ent-name)
16108 (vhdl-insert-keyword " IS\n")
16109 (indent-to vhdl-basic-offset)
16110 ;; insert block configuration (for architecture)
16111 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16112 (vhdl-insert-keyword "END ") (insert conf-name ";")
16113 (when conf-file-name
16114 ;; insert footer and save
16116 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16117 (vhdl-template-footer)
16118 (vhdl-comment-display-line) (insert "\n"))
16121 (concat (format "Generating configuration \"%s\"...done" conf-name)
16122 (and conf-file-name
16123 (format "\n File created: \"%s\"" conf-file-name))))))
16126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16127 ;;; Compilation / Makefile generation
16128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16129 ;; (using `compile.el')
16131 (defun vhdl-makefile-name ()
16132 "Return the Makefile name of the current project or the current compiler if
16133 no project is defined."
16134 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16135 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16136 (vhdl-replace-string
16137 (cons "\\(.*\\)\n\\(.*\\)"
16138 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16139 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16141 (defun vhdl-compile-directory ()
16142 "Return the directory where compilation/make should be run."
16143 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16144 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16145 (directory (vhdl-resolve-env-variable
16147 (vhdl-replace-string
16148 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16149 (nth 6 compiler)))))
16150 (file-name-as-directory
16151 (if (file-name-absolute-p directory)
16153 (expand-file-name directory (vhdl-default-directory))))))
16155 (defun vhdl-uniquify (in-list)
16156 "Remove duplicate elements from IN-LIST."
16159 (add-to-list 'out-list (car in-list))
16160 (setq in-list (cdr in-list)))
16163 (defun vhdl-set-compiler (name)
16164 "Set current compiler to NAME."
16166 (list (let ((completion-ignore-case t))
16167 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16168 (if (assoc name vhdl-compiler-alist)
16169 (progn (setq vhdl-compiler name)
16170 (message "Current compiler: \"%s\"" vhdl-compiler))
16171 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16176 (defun vhdl-compile-init ()
16177 "Initialize for compilation."
16178 (when (or (null compilation-error-regexp-alist)
16179 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16180 compilation-error-regexp-alist)))
16181 ;; `compilation-error-regexp-alist'
16182 (let ((commands-alist vhdl-compiler-alist)
16183 regexp-alist sublist)
16184 (while commands-alist
16185 (setq sublist (nth 11 (car commands-alist)))
16186 (unless (or (equal "" (car sublist))
16187 (assoc (car sublist) regexp-alist))
16188 (setq regexp-alist (cons (list (nth 0 sublist)
16189 (if (= 0 (nth 1 sublist))
16190 (if (featurep 'xemacs) 9 nil)
16192 (nth 2 sublist) (nth 3 sublist))
16194 (setq commands-alist (cdr commands-alist)))
16195 (setq compilation-error-regexp-alist
16196 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16197 ;; `compilation-file-regexp-alist'
16198 (let ((commands-alist vhdl-compiler-alist)
16199 regexp-alist sublist)
16200 ;; matches vhdl-mode file name output
16201 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16202 (while commands-alist
16203 (setq sublist (nth 12 (car commands-alist)))
16204 (unless (or (equal "" (car sublist))
16205 (assoc (car sublist) regexp-alist))
16206 (setq regexp-alist (cons sublist regexp-alist)))
16207 (setq commands-alist (cdr commands-alist)))
16208 (setq compilation-file-regexp-alist
16209 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16211 (defvar vhdl-compile-file-name nil
16212 "Name of file to be compiled.")
16214 (defun vhdl-compile-print-file-name ()
16215 "Function called within `compile' to print out file name for compilers that
16216 do not print any file names."
16217 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16219 (defun vhdl-get-compile-options (project compiler file-name
16220 &optional file-options-only)
16221 "Get compiler options. Returning nil means do not compile this file."
16222 (let* ((compiler-options (nth 1 compiler))
16223 (project-entry (aget (nth 4 project) vhdl-compiler))
16224 (project-options (nth 0 project-entry))
16225 (exception-list (and file-name (nth 2 project-entry)))
16226 (work-library (vhdl-work-library))
16227 (case-fold-search nil)
16229 (while (and exception-list
16230 (not (string-match (caar exception-list) file-name)))
16231 (setq exception-list (cdr exception-list)))
16232 (if (and exception-list (not (cdar exception-list)))
16234 (if (and file-options-only (not exception-list))
16236 (setq file-options (cdar exception-list))
16237 ;; insert library name in compiler-specific options
16238 (setq compiler-options
16239 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16241 ;; insert compiler-specific options in project-specific options
16242 (when project-options
16243 (setq project-options
16244 (vhdl-replace-string
16245 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16246 (concat work-library "\n" compiler-options))))
16247 ;; insert project-specific options in file-specific options
16250 (vhdl-replace-string
16251 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16252 (concat work-library "\n" compiler-options "\n"
16253 project-options))))
16255 (or file-options project-options compiler-options)))))
16257 (defun vhdl-get-make-options (project compiler)
16258 "Get make options."
16259 (let* ((compiler-options (nth 3 compiler))
16260 (project-entry (aget (nth 4 project) vhdl-compiler))
16261 (project-options (nth 1 project-entry))
16262 (makefile-name (vhdl-makefile-name)))
16263 ;; insert Makefile name in compiler-specific options
16264 (setq compiler-options
16265 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16267 ;; insert compiler-specific options in project-specific options
16268 (when project-options
16269 (setq project-options
16270 (vhdl-replace-string
16271 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16272 (concat makefile-name "\n" compiler-options))))
16274 (or project-options compiler-options)))
16276 (defun vhdl-compile ()
16277 "Compile current buffer using the VHDL compiler specified in
16280 (vhdl-compile-init)
16281 (let* ((project (aget vhdl-project-alist vhdl-project))
16282 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16283 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16284 (command (nth 0 compiler))
16285 (file-name (buffer-file-name))
16286 (options (vhdl-get-compile-options project compiler file-name))
16287 (default-directory (vhdl-compile-directory))
16288 compilation-process-setup-function)
16289 (unless (file-directory-p default-directory)
16290 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16291 ;; put file name into quotes if it contains spaces
16292 (when (string-match " " file-name)
16293 (setq file-name (concat "\"" file-name "\"")))
16294 ;; print out file name if compiler does not
16295 (setq vhdl-compile-file-name (buffer-file-name))
16296 (when (and (= 0 (nth 1 (nth 10 compiler)))
16297 (= 0 (nth 1 (nth 11 compiler))))
16298 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16302 (compile (concat command " " options " " file-name)))
16303 (vhdl-warning "Your project settings tell me not to compile this file"))))
16305 (defvar vhdl-make-target "all"
16306 "Default target for `vhdl-make' command.")
16308 (defun vhdl-make (&optional target)
16309 "Call make command for compilation of all updated source files (requires
16310 `Makefile'). Optional argument TARGET allows to compile the design
16311 specified by a target."
16313 (setq vhdl-make-target
16314 (or target (read-from-minibuffer "Target: " vhdl-make-target
16315 vhdl-minibuffer-local-map)))
16316 (vhdl-compile-init)
16317 (let* ((project (aget vhdl-project-alist vhdl-project))
16318 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16319 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16320 (command (nth 2 compiler))
16321 (options (vhdl-get-make-options project compiler))
16322 (default-directory (vhdl-compile-directory)))
16323 (unless (file-directory-p default-directory)
16324 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16326 (compile (concat (if (equal command "") "make" command)
16327 " " options " " vhdl-make-target))))
16329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16330 ;; Makefile generation
16332 (defun vhdl-generate-makefile ()
16333 "Generate `Makefile'."
16335 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16336 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16337 (command (nth 4 compiler)))
16338 ;; generate makefile
16340 (let ((default-directory (vhdl-compile-directory)))
16341 (compile (vhdl-replace-string
16342 (cons "\\(.*\\) \\(.*\\)" command)
16343 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16344 (vhdl-generate-makefile-1))))
16346 (defun vhdl-get-packages (lib-alist work-library)
16347 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16350 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16351 (setq pack-list (cons (cdar lib-alist) pack-list)))
16352 (setq lib-alist (cdr lib-alist)))
16355 (defun vhdl-generate-makefile-1 ()
16356 "Generate Makefile for current project or directory."
16357 ;; scan hierarchy if required
16358 (if (vhdl-project-p)
16359 (unless (or (assoc vhdl-project vhdl-file-alist)
16360 (vhdl-load-cache vhdl-project))
16361 (vhdl-scan-project-contents vhdl-project))
16362 (let ((directory (abbreviate-file-name default-directory)))
16363 (unless (or (assoc directory vhdl-file-alist)
16364 (vhdl-load-cache directory))
16365 (vhdl-scan-directory-contents directory))))
16366 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16367 (project (vhdl-project-p))
16368 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16369 (conf-alist (aget vhdl-config-alist (or project directory) t))
16370 (pack-alist (aget vhdl-package-alist (or project directory) t))
16371 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16372 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16373 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16374 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16375 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16376 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16377 (adjust-case (nth 5 regexp-list))
16378 (work-library (downcase (vhdl-work-library)))
16379 (compile-directory (expand-file-name (vhdl-compile-directory)
16380 default-directory))
16381 (makefile-name (vhdl-makefile-name))
16382 rule-alist arch-alist inst-alist
16383 target-list depend-list unit-list prim-list second-list subcomp-list
16384 lib-alist lib-body-alist pack-list all-pack-list
16385 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16386 conf-key conf-file-name pack-key pack-file-name
16387 ent-entry arch-entry conf-entry pack-entry inst-entry
16388 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16389 tmp-key tmp-list rule)
16390 ;; check prerequisites
16391 (unless (file-exists-p compile-directory)
16392 (make-directory compile-directory t))
16393 (unless regexp-list
16394 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16396 (message "Generating makefile \"%s\"..." makefile-name)
16397 ;; rules for all entities
16398 (setq tmp-list ent-alist)
16400 (setq ent-entry (car ent-alist)
16401 ent-key (nth 0 ent-entry))
16402 (when (nth 2 ent-entry)
16403 (setq ent-file-name (file-relative-name
16404 (nth 2 ent-entry) compile-directory)
16405 arch-alist (nth 4 ent-entry)
16406 lib-alist (nth 6 ent-entry)
16407 rule (aget rule-alist ent-file-name)
16408 target-list (nth 0 rule)
16409 depend-list (nth 1 rule)
16412 (setq tmp-key (vhdl-replace-string
16413 ent-regexp (funcall adjust-case ent-key)))
16414 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16415 ;; rule target for this entity
16416 (setq target-list (cons ent-key target-list))
16417 ;; rule dependencies for all used packages
16418 (setq pack-list (vhdl-get-packages lib-alist work-library))
16419 (setq depend-list (append depend-list pack-list))
16420 (setq all-pack-list pack-list)
16422 (aput 'rule-alist ent-file-name (list target-list depend-list))
16423 ;; rules for all corresponding architectures
16425 (setq arch-entry (car arch-alist)
16426 arch-key (nth 0 arch-entry)
16427 ent-arch-key (concat ent-key "-" arch-key)
16428 arch-file-name (file-relative-name (nth 2 arch-entry)
16430 inst-alist (nth 4 arch-entry)
16431 lib-alist (nth 5 arch-entry)
16432 rule (aget rule-alist arch-file-name)
16433 target-list (nth 0 rule)
16434 depend-list (nth 1 rule))
16435 (setq tmp-key (vhdl-replace-string
16437 (funcall adjust-case (concat arch-key " " ent-key))))
16439 (cons (cons ent-arch-key tmp-key) unit-list))
16440 (setq second-list (cons ent-arch-key second-list))
16441 ;; rule target for this architecture
16442 (setq target-list (cons ent-arch-key target-list))
16443 ;; rule dependency for corresponding entity
16444 (setq depend-list (cons ent-key depend-list))
16445 ;; rule dependencies for contained component instantiations
16447 (setq inst-entry (car inst-alist))
16448 (when (or (null (nth 8 inst-entry))
16449 (equal (downcase (nth 8 inst-entry)) work-library))
16450 (setq inst-ent-key (or (nth 7 inst-entry)
16451 (nth 5 inst-entry)))
16452 (setq depend-list (cons inst-ent-key depend-list)
16453 subcomp-list (cons inst-ent-key subcomp-list)))
16454 (setq inst-alist (cdr inst-alist)))
16455 ;; rule dependencies for all used packages
16456 (setq pack-list (vhdl-get-packages lib-alist work-library))
16457 (setq depend-list (append depend-list pack-list))
16458 (setq all-pack-list (append all-pack-list pack-list))
16460 (aput 'rule-alist arch-file-name (list target-list depend-list))
16461 (setq arch-alist (cdr arch-alist)))
16462 (setq prim-list (cons (list ent-key second-list
16463 (append subcomp-list all-pack-list))
16465 (setq ent-alist (cdr ent-alist)))
16466 (setq ent-alist tmp-list)
16467 ;; rules for all configurations
16468 (setq tmp-list conf-alist)
16470 (setq conf-entry (car conf-alist)
16471 conf-key (nth 0 conf-entry)
16472 conf-file-name (file-relative-name
16473 (nth 2 conf-entry) compile-directory)
16474 ent-key (nth 4 conf-entry)
16475 arch-key (nth 5 conf-entry)
16476 inst-alist (nth 6 conf-entry)
16477 lib-alist (nth 7 conf-entry)
16478 rule (aget rule-alist conf-file-name)
16479 target-list (nth 0 rule)
16480 depend-list (nth 1 rule)
16481 subcomp-list (list ent-key))
16482 (setq tmp-key (vhdl-replace-string
16483 conf-regexp (funcall adjust-case conf-key)))
16484 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16485 ;; rule target for this configuration
16486 (setq target-list (cons conf-key target-list))
16487 ;; rule dependency for corresponding entity and architecture
16489 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16490 ;; rule dependencies for used packages
16491 (setq pack-list (vhdl-get-packages lib-alist work-library))
16492 (setq depend-list (append depend-list pack-list))
16493 ;; rule dependencies for contained component configurations
16495 (setq inst-entry (car inst-alist))
16496 (setq inst-ent-key (nth 2 inst-entry)
16497 ; comp-arch-key (nth 2 inst-entry))
16498 inst-conf-key (nth 4 inst-entry))
16499 (when (equal (downcase (nth 5 inst-entry)) work-library)
16501 (setq depend-list (cons inst-ent-key depend-list)
16502 subcomp-list (cons inst-ent-key subcomp-list)))
16503 ; (when comp-arch-key
16504 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16506 (when inst-conf-key
16507 (setq depend-list (cons inst-conf-key depend-list)
16508 subcomp-list (cons inst-conf-key subcomp-list))))
16509 (setq inst-alist (cdr inst-alist)))
16511 (aput 'rule-alist conf-file-name (list target-list depend-list))
16512 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16514 (setq conf-alist (cdr conf-alist)))
16515 (setq conf-alist tmp-list)
16516 ;; rules for all packages
16517 (setq tmp-list pack-alist)
16519 (setq pack-entry (car pack-alist)
16520 pack-key (nth 0 pack-entry)
16522 (when (nth 2 pack-entry)
16523 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16525 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16526 rule (aget rule-alist pack-file-name)
16527 target-list (nth 0 rule) depend-list (nth 1 rule))
16528 (setq tmp-key (vhdl-replace-string
16529 pack-regexp (funcall adjust-case pack-key)))
16530 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16531 ;; rule target for this package
16532 (setq target-list (cons pack-key target-list))
16533 ;; rule dependencies for all used packages
16534 (setq pack-list (vhdl-get-packages lib-alist work-library))
16535 (setq depend-list (append depend-list pack-list))
16536 (setq all-pack-list pack-list)
16538 (aput 'rule-alist pack-file-name (list target-list depend-list))
16539 ;; rules for this package's body
16540 (when (nth 7 pack-entry)
16541 (setq pack-body-key (concat pack-key "-body")
16542 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16544 rule (aget rule-alist pack-body-file-name)
16545 target-list (nth 0 rule)
16546 depend-list (nth 1 rule))
16547 (setq tmp-key (vhdl-replace-string
16548 pack-body-regexp (funcall adjust-case pack-key)))
16550 (cons (cons pack-body-key tmp-key) unit-list))
16551 ;; rule target for this package's body
16552 (setq target-list (cons pack-body-key target-list))
16553 ;; rule dependency for corresponding package declaration
16554 (setq depend-list (cons pack-key depend-list))
16555 ;; rule dependencies for all used packages
16556 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16557 (setq depend-list (append depend-list pack-list))
16558 (setq all-pack-list (append all-pack-list pack-list))
16560 (aput 'rule-alist pack-body-file-name
16561 (list target-list depend-list)))
16563 (cons (list pack-key (when pack-body-key (list pack-body-key))
16566 (setq pack-alist (cdr pack-alist)))
16567 (setq pack-alist tmp-list)
16568 ;; generate Makefile
16569 (let* ((project (aget vhdl-project-alist project))
16570 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16571 (compiler-id (nth 9 compiler))
16573 (vhdl-resolve-env-variable
16574 (vhdl-replace-string
16575 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16577 (makefile-path-name (expand-file-name
16578 makefile-name compile-directory))
16579 (orig-buffer (current-buffer))
16580 cell second-list subcomp-list options unit-key unit-name)
16582 (setq unit-list (vhdl-sort-alist unit-list))
16583 (setq prim-list (vhdl-sort-alist prim-list))
16584 (setq tmp-list rule-alist)
16585 (while tmp-list ; pre-sort rule targets
16586 (setq cell (cdar tmp-list))
16587 (setcar cell (sort (car cell) 'string<))
16588 (setq tmp-list (cdr tmp-list)))
16589 (setq rule-alist ; sort by first rule target
16591 (function (lambda (a b)
16592 (string< (car (cadr a)) (car (cadr b)))))))
16593 ;; open and clear Makefile
16594 (set-buffer (find-file-noselect makefile-path-name t t))
16596 (insert "# -*- Makefile -*-\n"
16597 "### " (file-name-nondirectory makefile-name)
16598 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16601 (insert "\n# Project : " (nth 0 project))
16602 (insert "\n# Directory : \"" directory "\""))
16603 (insert "\n# Platform : " vhdl-compiler
16604 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16605 (user-login-name) "\n")
16606 ;; insert compile and option variable settings
16607 (insert "\n\n# Define compilation command and options\n"
16608 "\nCOMPILE = " (nth 0 compiler)
16609 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16611 ;; insert library paths
16612 (setq library-directory
16613 (directory-file-name
16614 (if (file-name-absolute-p library-directory)
16616 (file-relative-name
16617 (expand-file-name library-directory directory)
16618 compile-directory))))
16619 (insert "\n\n# Define library paths\n"
16620 "\nLIBRARY-" work-library " = " library-directory "\n")
16621 ;; insert variable definitions for all library unit files
16622 (insert "\n\n# Define library unit files\n")
16623 (setq tmp-list unit-list)
16625 (insert "\nUNIT-" work-library "-" (caar unit-list)
16626 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16627 (setq unit-list (cdr unit-list)))
16628 ;; insert variable definition for list of all library unit files
16629 (insert "\n\n\n# Define list of all library unit files\n"
16631 (setq unit-list tmp-list)
16633 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16634 (setq unit-list (cdr unit-list)))
16636 (setq unit-list tmp-list)
16637 ;; insert `make all' rule
16638 (insert "\n\n\n# Rule for compiling entire design\n"
16641 " \\\n\t\t$(ALL_UNITS)\n")
16642 ;; insert `make clean' rule
16643 (insert "\n\n# Rule for cleaning entire design\n"
16645 "\n\t-rm -f $(ALL_UNITS)\n")
16646 ;; insert `make library' rule
16647 (insert "\n\n# Rule for creating library directory\n"
16649 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16650 "\n$(LIBRARY-" work-library ") :"
16652 (vhdl-replace-string
16653 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16654 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16656 ;; insert rule for each library unit
16657 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16659 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16661 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16662 (setq unit-key (caar prim-list)
16663 unit-name (or (nth 0 (aget ent-alist unit-key t))
16664 (nth 0 (aget conf-alist unit-key t))
16665 (nth 0 (aget pack-alist unit-key t))))
16666 (insert "\n" unit-key)
16667 (unless (equal unit-key unit-name)
16668 (insert " \\\n" unit-name))
16671 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16673 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16674 (setq second-list (cdr second-list)))
16675 (while subcomp-list
16676 (when (and (assoc (car subcomp-list) unit-list)
16677 (not (equal unit-key (car subcomp-list))))
16678 (insert " \\\n\t\t" (car subcomp-list)))
16679 (setq subcomp-list (cdr subcomp-list)))
16681 (setq prim-list (cdr prim-list)))
16682 ;; insert rule for each library unit file
16683 (insert "\n\n# Rules for compiling single library unit files\n")
16685 (setq rule (car rule-alist))
16686 ;; get compiler options for this file
16688 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16689 ;; insert rule if file is supposed to be compiled
16690 (setq target-list (nth 1 rule)
16691 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16693 (setq tmp-list target-list)
16695 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16696 (if (cdr target-list) " \\" " :"))
16697 (setq target-list (cdr target-list)))
16698 (setq target-list tmp-list)
16699 ;; insert file name as first dependency
16700 (insert " \\\n\t\t" (nth 0 rule))
16701 ;; insert dependencies (except if also target or unit does not exist)
16703 (when (and (not (member (car depend-list) target-list))
16704 (assoc (car depend-list) unit-list))
16705 (insert " \\\n\t\t"
16706 "$(UNIT-" work-library "-" (car depend-list) ")"))
16707 (setq depend-list (cdr depend-list)))
16708 ;; insert compile command
16710 (insert "\n\t$(COMPILE) "
16711 (if (eq options 'default) "$(OPTIONS)" options) " "
16713 (setq tmp-list target-list)
16715 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16716 (if (cdr target-list) " \\" "\n"))
16717 (setq target-list (cdr target-list)))
16718 (setq target-list tmp-list))
16719 (setq rule-alist (cdr rule-alist)))
16720 (insert "\n\n### " makefile-name " ends here\n")
16721 ;; run Makefile generation hook
16722 (run-hooks 'vhdl-makefile-generation-hook)
16723 (message "Generating makefile \"%s\"...done" makefile-name)
16724 ;; save and close file
16725 (if (file-writable-p makefile-path-name)
16726 (progn (save-buffer)
16727 (kill-buffer (current-buffer))
16728 (set-buffer orig-buffer)
16729 (add-to-history 'file-name-history makefile-path-name))
16730 (vhdl-warning-when-idle
16731 (format "File not writable: \"%s\""
16732 (abbreviate-file-name makefile-path-name)))
16733 (switch-to-buffer (current-buffer))))))
16736 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16739 ;; (using `reporter.el')
16741 (defconst vhdl-mode-help-address
16742 "Reto Zimmermann <reto@gnu.org>"
16743 "Address for VHDL Mode bug reports.")
16745 (defun vhdl-submit-bug-report ()
16746 "Submit via mail a bug report on VHDL Mode."
16748 ;; load in reporter
16750 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16751 (let ((reporter-prompt-for-summary-p t))
16752 (reporter-submit-bug-report
16753 vhdl-mode-help-address
16754 (concat "VHDL Mode " vhdl-version)
16756 ;; report all important user options
16757 'vhdl-offsets-alist
16758 'vhdl-comment-only-line-offset
16760 'vhdl-electric-mode
16762 'vhdl-indent-tabs-mode
16763 'vhdl-project-alist
16765 'vhdl-project-file-name
16766 'vhdl-project-auto-load
16768 'vhdl-compiler-alist
16770 'vhdl-compile-use-local-error-regexp
16771 'vhdl-makefile-generation-hook
16772 'vhdl-default-library
16775 'vhdl-upper-case-keywords
16776 'vhdl-upper-case-types
16777 'vhdl-upper-case-attributes
16778 'vhdl-upper-case-enum-values
16779 'vhdl-upper-case-constants
16780 'vhdl-use-direct-instantiation
16781 'vhdl-compose-configuration-name
16782 'vhdl-entity-file-name
16783 'vhdl-architecture-file-name
16784 'vhdl-configuration-file-name
16785 'vhdl-package-file-name
16786 'vhdl-file-name-case
16787 'vhdl-electric-keywords
16788 'vhdl-optional-labels
16789 'vhdl-insert-empty-lines
16790 'vhdl-argument-list-indent
16791 'vhdl-association-list-with-formals
16792 'vhdl-conditions-in-parenthesis
16798 'vhdl-copyright-string
16799 'vhdl-platform-spec
16801 'vhdl-modify-date-prefix-string
16802 'vhdl-modify-date-on-saving
16804 'vhdl-reset-active-high
16805 'vhdl-clock-rising-edge
16806 'vhdl-clock-edge-condition
16810 'vhdl-include-port-comments
16811 'vhdl-include-direction-comments
16812 'vhdl-include-type-comments
16813 'vhdl-include-group-comments
16814 'vhdl-actual-port-name
16815 'vhdl-instance-name
16816 'vhdl-testbench-entity-name
16817 'vhdl-testbench-architecture-name
16818 'vhdl-testbench-configuration-name
16819 'vhdl-testbench-dut-name
16820 'vhdl-testbench-include-header
16821 'vhdl-testbench-declarations
16822 'vhdl-testbench-statements
16823 'vhdl-testbench-initialize-signals
16824 'vhdl-testbench-include-library
16825 'vhdl-testbench-include-configuration
16826 'vhdl-testbench-create-files
16827 'vhdl-testbench-entity-file-name
16828 'vhdl-testbench-architecture-file-name
16829 'vhdl-compose-create-files
16830 'vhdl-compose-configuration-create-file
16831 'vhdl-compose-configuration-hierarchical
16832 'vhdl-compose-configuration-use-subconfiguration
16833 'vhdl-compose-include-header
16834 'vhdl-compose-architecture-name
16835 'vhdl-components-package-name
16836 'vhdl-use-components-package
16837 'vhdl-self-insert-comments
16838 'vhdl-prompt-for-comments
16839 'vhdl-inline-comment-column
16840 'vhdl-end-comment-column
16843 'vhdl-align-group-separate
16844 'vhdl-align-same-indent
16845 'vhdl-highlight-keywords
16846 'vhdl-highlight-names
16847 'vhdl-highlight-special-words
16848 'vhdl-highlight-forbidden-words
16849 'vhdl-highlight-verilog-keywords
16850 'vhdl-highlight-translate-off
16851 'vhdl-highlight-case-sensitive
16852 'vhdl-special-syntax-alist
16853 'vhdl-forbidden-words
16854 'vhdl-forbidden-syntax
16855 'vhdl-directive-keywords
16856 'vhdl-speedbar-auto-open
16857 'vhdl-speedbar-display-mode
16858 'vhdl-speedbar-scan-limit
16859 'vhdl-speedbar-jump-to-unit
16860 'vhdl-speedbar-update-on-saving
16861 'vhdl-speedbar-save-cache
16862 'vhdl-speedbar-cache-file-name
16864 'vhdl-source-file-menu
16865 'vhdl-hideshow-menu
16866 'vhdl-hide-all-init
16867 'vhdl-print-two-column
16868 'vhdl-print-customize-faces
16869 'vhdl-intelligent-tab
16870 'vhdl-indent-syntax-based
16871 'vhdl-word-completion-case-sensitive
16872 'vhdl-word-completion-in-minibuffer
16873 'vhdl-underscore-is-part-of-word
16878 (if vhdl-special-indent-hook
16879 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16880 "vhdl-special-indent-hook is set to '"
16881 (format "%s" vhdl-special-indent-hook)
16882 ".\nPerhaps this is your problem?\n"
16883 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16893 (defconst vhdl-doc-release-notes nil
16895 Release Notes for VHDL Mode 3.33
16896 ================================
16905 CONFIGURATION DECLARATION GENERATION:
16906 - Automatic generation of a configuration declaration for a design.
16907 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16913 `vhdl-configuration-file-name': (new)
16914 Specify how the configuration file name is obtained.
16915 `vhdl-compose-configuration-name': (new)
16916 Specify how the configuration name is optained.
16917 `vhdl-compose-configuration-create-file': (new)
16918 Specify whether a new file should be created for a configuration.
16919 `vhdl-compose-configuration-hierarchical': (new)
16920 Specify whether hierarchical configurations should be created.
16921 `vhdl-compose-configuration-use-subconfiguration': (new)
16922 Specify whether subconfigurations should be used inside configurations.
16926 (defconst vhdl-doc-keywords nil
16928 Reserved words in VHDL
16929 ----------------------
16931 VHDL'93 (IEEE Std 1076-1993):
16932 `vhdl-93-keywords' : keywords
16933 `vhdl-93-types' : standardized types
16934 `vhdl-93-attributes' : standardized attributes
16935 `vhdl-93-enum-values' : standardized enumeration values
16936 `vhdl-93-functions' : standardized functions
16937 `vhdl-93-packages' : standardized packages and libraries
16939 VHDL-AMS (IEEE Std 1076.1):
16940 `vhdl-ams-keywords' : keywords
16941 `vhdl-ams-types' : standardized types
16942 `vhdl-ams-attributes' : standardized attributes
16943 `vhdl-ams-enum-values' : standardized enumeration values
16944 `vhdl-ams-functions' : standardized functions
16946 Math Packages (IEEE Std 1076.2):
16947 `vhdl-math-types' : standardized types
16948 `vhdl-math-constants' : standardized constants
16949 `vhdl-math-functions' : standardized functions
16950 `vhdl-math-packages' : standardized packages
16953 `vhdl-verilog-keywords' : Verilog reserved words
16955 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16958 (defconst vhdl-doc-coding-style nil
16960 For VHDL coding style and naming convention guidelines, see the following
16964 \"VHDL Coding Styles and Methodologies\".
16965 Kluwer Academic Publishers, 1999.
16966 http://members.aol.com/vhdlcohen/vhdl/
16968 \[2] Michael Keating and Pierre Bricaud.
16969 \"Reuse Methodology Manual, Second Edition\".
16970 Kluwer Academic Publishers, 1999.
16971 http://www.openmore.com/openmore/rmm2.html
16973 \[3] European Space Agency.
16974 \"VHDL Modelling Guidelines\".
16975 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16977 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16978 to visually support naming conventions.")
16981 (defun vhdl-version ()
16982 "Echo the current version of VHDL Mode in the minibuffer."
16984 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16985 (vhdl-keep-region-active))
16987 (defun vhdl-doc-variable (variable)
16988 "Display VARIABLE's documentation in *Help* buffer."
16990 (unless (featurep 'xemacs)
16991 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16992 (with-output-to-temp-buffer
16993 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16994 (princ (documentation-property variable 'variable-documentation))
16995 (with-current-buffer standard-output
16997 (print-help-return-message)))
16999 (defun vhdl-doc-mode ()
17000 "Display VHDL Mode documentation in *Help* buffer."
17002 (unless (featurep 'xemacs)
17003 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17004 (with-output-to-temp-buffer
17005 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17008 (princ (documentation 'vhdl-mode))
17009 (with-current-buffer standard-output
17011 (print-help-return-message)))
17014 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17016 (provide 'vhdl-mode)
17018 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17019 ;;; vhdl-mode.el ends here