* w32-fns.el (w32-shell-dos-semantics):
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob61c75ee60cd3c49e7a84ea4fc0b2c239c1594991
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
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Reto Zimmermann <reto@gnu.org>
8 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
9 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
10 ;; Keywords: languages vhdl
11 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
18 (defconst vhdl-version "3.33.6"
19 "VHDL Mode version number.")
21 (defconst vhdl-time-stamp "2005-08-30"
22 "VHDL Mode time stamp for last update.")
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;; Commentary:
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; This package provides an Emacs major mode for editing VHDL code.
44 ;; It includes the following features:
46 ;; - Syntax highlighting
47 ;; - Indentation
48 ;; - Template insertion (electrification)
49 ;; - Insertion of file headers
50 ;; - Insertion of user-specified models
51 ;; - Port translation / testbench generation
52 ;; - Structural composition
53 ;; - Configuration generation
54 ;; - Sensitivity list updating
55 ;; - File browser
56 ;; - Design hierarchy browser
57 ;; - Source file compilation (syntax analysis)
58 ;; - Makefile generation
59 ;; - Code hiding
60 ;; - Word/keyword completion
61 ;; - Block commenting
62 ;; - Code fixing/alignment/beautification
63 ;; - Postscript printing
64 ;; - VHDL'87/'93 and VHDL-AMS supported
65 ;; - Comprehensive menu
66 ;; - Fully customizable
67 ;; - Works under GNU Emacs (recommended) and XEmacs
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; Documentation
72 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; Emacs Versions
77 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
78 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;; Installation
83 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
85 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
86 ;; or into an arbitrary directory that is added to the load path by the
87 ;; following line in your Emacs start-up file `.emacs':
89 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
91 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
92 ;; directory. Otherwise, byte-compile the source file:
93 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
94 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
96 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
97 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
98 ;; (not required in Emacs 20.X):
100 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
101 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
103 ;; More detailed installation instructions are included in the official
104 ;; VHDL Mode distribution.
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;; Acknowledgements
109 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
110 ;; and Steve Grout.
112 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
113 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
115 ;; Many thanks to all the users who sent me bug reports and enhancement
116 ;; requests.
117 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
118 ;; enhancement suggestions and the fruitful discussions.
119 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
120 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
122 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
123 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
124 ;; giving me the opportunity to develop this code.
125 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
126 ;; of the Swiss Government.
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130 ;;; Code:
132 ;; Emacs 21+ handling
133 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 21, 22, ... is used.")
135 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
136 "Non-nil if GNU Emacs 22, ... is used.")
138 (defvar compilation-file-regexp-alist)
139 (defvar conf-alist)
140 (defvar conf-entry)
141 (defvar conf-key)
142 (defvar ent-alist)
143 (defvar itimer-version)
144 (defvar lazy-lock-defer-contextually)
145 (defvar lazy-lock-defer-on-scrolling)
146 (defvar lazy-lock-defer-on-the-fly)
147 (defvar speedbar-attached-frame)
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 ;;; Variables
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 ;; help function for user options
155 (defun vhdl-custom-set (variable value &rest functions)
156 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
157 (if (fboundp 'custom-set-default)
158 (custom-set-default variable value)
159 (set-default variable value))
160 (while functions
161 (when (fboundp (car functions)) (funcall (car functions)))
162 (setq functions (cdr functions))))
164 (defun vhdl-widget-directory-validate (widget)
165 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
166 '/' or is empty)."
167 (let ((val (widget-value widget)))
168 (unless (string-match "^\\(\\|.*/\\)$" val)
169 (widget-put widget :error "Invalid directory entry: must end with '/'")
170 widget)))
172 ;; help string for user options
173 (defconst vhdl-name-doc-string "
175 FROM REGEXP is a regular expression matching the original name:
176 \".*\" matches the entire string
177 \"\\(...\\)\" matches a substring
178 TO STRING specifies the string to be inserted as new name:
179 \"\\&\" means substitute entire matched text
180 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
181 Examples:
182 \".*\" \"\\&\" inserts original string
183 \".*\" \"\\&_i\" attaches \"_i\" to original string
184 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
185 \".*\" \"foo\" inserts constant string \"foo\"
186 \".*\" \"\" inserts empty string")
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 ;; User variables
191 (defgroup vhdl nil
192 "Customizations for VHDL Mode."
193 :prefix "vhdl-"
194 :group 'languages
195 ; :version "21.2" ; comment out for XEmacs
198 (defgroup vhdl-mode nil
199 "Customizations for modes."
200 :group 'vhdl)
202 (defcustom vhdl-electric-mode t
203 "*Non-nil enables electrification (automatic template generation).
204 If nil, template generators can still be invoked through key bindings and
205 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
206 toggled by `\\[vhdl-electric-mode]'."
207 :type 'boolean
208 :group 'vhdl-mode)
210 (defcustom vhdl-stutter-mode t
211 "*Non-nil enables stuttering.
212 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
213 by `\\[vhdl-stutter-mode]'."
214 :type 'boolean
215 :group 'vhdl-mode)
217 (defcustom vhdl-indent-tabs-mode nil
218 "*Non-nil means indentation can insert tabs.
219 Overrides local variable `indent-tabs-mode'."
220 :type 'boolean
221 :group 'vhdl-mode)
224 (defgroup vhdl-compile nil
225 "Customizations for compilation."
226 :group 'vhdl)
228 (defcustom vhdl-compiler-alist
230 ;; Cadence Leapfrog: cv -file test.vhd
231 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
232 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
233 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
234 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
235 ("\\1/entity" "\\2/\\1" "\\1/configuration"
236 "\\1/package" "\\1/body" downcase))
237 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
238 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
239 ;; (PLL_400X_TOP) is not declared [10.3].
240 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
241 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
242 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
243 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
244 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
245 ;; Ikos Voyager: analyze test.vhd
246 ;; analyze test.vhd
247 ;; E L4/C5: this library unit is inaccessible
248 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
249 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
250 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
251 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
252 nil)
253 ;; ModelSim, Model Technology: vcom test.vhd
254 ;; ERROR: test.vhd(14): Unknown identifier: positiv
255 ;; WARNING[2]: test.vhd(85): Possible infinite loop
256 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
257 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
258 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
259 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase))
262 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
263 ;; test.vhd:34: error message
264 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
265 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
268 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
269 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
270 ;; ERROR: test.vhd(24): near "dnd": expecting: END
271 ;; WARNING[4]: test.vhd(30): A space is required between ...
272 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
273 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
274 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
275 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
276 "\\1/_primary.dat" "\\1/body.dat" downcase))
277 ;; Savant: scram -publish-cc test.vhd
278 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
279 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
280 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
281 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
282 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
283 "\\1_config.vhdl" "\\1_package.vhdl"
284 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
285 ;; Simili: vhdlp -work test.vhd
286 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
287 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
289 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
290 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
291 "\\1/prim.var" "\\1/_body.var" downcase))
292 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
293 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
294 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
296 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
297 nil)
298 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
299 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
300 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
301 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
302 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
303 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
304 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
305 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
306 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
307 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
308 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
309 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
310 ;; Synplify:
311 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
312 ("Synplify" "n/a" "n/a" "make" "-f \\1"
313 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
314 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
315 nil)
316 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
317 ;; Compiling "test.vhd" line 1...
318 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
319 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
320 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
321 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
322 ("^ *Compiling \"\\(.+\\)\" " 1)
323 nil)
324 ;; VeriBest: vc vhdl test.vhd
325 ;; (no file name printed out!)
326 ;; 32: Z <= A and BitA ;
327 ;; ^^^^
328 ;; [Error] Name BITA is unknown
329 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
330 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
331 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
332 nil)
333 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
334 ;; Compiling "test.vhd" line 1...
335 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
336 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
337 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
338 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
339 ("^ *Compiling \"\\(.+\\)\" " 1)
340 nil)
342 "*List of available VHDL compilers and their properties.
343 Each list entry specifies the following items for a compiler:
344 Compiler:
345 Compiler name : name used in option `vhdl-compiler' to choose compiler
346 Compile command : command used for source file compilation
347 Compile options : compile options (\"\\1\" inserts library name)
348 Make command : command used for compilation using a Makefile
349 Make options : make options (\"\\1\" inserts Makefile name)
350 Generate Makefile: use built-in function or command to generate a Makefile
351 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
352 Library command : command to create library directory \(\"\\1\" inserts
353 library directory, \"\\2\" inserts library name)
354 Compile directory: where compilation is run and the Makefile is placed
355 Library directory: directory of default library
356 Makefile name : name of Makefile (default is \"Makefile\")
357 ID string : compiler identification string (see `vhdl-project-alist')
358 Error message:
359 Regexp : regular expression to match error messages (*)
360 File subexp index: index of subexpression that matches the file name
361 Line subexp index: index of subexpression that matches the line number
362 Column subexp idx: index of subexpression that matches the column number
363 File message:
364 Regexp : regular expression to match a file name message
365 File subexp index: index of subexpression that matches the file name
366 Unit-to-file name mapping: mapping of library unit names to names of files
367 generated by the compiler (used for Makefile generation)
368 To string : string a name is mapped to (\"\\1\" inserts the unit name,
369 \"\\2\" inserts the entity name for architectures)
370 Case adjustment : adjust case of inserted unit names
372 \(*) The regular expression must match the error message starting from the
373 beginning of the line (but not necessarily to the end of the line).
375 Compile options allows insertion of the library name (see `vhdl-project-alist')
376 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
378 For Makefile generation, the built-in function can be used (requires
379 specification of the unit-to-file name mapping). Alternatively, an
380 external command can be specified. Work directory allows specification of
381 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
382 used for Makefile generation). To use another library name than \"work\",
383 customize `vhdl-project-alist'. The library command is inserted in Makefiles
384 to automatically create the library directory if not existent.
386 Compile options, compile directory, library directory, and Makefile name are
387 overwritten by the project settings if a project is defined (see
388 `vhdl-project-alist'). Directory paths are relative to the source file
389 directory.
391 Some compilers do not include the file name in the error message, but print
392 out a file name message in advance. In this case, set \"File Subexp Index\"
393 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
394 If no file name at all is printed out, set both \"File Message\" entries to 0
395 \(a default file name message will be printed out instead, does not work in
396 XEmacs).
398 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
399 assigning its name to option `vhdl-compiler'.
401 Please send any missing or erroneous compiler properties to the maintainer for
402 updating.
404 NOTE: Activate new error and file message regexps and reflect the new setting
405 in the choice list of option `vhdl-compiler' by restarting Emacs."
406 :type '(repeat
407 (list :tag "Compiler" :indent 2
408 (string :tag "Compiler name ")
409 (string :tag "Compile command ")
410 (string :tag "Compile options " "-work \\1")
411 (string :tag "Make command " "make")
412 (string :tag "Make options " "-f \\1")
413 (choice :tag "Generate Makefile "
414 (const :tag "Built-in function" nil)
415 (string :tag "Command" "vmake \\2 > \\1"))
416 (string :tag "Library command " "mkdir \\1")
417 (directory :tag "Compile directory "
418 :validate vhdl-widget-directory-validate "./")
419 (directory :tag "Library directory "
420 :validate vhdl-widget-directory-validate "work/")
421 (file :tag "Makefile name " "Makefile")
422 (string :tag "ID string ")
423 (list :tag "Error message" :indent 4
424 (regexp :tag "Regexp ")
425 (integer :tag "File subexp index")
426 (integer :tag "Line subexp index")
427 (integer :tag "Column subexp idx"))
428 (list :tag "File message" :indent 4
429 (regexp :tag "Regexp ")
430 (integer :tag "File subexp index"))
431 (choice :tag "Unit-to-file name mapping"
432 :format "%t: %[Value Menu%] %v\n"
433 (const :tag "Not defined" nil)
434 (list :tag "To string" :indent 4
435 (string :tag "Entity " "\\1.vhd")
436 (string :tag "Architecture " "\\2_\\1.vhd")
437 (string :tag "Configuration " "\\1.vhd")
438 (string :tag "Package " "\\1.vhd")
439 (string :tag "Package Body " "\\1_body.vhd")
440 (choice :tag "Case adjustment "
441 (const :tag "None" identity)
442 (const :tag "Upcase" upcase)
443 (const :tag "Downcase" downcase))))))
444 :set (lambda (variable value)
445 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
446 :group 'vhdl-compile)
448 (defcustom vhdl-compiler "ModelSim"
449 "*Specifies the VHDL compiler to be used for syntax analysis.
450 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
451 :type (let ((alist vhdl-compiler-alist) list)
452 (while alist
453 (setq list (cons (list 'const (caar alist)) list))
454 (setq alist (cdr alist)))
455 (append '(choice) (nreverse list)))
456 :group 'vhdl-compile)
458 (defcustom vhdl-compile-use-local-error-regexp t
459 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
460 In this case, only error message regexps for VHDL compilers are active if
461 compilation is started from a VHDL buffer. Otherwise, the error message
462 regexps are appended to the predefined global regexps, and all regexps are
463 active all the time. Note that by doing that, the predefined global regexps
464 might result in erroneous parsing of error messages for some VHDL compilers.
466 NOTE: Activate the new setting by restarting Emacs."
467 :type 'boolean
468 :group 'vhdl-compile)
470 (defcustom vhdl-makefile-generation-hook nil
471 "*Functions to run at the end of Makefile generation.
472 Allows to insert user specific parts into a Makefile.
474 Example:
475 \(lambda nil
476 \(re-search-backward \"^# Rule for compiling entire design\")
477 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
478 :type 'hook
479 :group 'vhdl-compile)
481 (defcustom vhdl-default-library "work"
482 "*Name of default library.
483 Is overwritten by project settings if a project is active."
484 :type 'string
485 :group 'vhdl-compile)
488 (defgroup vhdl-project nil
489 "Customizations for projects."
490 :group 'vhdl)
492 (defcustom vhdl-project-alist
493 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
494 "~/example1/" ("src/system/" "src/components/") ""
495 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
496 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
497 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
498 ("Example 2" "Individual source files, multiple compilers in different directories"
499 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
500 nil "\\1/" "work" "\\1/work/" "Makefile" "")
501 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
502 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
503 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
504 -------------------------------------------------------------------------------
505 -- This is a multi-line project description
506 -- that can be used as a project dependent part of the file header.
508 "*List of projects and their properties.
509 Name : name used in option `vhdl-project' to choose project
510 Title : title of project (single-line string)
511 Default directory: default project directory (absolute path)
512 Sources : a) source files : path + \"/\" + file name
513 b) directory : path + \"/\"
514 c) directory tree: \"-r \" + path + \"/\"
515 Exclude regexp : matches file/directory names to be excluded as sources
516 Compile options : project-specific options for each compiler
517 Compiler name : name of compiler for which these options are valid
518 Compile options: project-specific compiler options
519 (\"\\1\" inserts library name, \"\\2\" default options)
520 Make options: project-specific make options
521 (\"\\1\" inserts Makefile name, \"\\2\" default options)
522 Exceptions : file-specific exceptions
523 File name regexp: matches file names for which exceptions are valid
524 - Options : file-specific compiler options string
525 (\"\\1\" inserts library name, \"\\2\" default options,
526 \"\\3\" project-specific options)
527 - Do not compile: do not compile this file (in Makefile)
528 Compile directory: where compilation is run and the Makefile is placed
529 \(\"\\1\" inserts compiler ID string)
530 Library name : name of library (default is \"work\")
531 Library directory: path to library (\"\\1\" inserts compiler ID string)
532 Makefile name : name of Makefile
533 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
534 Description : description of project (multi-line string)
536 Project title and description are used to insert into the file header (see
537 option `vhdl-file-header').
539 The default directory must have an absolute path (use `M-TAB' for completion).
540 All other paths can be absolute or relative to the default directory. All
541 paths must end with '/'.
543 The design units found in the sources (files and directories) are shown in the
544 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
545 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
546 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
547 specified, the default directory is taken as source directory. Otherwise,
548 the default directory is only taken as source directory if there is a sources
549 entry with the empty string or \"./\". Exclude regexp allows to filter out
550 specific file and directory names from the list of sources (e.g. CVS
551 directories).
553 Files are compiled in the compile directory. Makefiles are also placed into
554 the compile directory. Library directory specifies which directory the
555 compiler compiles into (used to generate the Makefile).
557 Since different compile/library directories and Makefiles may exist for
558 different compilers within one project, these paths and names allow the
559 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
560 Compile options, compile directory, library directory, and Makefile name
561 overwrite the settings of the current compiler.
563 File-specific compiler options (highest priority) overwrite project-specific
564 options which overwrite default options (lowest priority). Lower priority
565 options can be inserted in higher priority options. This allows to reuse
566 default options (e.g. \"-file\") in project- or file-specific options (e.g.
567 \"-93 -file\").
569 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
570 by restarting Emacs."
571 :type `(repeat
572 (list :tag "Project" :indent 2
573 (string :tag "Name ")
574 (string :tag "Title ")
575 (directory :tag "Default directory"
576 :validate vhdl-widget-directory-validate
577 ,(abbreviate-file-name default-directory))
578 (repeat :tag "Sources " :indent 4
579 (directory :format " %v" "./"))
580 (regexp :tag "Exclude regexp ")
581 (repeat
582 :tag "Compile options " :indent 4
583 (list :tag "Compiler" :indent 6
584 ,(let ((alist vhdl-compiler-alist) list)
585 (while alist
586 (setq list (cons (list 'const (caar alist)) list))
587 (setq alist (cdr alist)))
588 (append '(choice :tag "Compiler name")
589 (nreverse list)))
590 (string :tag "Compile options" "\\2")
591 (string :tag "Make options " "\\2")
592 (repeat
593 :tag "Exceptions " :indent 8
594 (cons :format "%v"
595 (regexp :tag "File name regexp ")
596 (choice :format "%[Value Menu%] %v"
597 (string :tag "Options" "\\3")
598 (const :tag "Do not compile" nil))))))
599 (directory :tag "Compile directory"
600 :validate vhdl-widget-directory-validate "./")
601 (string :tag "Library name " "work")
602 (directory :tag "Library directory"
603 :validate vhdl-widget-directory-validate "work/")
604 (file :tag "Makefile name " "Makefile")
605 (string :tag "Description: (type `C-j' for newline)"
606 :format "%t\n%v\n")))
607 :set (lambda (variable value)
608 (vhdl-custom-set variable value
609 'vhdl-update-mode-menu
610 'vhdl-speedbar-refresh))
611 :group 'vhdl-project)
613 (defcustom vhdl-project nil
614 "*Specifies the default for the current project.
615 Select a project name from the ones defined in option `vhdl-project-alist'.
616 Is used to determine the project title and description to be inserted in file
617 headers and the source files/directories to be scanned in the hierarchy
618 browser. The current project can also be changed temporarily in the menu."
619 :type (let ((alist vhdl-project-alist) list)
620 (while alist
621 (setq list (cons (list 'const (caar alist)) list))
622 (setq alist (cdr alist)))
623 (append '(choice (const :tag "None" nil) (const :tag "--"))
624 (nreverse list)))
625 :group 'vhdl-project)
627 (defcustom vhdl-project-file-name '("\\1.prj")
628 "*List of file names/paths for importing/exporting project setups.
629 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
630 replaced by the user name (allows to have user-specific project setups).
631 The first entry is used as file name to import/export individual project
632 setups. All entries are used to automatically import project setups at
633 startup (see option `vhdl-project-auto-load'). Projects loaded from the
634 first entry are automatically made current. Hint: specify local project
635 setups in first entry, global setups in following entries; loading a local
636 project setup will make it current, while loading the global setups
637 is done without changing the current project.
638 Names can also have an absolute path (i.e. project setups can be stored
639 in global directories)."
640 :type '(repeat (string :tag "File name" "\\1.prj"))
641 :group 'vhdl-project)
643 (defcustom vhdl-project-auto-load '(startup)
644 "*Automatically load project setups from files.
645 All project setup files that match the file names specified in option
646 `vhdl-project-file-name' are automatically loaded. The project of the
647 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
648 entry is activated.
649 A project setup file can be obtained by exporting a project (see menu).
650 At startup: project setup file is loaded at Emacs startup"
651 :type '(set (const :tag "At startup" startup))
652 :group 'vhdl-project)
654 (defcustom vhdl-project-sort t
655 "*Non-nil means projects are displayed in alphabetical order."
656 :type 'boolean
657 :group 'vhdl-project)
660 (defgroup vhdl-style nil
661 "Customizations for coding styles."
662 :group 'vhdl
663 :group 'vhdl-template
664 :group 'vhdl-port
665 :group 'vhdl-compose)
667 (defcustom vhdl-standard '(87 nil)
668 "*VHDL standards used.
669 Basic standard:
670 VHDL'87 : IEEE Std 1076-1987
671 VHDL'93 : IEEE Std 1076-1993
672 Additional standards:
673 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
674 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
676 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
677 \"Activate Options\"."
678 :type '(list (choice :tag "Basic standard"
679 (const :tag "VHDL'87" 87)
680 (const :tag "VHDL'93" 93))
681 (set :tag "Additional standards" :indent 2
682 (const :tag "VHDL-AMS" ams)
683 (const :tag "Math packages" math)))
684 :set (lambda (variable value)
685 (vhdl-custom-set variable value
686 'vhdl-template-map-init
687 'vhdl-mode-abbrev-table-init
688 'vhdl-template-construct-alist-init
689 'vhdl-template-package-alist-init
690 'vhdl-update-mode-menu
691 'vhdl-words-init 'vhdl-font-lock-init))
692 :group 'vhdl-style)
694 (defcustom vhdl-basic-offset 2
695 "*Amount of basic offset used for indentation.
696 This value is used by + and - symbols in `vhdl-offsets-alist'."
697 :type 'integer
698 :group 'vhdl-style)
700 (defcustom vhdl-upper-case-keywords nil
701 "*Non-nil means convert keywords to upper case.
702 This is done when typed or expanded or by the fix case functions."
703 :type 'boolean
704 :set (lambda (variable value)
705 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
706 :group 'vhdl-style)
708 (defcustom vhdl-upper-case-types nil
709 "*Non-nil means convert standardized types to upper case.
710 This is done when expanded or by the fix case functions."
711 :type 'boolean
712 :set (lambda (variable value)
713 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
714 :group 'vhdl-style)
716 (defcustom vhdl-upper-case-attributes nil
717 "*Non-nil means convert standardized attributes to upper case.
718 This is done when expanded or by the fix case functions."
719 :type 'boolean
720 :set (lambda (variable value)
721 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
722 :group 'vhdl-style)
724 (defcustom vhdl-upper-case-enum-values nil
725 "*Non-nil means convert standardized enumeration values to upper case.
726 This is done when expanded or by the fix case functions."
727 :type 'boolean
728 :set (lambda (variable value)
729 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
730 :group 'vhdl-style)
732 (defcustom vhdl-upper-case-constants t
733 "*Non-nil means convert standardized constants to upper case.
734 This is done when expanded."
735 :type 'boolean
736 :set (lambda (variable value)
737 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
738 :group 'vhdl-style)
740 (defcustom vhdl-use-direct-instantiation 'standard
741 "*Non-nil means use VHDL'93 direct component instantiation.
742 Never : never
743 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
744 Always : always"
745 :type '(choice (const :tag "Never" never)
746 (const :tag "Standard" standard)
747 (const :tag "Always" always))
748 :group 'vhdl-style)
751 (defgroup vhdl-naming nil
752 "Customizations for naming conventions."
753 :group 'vhdl)
755 (defcustom vhdl-entity-file-name '(".*" . "\\&")
756 (concat
757 "*Specifies how the entity file name is obtained.
758 The entity file name can be obtained by modifying the entity name (e.g.
759 attaching or stripping off a substring). The file extension is automatically
760 taken from the file name of the current buffer."
761 vhdl-name-doc-string)
762 :type '(cons (regexp :tag "From regexp")
763 (string :tag "To string "))
764 :group 'vhdl-naming
765 :group 'vhdl-compose)
767 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
768 (concat
769 "*Specifies how the architecture file name is obtained.
770 The architecture file name can be obtained by modifying the entity
771 and/or architecture name (e.g. attaching or stripping off a substring). The
772 file extension is automatically taken from the file name of the current
773 buffer. The string that is matched against the regexp is the concatenation
774 of the entity and the architecture name separated by a space. This gives
775 access to both names (see default setting as example)."
776 vhdl-name-doc-string)
777 :type '(cons (regexp :tag "From regexp")
778 (string :tag "To string "))
779 :group 'vhdl-naming
780 :group 'vhdl-compose)
782 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
783 (concat
784 "*Specifies how the configuration file name is obtained.
785 The configuration file name can be obtained by modifying the configuration
786 name (e.g. attaching or stripping off a substring). The file extension is
787 automatically taken from the file name of the current buffer."
788 vhdl-name-doc-string)
789 :type '(cons (regexp :tag "From regexp")
790 (string :tag "To string "))
791 :group 'vhdl-naming
792 :group 'vhdl-compose)
794 (defcustom vhdl-package-file-name '(".*" . "\\&")
795 (concat
796 "*Specifies how the package file name is obtained.
797 The package file name can be obtained by modifying the package name (e.g.
798 attaching or stripping off a substring). The file extension is automatically
799 taken from the file name of the current buffer. Package files can be created
800 in a different directory by prepending a relative or absolute path to the
801 file name."
802 vhdl-name-doc-string)
803 :type '(cons (regexp :tag "From regexp")
804 (string :tag "To string "))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
808 (defcustom vhdl-file-name-case 'identity
809 "*Specifies how to change case for obtaining file names.
810 When deriving a file name from a VHDL unit name, case can be changed as
811 follows:
812 As Is: case is not changed (taken as is)
813 Lower Case: whole name is changed to lower case
814 Upper Case: whole name is changed to upper case
815 Capitalize: first letter of each word in name is capitalized"
816 :type '(choice (const :tag "As Is" identity)
817 (const :tag "Lower Case" downcase)
818 (const :tag "Upper Case" upcase)
819 (const :tag "Capitalize" capitalize))
820 :group 'vhdl-naming
821 :group 'vhdl-compose)
824 (defgroup vhdl-template nil
825 "Customizations for electrification."
826 :group 'vhdl)
828 (defcustom vhdl-electric-keywords '(vhdl user)
829 "*Type of keywords for which electrification is enabled.
830 VHDL keywords: invoke built-in templates
831 User keywords: invoke user models (see option `vhdl-model-alist')"
832 :type '(set (const :tag "VHDL keywords" vhdl)
833 (const :tag "User model keywords" user))
834 :set (lambda (variable value)
835 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
836 :group 'vhdl-template)
838 (defcustom vhdl-optional-labels 'process
839 "*Constructs for which labels are to be queried.
840 Template generators prompt for optional labels for:
841 None : no constructs
842 Processes only: processes only (also procedurals in VHDL-AMS)
843 All constructs: all constructs with optional labels and keyword END"
844 :type '(choice (const :tag "None" none)
845 (const :tag "Processes only" process)
846 (const :tag "All constructs" all))
847 :group 'vhdl-template)
849 (defcustom vhdl-insert-empty-lines 'unit
850 "*Specifies whether to insert empty lines in some templates.
851 This improves readability of code. Empty lines are inserted in:
852 None : no constructs
853 Design units only: entities, architectures, configurations, packages only
854 All constructs : also all constructs with BEGIN...END parts
856 Replaces option `vhdl-additional-empty-lines'."
857 :type '(choice (const :tag "None" none)
858 (const :tag "Design units only" unit)
859 (const :tag "All constructs" all))
860 :group 'vhdl-template
861 :group 'vhdl-port
862 :group 'vhdl-compose)
864 (defcustom vhdl-argument-list-indent nil
865 "*Non-nil means indent argument lists relative to opening parenthesis.
866 That is, argument, association, and port lists start on the same line as the
867 opening parenthesis and subsequent lines are indented accordingly.
868 Otherwise, lists start on a new line and are indented as normal code."
869 :type 'boolean
870 :group 'vhdl-template
871 :group 'vhdl-port
872 :group 'vhdl-compose)
874 (defcustom vhdl-association-list-with-formals t
875 "*Non-nil means write association lists with formal parameters.
876 Templates prompt for formal and actual parameters (ports/generics).
877 When pasting component instantiations, formals are included.
878 If nil, only a list of actual parameters is entered."
879 :type 'boolean
880 :group 'vhdl-template
881 :group 'vhdl-port
882 :group 'vhdl-compose)
884 (defcustom vhdl-conditions-in-parenthesis nil
885 "*Non-nil means place parenthesis around condition expressions."
886 :type 'boolean
887 :group 'vhdl-template)
889 (defcustom vhdl-zero-string "'0'"
890 "*String to use for a logic zero."
891 :type 'string
892 :group 'vhdl-template)
894 (defcustom vhdl-one-string "'1'"
895 "*String to use for a logic one."
896 :type 'string
897 :group 'vhdl-template)
900 (defgroup vhdl-header nil
901 "Customizations for file header."
902 :group 'vhdl-template
903 :group 'vhdl-compose)
905 (defcustom vhdl-file-header "\
906 -------------------------------------------------------------------------------
907 -- Title : <title string>
908 -- Project : <project>
909 -------------------------------------------------------------------------------
910 -- File : <filename>
911 -- Author : <author>
912 -- Company : <company>
913 -- Created : <date>
914 -- Last update: <date>
915 -- Platform : <platform>
916 -- Standard : <standard>
917 <projectdesc>-------------------------------------------------------------------------------
918 -- Description: <cursor>
919 <copyright>-------------------------------------------------------------------------------
920 -- Revisions :
921 -- Date Version Author Description
922 -- <date> 1.0 <login>\tCreated
923 -------------------------------------------------------------------------------
926 "*String or file to insert as file header.
927 If the string specifies an existing file name, the contents of the file is
928 inserted, otherwise the string itself is inserted as file header.
929 Type `C-j' for newlines.
930 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
931 if the header needs to be version controlled.
933 The following keywords for template generation are supported:
934 <filename> : replaced by the name of the buffer
935 <author> : replaced by the user name and email address
936 \(`user-full-name', `mail-host-address', `user-mail-address')
937 <login> : replaced by user login name (`user-login-name')
938 <company> : replaced by contents of option `vhdl-company-name'
939 <date> : replaced by the current date
940 <year> : replaced by the current year
941 <project> : replaced by title of current project (`vhdl-project')
942 <projectdesc> : replaced by description of current project (`vhdl-project')
943 <copyright> : replaced by copyright string (`vhdl-copyright-string')
944 <platform> : replaced by contents of option `vhdl-platform-spec'
945 <standard> : replaced by the VHDL language standard(s) used
946 <... string> : replaced by a queried string (\"...\" is the prompt word)
947 <title string>: replaced by file title in automatically generated files
948 <cursor> : final cursor position
950 The (multi-line) project description <projectdesc> can be used as a project
951 dependent part of the file header and can also contain the above keywords."
952 :type 'string
953 :group 'vhdl-header)
955 (defcustom vhdl-file-footer ""
956 "*String or file to insert as file footer.
957 If the string specifies an existing file name, the contents of the file is
958 inserted, otherwise the string itself is inserted as file footer (i.e. at
959 the end of the file).
960 Type `C-j' for newlines.
961 The same keywords as in option `vhdl-file-header' can be used."
962 :type 'string
963 :group 'vhdl-header)
965 (defcustom vhdl-company-name ""
966 "*Name of company to insert in file header.
967 See option `vhdl-file-header'."
968 :type 'string
969 :group 'vhdl-header)
971 (defcustom vhdl-copyright-string "\
972 -------------------------------------------------------------------------------
973 -- Copyright (c) <year> <company>
975 "*Copyright string to insert in file header.
976 Can be multi-line string (type `C-j' for newline) and contain other file
977 header keywords (see option `vhdl-file-header')."
978 :type 'string
979 :group 'vhdl-header)
981 (defcustom vhdl-platform-spec ""
982 "*Specification of VHDL platform to insert in file header.
983 The platform specification should contain names and versions of the
984 simulation and synthesis tools used.
985 See option `vhdl-file-header'."
986 :type 'string
987 :group 'vhdl-header)
989 (defcustom vhdl-date-format "%Y-%m-%d"
990 "*Specifies the date format to use in the header.
991 This string is passed as argument to the command `format-time-string'.
992 For more information on format strings, see the documentation for the
993 `format-time-string' command (C-h f `format-time-string')."
994 :type 'string
995 :group 'vhdl-header)
997 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
998 "*Prefix string of modification date in VHDL file header.
999 If actualization of the modification date is called (menu,
1000 `\\[vhdl-template-modify]'), this string is searched and the rest
1001 of the line replaced by the current date."
1002 :type 'string
1003 :group 'vhdl-header)
1005 (defcustom vhdl-modify-date-on-saving t
1006 "*Non-nil means update the modification date when the buffer is saved.
1007 Calls function `\\[vhdl-template-modify]').
1009 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1010 \"Activate Options\"."
1011 :type 'boolean
1012 :group 'vhdl-header)
1015 (defgroup vhdl-sequential-process nil
1016 "Customizations for sequential processes."
1017 :group 'vhdl-template)
1019 (defcustom vhdl-reset-kind 'async
1020 "*Specifies which kind of reset to use in sequential processes."
1021 :type '(choice (const :tag "None" none)
1022 (const :tag "Synchronous" sync)
1023 (const :tag "Asynchronous" async))
1024 :group 'vhdl-sequential-process)
1026 (defcustom vhdl-reset-active-high nil
1027 "*Non-nil means reset in sequential processes is active high.
1028 Otherwise, reset is active low."
1029 :type 'boolean
1030 :group 'vhdl-sequential-process)
1032 (defcustom vhdl-clock-rising-edge t
1033 "*Non-nil means rising edge of clock triggers sequential processes.
1034 Otherwise, falling edge triggers."
1035 :type 'boolean
1036 :group 'vhdl-sequential-process)
1038 (defcustom vhdl-clock-edge-condition 'standard
1039 "*Syntax of the clock edge condition.
1040 Standard: \"clk'event and clk = '1'\"
1041 Function: \"rising_edge(clk)\""
1042 :type '(choice (const :tag "Standard" standard)
1043 (const :tag "Function" function))
1044 :group 'vhdl-sequential-process)
1046 (defcustom vhdl-clock-name ""
1047 "*Name of clock signal to use in templates."
1048 :type 'string
1049 :group 'vhdl-sequential-process)
1051 (defcustom vhdl-reset-name ""
1052 "*Name of reset signal to use in templates."
1053 :type 'string
1054 :group 'vhdl-sequential-process)
1057 (defgroup vhdl-model nil
1058 "Customizations for user models."
1059 :group 'vhdl)
1061 (defcustom vhdl-model-alist
1062 '(("Example Model"
1063 "<label> : process (<clock>, <reset>)
1064 begin -- process <label>
1065 if <reset> = '0' then -- asynchronous reset (active low)
1066 <cursor>
1067 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1068 if <enable> = '1' then -- synchronous load
1070 end if;
1071 end if;
1072 end process <label>;"
1073 "e" ""))
1074 "*List of user models.
1075 VHDL models (templates) can be specified by the user in this list. They can be
1076 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1077 electrification (i.e. overriding existing or creating new keywords, see
1078 option `vhdl-electric-keywords').
1079 Name : name of model (string of words and spaces)
1080 String : string or name of file to be inserted as model (newline: `C-j')
1081 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1082 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1083 Keyword : keyword to invoke model
1085 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1086 A prompt that appears several times is queried once and replaced throughout
1087 the model. Special prompts are:
1088 <clock> : name specified in `vhdl-clock-name' (if not empty)
1089 <reset> : name specified in `vhdl-reset-name' (if not empty)
1090 <cursor>: final cursor position
1091 File header prompts (see variable `vhdl-file-header') are automatically
1092 replaced, so that user models can also be used to insert different types of
1093 headers.
1095 If the string specifies an existing file name, the contents of the file is
1096 inserted, otherwise the string itself is inserted.
1097 The code within the models should be correctly indented.
1098 Type `C-j' for newlines.
1100 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1101 \"Activate Options\"."
1102 :type '(repeat (list :tag "Model" :indent 2
1103 (string :tag "Name ")
1104 (string :tag "String : (type `C-j' for newline)"
1105 :format "%t\n%v")
1106 (sexp :tag "Key binding" x)
1107 (string :tag "Keyword " :format "%t: %v\n")))
1108 :set (lambda (variable value)
1109 (vhdl-custom-set variable value
1110 'vhdl-model-map-init
1111 'vhdl-model-defun
1112 'vhdl-mode-abbrev-table-init
1113 'vhdl-update-mode-menu))
1114 :group 'vhdl-model)
1117 (defgroup vhdl-compose nil
1118 "Customizations for structural composition."
1119 :group 'vhdl)
1121 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1122 (concat
1123 "*Specifies how the component architecture name is obtained.
1124 The component architecture name can be obtained by modifying the entity name
1125 \(e.g. attaching or stripping off a substring).
1126 If TO STRING is empty, the architecture name is queried."
1127 vhdl-name-doc-string)
1128 :type '(cons (regexp :tag "From regexp")
1129 (string :tag "To string "))
1130 :group 'vhdl-compose)
1132 (defcustom vhdl-compose-configuration-name
1133 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1134 (concat
1135 "*Specifies how the configuration name is obtained.
1136 The configuration name can be obtained by modifying the entity and/or
1137 architecture name (e.g. attaching or stripping off a substring). The string
1138 that is matched against the regexp is the concatenation of the entity and the
1139 architecture name separated by a space. This gives access to both names (see
1140 default setting as example)."
1141 vhdl-name-doc-string)
1142 :type '(cons (regexp :tag "From regexp")
1143 (string :tag "To string "))
1144 :group 'vhdl-compose)
1146 (defcustom vhdl-components-package-name
1147 '((".*" . "\\&_components") . "components")
1148 (concat
1149 "*Specifies how the name for the components package is obtained.
1150 The components package is a package containing all component declarations for
1151 the current design. Its name can be obtained by modifying the project name
1152 \(e.g. attaching or stripping off a substring). If no project is defined, the
1153 DIRECTORY entry is chosen."
1154 vhdl-name-doc-string)
1155 :type '(cons (cons :tag "Project" :indent 2
1156 (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 (string :tag "Directory:\n String "))
1159 :group 'vhdl-compose)
1161 (defcustom vhdl-use-components-package nil
1162 "*Non-nil means use a separate components package for component declarations.
1163 Otherwise, component declarations are inserted and searched for in the
1164 architecture declarative parts."
1165 :type 'boolean
1166 :group 'vhdl-compose)
1168 (defcustom vhdl-compose-include-header t
1169 "*Non-nil means include a header in automatically generated files."
1170 :type 'boolean
1171 :group 'vhdl-compose)
1173 (defcustom vhdl-compose-create-files 'single
1174 "*Specifies whether new files should be created for the new component.
1175 The component's entity and architecture are inserted:
1176 None : in current buffer
1177 Single file : in new single file
1178 Separate files: in two separate files
1179 The file names are obtained from variables `vhdl-entity-file-name' and
1180 `vhdl-architecture-file-name'."
1181 :type '(choice (const :tag "None" none)
1182 (const :tag "Single file" single)
1183 (const :tag "Separate files" separate))
1184 :group 'vhdl-compose)
1186 (defcustom vhdl-compose-configuration-create-file nil
1187 "*Specifies whether a new file should be created for the configuration.
1188 If non-nil, a new file is created for the configuration.
1189 The file name is obtained from variable `vhdl-configuration-file-name'."
1190 :type 'boolean
1191 :group 'vhdl-compose)
1193 (defcustom vhdl-compose-configuration-hierarchical t
1194 "*Specifies whether hierarchical configurations should be created.
1195 If non-nil, automatically created configurations are hierarchical and include
1196 the whole hierarchy of subcomponents. Otherwise the configuration only
1197 includes one level of subcomponents."
1198 :type 'boolean
1199 :group 'vhdl-compose)
1201 (defcustom vhdl-compose-configuration-use-subconfiguration t
1202 "*Specifies whether subconfigurations should be used inside configurations.
1203 If non-nil, automatically created configurations use configurations in binding
1204 indications for subcomponents, if such configurations exist. Otherwise,
1205 entities are used in binding indications for subcomponents."
1206 :type 'boolean
1207 :group 'vhdl-compose)
1210 (defgroup vhdl-port nil
1211 "Customizations for port translation functions."
1212 :group 'vhdl
1213 :group 'vhdl-compose)
1215 (defcustom vhdl-include-port-comments nil
1216 "*Non-nil means include port comments when a port is pasted."
1217 :type 'boolean
1218 :group 'vhdl-port)
1220 (defcustom vhdl-include-direction-comments nil
1221 "*Non-nil means include port direction in instantiations as comments."
1222 :type 'boolean
1223 :group 'vhdl-port)
1225 (defcustom vhdl-include-type-comments nil
1226 "*Non-nil means include generic/port type in instantiations as comments."
1227 :type 'boolean
1228 :group 'vhdl-port)
1230 (defcustom vhdl-include-group-comments 'never
1231 "*Specifies whether to include group comments and spacings.
1232 The comments and empty lines between groups of ports are pasted:
1233 Never : never
1234 Declarations: in entity/component/constant/signal declarations only
1235 Always : also in generic/port maps"
1236 :type '(choice (const :tag "Never" never)
1237 (const :tag "Declarations" decl)
1238 (const :tag "Always" always))
1239 :group 'vhdl-port)
1241 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1242 (concat
1243 "*Specifies how actual port names are obtained from formal port names.
1244 In a component instantiation, an actual port name can be obtained by
1245 modifying the formal port name (e.g. attaching or stripping off a substring)."
1246 vhdl-name-doc-string)
1247 :type '(cons (regexp :tag "From regexp")
1248 (string :tag "To string "))
1249 :group 'vhdl-port)
1251 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1252 (concat
1253 "*Specifies how an instance name is obtained.
1254 The instance name can be obtained by modifying the name of the component to be
1255 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1256 by a unique number (starting with 1).
1257 If TO STRING is empty, the instance name is queried."
1258 vhdl-name-doc-string)
1259 :type '(cons (regexp :tag "From regexp")
1260 (string :tag "To string "))
1261 :group 'vhdl-port)
1264 (defgroup vhdl-testbench nil
1265 "Customizations for testbench generation."
1266 :group 'vhdl-port)
1268 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1269 (concat
1270 "*Specifies how the testbench entity name is obtained.
1271 The entity name of a testbench can be obtained by modifying the name of
1272 the component to be tested (e.g. attaching or stripping off a substring)."
1273 vhdl-name-doc-string)
1274 :type '(cons (regexp :tag "From regexp")
1275 (string :tag "To string "))
1276 :group 'vhdl-testbench)
1278 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1279 (concat
1280 "*Specifies how the testbench architecture name is obtained.
1281 The testbench architecture name can be obtained by modifying the name of
1282 the component to be tested (e.g. attaching or stripping off a substring).
1283 If TO STRING is empty, the architecture name is queried."
1284 vhdl-name-doc-string)
1285 :type '(cons (regexp :tag "From regexp")
1286 (string :tag "To string "))
1287 :group 'vhdl-testbench)
1289 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1290 (concat
1291 "*Specifies how the testbench configuration name is obtained.
1292 The configuration name of a testbench can be obtained by modifying the entity
1293 and/or architecture name (e.g. attaching or stripping off a substring). The
1294 string that is matched against the regexp is the concatenation of the entity
1295 and the architecture name separated by a space. This gives access to both
1296 names (see default setting as example)."
1297 vhdl-name-doc-string)
1298 :type '(cons (regexp :tag "From regexp")
1299 (string :tag "To string "))
1300 :group 'vhdl-testbench)
1302 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1303 (concat
1304 "*Specifies how a DUT instance name is obtained.
1305 The design-under-test instance name (i.e. the component instantiated in the
1306 testbench) can be obtained by modifying the component name (e.g. attaching
1307 or stripping off a substring)."
1308 vhdl-name-doc-string)
1309 :type '(cons (regexp :tag "From regexp")
1310 (string :tag "To string "))
1311 :group 'vhdl-testbench)
1313 (defcustom vhdl-testbench-include-header t
1314 "*Non-nil means include a header in automatically generated files."
1315 :type 'boolean
1316 :group 'vhdl-testbench)
1318 (defcustom vhdl-testbench-declarations "\
1319 -- clock
1320 signal Clk : std_logic := '1';
1322 "*String or file to be inserted in the testbench declarative part.
1323 If the string specifies an existing file name, the contents of the file is
1324 inserted, otherwise the string itself is inserted in the testbench
1325 architecture before the BEGIN keyword.
1326 Type `C-j' for newlines."
1327 :type 'string
1328 :group 'vhdl-testbench)
1330 (defcustom vhdl-testbench-statements "\
1331 -- clock generation
1332 Clk <= not Clk after 10 ns;
1334 -- waveform generation
1335 WaveGen_Proc: process
1336 begin
1337 -- insert signal assignments here
1339 wait until Clk = '1';
1340 end process WaveGen_Proc;
1342 "*String or file to be inserted in the testbench statement part.
1343 If the string specifies an existing file name, the contents of the file is
1344 inserted, otherwise the string itself is inserted in the testbench
1345 architecture before the END keyword.
1346 Type `C-j' for newlines."
1347 :type 'string
1348 :group 'vhdl-testbench)
1350 (defcustom vhdl-testbench-initialize-signals nil
1351 "*Non-nil means initialize signals with `0' when declared in testbench."
1352 :type 'boolean
1353 :group 'vhdl-testbench)
1355 (defcustom vhdl-testbench-include-library t
1356 "*Non-nil means a library/use clause for std_logic_1164 is included."
1357 :type 'boolean
1358 :group 'vhdl-testbench)
1360 (defcustom vhdl-testbench-include-configuration t
1361 "*Non-nil means a testbench configuration is attached at the end."
1362 :type 'boolean
1363 :group 'vhdl-testbench)
1365 (defcustom vhdl-testbench-create-files 'single
1366 "*Specifies whether new files should be created for the testbench.
1367 testbench entity and architecture are inserted:
1368 None : in current buffer
1369 Single file : in new single file
1370 Separate files: in two separate files
1371 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1372 and `vhdl-testbench-architecture-file-name'."
1373 :type '(choice (const :tag "None" none)
1374 (const :tag "Single file" single)
1375 (const :tag "Separate files" separate))
1376 :group 'vhdl-testbench)
1378 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1379 (concat
1380 "*Specifies how the testbench entity file name is obtained.
1381 The entity file name can be obtained by modifying the testbench entity name
1382 \(e.g. attaching or stripping off a substring). The file extension is
1383 automatically taken from the file name of the current buffer. Testbench
1384 files can be created in a different directory by prepending a relative or
1385 absolute path to the file name."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1391 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1392 (concat
1393 "*Specifies how the testbench architecture file name is obtained.
1394 The architecture file name can be obtained by modifying the testbench entity
1395 and/or architecture name (e.g. attaching or stripping off a substring). The
1396 string that is matched against the regexp is the concatenation of the entity
1397 and the architecture name separated by a space. This gives access to both
1398 names (see default setting as example). Testbench files can be created in
1399 a different directory by prepending a relative or absolute path to the file
1400 name."
1401 vhdl-name-doc-string)
1402 :type '(cons (regexp :tag "From regexp")
1403 (string :tag "To string "))
1404 :group 'vhdl-testbench)
1407 (defgroup vhdl-comment nil
1408 "Customizations for comments."
1409 :group 'vhdl)
1411 (defcustom vhdl-self-insert-comments t
1412 "*Non-nil means various templates automatically insert help comments."
1413 :type 'boolean
1414 :group 'vhdl-comment)
1416 (defcustom vhdl-prompt-for-comments t
1417 "*Non-nil means various templates prompt for user definable comments."
1418 :type 'boolean
1419 :group 'vhdl-comment)
1421 (defcustom vhdl-inline-comment-column 40
1422 "*Column to indent and align inline comments to.
1423 Overrides local option `comment-column'.
1425 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1426 \"Activate Options\"."
1427 :type 'integer
1428 :group 'vhdl-comment)
1430 (defcustom vhdl-end-comment-column 79
1431 "*End of comment column.
1432 Comments that exceed this column number are wrapped.
1434 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1435 \"Activate Options\"."
1436 :type 'integer
1437 :group 'vhdl-comment)
1439 (defvar end-comment-column)
1442 (defgroup vhdl-align nil
1443 "Customizations for alignment."
1444 :group 'vhdl)
1446 (defcustom vhdl-auto-align t
1447 "*Non-nil means align some templates automatically after generation."
1448 :type 'boolean
1449 :group 'vhdl-align)
1451 (defcustom vhdl-align-groups t
1452 "*Non-nil means align groups of code lines separately.
1453 A group of code lines is a region of consecutive lines between two lines that
1454 match the regexp in option `vhdl-align-group-separate'."
1455 :type 'boolean
1456 :group 'vhdl-align)
1458 (defcustom vhdl-align-group-separate "^\\s-*$"
1459 "*Regexp for matching a line that separates groups of lines for alignment.
1460 Examples:
1461 \"^\\s-*$\": matches an empty line
1462 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1463 :type 'regexp
1464 :group 'vhdl-align)
1466 (defcustom vhdl-align-same-indent t
1467 "*Non-nil means align blocks with same indent separately.
1468 When a region or the entire buffer is aligned, the code is divided into
1469 blocks of same indent which are aligned separately (except for argument/port
1470 lists). This gives nicer alignment in most cases.
1471 Option `vhdl-align-groups' still applies within these blocks."
1472 :type 'boolean
1473 :group 'vhdl-align)
1476 (defgroup vhdl-highlight nil
1477 "Customizations for highlighting."
1478 :group 'vhdl)
1480 (defcustom vhdl-highlight-keywords t
1481 "*Non-nil means highlight VHDL keywords and other standardized words.
1482 The following faces are used:
1483 `font-lock-keyword-face' : keywords
1484 `font-lock-type-face' : standardized types
1485 `vhdl-font-lock-attribute-face': standardized attributes
1486 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1487 `vhdl-font-lock-function-face' : standardized function and package names
1489 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1490 entry \"Fontify Buffer\")."
1491 :type 'boolean
1492 :set (lambda (variable value)
1493 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1494 :group 'vhdl-highlight)
1496 (defcustom vhdl-highlight-names t
1497 "*Non-nil means highlight declaration names and construct labels.
1498 The following faces are used:
1499 `font-lock-function-name-face' : names in declarations of units,
1500 subprograms, components, as well as labels of VHDL constructs
1501 `font-lock-type-face' : names in type/nature declarations
1502 `vhdl-font-lock-attribute-face': names in attribute declarations
1503 `font-lock-variable-name-face' : names in declarations of signals,
1504 variables, constants, subprogram parameters, generics, and ports
1506 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1507 entry \"Fontify Buffer\")."
1508 :type 'boolean
1509 :set (lambda (variable value)
1510 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1511 :group 'vhdl-highlight)
1513 (defcustom vhdl-highlight-special-words nil
1514 "*Non-nil means highlight words with special syntax.
1515 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1516 are highlighted accordingly.
1517 Can be used for visual support of naming conventions.
1519 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1520 entry \"Fontify Buffer\")."
1521 :type 'boolean
1522 :set (lambda (variable value)
1523 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1524 :group 'vhdl-highlight)
1526 (defcustom vhdl-highlight-forbidden-words nil
1527 "*Non-nil means highlight forbidden words.
1528 The reserved words specified in option `vhdl-forbidden-words' or having the
1529 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1530 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1531 use them.
1533 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1534 entry \"Fontify Buffer\")."
1535 :type 'boolean
1536 :set (lambda (variable value)
1537 (vhdl-custom-set variable value
1538 'vhdl-words-init 'vhdl-font-lock-init))
1539 :group 'vhdl-highlight)
1541 (defcustom vhdl-highlight-verilog-keywords nil
1542 "*Non-nil means highlight Verilog keywords as reserved words.
1543 Verilog keywords are highlighted in a warning color (face
1544 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1546 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1547 entry \"Fontify Buffer\")."
1548 :type 'boolean
1549 :set (lambda (variable value)
1550 (vhdl-custom-set variable value
1551 'vhdl-words-init 'vhdl-font-lock-init))
1552 :group 'vhdl-highlight)
1554 (defcustom vhdl-highlight-translate-off nil
1555 "*Non-nil means background-highlight code excluded from translation.
1556 That is, all code between \"-- pragma translate_off\" and
1557 \"-- pragma translate_on\" is highlighted using a different background color
1558 \(face `vhdl-font-lock-translate-off-face').
1559 Note: this might slow down on-the-fly fontification (and thus editing).
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1563 :type 'boolean
1564 :set (lambda (variable value)
1565 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1566 :group 'vhdl-highlight)
1568 (defcustom vhdl-highlight-case-sensitive nil
1569 "*Non-nil means consider case for highlighting.
1570 Possible trade-off:
1571 non-nil also upper-case VHDL words are highlighted, but case of words with
1572 special syntax is not considered
1573 nil only lower-case VHDL words are highlighted, but case of words with
1574 special syntax is considered
1575 Overrides local option `font-lock-keywords-case-fold-search'.
1577 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1578 entry \"Fontify Buffer\")."
1579 :type 'boolean
1580 :group 'vhdl-highlight)
1582 (defcustom vhdl-special-syntax-alist
1583 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1584 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1585 ("variable" "\\w+_v" "Grey50" "Grey80"))
1586 "*List of special syntax to be highlighted.
1587 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1588 syntax (as regular expression) are highlighted in the corresponding color.
1590 Name : string of words and spaces
1591 Regexp : regular expression describing word syntax
1592 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1593 Color (light): foreground color for light background
1594 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1595 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1596 Color (dark) : foreground color for dark background
1597 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1598 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1600 Can be used for visual support of naming conventions, such as highlighting
1601 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1602 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1603 common substrings or name suffices.
1604 For each entry, a new face is generated with the specified colors and name
1605 \"vhdl-font-lock-\" + name + \"-face\".
1607 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1608 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1609 :type '(repeat (list :tag "Face" :indent 2
1610 (string :tag "Name ")
1611 (regexp :tag "Regexp " "\\w+_")
1612 (string :tag "Color (light)")
1613 (string :tag "Color (dark) ")))
1614 :set (lambda (variable value)
1615 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1616 :group 'vhdl-highlight)
1618 (defcustom vhdl-forbidden-words '()
1619 "*List of forbidden words to be highlighted.
1620 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1621 words are highlighted in a warning color to indicate not to use them.
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type '(repeat (string :format "%v"))
1626 :set (lambda (variable value)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
1631 (defcustom vhdl-forbidden-syntax ""
1632 "*Syntax of forbidden words to be highlighted.
1633 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1634 syntax are highlighted in a warning color to indicate not to use them.
1635 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1636 highlights identifiers with 10 or more characters).
1638 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\")."
1640 :type 'regexp
1641 :set (lambda (variable value)
1642 (vhdl-custom-set variable value
1643 'vhdl-words-init 'vhdl-font-lock-init))
1644 :group 'vhdl-highlight)
1646 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1647 "*List of compiler directive keywords recognized for highlighting.
1649 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1650 entry \"Fontify Buffer\")."
1651 :type '(repeat (string :format "%v"))
1652 :set (lambda (variable value)
1653 (vhdl-custom-set variable value
1654 'vhdl-words-init 'vhdl-font-lock-init))
1655 :group 'vhdl-highlight)
1658 (defgroup vhdl-speedbar nil
1659 "Customizations for speedbar."
1660 :group 'vhdl)
1662 (defcustom vhdl-speedbar-auto-open nil
1663 "*Non-nil means automatically open speedbar at startup.
1664 Alternatively, the speedbar can be opened from the VHDL menu."
1665 :type 'boolean
1666 :group 'vhdl-speedbar)
1668 (defcustom vhdl-speedbar-display-mode 'files
1669 "*Specifies the default displaying mode when opening speedbar.
1670 Alternatively, the displaying mode can be selected from the speedbar menu or
1671 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1672 :type '(choice (const :tag "Files" files)
1673 (const :tag "Directory hierarchy" directory)
1674 (const :tag "Project hierarchy" project))
1675 :group 'vhdl-speedbar)
1677 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1678 "*Limits scanning of large files and netlists.
1679 Design units: maximum file size to scan for design units
1680 Hierarchy (instances of subcomponents):
1681 File size: maximum file size to scan for instances (in bytes)
1682 Instances per arch: maximum number of instances to scan per architecture
1684 \"None\" always means that there is no limit.
1685 In case of files not or incompletely scanned, a warning message and the file
1686 names are printed out.
1687 Background: scanning for instances is considerably slower than scanning for
1688 design units, especially when there are many instances. These limits should
1689 prevent the scanning of large netlists."
1690 :type '(list (choice :tag "Design units"
1691 :format "%t : %[Value Menu%] %v"
1692 (const :tag "None" nil)
1693 (integer :tag "File size"))
1694 (list :tag "Hierarchy" :indent 2
1695 (choice :tag "File size"
1696 :format "%t : %[Value Menu%] %v"
1697 (const :tag "None" nil)
1698 (integer :tag "Size "))
1699 (choice :tag "Instances per arch"
1700 (const :tag "None" nil)
1701 (integer :tag "Number "))))
1702 :group 'vhdl-speedbar)
1704 (defcustom vhdl-speedbar-jump-to-unit t
1705 "*Non-nil means jump to the design unit code when opened in a buffer.
1706 The buffer cursor position is left unchanged otherwise."
1707 :type 'boolean
1708 :group 'vhdl-speedbar)
1710 (defcustom vhdl-speedbar-update-on-saving t
1711 "*Automatically update design hierarchy when buffer is saved."
1712 :type 'boolean
1713 :group 'vhdl-speedbar)
1715 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1716 "*Automatically save modified hierarchy caches when exiting Emacs.
1717 Hierarchy: design hierarchy information
1718 Display: displaying information (which design units to expand)"
1719 :type '(set (const :tag "Hierarchy" hierarchy)
1720 (const :tag "Display" display))
1721 :group 'vhdl-speedbar)
1723 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1724 "*Name of file for saving hierarchy cache.
1725 \"\\1\" is replaced by the project name if a project is specified,
1726 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1727 different users to have cache files in the same directory). Can also have
1728 an absolute path (i.e. all caches can be stored in one global directory)."
1729 :type 'string
1730 :group 'vhdl-speedbar)
1733 (defgroup vhdl-menu nil
1734 "Customizations for menues."
1735 :group 'vhdl)
1737 (defcustom vhdl-index-menu nil
1738 "*Non-nil means add an index menu for a source file when loading.
1739 Alternatively, the speedbar can be used. Note that the index menu scans a file
1740 when it is opened, while speedbar only scans the file upon request."
1741 :type 'boolean
1742 :group 'vhdl-menu)
1744 (defcustom vhdl-source-file-menu nil
1745 "*Non-nil means add a menu of all source files in current directory.
1746 Alternatively, the speedbar can be used."
1747 :type 'boolean
1748 :group 'vhdl-menu)
1750 (defcustom vhdl-hideshow-menu nil
1751 "*Non-nil means add hideshow menu and functionality at startup.
1752 Hideshow can also be enabled from the VHDL Mode menu.
1753 Hideshow allows hiding code of various VHDL constructs.
1755 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1756 \"Activate Options\"."
1757 :type 'boolean
1758 :group 'vhdl-menu)
1760 (defcustom vhdl-hide-all-init nil
1761 "*Non-nil means hide all design units initially after a file is loaded."
1762 :type 'boolean
1763 :group 'vhdl-menu)
1766 (defgroup vhdl-print nil
1767 "Customizations for printing."
1768 :group 'vhdl)
1770 (defcustom vhdl-print-two-column t
1771 "*Non-nil means print code in two columns and landscape format.
1772 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1773 prints VHDL files in a nice two-column landscape style.
1775 NOTE: Activate the new setting by restarting Emacs.
1776 Overrides `ps-print' settings locally."
1777 :type 'boolean
1778 :group 'vhdl-print)
1780 (defcustom vhdl-print-customize-faces t
1781 "*Non-nil means use an optimized set of faces for postscript printing.
1783 NOTE: Activate the new setting by restarting Emacs.
1784 Overrides `ps-print' settings locally."
1785 :type 'boolean
1786 :group 'vhdl-print)
1789 (defgroup vhdl-misc nil
1790 "Miscellaneous customizations."
1791 :group 'vhdl)
1793 (defcustom vhdl-intelligent-tab t
1794 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1795 That is, if preceeding character is part of a word then complete word,
1796 else if not at beginning of line then insert tab,
1797 else if last command was a `TAB' or `RET' then dedent one step,
1798 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1799 If nil, TAB always indents current line (i.e. `TAB' is bound to
1800 `indent-according-to-mode').
1802 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1803 \"Activate Options\"."
1804 :type 'boolean
1805 :group 'vhdl-misc)
1807 (defcustom vhdl-indent-syntax-based t
1808 "*Non-nil means indent lines of code based on their syntactic context.
1809 Otherwise, a line is indented like the previous nonblank line. This can be
1810 useful in large files where syntax-based indentation gets very slow."
1811 :type 'boolean
1812 :group 'vhdl-misc)
1814 (defcustom vhdl-word-completion-case-sensitive nil
1815 "*Non-nil means word completion using `TAB' is case sensitive.
1816 That is, `TAB' completes words that start with the same letters and case.
1817 Otherwise, case is ignored."
1818 :type 'boolean
1819 :group 'vhdl-misc)
1821 (defcustom vhdl-word-completion-in-minibuffer t
1822 "*Non-nil enables word completion in minibuffer (for template prompts).
1824 NOTE: Activate the new setting by restarting Emacs."
1825 :type 'boolean
1826 :group 'vhdl-misc)
1828 (defcustom vhdl-underscore-is-part-of-word nil
1829 "*Non-nil means consider the underscore character `_' as part of word.
1830 An identifier containing underscores is then treated as a single word in
1831 select and move operations. All parts of an identifier separated by underscore
1832 are treated as single words otherwise.
1834 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1835 \"Activate Options\"."
1836 :type 'boolean
1837 :set (lambda (variable value)
1838 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1839 :group 'vhdl-misc)
1842 (defgroup vhdl-related nil
1843 "Related general customizations."
1844 :group 'vhdl)
1846 ;; add related general customizations
1847 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1848 (if (featurep 'xemacs)
1849 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1850 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1851 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1852 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1853 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1854 (unless (featurep 'xemacs)
1855 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1856 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1857 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1858 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1861 ;; Internal variables
1863 (defvar vhdl-menu-max-size 20
1864 "*Specifies the maximum size of a menu before splitting it into submenues.")
1866 (defvar vhdl-progress-interval 1
1867 "*Interval used to update progress status during long operations.
1868 If a number, percentage complete gets updated after each interval of
1869 that many seconds. To inhibit all messages, set this option to nil.")
1871 (defvar vhdl-inhibit-startup-warnings-p nil
1872 "*If non-nil, inhibits start up compatibility warnings.")
1874 (defvar vhdl-strict-syntax-p nil
1875 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1876 If the syntactic symbol for a particular line does not match a symbol
1877 in the offsets alist, an error is generated, otherwise no error is
1878 reported and the syntactic symbol is ignored.")
1880 (defvar vhdl-echo-syntactic-information-p nil
1881 "*If non-nil, syntactic info is echoed when the line is indented.")
1883 (defconst vhdl-offsets-alist-default
1884 '((string . -1000)
1885 (cpp-macro . -1000)
1886 (block-open . 0)
1887 (block-close . 0)
1888 (statement . 0)
1889 (statement-cont . vhdl-lineup-statement-cont)
1890 (statement-block-intro . +)
1891 (statement-case-intro . +)
1892 (case-alternative . +)
1893 (comment . vhdl-lineup-comment)
1894 (arglist-intro . +)
1895 (arglist-cont . 0)
1896 (arglist-cont-nonempty . vhdl-lineup-arglist)
1897 (arglist-close . vhdl-lineup-arglist)
1898 (entity . 0)
1899 (configuration . 0)
1900 (package . 0)
1901 (architecture . 0)
1902 (package-body . 0)
1904 "Default settings for offsets of syntactic elements.
1905 Do not change this constant! See the variable `vhdl-offsets-alist' for
1906 more information.")
1908 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1909 "*Association list of syntactic element symbols and indentation offsets.
1910 As described below, each cons cell in this list has the form:
1912 (SYNTACTIC-SYMBOL . OFFSET)
1914 When a line is indented, `vhdl-mode' first determines the syntactic
1915 context of the line by generating a list of symbols called syntactic
1916 elements. This list can contain more than one syntactic element and
1917 the global variable `vhdl-syntactic-context' contains the context list
1918 for the line being indented. Each element in this list is actually a
1919 cons cell of the syntactic symbol and a buffer position. This buffer
1920 position is call the relative indent point for the line. Some
1921 syntactic symbols may not have a relative indent point associated with
1922 them.
1924 After the syntactic context list for a line is generated, `vhdl-mode'
1925 calculates the absolute indentation for the line by looking at each
1926 syntactic element in the list. First, it compares the syntactic
1927 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1928 finds a match, it adds the OFFSET to the column of the relative indent
1929 point. The sum of this calculation for each element in the syntactic
1930 list is the absolute offset for line being indented.
1932 If the syntactic element does not match any in the `vhdl-offsets-alist',
1933 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1934 the element is ignored.
1936 Actually, OFFSET can be an integer, a function, a variable, or one of
1937 the following symbols: `+', `-', `++', or `--'. These latter
1938 designate positive or negative multiples of `vhdl-basic-offset',
1939 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1940 called with a single argument containing the cons of the syntactic
1941 element symbol and the relative indent point. The function should
1942 return an integer offset.
1944 Here is the current list of valid syntactic element symbols:
1946 string -- inside multi-line string
1947 block-open -- statement block open
1948 block-close -- statement block close
1949 statement -- a VHDL statement
1950 statement-cont -- a continuation of a VHDL statement
1951 statement-block-intro -- the first line in a new statement block
1952 statement-case-intro -- the first line in a case alternative block
1953 case-alternative -- a case statement alternative clause
1954 comment -- a line containing only a comment
1955 arglist-intro -- the first line in an argument list
1956 arglist-cont -- subsequent argument list lines when no
1957 arguments follow on the same line as the
1958 the arglist opening paren
1959 arglist-cont-nonempty -- subsequent argument list lines when at
1960 least one argument follows on the same
1961 line as the arglist opening paren
1962 arglist-close -- the solo close paren of an argument list
1963 entity -- inside an entity declaration
1964 configuration -- inside a configuration declaration
1965 package -- inside a package declaration
1966 architecture -- inside an architecture body
1967 package-body -- inside a package body")
1969 (defvar vhdl-comment-only-line-offset 0
1970 "*Extra offset for line which contains only the start of a comment.
1971 Can contain an integer or a cons cell of the form:
1973 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1975 Where NON-ANCHORED-OFFSET is the amount of offset given to
1976 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1977 the amount of offset to give column-zero anchored comment-only lines.
1978 Just an integer as value is equivalent to (<val> . 0)")
1980 (defvar vhdl-special-indent-hook nil
1981 "*Hook for user defined special indentation adjustments.
1982 This hook gets called after a line is indented by the mode.")
1984 (defvar vhdl-style-alist
1985 '(("IEEE"
1986 (vhdl-basic-offset . 4)
1987 (vhdl-offsets-alist . ())))
1988 "Styles of Indentation.
1989 Elements of this alist are of the form:
1991 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1993 where STYLE-STRING is a short descriptive string used to select a
1994 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1995 value for that variable when using the selected style.
1997 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1998 case, the VALUE is a list containing elements of the form:
2000 (SYNTACTIC-SYMBOL . VALUE)
2002 as described in `vhdl-offsets-alist'. These are passed directly to
2003 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2004 your style, only those that are different from the default.")
2006 ;; dynamically append the default value of most variables
2007 (or (assoc "Default" vhdl-style-alist)
2008 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2009 vhdl-strict-syntax-p
2010 vhdl-echo-syntactic-information-p
2011 vhdl-basic-offset
2012 vhdl-offsets-alist
2013 vhdl-comment-only-line-offset))
2014 (default (cons "Default"
2015 (mapcar
2016 (function
2017 (lambda (var)
2018 (cons var (symbol-value var))))
2019 varlist))))
2020 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2022 (defvar vhdl-mode-hook nil
2023 "*Hook called by `vhdl-mode'.")
2026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2027 ;;; Required packages
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030 ;; mandatory
2031 (require 'assoc)
2032 (require 'compile) ; XEmacs
2033 (require 'easymenu)
2034 (require 'hippie-exp)
2036 ;; optional (minimize warning messages during compile)
2037 (eval-when-compile
2038 (require 'font-lock)
2039 (require 'ps-print)
2040 (require 'speedbar))
2043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2044 ;;; Compatibility
2045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2048 ;; XEmacs compatibility
2050 ;; active regions
2051 (defun vhdl-keep-region-active ()
2052 "Do whatever is necessary to keep the region active in XEmacs.
2053 Ignore byte-compiler warnings you might see."
2054 (and (featurep 'xemacs)
2055 (setq zmacs-region-stays t)))
2057 ;; `wildcard-to-regexp' is included only in XEmacs 21
2058 (unless (fboundp 'wildcard-to-regexp)
2059 (defun wildcard-to-regexp (wildcard)
2060 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2061 (let* ((i (string-match "[*?]" wildcard))
2062 (result (substring wildcard 0 i))
2063 (len (length wildcard)))
2064 (when i
2065 (while (< i len)
2066 (let ((ch (aref wildcard i)))
2067 (setq result (concat result
2068 (cond ((eq ch ?*) "[^\000]*")
2069 ((eq ch ??) "[^\000]")
2070 (t (char-to-string ch)))))
2071 (setq i (1+ i)))))
2072 (concat "\\`" result "\\'"))))
2074 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2075 ;; `regexp-opt' accelerates fontification by 10-20%
2076 (unless (fboundp 'regexp-opt)
2077 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2078 (defun regexp-opt (strings &optional paren)
2079 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2080 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2082 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2083 (unless (fboundp 'match-string-no-properties)
2084 (defalias 'match-string-no-properties 'match-string))
2086 ;; `subst-char-in-string' undefined (XEmacs)
2087 (unless (fboundp 'subst-char-in-string)
2088 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2089 (let ((i (length string))
2090 (newstr (if inplace string (copy-sequence string))))
2091 (while (> i 0)
2092 (setq i (1- i))
2093 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2094 newstr)))
2096 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2097 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2098 (not noninteractive))
2099 (load "itimer")
2100 (when (string< itimer-version "1.09")
2101 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2102 (beep) (sit-for 5)))
2104 ;; `file-expand-wildcards' undefined (XEmacs)
2105 (unless (fboundp 'file-expand-wildcards)
2106 (defun file-expand-wildcards (pattern &optional full)
2107 "Taken from Emacs' `files.el'."
2108 (let* ((nondir (file-name-nondirectory pattern))
2109 (dirpart (file-name-directory pattern))
2110 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2111 (mapcar 'file-name-as-directory
2112 (file-expand-wildcards (directory-file-name dirpart)))
2113 (list dirpart)))
2114 contents)
2115 (while dirs
2116 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2117 (file-directory-p (directory-file-name (car dirs))))
2118 (let ((this-dir-contents
2119 (delq nil
2120 (mapcar #'(lambda (name)
2121 (unless (string-match "\\`\\.\\.?\\'"
2122 (file-name-nondirectory name))
2123 name))
2124 (directory-files (or (car dirs) ".") full
2125 (wildcard-to-regexp nondir))))))
2126 (setq contents
2127 (nconc
2128 (if (and (car dirs) (not full))
2129 (mapcar (function (lambda (name) (concat (car dirs) name)))
2130 this-dir-contents)
2131 this-dir-contents)
2132 contents))))
2133 (setq dirs (cdr dirs)))
2134 contents)))
2136 ;; `member-ignore-case' undefined (XEmacs)
2137 (unless (fboundp 'member-ignore-case)
2138 (defalias 'member-ignore-case 'member))
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141 ;; Compatibility with older VHDL Mode versions
2143 (defvar vhdl-warnings nil
2144 "Warnings to tell the user during start up.")
2146 (defun vhdl-run-when-idle (secs repeat function)
2147 "Wait until idle, then run FUNCTION."
2148 (if (fboundp 'start-itimer)
2149 (start-itimer "vhdl-mode" function secs repeat t)
2150 ; (run-with-idle-timer secs repeat function)))
2151 ;; explicitely activate timer (necessary when Emacs is already idle)
2152 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2154 (defun vhdl-warning-when-idle (&rest args)
2155 "Wait until idle, then print out warning STRING and beep."
2156 (if noninteractive
2157 (vhdl-warning (apply 'format args) t)
2158 (unless vhdl-warnings
2159 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2160 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2162 (defun vhdl-warning (string &optional nobeep)
2163 "Print out warning STRING and beep."
2164 (message "WARNING: %s" string)
2165 (unless (or nobeep noninteractive) (beep)))
2167 (defun vhdl-print-warnings ()
2168 "Print out messages in variable `vhdl-warnings'."
2169 (let ((no-warnings (length vhdl-warnings)))
2170 (setq vhdl-warnings (nreverse vhdl-warnings))
2171 (while vhdl-warnings
2172 (message "WARNING: %s" (car vhdl-warnings))
2173 (setq vhdl-warnings (cdr vhdl-warnings)))
2174 (beep)
2175 (when (> no-warnings 1)
2176 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2178 ;; Backward compatibility checks and fixes
2179 ;; option `vhdl-compiler' changed format
2180 (unless (stringp vhdl-compiler)
2181 (setq vhdl-compiler "ModelSim")
2182 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2184 ;; option `vhdl-standard' changed format
2185 (unless (listp vhdl-standard)
2186 (setq vhdl-standard '(87 nil))
2187 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2189 ;; option `vhdl-model-alist' changed format
2190 (when (= (length (car vhdl-model-alist)) 3)
2191 (let ((old-alist vhdl-model-alist)
2192 new-alist)
2193 (while old-alist
2194 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2195 (setq old-alist (cdr old-alist)))
2196 (setq vhdl-model-alist (nreverse new-alist)))
2197 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2199 ;; option `vhdl-project-alist' changed format
2200 (when (= (length (car vhdl-project-alist)) 3)
2201 (let ((old-alist vhdl-project-alist)
2202 new-alist)
2203 (while old-alist
2204 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2205 (setq old-alist (cdr old-alist)))
2206 (setq vhdl-project-alist (nreverse new-alist)))
2207 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2209 ;; option `vhdl-project-alist' changed format (3.31.1)
2210 (when (= (length (car vhdl-project-alist)) 4)
2211 (let ((old-alist vhdl-project-alist)
2212 new-alist elem)
2213 (while old-alist
2214 (setq elem (car old-alist))
2215 (setq new-alist
2216 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2217 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2218 new-alist))
2219 (setq old-alist (cdr old-alist)))
2220 (setq vhdl-project-alist (nreverse new-alist)))
2221 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2223 ;; option `vhdl-project-alist' changed format (3.31.12)
2224 (when (= (length (car vhdl-project-alist)) 10)
2225 (let ((tmp-alist vhdl-project-alist))
2226 (while tmp-alist
2227 (setcdr (nthcdr 3 (car tmp-alist))
2228 (cons "" (nthcdr 4 (car tmp-alist))))
2229 (setq tmp-alist (cdr tmp-alist))))
2230 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2232 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2233 (when (= (length (car vhdl-compiler-alist)) 7)
2234 (let ((old-alist vhdl-compiler-alist)
2235 new-alist elem)
2236 (while old-alist
2237 (setq elem (car old-alist))
2238 (setq new-alist
2239 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2240 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2241 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2242 (nth 5 elem) (nth 6 elem) nil)
2243 new-alist))
2244 (setq old-alist (cdr old-alist)))
2245 (setq vhdl-compiler-alist (nreverse new-alist)))
2246 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2248 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2249 (when (= (length (car vhdl-compiler-alist)) 12)
2250 (let ((tmp-alist vhdl-compiler-alist))
2251 (while tmp-alist
2252 (setcdr (nthcdr 4 (car tmp-alist))
2253 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2254 (setq tmp-alist (cdr tmp-alist))))
2255 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2257 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2258 (when (= (length (car vhdl-compiler-alist)) 13)
2259 (let ((tmp-alist vhdl-compiler-alist))
2260 (while tmp-alist
2261 (setcdr (nthcdr 3 (car tmp-alist))
2262 (cons "" (nthcdr 4 (car tmp-alist))))
2263 (setq tmp-alist (cdr tmp-alist))))
2264 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2266 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2267 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2268 (let ((tmp-alist vhdl-compiler-alist))
2269 (while tmp-alist
2270 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2271 '(0 . nil))
2272 (setq tmp-alist (cdr tmp-alist))))
2273 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2275 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2276 (when (equal vhdl-project "")
2277 (setq vhdl-project nil)
2278 (customize-save-variable 'vhdl-project vhdl-project))
2280 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2281 (when (stringp vhdl-project-file-name)
2282 (setq vhdl-project-file-name (list vhdl-project-file-name))
2283 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2285 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2286 (if (not (boundp 'speedbar-indentation-width))
2287 (defvar speedbar-indentation-width 2)
2288 ;; set default to 2 if not already customized
2289 (unless (get 'speedbar-indentation-width 'saved-value)
2290 (setq speedbar-indentation-width 2)))
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;;; Help functions / inline substitutions / macros
2295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2297 (defun vhdl-standard-p (standard)
2298 "Check if STANDARD is specified as used standard."
2299 (or (eq standard (car vhdl-standard))
2300 (memq standard (cadr vhdl-standard))))
2302 (defun vhdl-project-p (&optional warning)
2303 "Return non-nil if a project is displayed, i.e. directories or files are
2304 specified."
2305 (if (assoc vhdl-project vhdl-project-alist)
2306 vhdl-project
2307 (when (and vhdl-project warning)
2308 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2309 nil))
2311 (defun vhdl-resolve-env-variable (string)
2312 "Resolve environment variables in STRING."
2313 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2314 (setq string (concat (match-string 1 string)
2315 (getenv (match-string 2 string))
2316 (match-string 4 string))))
2317 string)
2319 (defun vhdl-default-directory ()
2320 "Return the default directory of the current project or the directory of the
2321 current buffer if no project is defined."
2322 (if (vhdl-project-p)
2323 (expand-file-name (vhdl-resolve-env-variable
2324 (nth 1 (aget vhdl-project-alist vhdl-project))))
2325 default-directory))
2327 (defmacro vhdl-prepare-search-1 (&rest body)
2328 "Enable case insensitive search and switch to syntax table that includes '_',
2329 then execute BODY, and finally restore the old environment. Used for
2330 consistent searching."
2331 `(let ((case-fold-search t) ; case insensitive search
2332 (current-syntax-table (syntax-table))
2333 result
2334 (restore-prog ; program to restore enviroment
2335 '(progn
2336 ;; restore syntax table
2337 (set-syntax-table current-syntax-table))))
2338 ;; use extended syntax table
2339 (set-syntax-table vhdl-mode-ext-syntax-table)
2340 ;; execute BODY safely
2341 (setq result
2342 (condition-case info
2343 (progn ,@body)
2344 (error (eval restore-prog) ; restore environment on error
2345 (error (cadr info))))) ; pass error up
2346 ;; restore environment
2347 (eval restore-prog)
2348 result))
2350 (defmacro vhdl-prepare-search-2 (&rest body)
2351 "Enable case insensitive search, switch to syntax table that includes '_',
2352 and remove `intangible' overlays, then execute BODY, and finally restore the
2353 old environment. Used for consistent searching."
2354 `(let ((case-fold-search t) ; case insensitive search
2355 (current-syntax-table (syntax-table))
2356 result overlay-all-list overlay-intangible-list overlay
2357 (restore-prog ; program to restore enviroment
2358 '(progn
2359 ;; restore syntax table
2360 (set-syntax-table current-syntax-table)
2361 ;; restore `intangible' overlays
2362 (when (fboundp 'overlay-lists)
2363 (while overlay-intangible-list
2364 (overlay-put (car overlay-intangible-list) 'intangible t)
2365 (setq overlay-intangible-list
2366 (cdr overlay-intangible-list)))))))
2367 ;; use extended syntax table
2368 (set-syntax-table vhdl-mode-ext-syntax-table)
2369 ;; remove `intangible' overlays
2370 (when (fboundp 'overlay-lists)
2371 (setq overlay-all-list (overlay-lists))
2372 (setq overlay-all-list
2373 (append (car overlay-all-list) (cdr overlay-all-list)))
2374 (while overlay-all-list
2375 (setq overlay (car overlay-all-list))
2376 (when (memq 'intangible (overlay-properties overlay))
2377 (setq overlay-intangible-list
2378 (cons overlay overlay-intangible-list))
2379 (overlay-put overlay 'intangible nil))
2380 (setq overlay-all-list (cdr overlay-all-list))))
2381 ;; execute BODY safely
2382 (setq result
2383 (condition-case info
2384 (progn ,@body)
2385 (error (eval restore-prog) ; restore environment on error
2386 (error (cadr info))))) ; pass error up
2387 ;; restore environment
2388 (eval restore-prog)
2389 result))
2391 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2392 "Visit file FILE-NAME and execute BODY."
2393 `(if (null ,file-name)
2394 (progn ,@body)
2395 (unless (file-directory-p ,file-name)
2396 (let ((source-buffer (current-buffer))
2397 (visiting-buffer (find-buffer-visiting ,file-name))
2398 file-opened)
2399 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2400 (condition-case ()
2401 (progn (set-buffer (create-file-buffer ,file-name))
2402 (setq file-opened t)
2403 (vhdl-insert-file-contents ,file-name)
2404 (modify-syntax-entry ?\- ". 12" (syntax-table))
2405 (modify-syntax-entry ?\n ">" (syntax-table))
2406 (modify-syntax-entry ?\^M ">" (syntax-table))
2407 (modify-syntax-entry ?_ "w" (syntax-table))
2409 (error
2410 (if ,issue-error
2411 (progn
2412 (when file-opened (kill-buffer (current-buffer)))
2413 (set-buffer source-buffer)
2414 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2415 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2416 nil))))
2417 (condition-case info
2418 (progn ,@body)
2419 (error
2420 (if ,issue-error
2421 (progn
2422 (when file-opened (kill-buffer (current-buffer)))
2423 (set-buffer source-buffer)
2424 (error (cadr info)))
2425 (vhdl-warning (cadr info))))))
2426 (when file-opened (kill-buffer (current-buffer)))
2427 (set-buffer source-buffer)))))
2429 (defun vhdl-insert-file-contents (filename)
2430 "Nicked from `insert-file-contents-literally', but allow coding system
2431 conversion."
2432 (let ((format-alist nil)
2433 (after-insert-file-functions nil)
2434 (jka-compr-compression-info-list nil))
2435 (insert-file-contents filename t)))
2437 (defun vhdl-sort-alist (alist)
2438 "Sort ALIST."
2439 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2441 (defun vhdl-get-subdirs (directory)
2442 "Recursively get subdirectories of DIRECTORY."
2443 (let ((dir-list (list (file-name-as-directory directory)))
2444 file-list)
2445 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2446 (while file-list
2447 (when (file-directory-p (car file-list))
2448 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2449 (setq file-list (cdr file-list)))
2450 dir-list))
2452 (defun vhdl-aput (alist-symbol key &optional value)
2453 "As `aput', but delete key-value pair if VALUE is nil."
2454 (if value
2455 (aput alist-symbol key value)
2456 (adelete alist-symbol key)))
2458 (defun vhdl-delete (elt list)
2459 "Delete by side effect the first occurrence of ELT as a member of LIST."
2460 (setq list (cons nil list))
2461 (let ((list1 list))
2462 (while (and (cdr list1) (not (equal elt (cadr list1))))
2463 (setq list1 (cdr list1)))
2464 (when list
2465 (setcdr list1 (cddr list1))))
2466 (cdr list))
2468 (defun vhdl-speedbar-refresh (&optional key)
2469 "Refresh directory or project with name KEY."
2470 (when (and (boundp 'speedbar-frame)
2471 (frame-live-p speedbar-frame))
2472 (let ((pos (point))
2473 (last-frame (selected-frame)))
2474 (if (null key)
2475 (speedbar-refresh)
2476 (select-frame speedbar-frame)
2477 (when (save-excursion
2478 (goto-char (point-min))
2479 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2480 (goto-char (match-end 1))
2481 (speedbar-do-function-pointer)
2482 (backward-char 2)
2483 (speedbar-do-function-pointer)
2484 (message "Refreshing speedbar...done"))
2485 (select-frame last-frame)))))
2487 (defun vhdl-show-messages ()
2488 "Get *Messages* buffer to show recent messages."
2489 (interactive)
2490 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2492 (defun vhdl-use-direct-instantiation ()
2493 "Return whether direct instantiation is used."
2494 (or (eq vhdl-use-direct-instantiation 'always)
2495 (and (eq vhdl-use-direct-instantiation 'standard)
2496 (not (vhdl-standard-p '87)))))
2498 (defun vhdl-max-marker (marker1 marker2)
2499 "Return larger marker."
2500 (if (> marker1 marker2) marker1 marker2))
2502 (defun vhdl-goto-marker (marker)
2503 "Goto marker in appropriate buffer."
2504 (when (markerp marker)
2505 (set-buffer (marker-buffer marker)))
2506 (goto-char marker))
2508 (defun vhdl-menu-split (list title)
2509 "Split menu LIST into several submenues, if number of
2510 elements > `vhdl-menu-max-size'."
2511 (if (> (length list) vhdl-menu-max-size)
2512 (let ((remain list)
2513 (result '())
2514 (sublist '())
2515 (menuno 1)
2516 (i 0))
2517 (while remain
2518 (setq sublist (cons (car remain) sublist))
2519 (setq remain (cdr remain))
2520 (setq i (+ i 1))
2521 (if (= i vhdl-menu-max-size)
2522 (progn
2523 (setq result (cons (cons (format "%s %s" title menuno)
2524 (nreverse sublist)) result))
2525 (setq i 0)
2526 (setq menuno (+ menuno 1))
2527 (setq sublist '()))))
2528 (and sublist
2529 (setq result (cons (cons (format "%s %s" title menuno)
2530 (nreverse sublist)) result)))
2531 (nreverse result))
2532 list))
2535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2536 ;;; Bindings
2537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2540 ;; Key bindings
2542 (defvar vhdl-template-map nil
2543 "Keymap for VHDL templates.")
2545 (defun vhdl-template-map-init ()
2546 "Initialize `vhdl-template-map'."
2547 (setq vhdl-template-map (make-sparse-keymap))
2548 ;; key bindings for VHDL templates
2549 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2550 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2551 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2552 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2553 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2554 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2555 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2556 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2557 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2558 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2559 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2560 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2561 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2562 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2563 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2564 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2565 (define-key vhdl-template-map "el" 'vhdl-template-else)
2566 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2567 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2568 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2569 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2570 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2571 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2572 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2573 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2574 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2575 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2576 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2577 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2578 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2579 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2580 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2581 (define-key vhdl-template-map "li" 'vhdl-template-library)
2582 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2583 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2584 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2585 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2586 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2587 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2588 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2589 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2590 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2591 (define-key vhdl-template-map "po" 'vhdl-template-port)
2592 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2593 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2594 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2595 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2596 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2597 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2598 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2599 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2600 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2601 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2602 (define-key vhdl-template-map "us" 'vhdl-template-use)
2603 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2604 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2605 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2606 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2607 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2608 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2609 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2610 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2611 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2612 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2613 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2614 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2615 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2616 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2617 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2618 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2619 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2620 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2621 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2622 (when (vhdl-standard-p 'ams)
2623 (define-key vhdl-template-map "br" 'vhdl-template-break)
2624 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2625 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2626 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2627 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2628 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2629 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2630 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2631 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2632 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2633 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2635 (when (vhdl-standard-p 'math)
2636 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2637 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2640 ;; initialize template map for VHDL Mode
2641 (vhdl-template-map-init)
2643 (defun vhdl-function-name (prefix string &optional postfix)
2644 "Generate a Lisp function name.
2645 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2646 STRING are replaced by `-' and substrings are converted to lower case."
2647 (let ((name prefix))
2648 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2649 (setq name
2650 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2651 (setq string (substring string (match-beginning 2))))
2652 (when postfix (setq name (concat name "-" postfix)))
2653 (intern name)))
2655 (defvar vhdl-model-map nil
2656 "Keymap for VHDL models.")
2658 (defun vhdl-model-map-init ()
2659 "Initialize `vhdl-model-map'."
2660 (setq vhdl-model-map (make-sparse-keymap))
2661 ;; key bindings for VHDL models
2662 (let ((model-alist vhdl-model-alist) model)
2663 (while model-alist
2664 (setq model (car model-alist))
2665 (define-key vhdl-model-map (nth 2 model)
2666 (vhdl-function-name "vhdl-model" (nth 0 model)))
2667 (setq model-alist (cdr model-alist)))))
2669 ;; initialize user model map for VHDL Mode
2670 (vhdl-model-map-init)
2672 (defvar vhdl-mode-map nil
2673 "Keymap for VHDL Mode.")
2675 (defun vhdl-mode-map-init ()
2676 "Initialize `vhdl-mode-map'."
2677 (setq vhdl-mode-map (make-sparse-keymap))
2678 ;; template key bindings
2679 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2680 ;; model key bindings
2681 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2682 ;; standard key bindings
2683 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2684 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2685 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2686 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2687 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2688 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2689 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2690 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2691 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2692 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2693 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2694 ;; backspace/delete key bindings
2695 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2696 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2697 (define-key vhdl-mode-map [delete] 'delete-char)
2698 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2699 ;; mode specific key bindings
2700 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2701 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2702 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2703 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2704 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2705 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2706 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2707 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2708 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2709 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2710 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2711 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2712 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2713 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2714 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2715 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2716 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2717 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2718 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2719 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2720 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2721 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2722 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2723 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2724 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2725 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2726 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2727 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2728 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2729 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2730 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2731 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2732 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2733 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2734 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2735 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2736 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2737 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2740 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2741 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2743 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2746 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2747 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2748 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2749 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2750 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2751 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2752 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2753 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2754 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2755 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2756 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2757 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2758 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2759 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2761 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2762 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2763 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2764 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2765 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2766 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2767 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2768 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2769 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2770 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2771 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2772 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2773 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2774 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2775 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2776 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2777 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2778 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2779 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2780 ;; insert commands bindings
2781 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2782 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2783 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2784 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2785 ;; electric key bindings
2786 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2787 (when vhdl-intelligent-tab
2788 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2789 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2790 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2791 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2792 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2793 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2794 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2795 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2796 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2797 (when (vhdl-standard-p 'ams)
2798 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2800 ;; initialize mode map for VHDL Mode
2801 (vhdl-mode-map-init)
2803 ;; define special minibuffer keymap for enabling word completion in minibuffer
2804 ;; (useful in template generator prompts)
2805 (defvar vhdl-minibuffer-local-map
2806 (let ((map (make-sparse-keymap)))
2807 (set-keymap-parent map minibuffer-local-map)
2808 (when vhdl-word-completion-in-minibuffer
2809 (define-key map "\t" 'vhdl-minibuffer-tab))
2810 map)
2811 "Keymap for minibuffer used in VHDL Mode.")
2813 ;; set up electric character functions to work with
2814 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2815 (mapc
2816 (function
2817 (lambda (sym)
2818 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2819 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2820 '(vhdl-electric-space
2821 vhdl-electric-tab
2822 vhdl-electric-return
2823 vhdl-electric-dash
2824 vhdl-electric-open-bracket
2825 vhdl-electric-close-bracket
2826 vhdl-electric-quote
2827 vhdl-electric-semicolon
2828 vhdl-electric-comma
2829 vhdl-electric-period
2830 vhdl-electric-equal))
2832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2833 ;; Syntax table
2835 (defvar vhdl-mode-syntax-table nil
2836 "Syntax table used in `vhdl-mode' buffers.")
2838 (defvar vhdl-mode-ext-syntax-table nil
2839 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2841 (defun vhdl-mode-syntax-table-init ()
2842 "Initialize `vhdl-mode-syntax-table'."
2843 (setq vhdl-mode-syntax-table (make-syntax-table))
2844 ;; define punctuation
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)
2857 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2859 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2860 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2861 ;; define string
2862 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2863 ;; define underscore
2864 (when vhdl-underscore-is-part-of-word
2865 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2866 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2867 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2868 ;; and \n and \^M end a comment
2869 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2870 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2871 ;; define parentheses to match
2872 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2873 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2874 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2877 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2878 ;; extended syntax table including '_' (for simpler search regexps)
2879 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2880 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2882 ;; initialize syntax table for VHDL Mode
2883 (vhdl-mode-syntax-table-init)
2885 (defvar vhdl-syntactic-context nil
2886 "Buffer local variable containing syntactic analysis list.")
2887 (make-variable-buffer-local 'vhdl-syntactic-context)
2889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2890 ;; Abbrev ook bindings
2892 (defvar vhdl-mode-abbrev-table nil
2893 "Abbrev table to use in `vhdl-mode' buffers.")
2895 (defun vhdl-mode-abbrev-table-init ()
2896 "Initialize `vhdl-mode-abbrev-table'."
2897 (define-abbrev-table 'vhdl-mode-abbrev-table
2898 (append
2899 (when (memq 'vhdl vhdl-electric-keywords)
2900 ;; VHDL'93 keywords
2902 ("--" "" vhdl-template-display-comment-hook 0)
2903 ("abs" "" vhdl-template-default-hook 0)
2904 ("access" "" vhdl-template-default-hook 0)
2905 ("after" "" vhdl-template-default-hook 0)
2906 ("alias" "" vhdl-template-alias-hook 0)
2907 ("all" "" vhdl-template-default-hook 0)
2908 ("and" "" vhdl-template-default-hook 0)
2909 ("arch" "" vhdl-template-architecture-hook 0)
2910 ("architecture" "" vhdl-template-architecture-hook 0)
2911 ("array" "" vhdl-template-default-hook 0)
2912 ("assert" "" vhdl-template-assert-hook 0)
2913 ("attr" "" vhdl-template-attribute-hook 0)
2914 ("attribute" "" vhdl-template-attribute-hook 0)
2915 ("begin" "" vhdl-template-default-indent-hook 0)
2916 ("block" "" vhdl-template-block-hook 0)
2917 ("body" "" vhdl-template-default-hook 0)
2918 ("buffer" "" vhdl-template-default-hook 0)
2919 ("bus" "" vhdl-template-default-hook 0)
2920 ("case" "" vhdl-template-case-hook 0)
2921 ("comp" "" vhdl-template-component-hook 0)
2922 ("component" "" vhdl-template-component-hook 0)
2923 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2924 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2925 ("conf" "" vhdl-template-configuration-hook 0)
2926 ("configuration" "" vhdl-template-configuration-hook 0)
2927 ("cons" "" vhdl-template-constant-hook 0)
2928 ("constant" "" vhdl-template-constant-hook 0)
2929 ("disconnect" "" vhdl-template-disconnect-hook 0)
2930 ("downto" "" vhdl-template-default-hook 0)
2931 ("else" "" vhdl-template-else-hook 0)
2932 ("elseif" "" vhdl-template-elsif-hook 0)
2933 ("elsif" "" vhdl-template-elsif-hook 0)
2934 ("end" "" vhdl-template-default-indent-hook 0)
2935 ("entity" "" vhdl-template-entity-hook 0)
2936 ("exit" "" vhdl-template-exit-hook 0)
2937 ("file" "" vhdl-template-file-hook 0)
2938 ("for" "" vhdl-template-for-hook 0)
2939 ("func" "" vhdl-template-function-hook 0)
2940 ("function" "" vhdl-template-function-hook 0)
2941 ("generic" "" vhdl-template-generic-hook 0)
2942 ("group" "" vhdl-template-group-hook 0)
2943 ("guarded" "" vhdl-template-default-hook 0)
2944 ("if" "" vhdl-template-if-hook 0)
2945 ("impure" "" vhdl-template-default-hook 0)
2946 ("in" "" vhdl-template-default-hook 0)
2947 ("inertial" "" vhdl-template-default-hook 0)
2948 ("inout" "" vhdl-template-default-hook 0)
2949 ("inst" "" vhdl-template-instance-hook 0)
2950 ("instance" "" vhdl-template-instance-hook 0)
2951 ("is" "" vhdl-template-default-hook 0)
2952 ("label" "" vhdl-template-default-hook 0)
2953 ("library" "" vhdl-template-library-hook 0)
2954 ("linkage" "" vhdl-template-default-hook 0)
2955 ("literal" "" vhdl-template-default-hook 0)
2956 ("loop" "" vhdl-template-bare-loop-hook 0)
2957 ("map" "" vhdl-template-map-hook 0)
2958 ("mod" "" vhdl-template-default-hook 0)
2959 ("nand" "" vhdl-template-default-hook 0)
2960 ("new" "" vhdl-template-default-hook 0)
2961 ("next" "" vhdl-template-next-hook 0)
2962 ("nor" "" vhdl-template-default-hook 0)
2963 ("not" "" vhdl-template-default-hook 0)
2964 ("null" "" vhdl-template-default-hook 0)
2965 ("of" "" vhdl-template-default-hook 0)
2966 ("on" "" vhdl-template-default-hook 0)
2967 ("open" "" vhdl-template-default-hook 0)
2968 ("or" "" vhdl-template-default-hook 0)
2969 ("others" "" vhdl-template-others-hook 0)
2970 ("out" "" vhdl-template-default-hook 0)
2971 ("pack" "" vhdl-template-package-hook 0)
2972 ("package" "" vhdl-template-package-hook 0)
2973 ("port" "" vhdl-template-port-hook 0)
2974 ("postponed" "" vhdl-template-default-hook 0)
2975 ("procedure" "" vhdl-template-procedure-hook 0)
2976 ("process" "" vhdl-template-process-hook 0)
2977 ("pure" "" vhdl-template-default-hook 0)
2978 ("range" "" vhdl-template-default-hook 0)
2979 ("record" "" vhdl-template-default-hook 0)
2980 ("register" "" vhdl-template-default-hook 0)
2981 ("reject" "" vhdl-template-default-hook 0)
2982 ("rem" "" vhdl-template-default-hook 0)
2983 ("report" "" vhdl-template-report-hook 0)
2984 ("return" "" vhdl-template-return-hook 0)
2985 ("rol" "" vhdl-template-default-hook 0)
2986 ("ror" "" vhdl-template-default-hook 0)
2987 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2988 ("severity" "" vhdl-template-default-hook 0)
2989 ("shared" "" vhdl-template-default-hook 0)
2990 ("sig" "" vhdl-template-signal-hook 0)
2991 ("signal" "" vhdl-template-signal-hook 0)
2992 ("sla" "" vhdl-template-default-hook 0)
2993 ("sll" "" vhdl-template-default-hook 0)
2994 ("sra" "" vhdl-template-default-hook 0)
2995 ("srl" "" vhdl-template-default-hook 0)
2996 ("subtype" "" vhdl-template-subtype-hook 0)
2997 ("then" "" vhdl-template-default-hook 0)
2998 ("to" "" vhdl-template-default-hook 0)
2999 ("transport" "" vhdl-template-default-hook 0)
3000 ("type" "" vhdl-template-type-hook 0)
3001 ("unaffected" "" vhdl-template-default-hook 0)
3002 ("units" "" vhdl-template-default-hook 0)
3003 ("until" "" vhdl-template-default-hook 0)
3004 ("use" "" vhdl-template-use-hook 0)
3005 ("var" "" vhdl-template-variable-hook 0)
3006 ("variable" "" vhdl-template-variable-hook 0)
3007 ("wait" "" vhdl-template-wait-hook 0)
3008 ("when" "" vhdl-template-when-hook 0)
3009 ("while" "" vhdl-template-while-loop-hook 0)
3010 ("with" "" vhdl-template-with-hook 0)
3011 ("xnor" "" vhdl-template-default-hook 0)
3012 ("xor" "" vhdl-template-default-hook 0)
3014 ;; VHDL-AMS keywords
3015 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3017 ("across" "" vhdl-template-default-hook 0)
3018 ("break" "" vhdl-template-break-hook 0)
3019 ("limit" "" vhdl-template-limit-hook 0)
3020 ("nature" "" vhdl-template-nature-hook 0)
3021 ("noise" "" vhdl-template-default-hook 0)
3022 ("procedural" "" vhdl-template-procedural-hook 0)
3023 ("quantity" "" vhdl-template-quantity-hook 0)
3024 ("reference" "" vhdl-template-default-hook 0)
3025 ("spectrum" "" vhdl-template-default-hook 0)
3026 ("subnature" "" vhdl-template-subnature-hook 0)
3027 ("terminal" "" vhdl-template-terminal-hook 0)
3028 ("through" "" vhdl-template-default-hook 0)
3029 ("tolerance" "" vhdl-template-default-hook 0)
3031 ;; user model keywords
3032 (when (memq 'user vhdl-electric-keywords)
3033 (let ((alist vhdl-model-alist)
3034 abbrev-list keyword)
3035 (while alist
3036 (setq keyword (nth 3 (car alist)))
3037 (unless (equal keyword "")
3038 (setq abbrev-list
3039 (cons (list keyword ""
3040 (vhdl-function-name
3041 "vhdl-model" (nth 0 (car alist)) "hook") 0)
3042 abbrev-list)))
3043 (setq alist (cdr alist)))
3044 abbrev-list)))))
3046 ;; initialize abbrev table for VHDL Mode
3047 (vhdl-mode-abbrev-table-init)
3049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3050 ;; Template completion lists
3052 (defvar vhdl-template-construct-alist nil
3053 "List of built-in construct templates.")
3055 (defun vhdl-template-construct-alist-init ()
3056 "Initialize `vhdl-template-construct-alist'."
3057 (setq
3058 vhdl-template-construct-alist
3059 (append
3061 ("alias declaration" vhdl-template-alias)
3062 ("architecture body" vhdl-template-architecture)
3063 ("assertion" vhdl-template-assert)
3064 ("attribute declaration" vhdl-template-attribute-decl)
3065 ("attribute specification" vhdl-template-attribute-spec)
3066 ("block configuration" vhdl-template-block-configuration)
3067 ("block statement" vhdl-template-block)
3068 ("case statement" vhdl-template-case-is)
3069 ("component configuration" vhdl-template-component-conf)
3070 ("component declaration" vhdl-template-component-decl)
3071 ("component instantiation statement" vhdl-template-component-inst)
3072 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3073 ("configuration declaration" vhdl-template-configuration-decl)
3074 ("configuration specification" vhdl-template-configuration-spec)
3075 ("constant declaration" vhdl-template-constant)
3076 ("disconnection specification" vhdl-template-disconnect)
3077 ("entity declaration" vhdl-template-entity)
3078 ("exit statement" vhdl-template-exit)
3079 ("file declaration" vhdl-template-file)
3080 ("generate statement" vhdl-template-generate)
3081 ("generic clause" vhdl-template-generic)
3082 ("group declaration" vhdl-template-group-decl)
3083 ("group template declaration" vhdl-template-group-template)
3084 ("if statement" vhdl-template-if-then)
3085 ("library clause" vhdl-template-library)
3086 ("loop statement" vhdl-template-loop)
3087 ("next statement" vhdl-template-next)
3088 ("package declaration" vhdl-template-package-decl)
3089 ("package body" vhdl-template-package-body)
3090 ("port clause" vhdl-template-port)
3091 ("process statement" vhdl-template-process)
3092 ("report statement" vhdl-template-report)
3093 ("return statement" vhdl-template-return)
3094 ("selected signal assignment" vhdl-template-selected-signal-asst)
3095 ("signal declaration" vhdl-template-signal)
3096 ("subprogram declaration" vhdl-template-subprogram-decl)
3097 ("subprogram body" vhdl-template-subprogram-body)
3098 ("subtype declaration" vhdl-template-subtype)
3099 ("type declaration" vhdl-template-type)
3100 ("use clause" vhdl-template-use)
3101 ("variable declaration" vhdl-template-variable)
3102 ("wait statement" vhdl-template-wait)
3104 (when (vhdl-standard-p 'ams)
3106 ("break statement" vhdl-template-break)
3107 ("nature declaration" vhdl-template-nature)
3108 ("quantity declaration" vhdl-template-quantity)
3109 ("simultaneous case statement" vhdl-template-case-use)
3110 ("simultaneous if statement" vhdl-template-if-use)
3111 ("simultaneous procedural statement" vhdl-template-procedural)
3112 ("step limit specification" vhdl-template-limit)
3113 ("subnature declaration" vhdl-template-subnature)
3114 ("terminal declaration" vhdl-template-terminal)
3115 )))))
3117 ;; initialize for VHDL Mode
3118 (vhdl-template-construct-alist-init)
3120 (defvar vhdl-template-package-alist nil
3121 "List of built-in package templates.")
3123 (defun vhdl-template-package-alist-init ()
3124 "Initialize `vhdl-template-package-alist'."
3125 (setq
3126 vhdl-template-package-alist
3127 (append
3129 ("numeric_bit" vhdl-template-package-numeric-bit)
3130 ("numeric_std" vhdl-template-package-numeric-std)
3131 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3132 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3133 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3134 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3135 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3136 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3137 ("textio" vhdl-template-package-textio)
3139 (when (vhdl-standard-p 'math)
3141 ("math_complex" vhdl-template-package-math-complex)
3142 ("math_real" vhdl-template-package-math-real)
3143 )))))
3145 ;; initialize for VHDL Mode
3146 (vhdl-template-package-alist-init)
3148 (defvar vhdl-template-directive-alist
3150 ("translate_on" vhdl-template-directive-translate-on)
3151 ("translate_off" vhdl-template-directive-translate-off)
3152 ("synthesis_on" vhdl-template-directive-synthesis-on)
3153 ("synthesis_off" vhdl-template-directive-synthesis-off)
3155 "List of built-in directive templates.")
3158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3159 ;;; Menues
3160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3163 ;; VHDL menu (using `easy-menu.el')
3165 (defun vhdl-customize ()
3166 "Call the customize function with `vhdl' as argument."
3167 (interactive)
3168 (customize-browse 'vhdl))
3170 (defun vhdl-create-mode-menu ()
3171 "Create VHDL Mode menu."
3172 `("VHDL"
3173 ,(append
3174 '("Project"
3175 ["None" (vhdl-set-project "")
3176 :style radio :selected (null vhdl-project)]
3177 "--")
3178 ;; add menu entries for defined projects
3179 (let ((project-alist vhdl-project-alist) menu-list name)
3180 (while project-alist
3181 (setq name (caar project-alist))
3182 (setq menu-list
3183 (cons `[,name (vhdl-set-project ,name)
3184 :style radio :selected (equal ,name vhdl-project)]
3185 menu-list))
3186 (setq project-alist (cdr project-alist)))
3187 (setq menu-list
3188 (if vhdl-project-sort
3189 (sort menu-list
3190 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3191 (nreverse menu-list)))
3192 (vhdl-menu-split menu-list "Project"))
3193 '("--" "--"
3194 ["Select Project..." vhdl-set-project t]
3195 ["Set As Default Project" vhdl-set-default-project t]
3196 "--"
3197 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3198 ["Import Project..." vhdl-import-project
3199 :keys "C-c C-p C-m" :active t]
3200 ["Export Project" vhdl-export-project vhdl-project]
3201 "--"
3202 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3203 "--"
3204 ("Compile"
3205 ["Compile Buffer" vhdl-compile t]
3206 ["Stop Compilation" kill-compilation t]
3207 "--"
3208 ["Make" vhdl-make t]
3209 ["Generate Makefile" vhdl-generate-makefile t]
3210 "--"
3211 ["Next Error" next-error t]
3212 ["Previous Error" previous-error t]
3213 ["First Error" first-error t]
3214 "--"
3215 ,(append
3216 '("Compiler")
3217 ;; add menu entries for defined compilers
3218 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3219 (while comp-alist
3220 (setq name (caar comp-alist))
3221 (setq menu-list
3222 (cons `[,name (setq vhdl-compiler ,name)
3223 :style radio :selected (equal ,name vhdl-compiler)]
3224 menu-list))
3225 (setq comp-alist (cdr comp-alist)))
3226 (setq menu-list (nreverse menu-list))
3227 (vhdl-menu-split menu-list "Compiler"))
3228 '("--" "--"
3229 ["Select Compiler..." vhdl-set-compiler t]
3230 "--"
3231 ["Customize Compiler..."
3232 (customize-option 'vhdl-compiler-alist) t])))
3233 "--"
3234 ,(append
3235 '("Template"
3236 ("VHDL Construct 1"
3237 ["Alias" vhdl-template-alias t]
3238 ["Architecture" vhdl-template-architecture t]
3239 ["Assert" vhdl-template-assert t]
3240 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3241 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3242 ["Block" vhdl-template-block t]
3243 ["Case" vhdl-template-case-is t]
3244 ["Component (Decl)" vhdl-template-component-decl t]
3245 ["(Component) Instance" vhdl-template-component-inst t]
3246 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3247 ["Configuration (Block)" vhdl-template-block-configuration t]
3248 ["Configuration (Comp)" vhdl-template-component-conf t]
3249 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3250 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3251 ["Constant" vhdl-template-constant t]
3252 ["Disconnect" vhdl-template-disconnect t]
3253 ["Else" vhdl-template-else t]
3254 ["Elsif" vhdl-template-elsif t]
3255 ["Entity" vhdl-template-entity t]
3256 ["Exit" vhdl-template-exit t]
3257 ["File" vhdl-template-file t]
3258 ["For (Generate)" vhdl-template-for-generate t]
3259 ["For (Loop)" vhdl-template-for-loop t]
3260 ["Function (Body)" vhdl-template-function-body t]
3261 ["Function (Decl)" vhdl-template-function-decl t]
3262 ["Generic" vhdl-template-generic t]
3263 ["Group (Decl)" vhdl-template-group-decl t]
3264 ["Group (Template)" vhdl-template-group-template t])
3265 ("VHDL Construct 2"
3266 ["If (Generate)" vhdl-template-if-generate t]
3267 ["If (Then)" vhdl-template-if-then t]
3268 ["Library" vhdl-template-library t]
3269 ["Loop" vhdl-template-bare-loop t]
3270 ["Map" vhdl-template-map t]
3271 ["Next" vhdl-template-next t]
3272 ["Others (Aggregate)" vhdl-template-others t]
3273 ["Package (Decl)" vhdl-template-package-decl t]
3274 ["Package (Body)" vhdl-template-package-body t]
3275 ["Port" vhdl-template-port t]
3276 ["Procedure (Body)" vhdl-template-procedure-body t]
3277 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3278 ["Process (Comb)" vhdl-template-process-comb t]
3279 ["Process (Seq)" vhdl-template-process-seq t]
3280 ["Report" vhdl-template-report t]
3281 ["Return" vhdl-template-return t]
3282 ["Select" vhdl-template-selected-signal-asst t]
3283 ["Signal" vhdl-template-signal t]
3284 ["Subtype" vhdl-template-subtype t]
3285 ["Type" vhdl-template-type t]
3286 ["Use" vhdl-template-use t]
3287 ["Variable" vhdl-template-variable t]
3288 ["Wait" vhdl-template-wait t]
3289 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3290 ["When" vhdl-template-when t]
3291 ["While (Loop)" vhdl-template-while-loop t]
3292 ["With" vhdl-template-with t]))
3293 (when (vhdl-standard-p 'ams)
3294 '(("VHDL-AMS Construct"
3295 ["Break" vhdl-template-break t]
3296 ["Case (Use)" vhdl-template-case-use t]
3297 ["If (Use)" vhdl-template-if-use t]
3298 ["Limit" vhdl-template-limit t]
3299 ["Nature" vhdl-template-nature t]
3300 ["Procedural" vhdl-template-procedural t]
3301 ["Quantity (Free)" vhdl-template-quantity-free t]
3302 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3303 ["Quantity (Source)" vhdl-template-quantity-source t]
3304 ["Subnature" vhdl-template-subnature t]
3305 ["Terminal" vhdl-template-terminal t])))
3306 '(["Insert Construct..." vhdl-template-insert-construct
3307 :keys "C-c C-i C-t"]
3308 "--")
3309 (list
3310 (append
3311 '("Package")
3312 (when (vhdl-standard-p 'math)
3313 '(["math_complex" vhdl-template-package-math-complex t]
3314 ["math_real" vhdl-template-package-math-real t]))
3315 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3316 ["numeric_std" vhdl-template-package-numeric-std t]
3317 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3318 ["textio" vhdl-template-package-textio t]
3319 "--"
3320 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3321 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3322 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3323 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3324 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3325 "--"
3326 ["Insert Package..." vhdl-template-insert-package
3327 :keys "C-c C-i C-p"])))
3328 '(("Directive"
3329 ["translate_on" vhdl-template-directive-translate-on t]
3330 ["translate_off" vhdl-template-directive-translate-off t]
3331 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3332 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3333 "--"
3334 ["Insert Directive..." vhdl-template-insert-directive
3335 :keys "C-c C-i C-d"])
3336 "--"
3337 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3338 ["Insert Footer" vhdl-template-footer t]
3339 ["Insert Date" vhdl-template-insert-date t]
3340 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3341 "--"
3342 ["Query Next Prompt" vhdl-template-search-prompt t]))
3343 ,(append
3344 '("Model")
3345 ;; add menu entries for defined models
3346 (let ((model-alist vhdl-model-alist) menu-list model)
3347 (while model-alist
3348 (setq model (car model-alist))
3349 (setq menu-list
3350 (cons
3351 (vector
3352 (nth 0 model)
3353 (vhdl-function-name "vhdl-model" (nth 0 model))
3354 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3355 menu-list))
3356 (setq model-alist (cdr model-alist)))
3357 (setq menu-list (nreverse menu-list))
3358 (vhdl-menu-split menu-list "Model"))
3359 '("--" "--"
3360 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3361 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3362 ("Port"
3363 ["Copy" vhdl-port-copy t]
3364 "--"
3365 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3366 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3367 ["Paste As Instance" vhdl-port-paste-instance
3368 :keys "C-c C-p C-i" :active vhdl-port-list]
3369 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3370 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3371 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3372 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3373 "--"
3374 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3375 "--"
3376 ["Flatten" vhdl-port-flatten
3377 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3378 ["Reverse Direction" vhdl-port-reverse-direction
3379 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3380 ("Compose"
3381 ["New Component" vhdl-compose-new-component t]
3382 ["Copy Component" vhdl-port-copy t]
3383 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3384 ["Wire Components" vhdl-compose-wire-components t]
3385 "--"
3386 ["Generate Configuration" vhdl-compose-configuration t]
3387 ["Generate Components Package" vhdl-compose-components-package t])
3388 ("Subprogram"
3389 ["Copy" vhdl-subprog-copy t]
3390 "--"
3391 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3392 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3393 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3394 "--"
3395 ["Flatten" vhdl-subprog-flatten
3396 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3397 "--"
3398 ("Comment"
3399 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3400 "--"
3401 ["Insert Inline Comment" vhdl-comment-append-inline t]
3402 ["Insert Horizontal Line" vhdl-comment-display-line t]
3403 ["Insert Display Comment" vhdl-comment-display t]
3404 "--"
3405 ["Fill Comment" fill-paragraph t]
3406 ["Fill Comment Region" fill-region (mark)]
3407 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3408 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3409 ("Line"
3410 ["Kill" vhdl-line-kill t]
3411 ["Copy" vhdl-line-copy t]
3412 ["Yank" vhdl-line-yank t]
3413 ["Expand" vhdl-line-expand t]
3414 "--"
3415 ["Transpose Next" vhdl-line-transpose-next t]
3416 ["Transpose Prev" vhdl-line-transpose-previous t]
3417 ["Open" vhdl-line-open t]
3418 ["Join" vhdl-delete-indentation t]
3419 "--"
3420 ["Goto" goto-line t]
3421 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3422 ("Move"
3423 ["Forward Statement" vhdl-end-of-statement t]
3424 ["Backward Statement" vhdl-beginning-of-statement t]
3425 ["Forward Expression" vhdl-forward-sexp t]
3426 ["Backward Expression" vhdl-backward-sexp t]
3427 ["Forward Same Indent" vhdl-forward-same-indent t]
3428 ["Backward Same Indent" vhdl-backward-same-indent t]
3429 ["Forward Function" vhdl-end-of-defun t]
3430 ["Backward Function" vhdl-beginning-of-defun t]
3431 ["Mark Function" vhdl-mark-defun t])
3432 "--"
3433 ("Indent"
3434 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3435 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3436 ["Region" vhdl-indent-region (mark)]
3437 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3438 ("Align"
3439 ["Group" vhdl-align-group t]
3440 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3441 ["List" vhdl-align-list t]
3442 ["Declarations" vhdl-align-declarations t]
3443 ["Region" vhdl-align-region (mark)]
3444 ["Buffer" vhdl-align-buffer t]
3445 "--"
3446 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3447 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3448 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3449 ("Fill"
3450 ["List" vhdl-fill-list t]
3451 ["Group" vhdl-fill-group t]
3452 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3453 ["Region" vhdl-fill-region (mark)])
3454 ("Beautify"
3455 ["Region" vhdl-beautify-region (mark)]
3456 ["Buffer" vhdl-beautify-buffer t])
3457 ("Fix"
3458 ["Generic/Port Clause" vhdl-fix-clause t]
3459 "--"
3460 ["Case Region" vhdl-fix-case-region (mark)]
3461 ["Case Buffer" vhdl-fix-case-buffer t]
3462 "--"
3463 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3464 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3465 "--"
3466 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3467 ("Update"
3468 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3469 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3470 "--"
3471 ["Fontify Buffer" vhdl-fontify-buffer t]
3472 ["Statistics Buffer" vhdl-statistics-buffer t]
3473 ["Show Messages" vhdl-show-messages t]
3474 ["Syntactic Info" vhdl-show-syntactic-information t]
3475 "--"
3476 ["Speedbar" vhdl-speedbar t]
3477 ["Hide/Show" vhdl-hs-minor-mode t]
3478 "--"
3479 ("Documentation"
3480 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3481 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3482 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3483 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3484 ["Version" vhdl-version t]
3485 ["Bug Report..." vhdl-submit-bug-report t]
3486 "--"
3487 ("Options"
3488 ("Mode"
3489 ["Electric Mode"
3490 (progn (customize-set-variable 'vhdl-electric-mode
3491 (not vhdl-electric-mode))
3492 (vhdl-mode-line-update))
3493 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3494 ["Stutter Mode"
3495 (progn (customize-set-variable 'vhdl-stutter-mode
3496 (not vhdl-stutter-mode))
3497 (vhdl-mode-line-update))
3498 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3499 ["Indent Tabs Mode"
3500 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3501 (not vhdl-indent-tabs-mode))
3502 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3503 :style toggle :selected vhdl-indent-tabs-mode]
3504 "--"
3505 ["Customize Group..." (customize-group 'vhdl-mode) t])
3506 ("Project"
3507 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3508 ,(append
3509 '("Selected Project at Startup"
3510 ["None" (progn (customize-set-variable 'vhdl-project nil)
3511 (vhdl-set-project ""))
3512 :style radio :selected (null vhdl-project)]
3513 "--")
3514 ;; add menu entries for defined projects
3515 (let ((project-alist vhdl-project-alist) menu-list name)
3516 (while project-alist
3517 (setq name (caar project-alist))
3518 (setq menu-list
3519 (cons `[,name (progn (customize-set-variable
3520 'vhdl-project ,name)
3521 (vhdl-set-project ,name))
3522 :style radio :selected (equal ,name vhdl-project)]
3523 menu-list))
3524 (setq project-alist (cdr project-alist)))
3525 (setq menu-list (nreverse menu-list))
3526 (vhdl-menu-split menu-list "Project")))
3527 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3528 ("Auto Load Setup File"
3529 ["At Startup"
3530 (customize-set-variable 'vhdl-project-auto-load
3531 (if (memq 'startup vhdl-project-auto-load)
3532 (delq 'startup vhdl-project-auto-load)
3533 (cons 'startup vhdl-project-auto-load)))
3534 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3535 ["Sort Projects"
3536 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3537 :style toggle :selected vhdl-project-sort]
3538 "--"
3539 ["Customize Group..." (customize-group 'vhdl-project) t])
3540 ("Compiler"
3541 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3542 ,(append
3543 '("Selected Compiler at Startup")
3544 ;; add menu entries for defined compilers
3545 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3546 (while comp-alist
3547 (setq name (caar comp-alist))
3548 (setq menu-list
3549 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3550 :style radio :selected (equal ,name vhdl-compiler)]
3551 menu-list))
3552 (setq comp-alist (cdr comp-alist)))
3553 (setq menu-list (nreverse menu-list))
3554 (vhdl-menu-split menu-list "Compler")))
3555 ["Use Local Error Regexp"
3556 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3557 (not vhdl-compile-use-local-error-regexp))
3558 :style toggle :selected vhdl-compile-use-local-error-regexp]
3559 ["Makefile Generation Hook..."
3560 (customize-option 'vhdl-makefile-generation-hook) t]
3561 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3562 "--"
3563 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3564 ("Style"
3565 ("VHDL Standard"
3566 ["VHDL'87"
3567 (progn (customize-set-variable 'vhdl-standard
3568 (list '87 (cadr vhdl-standard)))
3569 (vhdl-activate-customizations))
3570 :style radio :selected (eq '87 (car vhdl-standard))]
3571 ["VHDL'93"
3572 (progn (customize-set-variable 'vhdl-standard
3573 (list '93 (cadr vhdl-standard)))
3574 (vhdl-activate-customizations))
3575 :style radio :selected (eq '93 (car vhdl-standard))]
3576 "--"
3577 ["VHDL-AMS"
3578 (progn (customize-set-variable
3579 'vhdl-standard (list (car vhdl-standard)
3580 (if (memq 'ams (cadr vhdl-standard))
3581 (delq 'ams (cadr vhdl-standard))
3582 (cons 'ams (cadr vhdl-standard)))))
3583 (vhdl-activate-customizations))
3584 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3585 ["Math Packages"
3586 (progn (customize-set-variable
3587 'vhdl-standard (list (car vhdl-standard)
3588 (if (memq 'math (cadr vhdl-standard))
3589 (delq 'math (cadr vhdl-standard))
3590 (cons 'math (cadr vhdl-standard)))))
3591 (vhdl-activate-customizations))
3592 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3593 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3594 ["Upper Case Keywords"
3595 (customize-set-variable 'vhdl-upper-case-keywords
3596 (not vhdl-upper-case-keywords))
3597 :style toggle :selected vhdl-upper-case-keywords]
3598 ["Upper Case Types"
3599 (customize-set-variable 'vhdl-upper-case-types
3600 (not vhdl-upper-case-types))
3601 :style toggle :selected vhdl-upper-case-types]
3602 ["Upper Case Attributes"
3603 (customize-set-variable 'vhdl-upper-case-attributes
3604 (not vhdl-upper-case-attributes))
3605 :style toggle :selected vhdl-upper-case-attributes]
3606 ["Upper Case Enumeration Values"
3607 (customize-set-variable 'vhdl-upper-case-enum-values
3608 (not vhdl-upper-case-enum-values))
3609 :style toggle :selected vhdl-upper-case-enum-values]
3610 ["Upper Case Constants"
3611 (customize-set-variable 'vhdl-upper-case-constants
3612 (not vhdl-upper-case-constants))
3613 :style toggle :selected vhdl-upper-case-constants]
3614 ("Use Direct Instantiation"
3615 ["Never"
3616 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3617 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3618 ["Standard"
3619 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3620 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3621 ["Always"
3622 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3623 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3624 "--"
3625 ["Customize Group..." (customize-group 'vhdl-style) t])
3626 ("Naming"
3627 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3628 ["Architecture File Name..."
3629 (customize-option 'vhdl-architecture-file-name) t]
3630 ["Configuration File Name..."
3631 (customize-option 'vhdl-configuration-file-name) t]
3632 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3633 ("File Name Case"
3634 ["As Is"
3635 (customize-set-variable 'vhdl-file-name-case 'identity)
3636 :style radio :selected (eq 'identity vhdl-file-name-case)]
3637 ["Lower Case"
3638 (customize-set-variable 'vhdl-file-name-case 'downcase)
3639 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3640 ["Upper Case"
3641 (customize-set-variable 'vhdl-file-name-case 'upcase)
3642 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3643 ["Capitalize"
3644 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3645 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3646 "--"
3647 ["Customize Group..." (customize-group 'vhdl-naming) t])
3648 ("Template"
3649 ("Electric Keywords"
3650 ["VHDL Keywords"
3651 (customize-set-variable 'vhdl-electric-keywords
3652 (if (memq 'vhdl vhdl-electric-keywords)
3653 (delq 'vhdl vhdl-electric-keywords)
3654 (cons 'vhdl vhdl-electric-keywords)))
3655 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3656 ["User Model Keywords"
3657 (customize-set-variable 'vhdl-electric-keywords
3658 (if (memq 'user vhdl-electric-keywords)
3659 (delq 'user vhdl-electric-keywords)
3660 (cons 'user vhdl-electric-keywords)))
3661 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3662 ("Insert Optional Labels"
3663 ["None"
3664 (customize-set-variable 'vhdl-optional-labels 'none)
3665 :style radio :selected (eq 'none vhdl-optional-labels)]
3666 ["Processes Only"
3667 (customize-set-variable 'vhdl-optional-labels 'process)
3668 :style radio :selected (eq 'process vhdl-optional-labels)]
3669 ["All Constructs"
3670 (customize-set-variable 'vhdl-optional-labels 'all)
3671 :style radio :selected (eq 'all vhdl-optional-labels)])
3672 ("Insert Empty Lines"
3673 ["None"
3674 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3675 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3676 ["Design Units Only"
3677 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3678 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3679 ["All Constructs"
3680 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3681 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3682 ["Argument List Indent"
3683 (customize-set-variable 'vhdl-argument-list-indent
3684 (not vhdl-argument-list-indent))
3685 :style toggle :selected vhdl-argument-list-indent]
3686 ["Association List with Formals"
3687 (customize-set-variable 'vhdl-association-list-with-formals
3688 (not vhdl-association-list-with-formals))
3689 :style toggle :selected vhdl-association-list-with-formals]
3690 ["Conditions in Parenthesis"
3691 (customize-set-variable 'vhdl-conditions-in-parenthesis
3692 (not vhdl-conditions-in-parenthesis))
3693 :style toggle :selected vhdl-conditions-in-parenthesis]
3694 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3695 ["One String..." (customize-option 'vhdl-one-string) t]
3696 ("File Header"
3697 ["Header String..." (customize-option 'vhdl-file-header) t]
3698 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3699 ["Company Name..." (customize-option 'vhdl-company-name) t]
3700 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3701 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3702 ["Date Format..." (customize-option 'vhdl-date-format) t]
3703 ["Modify Date Prefix String..."
3704 (customize-option 'vhdl-modify-date-prefix-string) t]
3705 ["Modify Date on Saving"
3706 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3707 (not vhdl-modify-date-on-saving))
3708 (vhdl-activate-customizations))
3709 :style toggle :selected vhdl-modify-date-on-saving])
3710 ("Sequential Process"
3711 ("Kind of Reset"
3712 ["None"
3713 (customize-set-variable 'vhdl-reset-kind 'none)
3714 :style radio :selected (eq 'none vhdl-reset-kind)]
3715 ["Synchronous"
3716 (customize-set-variable 'vhdl-reset-kind 'sync)
3717 :style radio :selected (eq 'sync vhdl-reset-kind)]
3718 ["Asynchronous"
3719 (customize-set-variable 'vhdl-reset-kind 'async)
3720 :style radio :selected (eq 'async vhdl-reset-kind)])
3721 ["Reset is Active High"
3722 (customize-set-variable 'vhdl-reset-active-high
3723 (not vhdl-reset-active-high))
3724 :style toggle :selected vhdl-reset-active-high]
3725 ["Use Rising Clock Edge"
3726 (customize-set-variable 'vhdl-clock-rising-edge
3727 (not vhdl-clock-rising-edge))
3728 :style toggle :selected vhdl-clock-rising-edge]
3729 ("Clock Edge Condition"
3730 ["Standard"
3731 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3732 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3733 ["Function \"rising_edge\""
3734 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3735 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3736 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3737 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3738 "--"
3739 ["Customize Group..." (customize-group 'vhdl-template) t])
3740 ("Model"
3741 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3742 ("Port"
3743 ["Include Port Comments"
3744 (customize-set-variable 'vhdl-include-port-comments
3745 (not vhdl-include-port-comments))
3746 :style toggle :selected vhdl-include-port-comments]
3747 ["Include Direction Comments"
3748 (customize-set-variable 'vhdl-include-direction-comments
3749 (not vhdl-include-direction-comments))
3750 :style toggle :selected vhdl-include-direction-comments]
3751 ["Include Type Comments"
3752 (customize-set-variable 'vhdl-include-type-comments
3753 (not vhdl-include-type-comments))
3754 :style toggle :selected vhdl-include-type-comments]
3755 ("Include Group Comments"
3756 ["Never"
3757 (customize-set-variable 'vhdl-include-group-comments 'never)
3758 :style radio :selected (eq 'never vhdl-include-group-comments)]
3759 ["Declarations"
3760 (customize-set-variable 'vhdl-include-group-comments 'decl)
3761 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3762 ["Always"
3763 (customize-set-variable 'vhdl-include-group-comments 'always)
3764 :style radio :selected (eq 'always vhdl-include-group-comments)])
3765 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3766 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3767 ("Testbench"
3768 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3769 ["Architecture Name..."
3770 (customize-option 'vhdl-testbench-architecture-name) t]
3771 ["Configuration Name..."
3772 (customize-option 'vhdl-testbench-configuration-name) t]
3773 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3774 ["Include Header"
3775 (customize-set-variable 'vhdl-testbench-include-header
3776 (not vhdl-testbench-include-header))
3777 :style toggle :selected vhdl-testbench-include-header]
3778 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3779 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3780 ["Initialize Signals"
3781 (customize-set-variable 'vhdl-testbench-initialize-signals
3782 (not vhdl-testbench-initialize-signals))
3783 :style toggle :selected vhdl-testbench-initialize-signals]
3784 ["Include Library Clause"
3785 (customize-set-variable 'vhdl-testbench-include-library
3786 (not vhdl-testbench-include-library))
3787 :style toggle :selected vhdl-testbench-include-library]
3788 ["Include Configuration"
3789 (customize-set-variable 'vhdl-testbench-include-configuration
3790 (not vhdl-testbench-include-configuration))
3791 :style toggle :selected vhdl-testbench-include-configuration]
3792 ("Create Files"
3793 ["None"
3794 (customize-set-variable 'vhdl-testbench-create-files 'none)
3795 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3796 ["Single"
3797 (customize-set-variable 'vhdl-testbench-create-files 'single)
3798 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3799 ["Separate"
3800 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3801 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3802 ["Testbench Entity File Name..."
3803 (customize-option 'vhdl-testbench-entity-file-name) t]
3804 ["Testbench Architecture File Name..."
3805 (customize-option 'vhdl-testbench-architecture-file-name) t])
3806 "--"
3807 ["Customize Group..." (customize-group 'vhdl-port) t])
3808 ("Compose"
3809 ["Architecture Name..."
3810 (customize-option 'vhdl-compose-architecture-name) t]
3811 ["Configuration Name..."
3812 (customize-option 'vhdl-compose-configuration-name) t]
3813 ["Components Package Name..."
3814 (customize-option 'vhdl-components-package-name) t]
3815 ["Use Components Package"
3816 (customize-set-variable 'vhdl-use-components-package
3817 (not vhdl-use-components-package))
3818 :style toggle :selected vhdl-use-components-package]
3819 ["Include Header"
3820 (customize-set-variable 'vhdl-compose-include-header
3821 (not vhdl-compose-include-header))
3822 :style toggle :selected vhdl-compose-include-header]
3823 ("Create Entity/Architecture Files"
3824 ["None"
3825 (customize-set-variable 'vhdl-compose-create-files 'none)
3826 :style radio :selected (eq 'none vhdl-compose-create-files)]
3827 ["Single"
3828 (customize-set-variable 'vhdl-compose-create-files 'single)
3829 :style radio :selected (eq 'single vhdl-compose-create-files)]
3830 ["Separate"
3831 (customize-set-variable 'vhdl-compose-create-files 'separate)
3832 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3833 ["Create Configuration File"
3834 (customize-set-variable 'vhdl-compose-configuration-create-file
3835 (not vhdl-compose-configuration-create-file))
3836 :style toggle :selected vhdl-compose-configuration-create-file]
3837 ["Hierarchical Configuration"
3838 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3839 (not vhdl-compose-configuration-hierarchical))
3840 :style toggle :selected vhdl-compose-configuration-hierarchical]
3841 ["Use Subconfiguration"
3842 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3843 (not vhdl-compose-configuration-use-subconfiguration))
3844 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3845 "--"
3846 ["Customize Group..." (customize-group 'vhdl-compose) t])
3847 ("Comment"
3848 ["Self Insert Comments"
3849 (customize-set-variable 'vhdl-self-insert-comments
3850 (not vhdl-self-insert-comments))
3851 :style toggle :selected vhdl-self-insert-comments]
3852 ["Prompt for Comments"
3853 (customize-set-variable 'vhdl-prompt-for-comments
3854 (not vhdl-prompt-for-comments))
3855 :style toggle :selected vhdl-prompt-for-comments]
3856 ["Inline Comment Column..."
3857 (customize-option 'vhdl-inline-comment-column) t]
3858 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3859 "--"
3860 ["Customize Group..." (customize-group 'vhdl-comment) t])
3861 ("Align"
3862 ["Auto Align Templates"
3863 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3864 :style toggle :selected vhdl-auto-align]
3865 ["Align Line Groups"
3866 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3867 :style toggle :selected vhdl-align-groups]
3868 ["Group Separation String..."
3869 (customize-set-variable 'vhdl-align-group-separate) t]
3870 ["Align Lines with Same Indent"
3871 (customize-set-variable 'vhdl-align-same-indent
3872 (not vhdl-align-same-indent))
3873 :style toggle :selected vhdl-align-same-indent]
3874 "--"
3875 ["Customize Group..." (customize-group 'vhdl-align) t])
3876 ("Highlight"
3877 ["Highlighting On/Off..."
3878 (customize-option
3879 (if (fboundp 'global-font-lock-mode)
3880 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3881 ["Highlight Keywords"
3882 (progn (customize-set-variable 'vhdl-highlight-keywords
3883 (not vhdl-highlight-keywords))
3884 (vhdl-fontify-buffer))
3885 :style toggle :selected vhdl-highlight-keywords]
3886 ["Highlight Names"
3887 (progn (customize-set-variable 'vhdl-highlight-names
3888 (not vhdl-highlight-names))
3889 (vhdl-fontify-buffer))
3890 :style toggle :selected vhdl-highlight-names]
3891 ["Highlight Special Words"
3892 (progn (customize-set-variable 'vhdl-highlight-special-words
3893 (not vhdl-highlight-special-words))
3894 (vhdl-fontify-buffer))
3895 :style toggle :selected vhdl-highlight-special-words]
3896 ["Highlight Forbidden Words"
3897 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3898 (not vhdl-highlight-forbidden-words))
3899 (vhdl-fontify-buffer))
3900 :style toggle :selected vhdl-highlight-forbidden-words]
3901 ["Highlight Verilog Keywords"
3902 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3903 (not vhdl-highlight-verilog-keywords))
3904 (vhdl-fontify-buffer))
3905 :style toggle :selected vhdl-highlight-verilog-keywords]
3906 ["Highlight \"translate_off\""
3907 (progn (customize-set-variable 'vhdl-highlight-translate-off
3908 (not vhdl-highlight-translate-off))
3909 (vhdl-fontify-buffer))
3910 :style toggle :selected vhdl-highlight-translate-off]
3911 ["Case Sensitive Highlighting"
3912 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3913 (not vhdl-highlight-case-sensitive))
3914 (vhdl-fontify-buffer))
3915 :style toggle :selected vhdl-highlight-case-sensitive]
3916 ["Special Syntax Definition..."
3917 (customize-option 'vhdl-special-syntax-alist) t]
3918 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3919 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3920 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3921 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3922 "--"
3923 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3924 ("Speedbar"
3925 ["Auto Open at Startup"
3926 (customize-set-variable 'vhdl-speedbar-auto-open
3927 (not vhdl-speedbar-auto-open))
3928 :style toggle :selected vhdl-speedbar-auto-open]
3929 ("Default Displaying Mode"
3930 ["Files"
3931 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3932 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3933 ["Directory Hierarchy"
3934 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3935 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3936 ["Project Hierarchy"
3937 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3938 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3939 ["Indentation Offset..."
3940 (customize-option 'speedbar-indentation-width) t]
3941 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3942 ["Jump to Unit when Opening"
3943 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3944 (not vhdl-speedbar-jump-to-unit))
3945 :style toggle :selected vhdl-speedbar-jump-to-unit]
3946 ["Update Hierarchy on File Saving"
3947 (customize-set-variable 'vhdl-speedbar-update-on-saving
3948 (not vhdl-speedbar-update-on-saving))
3949 :style toggle :selected vhdl-speedbar-update-on-saving]
3950 ("Save in Cache File"
3951 ["Hierarchy Information"
3952 (customize-set-variable 'vhdl-speedbar-save-cache
3953 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3954 (delq 'hierarchy vhdl-speedbar-save-cache)
3955 (cons 'hierarchy vhdl-speedbar-save-cache)))
3956 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3957 ["Displaying Status"
3958 (customize-set-variable 'vhdl-speedbar-save-cache
3959 (if (memq 'display vhdl-speedbar-save-cache)
3960 (delq 'display vhdl-speedbar-save-cache)
3961 (cons 'display vhdl-speedbar-save-cache)))
3962 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3963 ["Cache File Name..."
3964 (customize-option 'vhdl-speedbar-cache-file-name) t]
3965 "--"
3966 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3967 ("Menu"
3968 ["Add Index Menu when Loading File"
3969 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3970 (vhdl-index-menu-init))
3971 :style toggle :selected vhdl-index-menu]
3972 ["Add Source File Menu when Loading File"
3973 (progn (customize-set-variable 'vhdl-source-file-menu
3974 (not vhdl-source-file-menu))
3975 (vhdl-add-source-files-menu))
3976 :style toggle :selected vhdl-source-file-menu]
3977 ["Add Hideshow Menu at Startup"
3978 (progn (customize-set-variable 'vhdl-hideshow-menu
3979 (not vhdl-hideshow-menu))
3980 (vhdl-activate-customizations))
3981 :style toggle :selected vhdl-hideshow-menu]
3982 ["Hide Everything Initially"
3983 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3984 :style toggle :selected vhdl-hide-all-init]
3985 "--"
3986 ["Customize Group..." (customize-group 'vhdl-menu) t])
3987 ("Print"
3988 ["In Two Column Format"
3989 (progn (customize-set-variable 'vhdl-print-two-column
3990 (not vhdl-print-two-column))
3991 (message "Activate new setting by saving options and restarting Emacs"))
3992 :style toggle :selected vhdl-print-two-column]
3993 ["Use Customized Faces"
3994 (progn (customize-set-variable 'vhdl-print-customize-faces
3995 (not vhdl-print-customize-faces))
3996 (message "Activate new setting by saving options and restarting Emacs"))
3997 :style toggle :selected vhdl-print-customize-faces]
3998 "--"
3999 ["Customize Group..." (customize-group 'vhdl-print) t])
4000 ("Miscellaneous"
4001 ["Use Intelligent Tab"
4002 (progn (customize-set-variable 'vhdl-intelligent-tab
4003 (not vhdl-intelligent-tab))
4004 (vhdl-activate-customizations))
4005 :style toggle :selected vhdl-intelligent-tab]
4006 ["Indent Syntax-Based"
4007 (customize-set-variable 'vhdl-indent-syntax-based
4008 (not vhdl-indent-syntax-based))
4009 :style toggle :selected vhdl-indent-syntax-based]
4010 ["Word Completion is Case Sensitive"
4011 (customize-set-variable 'vhdl-word-completion-case-sensitive
4012 (not vhdl-word-completion-case-sensitive))
4013 :style toggle :selected vhdl-word-completion-case-sensitive]
4014 ["Word Completion in Minibuffer"
4015 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4016 (not vhdl-word-completion-in-minibuffer))
4017 (message "Activate new setting by saving options and restarting Emacs"))
4018 :style toggle :selected vhdl-word-completion-in-minibuffer]
4019 ["Underscore is Part of Word"
4020 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4021 (not vhdl-underscore-is-part-of-word))
4022 (vhdl-activate-customizations))
4023 :style toggle :selected vhdl-underscore-is-part-of-word]
4024 "--"
4025 ["Customize Group..." (customize-group 'vhdl-misc) t])
4026 ["Related..." (customize-browse 'vhdl-related) t]
4027 "--"
4028 ["Save Options" customize-save-customized t]
4029 ["Activate Options" vhdl-activate-customizations t]
4030 ["Browse Options..." vhdl-customize t])))
4032 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4033 "VHDL Mode menu.")
4035 (defun vhdl-update-mode-menu ()
4036 "Update VHDL Mode menu."
4037 (interactive)
4038 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4039 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4040 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4041 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4042 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4045 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4047 (defconst vhdl-imenu-generic-expression
4049 ("Subprogram"
4050 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4052 ("Instance"
4053 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4055 ("Component"
4056 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4058 ("Procedural"
4059 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4061 ("Process"
4062 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4064 ("Block"
4065 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4067 ("Package"
4068 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4070 ("Configuration"
4071 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4073 ("Architecture"
4074 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4076 ("Entity"
4077 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4080 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4082 (defun vhdl-index-menu-init ()
4083 "Initialize index menu."
4084 (set (make-local-variable 'imenu-case-fold-search) t)
4085 (set (make-local-variable 'imenu-generic-expression)
4086 vhdl-imenu-generic-expression)
4087 (when (and vhdl-index-menu (fboundp 'imenu))
4088 (if (or (not (boundp 'font-lock-maximum-size))
4089 (> font-lock-maximum-size (buffer-size)))
4090 (imenu-add-to-menubar "Index")
4091 (message "Scanning buffer for index...buffer too big"))))
4093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4094 ;; Source file menu (using `easy-menu.el')
4096 (defvar vhdl-sources-menu nil)
4098 (defun vhdl-directory-files (directory &optional full match)
4099 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4100 message."
4101 (if (not (file-directory-p directory))
4102 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4103 (let ((dir (directory-files directory full match)))
4104 (setq dir (delete "." dir))
4105 (setq dir (delete ".." dir))
4106 dir)))
4108 (defun vhdl-get-source-files (&optional full directory)
4109 "Get list of VHDL source files in DIRECTORY or current directory."
4110 (let ((mode-alist auto-mode-alist)
4111 filename-regexp)
4112 ;; create regular expressions for matching file names
4113 (setq filename-regexp "\\`[^.].*\\(")
4114 (while mode-alist
4115 (when (eq (cdar mode-alist) 'vhdl-mode)
4116 (setq filename-regexp
4117 (concat filename-regexp (caar mode-alist) "\\|")))
4118 (setq mode-alist (cdr mode-alist)))
4119 (setq filename-regexp
4120 (concat (substring filename-regexp 0
4121 (string-match "\\\\|$" filename-regexp)) "\\)"))
4122 ;; find files
4123 (vhdl-directory-files
4124 (or directory default-directory) full filename-regexp)))
4126 (defun vhdl-add-source-files-menu ()
4127 "Scan directory for all VHDL source files and generate menu.
4128 The directory of the current source file is scanned."
4129 (interactive)
4130 (message "Scanning directory for source files ...")
4131 (let ((newmap (current-local-map))
4132 (file-list (vhdl-get-source-files))
4133 menu-list found)
4134 ;; Create list for menu
4135 (setq found nil)
4136 (while file-list
4137 (setq found t)
4138 (setq menu-list (cons (vector (car file-list)
4139 (list 'find-file (car file-list)) t)
4140 menu-list))
4141 (setq file-list (cdr file-list)))
4142 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4143 (when found (setq menu-list (cons "--" menu-list)))
4144 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4145 (setq menu-list (cons "Sources" menu-list))
4146 ;; Create menu
4147 (easy-menu-add menu-list)
4148 (easy-menu-define vhdl-sources-menu newmap
4149 "VHDL source files menu" menu-list))
4150 (message ""))
4153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4154 ;;; Mode definition
4155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4156 ;; performs all buffer local initializations
4158 ;;;###autoload
4159 (defun vhdl-mode ()
4160 "Major mode for editing VHDL code.
4162 Usage:
4163 ------
4165 TEMPLATE INSERTION (electrification):
4166 After typing a VHDL keyword and entering `SPC', you are prompted for
4167 arguments while a template is generated for that VHDL construct. Typing
4168 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4169 template generation. Optional arguments are indicated by square
4170 brackets and removed if the queried string is left empty. Prompts for
4171 mandatory arguments remain in the code if the queried string is left
4172 empty. They can be queried again by `C-c C-t C-q'. Enabled
4173 electrification is indicated by `/e' in the modeline.
4175 Typing `M-SPC' after a keyword inserts a space without calling the
4176 template generator. Automatic template generation (i.e.
4177 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4178 setting option `vhdl-electric-mode' (see OPTIONS).
4180 Template generators can be invoked from the VHDL menu, by key
4181 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4182 the keyword (i.e. first word of menu entry not in parenthesis) and
4183 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4184 conf, comp, cons, func, inst, pack, sig, var.
4186 Template styles can be customized in customization group
4187 `vhdl-template' \(see OPTIONS).
4190 HEADER INSERTION:
4191 A file header can be inserted by `C-c C-t C-h'. A file footer
4192 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4193 See customization group `vhdl-header'.
4196 STUTTERING:
4197 Double striking of some keys inserts cumbersome VHDL syntax elements.
4198 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4199 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4200 the modeline. The stuttering keys and their effects are:
4202 ;; --> \" : \" [ --> ( -- --> comment
4203 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4204 .. --> \" => \" ] --> ) --- --> horizontal line
4205 ,, --> \" <= \" ]] --> ] ---- --> display comment
4206 == --> \" == \" '' --> \\\"
4209 WORD COMPLETION:
4210 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4211 word in the buffer that starts alike, inserts it and adjusts case.
4212 Re-typing `TAB' toggles through alternative word completions. This also
4213 works in the minibuffer (i.e. in template generator prompts).
4215 Typing `TAB' after `(' looks for and inserts complete parenthesized
4216 expressions (e.g. for array index ranges). All keywords as well as
4217 standard types and subprograms of VHDL have predefined abbreviations
4218 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4219 beginning with \"std\").
4221 Typing `TAB' after a non-word character indents the line if at the
4222 beginning of a line (i.e. no preceding non-blank characters), and
4223 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4224 stop.
4227 COMMENTS:
4228 `--' puts a single comment.
4229 `---' draws a horizontal line for separating code segments.
4230 `----' inserts a display comment, i.e. two horizontal lines
4231 with a comment in between.
4232 `--CR' comments out code on that line. Re-hitting CR comments
4233 out following lines.
4234 `C-c c' comments out a region if not commented out,
4235 uncomments a region if already commented out.
4237 You are prompted for comments after object definitions (i.e. signals,
4238 variables, constants, ports) and after subprogram and process
4239 specifications if option `vhdl-prompt-for-comments' is non-nil.
4240 Comments are automatically inserted as additional labels (e.g. after
4241 begin statements) and as help comments if `vhdl-self-insert-comments' is
4242 non-nil.
4244 Inline comments (i.e. comments after a piece of code on the same line)
4245 are indented at least to `vhdl-inline-comment-column'. Comments go at
4246 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4247 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4248 in a comment automatically opens a new comment line. `M-q' re-fills
4249 multi-line comments.
4252 INDENTATION:
4253 `TAB' indents a line if at the beginning of the line. The amount of
4254 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4255 always indents the current line (is bound to `TAB' if option
4256 `vhdl-intelligent-tab' is nil).
4258 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4259 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4260 indented normally (nil) or relative to the opening parenthesis (non-nil)
4261 according to option `vhdl-argument-list-indent'.
4263 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4264 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4265 and vice versa.
4267 Syntax-based indentation can be very slow in large files. Option
4268 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4271 ALIGNMENT:
4272 The alignment functions align operators, keywords, and inline comments
4273 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4274 separated by blank lines, `C-c C-a C-i' a block of lines with same
4275 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4276 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4277 C-a C-d' all lines within the declarative part of a design unit. `C-c
4278 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4279 for a group of lines, and `C-c C-a M-c' for a region.
4281 If option `vhdl-align-groups' is non-nil, groups of code lines
4282 separated by special lines (see option `vhdl-align-group-separate') are
4283 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4284 blocks of lines with same indent are aligned separately. Some templates
4285 are automatically aligned after generation if option `vhdl-auto-align'
4286 is non-nil.
4288 Alignment tries to align inline comments at
4289 `vhdl-inline-comment-column' and tries inline comment not to exceed
4290 `vhdl-end-comment-column'.
4292 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4293 symbols are surrounded by one space, and multiple spaces are eliminated.
4296 CODE FILLING:
4297 Code filling allows to condense code (e.g. sensitivity lists or port
4298 maps) by removing comments and newlines and re-wrapping so that all
4299 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4300 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4301 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4302 `C-c C-f M-f' an entire region.
4305 CODE BEAUTIFICATION:
4306 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4307 buffer respectively. This inludes indentation, alignment, and case
4308 fixing. Code beautification can also be run non-interactively using the
4309 command:
4311 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4314 PORT TRANSLATION:
4315 Generic and port clauses from entity or component declarations can be
4316 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4317 as component instantiations and corresponding internal constants and
4318 signals, as a generic map with constants as actual generics, and as
4319 internal signal initializations (menu).
4321 To include formals in component instantiations, see option
4322 `vhdl-association-list-with-formals'. To include comments in pasting,
4323 see options `vhdl-include-...-comments'.
4325 A clause with several generic/port names on the same line can be
4326 flattened (`C-c C-p C-f') so that only one name per line exists. The
4327 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4328 outputs and vice versa, which can be useful in testbenches. (This
4329 reversion is done on the internal data structure and is only reflected
4330 in subsequent paste operations.)
4332 Names for actual ports, instances, testbenches, and
4333 design-under-test instances can be derived from existing names according
4334 to options `vhdl-...-name'. See customization group `vhdl-port'.
4337 SUBPROGRAM TRANSLATION:
4338 Similar functionality exists for copying/pasting the interface of
4339 subprograms (function/procedure). A subprogram interface can be copied
4340 and then pasted as a subprogram declaration, body or call (uses
4341 association list with formals).
4344 TESTBENCH GENERATION:
4345 A copied port can also be pasted as a testbench. The generated
4346 testbench includes an entity, an architecture, and an optional
4347 configuration. The architecture contains the component declaration and
4348 instantiation of the DUT as well as internal constant and signal
4349 declarations. Additional user-defined templates can be inserted. The
4350 names used for entity/architecture/configuration/DUT as well as the file
4351 structure to be generated can be customized. See customization group
4352 `vhdl-testbench'.
4355 KEY BINDINGS:
4356 Key bindings (`C-c ...') exist for most commands (see in menu).
4359 VHDL MENU:
4360 All commands can be found in the VHDL menu including their key bindings.
4363 FILE BROWSER:
4364 The speedbar allows browsing of directories and file contents. It can
4365 be accessed from the VHDL menu and is automatically opened if option
4366 `vhdl-speedbar-auto-open' is non-nil.
4368 In speedbar, open files and directories with `mouse-2' on the name and
4369 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4372 DESIGN HIERARCHY BROWSER:
4373 The speedbar can also be used for browsing the hierarchy of design units
4374 contained in the source files of the current directory or the specified
4375 projects (see option `vhdl-project-alist').
4377 The speedbar can be switched between file, directory hierarchy and
4378 project hierarchy browsing mode in the speedbar menu or by typing `f',
4379 `h' or `H' in speedbar.
4381 In speedbar, open design units with `mouse-2' on the name and browse
4382 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4383 from entities and components (in packages). Individual design units and
4384 complete designs can directly be compiled (\"Make\" menu entry).
4386 The hierarchy is automatically updated upon saving a modified source
4387 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4388 hierarchy is only updated for projects that have been opened once in the
4389 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4390 options in group `vhdl-speedbar').
4392 Simple design consistency checks are done during scanning, such as
4393 multiple declarations of the same unit or missing primary units that are
4394 required by secondary units.
4397 STRUCTURAL COMPOSITION:
4398 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4399 for a new component. Subcomponents (i.e. component declaration and
4400 instantiation) can be automatically placed from a previously read port
4401 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4402 all subcomponents can be automatically connected using internal signals
4403 and ports (`C-c C-c C-w') following these rules:
4404 - subcomponent actual ports with same name are considered to be
4405 connected by a signal (internal signal or port)
4406 - signals that are only inputs to subcomponents are considered as
4407 inputs to this component -> input port created
4408 - signals that are only outputs from subcomponents are considered as
4409 outputs from this component -> output port created
4410 - signals that are inputs to AND outputs from subcomponents are
4411 considered as internal connections -> internal signal created
4413 Purpose: With appropriate naming conventions it is possible to
4414 create higher design levels with only a few mouse clicks or key
4415 strokes. A new design level can be created by simply generating a new
4416 component, placing the required subcomponents from the hierarchy
4417 browser, and wiring everything automatically.
4419 Note: Automatic wiring only works reliably on templates of new
4420 components and component instantiations that were created by VHDL mode.
4422 Component declarations can be placed in a components package (option
4423 `vhdl-use-components-package') which can be automatically generated for
4424 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4425 component instantiation is also supported (option
4426 `vhdl-use-direct-instantiation').
4428 | Configuration declarations can automatically be generated either from
4429 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4430 | the speedbar menu (for the architecture under the cursor). The
4431 | configurations can optionally be hierarchical (i.e. include all
4432 | component levels of a hierarchical design, option
4433 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4434 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4435 | subcomponents in hierarchical configurations, the most-recently-analyzed
4436 | (mra) architecture is selected. If another architecture is desired, it
4437 | can be marked as most-recently-analyzed (speedbar menu) before
4438 | generating the configuration.
4440 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4441 | declarations) are currently not considered when displaying
4442 | configurations in speedbar.
4444 See the options group `vhdl-compose' for all relevant user options.
4447 SOURCE FILE COMPILATION:
4448 The syntax of the current buffer can be analyzed by calling a VHDL
4449 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4450 option `vhdl-compiler'. The available compilers are listed in option
4451 `vhdl-compiler-alist' including all required compilation command,
4452 command options, compilation directory, and error message syntax
4453 information. New compilers can be added.
4455 All the source files of an entire design can be compiled by the `make'
4456 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4459 MAKEFILE GENERATION:
4460 Makefiles can be generated automatically by an internal generation
4461 routine (`C-c M-k'). The library unit dependency information is
4462 obtained from the hierarchy browser. Makefile generation can be
4463 customized for each compiler in option `vhdl-compiler-alist'.
4465 Makefile generation can also be run non-interactively using the
4466 command:
4468 emacs -batch -l ~/.emacs -l vhdl-mode
4469 [-compiler compilername] [-project projectname]
4470 -f vhdl-generate-makefile
4472 The Makefile's default target \"all\" compiles the entire design, the
4473 target \"clean\" removes it and the target \"library\" creates the
4474 library directory if not existent. The Makefile also includes a target
4475 for each primary library unit which allows selective compilation of this
4476 unit, its secondary units and its subhierarchy (example: compilation of
4477 a design specified by a configuration). User specific parts can be
4478 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4480 Limitations:
4481 - Only library units and dependencies within the current library are
4482 considered. Makefiles for designs that span multiple libraries are
4483 not (yet) supported.
4484 - Only one-level configurations are supported (also hierarchical),
4485 but configurations that go down several levels are not.
4486 - The \"others\" keyword in configurations is not supported.
4489 PROJECTS:
4490 Projects can be defined in option `vhdl-project-alist' and a current
4491 project be selected using option `vhdl-project' (permanently) or from
4492 the menu or speedbar (temporarily). For each project, title and
4493 description strings (for the file headers), source files/directories
4494 (for the hierarchy browser and Makefile generation), library name, and
4495 compiler-dependent options, exceptions and compilation directory can be
4496 specified. Compilation settings overwrite the settings of option
4497 `vhdl-compiler-alist'.
4499 Project setups can be exported (i.e. written to a file) and imported.
4500 Imported setups are not automatically saved in `vhdl-project-alist' but
4501 can be saved afterwards in its customization buffer. When starting
4502 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4503 vhdl-mode\") in a directory with an existing project setup file, it is
4504 automatically loaded and its project activated if option
4505 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4506 files can be specified in option `vhdl-project-file-name'. Multiple
4507 project setups can be automatically loaded from global directories.
4508 This is an alternative to specifying project setups with option
4509 `vhdl-project-alist'.
4512 SPECIAL MENUES:
4513 As an alternative to the speedbar, an index menu can be added (set
4514 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4515 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4516 file) for browsing the file contents (is not populated if buffer is
4517 larger than `font-lock-maximum-size'). Also, a source file menu can be
4518 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4519 current directory for VHDL source files.
4522 VHDL STANDARDS:
4523 The VHDL standards to be used are specified in option `vhdl-standard'.
4524 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4527 KEYWORD CASE:
4528 Lower and upper case for keywords and standardized types, attributes,
4529 and enumeration values is supported. If the option
4530 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4531 lower case and are converted into upper case automatically (not for
4532 types, attributes, and enumeration values). The case of keywords,
4533 types, attributes,and enumeration values can be fixed for an entire
4534 region (menu) or buffer (`C-c C-x C-c') according to the options
4535 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4538 HIGHLIGHTING (fontification):
4539 Keywords and standardized types, attributes, enumeration values, and
4540 function names (controlled by option `vhdl-highlight-keywords'), as well
4541 as comments, strings, and template prompts are highlighted using
4542 different colors. Unit, subprogram, signal, variable, constant,
4543 parameter and generic/port names in declarations as well as labels are
4544 highlighted if option `vhdl-highlight-names' is non-nil.
4546 Additional reserved words or words with a forbidden syntax (e.g. words
4547 that should be avoided) can be specified in option
4548 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4549 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4550 keywords are highlighted as forbidden words if option
4551 `vhdl-highlight-verilog-keywords' is non-nil.
4553 Words with special syntax can be highlighted by specifying their
4554 syntax and color in option `vhdl-special-syntax-alist' and by setting
4555 option `vhdl-highlight-special-words' to non-nil. This allows to
4556 establish some naming conventions (e.g. to distinguish different kinds
4557 of signals or other objects by using name suffices) and to support them
4558 visually.
4560 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4561 to support case-sensitive highlighting. However, keywords are then only
4562 highlighted if written in lower case.
4564 Code between \"translate_off\" and \"translate_on\" pragmas is
4565 highlighted using a different background color if option
4566 `vhdl-highlight-translate-off' is non-nil.
4568 For documentation and customization of the used colors see
4569 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4570 highlighting of matching parenthesis, see customization group
4571 `paren-showing'. Automatic buffer highlighting is turned on/off by
4572 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4575 USER MODELS:
4576 VHDL models (templates) can be specified by the user and made accessible
4577 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4578 electrification. See option `vhdl-model-alist'.
4581 HIDE/SHOW:
4582 The code of blocks, processes, subprograms, component declarations and
4583 instantiations, generic/port clauses, and configuration declarations can
4584 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4585 the code (see customization group `vhdl-menu'). XEmacs: limited
4586 functionality due to old `hideshow.el' package.
4589 CODE UPDATING:
4590 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4591 current process, `C-c C-u M-s' of all processes in the current buffer.
4592 Limitations:
4593 - Only declared local signals (ports, signals declared in
4594 architecture and blocks) are automatically inserted.
4595 - Global signals declared in packages are not automatically inserted.
4596 Insert them once manually (will be kept afterwards).
4597 - Out parameters of procedures are considered to be read.
4598 Use option `vhdl-entity-file-name' to specify the entity file name
4599 \(used to obtain the port names).
4602 CODE FIXING:
4603 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4604 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4607 PRINTING:
4608 Postscript printing with different faces (an optimized set of faces is
4609 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4610 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4611 postscript printing commands. Option `vhdl-print-two-column' defines
4612 appropriate default settings for nice landscape two-column printing.
4613 The paper format can be set by option `ps-paper-type'. Do not forget to
4614 switch `ps-print-color-p' to nil for printing on black-and-white
4615 printers.
4618 OPTIONS:
4619 User options allow customization of VHDL Mode. All options are
4620 accessible from the \"Options\" menu entry. Simple options (switches
4621 and choices) can directly be changed, while for complex options a
4622 customization buffer is opened. Changed options can be saved for future
4623 sessions using the \"Save Options\" menu entry.
4625 Options and their detailed descriptions can also be accessed by using
4626 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4627 customize-group' for groups). Some customizations only take effect
4628 after some action (read the NOTE in the option documentation).
4629 Customization can also be done globally (i.e. site-wide, read the
4630 INSTALL file).
4632 Not all options are described in this documentation, so go and see
4633 what other useful user options there are (`M-x vhdl-customize' or menu)!
4636 FILE EXTENSIONS:
4637 As default, files with extensions \".vhd\" and \".vhdl\" are
4638 automatically recognized as VHDL source files. To add an extension
4639 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4641 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4644 HINTS:
4645 - To start Emacs with open VHDL hierarchy browser without having to load
4646 a VHDL file first, use the command:
4648 emacs -l vhdl-mode -f speedbar-frame-mode
4650 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4652 - Some features only work on properly indented code.
4655 RELEASE NOTES:
4656 See also the release notes (menu) for added features in new releases.
4659 Maintenance:
4660 ------------
4662 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4663 Add a description of the problem and include a reproducible test case.
4665 Questions and enhancement requests can be sent to <reto@gnu.org>.
4667 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4668 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4669 releases. You are kindly invited to participate in beta testing. Subscribe
4670 to above mailing lists by sending an email to <reto@gnu.org>.
4672 VHDL Mode is officially distributed at
4673 http://opensource.ethz.ch/emacs/vhdl-mode.html
4674 where the latest version can be found.
4677 Known problems:
4678 ---------------
4680 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4681 - XEmacs: Incorrect start-up when automatically opening speedbar.
4682 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4685 The VHDL Mode Authors
4686 Reto Zimmermann and Rod Whitby
4688 Key bindings:
4689 -------------
4691 \\{vhdl-mode-map}"
4692 (interactive)
4693 (kill-all-local-variables)
4694 (setq major-mode 'vhdl-mode)
4695 (setq mode-name "VHDL")
4697 ;; set maps and tables
4698 (use-local-map vhdl-mode-map)
4699 (set-syntax-table vhdl-mode-syntax-table)
4700 (setq local-abbrev-table vhdl-mode-abbrev-table)
4702 ;; set local variables
4703 (set (make-local-variable 'paragraph-start)
4704 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4705 (set (make-local-variable 'paragraph-separate) paragraph-start)
4706 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4707 (set (make-local-variable 'require-final-newline)
4708 (if vhdl-emacs-22 mode-require-final-newline t))
4709 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4710 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4711 (set (make-local-variable 'comment-start) "--")
4712 (set (make-local-variable 'comment-end) "")
4713 (when vhdl-emacs-21
4714 (set (make-local-variable 'comment-padding) ""))
4715 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4716 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4717 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4718 (set (make-local-variable 'comment-multi-line) nil)
4719 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4720 (set (make-local-variable 'hippie-expand-verbose) nil)
4722 ;; setup the comment indent variable in a Emacs version portable way
4723 ;; ignore any byte compiler warnings you might get here
4724 (when (boundp 'comment-indent-function)
4725 (make-local-variable 'comment-indent-function)
4726 (setq comment-indent-function 'vhdl-comment-indent))
4728 ;; initialize font locking
4729 (set (make-local-variable 'font-lock-defaults)
4730 (list
4731 '(nil vhdl-font-lock-keywords) nil
4732 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4733 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4734 (unless vhdl-emacs-21
4735 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4736 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4737 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4738 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4739 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4740 ; (turn-on-font-lock)
4742 ;; variables for source file compilation
4743 (when vhdl-compile-use-local-error-regexp
4744 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4745 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4747 ;; add index menu
4748 (vhdl-index-menu-init)
4749 ;; add source file menu
4750 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4751 ;; add VHDL menu
4752 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4753 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4754 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4755 ;; initialize hideshow and add menu
4756 (vhdl-hideshow-init)
4757 (run-hooks 'menu-bar-update-hook)
4759 ;; miscellaneous
4760 (vhdl-ps-print-init)
4761 (vhdl-write-file-hooks-init)
4762 (vhdl-mode-line-update)
4763 (message "VHDL Mode %s.%s" vhdl-version
4764 (if noninteractive "" " See menu for documentation and release notes."))
4766 ;; run hooks
4767 (if vhdl-emacs-22
4768 (run-mode-hooks 'vhdl-mode-hook)
4769 (run-hooks 'vhdl-mode-hook)))
4771 (defun vhdl-activate-customizations ()
4772 "Activate all customizations on local variables."
4773 (interactive)
4774 (vhdl-mode-map-init)
4775 (use-local-map vhdl-mode-map)
4776 (set-syntax-table vhdl-mode-syntax-table)
4777 (setq comment-column vhdl-inline-comment-column)
4778 (setq end-comment-column vhdl-end-comment-column)
4779 (vhdl-write-file-hooks-init)
4780 (vhdl-update-mode-menu)
4781 (vhdl-hideshow-init)
4782 (run-hooks 'menu-bar-update-hook)
4783 (vhdl-mode-line-update))
4785 (defun vhdl-write-file-hooks-init ()
4786 "Add/remove hooks when buffer is saved."
4787 (if vhdl-modify-date-on-saving
4788 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4789 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4790 (make-local-variable 'after-save-hook)
4791 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4793 (defun vhdl-process-command-line-option (option)
4794 "Process command line options for VHDL Mode."
4795 (cond
4796 ;; set compiler
4797 ((equal option "-compiler")
4798 (vhdl-set-compiler (car command-line-args-left))
4799 (setq command-line-args-left (cdr command-line-args-left)))
4800 ;; set project
4801 ((equal option "-project")
4802 (vhdl-set-project (car command-line-args-left))
4803 (setq command-line-args-left (cdr command-line-args-left)))))
4805 ;; make Emacs process VHDL Mode options
4806 (setq command-switch-alist
4807 (append command-switch-alist
4808 '(("-compiler" . vhdl-process-command-line-option)
4809 ("-project" . vhdl-process-command-line-option))))
4812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4813 ;;; Keywords and standardized words
4814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4816 (defconst vhdl-93-keywords
4818 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4819 "assert" "attribute"
4820 "begin" "block" "body" "buffer" "bus"
4821 "case" "component" "configuration" "constant"
4822 "disconnect" "downto"
4823 "else" "elsif" "end" "entity" "exit"
4824 "file" "for" "function"
4825 "generate" "generic" "group" "guarded"
4826 "if" "impure" "in" "inertial" "inout" "is"
4827 "label" "library" "linkage" "literal" "loop"
4828 "map" "mod"
4829 "nand" "new" "next" "nor" "not" "null"
4830 "of" "on" "open" "or" "others" "out"
4831 "package" "port" "postponed" "procedure" "process" "pure"
4832 "range" "record" "register" "reject" "rem" "report" "return"
4833 "rol" "ror"
4834 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4835 "then" "to" "transport" "type"
4836 "unaffected" "units" "until" "use"
4837 "variable"
4838 "wait" "when" "while" "with"
4839 "xnor" "xor"
4841 "List of VHDL'93 keywords.")
4843 (defconst vhdl-ams-keywords
4845 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4846 "reference" "spectrum" "subnature" "terminal" "through"
4847 "tolerance"
4849 "List of VHDL-AMS keywords.")
4851 (defconst vhdl-verilog-keywords
4853 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4854 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4855 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4856 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4857 "endprimitive" "endspecify" "endtable" "endtask" "event"
4858 "for" "force" "forever" "fork" "function"
4859 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4860 "macromodule" "makefile" "medium" "module"
4861 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4862 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4863 "pullup"
4864 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4865 "rtranif0" "rtranif1"
4866 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4867 "strong1" "supply" "supply0" "supply1"
4868 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4869 "triand" "trior" "trireg"
4870 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4872 "List of Verilog keywords as candidate for additional reserved words.")
4874 (defconst vhdl-93-types
4876 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4877 "real" "time" "natural" "positive" "string" "line" "text" "side"
4878 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4879 "std_logic" "std_logic_vector"
4880 "std_ulogic" "std_ulogic_vector"
4882 "List of VHDL'93 standardized types.")
4884 (defconst vhdl-ams-types
4886 "domain_type" "real_vector"
4887 ;; from `nature_pkg' package
4888 "voltage" "current" "electrical" "position" "velocity" "force"
4889 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4890 "pressure" "flowrate" "fluid"
4892 "List of VHDL-AMS standardized types.")
4894 (defconst vhdl-math-types
4896 "complex" "complex_polar"
4898 "List of Math Packages standardized types.")
4900 (defconst vhdl-93-attributes
4902 "base" "left" "right" "high" "low" "pos" "val" "succ"
4903 "pred" "leftof" "rightof" "range" "reverse_range"
4904 "length" "delayed" "stable" "quiet" "transaction"
4905 "event" "active" "last_event" "last_active" "last_value"
4906 "driving" "driving_value" "ascending" "value" "image"
4907 "simple_name" "instance_name" "path_name"
4908 "foreign"
4910 "List of VHDL'93 standardized attributes.")
4912 (defconst vhdl-ams-attributes
4914 "across" "through"
4915 "reference" "contribution" "tolerance"
4916 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4917 "ramp" "slew"
4919 "List of VHDL-AMS standardized attributes.")
4921 (defconst vhdl-93-enum-values
4923 "true" "false"
4924 "note" "warning" "error" "failure"
4925 "read_mode" "write_mode" "append_mode"
4926 "open_ok" "status_error" "name_error" "mode_error"
4927 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4928 "right" "left"
4930 "List of VHDL'93 standardized enumeration values.")
4932 (defconst vhdl-ams-enum-values
4934 "quiescent_domain" "time_domain" "frequency_domain"
4935 ;; from `nature_pkg' package
4936 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4938 "List of VHDL-AMS standardized enumeration values.")
4940 (defconst vhdl-math-constants
4942 "math_e" "math_1_over_e"
4943 "math_pi" "math_two_pi" "math_1_over_pi"
4944 "math_half_pi" "math_q_pi" "math_3_half_pi"
4945 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4946 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4947 "math_deg_to_rad" "math_rad_to_deg"
4948 "cbase_1" "cbase_j" "czero"
4950 "List of Math Packages standardized constants.")
4952 (defconst vhdl-93-functions
4954 "now" "resolved" "rising_edge" "falling_edge"
4955 "read" "readline" "write" "writeline" "endfile"
4956 "resize" "is_X" "std_match"
4957 "shift_left" "shift_right" "rotate_left" "rotate_right"
4958 "to_unsigned" "to_signed" "to_integer"
4959 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4960 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4961 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4962 "shl" "shr" "ext" "sxt"
4963 "deallocate"
4965 "List of VHDL'93 standardized functions.")
4967 (defconst vhdl-ams-functions
4969 "frequency"
4971 "List of VHDL-AMS standardized functions.")
4973 (defconst vhdl-math-functions
4975 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4976 "sqrt" "cbrt" "exp" "log"
4977 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4978 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4979 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4981 "List of Math Packages standardized functions.")
4983 (defconst vhdl-93-packages
4985 "std_logic_1164" "numeric_std" "numeric_bit"
4986 "standard" "textio"
4987 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4988 "std_logic_misc" "std_logic_textio"
4989 "ieee" "std" "work"
4991 "List of VHDL'93 standardized packages and libraries.")
4993 (defconst vhdl-ams-packages
4995 ;; from `nature_pkg' package
4996 "nature_pkg"
4998 "List of VHDL-AMS standardized packages and libraries.")
5000 (defconst vhdl-math-packages
5002 "math_real" "math_complex"
5004 "List of Math Packages standardized packages and libraries.")
5006 (defvar vhdl-keywords nil
5007 "List of VHDL keywords.")
5009 (defvar vhdl-types nil
5010 "List of VHDL standardized types.")
5012 (defvar vhdl-attributes nil
5013 "List of VHDL standardized attributes.")
5015 (defvar vhdl-enum-values nil
5016 "List of VHDL standardized enumeration values.")
5018 (defvar vhdl-constants nil
5019 "List of VHDL standardized constants.")
5021 (defvar vhdl-functions nil
5022 "List of VHDL standardized functions.")
5024 (defvar vhdl-packages nil
5025 "List of VHDL standardized packages and libraries.")
5027 (defvar vhdl-reserved-words nil
5028 "List of additional reserved words.")
5030 (defvar vhdl-keywords-regexp nil
5031 "Regexp for VHDL keywords.")
5033 (defvar vhdl-types-regexp nil
5034 "Regexp for VHDL standardized types.")
5036 (defvar vhdl-attributes-regexp nil
5037 "Regexp for VHDL standardized attributes.")
5039 (defvar vhdl-enum-values-regexp nil
5040 "Regexp for VHDL standardized enumeration values.")
5042 (defvar vhdl-functions-regexp nil
5043 "Regexp for VHDL standardized functions.")
5045 (defvar vhdl-packages-regexp nil
5046 "Regexp for VHDL standardized packages and libraries.")
5048 (defvar vhdl-reserved-words-regexp nil
5049 "Regexp for additional reserved words.")
5051 (defvar vhdl-directive-keywords-regexp nil
5052 "Regexp for compiler directive keywords.")
5054 (defun vhdl-words-init ()
5055 "Initialize reserved words."
5056 (setq vhdl-keywords
5057 (append vhdl-93-keywords
5058 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5059 (setq vhdl-types
5060 (append vhdl-93-types
5061 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5062 (when (vhdl-standard-p 'math) vhdl-math-types)))
5063 (setq vhdl-attributes
5064 (append vhdl-93-attributes
5065 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5066 (setq vhdl-enum-values
5067 (append vhdl-93-enum-values
5068 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5069 (setq vhdl-constants
5070 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5071 (setq vhdl-functions
5072 (append vhdl-93-functions
5073 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5074 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5075 (setq vhdl-packages
5076 (append vhdl-93-packages
5077 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5078 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5079 (setq vhdl-reserved-words
5080 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5081 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5082 '("")))
5083 (setq vhdl-keywords-regexp
5084 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5085 (setq vhdl-types-regexp
5086 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5087 (setq vhdl-attributes-regexp
5088 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5089 (setq vhdl-enum-values-regexp
5090 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5091 (setq vhdl-functions-regexp
5092 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5093 (setq vhdl-packages-regexp
5094 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5095 (setq vhdl-reserved-words-regexp
5096 (concat "\\<\\("
5097 (unless (equal vhdl-forbidden-syntax "")
5098 (concat vhdl-forbidden-syntax "\\|"))
5099 (regexp-opt vhdl-reserved-words)
5100 "\\)\\>"))
5101 (setq vhdl-directive-keywords-regexp
5102 (concat "\\<\\(" (mapconcat 'regexp-quote
5103 vhdl-directive-keywords "\\|") "\\)\\>"))
5104 (vhdl-abbrev-list-init))
5106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5107 ;; Words to expand
5109 (defvar vhdl-abbrev-list nil
5110 "Predefined abbreviations for VHDL.")
5112 (defun vhdl-abbrev-list-init ()
5113 (setq vhdl-abbrev-list
5114 (append
5115 (list vhdl-upper-case-keywords) vhdl-keywords
5116 (list vhdl-upper-case-types) vhdl-types
5117 (list vhdl-upper-case-attributes) vhdl-attributes
5118 (list vhdl-upper-case-enum-values) vhdl-enum-values
5119 (list vhdl-upper-case-constants) vhdl-constants
5120 (list nil) vhdl-functions
5121 (list nil) vhdl-packages)))
5123 ;; initialize reserved words for VHDL Mode
5124 (vhdl-words-init)
5127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5128 ;;; Indentation
5129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5132 ;; Syntax analysis
5134 ;; constant regular expressions for looking at various constructs
5136 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5137 "Regexp describing a VHDL symbol.
5138 We cannot use just `word' syntax class since `_' cannot be in word
5139 class. Putting underscore in word class breaks forward word movement
5140 behavior that users are familiar with.")
5142 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5143 "Regexp describing a case statement header key.")
5145 (defconst vhdl-label-key
5146 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5147 "Regexp describing a VHDL label.")
5149 ;; Macro definitions:
5151 (defmacro vhdl-point (position)
5152 "Return the value of point at certain commonly referenced POSITIONs.
5153 POSITION can be one of the following symbols:
5155 bol -- beginning of line
5156 eol -- end of line
5157 bod -- beginning of defun
5158 boi -- back to indentation
5159 eoi -- last whitespace on line
5160 ionl -- indentation of next line
5161 iopl -- indentation of previous line
5162 bonl -- beginning of next line
5163 bopl -- beginning of previous line
5165 This function does not modify point or mark."
5166 (or (and (eq 'quote (car-safe position))
5167 (null (cddr position)))
5168 (error "ERROR: Bad buffer position requested: %s" position))
5169 (setq position (nth 1 position))
5170 `(let ((here (point)))
5171 ,@(cond
5172 ((eq position 'bol) '((beginning-of-line)))
5173 ((eq position 'eol) '((end-of-line)))
5174 ((eq position 'bod) '((save-match-data
5175 (vhdl-beginning-of-defun))))
5176 ((eq position 'boi) '((back-to-indentation)))
5177 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5178 ((eq position 'bonl) '((forward-line 1)))
5179 ((eq position 'bopl) '((forward-line -1)))
5180 ((eq position 'iopl)
5181 '((forward-line -1)
5182 (back-to-indentation)))
5183 ((eq position 'ionl)
5184 '((forward-line 1)
5185 (back-to-indentation)))
5186 (t (error "ERROR: Unknown buffer position requested: %s" position))
5188 (prog1
5189 (point)
5190 (goto-char here))
5191 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5192 ;; doesn't hurt for v19
5193 ,@nil
5196 (defmacro vhdl-safe (&rest body)
5197 "Safely execute BODY, return nil if an error occurred."
5198 `(condition-case nil
5199 (progn ,@body)
5200 (error nil)))
5202 (defmacro vhdl-add-syntax (symbol &optional relpos)
5203 "A simple macro to append the syntax in SYMBOL to the syntax list.
5204 Try to increase performance by using this macro."
5205 `(setq vhdl-syntactic-context
5206 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5208 (defmacro vhdl-has-syntax (symbol)
5209 "A simple macro to return check the syntax list.
5210 Try to increase performance by using this macro."
5211 `(assoc ,symbol vhdl-syntactic-context))
5213 ;; Syntactic element offset manipulation:
5215 (defun vhdl-read-offset (langelem)
5216 "Read new offset value for LANGELEM from minibuffer.
5217 Return a valid value only."
5218 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5219 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5220 (prompt "Offset: ")
5221 offset input interned)
5222 (while (not offset)
5223 (setq input (read-string prompt oldoff)
5224 offset (cond ((string-equal "+" input) '+)
5225 ((string-equal "-" input) '-)
5226 ((string-equal "++" input) '++)
5227 ((string-equal "--" input) '--)
5228 ((string-match "^-?[0-9]+$" input)
5229 (string-to-number input))
5230 ((fboundp (setq interned (intern input)))
5231 interned)
5232 ((boundp interned) interned)
5233 ;; error, but don't signal one, keep trying
5234 ;; to read an input value
5235 (t (ding)
5236 (setq prompt errmsg)
5237 nil))))
5238 offset))
5240 (defun vhdl-set-offset (symbol offset &optional add-p)
5241 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5242 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5243 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5244 `vhdl-offsets-alist' if it doesn't already appear there."
5245 (interactive
5246 (let* ((langelem
5247 (intern (completing-read
5248 (concat "Syntactic symbol to change"
5249 (if current-prefix-arg " or add" "")
5250 ": ")
5251 (mapcar
5252 (function
5253 (lambda (langelem)
5254 (cons (format "%s" (car langelem)) nil)))
5255 vhdl-offsets-alist)
5256 nil (not current-prefix-arg)
5257 ;; initial contents tries to be the last element
5258 ;; on the syntactic analysis list for the current
5259 ;; line
5260 (let* ((syntax (vhdl-get-syntactic-context))
5261 (len (length syntax))
5262 (ic (format "%s" (car (nth (1- len) syntax)))))
5265 (offset (vhdl-read-offset langelem)))
5266 (list langelem offset current-prefix-arg)))
5267 ;; sanity check offset
5268 (or (eq offset '+)
5269 (eq offset '-)
5270 (eq offset '++)
5271 (eq offset '--)
5272 (integerp offset)
5273 (fboundp offset)
5274 (boundp offset)
5275 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5276 offset))
5277 (let ((entry (assq symbol vhdl-offsets-alist)))
5278 (if entry
5279 (setcdr entry offset)
5280 (if add-p
5281 (setq vhdl-offsets-alist
5282 (cons (cons symbol offset) vhdl-offsets-alist))
5283 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5284 (vhdl-keep-region-active))
5286 (defun vhdl-set-style (style &optional local)
5287 "Set `vhdl-mode' variables to use one of several different indentation styles.
5288 STYLE is a string representing the desired style and optional LOCAL is
5289 a flag which, if non-nil, means to make the style variables being
5290 changed buffer local, instead of the default, which is to set the
5291 global variables. Interactively, the flag comes from the prefix
5292 argument. The styles are chosen from the `vhdl-style-alist' variable."
5293 (interactive (list (completing-read "Use which VHDL indentation style? "
5294 vhdl-style-alist nil t)
5295 current-prefix-arg))
5296 (let ((vars (cdr (assoc style vhdl-style-alist))))
5297 (or vars
5298 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5299 ;; set all the variables
5300 (mapc
5301 (function
5302 (lambda (varentry)
5303 (let ((var (car varentry))
5304 (val (cdr varentry)))
5305 (and local
5306 (make-local-variable var))
5307 ;; special case for vhdl-offsets-alist
5308 (if (not (eq var 'vhdl-offsets-alist))
5309 (set var val)
5310 ;; reset vhdl-offsets-alist to the default value first
5311 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5312 ;; now set the langelems that are different
5313 (mapcar
5314 (function
5315 (lambda (langentry)
5316 (let ((langelem (car langentry))
5317 (offset (cdr langentry)))
5318 (vhdl-set-offset langelem offset)
5320 val))
5322 vars))
5323 (vhdl-keep-region-active))
5325 (defun vhdl-get-offset (langelem)
5326 "Get offset from LANGELEM which is a cons cell of the form:
5327 \(SYMBOL . RELPOS). The symbol is matched against
5328 vhdl-offsets-alist and the offset found there is either returned,
5329 or added to the indentation at RELPOS. If RELPOS is nil, then
5330 the offset is simply returned."
5331 (let* ((symbol (car langelem))
5332 (relpos (cdr langelem))
5333 (match (assq symbol vhdl-offsets-alist))
5334 (offset (cdr-safe match)))
5335 ;; offset can be a number, a function, a variable, or one of the
5336 ;; symbols + or -
5337 (cond
5338 ((not match)
5339 (if vhdl-strict-syntax-p
5340 (error "ERROR: Don't know how to indent a %s" symbol)
5341 (setq offset 0
5342 relpos 0)))
5343 ((eq offset '+) (setq offset vhdl-basic-offset))
5344 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5345 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5346 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5347 ((and (not (numberp offset))
5348 (fboundp offset))
5349 (setq offset (funcall offset langelem)))
5350 ((not (numberp offset))
5351 (setq offset (eval offset)))
5353 (+ (if (and relpos
5354 (< relpos (vhdl-point 'bol)))
5355 (save-excursion
5356 (goto-char relpos)
5357 (current-column))
5359 offset)))
5361 ;; Syntactic support functions:
5363 (defun vhdl-in-comment-p ()
5364 "Check if point is in a comment."
5365 (eq (vhdl-in-literal) 'comment))
5367 (defun vhdl-in-string-p ()
5368 "Check if point is in a string."
5369 (eq (vhdl-in-literal) 'string))
5371 (defun vhdl-in-literal ()
5372 "Determine if point is in a VHDL literal."
5373 (save-excursion
5374 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5375 (cond
5376 ((nth 3 state) 'string)
5377 ((nth 4 state) 'comment)
5378 ((vhdl-beginning-of-macro) 'pound)
5379 (t nil)))))
5381 (defun vhdl-forward-comment (&optional direction)
5382 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5383 negative, skip forward otherwise."
5384 (interactive "p")
5385 (if (and direction (< direction 0))
5386 ;; skip backwards
5387 (progn
5388 (skip-chars-backward " \t\n")
5389 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5390 (goto-char (match-beginning 3))
5391 (skip-chars-backward " \t\n")))
5392 ;; skip forwards
5393 (skip-chars-forward " \t\n")
5394 (while (looking-at "--.*")
5395 (goto-char (match-end 0))
5396 (skip-chars-forward " \t\n"))))
5398 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5399 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5400 (defalias 'vhdl-forward-comment 'forward-comment))
5402 ;; This is the best we can do in Win-Emacs.
5403 (defun vhdl-win-il (&optional lim)
5404 "Determine if point is in a VHDL literal."
5405 (save-excursion
5406 (let* ((here (point))
5407 (state nil)
5408 (match nil)
5409 (lim (or lim (vhdl-point 'bod))))
5410 (goto-char lim )
5411 (while (< (point) here)
5412 (setq match
5413 (and (re-search-forward "--\\|[\"']"
5414 here 'move)
5415 (buffer-substring (match-beginning 0) (match-end 0))))
5416 (setq state
5417 (cond
5418 ;; no match
5419 ((null match) nil)
5420 ;; looking at the opening of a VHDL style comment
5421 ((string= "--" match)
5422 (if (<= here (progn (end-of-line) (point))) 'comment))
5423 ;; looking at the opening of a double quote string
5424 ((string= "\"" match)
5425 (if (not (save-restriction
5426 ;; this seems to be necessary since the
5427 ;; re-search-forward will not work without it
5428 (narrow-to-region (point) here)
5429 (re-search-forward
5430 ;; this regexp matches a double quote
5431 ;; which is preceded by an even number
5432 ;; of backslashes, including zero
5433 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5434 'string))
5435 ;; looking at the opening of a single quote string
5436 ((string= "'" match)
5437 (if (not (save-restriction
5438 ;; see comments from above
5439 (narrow-to-region (point) here)
5440 (re-search-forward
5441 ;; this matches a single quote which is
5442 ;; preceded by zero or two backslashes.
5443 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5444 here 'move)))
5445 'string))
5446 (t nil)))
5447 ) ; end-while
5448 state)))
5450 (and (string-match "Win-Emacs" emacs-version)
5451 (fset 'vhdl-in-literal 'vhdl-win-il))
5453 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5454 ;; defined as lexical whitespace or comments. Search no farther back
5455 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5456 ;; used for backward skipping, (point-max) is used for forward
5457 ;; skipping.
5459 (defun vhdl-forward-syntactic-ws (&optional lim)
5460 "Forward skip of syntactic whitespace."
5461 (let* ((here (point-max))
5462 (hugenum (point-max)))
5463 (while (/= here (point))
5464 (setq here (point))
5465 (vhdl-forward-comment hugenum)
5466 ;; skip preprocessor directives
5467 (when (and (eq (char-after) ?#)
5468 (= (vhdl-point 'boi) (point)))
5469 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5470 (= (forward-line 1) 0)))
5471 (end-of-line)))
5472 (if lim (goto-char (min (point) lim)))))
5475 ;; This is the best we can do in Win-Emacs.
5476 (defun vhdl-win-fsws (&optional lim)
5477 "Forward skip syntactic whitespace for Win-Emacs."
5478 (let ((lim (or lim (point-max)))
5479 stop)
5480 (while (not stop)
5481 (skip-chars-forward " \t\n\r\f" lim)
5482 (cond
5483 ;; vhdl comment
5484 ((looking-at "--") (end-of-line))
5485 ;; none of the above
5486 (t (setq stop t))))))
5488 (and (string-match "Win-Emacs" emacs-version)
5489 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5491 (defun vhdl-beginning-of-macro (&optional lim)
5492 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5493 (let ((here (point)))
5494 (beginning-of-line)
5495 (while (eq (char-before (1- (point))) ?\\)
5496 (forward-line -1))
5497 (back-to-indentation)
5498 (if (and (<= (point) here)
5499 (eq (char-after) ?#))
5501 (goto-char here)
5502 nil)))
5504 (defun vhdl-backward-syntactic-ws (&optional lim)
5505 "Backward skip over syntactic whitespace."
5506 (let* ((here (point-min))
5507 (hugenum (- (point-max))))
5508 (while (/= here (point))
5509 (setq here (point))
5510 (vhdl-forward-comment hugenum)
5511 (vhdl-beginning-of-macro))
5512 (if lim (goto-char (max (point) lim)))))
5514 ;; This is the best we can do in Win-Emacs.
5515 (defun vhdl-win-bsws (&optional lim)
5516 "Backward skip syntactic whitespace for Win-Emacs."
5517 (let ((lim (or lim (vhdl-point 'bod)))
5518 stop)
5519 (while (not stop)
5520 (skip-chars-backward " \t\n\r\f" lim)
5521 (cond
5522 ;; vhdl comment
5523 ((eq (vhdl-in-literal) 'comment)
5524 (skip-chars-backward "^-" lim)
5525 (skip-chars-backward "-" lim)
5526 (while (not (or (and (= (following-char) ?-)
5527 (= (char-after (1+ (point))) ?-))
5528 (<= (point) lim)))
5529 (skip-chars-backward "^-" lim)
5530 (skip-chars-backward "-" lim)))
5531 ;; none of the above
5532 (t (setq stop t))))))
5534 (and (string-match "Win-Emacs" emacs-version)
5535 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5537 ;; Functions to help finding the correct indentation column:
5539 (defun vhdl-first-word (point)
5540 "If the keyword at POINT is at boi, then return (current-column) at
5541 that point, else nil."
5542 (save-excursion
5543 (and (goto-char point)
5544 (eq (point) (vhdl-point 'boi))
5545 (current-column))))
5547 (defun vhdl-last-word (point)
5548 "If the keyword at POINT is at eoi, then return (current-column) at
5549 that point, else nil."
5550 (save-excursion
5551 (and (goto-char point)
5552 (save-excursion (or (eq (progn (forward-sexp) (point))
5553 (vhdl-point 'eoi))
5554 (looking-at "\\s-*\\(--\\)?")))
5555 (current-column))))
5557 ;; Core syntactic evaluation functions:
5559 (defconst vhdl-libunit-re
5560 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5562 (defun vhdl-libunit-p ()
5563 (and
5564 (save-excursion
5565 (forward-sexp)
5566 (skip-chars-forward " \t\n")
5567 (not (looking-at "is\\b[^_]")))
5568 (save-excursion
5569 (backward-sexp)
5570 (and (not (looking-at "use\\b[^_]"))
5571 (progn
5572 (forward-sexp)
5573 (vhdl-forward-syntactic-ws)
5574 (/= (following-char) ?:))))
5577 (defconst vhdl-defun-re
5578 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5580 (defun vhdl-defun-p ()
5581 (save-excursion
5582 (if (looking-at "block\\|process\\|procedural")
5583 ;; "block", "process", "procedural":
5584 (save-excursion
5585 (backward-sexp)
5586 (not (looking-at "end\\s-+\\w")))
5587 ;; "architecture", "configuration", "entity",
5588 ;; "package", "procedure", "function":
5589 t)))
5591 (defun vhdl-corresponding-defun ()
5592 "If the word at the current position corresponds to a \"defun\"
5593 keyword, then return a string that can be used to find the
5594 corresponding \"begin\" keyword, else return nil."
5595 (save-excursion
5596 (and (looking-at vhdl-defun-re)
5597 (vhdl-defun-p)
5598 (if (looking-at "block\\|process\\|procedural")
5599 ;; "block", "process". "procedural:
5600 (buffer-substring (match-beginning 0) (match-end 0))
5601 ;; "architecture", "configuration", "entity", "package",
5602 ;; "procedure", "function":
5603 "is"))))
5605 (defconst vhdl-begin-fwd-re
5606 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5607 "A regular expression for searching forward that matches all known
5608 \"begin\" keywords.")
5610 (defconst vhdl-begin-bwd-re
5611 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5612 "A regular expression for searching backward that matches all known
5613 \"begin\" keywords.")
5615 (defun vhdl-begin-p (&optional lim)
5616 "Return t if we are looking at a real \"begin\" keyword.
5617 Assumes that the caller will make sure that we are looking at
5618 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5619 the middle of an identifier that just happens to contain a \"begin\"
5620 keyword."
5621 (cond
5622 ;; "[architecture|case|configuration|entity|package|
5623 ;; procedure|function] ... is":
5624 ((and (looking-at "i")
5625 (save-excursion
5626 ;; Skip backward over first sexp (needed to skip over a
5627 ;; procedure interface list, and is harmless in other
5628 ;; situations). Note that we need "return" in the
5629 ;; following search list so that we don't run into
5630 ;; semicolons in the function interface list.
5631 (backward-sexp)
5632 (let (foundp)
5633 (while (and (not foundp)
5634 (re-search-backward
5635 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5636 lim 'move))
5637 (if (or (= (preceding-char) ?_)
5638 (vhdl-in-literal))
5639 (backward-char)
5640 (setq foundp t))))
5641 (and (/= (following-char) ?\;)
5642 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5644 ;; "begin", "then":
5645 ((looking-at "be\\|t")
5647 ;; "else":
5648 ((and (looking-at "e")
5649 ;; make sure that the "else" isn't inside a
5650 ;; conditional signal assignment.
5651 (save-excursion
5652 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5653 (or (eq (following-char) ?\;)
5654 (eq (point) lim))))
5656 ;; "block", "generate", "loop", "process", "procedural",
5657 ;; "units", "record":
5658 ((and (looking-at "bl\\|[glpur]")
5659 (save-excursion
5660 (backward-sexp)
5661 (not (looking-at "end\\s-+\\w"))))
5663 ;; "component":
5664 ((and (looking-at "c")
5665 (save-excursion
5666 (backward-sexp)
5667 (not (looking-at "end\\s-+\\w")))
5668 ;; look out for the dreaded entity class in an attribute
5669 (save-excursion
5670 (vhdl-backward-syntactic-ws lim)
5671 (/= (preceding-char) ?:)))
5673 ;; "for" (inside configuration declaration):
5674 ((and (looking-at "f")
5675 (save-excursion
5676 (backward-sexp)
5677 (not (looking-at "end\\s-+\\w")))
5678 (vhdl-has-syntax 'configuration))
5682 (defun vhdl-corresponding-mid (&optional lim)
5683 (cond
5684 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5685 "begin")
5686 ((looking-at "then")
5687 "<else>")
5689 "end")))
5691 (defun vhdl-corresponding-end (&optional lim)
5692 "If the word at the current position corresponds to a \"begin\"
5693 keyword, then return a vector containing enough information to find
5694 the corresponding \"end\" keyword, else return nil. The keyword to
5695 search forward for is aref 0. The column in which the keyword must
5696 appear is aref 1 or nil if any column is suitable.
5697 Assumes that the caller will make sure that we are not in the middle
5698 of an identifier that just happens to contain a \"begin\" keyword."
5699 (save-excursion
5700 (and (looking-at vhdl-begin-fwd-re)
5701 (/= (preceding-char) ?_)
5702 (not (vhdl-in-literal))
5703 (vhdl-begin-p lim)
5704 (cond
5705 ;; "is", "generate", "loop":
5706 ((looking-at "[igl]")
5707 (vector "end"
5708 (and (vhdl-last-word (point))
5709 (or (vhdl-first-word (point))
5710 (save-excursion
5711 (vhdl-beginning-of-statement-1 lim)
5712 (vhdl-backward-skip-label lim)
5713 (vhdl-first-word (point)))))))
5714 ;; "begin", "else", "for":
5715 ((looking-at "be\\|[ef]")
5716 (vector "end"
5717 (and (vhdl-last-word (point))
5718 (or (vhdl-first-word (point))
5719 (save-excursion
5720 (vhdl-beginning-of-statement-1 lim)
5721 (vhdl-backward-skip-label lim)
5722 (vhdl-first-word (point)))))))
5723 ;; "component", "units", "record":
5724 ((looking-at "[cur]")
5725 ;; The first end found will close the block
5726 (vector "end" nil))
5727 ;; "block", "process", "procedural":
5728 ((looking-at "bl\\|p")
5729 (vector "end"
5730 (or (vhdl-first-word (point))
5731 (save-excursion
5732 (vhdl-beginning-of-statement-1 lim)
5733 (vhdl-backward-skip-label lim)
5734 (vhdl-first-word (point))))))
5735 ;; "then":
5736 ((looking-at "t")
5737 (vector "elsif\\|else\\|end\\s-+if"
5738 (and (vhdl-last-word (point))
5739 (or (vhdl-first-word (point))
5740 (save-excursion
5741 (vhdl-beginning-of-statement-1 lim)
5742 (vhdl-backward-skip-label lim)
5743 (vhdl-first-word (point)))))))
5744 ))))
5746 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5748 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5750 (defun vhdl-end-p (&optional lim)
5751 "Return t if we are looking at a real \"end\" keyword.
5752 Assumes that the caller will make sure that we are looking at
5753 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5754 the middle of an identifier that just happens to contain an \"end\"
5755 keyword."
5756 (or (not (looking-at "else"))
5757 ;; make sure that the "else" isn't inside a conditional signal
5758 ;; assignment.
5759 (save-excursion
5760 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5761 (or (eq (following-char) ?\;)
5762 (eq (point) lim)
5763 (vhdl-in-literal)))))
5765 (defun vhdl-corresponding-begin (&optional lim)
5766 "If the word at the current position corresponds to an \"end\"
5767 keyword, then return a vector containing enough information to find
5768 the corresponding \"begin\" keyword, else return nil. The keyword to
5769 search backward for is aref 0. The column in which the keyword must
5770 appear is aref 1 or nil if any column is suitable. The supplementary
5771 keyword to search forward for is aref 2 or nil if this is not
5772 required. If aref 3 is t, then the \"begin\" keyword may be found in
5773 the middle of a statement.
5774 Assumes that the caller will make sure that we are not in the middle
5775 of an identifier that just happens to contain an \"end\" keyword."
5776 (save-excursion
5777 (let (pos)
5778 (if (and (looking-at vhdl-end-fwd-re)
5779 (not (vhdl-in-literal))
5780 (vhdl-end-p lim))
5781 (if (looking-at "el")
5782 ;; "else", "elsif":
5783 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5784 ;; "end ...":
5785 (setq pos (point))
5786 (forward-sexp)
5787 (skip-chars-forward " \t\n")
5788 (cond
5789 ;; "end if":
5790 ((looking-at "if\\b[^_]")
5791 (vector "else\\|elsif\\|if"
5792 (vhdl-first-word pos)
5793 "else\\|then" nil))
5794 ;; "end component":
5795 ((looking-at "component\\b[^_]")
5796 (vector (buffer-substring (match-beginning 1)
5797 (match-end 1))
5798 (vhdl-first-word pos)
5799 nil nil))
5800 ;; "end units", "end record":
5801 ((looking-at "\\(units\\|record\\)\\b[^_]")
5802 (vector (buffer-substring (match-beginning 1)
5803 (match-end 1))
5804 (vhdl-first-word pos)
5805 nil t))
5806 ;; "end block", "end process", "end procedural":
5807 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5808 (vector "begin" (vhdl-first-word pos) nil nil))
5809 ;; "end case":
5810 ((looking-at "case\\b[^_]")
5811 (vector "case" (vhdl-first-word pos) "is" nil))
5812 ;; "end generate":
5813 ((looking-at "generate\\b[^_]")
5814 (vector "generate\\|for\\|if"
5815 (vhdl-first-word pos)
5816 "generate" nil))
5817 ;; "end loop":
5818 ((looking-at "loop\\b[^_]")
5819 (vector "loop\\|while\\|for"
5820 (vhdl-first-word pos)
5821 "loop" nil))
5822 ;; "end for" (inside configuration declaration):
5823 ((looking-at "for\\b[^_]")
5824 (vector "for" (vhdl-first-word pos) nil nil))
5825 ;; "end [id]":
5827 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5828 (vhdl-first-word pos)
5829 ;; return an alist of (statement . keyword) mappings
5831 ;; "begin ... end [id]":
5832 ("begin" . nil)
5833 ;; "architecture ... is ... begin ... end [id]":
5834 ("architecture" . "is")
5835 ;; "configuration ... is ... end [id]":
5836 ("configuration" . "is")
5837 ;; "entity ... is ... end [id]":
5838 ("entity" . "is")
5839 ;; "package ... is ... end [id]":
5840 ("package" . "is")
5841 ;; "procedure ... is ... begin ... end [id]":
5842 ("procedure" . "is")
5843 ;; "function ... is ... begin ... end [id]":
5844 ("function" . "is")
5846 nil))
5847 ))) ; "end ..."
5850 (defconst vhdl-leader-re
5851 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5853 (defun vhdl-end-of-leader ()
5854 (save-excursion
5855 (cond ((looking-at "block\\|process\\|procedural")
5856 (if (save-excursion
5857 (forward-sexp)
5858 (skip-chars-forward " \t\n")
5859 (= (following-char) ?\())
5860 (forward-sexp 2)
5861 (forward-sexp))
5862 (when (looking-at "[ \t\n]*is")
5863 (goto-char (match-end 0)))
5864 (point))
5865 ((looking-at "component")
5866 (forward-sexp 2)
5867 (when (looking-at "[ \t\n]*is")
5868 (goto-char (match-end 0)))
5869 (point))
5870 ((looking-at "for")
5871 (forward-sexp 2)
5872 (skip-chars-forward " \t\n")
5873 (while (looking-at "[,:(]")
5874 (forward-sexp)
5875 (skip-chars-forward " \t\n"))
5876 (point))
5877 (t nil)
5880 (defconst vhdl-trailer-re
5881 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5883 (defconst vhdl-statement-fwd-re
5884 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5885 "A regular expression for searching forward that matches all known
5886 \"statement\" keywords.")
5888 (defconst vhdl-statement-bwd-re
5889 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5890 "A regular expression for searching backward that matches all known
5891 \"statement\" keywords.")
5893 (defun vhdl-statement-p (&optional lim)
5894 "Return t if we are looking at a real \"statement\" keyword.
5895 Assumes that the caller will make sure that we are looking at
5896 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5897 in the middle of an identifier that just happens to contain a
5898 \"statement\" keyword."
5899 (cond
5900 ;; "for" ... "generate":
5901 ((and (looking-at "f")
5902 ;; Make sure it's the start of a parameter specification.
5903 (save-excursion
5904 (forward-sexp 2)
5905 (skip-chars-forward " \t\n")
5906 (looking-at "in\\b[^_]"))
5907 ;; Make sure it's not an "end for".
5908 (save-excursion
5909 (backward-sexp)
5910 (not (looking-at "end\\s-+\\w"))))
5912 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5913 ((and (looking-at "i")
5914 ;; Make sure it's not an "end if".
5915 (save-excursion
5916 (backward-sexp)
5917 (not (looking-at "end\\s-+\\w"))))
5919 ;; "while" ... "loop":
5920 ((looking-at "w")
5924 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5925 "Regexp describing a case statement alternative key.")
5927 (defun vhdl-case-alternative-p (&optional lim)
5928 "Return t if we are looking at a real case alternative.
5929 Assumes that the caller will make sure that we are looking at
5930 vhdl-case-alternative-re, and are not inside a literal, and that
5931 we are not in the middle of an identifier that just happens to
5932 contain a \"when\" keyword."
5933 (save-excursion
5934 (let (foundp)
5935 (while (and (not foundp)
5936 (re-search-backward ";\\|<=" lim 'move))
5937 (if (or (= (preceding-char) ?_)
5938 (vhdl-in-literal))
5939 (backward-char)
5940 (setq foundp t)))
5941 (or (eq (following-char) ?\;)
5942 (eq (point) lim)))
5945 ;; Core syntactic movement functions:
5947 (defconst vhdl-b-t-b-re
5948 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5950 (defun vhdl-backward-to-block (&optional lim)
5951 "Move backward to the previous \"begin\" or \"end\" keyword."
5952 (let (foundp)
5953 (while (and (not foundp)
5954 (re-search-backward vhdl-b-t-b-re lim 'move))
5955 (if (or (= (preceding-char) ?_)
5956 (vhdl-in-literal))
5957 (backward-char)
5958 (cond
5959 ;; "begin" keyword:
5960 ((and (looking-at vhdl-begin-fwd-re)
5961 (/= (preceding-char) ?_)
5962 (vhdl-begin-p lim))
5963 (setq foundp 'begin))
5964 ;; "end" keyword:
5965 ((and (looking-at vhdl-end-fwd-re)
5966 (/= (preceding-char) ?_)
5967 (vhdl-end-p lim))
5968 (setq foundp 'end))
5971 foundp
5974 (defun vhdl-forward-sexp (&optional count lim)
5975 "Move forward across one balanced expression (sexp).
5976 With COUNT, do it that many times."
5977 (interactive "p")
5978 (let ((count (or count 1))
5979 (case-fold-search t)
5980 end-vec target)
5981 (save-excursion
5982 (while (> count 0)
5983 ;; skip whitespace
5984 (skip-chars-forward " \t\n")
5985 ;; Check for an unbalanced "end" keyword
5986 (if (and (looking-at vhdl-end-fwd-re)
5987 (/= (preceding-char) ?_)
5988 (not (vhdl-in-literal))
5989 (vhdl-end-p lim)
5990 (not (looking-at "else")))
5991 (error
5992 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5993 ;; If the current keyword is a "begin" keyword, then find the
5994 ;; corresponding "end" keyword.
5995 (if (setq end-vec (vhdl-corresponding-end lim))
5996 (let (
5997 ;; end-re is the statement keyword to search for
5998 (end-re
5999 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6000 ;; column is either the statement keyword target column
6001 ;; or nil
6002 (column (aref end-vec 1))
6003 (eol (vhdl-point 'eol))
6004 foundp literal placeholder)
6005 ;; Look for the statement keyword.
6006 (while (and (not foundp)
6007 (re-search-forward end-re nil t)
6008 (setq placeholder (match-end 1))
6009 (goto-char (match-beginning 0)))
6010 ;; If we are in a literal, or not in the right target
6011 ;; column and not on the same line as the begin, then
6012 ;; try again.
6013 (if (or (and column
6014 (/= (current-indentation) column)
6015 (> (point) eol))
6016 (= (preceding-char) ?_)
6017 (setq literal (vhdl-in-literal)))
6018 (if (eq literal 'comment)
6019 (end-of-line)
6020 (forward-char))
6021 ;; An "else" keyword corresponds to both the opening brace
6022 ;; of the following sexp and the closing brace of the
6023 ;; previous sexp.
6024 (if (not (looking-at "else"))
6025 (goto-char placeholder))
6026 (setq foundp t))
6028 (if (not foundp)
6029 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6031 ;; If the current keyword is not a "begin" keyword, then just
6032 ;; perform the normal forward-sexp.
6033 (forward-sexp)
6035 (setq count (1- count))
6037 (setq target (point)))
6038 (goto-char target)
6039 nil))
6041 (defun vhdl-backward-sexp (&optional count lim)
6042 "Move backward across one balanced expression (sexp).
6043 With COUNT, do it that many times. LIM bounds any required backward
6044 searches."
6045 (interactive "p")
6046 (let ((count (or count 1))
6047 (case-fold-search t)
6048 begin-vec target)
6049 (save-excursion
6050 (while (> count 0)
6051 ;; Perform the normal backward-sexp, unless we are looking at
6052 ;; "else" - an "else" keyword corresponds to both the opening brace
6053 ;; of the following sexp and the closing brace of the previous sexp.
6054 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6055 (/= (preceding-char) ?_)
6056 (not (vhdl-in-literal)))
6058 (backward-sexp)
6059 (if (and (looking-at vhdl-begin-fwd-re)
6060 (/= (preceding-char) ?_)
6061 (not (vhdl-in-literal))
6062 (vhdl-begin-p lim))
6063 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6064 ;; If the current keyword is an "end" keyword, then find the
6065 ;; corresponding "begin" keyword.
6066 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6067 (/= (preceding-char) ?_))
6068 (let (
6069 ;; begin-re is the statement keyword to search for
6070 (begin-re
6071 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6072 ;; column is either the statement keyword target column
6073 ;; or nil
6074 (column (aref begin-vec 1))
6075 ;; internal-p controls where the statement keyword can
6076 ;; be found.
6077 (internal-p (aref begin-vec 3))
6078 (last-backward (point)) last-forward
6079 foundp literal keyword)
6080 ;; Look for the statement keyword.
6081 (while (and (not foundp)
6082 (re-search-backward begin-re lim t)
6083 (setq keyword
6084 (buffer-substring (match-beginning 1)
6085 (match-end 1))))
6086 ;; If we are in a literal or in the wrong column,
6087 ;; then try again.
6088 (if (or (and column
6089 (and (/= (current-indentation) column)
6090 ;; possibly accept current-column as
6091 ;; well as current-indentation.
6092 (or (not internal-p)
6093 (/= (current-column) column))))
6094 (= (preceding-char) ?_)
6095 (vhdl-in-literal))
6096 (backward-char)
6097 ;; If there is a supplementary keyword, then
6098 ;; search forward for it.
6099 (if (and (setq begin-re (aref begin-vec 2))
6100 (or (not (listp begin-re))
6101 ;; If begin-re is an alist, then find the
6102 ;; element corresponding to the actual
6103 ;; keyword that we found.
6104 (progn
6105 (setq begin-re
6106 (assoc keyword begin-re))
6107 (and begin-re
6108 (setq begin-re (cdr begin-re))))))
6109 (and
6110 (setq begin-re
6111 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6112 (save-excursion
6113 (setq last-forward (point))
6114 ;; Look for the supplementary keyword
6115 ;; (bounded by the backward search start
6116 ;; point).
6117 (while (and (not foundp)
6118 (re-search-forward begin-re
6119 last-backward t)
6120 (goto-char (match-beginning 1)))
6121 ;; If we are in a literal, then try again.
6122 (if (or (= (preceding-char) ?_)
6123 (setq literal
6124 (vhdl-in-literal)))
6125 (if (eq literal 'comment)
6126 (goto-char
6127 (min (vhdl-point 'eol) last-backward))
6128 (forward-char))
6129 ;; We have found the supplementary keyword.
6130 ;; Save the position of the keyword in foundp.
6131 (setq foundp (point)))
6133 foundp)
6134 ;; If the supplementary keyword was found, then
6135 ;; move point to the supplementary keyword.
6136 (goto-char foundp))
6137 ;; If there was no supplementary keyword, then
6138 ;; point is already at the statement keyword.
6139 (setq foundp t)))
6140 ) ; end of the search for the statement keyword
6141 (if (not foundp)
6142 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6144 (setq count (1- count))
6146 (setq target (point)))
6147 (goto-char target)
6148 nil))
6150 (defun vhdl-backward-up-list (&optional count limit)
6151 "Move backward out of one level of blocks.
6152 With argument, do this that many times."
6153 (interactive "p")
6154 (let ((count (or count 1))
6155 target)
6156 (save-excursion
6157 (while (> count 0)
6158 (if (looking-at vhdl-defun-re)
6159 (error "ERROR: Unbalanced blocks"))
6160 (vhdl-backward-to-block limit)
6161 (setq count (1- count)))
6162 (setq target (point)))
6163 (goto-char target)))
6165 (defun vhdl-end-of-defun (&optional count)
6166 "Move forward to the end of a VHDL defun."
6167 (interactive)
6168 (let ((case-fold-search t))
6169 (vhdl-beginning-of-defun)
6170 (if (not (looking-at "block\\|process\\|procedural"))
6171 (re-search-forward "\\bis\\b"))
6172 (vhdl-forward-sexp)))
6174 (defun vhdl-mark-defun ()
6175 "Put mark at end of this \"defun\", point at beginning."
6176 (interactive)
6177 (let ((case-fold-search t))
6178 (push-mark)
6179 (vhdl-beginning-of-defun)
6180 (push-mark)
6181 (if (not (looking-at "block\\|process\\|procedural"))
6182 (re-search-forward "\\bis\\b"))
6183 (vhdl-forward-sexp)
6184 (exchange-point-and-mark)))
6186 (defun vhdl-beginning-of-libunit ()
6187 "Move backward to the beginning of a VHDL library unit.
6188 Returns the location of the corresponding begin keyword, unless search
6189 stops due to beginning or end of buffer.
6190 Note that if point is between the \"libunit\" keyword and the
6191 corresponding \"begin\" keyword, then that libunit will not be
6192 recognized, and the search will continue backwards. If point is
6193 at the \"begin\" keyword, then the defun will be recognized. The
6194 returned point is at the first character of the \"libunit\" keyword."
6195 (let ((last-forward (point))
6196 (last-backward
6197 ;; Just in case we are actually sitting on the "begin"
6198 ;; keyword, allow for the keyword and an extra character,
6199 ;; as this will be used when looking forward for the
6200 ;; "begin" keyword.
6201 (save-excursion (forward-word 1) (1+ (point))))
6202 foundp literal placeholder)
6203 ;; Find the "libunit" keyword.
6204 (while (and (not foundp)
6205 (re-search-backward vhdl-libunit-re nil 'move))
6206 ;; If we are in a literal, or not at a real libunit, then try again.
6207 (if (or (= (preceding-char) ?_)
6208 (vhdl-in-literal)
6209 (not (vhdl-libunit-p)))
6210 (backward-char)
6211 ;; Find the corresponding "begin" keyword.
6212 (setq last-forward (point))
6213 (while (and (not foundp)
6214 (re-search-forward "\\bis\\b[^_]" last-backward t)
6215 (setq placeholder (match-beginning 0)))
6216 (if (or (= (preceding-char) ?_)
6217 (setq literal (vhdl-in-literal)))
6218 ;; It wasn't a real keyword, so keep searching.
6219 (if (eq literal 'comment)
6220 (goto-char
6221 (min (vhdl-point 'eol) last-backward))
6222 (forward-char))
6223 ;; We have found the begin keyword, loop will exit.
6224 (setq foundp placeholder)))
6225 ;; Go back to the libunit keyword
6226 (goto-char last-forward)))
6227 foundp))
6229 (defun vhdl-beginning-of-defun (&optional count)
6230 "Move backward to the beginning of a VHDL defun.
6231 With argument, do it that many times.
6232 Returns the location of the corresponding begin keyword, unless search
6233 stops due to beginning or end of buffer."
6234 ;; Note that if point is between the "defun" keyword and the
6235 ;; corresponding "begin" keyword, then that defun will not be
6236 ;; recognized, and the search will continue backwards. If point is
6237 ;; at the "begin" keyword, then the defun will be recognized. The
6238 ;; returned point is at the first character of the "defun" keyword.
6239 (interactive "p")
6240 (let ((count (or count 1))
6241 (case-fold-search t)
6242 (last-forward (point))
6243 foundp)
6244 (while (> count 0)
6245 (setq foundp nil)
6246 (goto-char last-forward)
6247 (let ((last-backward
6248 ;; Just in case we are actually sitting on the "begin"
6249 ;; keyword, allow for the keyword and an extra character,
6250 ;; as this will be used when looking forward for the
6251 ;; "begin" keyword.
6252 (save-excursion (forward-word 1) (1+ (point))))
6253 begin-string literal)
6254 (while (and (not foundp)
6255 (re-search-backward vhdl-defun-re nil 'move))
6256 ;; If we are in a literal, then try again.
6257 (if (or (= (preceding-char) ?_)
6258 (vhdl-in-literal))
6259 (backward-char)
6260 (if (setq begin-string (vhdl-corresponding-defun))
6261 ;; This is a real defun keyword.
6262 ;; Find the corresponding "begin" keyword.
6263 ;; Look for the begin keyword.
6264 (progn
6265 ;; Save the search start point.
6266 (setq last-forward (point))
6267 (while (and (not foundp)
6268 (search-forward begin-string last-backward t))
6269 (if (or (= (preceding-char) ?_)
6270 (save-match-data
6271 (setq literal (vhdl-in-literal))))
6272 ;; It wasn't a real keyword, so keep searching.
6273 (if (eq literal 'comment)
6274 (goto-char
6275 (min (vhdl-point 'eol) last-backward))
6276 (forward-char))
6277 ;; We have found the begin keyword, loop will exit.
6278 (setq foundp (match-beginning 0)))
6280 ;; Go back to the defun keyword
6281 (goto-char last-forward)) ; end search for begin keyword
6283 ) ; end of the search for the defun keyword
6285 (setq count (1- count))
6287 (vhdl-keep-region-active)
6288 foundp))
6290 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6291 "Go to the beginning of the innermost VHDL statement.
6292 With prefix arg, go back N - 1 statements. If already at the
6293 beginning of a statement then go to the beginning of the preceding
6294 one. If within a string or comment, or next to a comment (only
6295 whitespace between), move by sentences instead of statements.
6297 When called from a program, this function takes 3 optional args: the
6298 prefix arg, a buffer position limit which is the farthest back to
6299 search, and an argument indicating an interactive call."
6300 (interactive "p\np")
6301 (let ((count (or count 1))
6302 (case-fold-search t)
6303 (lim (or lim (point-min)))
6304 (here (point))
6305 state)
6306 (save-excursion
6307 (goto-char lim)
6308 (setq state (parse-partial-sexp (point) here nil nil)))
6309 (if (and interactive
6310 (or (nth 3 state)
6311 (nth 4 state)
6312 (looking-at (concat "[ \t]*" comment-start-skip))))
6313 (forward-sentence (- count))
6314 (while (> count 0)
6315 (vhdl-beginning-of-statement-1 lim)
6316 (setq count (1- count))))
6317 ;; its possible we've been left up-buf of lim
6318 (goto-char (max (point) lim))
6320 (vhdl-keep-region-active))
6322 (defconst vhdl-e-o-s-re
6323 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6325 (defun vhdl-end-of-statement ()
6326 "Very simple implementation."
6327 (interactive)
6328 (re-search-forward vhdl-e-o-s-re))
6330 (defconst vhdl-b-o-s-re
6331 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6332 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6334 (defun vhdl-beginning-of-statement-1 (&optional lim)
6335 "Move to the start of the current statement, or the previous
6336 statement if already at the beginning of one."
6337 (let ((lim (or lim (point-min)))
6338 (here (point))
6339 (pos (point))
6340 donep)
6341 ;; go backwards one balanced expression, but be careful of
6342 ;; unbalanced paren being reached
6343 (if (not (vhdl-safe (progn (backward-sexp) t)))
6344 (progn
6345 (backward-up-list 1)
6346 (forward-char)
6347 (vhdl-forward-syntactic-ws here)
6348 (setq donep t)))
6349 (while (and (not donep)
6350 (not (bobp))
6351 ;; look backwards for a statement boundary
6352 (re-search-backward vhdl-b-o-s-re lim 'move))
6353 (if (or (= (preceding-char) ?_)
6354 (vhdl-in-literal))
6355 (backward-char)
6356 (cond
6357 ;; If we are looking at an open paren, then stop after it
6358 ((eq (following-char) ?\()
6359 (forward-char)
6360 (vhdl-forward-syntactic-ws here)
6361 (setq donep t))
6362 ;; If we are looking at a close paren, then skip it
6363 ((eq (following-char) ?\))
6364 (forward-char)
6365 (setq pos (point))
6366 (backward-sexp)
6367 (if (< (point) lim)
6368 (progn (goto-char pos)
6369 (vhdl-forward-syntactic-ws here)
6370 (setq donep t))))
6371 ;; If we are looking at a semicolon, then stop
6372 ((eq (following-char) ?\;)
6373 (progn
6374 (forward-char)
6375 (vhdl-forward-syntactic-ws here)
6376 (setq donep t)))
6377 ;; If we are looking at a "begin", then stop
6378 ((and (looking-at vhdl-begin-fwd-re)
6379 (/= (preceding-char) ?_)
6380 (vhdl-begin-p nil))
6381 ;; If it's a leader "begin", then find the
6382 ;; right place
6383 (if (looking-at vhdl-leader-re)
6384 (save-excursion
6385 ;; set a default stop point at the begin
6386 (setq pos (point))
6387 ;; is the start point inside the leader area ?
6388 (goto-char (vhdl-end-of-leader))
6389 (vhdl-forward-syntactic-ws here)
6390 (if (< (point) here)
6391 ;; start point was not inside leader area
6392 ;; set stop point at word after leader
6393 (setq pos (point))))
6394 (forward-word 1)
6395 (vhdl-forward-syntactic-ws here)
6396 (setq pos (point)))
6397 (goto-char pos)
6398 (setq donep t))
6399 ;; If we are looking at a "statement", then stop
6400 ((and (looking-at vhdl-statement-fwd-re)
6401 (/= (preceding-char) ?_)
6402 (vhdl-statement-p nil))
6403 (setq donep t))
6404 ;; If we are looking at a case alternative key, then stop
6405 ((and (looking-at vhdl-case-alternative-re)
6406 (vhdl-case-alternative-p lim))
6407 (save-excursion
6408 ;; set a default stop point at the when
6409 (setq pos (point))
6410 ;; is the start point inside the case alternative key ?
6411 (looking-at vhdl-case-alternative-re)
6412 (goto-char (match-end 0))
6413 (vhdl-forward-syntactic-ws here)
6414 (if (< (point) here)
6415 ;; start point was not inside the case alternative key
6416 ;; set stop point at word after case alternative keyleader
6417 (setq pos (point))))
6418 (goto-char pos)
6419 (setq donep t))
6420 ;; Bogus find, continue
6422 (backward-char)))))
6425 ;; Defuns for calculating the current syntactic state:
6427 (defun vhdl-get-library-unit (bod placeholder)
6428 "If there is an enclosing library unit at BOD, with its \"begin\"
6429 keyword at PLACEHOLDER, then return the library unit type."
6430 (let ((here (vhdl-point 'bol)))
6431 (if (save-excursion
6432 (goto-char placeholder)
6433 (vhdl-safe (vhdl-forward-sexp 1 bod))
6434 (<= here (point)))
6435 (save-excursion
6436 (goto-char bod)
6437 (cond
6438 ((looking-at "e") 'entity)
6439 ((looking-at "a") 'architecture)
6440 ((looking-at "c") 'configuration)
6441 ((looking-at "p")
6442 (save-excursion
6443 (goto-char bod)
6444 (forward-sexp)
6445 (vhdl-forward-syntactic-ws here)
6446 (if (looking-at "body\\b[^_]")
6447 'package-body 'package))))))
6450 (defun vhdl-get-block-state (&optional lim)
6451 "Finds and records all the closest opens.
6452 LIM is the furthest back we need to search (it should be the
6453 previous libunit keyword)."
6454 (let ((here (point))
6455 (lim (or lim (point-min)))
6456 keyword sexp-start sexp-mid sexp-end
6457 preceding-sexp containing-sexp
6458 containing-begin containing-mid containing-paren)
6459 (save-excursion
6460 ;; Find the containing-paren, and use that as the limit
6461 (if (setq containing-paren
6462 (save-restriction
6463 (narrow-to-region lim (point))
6464 (vhdl-safe (scan-lists (point) -1 1))))
6465 (setq lim containing-paren))
6466 ;; Look backwards for "begin" and "end" keywords.
6467 (while (and (> (point) lim)
6468 (not containing-sexp))
6469 (setq keyword (vhdl-backward-to-block lim))
6470 (cond
6471 ((eq keyword 'begin)
6472 ;; Found a "begin" keyword
6473 (setq sexp-start (point))
6474 (setq sexp-mid (vhdl-corresponding-mid lim))
6475 (setq sexp-end (vhdl-safe
6476 (save-excursion
6477 (vhdl-forward-sexp 1 lim) (point))))
6478 (if (and sexp-end (<= sexp-end here))
6479 ;; we want to record this sexp, but we only want to
6480 ;; record the last-most of any of them before here
6481 (or preceding-sexp
6482 (setq preceding-sexp sexp-start))
6483 ;; we're contained in this sexp so put sexp-start on
6484 ;; front of list
6485 (setq containing-sexp sexp-start)
6486 (setq containing-mid sexp-mid)
6487 (setq containing-begin t)))
6488 ((eq keyword 'end)
6489 ;; Found an "end" keyword
6490 (forward-sexp)
6491 (setq sexp-end (point))
6492 (setq sexp-mid nil)
6493 (setq sexp-start
6494 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6495 (progn (backward-sexp) (point))))
6496 ;; we want to record this sexp, but we only want to
6497 ;; record the last-most of any of them before here
6498 (or preceding-sexp
6499 (setq preceding-sexp sexp-start)))
6501 ;; Check if the containing-paren should be the containing-sexp
6502 (if (and containing-paren
6503 (or (null containing-sexp)
6504 (< containing-sexp containing-paren)))
6505 (setq containing-sexp containing-paren
6506 preceding-sexp nil
6507 containing-begin nil
6508 containing-mid nil))
6509 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6513 (defconst vhdl-s-c-a-re
6514 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6516 (defun vhdl-skip-case-alternative (&optional lim)
6517 "Skip forward over case/when bodies, with optional maximal
6518 limit. If no next case alternative is found, nil is returned and
6519 point is not moved."
6520 (let ((lim (or lim (point-max)))
6521 (here (point))
6522 donep foundp)
6523 (while (and (< (point) lim)
6524 (not donep))
6525 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6526 (save-match-data
6527 (not (vhdl-in-literal)))
6528 (/= (match-beginning 0) here))
6529 (progn
6530 (goto-char (match-beginning 0))
6531 (cond
6532 ((and (looking-at "case")
6533 (re-search-forward "\\bis[^_]" lim t))
6534 (backward-sexp)
6535 (vhdl-forward-sexp))
6537 (setq donep t
6538 foundp t))))))
6539 (if (not foundp)
6540 (goto-char here))
6541 foundp))
6543 (defun vhdl-backward-skip-label (&optional lim)
6544 "Skip backward over a label, with optional maximal
6545 limit. If label is not found, nil is returned and point
6546 is not moved."
6547 (let ((lim (or lim (point-min)))
6548 placeholder)
6549 (if (save-excursion
6550 (vhdl-backward-syntactic-ws lim)
6551 (and (eq (preceding-char) ?:)
6552 (progn
6553 (backward-sexp)
6554 (setq placeholder (point))
6555 (looking-at vhdl-label-key))))
6556 (goto-char placeholder))
6559 (defun vhdl-forward-skip-label (&optional lim)
6560 "Skip forward over a label, with optional maximal
6561 limit. If label is not found, nil is returned and point
6562 is not moved."
6563 (let ((lim (or lim (point-max))))
6564 (if (looking-at vhdl-label-key)
6565 (progn
6566 (goto-char (match-end 0))
6567 (vhdl-forward-syntactic-ws lim)))
6570 (defun vhdl-get-syntactic-context ()
6571 "Guess the syntactic description of the current line of VHDL code."
6572 (save-excursion
6573 (save-restriction
6574 (beginning-of-line)
6575 (let* ((indent-point (point))
6576 (case-fold-search t)
6577 vec literal containing-sexp preceding-sexp
6578 containing-begin containing-mid containing-leader
6579 char-before-ip char-after-ip begin-after-ip end-after-ip
6580 placeholder lim library-unit
6583 ;; Reset the syntactic context
6584 (setq vhdl-syntactic-context nil)
6586 (save-excursion
6587 ;; Move to the start of the previous library unit, and
6588 ;; record the position of the "begin" keyword.
6589 (setq placeholder (vhdl-beginning-of-libunit))
6590 ;; The position of the "libunit" keyword gives us a gross
6591 ;; limit point.
6592 (setq lim (point))
6595 ;; If there is a previous library unit, and we are enclosed by
6596 ;; it, then set the syntax accordingly.
6597 (and placeholder
6598 (setq library-unit (vhdl-get-library-unit lim placeholder))
6599 (vhdl-add-syntax library-unit lim))
6601 ;; Find the surrounding state.
6602 (if (setq vec (vhdl-get-block-state lim))
6603 (progn
6604 (setq containing-sexp (aref vec 0))
6605 (setq preceding-sexp (aref vec 1))
6606 (setq containing-begin (aref vec 2))
6607 (setq containing-mid (aref vec 3))
6610 ;; set the limit on the farthest back we need to search
6611 (setq lim (if containing-sexp
6612 (save-excursion
6613 (goto-char containing-sexp)
6614 ;; set containing-leader if required
6615 (if (looking-at vhdl-leader-re)
6616 (setq containing-leader (vhdl-end-of-leader)))
6617 (vhdl-point 'bol))
6618 (point-min)))
6620 ;; cache char before and after indent point, and move point to
6621 ;; the most likely position to perform the majority of tests
6622 (goto-char indent-point)
6623 (skip-chars-forward " \t")
6624 (setq literal (vhdl-in-literal))
6625 (setq char-after-ip (following-char))
6626 (setq begin-after-ip (and
6627 (not literal)
6628 (looking-at vhdl-begin-fwd-re)
6629 (vhdl-begin-p)))
6630 (setq end-after-ip (and
6631 (not literal)
6632 (looking-at vhdl-end-fwd-re)
6633 (vhdl-end-p)))
6634 (vhdl-backward-syntactic-ws lim)
6635 (setq char-before-ip (preceding-char))
6636 (goto-char indent-point)
6637 (skip-chars-forward " \t")
6639 ;; now figure out syntactic qualities of the current line
6640 (cond
6641 ;; CASE 1: in a string or comment.
6642 ((memq literal '(string comment))
6643 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6644 ;; CASE 2: Line is at top level.
6645 ((null containing-sexp)
6646 ;; Find the point to which indentation will be relative
6647 (save-excursion
6648 (if (null preceding-sexp)
6649 ;; CASE 2X.1
6650 ;; no preceding-sexp -> use the preceding statement
6651 (vhdl-beginning-of-statement-1 lim)
6652 ;; CASE 2X.2
6653 ;; if there is a preceding-sexp then indent relative to it
6654 (goto-char preceding-sexp)
6655 ;; if not at boi, then the block-opening keyword is
6656 ;; probably following a label, so we need a different
6657 ;; relpos
6658 (if (/= (point) (vhdl-point 'boi))
6659 ;; CASE 2X.3
6660 (vhdl-beginning-of-statement-1 lim)))
6661 ;; v-b-o-s could have left us at point-min
6662 (and (bobp)
6663 ;; CASE 2X.4
6664 (vhdl-forward-syntactic-ws indent-point))
6665 (setq placeholder (point)))
6666 (cond
6667 ;; CASE 2A : we are looking at a block-open
6668 (begin-after-ip
6669 (vhdl-add-syntax 'block-open placeholder))
6670 ;; CASE 2B: we are looking at a block-close
6671 (end-after-ip
6672 (vhdl-add-syntax 'block-close placeholder))
6673 ;; CASE 2C: we are looking at a top-level statement
6674 ((progn
6675 (vhdl-backward-syntactic-ws lim)
6676 (or (bobp)
6677 (= (preceding-char) ?\;)))
6678 (vhdl-add-syntax 'statement placeholder))
6679 ;; CASE 2D: we are looking at a top-level statement-cont
6681 (vhdl-beginning-of-statement-1 lim)
6682 ;; v-b-o-s could have left us at point-min
6683 (and (bobp)
6684 ;; CASE 2D.1
6685 (vhdl-forward-syntactic-ws indent-point))
6686 (vhdl-add-syntax 'statement-cont (point)))
6687 )) ; end CASE 2
6688 ;; CASE 3: line is inside parentheses. Most likely we are
6689 ;; either in a subprogram argument (interface) list, or a
6690 ;; continued expression containing parentheses.
6691 ((null containing-begin)
6692 (vhdl-backward-syntactic-ws containing-sexp)
6693 (cond
6694 ;; CASE 3A: we are looking at the arglist closing paren
6695 ((eq char-after-ip ?\))
6696 (goto-char containing-sexp)
6697 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6698 ;; CASE 3B: we are looking at the first argument in an empty
6699 ;; argument list.
6700 ((eq char-before-ip ?\()
6701 (goto-char containing-sexp)
6702 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6703 ;; CASE 3C: we are looking at an arglist continuation line,
6704 ;; but the preceding argument is on the same line as the
6705 ;; opening paren. This case includes multi-line
6706 ;; expression paren groupings.
6707 ((and (save-excursion
6708 (goto-char (1+ containing-sexp))
6709 (skip-chars-forward " \t")
6710 (not (eolp))
6711 (not (looking-at "--")))
6712 (save-excursion
6713 (vhdl-beginning-of-statement-1 containing-sexp)
6714 (skip-chars-backward " \t(")
6715 (<= (point) containing-sexp)))
6716 (goto-char containing-sexp)
6717 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6718 ;; CASE 3D: we are looking at just a normal arglist
6719 ;; continuation line
6720 (t (vhdl-beginning-of-statement-1 containing-sexp)
6721 (vhdl-forward-syntactic-ws indent-point)
6722 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6724 ;; CASE 4: A block mid open
6725 ((and begin-after-ip
6726 (looking-at containing-mid))
6727 (goto-char containing-sexp)
6728 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6729 (if (looking-at vhdl-trailer-re)
6730 ;; CASE 4.1
6731 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6732 (vhdl-backward-skip-label (vhdl-point 'boi))
6733 (vhdl-add-syntax 'block-open (point)))
6734 ;; CASE 5: block close brace
6735 (end-after-ip
6736 (goto-char containing-sexp)
6737 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6738 (if (looking-at vhdl-trailer-re)
6739 ;; CASE 5.1
6740 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6741 (vhdl-backward-skip-label (vhdl-point 'boi))
6742 (vhdl-add-syntax 'block-close (point)))
6743 ;; CASE 6: A continued statement
6744 ((and (/= char-before-ip ?\;)
6745 ;; check it's not a trailer begin keyword, or a begin
6746 ;; keyword immediately following a label.
6747 (not (and begin-after-ip
6748 (or (looking-at vhdl-trailer-re)
6749 (save-excursion
6750 (vhdl-backward-skip-label containing-sexp)))))
6751 ;; check it's not a statement keyword
6752 (not (and (looking-at vhdl-statement-fwd-re)
6753 (vhdl-statement-p)))
6754 ;; see if the b-o-s is before the indent point
6755 (> indent-point
6756 (save-excursion
6757 (vhdl-beginning-of-statement-1 containing-sexp)
6758 ;; If we ended up after a leader, then this will
6759 ;; move us forward to the start of the first
6760 ;; statement. Note that a containing sexp here is
6761 ;; always a keyword, not a paren, so this will
6762 ;; have no effect if we hit the containing-sexp.
6763 (vhdl-forward-syntactic-ws indent-point)
6764 (setq placeholder (point))))
6765 ;; check it's not a block-intro
6766 (/= placeholder containing-sexp)
6767 ;; check it's not a case block-intro
6768 (save-excursion
6769 (goto-char placeholder)
6770 (or (not (looking-at vhdl-case-alternative-re))
6771 (> (match-end 0) indent-point))))
6772 ;; Make placeholder skip a label, but only if it puts us
6773 ;; before the indent point at the start of a line.
6774 (let ((new placeholder))
6775 (if (and (> indent-point
6776 (save-excursion
6777 (goto-char placeholder)
6778 (vhdl-forward-skip-label indent-point)
6779 (setq new (point))))
6780 (save-excursion
6781 (goto-char new)
6782 (eq new (progn (back-to-indentation) (point)))))
6783 (setq placeholder new)))
6784 (vhdl-add-syntax 'statement-cont placeholder)
6785 (if begin-after-ip
6786 (vhdl-add-syntax 'block-open)))
6787 ;; Statement. But what kind?
6788 ;; CASE 7: A case alternative key
6789 ((and (looking-at vhdl-case-alternative-re)
6790 (vhdl-case-alternative-p containing-sexp))
6791 ;; for a case alternative key, we set relpos to the first
6792 ;; non-whitespace char on the line containing the "case"
6793 ;; keyword.
6794 (goto-char containing-sexp)
6795 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6796 (if (looking-at vhdl-trailer-re)
6797 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6798 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6799 ;; CASE 8: statement catchall
6801 ;; we know its a statement, but we need to find out if it is
6802 ;; the first statement in a block
6803 (if containing-leader
6804 (goto-char containing-leader)
6805 (goto-char containing-sexp)
6806 ;; Note that a containing sexp here is always a keyword,
6807 ;; not a paren, so skip over the keyword.
6808 (forward-sexp))
6809 ;; move to the start of the first statement
6810 (vhdl-forward-syntactic-ws indent-point)
6811 (setq placeholder (point))
6812 ;; we want to ignore case alternatives keys when skipping forward
6813 (let (incase-p)
6814 (while (looking-at vhdl-case-alternative-re)
6815 (setq incase-p (point))
6816 ;; we also want to skip over the body of the
6817 ;; case/when statement if that doesn't put us at
6818 ;; after the indent-point
6819 (while (vhdl-skip-case-alternative indent-point))
6820 ;; set up the match end
6821 (looking-at vhdl-case-alternative-re)
6822 (goto-char (match-end 0))
6823 ;; move to the start of the first case alternative statement
6824 (vhdl-forward-syntactic-ws indent-point)
6825 (setq placeholder (point)))
6826 (cond
6827 ;; CASE 8A: we saw a case/when statement so we must be
6828 ;; in a switch statement. find out if we are at the
6829 ;; statement just after a case alternative key
6830 ((and incase-p
6831 (= (point) indent-point))
6832 ;; relpos is the "when" keyword
6833 (vhdl-add-syntax 'statement-case-intro incase-p))
6834 ;; CASE 8B: any old statement
6835 ((< (point) indent-point)
6836 ;; relpos is the first statement of the block
6837 (vhdl-add-syntax 'statement placeholder)
6838 (if begin-after-ip
6839 (vhdl-add-syntax 'block-open)))
6840 ;; CASE 8C: first statement in a block
6842 (goto-char containing-sexp)
6843 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6844 (if (looking-at vhdl-trailer-re)
6845 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6846 (vhdl-backward-skip-label (vhdl-point 'boi))
6847 (vhdl-add-syntax 'statement-block-intro (point))
6848 (if begin-after-ip
6849 (vhdl-add-syntax 'block-open)))
6853 ;; now we need to look at any modifiers
6854 (goto-char indent-point)
6855 (skip-chars-forward " \t")
6856 (if (looking-at "--")
6857 (vhdl-add-syntax 'comment))
6858 (if (eq literal 'pound)
6859 (vhdl-add-syntax 'cpp-macro))
6860 ;; return the syntax
6861 vhdl-syntactic-context))))
6863 ;; Standard indentation line-ups:
6865 (defun vhdl-lineup-arglist (langelem)
6866 "Lineup the current arglist line with the arglist appearing just
6867 after the containing paren which starts the arglist."
6868 (save-excursion
6869 (let* ((containing-sexp
6870 (save-excursion
6871 ;; arglist-cont-nonempty gives relpos ==
6872 ;; to boi of containing-sexp paren. This
6873 ;; is good when offset is +, but bad
6874 ;; when it is vhdl-lineup-arglist, so we
6875 ;; have to special case a kludge here.
6876 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6877 (progn
6878 (beginning-of-line)
6879 (backward-up-list 1)
6880 (skip-chars-forward " \t" (vhdl-point 'eol)))
6881 (goto-char (cdr langelem)))
6882 (point)))
6883 (cs-curcol (save-excursion
6884 (goto-char (cdr langelem))
6885 (current-column))))
6886 (if (save-excursion
6887 (beginning-of-line)
6888 (looking-at "[ \t]*)"))
6889 (progn (goto-char (match-end 0))
6890 (backward-sexp)
6891 (forward-char)
6892 (vhdl-forward-syntactic-ws)
6893 (- (current-column) cs-curcol))
6894 (goto-char containing-sexp)
6895 (or (eolp)
6896 (let ((eol (vhdl-point 'eol))
6897 (here (progn
6898 (forward-char)
6899 (skip-chars-forward " \t")
6900 (point))))
6901 (vhdl-forward-syntactic-ws)
6902 (if (< (point) eol)
6903 (goto-char here))))
6904 (- (current-column) cs-curcol)
6905 ))))
6907 (defun vhdl-lineup-arglist-intro (langelem)
6908 "Lineup an arglist-intro line to just after the open paren."
6909 (save-excursion
6910 (let ((cs-curcol (save-excursion
6911 (goto-char (cdr langelem))
6912 (current-column)))
6913 (ce-curcol (save-excursion
6914 (beginning-of-line)
6915 (backward-up-list 1)
6916 (skip-chars-forward " \t" (vhdl-point 'eol))
6917 (current-column))))
6918 (- ce-curcol cs-curcol -1))))
6920 (defun vhdl-lineup-comment (langelem)
6921 "Support old behavior for comment indentation. We look at
6922 vhdl-comment-only-line-offset to decide how to indent comment
6923 only-lines."
6924 (save-excursion
6925 (back-to-indentation)
6926 ;; at or to the right of comment-column
6927 (if (>= (current-column) comment-column)
6928 (vhdl-comment-indent)
6929 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6930 (if (not (bolp))
6931 (or (car-safe vhdl-comment-only-line-offset)
6932 vhdl-comment-only-line-offset)
6933 (or (cdr-safe vhdl-comment-only-line-offset)
6934 (car-safe vhdl-comment-only-line-offset)
6935 -1000 ;jam it against the left side
6936 )))))
6938 (defun vhdl-lineup-statement-cont (langelem)
6939 "Line up statement-cont after the assignment operator."
6940 (save-excursion
6941 (let* ((relpos (cdr langelem))
6942 (assignp (save-excursion
6943 (goto-char (vhdl-point 'boi))
6944 (and (re-search-forward "\\(<\\|:\\)="
6945 (vhdl-point 'eol) t)
6946 (- (point) (vhdl-point 'boi)))))
6947 (curcol (progn
6948 (goto-char relpos)
6949 (current-column)))
6950 foundp)
6951 (while (and (not foundp)
6952 (< (point) (vhdl-point 'eol)))
6953 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6954 (if (vhdl-in-literal)
6955 (forward-char)
6956 (if (= (preceding-char) ?\()
6957 ;; skip over any parenthesized expressions
6958 (goto-char (min (vhdl-point 'eol)
6959 (scan-lists (point) 1 1)))
6960 ;; found an assignment operator (not at eol)
6961 (setq foundp (not (looking-at "\\s-*$"))))))
6962 (if (not foundp)
6963 ;; there's no assignment operator on the line
6964 vhdl-basic-offset
6965 ;; calculate indentation column after assign and ws, unless
6966 ;; our line contains an assignment operator
6967 (if (not assignp)
6968 (progn
6969 (forward-char)
6970 (skip-chars-forward " \t")
6971 (setq assignp 0)))
6972 (- (current-column) assignp curcol))
6975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6976 ;; Progress reporting
6978 (defvar vhdl-progress-info nil
6979 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6981 (defun vhdl-update-progress-info (string pos)
6982 "Update progress information."
6983 (when (and vhdl-progress-info (not noninteractive)
6984 (< vhdl-progress-interval
6985 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6986 (let ((delta (- (aref vhdl-progress-info 1)
6987 (aref vhdl-progress-info 0))))
6988 (if (= 0 delta)
6989 (message (concat string "... (100%s)") "%")
6990 (message (concat string "... (%2d%s)")
6991 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6992 delta) "%")))
6993 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6996 ;; Indentation commands
6998 (defun vhdl-electric-tab (&optional prefix-arg)
6999 "If preceeding character is part of a word or a paren then hippie-expand,
7000 else if right of non whitespace on line then insert tab,
7001 else if last command was a tab or return then dedent one step or if a comment
7002 toggle between normal indent and inline comment indent,
7003 else indent `correctly'."
7004 (interactive "*P")
7005 (vhdl-prepare-search-2
7006 (cond
7007 ;; indent region if region is active
7008 ((and (not (featurep 'xemacs)) (use-region-p))
7009 (vhdl-indent-region (region-beginning) (region-end) nil))
7010 ;; expand word
7011 ((= (char-syntax (preceding-char)) ?w)
7012 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7013 (case-replace nil)
7014 (hippie-expand-only-buffers
7015 (or (and (boundp 'hippie-expand-only-buffers)
7016 hippie-expand-only-buffers)
7017 '(vhdl-mode))))
7018 (vhdl-expand-abbrev prefix-arg)))
7019 ;; expand parenthesis
7020 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7021 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7022 (case-replace nil))
7023 (vhdl-expand-paren prefix-arg)))
7024 ;; insert tab
7025 ((> (current-column) (current-indentation))
7026 (insert-tab))
7027 ;; toggle comment indent
7028 ((and (looking-at "--")
7029 (or (eq last-command 'vhdl-electric-tab)
7030 (eq last-command 'vhdl-electric-return)))
7031 (cond ((= (current-indentation) 0) ; no indent
7032 (indent-to 1)
7033 (indent-according-to-mode))
7034 ((< (current-indentation) comment-column) ; normal indent
7035 (indent-to comment-column)
7036 (indent-according-to-mode))
7037 (t ; inline comment indent
7038 (delete-region (line-beginning-position) (point)))))
7039 ;; dedent
7040 ((and (>= (current-indentation) vhdl-basic-offset)
7041 (or (eq last-command 'vhdl-electric-tab)
7042 (eq last-command 'vhdl-electric-return)))
7043 (backward-delete-char-untabify vhdl-basic-offset nil))
7044 ;; indent line
7045 (t (indent-according-to-mode)))
7046 (setq this-command 'vhdl-electric-tab)))
7048 (defun vhdl-electric-return ()
7049 "newline-and-indent or indent-new-comment-line if in comment and preceding
7050 character is a space."
7051 (interactive)
7052 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7053 (indent-new-comment-line)
7054 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7055 (vhdl-fix-case-word -1))
7056 (newline-and-indent)))
7058 (defun vhdl-indent-line ()
7059 "Indent the current line as VHDL code. Returns the amount of
7060 indentation change."
7061 (interactive)
7062 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7063 (pos (- (point-max) (point)))
7064 (indent
7065 (if syntax
7066 ;; indent syntax-based
7067 (if (and (eq (caar syntax) 'comment)
7068 (>= (vhdl-get-offset (car syntax)) comment-column))
7069 ;; special case: comments at or right of comment-column
7070 (vhdl-get-offset (car syntax))
7071 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7072 ;; indent like previous nonblank line
7073 (save-excursion (beginning-of-line)
7074 (re-search-backward "^[^\n]" nil t)
7075 (current-indentation))))
7076 (shift-amt (- indent (current-indentation))))
7077 (and vhdl-echo-syntactic-information-p
7078 (message "syntax: %s, indent= %d" syntax indent))
7079 (unless (zerop shift-amt)
7080 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7081 (beginning-of-line)
7082 (indent-to indent))
7083 (if (< (point) (vhdl-point 'boi))
7084 (back-to-indentation)
7085 ;; If initial point was within line's indentation, position after
7086 ;; the indentation. Else stay at same point in text.
7087 (when (> (- (point-max) pos) (point))
7088 (goto-char (- (point-max) pos))))
7089 (run-hooks 'vhdl-special-indent-hook)
7090 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7091 shift-amt))
7093 (defun vhdl-indent-region (beg end column)
7094 "Indent region as VHDL code.
7095 Adds progress reporting to `indent-region'."
7096 (interactive "r\nP")
7097 (when vhdl-progress-interval
7098 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7099 (count-lines (point-min) end) 0)))
7100 (indent-region beg end column)
7101 (when vhdl-progress-interval (message "Indenting...done"))
7102 (setq vhdl-progress-info nil))
7104 (defun vhdl-indent-buffer ()
7105 "Indent whole buffer as VHDL code.
7106 Calls `indent-region' for whole buffer and adds progress reporting."
7107 (interactive)
7108 (vhdl-indent-region (point-min) (point-max) nil))
7110 (defun vhdl-indent-group ()
7111 "Indent group of lines between empty lines."
7112 (interactive)
7113 (let ((beg (save-excursion
7114 (if (re-search-backward vhdl-align-group-separate nil t)
7115 (point-marker)
7116 (point-min-marker))))
7117 (end (save-excursion
7118 (if (re-search-forward vhdl-align-group-separate nil t)
7119 (point-marker)
7120 (point-max-marker)))))
7121 (vhdl-indent-region beg end nil)))
7123 (defun vhdl-indent-sexp (&optional endpos)
7124 "Indent each line of the list starting just after point.
7125 If optional arg ENDPOS is given, indent each line, stopping when
7126 ENDPOS is encountered."
7127 (interactive)
7128 (save-excursion
7129 (let ((beg (point))
7130 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7131 (indent-region beg end nil))))
7133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7134 ;; Miscellaneous commands
7136 (defun vhdl-show-syntactic-information ()
7137 "Show syntactic information for current line."
7138 (interactive)
7139 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7140 (vhdl-keep-region-active))
7142 ;; Verification and regression functions:
7144 (defun vhdl-regress-line (&optional arg)
7145 "Check syntactic information for current line."
7146 (interactive "P")
7147 (let ((expected (save-excursion
7148 (end-of-line)
7149 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7150 (forward-char 4)
7151 (read (current-buffer)))))
7152 (actual (vhdl-get-syntactic-context))
7153 (expurgated))
7154 ;; remove the library unit symbols
7155 (mapc
7156 (function
7157 (lambda (elt)
7158 (if (memq (car elt) '(entity configuration package
7159 package-body architecture))
7161 (setq expurgated (append expurgated (list elt))))))
7162 actual)
7163 (if (and (not arg) expected (listp expected))
7164 (if (not (equal expected expurgated))
7165 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7166 (save-excursion
7167 (beginning-of-line)
7168 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7169 (end-of-line)
7170 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7171 (delete-region (point) (line-end-position)))
7172 (insert " -- ")
7173 (insert (format "%s" expurgated))))))
7174 (vhdl-keep-region-active))
7177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7178 ;;; Alignment, whitespace fixup, beautifying
7179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7181 (defconst vhdl-align-alist
7183 ;; after some keywords
7184 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7185 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7186 ;; before ':'
7187 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7188 ;; after direction specifications
7189 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7190 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7191 ;; before "==", ":=", "=>", and "<="
7192 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7193 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7194 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7195 ;; before some keywords
7196 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7197 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7198 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7199 ;; before "=>" since "when/else ... =>" can occur
7200 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7202 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7203 It is searched in order. If REGEXP is found anywhere in the first
7204 line of a region to be aligned, ALIGN-PATTERN will be used for that
7205 region. ALIGN-PATTERN must include the whitespace to be expanded or
7206 contracted. It may also provide regexps for the text surrounding the
7207 whitespace. SUBEXP specifies which sub-expression of
7208 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7211 ;; Align code
7213 (defvar vhdl-align-try-all-clauses t
7214 "If REGEXP is not found on the first line of the region that clause
7215 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7217 (defun vhdl-do-group (function &optional spacing)
7218 "Apply FUNCTION on group of lines between empty lines."
7219 (let
7220 ;; search for group beginning
7221 ((beg (save-excursion
7222 (if (re-search-backward vhdl-align-group-separate nil t)
7223 (progn (beginning-of-line 2) (back-to-indentation) (point))
7224 (point-min))))
7225 ;; search for group end
7226 (end (save-excursion
7227 (if (re-search-forward vhdl-align-group-separate nil t)
7228 (progn (beginning-of-line) (point))
7229 (point-max)))))
7230 ;; run FUNCTION
7231 (funcall function beg end spacing)))
7233 (defun vhdl-do-list (function &optional spacing)
7234 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7235 parentheses."
7236 (let (beg end)
7237 (save-excursion
7238 ;; search for beginning of balanced group of parentheses
7239 (setq beg (vhdl-re-search-backward "[()]" nil t))
7240 (while (looking-at ")")
7241 (forward-char) (backward-sexp)
7242 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7243 ;; search for end of balanced group of parentheses
7244 (when beg
7245 (forward-list)
7246 (setq end (point))
7247 (goto-char (1+ beg))
7248 (skip-chars-forward " \t\n")
7249 (setq beg (point))))
7250 ;; run FUNCTION
7251 (if beg
7252 (funcall function beg end spacing)
7253 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7255 (defun vhdl-do-same-indent (function &optional spacing)
7256 "Apply FUNCTION to block of lines with same indent."
7257 (let ((indent (current-indentation))
7258 beg end)
7259 ;; search for first line with same indent
7260 (save-excursion
7261 (while (and (not (bobp))
7262 (or (looking-at "^\\s-*\\(--.*\\)?$")
7263 (= (current-indentation) indent)))
7264 (unless (looking-at "^\\s-*$")
7265 (back-to-indentation) (setq beg (point)))
7266 (beginning-of-line -0)))
7267 ;; search for last line with same indent
7268 (save-excursion
7269 (while (and (not (eobp))
7270 (or (looking-at "^\\s-*\\(--.*\\)?$")
7271 (= (current-indentation) indent)))
7272 (if (looking-at "^\\s-*$")
7273 (beginning-of-line 2)
7274 (beginning-of-line 2)
7275 (setq end (point)))))
7276 ;; run FUNCTION
7277 (funcall function beg end spacing)))
7279 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7280 "Attempt to align a range of lines based on the content of the
7281 lines. The definition of `alignment-list' determines the matching
7282 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7283 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7284 indentation is done before aligning."
7285 (interactive "r\np")
7286 (setq alignment-list (or alignment-list vhdl-align-alist))
7287 (setq spacing (or spacing 1))
7288 (save-excursion
7289 (let (bol indent)
7290 (goto-char end)
7291 (setq end (point-marker))
7292 (goto-char begin)
7293 (setq bol (setq begin (progn (beginning-of-line) (point))))
7294 ; (untabify bol end)
7295 (when indent
7296 (indent-region bol end nil))))
7297 (let ((copy (copy-alist alignment-list)))
7298 (vhdl-prepare-search-2
7299 (while copy
7300 (save-excursion
7301 (goto-char begin)
7302 (let (element
7303 (eol (save-excursion (progn (end-of-line) (point)))))
7304 (setq element (nth 0 copy))
7305 (when (and (or (and (listp (car element))
7306 (memq major-mode (car element)))
7307 (eq major-mode (car element)))
7308 (or vhdl-align-try-all-clauses
7309 (re-search-forward (car (cdr element)) eol t)))
7310 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7311 (car (cdr (cdr (cdr element)))) spacing))
7312 (setq copy (cdr copy))))))))
7314 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7315 "Align a range of lines from BEGIN to END. The regular expression
7316 MATCH must match exactly one field: the whitespace to be
7317 contracted/expanded. The alignment column will equal the
7318 rightmost column of the widest whitespace block. SPACING is
7319 the amount of extra spaces to add to the calculated maximum required.
7320 SPACING defaults to 1 so that at least one space is inserted after
7321 the token in MATCH."
7322 (setq spacing (or spacing 1))
7323 (setq substr (or substr 1))
7324 (save-excursion
7325 (let (distance (max 0) (lines 0) bol eol width)
7326 ;; Determine the greatest whitespace distance to the alignment
7327 ;; character
7328 (goto-char begin)
7329 (setq eol (progn (end-of-line) (point))
7330 bol (setq begin (progn (beginning-of-line) (point))))
7331 (while (< bol end)
7332 (save-excursion
7333 (when (and (re-search-forward match eol t)
7334 (not (vhdl-in-literal)))
7335 (setq distance (- (match-beginning substr) bol))
7336 (when (> distance max)
7337 (setq max distance))))
7338 (forward-line)
7339 (setq bol (point)
7340 eol (save-excursion (end-of-line) (point)))
7341 (setq lines (1+ lines)))
7342 ;; Now insert enough maxs to push each assignment operator to
7343 ;; the same column. We need to use 'lines' as a counter, since
7344 ;; the location of the mark may change
7345 (goto-char (setq bol begin))
7346 (setq eol (save-excursion (end-of-line) (point)))
7347 (while (> lines 0)
7348 (when (and (re-search-forward match eol t)
7349 (not (vhdl-in-literal)))
7350 (setq width (- (match-end substr) (match-beginning substr)))
7351 (setq distance (- (match-beginning substr) bol))
7352 (goto-char (match-beginning substr))
7353 (delete-char width)
7354 (insert-char ? (+ (- max distance) spacing)))
7355 (beginning-of-line)
7356 (forward-line)
7357 (setq bol (point)
7358 eol (save-excursion (end-of-line) (point)))
7359 (setq lines (1- lines))))))
7361 (defun vhdl-align-region-groups (beg end &optional spacing
7362 no-message no-comments)
7363 "Align region, treat groups of lines separately."
7364 (interactive "r\nP")
7365 (save-excursion
7366 (let (orig pos)
7367 (goto-char beg)
7368 (beginning-of-line)
7369 (setq orig (point-marker))
7370 (setq beg (point))
7371 (goto-char end)
7372 (setq end (point-marker))
7373 (untabify beg end)
7374 (unless no-message
7375 (when vhdl-progress-interval
7376 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7377 (count-lines (point-min) end) 0))))
7378 (vhdl-fixup-whitespace-region beg end t)
7379 (goto-char beg)
7380 (if (not vhdl-align-groups)
7381 ;; align entire region
7382 (progn (vhdl-align-region-1 beg end spacing)
7383 (unless no-comments
7384 (vhdl-align-inline-comment-region-1 beg end)))
7385 ;; align groups
7386 (while (and (< beg end)
7387 (re-search-forward vhdl-align-group-separate end t))
7388 (setq pos (point-marker))
7389 (vhdl-align-region-1 beg pos spacing)
7390 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7391 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7392 (setq beg (1+ pos))
7393 (goto-char beg))
7394 ;; align last group
7395 (when (< beg end)
7396 (vhdl-align-region-1 beg end spacing)
7397 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7398 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7399 (when vhdl-indent-tabs-mode
7400 (tabify orig end))
7401 (unless no-message
7402 (when vhdl-progress-interval (message "Aligning...done"))
7403 (setq vhdl-progress-info nil)))))
7405 (defun vhdl-align-region (beg end &optional spacing)
7406 "Align region, treat blocks with same indent and argument lists separately."
7407 (interactive "r\nP")
7408 (if (not vhdl-align-same-indent)
7409 ;; align entire region
7410 (vhdl-align-region-groups beg end spacing)
7411 ;; align blocks with same indent and argument lists
7412 (save-excursion
7413 (let ((cur-beg beg)
7414 indent cur-end)
7415 (when vhdl-progress-interval
7416 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7417 (count-lines (point-min) end) 0)))
7418 (goto-char end)
7419 (setq end (point-marker))
7420 (goto-char cur-beg)
7421 (while (< (point) end)
7422 ;; is argument list opening?
7423 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7424 (point) (vhdl-point 'eol)))))
7425 ;; determine region for argument list
7426 (progn (goto-char cur-beg)
7427 (forward-sexp)
7428 (setq cur-end (point))
7429 (beginning-of-line 2))
7430 ;; determine region with same indent
7431 (setq indent (current-indentation))
7432 (setq cur-beg (point))
7433 (setq cur-end (vhdl-point 'bonl))
7434 (beginning-of-line 2)
7435 (while (and (< (point) end)
7436 (or (looking-at "^\\s-*\\(--.*\\)?$")
7437 (= (current-indentation) indent))
7438 (<= (save-excursion
7439 (nth 0 (parse-partial-sexp
7440 (point) (vhdl-point 'eol)))) 0))
7441 (unless (looking-at "^\\s-*$")
7442 (setq cur-end (vhdl-point 'bonl)))
7443 (beginning-of-line 2)))
7444 ;; align region
7445 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7446 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7447 (when vhdl-progress-interval (message "Aligning...done"))
7448 (setq vhdl-progress-info nil)))))
7450 (defun vhdl-align-group (&optional spacing)
7451 "Align group of lines between empty lines."
7452 (interactive)
7453 (vhdl-do-group 'vhdl-align-region spacing))
7455 (defun vhdl-align-list (&optional spacing)
7456 "Align the lines of a list surrounded by a balanced group of parentheses."
7457 (interactive)
7458 (vhdl-do-list 'vhdl-align-region-groups spacing))
7460 (defun vhdl-align-same-indent (&optional spacing)
7461 "Align block of lines with same indent."
7462 (interactive)
7463 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7465 (defun vhdl-align-declarations (&optional spacing)
7466 "Align the lines within the declarative part of a design unit."
7467 (interactive)
7468 (let (beg end)
7469 (vhdl-prepare-search-2
7470 (save-excursion
7471 ;; search for declarative part
7472 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7473 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7474 (setq beg (point))
7475 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7476 (setq end (point)))))
7477 (if beg
7478 (vhdl-align-region-groups beg end spacing)
7479 (error "ERROR: Not within the declarative part of a design unit"))))
7481 (defun vhdl-align-buffer ()
7482 "Align buffer."
7483 (interactive)
7484 (vhdl-align-region (point-min) (point-max)))
7486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7487 ;; Align inline comments
7489 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7490 "Align inline comments in region."
7491 (save-excursion
7492 (let ((start-max comment-column)
7493 (length-max 0)
7494 comment-list start-list tmp-list start length
7495 cur-start prev-start no-code)
7496 (setq spacing (or spacing 2))
7497 (vhdl-prepare-search-2
7498 (goto-char beg)
7499 ;; search for comment start positions and lengths
7500 (while (< (point) end)
7501 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7502 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7503 (not (save-excursion (goto-char (match-beginning 2))
7504 (vhdl-in-literal))))
7505 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7506 (setq length (- (match-end 2) (match-beginning 2)))
7507 (setq start-max (max start start-max))
7508 (setq length-max (max length length-max))
7509 (setq comment-list (cons (cons start length) comment-list)))
7510 (beginning-of-line 2))
7511 (setq comment-list
7512 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7513 ;; reduce start positions
7514 (setq start-list (list (caar comment-list)))
7515 (setq comment-list (cdr comment-list))
7516 (while comment-list
7517 (unless (or (= (caar comment-list) (car start-list))
7518 (<= (+ (car start-list) (cdar comment-list))
7519 end-comment-column))
7520 (setq start-list (cons (caar comment-list) start-list)))
7521 (setq comment-list (cdr comment-list)))
7522 ;; align lines as nicely as possible
7523 (goto-char beg)
7524 (while (< (point) end)
7525 (setq cur-start nil)
7526 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7527 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7528 (not (save-excursion
7529 (goto-char (match-beginning 3))
7530 (vhdl-in-literal))))
7531 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7532 (>= (- (match-end 2) (match-beginning 2))
7533 comment-column))))
7534 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7535 (setq length (- (match-end 3) (match-beginning 3)))
7536 (setq no-code (= (match-beginning 1) (match-end 1)))
7537 ;; insert minimum whitespace
7538 (goto-char (match-end 2))
7539 (delete-region (match-beginning 2) (match-end 2))
7540 (insert-char ?\ spacing)
7541 (setq tmp-list start-list)
7542 ;; insert additional whitespace to align
7543 (setq cur-start
7544 (cond
7545 ;; align comment-only line to inline comment of previous line
7546 ((and no-code prev-start
7547 (<= length (- end-comment-column prev-start)))
7548 prev-start)
7549 ;; align all comments at `start-max' if this is possible
7550 ((<= (+ start-max length-max) end-comment-column)
7551 start-max)
7552 ;; align at `comment-column' if possible
7553 ((and (<= start comment-column)
7554 (<= length (- end-comment-column comment-column)))
7555 comment-column)
7556 ;; align at left-most possible start position otherwise
7558 (while (and tmp-list (< (car tmp-list) start))
7559 (setq tmp-list (cdr tmp-list)))
7560 (car tmp-list))))
7561 (indent-to cur-start))
7562 (setq prev-start cur-start)
7563 (beginning-of-line 2))))))
7565 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7566 "Align inline comments within a region. Groups of code lines separated by
7567 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7568 (interactive "r\nP")
7569 (save-excursion
7570 (let (orig pos)
7571 (goto-char beg)
7572 (beginning-of-line)
7573 (setq orig (point-marker))
7574 (setq beg (point))
7575 (goto-char end)
7576 (setq end (point-marker))
7577 (untabify beg end)
7578 (unless no-message (message "Aligning inline comments..."))
7579 (goto-char beg)
7580 (if (not vhdl-align-groups)
7581 ;; align entire region
7582 (vhdl-align-inline-comment-region-1 beg end spacing)
7583 ;; align groups
7584 (while (and (< beg end)
7585 (re-search-forward vhdl-align-group-separate end t))
7586 (setq pos (point-marker))
7587 (vhdl-align-inline-comment-region-1 beg pos spacing)
7588 (setq beg (1+ pos))
7589 (goto-char beg))
7590 ;; align last group
7591 (when (< beg end)
7592 (vhdl-align-inline-comment-region-1 beg end spacing)))
7593 (when vhdl-indent-tabs-mode
7594 (tabify orig end))
7595 (unless no-message (message "Aligning inline comments...done")))))
7597 (defun vhdl-align-inline-comment-group (&optional spacing)
7598 "Align inline comments within a group of lines between empty lines."
7599 (interactive)
7600 (save-excursion
7601 (let ((start (point))
7602 beg end)
7603 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7604 (point-marker) (point-max)))
7605 (goto-char start)
7606 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7607 (point) (point-min)))
7608 (untabify beg end)
7609 (message "Aligning inline comments...")
7610 (vhdl-align-inline-comment-region-1 beg end)
7611 (when vhdl-indent-tabs-mode
7612 (tabify beg end))
7613 (message "Aligning inline comments...done"))))
7615 (defun vhdl-align-inline-comment-buffer ()
7616 "Align inline comments within buffer. Groups of code lines separated by
7617 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7618 (interactive)
7619 (vhdl-align-inline-comment-region (point-min) (point-max)))
7621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7622 ;; Fixup whitespace
7624 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7625 "Fixup whitespace in region. Surround operator symbols by one space,
7626 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7627 end of line, do nothing in comments and strings."
7628 (interactive "r")
7629 (unless no-message (message "Fixing up whitespace..."))
7630 (save-excursion
7631 (goto-char end)
7632 (setq end (point-marker))
7633 ;; have no space before and one space after `,' and ';'
7634 (goto-char beg)
7635 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7636 (if (match-string 1)
7637 (goto-char (match-end 1))
7638 (replace-match "\\3 " nil nil nil 3)))
7639 ;; have no space after `('
7640 (goto-char beg)
7641 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7642 (if (match-string 1)
7643 (goto-char (match-end 1))
7644 (replace-match "\\2")))
7645 ;; have no space before `)'
7646 (goto-char beg)
7647 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7648 (if (match-string 1)
7649 (goto-char (match-end 1))
7650 (replace-match "\\2")))
7651 ;; surround operator symbols by one space
7652 (goto-char beg)
7653 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7654 (if (match-string 1)
7655 (goto-char (match-end 1))
7656 (replace-match "\\3 \\4 \\5")
7657 (goto-char (match-end 2))))
7658 ;; eliminate multiple spaces and spaces at end of line
7659 (goto-char beg)
7660 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7661 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7662 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7663 (progn (replace-match "" nil nil) t))
7664 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7665 (progn (replace-match ";" nil nil) t))
7666 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7667 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7668 (progn (replace-match " " nil nil) t))
7669 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7670 (progn (replace-match " " nil nil) t))
7671 ; (re-search-forward "[^ \t-]+" end t))))
7672 (re-search-forward "[^ \t\"-]+" end t))))
7673 (unless no-message (message "Fixing up whitespace...done")))
7675 (defun vhdl-fixup-whitespace-buffer ()
7676 "Fixup whitespace in buffer. Surround operator symbols by one space,
7677 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7678 end of line, do nothing in comments."
7679 (interactive)
7680 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7682 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7683 ;; Beautify
7685 (defun vhdl-beautify-region (beg end)
7686 "Beautify region by applying indentation, whitespace fixup, alignment, and
7687 case fixing to a region. Calls functions `vhdl-indent-buffer',
7688 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7689 `vhdl-fix-case-buffer'."
7690 (interactive "r")
7691 (setq end (save-excursion (goto-char end) (point-marker)))
7692 (vhdl-indent-region beg end nil)
7693 (let ((vhdl-align-groups t))
7694 (vhdl-align-region beg end))
7695 (vhdl-fix-case-region beg end))
7697 (defun vhdl-beautify-buffer ()
7698 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7699 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7700 buffer."
7701 (interactive)
7702 (vhdl-beautify-region (point-min) (point-max))
7703 (when noninteractive (save-buffer)))
7705 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7706 ;; Code filling
7708 (defun vhdl-fill-region (beg end &optional arg)
7709 "Fill lines for a region of code."
7710 (interactive "r\np")
7711 (save-excursion
7712 (goto-char beg)
7713 (let ((margin (if arg (current-indentation) (current-column))))
7714 (goto-char end)
7715 (setq end (point-marker))
7716 ;; remove inline comments, newlines and whitespace
7717 (vhdl-comment-kill-region beg end)
7718 (vhdl-comment-kill-inline-region beg end)
7719 (subst-char-in-region beg (1- end) ?\n ?\ )
7720 (vhdl-fixup-whitespace-region beg end)
7721 ;; wrap and end-comment-column
7722 (goto-char beg)
7723 (while (re-search-forward "\\s-" end t)
7724 (when(> (current-column) vhdl-end-comment-column)
7725 (backward-char)
7726 (when (re-search-backward "\\s-" beg t)
7727 (replace-match "\n")
7728 (indent-to margin)))))))
7730 (defun vhdl-fill-group ()
7731 "Fill group of lines between empty lines."
7732 (interactive)
7733 (vhdl-do-group 'vhdl-fill-region))
7735 (defun vhdl-fill-list ()
7736 "Fill the lines of a list surrounded by a balanced group of parentheses."
7737 (interactive)
7738 (vhdl-do-list 'vhdl-fill-region))
7740 (defun vhdl-fill-same-indent ()
7741 "Fill the lines of block of lines with same indent."
7742 (interactive)
7743 (vhdl-do-same-indent 'vhdl-fill-region))
7746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7747 ;;; Code updating/fixing
7748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7751 ;; Sensitivity list update
7753 ;; Strategy:
7754 ;; - no sensitivity list is generated for processes with wait statements
7755 ;; - otherwise, do the following:
7756 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7757 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7758 ;; manually entered global signals)
7759 ;; 3. signals from 1. and 2. form the list of visible signals
7760 ;; 4. search for if/elsif conditions containing an event (sequential code)
7761 ;; 5. scan for strings that are within syntactical regions where signals are
7762 ;; read but not within sequential code, and that correspond to visible
7763 ;; signals
7764 ;; 6. replace sensitivity list by list of signals from 5.
7766 (defun vhdl-update-sensitivity-list-process ()
7767 "Update sensitivity list of current process."
7768 (interactive)
7769 (save-excursion
7770 (vhdl-prepare-search-2
7771 (end-of-line)
7772 ;; look whether in process
7773 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7774 (equal (upcase (match-string 2)) "PROCESS")
7775 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7776 (error "ERROR: Not within a process")
7777 (message "Updating sensitivity list...")
7778 (vhdl-update-sensitivity-list)
7779 (message "Updating sensitivity list...done")))))
7781 (defun vhdl-update-sensitivity-list-buffer ()
7782 "Update sensitivity list of all processes in current buffer."
7783 (interactive)
7784 (save-excursion
7785 (vhdl-prepare-search-2
7786 (goto-char (point-min))
7787 (message "Updating sensitivity lists...")
7788 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7789 (goto-char (match-beginning 0))
7790 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7791 (message "Updating sensitivity lists...done"))))
7793 (defun vhdl-update-sensitivity-list ()
7794 "Update sensitivity list."
7795 (let ((proc-beg (point))
7796 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7797 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7798 seq-region-list)
7799 (cond
7800 ;; search for wait statement (no sensitivity list allowed)
7801 ((progn (goto-char proc-mid)
7802 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7803 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7804 ;; combinational process (update sensitivity list)
7806 (let
7807 ;; scan for visible signals
7808 ((visible-list (vhdl-get-visible-signals))
7809 ;; define syntactic regions where signals are read
7810 (scan-regions-list
7811 '(;; right-hand side of signal/variable assignment
7812 ;; (special case: "<=" is relational operator in a condition)
7813 ((re-search-forward "[<:]=" proc-end t)
7814 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7815 ;; if condition
7816 ((re-search-forward "^\\s-*if\\>" proc-end t)
7817 (re-search-forward "\\<then\\>" proc-end t))
7818 ;; elsif condition
7819 ((re-search-forward "\\<elsif\\>" proc-end t)
7820 (re-search-forward "\\<then\\>" proc-end t))
7821 ;; while loop condition
7822 ((re-search-forward "^\\s-*while\\>" proc-end t)
7823 (re-search-forward "\\<loop\\>" proc-end t))
7824 ;; exit/next condition
7825 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7826 (re-search-forward ";" proc-end t))
7827 ;; assert condition
7828 ((re-search-forward "\\<assert\\>" proc-end t)
7829 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7830 ;; case expression
7831 ((re-search-forward "^\\s-*case\\>" proc-end t)
7832 (re-search-forward "\\<is\\>" proc-end t))
7833 ;; parameter list of procedure call
7834 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7835 (1- (point)))
7836 (progn (backward-char) (forward-sexp)
7837 (while (looking-at "(") (forward-sexp)) (point)))))
7838 name read-list sens-list signal-list
7839 sens-beg sens-end beg end margin)
7840 ;; scan for signals in old sensitivity list
7841 (goto-char proc-beg)
7842 (re-search-forward "\\<process\\>" proc-mid t)
7843 (if (not (looking-at "[ \t\n]*("))
7844 (setq sens-beg (point))
7845 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7846 (goto-char (match-end 1))
7847 (forward-sexp)
7848 (setq sens-end (1- (point)))
7849 (goto-char sens-beg)
7850 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7851 (setq sens-list
7852 (cons (downcase (match-string 0)) sens-list))
7853 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7854 (setq signal-list (append visible-list sens-list))
7855 ;; search for sequential parts
7856 (goto-char proc-mid)
7857 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7858 (setq end (re-search-forward "\\<then\\>" proc-end t))
7859 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7860 (goto-char end)
7861 (backward-word 1)
7862 (vhdl-forward-sexp)
7863 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7864 (beginning-of-line)))
7865 ;; scan for signals read in process
7866 (while scan-regions-list
7867 (goto-char proc-mid)
7868 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7869 (setq end (eval (nth 1 (car scan-regions-list)))))
7870 (goto-char beg)
7871 (unless (or (vhdl-in-literal)
7872 (and seq-region-list
7873 (let ((tmp-list seq-region-list))
7874 (while (and tmp-list
7875 (< (point) (caar tmp-list)))
7876 (setq tmp-list (cdr tmp-list)))
7877 (and tmp-list (< (point) (cdar tmp-list))))))
7878 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7879 (setq name (match-string 1))
7880 (when (and (not (match-string 4)) ; not when formal parameter
7881 (not (and (match-string 3) ; not event attribute
7882 (not (member (downcase (match-string 3))
7883 '("event" "last_event" "transaction")))))
7884 (member (downcase name) signal-list))
7885 (unless (member-ignore-case name read-list)
7886 (setq read-list (cons name read-list))))
7887 (goto-char (match-end 1)))))
7888 (setq scan-regions-list (cdr scan-regions-list)))
7889 ;; update sensitivity list
7890 (goto-char sens-beg)
7891 (if sens-end
7892 (delete-region sens-beg sens-end)
7893 (when read-list
7894 (insert " ()") (backward-char)))
7895 (setq read-list (sort read-list 'string<))
7896 (when read-list
7897 (setq margin (current-column))
7898 (insert (car read-list))
7899 (setq read-list (cdr read-list))
7900 (while read-list
7901 (insert ",")
7902 (if (<= (+ (current-column) (length (car read-list)) 2)
7903 end-comment-column)
7904 (insert " ")
7905 (insert "\n") (indent-to margin))
7906 (insert (car read-list))
7907 (setq read-list (cdr read-list)))))))))
7909 (defun vhdl-get-visible-signals ()
7910 "Get all signals visible in the current block."
7911 (let (beg end signal-list entity-name file-name)
7912 (vhdl-prepare-search-2
7913 ;; get entity name
7914 (save-excursion
7915 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7916 (not (equal "END" (upcase (match-string 1))))
7917 (setq entity-name (match-string 2)))
7918 (error "ERROR: Not within an architecture")))
7919 ;; search for signals declared in entity port clause
7920 (save-excursion
7921 (goto-char (point-min))
7922 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7923 (setq file-name
7924 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7925 "." (file-name-extension (buffer-file-name)))))
7926 (vhdl-visit-file
7927 file-name t
7928 (vhdl-prepare-search-2
7929 (goto-char (point-min))
7930 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7931 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7932 (when (setq beg (re-search-forward
7933 "^\\s-*port[ \t\n]*("
7934 (save-excursion
7935 (re-search-forward "^end\\>" nil t)) t))
7936 (setq end (save-excursion
7937 (backward-char) (forward-sexp) (point)))
7938 (vhdl-forward-syntactic-ws)
7939 (while (< (point) end)
7940 (when (looking-at "signal[ \t\n]+")
7941 (goto-char (match-end 0)))
7942 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7943 (setq signal-list
7944 (cons (downcase (match-string 1)) signal-list))
7945 (goto-char (match-end 0))
7946 (vhdl-forward-syntactic-ws))
7947 (re-search-forward ";" end 1)
7948 (vhdl-forward-syntactic-ws)))))))
7949 ;; search for signals declared in architecture declarative part
7950 (save-excursion
7951 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7952 (not (equal "END" (upcase (match-string 1))))
7953 (setq end (re-search-forward "^begin\\>" nil t))))
7954 (error "ERROR: No architecture declarative part found")
7955 ;; scan for all declared signal and alias names
7956 (goto-char beg)
7957 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7958 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7959 (if (match-string 2)
7960 ;; scan signal name
7961 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7962 (setq signal-list
7963 (cons (downcase (match-string 1)) signal-list))
7964 (goto-char (match-end 0)))
7965 ;; scan alias name, check is alias of (declared) signal
7966 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7967 (member (downcase (match-string 2)) signal-list))
7968 (setq signal-list
7969 (cons (downcase (match-string 1)) signal-list))
7970 (goto-char (match-end 0))))
7971 (setq beg (point))))))
7972 ;; search for signals declared in surrounding block declarative parts
7973 (save-excursion
7974 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7975 (match-string 2))
7976 (goto-char (match-end 2))
7977 (vhdl-backward-sexp)
7978 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7979 beg)
7980 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7981 ;; scan for all declared signal names
7982 (goto-char beg)
7983 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7984 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7985 (if (match-string 2)
7986 ;; scan signal name
7987 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7988 (setq signal-list
7989 (cons (downcase (match-string 1)) signal-list))
7990 (goto-char (match-end 0)))
7991 ;; scan alias name, check is alias of (declared) signal
7992 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7993 (member (downcase (match-string 2)) signal-list))
7994 (setq signal-list
7995 (cons (downcase (match-string 1)) signal-list))
7996 (goto-char (match-end 0))))))
7997 (goto-char beg)))
7998 signal-list)))
8000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8001 ;; Generic/port clause fixing
8003 (defun vhdl-fix-clause ()
8004 "Fix closing parenthesis within generic/port clause."
8005 (interactive)
8006 (save-excursion
8007 (vhdl-prepare-search-2
8008 (let ((pos (point))
8009 beg end)
8010 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8011 (error "ERROR: Not within a generic/port clause")
8012 ;; search for end of clause
8013 (goto-char (match-end 0))
8014 (setq beg (1- (point)))
8015 (vhdl-forward-syntactic-ws)
8016 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8017 (goto-char (1- (match-end 0)))
8018 (setq end (point-marker))
8019 (forward-char)
8020 (vhdl-forward-syntactic-ws))
8021 (goto-char end)
8022 (when (> pos (save-excursion (end-of-line) (point)))
8023 (error "ERROR: Not within a generic/port clause"))
8024 ;; delete closing parenthesis on separate line (not supported style)
8025 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8026 (vhdl-line-kill)
8027 (vhdl-backward-syntactic-ws)
8028 (setq end (point-marker))
8029 (insert ";"))
8030 ;; delete superfluous parentheses
8031 (while (progn (goto-char beg)
8032 (condition-case () (forward-sexp)
8033 (error (goto-char (point-max))))
8034 (< (point) end))
8035 (delete-backward-char 1))
8036 ;; add closing parenthesis
8037 (when (> (point) end)
8038 (goto-char end)
8039 (insert ")")))))))
8041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8042 ;; Miscellaneous
8044 (defun vhdl-remove-trailing-spaces ()
8045 "Remove trailing spaces in the whole buffer."
8046 (interactive)
8047 (save-match-data
8048 (save-excursion
8049 (goto-char (point-min))
8050 (while (re-search-forward "[ \t]+$" (point-max) t)
8051 (unless (vhdl-in-literal)
8052 (replace-match "" nil nil))))))
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056 ;;; Electrification
8057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8059 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8060 "Syntax of prompt inserted by template generators.")
8062 (defvar vhdl-template-invoked-by-hook nil
8063 "Indicates whether a template has been invoked by a hook or by key or menu.
8064 Used for undoing after template abortion.")
8066 ;; correct different behavior of function `unread-command-events' in XEmacs
8067 (defun vhdl-character-to-event (arg))
8068 (defalias 'vhdl-character-to-event
8069 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8071 (defun vhdl-work-library ()
8072 "Return the working library name of the current project or \"work\" if no
8073 project is defined."
8074 (vhdl-resolve-env-variable
8075 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8078 ;; Enabling/disabling
8080 (defun vhdl-mode-line-update ()
8081 "Update the modeline string for VHDL major mode."
8082 (setq mode-name (concat "VHDL"
8083 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8084 (and vhdl-electric-mode "e")
8085 (and vhdl-stutter-mode "s")))
8086 (force-mode-line-update t))
8088 (defun vhdl-electric-mode (arg)
8089 "Toggle VHDL electric mode.
8090 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8091 (interactive "P")
8092 (setq vhdl-electric-mode
8093 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8094 ((> arg 0) t) (t nil)))
8095 (vhdl-mode-line-update))
8097 (defun vhdl-stutter-mode (arg)
8098 "Toggle VHDL stuttering mode.
8099 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8100 (interactive "P")
8101 (setq vhdl-stutter-mode
8102 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8103 ((> arg 0) t) (t nil)))
8104 (vhdl-mode-line-update))
8106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8107 ;; Stuttering
8109 (defun vhdl-electric-dash (count)
8110 "-- starts a comment, --- draws a horizontal line,
8111 ---- starts a display comment."
8112 (interactive "p")
8113 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8114 (cond
8115 ((and abbrev-start-location (= abbrev-start-location (point)))
8116 (setq abbrev-start-location nil)
8117 (goto-char last-abbrev-location)
8118 (beginning-of-line nil)
8119 (vhdl-comment-display))
8120 ((/= (preceding-char) ?-) ; standard dash (minus)
8121 (self-insert-command count))
8122 (t (self-insert-command count)
8123 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8124 (let ((next-input (read-char)))
8125 (if (= next-input ?-) ; triple dash
8126 (progn
8127 (vhdl-comment-display-line)
8128 (message
8129 "Enter '-' for display comment, else continue coding")
8130 (let ((next-input (read-char)))
8131 (if (= next-input ?-) ; four dashes
8132 (vhdl-comment-display t)
8133 (setq unread-command-events ; pushback the char
8134 (list (vhdl-character-to-event next-input))))))
8135 (setq unread-command-events ; pushback the char
8136 (list (vhdl-character-to-event next-input)))
8137 (vhdl-comment-insert)))))
8138 (self-insert-command count)))
8140 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8141 (interactive "p")
8142 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8143 (if (= (preceding-char) ?\()
8144 (progn (delete-char -1) (insert-char ?\[ 1))
8145 (insert-char ?\( 1))
8146 (self-insert-command count)))
8148 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8149 (interactive "p")
8150 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8151 (progn
8152 (if (= (preceding-char) ?\))
8153 (progn (delete-char -1) (insert-char ?\] 1))
8154 (insert-char ?\) 1))
8155 (blink-matching-open))
8156 (self-insert-command count)))
8158 (defun vhdl-electric-quote (count) "'' --> \""
8159 (interactive "p")
8160 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8161 (if (= (preceding-char) last-input-char)
8162 (progn (delete-backward-char 1) (insert-char ?\" 1))
8163 (insert-char ?\' 1))
8164 (self-insert-command count)))
8166 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8167 (interactive "p")
8168 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8169 (cond ((= (preceding-char) last-input-char)
8170 (progn (delete-char -1)
8171 (unless (eq (preceding-char) ? ) (insert " "))
8172 (insert ": ")
8173 (setq this-command 'vhdl-electric-colon)))
8174 ((and
8175 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8176 (progn (delete-char -1) (insert "= ")))
8177 (t (insert-char ?\; 1)))
8178 (self-insert-command count)))
8180 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8181 (interactive "p")
8182 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8183 (cond ((= (preceding-char) last-input-char)
8184 (progn (delete-char -1)
8185 (unless (eq (preceding-char) ? ) (insert " "))
8186 (insert "<= ")))
8187 (t (insert-char ?\, 1)))
8188 (self-insert-command count)))
8190 (defun vhdl-electric-period (count) "'..' --> ' => '"
8191 (interactive "p")
8192 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8193 (cond ((= (preceding-char) last-input-char)
8194 (progn (delete-char -1)
8195 (unless (eq (preceding-char) ? ) (insert " "))
8196 (insert "=> ")))
8197 (t (insert-char ?\. 1)))
8198 (self-insert-command count)))
8200 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8201 (interactive "p")
8202 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8203 (cond ((= (preceding-char) last-input-char)
8204 (progn (delete-char -1)
8205 (unless (eq (preceding-char) ? ) (insert " "))
8206 (insert "== ")))
8207 (t (insert-char ?\= 1)))
8208 (self-insert-command count)))
8210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8211 ;; VHDL templates
8213 (defun vhdl-template-paired-parens ()
8214 "Insert a pair of round parentheses, placing point between them."
8215 (interactive)
8216 (insert "()")
8217 (backward-char))
8219 (defun vhdl-template-alias ()
8220 "Insert alias declaration."
8221 (interactive)
8222 (let ((start (point)))
8223 (vhdl-insert-keyword "ALIAS ")
8224 (when (vhdl-template-field "name" nil t start (point))
8225 (insert " : ")
8226 (unless (vhdl-template-field
8227 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8228 nil t)
8229 (delete-backward-char 3))
8230 (vhdl-insert-keyword " IS ")
8231 (vhdl-template-field "name" ";")
8232 (vhdl-comment-insert-inline))))
8234 (defun vhdl-template-architecture ()
8235 "Insert architecture."
8236 (interactive)
8237 (let ((margin (current-indentation))
8238 (start (point))
8239 arch-name)
8240 (vhdl-insert-keyword "ARCHITECTURE ")
8241 (when (setq arch-name
8242 (vhdl-template-field "name" nil t start (point)))
8243 (vhdl-insert-keyword " OF ")
8244 (if (save-excursion
8245 (vhdl-prepare-search-1
8246 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8247 (insert (match-string 1))
8248 (vhdl-template-field "entity name"))
8249 (vhdl-insert-keyword " IS\n")
8250 (vhdl-template-begin-end
8251 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8252 (memq vhdl-insert-empty-lines '(unit all))))))
8254 (defun vhdl-template-array (kind &optional secondary)
8255 "Insert array type definition."
8256 (interactive)
8257 (let ((start (point)))
8258 (vhdl-insert-keyword "ARRAY (")
8259 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8260 secondary)
8261 (vhdl-insert-keyword ") OF ")
8262 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8263 (vhdl-insert-keyword ";"))))
8265 (defun vhdl-template-assert ()
8266 "Insert an assertion statement."
8267 (interactive)
8268 (let ((start (point)))
8269 (vhdl-insert-keyword "ASSERT ")
8270 (when vhdl-conditions-in-parenthesis (insert "("))
8271 (when (vhdl-template-field "condition (negated)" nil t start (point))
8272 (when vhdl-conditions-in-parenthesis (insert ")"))
8273 (setq start (point))
8274 (vhdl-insert-keyword " REPORT ")
8275 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8276 (delete-region start (point)))
8277 (setq start (point))
8278 (vhdl-insert-keyword " SEVERITY ")
8279 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8280 (delete-region start (point)))
8281 (insert ";"))))
8283 (defun vhdl-template-attribute ()
8284 "Insert an attribute declaration or specification."
8285 (interactive)
8286 (if (eq (vhdl-decision-query
8287 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8288 (vhdl-template-attribute-spec)
8289 (vhdl-template-attribute-decl)))
8291 (defun vhdl-template-attribute-decl ()
8292 "Insert an attribute declaration."
8293 (interactive)
8294 (let ((start (point)))
8295 (vhdl-insert-keyword "ATTRIBUTE ")
8296 (when (vhdl-template-field "name" " : " t start (point))
8297 (vhdl-template-field "type" ";")
8298 (vhdl-comment-insert-inline))))
8300 (defun vhdl-template-attribute-spec ()
8301 "Insert an attribute specification."
8302 (interactive)
8303 (let ((start (point)))
8304 (vhdl-insert-keyword "ATTRIBUTE ")
8305 (when (vhdl-template-field "name" nil t start (point))
8306 (vhdl-insert-keyword " OF ")
8307 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8308 (vhdl-template-field "entity class")
8309 (vhdl-insert-keyword " IS ")
8310 (vhdl-template-field "expression" ";"))))
8312 (defun vhdl-template-block ()
8313 "Insert a block."
8314 (interactive)
8315 (let ((margin (current-indentation))
8316 (start (point))
8317 label)
8318 (vhdl-insert-keyword ": BLOCK ")
8319 (goto-char start)
8320 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8321 (forward-word 1)
8322 (forward-char 1)
8323 (insert "(")
8324 (if (vhdl-template-field "[guard expression]" nil t)
8325 (insert ")")
8326 (delete-char -2))
8327 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8328 (insert "\n")
8329 (vhdl-template-begin-end "BLOCK" label margin)
8330 (vhdl-comment-block))))
8332 (defun vhdl-template-block-configuration ()
8333 "Insert a block configuration statement."
8334 (interactive)
8335 (let ((margin (current-indentation))
8336 (start (point)))
8337 (vhdl-insert-keyword "FOR ")
8338 (when (vhdl-template-field "block name" nil t start (point))
8339 (vhdl-insert-keyword "\n\n")
8340 (indent-to margin)
8341 (vhdl-insert-keyword "END FOR;")
8342 (end-of-line 0)
8343 (indent-to (+ margin vhdl-basic-offset)))))
8345 (defun vhdl-template-break ()
8346 "Insert a break statement."
8347 (interactive)
8348 (let (position)
8349 (vhdl-insert-keyword "BREAK")
8350 (setq position (point))
8351 (insert " ")
8352 (while (or
8353 (progn (vhdl-insert-keyword "FOR ")
8354 (if (vhdl-template-field "[quantity name]" " USE " t)
8355 (progn (vhdl-template-field "quantity name" " => ") t)
8356 (delete-region (point)
8357 (progn (forward-word -1) (point)))
8358 nil))
8359 (vhdl-template-field "[quantity name]" " => " t))
8360 (vhdl-template-field "expression")
8361 (setq position (point))
8362 (insert ", "))
8363 (delete-region position (point))
8364 (unless (vhdl-sequential-statement-p)
8365 (vhdl-insert-keyword " ON ")
8366 (if (vhdl-template-field "[sensitivity list]" nil t)
8367 (setq position (point))
8368 (delete-region position (point))))
8369 (vhdl-insert-keyword " WHEN ")
8370 (when vhdl-conditions-in-parenthesis (insert "("))
8371 (if (vhdl-template-field "[condition]" nil t)
8372 (when vhdl-conditions-in-parenthesis (insert ")"))
8373 (delete-region position (point)))
8374 (insert ";")))
8376 (defun vhdl-template-case (&optional kind)
8377 "Insert a case statement."
8378 (interactive)
8379 (let ((margin (current-indentation))
8380 (start (point))
8381 label)
8382 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8383 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8384 (vhdl-insert-keyword "CASE ")
8385 (vhdl-insert-keyword ": CASE ")
8386 (goto-char start)
8387 (setq label (vhdl-template-field "[label]" nil t))
8388 (unless label (delete-char 2))
8389 (forward-word 1)
8390 (forward-char 1))
8391 (when (vhdl-template-field "expression" nil t start (point))
8392 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8393 (indent-to margin)
8394 (vhdl-insert-keyword "END CASE")
8395 (when label (insert " " label))
8396 (insert ";")
8397 (forward-line -1)
8398 (indent-to (+ margin vhdl-basic-offset))
8399 (vhdl-insert-keyword "WHEN ")
8400 (let ((position (point)))
8401 (insert " => ;\n")
8402 (indent-to (+ margin vhdl-basic-offset))
8403 (vhdl-insert-keyword "WHEN OTHERS => null;")
8404 (goto-char position)))))
8406 (defun vhdl-template-case-is ()
8407 "Insert a sequential case statement."
8408 (interactive)
8409 (vhdl-template-case 'is))
8411 (defun vhdl-template-case-use ()
8412 "Insert a simultaneous case statement."
8413 (interactive)
8414 (vhdl-template-case 'use))
8416 (defun vhdl-template-component ()
8417 "Insert a component declaration."
8418 (interactive)
8419 (vhdl-template-component-decl))
8421 (defun vhdl-template-component-conf ()
8422 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8423 since these are almost equivalent)."
8424 (interactive)
8425 (let ((margin (current-indentation))
8426 (result (vhdl-template-configuration-spec t)))
8427 (when result
8428 (insert "\n")
8429 (indent-to margin)
8430 (vhdl-insert-keyword "END FOR;")
8431 (when (eq result 'no-use)
8432 (end-of-line -0)))))
8434 (defun vhdl-template-component-decl ()
8435 "Insert a component declaration."
8436 (interactive)
8437 (let ((margin (current-indentation))
8438 (start (point))
8439 name end-column)
8440 (vhdl-insert-keyword "COMPONENT ")
8441 (when (setq name (vhdl-template-field "name" nil t start (point)))
8442 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8443 (insert "\n\n")
8444 (indent-to margin)
8445 (vhdl-insert-keyword "END COMPONENT")
8446 (unless (vhdl-standard-p '87) (insert " " name))
8447 (insert ";")
8448 (setq end-column (current-column))
8449 (end-of-line -0)
8450 (indent-to (+ margin vhdl-basic-offset))
8451 (vhdl-template-generic-list t t)
8452 (insert "\n")
8453 (indent-to (+ margin vhdl-basic-offset))
8454 (vhdl-template-port-list t)
8455 (beginning-of-line 2)
8456 (forward-char end-column))))
8458 (defun vhdl-template-component-inst ()
8459 "Insert a component instantiation statement."
8460 (interactive)
8461 (let ((margin (current-indentation))
8462 (start (point))
8463 unit position)
8464 (when (vhdl-template-field "instance label" nil t start (point))
8465 (insert ": ")
8466 (if (not (vhdl-use-direct-instantiation))
8467 (vhdl-template-field "component name")
8468 ;; direct instantiation
8469 (setq unit (vhdl-template-field
8470 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8471 (setq unit (upcase (or unit "")))
8472 (cond ((equal unit "ENTITY")
8473 (vhdl-template-field "library name" "." nil nil nil nil
8474 (vhdl-work-library))
8475 (vhdl-template-field "entity name" "(")
8476 (if (vhdl-template-field "[architecture name]" nil t)
8477 (insert ")")
8478 (delete-char -1)))
8479 ((equal unit "CONFIGURATION")
8480 (vhdl-template-field "library name" "." nil nil nil nil
8481 (vhdl-work-library))
8482 (vhdl-template-field "configuration name"))
8483 (t (vhdl-template-field "component name"))))
8484 (insert "\n")
8485 (indent-to (+ margin vhdl-basic-offset))
8486 (setq position (point))
8487 (vhdl-insert-keyword "GENERIC ")
8488 (when (vhdl-template-map position t t)
8489 (insert "\n")
8490 (indent-to (+ margin vhdl-basic-offset)))
8491 (setq position (point))
8492 (vhdl-insert-keyword "PORT ")
8493 (unless (vhdl-template-map position t t)
8494 (delete-region (line-beginning-position) (point))
8495 (delete-char -1))
8496 (insert ";"))))
8498 (defun vhdl-template-conditional-signal-asst ()
8499 "Insert a conditional signal assignment."
8500 (interactive)
8501 (when (vhdl-template-field "target signal")
8502 (insert " <= ")
8503 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8504 ; (insert " "))
8505 (let ((margin (current-column))
8506 (start (point))
8507 position)
8508 (vhdl-template-field "waveform")
8509 (setq position (point))
8510 (vhdl-insert-keyword " WHEN ")
8511 (when vhdl-conditions-in-parenthesis (insert "("))
8512 (while (and (vhdl-template-field "[condition]" nil t)
8513 (progn
8514 (when vhdl-conditions-in-parenthesis (insert ")"))
8515 (setq position (point))
8516 (vhdl-insert-keyword " ELSE")
8517 (insert "\n")
8518 (indent-to margin)
8519 (vhdl-template-field "[waveform]" nil t)))
8520 (setq position (point))
8521 (vhdl-insert-keyword " WHEN ")
8522 (when vhdl-conditions-in-parenthesis (insert "(")))
8523 (delete-region position (point))
8524 (insert ";")
8525 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8527 (defun vhdl-template-configuration ()
8528 "Insert a configuration specification if within an architecture,
8529 a block or component configuration if within a configuration declaration,
8530 a configuration declaration if not within a design unit."
8531 (interactive)
8532 (vhdl-prepare-search-1
8533 (cond
8534 ((and (save-excursion ; architecture body
8535 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8536 (equal "ARCHITECTURE" (upcase (match-string 1))))
8537 (vhdl-template-configuration-spec))
8538 ((and (save-excursion ; configuration declaration
8539 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8540 (equal "CONFIGURATION" (upcase (match-string 1))))
8541 (if (eq (vhdl-decision-query
8542 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8543 (vhdl-template-component-conf)
8544 (vhdl-template-block-configuration)))
8545 (t (vhdl-template-configuration-decl))))) ; otherwise
8547 (defun vhdl-template-configuration-spec (&optional optional-use)
8548 "Insert a configuration specification."
8549 (interactive)
8550 (let ((margin (current-indentation))
8551 (start (point))
8552 aspect position)
8553 (vhdl-insert-keyword "FOR ")
8554 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8555 t start (point))
8556 (vhdl-template-field "component name" "\n")
8557 (indent-to (+ margin vhdl-basic-offset))
8558 (setq start (point))
8559 (vhdl-insert-keyword "USE ")
8560 (if (and optional-use
8561 (not (setq aspect (vhdl-template-field
8562 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8563 (progn (delete-region start (point)) 'no-use)
8564 (unless optional-use
8565 (setq aspect (vhdl-template-field
8566 "ENTITY | CONFIGURATION | OPEN" " ")))
8567 (setq aspect (upcase (or aspect "")))
8568 (cond ((equal aspect "ENTITY")
8569 (vhdl-template-field "library name" "." nil nil nil nil
8570 (vhdl-work-library))
8571 (vhdl-template-field "entity name" "(")
8572 (if (vhdl-template-field "[architecture name]" nil t)
8573 (insert ")")
8574 (delete-char -1))
8575 (insert "\n")
8576 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8577 (setq position (point))
8578 (vhdl-insert-keyword "GENERIC ")
8579 (when (vhdl-template-map position t t)
8580 (insert "\n")
8581 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8582 (setq position (point))
8583 (vhdl-insert-keyword "PORT ")
8584 (unless (vhdl-template-map position t t)
8585 (delete-region (line-beginning-position) (point))
8586 (delete-char -1))
8587 (insert ";")
8589 ((equal aspect "CONFIGURATION")
8590 (vhdl-template-field "library name" "." nil nil nil nil
8591 (vhdl-work-library))
8592 (vhdl-template-field "configuration name" ";"))
8593 (t (delete-backward-char 1) (insert ";") t))))))
8596 (defun vhdl-template-configuration-decl ()
8597 "Insert a configuration declaration."
8598 (interactive)
8599 (let ((margin (current-indentation))
8600 (start (point))
8601 entity-exists string name position)
8602 (vhdl-insert-keyword "CONFIGURATION ")
8603 (when (setq name (vhdl-template-field "name" nil t start (point)))
8604 (vhdl-insert-keyword " OF ")
8605 (save-excursion
8606 (vhdl-prepare-search-1
8607 (setq entity-exists (vhdl-re-search-backward
8608 "\\<entity \\(\\w*\\) is\\>" nil t))
8609 (setq string (match-string 1))))
8610 (if (and entity-exists (not (equal string "")))
8611 (insert string)
8612 (vhdl-template-field "entity name"))
8613 (vhdl-insert-keyword " IS\n")
8614 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8615 (indent-to (+ margin vhdl-basic-offset))
8616 (setq position (point))
8617 (insert "\n")
8618 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8619 (indent-to margin)
8620 (vhdl-insert-keyword "END ")
8621 (unless (vhdl-standard-p '87)
8622 (vhdl-insert-keyword "CONFIGURATION "))
8623 (insert name ";")
8624 (goto-char position))))
8626 (defun vhdl-template-constant ()
8627 "Insert a constant declaration."
8628 (interactive)
8629 (let ((start (point))
8630 (in-arglist (vhdl-in-argument-list-p)))
8631 (vhdl-insert-keyword "CONSTANT ")
8632 (when (vhdl-template-field "name" nil t start (point))
8633 (insert " : ")
8634 (when in-arglist (vhdl-insert-keyword "IN "))
8635 (vhdl-template-field "type")
8636 (if in-arglist
8637 (progn (insert ";")
8638 (vhdl-comment-insert-inline))
8639 (let ((position (point)))
8640 (insert " := ")
8641 (unless (vhdl-template-field "[initialization]" nil t)
8642 (delete-region position (point)))
8643 (insert ";")
8644 (vhdl-comment-insert-inline))))))
8646 (defun vhdl-template-default ()
8647 "Insert nothing."
8648 (interactive)
8649 (insert " ")
8650 (unexpand-abbrev)
8651 (backward-word 1)
8652 (vhdl-case-word 1)
8653 (forward-char 1))
8655 (defun vhdl-template-default-indent ()
8656 "Insert nothing and indent."
8657 (interactive)
8658 (insert " ")
8659 (unexpand-abbrev)
8660 (backward-word 1)
8661 (vhdl-case-word 1)
8662 (forward-char 1)
8663 (indent-according-to-mode))
8665 (defun vhdl-template-disconnect ()
8666 "Insert a disconnect statement."
8667 (interactive)
8668 (let ((start (point)))
8669 (vhdl-insert-keyword "DISCONNECT ")
8670 (when (vhdl-template-field "signal names | OTHERS | ALL"
8671 " : " t start (point))
8672 (vhdl-template-field "type")
8673 (vhdl-insert-keyword " AFTER ")
8674 (vhdl-template-field "time expression" ";"))))
8676 (defun vhdl-template-else ()
8677 "Insert an else statement."
8678 (interactive)
8679 (let (margin)
8680 (vhdl-prepare-search-1
8681 (vhdl-insert-keyword "ELSE")
8682 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8683 (equal "WHEN" (upcase (match-string 1))))
8684 (insert " ")
8685 (indent-according-to-mode)
8686 (setq margin (current-indentation))
8687 (insert "\n")
8688 (indent-to (+ margin vhdl-basic-offset))))))
8690 (defun vhdl-template-elsif ()
8691 "Insert an elsif statement."
8692 (interactive)
8693 (let ((start (point))
8694 margin)
8695 (vhdl-insert-keyword "ELSIF ")
8696 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8697 (when vhdl-conditions-in-parenthesis (insert "("))
8698 (when (vhdl-template-field "condition" nil t start (point))
8699 (when vhdl-conditions-in-parenthesis (insert ")"))
8700 (indent-according-to-mode)
8701 (setq margin (current-indentation))
8702 (vhdl-insert-keyword
8703 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8704 (indent-to (+ margin vhdl-basic-offset))))))
8706 (defun vhdl-template-entity ()
8707 "Insert an entity."
8708 (interactive)
8709 (let ((margin (current-indentation))
8710 (start (point))
8711 name end-column)
8712 (vhdl-insert-keyword "ENTITY ")
8713 (when (setq name (vhdl-template-field "name" nil t start (point)))
8714 (vhdl-insert-keyword " IS\n\n")
8715 (indent-to margin)
8716 (vhdl-insert-keyword "END ")
8717 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8718 (insert name ";")
8719 (setq end-column (current-column))
8720 (end-of-line -0)
8721 (indent-to (+ margin vhdl-basic-offset))
8722 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8723 (indent-to (+ margin vhdl-basic-offset))
8724 (when (vhdl-template-generic-list t)
8725 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8726 (insert "\n")
8727 (indent-to (+ margin vhdl-basic-offset))
8728 (when (vhdl-template-port-list t)
8729 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8730 (beginning-of-line 2)
8731 (forward-char end-column))))
8733 (defun vhdl-template-exit ()
8734 "Insert an exit statement."
8735 (interactive)
8736 (let ((start (point)))
8737 (vhdl-insert-keyword "EXIT ")
8738 (if (vhdl-template-field "[loop label]" nil t start (point))
8739 (let ((position (point)))
8740 (vhdl-insert-keyword " WHEN ")
8741 (when vhdl-conditions-in-parenthesis (insert "("))
8742 (if (vhdl-template-field "[condition]" nil t)
8743 (when vhdl-conditions-in-parenthesis (insert ")"))
8744 (delete-region position (point))))
8745 (delete-char -1))
8746 (insert ";")))
8748 (defun vhdl-template-file ()
8749 "Insert a file declaration."
8750 (interactive)
8751 (let ((start (point)))
8752 (vhdl-insert-keyword "FILE ")
8753 (when (vhdl-template-field "name" nil t start (point))
8754 (insert " : ")
8755 (vhdl-template-field "type")
8756 (unless (vhdl-standard-p '87)
8757 (vhdl-insert-keyword " OPEN ")
8758 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8759 nil t)
8760 (delete-backward-char 6)))
8761 (vhdl-insert-keyword " IS ")
8762 (when (vhdl-standard-p '87)
8763 (vhdl-template-field "[IN | OUT]" " " t))
8764 (vhdl-template-field "filename-string" nil nil nil nil t)
8765 (insert ";")
8766 (vhdl-comment-insert-inline))))
8768 (defun vhdl-template-for ()
8769 "Insert a block or component configuration if within a configuration
8770 declaration, a configuration specification if within an architecture
8771 declarative part (and not within a subprogram), a for-loop if within a
8772 sequential statement part (subprogram or process), and a for-generate
8773 otherwise."
8774 (interactive)
8775 (vhdl-prepare-search-1
8776 (cond
8777 ((vhdl-sequential-statement-p) ; sequential statement
8778 (vhdl-template-for-loop))
8779 ((and (save-excursion ; configuration declaration
8780 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8781 (equal "CONFIGURATION" (upcase (match-string 1))))
8782 (if (eq (vhdl-decision-query
8783 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8784 (vhdl-template-component-conf)
8785 (vhdl-template-block-configuration)))
8786 ((and (save-excursion
8787 (re-search-backward ; architecture declarative part
8788 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8789 (equal "ARCHITECTURE" (upcase (match-string 1))))
8790 (vhdl-template-configuration-spec))
8791 (t (vhdl-template-for-generate))))) ; concurrent statement
8793 (defun vhdl-template-for-generate ()
8794 "Insert a for-generate."
8795 (interactive)
8796 (let ((margin (current-indentation))
8797 (start (point))
8798 label position)
8799 (vhdl-insert-keyword ": FOR ")
8800 (setq position (point-marker))
8801 (goto-char start)
8802 (when (setq label (vhdl-template-field "label" nil t start position))
8803 (goto-char position)
8804 (vhdl-template-field "loop variable")
8805 (vhdl-insert-keyword " IN ")
8806 (vhdl-template-field "range")
8807 (vhdl-template-generate-body margin label))))
8809 (defun vhdl-template-for-loop ()
8810 "Insert a for loop."
8811 (interactive)
8812 (let ((margin (current-indentation))
8813 (start (point))
8814 label index)
8815 (if (not (eq vhdl-optional-labels 'all))
8816 (vhdl-insert-keyword "FOR ")
8817 (vhdl-insert-keyword ": FOR ")
8818 (goto-char start)
8819 (setq label (vhdl-template-field "[label]" nil t))
8820 (unless label (delete-char 2))
8821 (forward-word 1)
8822 (forward-char 1))
8823 (when (setq index (vhdl-template-field "loop variable"
8824 nil t start (point)))
8825 (vhdl-insert-keyword " IN ")
8826 (vhdl-template-field "range")
8827 (vhdl-insert-keyword " LOOP\n\n")
8828 (indent-to margin)
8829 (vhdl-insert-keyword "END LOOP")
8830 (if label
8831 (insert " " label ";")
8832 (insert ";")
8833 (when vhdl-self-insert-comments (insert " -- " index)))
8834 (forward-line -1)
8835 (indent-to (+ margin vhdl-basic-offset)))))
8837 (defun vhdl-template-function (&optional kind)
8838 "Insert a function declaration or body."
8839 (interactive)
8840 (let ((margin (current-indentation))
8841 (start (point))
8842 name)
8843 (vhdl-insert-keyword "FUNCTION ")
8844 (when (setq name (vhdl-template-field "name" nil t start (point)))
8845 (vhdl-template-argument-list t)
8846 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8847 (end-of-line)
8848 (insert "\n")
8849 (indent-to (+ margin vhdl-basic-offset))
8850 (vhdl-insert-keyword "RETURN ")
8851 (vhdl-template-field "type")
8852 (if (if kind (eq kind 'body)
8853 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8854 (progn (vhdl-insert-keyword " IS\n")
8855 (vhdl-template-begin-end
8856 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8857 (vhdl-comment-block))
8858 (insert ";")))))
8860 (defun vhdl-template-function-decl ()
8861 "Insert a function declaration."
8862 (interactive)
8863 (vhdl-template-function 'decl))
8865 (defun vhdl-template-function-body ()
8866 "Insert a function declaration."
8867 (interactive)
8868 (vhdl-template-function 'body))
8870 (defun vhdl-template-generate ()
8871 "Insert a generation scheme."
8872 (interactive)
8873 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8874 (vhdl-template-if-generate)
8875 (vhdl-template-for-generate)))
8877 (defun vhdl-template-generic ()
8878 "Insert generic declaration, or generic map in instantiation statements."
8879 (interactive)
8880 (let ((start (point)))
8881 (vhdl-prepare-search-1
8882 (cond
8883 ((and (save-excursion ; entity declaration
8884 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8885 (equal "ENTITY" (upcase (match-string 1))))
8886 (vhdl-template-generic-list nil))
8887 ((or (save-excursion
8888 (or (beginning-of-line)
8889 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8890 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8891 (vhdl-insert-keyword "GENERIC ")
8892 (vhdl-template-map start))
8893 (t (vhdl-template-generic-list nil t))))))
8895 (defun vhdl-template-group ()
8896 "Insert group or group template declaration."
8897 (interactive)
8898 (let ((start (point)))
8899 (if (eq (vhdl-decision-query
8900 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8901 (vhdl-template-group-template)
8902 (vhdl-template-group-decl))))
8904 (defun vhdl-template-group-decl ()
8905 "Insert group declaration."
8906 (interactive)
8907 (let ((start (point)))
8908 (vhdl-insert-keyword "GROUP ")
8909 (when (vhdl-template-field "name" " : " t start (point))
8910 (vhdl-template-field "template name" " (")
8911 (vhdl-template-field "constituent list" ");")
8912 (vhdl-comment-insert-inline))))
8914 (defun vhdl-template-group-template ()
8915 "Insert group template declaration."
8916 (interactive)
8917 (let ((start (point)))
8918 (vhdl-insert-keyword "GROUP ")
8919 (when (vhdl-template-field "template name" nil t start (point))
8920 (vhdl-insert-keyword " IS (")
8921 (vhdl-template-field "entity class list" ");")
8922 (vhdl-comment-insert-inline))))
8924 (defun vhdl-template-if ()
8925 "Insert a sequential if statement or an if-generate statement."
8926 (interactive)
8927 (if (vhdl-sequential-statement-p)
8928 (vhdl-template-if-then)
8929 (if (and (vhdl-standard-p 'ams)
8930 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8931 (vhdl-template-if-use)
8932 (vhdl-template-if-generate))))
8934 (defun vhdl-template-if-generate ()
8935 "Insert an if-generate."
8936 (interactive)
8937 (let ((margin (current-indentation))
8938 (start (point))
8939 label position)
8940 (vhdl-insert-keyword ": IF ")
8941 (setq position (point-marker))
8942 (goto-char start)
8943 (when (setq label (vhdl-template-field "label" nil t start position))
8944 (goto-char position)
8945 (when vhdl-conditions-in-parenthesis (insert "("))
8946 (vhdl-template-field "condition")
8947 (when vhdl-conditions-in-parenthesis (insert ")"))
8948 (vhdl-template-generate-body margin label))))
8950 (defun vhdl-template-if-then-use (kind)
8951 "Insert a sequential if statement."
8952 (interactive)
8953 (let ((margin (current-indentation))
8954 (start (point))
8955 label)
8956 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8957 (vhdl-insert-keyword "IF ")
8958 (vhdl-insert-keyword ": IF ")
8959 (goto-char start)
8960 (setq label (vhdl-template-field "[label]" nil t))
8961 (unless label (delete-char 2))
8962 (forward-word 1)
8963 (forward-char 1))
8964 (when vhdl-conditions-in-parenthesis (insert "("))
8965 (when (vhdl-template-field "condition" nil t start (point))
8966 (when vhdl-conditions-in-parenthesis (insert ")"))
8967 (vhdl-insert-keyword
8968 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8969 (indent-to margin)
8970 (vhdl-insert-keyword "END IF")
8971 (when label (insert " " label))
8972 (insert ";")
8973 (forward-line -1)
8974 (indent-to (+ margin vhdl-basic-offset)))))
8976 (defun vhdl-template-if-then ()
8977 "Insert a sequential if statement."
8978 (interactive)
8979 (vhdl-template-if-then-use 'then))
8981 (defun vhdl-template-if-use ()
8982 "Insert a simultaneous if statement."
8983 (interactive)
8984 (vhdl-template-if-then-use 'use))
8986 (defun vhdl-template-instance ()
8987 "Insert a component instantiation statement."
8988 (interactive)
8989 (vhdl-template-component-inst))
8991 (defun vhdl-template-library ()
8992 "Insert a library specification."
8993 (interactive)
8994 (let ((margin (current-indentation))
8995 (start (point))
8996 name end-pos)
8997 (vhdl-insert-keyword "LIBRARY ")
8998 (when (setq name (vhdl-template-field "names" nil t start (point)))
8999 (insert ";")
9000 (unless (string-match "," name)
9001 (setq end-pos (point))
9002 (insert "\n")
9003 (indent-to margin)
9004 (vhdl-insert-keyword "USE ")
9005 (insert name)
9006 (vhdl-insert-keyword "..ALL;")
9007 (backward-char 5)
9008 (if (vhdl-template-field "package name")
9009 (forward-char 5)
9010 (delete-region end-pos (+ (point) 5)))))))
9012 (defun vhdl-template-limit ()
9013 "Insert a limit."
9014 (interactive)
9015 (let ((start (point)))
9016 (vhdl-insert-keyword "LIMIT ")
9017 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9018 t start (point))
9019 (vhdl-template-field "type")
9020 (vhdl-insert-keyword " WITH ")
9021 (vhdl-template-field "real expression" ";"))))
9023 (defun vhdl-template-loop ()
9024 "Insert a loop."
9025 (interactive)
9026 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9027 (cond ((eq char ?w)
9028 (vhdl-template-while-loop))
9029 ((eq char ?f)
9030 (vhdl-template-for-loop))
9031 (t (vhdl-template-bare-loop)))))
9033 (defun vhdl-template-bare-loop ()
9034 "Insert a loop."
9035 (interactive)
9036 (let ((margin (current-indentation))
9037 (start (point))
9038 label)
9039 (if (not (eq vhdl-optional-labels 'all))
9040 (vhdl-insert-keyword "LOOP ")
9041 (vhdl-insert-keyword ": LOOP ")
9042 (goto-char start)
9043 (setq label (vhdl-template-field "[label]" nil t))
9044 (unless label (delete-char 2))
9045 (forward-word 1)
9046 (delete-char 1))
9047 (insert "\n\n")
9048 (indent-to margin)
9049 (vhdl-insert-keyword "END LOOP")
9050 (insert (if label (concat " " label ";") ";"))
9051 (forward-line -1)
9052 (indent-to (+ margin vhdl-basic-offset))))
9054 (defun vhdl-template-map (&optional start optional secondary)
9055 "Insert a map specification with association list."
9056 (interactive)
9057 (let ((start (or start (point)))
9058 margin end-pos)
9059 (vhdl-insert-keyword "MAP (")
9060 (if (not vhdl-association-list-with-formals)
9061 (if (vhdl-template-field
9062 (concat (and optional "[") "association list" (and optional "]"))
9063 ")" (or (not secondary) optional)
9064 (and (not secondary) start) (point))
9066 (if (and optional secondary) (delete-region start (point)))
9067 nil)
9068 (if vhdl-argument-list-indent
9069 (setq margin (current-column))
9070 (setq margin (+ (current-indentation) vhdl-basic-offset))
9071 (insert "\n")
9072 (indent-to margin))
9073 (if (vhdl-template-field
9074 (concat (and optional "[") "formal" (and optional "]"))
9075 " => " (or (not secondary) optional)
9076 (and (not secondary) start) (point))
9077 (progn
9078 (vhdl-template-field "actual" ",")
9079 (setq end-pos (point))
9080 (insert "\n")
9081 (indent-to margin)
9082 (while (vhdl-template-field "[formal]" " => " t)
9083 (vhdl-template-field "actual" ",")
9084 (setq end-pos (point))
9085 (insert "\n")
9086 (indent-to margin))
9087 (delete-region end-pos (point))
9088 (delete-backward-char 1)
9089 (insert ")")
9090 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9092 (when (and optional secondary) (delete-region start (point)))
9093 nil))))
9095 (defun vhdl-template-modify (&optional noerror)
9096 "Actualize modification date."
9097 (interactive)
9098 (vhdl-prepare-search-2
9099 (save-excursion
9100 (goto-char (point-min))
9101 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9102 (progn (delete-region (point) (progn (end-of-line) (point)))
9103 (vhdl-template-insert-date))
9104 (unless noerror
9105 (error "ERROR: Modification date prefix string \"%s\" not found"
9106 vhdl-modify-date-prefix-string))))))
9109 (defun vhdl-template-modify-noerror ()
9110 "Call `vhdl-template-modify' with NOERROR non-nil."
9111 (vhdl-template-modify t))
9113 (defun vhdl-template-nature ()
9114 "Insert a nature declaration."
9115 (interactive)
9116 (let ((start (point))
9117 name mid-pos end-pos)
9118 (vhdl-insert-keyword "NATURE ")
9119 (when (setq name (vhdl-template-field "name" nil t start (point)))
9120 (vhdl-insert-keyword " IS ")
9121 (let ((definition
9122 (upcase
9123 (or (vhdl-template-field
9124 "across type | ARRAY | RECORD")
9125 ""))))
9126 (cond ((equal definition "")
9127 (insert ";"))
9128 ((equal definition "ARRAY")
9129 (delete-region (point) (progn (forward-word -1) (point)))
9130 (vhdl-template-array 'nature t))
9131 ((equal definition "RECORD")
9132 (setq mid-pos (point-marker))
9133 (delete-region (point) (progn (forward-word -1) (point)))
9134 (vhdl-template-record 'nature name t))
9136 (vhdl-insert-keyword " ACROSS ")
9137 (vhdl-template-field "through type")
9138 (vhdl-insert-keyword " THROUGH ")
9139 (vhdl-template-field "reference name")
9140 (vhdl-insert-keyword " REFERENCE;")))
9141 (when mid-pos
9142 (setq end-pos (point-marker))
9143 (goto-char mid-pos)
9144 (end-of-line))
9145 (vhdl-comment-insert-inline)
9146 (when end-pos (goto-char end-pos))))))
9148 (defun vhdl-template-next ()
9149 "Insert a next statement."
9150 (interactive)
9151 (let ((start (point)))
9152 (vhdl-insert-keyword "NEXT ")
9153 (if (vhdl-template-field "[loop label]" nil t start (point))
9154 (let ((position (point)))
9155 (vhdl-insert-keyword " WHEN ")
9156 (when vhdl-conditions-in-parenthesis (insert "("))
9157 (if (vhdl-template-field "[condition]" nil t)
9158 (when vhdl-conditions-in-parenthesis (insert ")"))
9159 (delete-region position (point))))
9160 (delete-char -1))
9161 (insert ";")))
9163 (defun vhdl-template-others ()
9164 "Insert an others aggregate."
9165 (interactive)
9166 (let ((start (point)))
9167 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9168 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9169 (vhdl-insert-keyword "OTHERS => '")
9170 (when (vhdl-template-field "value" nil t start (point))
9171 (insert "')")))
9172 (vhdl-insert-keyword "OTHERS "))))
9174 (defun vhdl-template-package (&optional kind)
9175 "Insert a package specification or body."
9176 (interactive)
9177 (let ((margin (current-indentation))
9178 (start (point))
9179 name body position)
9180 (vhdl-insert-keyword "PACKAGE ")
9181 (setq body (if kind (eq kind 'body)
9182 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9183 (when body
9184 (vhdl-insert-keyword "BODY ")
9185 (when (save-excursion
9186 (vhdl-prepare-search-1
9187 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9188 (insert (setq name (match-string 1)))))
9189 (when (or name
9190 (setq name (vhdl-template-field "name" nil t start (point))))
9191 (vhdl-insert-keyword " IS\n")
9192 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9193 (indent-to (+ margin vhdl-basic-offset))
9194 (setq position (point))
9195 (insert "\n")
9196 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9197 (indent-to margin)
9198 (vhdl-insert-keyword "END ")
9199 (unless (vhdl-standard-p '87)
9200 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9201 (insert (or name "") ";")
9202 (goto-char position))))
9204 (defun vhdl-template-package-decl ()
9205 "Insert a package specification."
9206 (interactive)
9207 (vhdl-template-package 'decl))
9209 (defun vhdl-template-package-body ()
9210 "Insert a package body."
9211 (interactive)
9212 (vhdl-template-package 'body))
9214 (defun vhdl-template-port ()
9215 "Insert a port declaration, or port map in instantiation statements."
9216 (interactive)
9217 (let ((start (point)))
9218 (vhdl-prepare-search-1
9219 (cond
9220 ((and (save-excursion ; entity declaration
9221 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9222 (equal "ENTITY" (upcase (match-string 1))))
9223 (vhdl-template-port-list nil))
9224 ((or (save-excursion
9225 (or (beginning-of-line)
9226 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9227 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9228 (vhdl-insert-keyword "PORT ")
9229 (vhdl-template-map start))
9230 (t (vhdl-template-port-list nil))))))
9232 (defun vhdl-template-procedural ()
9233 "Insert a procedural."
9234 (interactive)
9235 (let ((margin (current-indentation))
9236 (start (point))
9237 (case-fold-search t)
9238 label)
9239 (vhdl-insert-keyword "PROCEDURAL ")
9240 (when (memq vhdl-optional-labels '(process all))
9241 (goto-char start)
9242 (insert ": ")
9243 (goto-char start)
9244 (setq label (vhdl-template-field "[label]" nil t))
9245 (unless label (delete-char 2))
9246 (forward-word 1)
9247 (forward-char 1))
9248 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9249 (insert "\n")
9250 (vhdl-template-begin-end "PROCEDURAL" label margin)
9251 (vhdl-comment-block)))
9253 (defun vhdl-template-procedure (&optional kind)
9254 "Insert a procedure declaration or body."
9255 (interactive)
9256 (let ((margin (current-indentation))
9257 (start (point))
9258 name)
9259 (vhdl-insert-keyword "PROCEDURE ")
9260 (when (setq name (vhdl-template-field "name" nil t start (point)))
9261 (vhdl-template-argument-list)
9262 (if (if kind (eq kind 'body)
9263 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9264 (progn (vhdl-insert-keyword " IS")
9265 (when vhdl-auto-align
9266 (vhdl-align-region-groups start (point) 1))
9267 (end-of-line) (insert "\n")
9268 (vhdl-template-begin-end
9269 (unless (vhdl-standard-p '87) "PROCEDURE")
9270 name margin)
9271 (vhdl-comment-block))
9272 (insert ";")
9273 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9274 (end-of-line)))))
9276 (defun vhdl-template-procedure-decl ()
9277 "Insert a procedure declaration."
9278 (interactive)
9279 (vhdl-template-procedure 'decl))
9281 (defun vhdl-template-procedure-body ()
9282 "Insert a procedure body."
9283 (interactive)
9284 (vhdl-template-procedure 'body))
9286 (defun vhdl-template-process (&optional kind)
9287 "Insert a process."
9288 (interactive)
9289 (let ((margin (current-indentation))
9290 (start (point))
9291 label seq input-signals clock reset final-pos)
9292 (setq seq (if kind (eq kind 'seq)
9293 (eq (vhdl-decision-query
9294 "process" "(c)ombinational or (s)equential?" t) ?s)))
9295 (vhdl-insert-keyword "PROCESS ")
9296 (when (memq vhdl-optional-labels '(process all))
9297 (goto-char start)
9298 (insert ": ")
9299 (goto-char start)
9300 (setq label (vhdl-template-field "[label]" nil t))
9301 (unless label (delete-char 2))
9302 (forward-word 1)
9303 (forward-char 1))
9304 (insert "(")
9305 (if (not seq)
9306 (unless (setq input-signals
9307 (vhdl-template-field "[sensitivity list]" ")" t))
9308 (setq input-signals "")
9309 (delete-char -2))
9310 (setq clock (or (and (not (equal "" vhdl-clock-name))
9311 (progn (insert vhdl-clock-name) vhdl-clock-name))
9312 (vhdl-template-field "clock name") "<clock>"))
9313 (when (eq vhdl-reset-kind 'async)
9314 (insert ", ")
9315 (setq reset (or (and (not (equal "" vhdl-reset-name))
9316 (progn (insert vhdl-reset-name) vhdl-reset-name))
9317 (vhdl-template-field "reset name") "<reset>")))
9318 (insert ")"))
9319 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9320 (insert "\n")
9321 (vhdl-template-begin-end "PROCESS" label margin)
9322 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9323 (when vhdl-prompt-for-comments
9324 (setq final-pos (point-marker))
9325 (vhdl-prepare-search-2
9326 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9327 (vhdl-re-search-backward "\\<process\\>" nil t))
9328 (end-of-line -0)
9329 (if (bobp)
9330 (progn (insert "\n") (forward-line -1))
9331 (insert "\n"))
9332 (indent-to margin)
9333 (insert "-- purpose: ")
9334 (if (not (vhdl-template-field "[description]" nil t))
9335 (vhdl-line-kill-entire)
9336 (insert "\n")
9337 (indent-to margin)
9338 (insert "-- type : ")
9339 (insert (if seq "sequential" "combinational") "\n")
9340 (indent-to margin)
9341 (insert "-- inputs : ")
9342 (if (not seq)
9343 (insert input-signals)
9344 (insert clock ", ")
9345 (when reset (insert reset ", "))
9346 (unless (vhdl-template-field "[signal names]" nil t)
9347 (delete-char -2)))
9348 (insert "\n")
9349 (indent-to margin)
9350 (insert "-- outputs: ")
9351 (vhdl-template-field "[signal names]" nil t))))
9352 (goto-char final-pos))))
9354 (defun vhdl-template-process-comb ()
9355 "Insert a combinational process."
9356 (interactive)
9357 (vhdl-template-process 'comb))
9359 (defun vhdl-template-process-seq ()
9360 "Insert a sequential process."
9361 (interactive)
9362 (vhdl-template-process 'seq))
9364 (defun vhdl-template-quantity ()
9365 "Insert a quantity declaration."
9366 (interactive)
9367 (if (vhdl-in-argument-list-p)
9368 (let ((start (point)))
9369 (vhdl-insert-keyword "QUANTITY ")
9370 (when (vhdl-template-field "names" nil t start (point))
9371 (insert " : ")
9372 (vhdl-template-field "[IN | OUT]" " " t)
9373 (vhdl-template-field "type")
9374 (insert ";")
9375 (vhdl-comment-insert-inline)))
9376 (let ((char (vhdl-decision-query
9377 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9378 (cond ((eq char ?f) (vhdl-template-quantity-free))
9379 ((eq char ?b) (vhdl-template-quantity-branch))
9380 ((eq char ?s) (vhdl-template-quantity-source))
9381 (t (vhdl-template-undo (point) (point)))))))
9383 (defun vhdl-template-quantity-free ()
9384 "Insert a free quantity declaration."
9385 (interactive)
9386 (vhdl-insert-keyword "QUANTITY ")
9387 (vhdl-template-field "names")
9388 (insert " : ")
9389 (vhdl-template-field "type")
9390 (let ((position (point)))
9391 (insert " := ")
9392 (unless (vhdl-template-field "[initialization]" nil t)
9393 (delete-region position (point)))
9394 (insert ";")
9395 (vhdl-comment-insert-inline)))
9397 (defun vhdl-template-quantity-branch ()
9398 "Insert a branch quantity declaration."
9399 (interactive)
9400 (let (position)
9401 (vhdl-insert-keyword "QUANTITY ")
9402 (when (vhdl-template-field "[across names]" " " t)
9403 (vhdl-insert-keyword "ACROSS "))
9404 (when (vhdl-template-field "[through names]" " " t)
9405 (vhdl-insert-keyword "THROUGH "))
9406 (vhdl-template-field "plus terminal name")
9407 (setq position (point))
9408 (vhdl-insert-keyword " TO ")
9409 (unless (vhdl-template-field "[minus terminal name]" nil t)
9410 (delete-region position (point)))
9411 (insert ";")
9412 (vhdl-comment-insert-inline)))
9414 (defun vhdl-template-quantity-source ()
9415 "Insert a source quantity declaration."
9416 (interactive)
9417 (vhdl-insert-keyword "QUANTITY ")
9418 (vhdl-template-field "names")
9419 (insert " : ")
9420 (vhdl-template-field "type" " ")
9421 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9422 (progn (vhdl-insert-keyword "NOISE ")
9423 (vhdl-template-field "power expression"))
9424 (vhdl-insert-keyword "SPECTRUM ")
9425 (vhdl-template-field "magnitude expression" ", ")
9426 (vhdl-template-field "phase expression"))
9427 (insert ";")
9428 (vhdl-comment-insert-inline))
9430 (defun vhdl-template-record (kind &optional name secondary)
9431 "Insert a record type declaration."
9432 (interactive)
9433 (let ((margin (current-column))
9434 (start (point))
9435 (first t))
9436 (vhdl-insert-keyword "RECORD\n")
9437 (indent-to (+ margin vhdl-basic-offset))
9438 (when (or (vhdl-template-field "element names"
9439 nil (not secondary) start (point))
9440 secondary)
9441 (while (or first (vhdl-template-field "[element names]" nil t))
9442 (insert " : ")
9443 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9444 (vhdl-comment-insert-inline)
9445 (insert "\n")
9446 (indent-to (+ margin vhdl-basic-offset))
9447 (setq first nil))
9448 (delete-region (line-beginning-position) (point))
9449 (indent-to margin)
9450 (vhdl-insert-keyword "END RECORD")
9451 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9452 (insert ";")
9453 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9455 (defun vhdl-template-report ()
9456 "Insert a report statement."
9457 (interactive)
9458 (let ((start (point)))
9459 (vhdl-insert-keyword "REPORT ")
9460 (if (equal "\"\"" (vhdl-template-field
9461 "string expression" nil t start (point) t))
9462 (delete-backward-char 2)
9463 (setq start (point))
9464 (vhdl-insert-keyword " SEVERITY ")
9465 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9466 (delete-region start (point)))
9467 (insert ";"))))
9469 (defun vhdl-template-return ()
9470 "Insert a return statement."
9471 (interactive)
9472 (let ((start (point)))
9473 (vhdl-insert-keyword "RETURN ")
9474 (unless (vhdl-template-field "[expression]" nil t start (point))
9475 (delete-char -1))
9476 (insert ";")))
9478 (defun vhdl-template-selected-signal-asst ()
9479 "Insert a selected signal assignment."
9480 (interactive)
9481 (let ((margin (current-indentation))
9482 (start (point))
9483 (choices t))
9484 (let ((position (point)))
9485 (vhdl-insert-keyword " SELECT ")
9486 (goto-char position))
9487 (vhdl-insert-keyword "WITH ")
9488 (when (vhdl-template-field "selector expression"
9489 nil t start (+ (point) 7))
9490 (forward-word 1)
9491 (delete-char 1)
9492 (insert "\n")
9493 (indent-to (+ margin vhdl-basic-offset))
9494 (vhdl-template-field "target signal" " <= ")
9495 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9496 (insert "\n")
9497 (indent-to (+ margin vhdl-basic-offset))
9498 (vhdl-template-field "waveform")
9499 (vhdl-insert-keyword " WHEN ")
9500 (vhdl-template-field "choices" ",")
9501 (insert "\n")
9502 (indent-to (+ margin vhdl-basic-offset))
9503 (while (and choices (vhdl-template-field "[waveform]" nil t))
9504 (vhdl-insert-keyword " WHEN ")
9505 (if (setq choices (vhdl-template-field "[choices]" "," t))
9506 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9507 (vhdl-insert-keyword "OTHERS")))
9508 (when choices
9509 (fixup-whitespace)
9510 (delete-char -2))
9511 (insert ";")
9512 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9514 (defun vhdl-template-signal ()
9515 "Insert a signal declaration."
9516 (interactive)
9517 (let ((start (point))
9518 (in-arglist (vhdl-in-argument-list-p)))
9519 (vhdl-insert-keyword "SIGNAL ")
9520 (when (vhdl-template-field "names" nil t start (point))
9521 (insert " : ")
9522 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9523 (vhdl-template-field "type")
9524 (if in-arglist
9525 (progn (insert ";")
9526 (vhdl-comment-insert-inline))
9527 (let ((position (point)))
9528 (insert " := ")
9529 (unless (vhdl-template-field "[initialization]" nil t)
9530 (delete-region position (point)))
9531 (insert ";")
9532 (vhdl-comment-insert-inline))))))
9534 (defun vhdl-template-subnature ()
9535 "Insert a subnature declaration."
9536 (interactive)
9537 (let ((start (point))
9538 position)
9539 (vhdl-insert-keyword "SUBNATURE ")
9540 (when (vhdl-template-field "name" nil t start (point))
9541 (vhdl-insert-keyword " IS ")
9542 (vhdl-template-field "nature" " (")
9543 (if (vhdl-template-field "[index range]" nil t)
9544 (insert ")")
9545 (delete-char -2))
9546 (setq position (point))
9547 (vhdl-insert-keyword " TOLERANCE ")
9548 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9549 nil t nil nil t))
9550 (delete-region position (point))
9551 (vhdl-insert-keyword " ACROSS ")
9552 (vhdl-template-field "string expression" nil nil nil nil t)
9553 (vhdl-insert-keyword " THROUGH"))
9554 (insert ";")
9555 (vhdl-comment-insert-inline))))
9557 (defun vhdl-template-subprogram-body ()
9558 "Insert a subprogram body."
9559 (interactive)
9560 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9561 (vhdl-template-function-body)
9562 (vhdl-template-procedure-body)))
9564 (defun vhdl-template-subprogram-decl ()
9565 "Insert a subprogram declaration."
9566 (interactive)
9567 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9568 (vhdl-template-function-decl)
9569 (vhdl-template-procedure-decl)))
9571 (defun vhdl-template-subtype ()
9572 "Insert a subtype declaration."
9573 (interactive)
9574 (let ((start (point)))
9575 (vhdl-insert-keyword "SUBTYPE ")
9576 (when (vhdl-template-field "name" nil t start (point))
9577 (vhdl-insert-keyword " IS ")
9578 (vhdl-template-field "type" " ")
9579 (unless
9580 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9581 (delete-char -1))
9582 (insert ";")
9583 (vhdl-comment-insert-inline))))
9585 (defun vhdl-template-terminal ()
9586 "Insert a terminal declaration."
9587 (interactive)
9588 (let ((start (point)))
9589 (vhdl-insert-keyword "TERMINAL ")
9590 (when (vhdl-template-field "names" nil t start (point))
9591 (insert " : ")
9592 (vhdl-template-field "nature")
9593 (insert ";")
9594 (vhdl-comment-insert-inline))))
9596 (defun vhdl-template-type ()
9597 "Insert a type declaration."
9598 (interactive)
9599 (let ((start (point))
9600 name mid-pos end-pos)
9601 (vhdl-insert-keyword "TYPE ")
9602 (when (setq name (vhdl-template-field "name" nil t start (point)))
9603 (vhdl-insert-keyword " IS ")
9604 (let ((definition
9605 (upcase
9606 (or (vhdl-template-field
9607 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9608 ""))))
9609 (cond ((equal definition "")
9610 (delete-backward-char 4)
9611 (insert ";"))
9612 ((equal definition "ARRAY")
9613 (delete-region (point) (progn (forward-word -1) (point)))
9614 (vhdl-template-array 'type t))
9615 ((equal definition "RECORD")
9616 (setq mid-pos (point-marker))
9617 (delete-region (point) (progn (forward-word -1) (point)))
9618 (vhdl-template-record 'type name t))
9619 ((equal definition "ACCESS")
9620 (insert " ")
9621 (vhdl-template-field "type" ";"))
9622 ((equal definition "FILE")
9623 (vhdl-insert-keyword " OF ")
9624 (vhdl-template-field "type" ";"))
9625 (t (insert ";")))
9626 (when mid-pos
9627 (setq end-pos (point-marker))
9628 (goto-char mid-pos)
9629 (end-of-line))
9630 (vhdl-comment-insert-inline)
9631 (when end-pos (goto-char end-pos))))))
9633 (defun vhdl-template-use ()
9634 "Insert a use clause."
9635 (interactive)
9636 (let ((start (point)))
9637 (vhdl-prepare-search-1
9638 (vhdl-insert-keyword "USE ")
9639 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9640 (vhdl-insert-keyword "..ALL;")
9641 (backward-char 6)
9642 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9643 (forward-char 1)
9644 (vhdl-template-field "package name")
9645 (forward-char 5))))))
9647 (defun vhdl-template-variable ()
9648 "Insert a variable declaration."
9649 (interactive)
9650 (let ((start (point))
9651 (in-arglist (vhdl-in-argument-list-p)))
9652 (vhdl-prepare-search-2
9653 (if (or (save-excursion
9654 (and (vhdl-re-search-backward
9655 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9656 nil t)
9657 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9658 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9659 (vhdl-insert-keyword "VARIABLE ")
9660 (vhdl-insert-keyword "SHARED VARIABLE ")))
9661 (when (vhdl-template-field "names" nil t start (point))
9662 (insert " : ")
9663 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9664 (vhdl-template-field "type")
9665 (if in-arglist
9666 (progn (insert ";")
9667 (vhdl-comment-insert-inline))
9668 (let ((position (point)))
9669 (insert " := ")
9670 (unless (vhdl-template-field "[initialization]" nil t)
9671 (delete-region position (point)))
9672 (insert ";")
9673 (vhdl-comment-insert-inline))))))
9675 (defun vhdl-template-wait ()
9676 "Insert a wait statement."
9677 (interactive)
9678 (vhdl-insert-keyword "WAIT ")
9679 (unless (vhdl-template-field
9680 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9681 nil t)
9682 (delete-char -1))
9683 (insert ";"))
9685 (defun vhdl-template-when ()
9686 "Indent correctly if within a case statement."
9687 (interactive)
9688 (let ((position (point))
9689 margin)
9690 (vhdl-prepare-search-2
9691 (if (and (= (current-column) (current-indentation))
9692 (vhdl-re-search-forward "\\<end\\>" nil t)
9693 (looking-at "\\s-*\\<case\\>"))
9694 (progn
9695 (setq margin (current-indentation))
9696 (goto-char position)
9697 (delete-horizontal-space)
9698 (indent-to (+ margin vhdl-basic-offset)))
9699 (goto-char position)))
9700 (vhdl-insert-keyword "WHEN ")))
9702 (defun vhdl-template-while-loop ()
9703 "Insert a while loop."
9704 (interactive)
9705 (let* ((margin (current-indentation))
9706 (start (point))
9707 label)
9708 (if (not (eq vhdl-optional-labels 'all))
9709 (vhdl-insert-keyword "WHILE ")
9710 (vhdl-insert-keyword ": WHILE ")
9711 (goto-char start)
9712 (setq label (vhdl-template-field "[label]" nil t))
9713 (unless label (delete-char 2))
9714 (forward-word 1)
9715 (forward-char 1))
9716 (when vhdl-conditions-in-parenthesis (insert "("))
9717 (when (vhdl-template-field "condition" nil t start (point))
9718 (when vhdl-conditions-in-parenthesis (insert ")"))
9719 (vhdl-insert-keyword " LOOP\n\n")
9720 (indent-to margin)
9721 (vhdl-insert-keyword "END LOOP")
9722 (insert (if label (concat " " label ";") ";"))
9723 (forward-line -1)
9724 (indent-to (+ margin vhdl-basic-offset)))))
9726 (defun vhdl-template-with ()
9727 "Insert a with statement (i.e. selected signal assignment)."
9728 (interactive)
9729 (vhdl-prepare-search-1
9730 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9731 (equal ";" (match-string 1)))
9732 (vhdl-template-selected-signal-asst)
9733 (vhdl-insert-keyword "WITH "))))
9735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9736 ;; Special templates
9738 (defun vhdl-template-clocked-wait ()
9739 "Insert a wait statement for rising/falling clock edge."
9740 (interactive)
9741 (let ((start (point))
9742 clock)
9743 (vhdl-insert-keyword "WAIT UNTIL ")
9744 (when (setq clock
9745 (or (and (not (equal "" vhdl-clock-name))
9746 (progn (insert vhdl-clock-name) vhdl-clock-name))
9747 (vhdl-template-field "clock name" nil t start (point))))
9748 (insert "'event")
9749 (vhdl-insert-keyword " AND ")
9750 (insert clock)
9751 (insert
9752 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9753 (vhdl-comment-insert-inline
9754 (concat (if vhdl-clock-rising-edge "rising" "falling")
9755 " clock edge")))))
9757 (defun vhdl-template-seq-process (clock reset)
9758 "Insert a template for the body of a sequential process."
9759 (let ((margin (current-indentation))
9760 position)
9761 (vhdl-insert-keyword "IF ")
9762 (when (eq vhdl-reset-kind 'async)
9763 (insert reset " = "
9764 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9765 (vhdl-insert-keyword " THEN")
9766 (vhdl-comment-insert-inline
9767 (concat "asynchronous reset (active "
9768 (if vhdl-reset-active-high "high" "low") ")"))
9769 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9770 (setq position (point))
9771 (insert "\n") (indent-to margin)
9772 (vhdl-insert-keyword "ELSIF "))
9773 (if (eq vhdl-clock-edge-condition 'function)
9774 (insert (if vhdl-clock-rising-edge "rising" "falling")
9775 "_edge(" clock ")")
9776 (insert clock "'event")
9777 (vhdl-insert-keyword " AND ")
9778 (insert clock " = "
9779 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9780 (vhdl-insert-keyword " THEN")
9781 (vhdl-comment-insert-inline
9782 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9783 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9784 (when (eq vhdl-reset-kind 'sync)
9785 (vhdl-insert-keyword "IF ")
9786 (setq reset (or (and (not (equal "" vhdl-reset-name))
9787 (progn (insert vhdl-reset-name) vhdl-reset-name))
9788 (vhdl-template-field "reset name") "<reset>"))
9789 (insert " = "
9790 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9791 (vhdl-insert-keyword " THEN")
9792 (vhdl-comment-insert-inline
9793 (concat "synchronous reset (active "
9794 (if vhdl-reset-active-high "high" "low") ")"))
9795 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9796 (setq position (point))
9797 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9798 (vhdl-insert-keyword "ELSE")
9799 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9800 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9801 (vhdl-insert-keyword "END IF;"))
9802 (when (eq vhdl-reset-kind 'none)
9803 (setq position (point)))
9804 (insert "\n") (indent-to margin)
9805 (vhdl-insert-keyword "END IF;")
9806 (goto-char position)
9807 reset))
9809 (defun vhdl-template-standard-package (library package)
9810 "Insert specification of a standard package. Include a library
9811 specification, if not already there."
9812 (let ((margin (current-indentation)))
9813 (unless (equal library "std")
9814 (unless (or (save-excursion
9815 (vhdl-prepare-search-1
9816 (and (not (bobp))
9817 (re-search-backward
9818 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9819 library "\\|end\\)\\>") nil t)
9820 (match-string 2))))
9821 (equal (downcase library) "work"))
9822 (vhdl-insert-keyword "LIBRARY ")
9823 (insert library ";")
9824 (when package
9825 (insert "\n")
9826 (indent-to margin)))
9827 (when package
9828 (vhdl-insert-keyword "USE ")
9829 (insert library "." package)
9830 (vhdl-insert-keyword ".ALL;")))))
9832 (defun vhdl-template-package-math-complex ()
9833 "Insert specification of `math_complex' package."
9834 (interactive)
9835 (vhdl-template-standard-package "ieee" "math_complex"))
9837 (defun vhdl-template-package-math-real ()
9838 "Insert specification of `math_real' package."
9839 (interactive)
9840 (vhdl-template-standard-package "ieee" "math_real"))
9842 (defun vhdl-template-package-numeric-bit ()
9843 "Insert specification of `numeric_bit' package."
9844 (interactive)
9845 (vhdl-template-standard-package "ieee" "numeric_bit"))
9847 (defun vhdl-template-package-numeric-std ()
9848 "Insert specification of `numeric_std' package."
9849 (interactive)
9850 (vhdl-template-standard-package "ieee" "numeric_std"))
9852 (defun vhdl-template-package-std-logic-1164 ()
9853 "Insert specification of `std_logic_1164' package."
9854 (interactive)
9855 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9857 (defun vhdl-template-package-std-logic-arith ()
9858 "Insert specification of `std_logic_arith' package."
9859 (interactive)
9860 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9862 (defun vhdl-template-package-std-logic-misc ()
9863 "Insert specification of `std_logic_misc' package."
9864 (interactive)
9865 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9867 (defun vhdl-template-package-std-logic-signed ()
9868 "Insert specification of `std_logic_signed' package."
9869 (interactive)
9870 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9872 (defun vhdl-template-package-std-logic-textio ()
9873 "Insert specification of `std_logic_textio' package."
9874 (interactive)
9875 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9877 (defun vhdl-template-package-std-logic-unsigned ()
9878 "Insert specification of `std_logic_unsigned' package."
9879 (interactive)
9880 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9882 (defun vhdl-template-package-textio ()
9883 "Insert specification of `textio' package."
9884 (interactive)
9885 (vhdl-template-standard-package "std" "textio"))
9887 (defun vhdl-template-directive (directive)
9888 "Insert directive."
9889 (unless (= (current-indentation) (current-column))
9890 (delete-horizontal-space)
9891 (insert " "))
9892 (insert "-- pragma " directive))
9894 (defun vhdl-template-directive-translate-on ()
9895 "Insert directive 'translate_on'."
9896 (interactive)
9897 (vhdl-template-directive "translate_on"))
9899 (defun vhdl-template-directive-translate-off ()
9900 "Insert directive 'translate_off'."
9901 (interactive)
9902 (vhdl-template-directive "translate_off"))
9904 (defun vhdl-template-directive-synthesis-on ()
9905 "Insert directive 'synthesis_on'."
9906 (interactive)
9907 (vhdl-template-directive "synthesis_on"))
9909 (defun vhdl-template-directive-synthesis-off ()
9910 "Insert directive 'synthesis_off'."
9911 (interactive)
9912 (vhdl-template-directive "synthesis_off"))
9914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9915 ;; Header and footer templates
9917 (defun vhdl-template-header (&optional file-title)
9918 "Insert a VHDL file header."
9919 (interactive)
9920 (unless (equal vhdl-file-header "")
9921 (let (pos)
9922 (save-excursion
9923 (goto-char (point-min))
9924 (vhdl-insert-string-or-file vhdl-file-header)
9925 (setq pos (point-marker)))
9926 (vhdl-template-replace-header-keywords
9927 (point-min-marker) pos file-title))))
9929 (defun vhdl-template-footer ()
9930 "Insert a VHDL file footer."
9931 (interactive)
9932 (unless (equal vhdl-file-footer "")
9933 (let (pos)
9934 (save-excursion
9935 (goto-char (point-max))
9936 (setq pos (point-marker))
9937 (vhdl-insert-string-or-file vhdl-file-footer)
9938 (unless (= (preceding-char) ?\n)
9939 (insert "\n")))
9940 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9942 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9943 is-model)
9944 "Replace keywords in header and footer."
9945 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9946 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9947 pos)
9948 (vhdl-prepare-search-2
9949 (save-excursion
9950 (goto-char beg)
9951 (while (search-forward "<projectdesc>" end t)
9952 (replace-match project-desc t t))
9953 (goto-char beg)
9954 (while (search-forward "<filename>" end t)
9955 (replace-match (buffer-name) t t))
9956 (goto-char beg)
9957 (while (search-forward "<copyright>" end t)
9958 (replace-match vhdl-copyright-string t t))
9959 (goto-char beg)
9960 (while (search-forward "<author>" end t)
9961 (replace-match "" t t)
9962 (insert (user-full-name))
9963 (when user-mail-address (insert " <" user-mail-address ">")))
9964 (goto-char beg)
9965 (while (search-forward "<login>" end t)
9966 (replace-match (user-login-name) t t))
9967 (goto-char beg)
9968 (while (search-forward "<project>" end t)
9969 (replace-match project-title t t))
9970 (goto-char beg)
9971 (while (search-forward "<company>" end t)
9972 (replace-match vhdl-company-name t t))
9973 (goto-char beg)
9974 (while (search-forward "<platform>" end t)
9975 (replace-match vhdl-platform-spec t t))
9976 (goto-char beg)
9977 (while (search-forward "<standard>" end t)
9978 (replace-match
9979 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9980 ((vhdl-standard-p '93) "'93"))
9981 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9982 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9983 (goto-char beg)
9984 ;; Replace <RCS> with $, so that RCS for the source is
9985 ;; not over-enthusiastic with replacements
9986 (while (search-forward "<RCS>" end t)
9987 (replace-match "$" nil t))
9988 (goto-char beg)
9989 (while (search-forward "<date>" end t)
9990 (replace-match "" t t)
9991 (vhdl-template-insert-date))
9992 (goto-char beg)
9993 (while (search-forward "<year>" end t)
9994 (replace-match (format-time-string "%Y" nil) t t))
9995 (goto-char beg)
9996 (when file-title
9997 (while (search-forward "<title string>" end t)
9998 (replace-match file-title t t))
9999 (goto-char beg))
10000 (let (string)
10001 (while
10002 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10003 (setq string (read-string (concat (match-string 1) ": ")))
10004 (replace-match string t t)))
10005 (goto-char beg)
10006 (when (and (not is-model) (search-forward "<cursor>" end t))
10007 (replace-match "" t t)
10008 (setq pos (point))))
10009 (when pos (goto-char pos))
10010 (unless is-model
10011 (when (or (not project-title) (equal project-title ""))
10012 (message "You can specify a project title in user option `vhdl-project-alist'"))
10013 (when (or (not project-desc) (equal project-desc ""))
10014 (message "You can specify a project description in user option `vhdl-project-alist'"))
10015 (when (equal vhdl-platform-spec "")
10016 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10017 (when (equal vhdl-company-name "")
10018 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10021 ;; Comment templates and functions
10023 (defun vhdl-comment-indent ()
10024 "Indent comments."
10025 (let* ((position (point))
10026 (col
10027 (progn
10028 (forward-line -1)
10029 (if (re-search-forward "--" position t)
10030 (- (current-column) 2) ; existing comment at bol stays there
10031 (goto-char position)
10032 (skip-chars-backward " \t")
10033 (max comment-column ; else indent to comment column
10034 (1+ (current-column))))))) ; except leave at least one space
10035 (goto-char position)
10036 col))
10038 (defun vhdl-comment-insert ()
10039 "Start a comment at the end of the line.
10040 If on line with code, indent at least `comment-column'.
10041 If starting after end-comment-column, start a new line."
10042 (interactive)
10043 (when (> (current-column) end-comment-column) (newline-and-indent))
10044 (if (or (looking-at "\\s-*$") ; end of line
10045 (and (not unread-command-events) ; called with key binding or menu
10046 (not (end-of-line))))
10047 (let (margin)
10048 (while (= (preceding-char) ?-) (delete-char -1))
10049 (setq margin (current-column))
10050 (delete-horizontal-space)
10051 (if (bolp)
10052 (progn (indent-to margin) (insert "--"))
10053 (insert " ")
10054 (indent-to comment-column)
10055 (insert "--"))
10056 (if (not unread-command-events) (insert " ")))
10057 ;; else code following current point implies commenting out code
10058 (let (next-input code)
10059 (while (= (preceding-char) ?-) (delete-char -2))
10060 (while (= (setq next-input (read-char)) 13) ; CR
10061 (insert "--") ; or have a space after it?
10062 (forward-char -2)
10063 (forward-line 1)
10064 (message "Enter CR if commenting out a line of code.")
10065 (setq code t))
10066 (unless code
10067 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10068 (setq unread-command-events
10069 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10071 (defun vhdl-comment-display (&optional line-exists)
10072 "Add 2 comment lines at the current indent, making a display comment."
10073 (interactive)
10074 (let ((margin (current-indentation)))
10075 (unless line-exists (vhdl-comment-display-line))
10076 (insert "\n") (indent-to margin)
10077 (insert "\n") (indent-to margin)
10078 (vhdl-comment-display-line)
10079 (end-of-line -0)
10080 (insert "-- ")))
10082 (defun vhdl-comment-display-line ()
10083 "Displays one line of dashes."
10084 (interactive)
10085 (while (= (preceding-char) ?-) (delete-char -2))
10086 (let* ((col (current-column))
10087 (len (- end-comment-column col)))
10088 (insert-char ?- len)))
10090 (defun vhdl-comment-append-inline ()
10091 "Append empty inline comment to current line."
10092 (interactive)
10093 (end-of-line)
10094 (delete-horizontal-space)
10095 (insert " ")
10096 (indent-to comment-column)
10097 (insert "-- "))
10099 (defun vhdl-comment-insert-inline (&optional string always-insert)
10100 "Insert inline comment."
10101 (when (or (and string (or vhdl-self-insert-comments always-insert))
10102 (and (not string) vhdl-prompt-for-comments))
10103 (let ((position (point)))
10104 (insert " ")
10105 (indent-to comment-column)
10106 (insert "-- ")
10107 (if (not (or (and string (progn (insert string) t))
10108 (vhdl-template-field "[comment]" nil t)))
10109 (delete-region position (point))
10110 (while (= (preceding-char) ? ) (delete-backward-char 1))
10111 ; (when (> (current-column) end-comment-column)
10112 ; (setq position (point-marker))
10113 ; (re-search-backward "-- ")
10114 ; (insert "\n")
10115 ; (indent-to comment-column)
10116 ; (goto-char position))
10117 ))))
10119 (defun vhdl-comment-block ()
10120 "Insert comment for code block."
10121 (when vhdl-prompt-for-comments
10122 (let ((final-pos (point-marker)))
10123 (vhdl-prepare-search-2
10124 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10125 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10126 (let (margin)
10127 (back-to-indentation)
10128 (setq margin (current-column))
10129 (end-of-line -0)
10130 (if (bobp)
10131 (progn (insert "\n") (forward-line -1))
10132 (insert "\n"))
10133 (indent-to margin)
10134 (insert "-- purpose: ")
10135 (unless (vhdl-template-field "[description]" nil t)
10136 (vhdl-line-kill-entire)))))
10137 (goto-char final-pos))))
10139 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10140 "Comment out region if not commented out, uncomment otherwise."
10141 (interactive "r\nP")
10142 (save-excursion
10143 (goto-char (1- end))
10144 (end-of-line)
10145 (setq end (point-marker))
10146 (goto-char beg)
10147 (beginning-of-line)
10148 (setq beg (point))
10149 (if (looking-at comment-start)
10150 (comment-region beg end '(4))
10151 (comment-region beg end))))
10153 (defun vhdl-comment-uncomment-line (&optional arg)
10154 "Comment out line if not commented out, uncomment otherwise."
10155 (interactive "p")
10156 (save-excursion
10157 (beginning-of-line)
10158 (let ((position (point)))
10159 (forward-line (or arg 1))
10160 (vhdl-comment-uncomment-region position (point)))))
10162 (defun vhdl-comment-kill-region (beg end)
10163 "Kill comments in region."
10164 (interactive "r")
10165 (save-excursion
10166 (goto-char end)
10167 (setq end (point-marker))
10168 (goto-char beg)
10169 (beginning-of-line)
10170 (while (< (point) end)
10171 (if (looking-at "^\\(\\s-*--.*\n\\)")
10172 (progn (delete-region (match-beginning 1) (match-end 1)))
10173 (beginning-of-line 2)))))
10175 (defun vhdl-comment-kill-inline-region (beg end)
10176 "Kill inline comments in region."
10177 (interactive "r")
10178 (save-excursion
10179 (goto-char end)
10180 (setq end (point-marker))
10181 (goto-char beg)
10182 (beginning-of-line)
10183 (while (< (point) end)
10184 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10185 (delete-region (match-beginning 1) (match-end 1)))
10186 (beginning-of-line 2))))
10188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10189 ;; Subtemplates
10191 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10192 "Insert a begin ... end pair with optional name after the end.
10193 Point is left between them."
10194 (let (position)
10195 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10196 (indent-to margin)
10197 (vhdl-insert-keyword "BEGIN")
10198 (when (and (or construct name) vhdl-self-insert-comments)
10199 (insert " --")
10200 (when construct (insert " ") (vhdl-insert-keyword construct))
10201 (when name (insert " " name)))
10202 (insert "\n")
10203 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10204 (indent-to (+ margin vhdl-basic-offset))
10205 (setq position (point))
10206 (insert "\n")
10207 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10208 (indent-to margin)
10209 (vhdl-insert-keyword "END")
10210 (when construct (insert " ") (vhdl-insert-keyword construct))
10211 (insert (if name (concat " " name) "") ";")
10212 (goto-char position)))
10214 (defun vhdl-template-argument-list (&optional is-function)
10215 "Read from user a procedure or function argument list."
10216 (insert " (")
10217 (let ((margin (current-column))
10218 (start (point))
10219 (end-pos (point))
10220 not-empty interface semicolon-pos)
10221 (unless vhdl-argument-list-indent
10222 (setq margin (+ (current-indentation) vhdl-basic-offset))
10223 (insert "\n")
10224 (indent-to margin))
10225 (setq interface (vhdl-template-field
10226 (concat "[CONSTANT | SIGNAL"
10227 (unless is-function " | VARIABLE") "]") " " t))
10228 (while (vhdl-template-field "[names]" nil t)
10229 (setq not-empty t)
10230 (insert " : ")
10231 (unless is-function
10232 (if (and interface (equal (upcase interface) "CONSTANT"))
10233 (vhdl-insert-keyword "IN ")
10234 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10235 (vhdl-template-field "type")
10236 (setq semicolon-pos (point))
10237 (insert ";")
10238 (vhdl-comment-insert-inline)
10239 (setq end-pos (point))
10240 (insert "\n")
10241 (indent-to margin)
10242 (setq interface (vhdl-template-field
10243 (concat "[CONSTANT | SIGNAL"
10244 (unless is-function " | VARIABLE") "]") " " t)))
10245 (delete-region end-pos (point))
10246 (when semicolon-pos (goto-char semicolon-pos))
10247 (if not-empty
10248 (progn (delete-char 1) (insert ")"))
10249 (delete-backward-char 2))))
10251 (defun vhdl-template-generic-list (optional &optional no-value)
10252 "Read from user a generic spec argument list."
10253 (let (margin
10254 (start (point)))
10255 (vhdl-insert-keyword "GENERIC (")
10256 (setq margin (current-column))
10257 (unless vhdl-argument-list-indent
10258 (let ((position (point)))
10259 (back-to-indentation)
10260 (setq margin (+ (current-column) vhdl-basic-offset))
10261 (goto-char position)
10262 (insert "\n")
10263 (indent-to margin)))
10264 (let ((vhdl-generics (vhdl-template-field
10265 (concat (and optional "[") "name"
10266 (and no-value "s") (and optional "]"))
10267 nil optional)))
10268 (if (not vhdl-generics)
10269 (if optional
10270 (progn (vhdl-line-kill-entire) (end-of-line -0)
10271 (unless vhdl-argument-list-indent
10272 (vhdl-line-kill-entire) (end-of-line -0)))
10273 (vhdl-template-undo start (point))
10274 nil )
10275 (insert " : ")
10276 (let (semicolon-pos end-pos)
10277 (while vhdl-generics
10278 (vhdl-template-field "type")
10279 (if no-value
10280 (progn (setq semicolon-pos (point))
10281 (insert ";"))
10282 (insert " := ")
10283 (unless (vhdl-template-field "[value]" nil t)
10284 (delete-char -4))
10285 (setq semicolon-pos (point))
10286 (insert ";"))
10287 (vhdl-comment-insert-inline)
10288 (setq end-pos (point))
10289 (insert "\n")
10290 (indent-to margin)
10291 (setq vhdl-generics (vhdl-template-field
10292 (concat "[name" (and no-value "s") "]")
10293 " : " t)))
10294 (delete-region end-pos (point))
10295 (goto-char semicolon-pos)
10296 (insert ")")
10297 (end-of-line)
10298 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10299 t)))))
10301 (defun vhdl-template-port-list (optional)
10302 "Read from user a port spec argument list."
10303 (let ((start (point))
10304 margin vhdl-ports object)
10305 (vhdl-insert-keyword "PORT (")
10306 (setq margin (current-column))
10307 (unless vhdl-argument-list-indent
10308 (let ((position (point)))
10309 (back-to-indentation)
10310 (setq margin (+ (current-column) vhdl-basic-offset))
10311 (goto-char position)
10312 (insert "\n")
10313 (indent-to margin)))
10314 (when (vhdl-standard-p 'ams)
10315 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10316 " " t)))
10317 (setq vhdl-ports (vhdl-template-field
10318 (concat (and optional "[") "names" (and optional "]"))
10319 nil optional))
10320 (if (not vhdl-ports)
10321 (if optional
10322 (progn (vhdl-line-kill-entire) (end-of-line -0)
10323 (unless vhdl-argument-list-indent
10324 (vhdl-line-kill-entire) (end-of-line -0)))
10325 (vhdl-template-undo start (point))
10326 nil)
10327 (insert " : ")
10328 (let (semicolon-pos end-pos)
10329 (while vhdl-ports
10330 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10331 (vhdl-template-field "IN | OUT | INOUT" " "))
10332 ((equal "QUANTITY" (upcase object))
10333 (vhdl-template-field "[IN | OUT]" " " t)))
10334 (vhdl-template-field
10335 (if (and object (equal "TERMINAL" (upcase object)))
10336 "nature" "type"))
10337 (setq semicolon-pos (point))
10338 (insert ";")
10339 (vhdl-comment-insert-inline)
10340 (setq end-pos (point))
10341 (insert "\n")
10342 (indent-to margin)
10343 (when (vhdl-standard-p 'ams)
10344 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10345 " " t)))
10346 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10347 (delete-region end-pos (point))
10348 (goto-char semicolon-pos)
10349 (insert ")")
10350 (end-of-line)
10351 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10352 t))))
10354 (defun vhdl-template-generate-body (margin label)
10355 "Insert body for generate template."
10356 (vhdl-insert-keyword " GENERATE")
10357 ; (if (not (vhdl-standard-p '87))
10358 ; (vhdl-template-begin-end "GENERATE" label margin)
10359 (insert "\n\n")
10360 (indent-to margin)
10361 (vhdl-insert-keyword "END GENERATE ")
10362 (insert label ";")
10363 (end-of-line 0)
10364 (indent-to (+ margin vhdl-basic-offset)))
10366 (defun vhdl-template-insert-date ()
10367 "Insert date in appropriate format."
10368 (interactive)
10369 (insert
10370 (cond
10371 ;; 'american, 'european, 'scientific kept for backward compatibility
10372 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10373 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10374 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10375 (t (format-time-string vhdl-date-format nil)))))
10377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10378 ;; Help functions
10380 (defun vhdl-electric-space (count)
10381 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10382 if in comment and past end-comment-column."
10383 (interactive "p")
10384 (cond ((vhdl-in-comment-p)
10385 (self-insert-command count)
10386 (cond ((>= (current-column) (+ 2 end-comment-column))
10387 (backward-char 1)
10388 (skip-chars-backward "^ \t\n")
10389 (indent-new-comment-line)
10390 (skip-chars-forward "^ \t\n")
10391 (forward-char 1))
10392 ((>= (current-column) end-comment-column)
10393 (indent-new-comment-line))
10394 (t nil)))
10395 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10396 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10397 (vhdl-prepare-search-1
10398 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10399 (self-insert-command count))
10400 (t (self-insert-command count))))
10402 (defun vhdl-template-field (prompt &optional follow-string optional
10403 begin end is-string default)
10404 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10405 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10406 an empty string is inserted, return nil and call `vhdl-template-undo' for
10407 the region between BEGIN and END. IS-STRING indicates whether a string
10408 with double-quotes is to be inserted. DEFAULT specifies a default string."
10409 (let ((position (point))
10410 string)
10411 (insert "<" prompt ">")
10412 (setq string
10413 (condition-case ()
10414 (read-from-minibuffer (concat prompt ": ")
10415 (or (and is-string '("\"\"" . 2)) default)
10416 vhdl-minibuffer-local-map)
10417 (quit (if (and optional begin end)
10418 (progn (beep) "")
10419 (keyboard-quit)))))
10420 (when (or (not (equal string "")) optional)
10421 (delete-region position (point)))
10422 (when (and (equal string "") optional begin end)
10423 (vhdl-template-undo begin end)
10424 (message "Template aborted"))
10425 (unless (equal string "")
10426 (insert string)
10427 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10428 vhdl-keywords-regexp)
10429 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10430 vhdl-types-regexp)
10431 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10432 (concat "'" vhdl-attributes-regexp))
10433 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10434 vhdl-enum-values-regexp))
10435 (when (or (not (equal string "")) (not optional))
10436 (insert (or follow-string "")))
10437 (if (equal string "") nil string)))
10439 (defun vhdl-decision-query (string prompt &optional optional)
10440 "Query a decision from the user."
10441 (let ((start (point)))
10442 (when string (vhdl-insert-keyword (concat string " ")))
10443 (message "%s" (or prompt ""))
10444 (let ((char (read-char)))
10445 (delete-region start (point))
10446 (if (and optional (eq char ?\r))
10447 (progn (insert " ")
10448 (unexpand-abbrev)
10449 (throw 'abort "ERROR: Template aborted"))
10450 char))))
10452 (defun vhdl-insert-keyword (keyword)
10453 "Insert KEYWORD and adjust case."
10454 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10456 (defun vhdl-case-keyword (keyword)
10457 "Adjust case of KEYWORD."
10458 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10460 (defun vhdl-case-word (num)
10461 "Adjust case of following NUM words."
10462 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10464 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10465 "If preceeding character is part of a word or a paren then hippie-expand,
10466 else insert tab (used for word completion in VHDL minibuffer)."
10467 (interactive "P")
10468 (cond
10469 ;; expand word
10470 ((= (char-syntax (preceding-char)) ?w)
10471 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10472 (case-replace nil)
10473 (hippie-expand-only-buffers
10474 (or (and (boundp 'hippie-expand-only-buffers)
10475 hippie-expand-only-buffers)
10476 '(vhdl-mode))))
10477 (vhdl-expand-abbrev prefix-arg)))
10478 ;; expand parenthesis
10479 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10480 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10481 (case-replace nil))
10482 (vhdl-expand-paren prefix-arg)))
10483 ;; insert tab
10484 (t (insert-tab))))
10486 (defun vhdl-template-search-prompt ()
10487 "Search for left out template prompts and query again."
10488 (interactive)
10489 (vhdl-prepare-search-2
10490 (when (or (re-search-forward
10491 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10492 (re-search-backward
10493 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10494 (let ((string (match-string 1)))
10495 (replace-match "")
10496 (vhdl-template-field string)))))
10498 (defun vhdl-template-undo (begin end)
10499 "Undo aborted template by deleting region and unexpanding the keyword."
10500 (cond (vhdl-template-invoked-by-hook
10501 (goto-char end)
10502 (insert " ")
10503 (delete-region begin end)
10504 (unexpand-abbrev))
10505 (t (delete-region begin end))))
10507 (defun vhdl-insert-string-or-file (string)
10508 "Insert STRING or file contents if STRING is an existing file name."
10509 (unless (equal string "")
10510 (let ((file-name
10511 (progn (string-match "^\\([^\n]+\\)" string)
10512 (vhdl-resolve-env-variable (match-string 1 string)))))
10513 (if (file-exists-p file-name)
10514 (forward-char (cadr (insert-file-contents file-name)))
10515 (insert string)))))
10517 (defun vhdl-beginning-of-block ()
10518 "Move cursor to the beginning of the enclosing block."
10519 (let (pos)
10520 (save-excursion
10521 (beginning-of-line)
10522 ;; search backward for block beginning or end
10523 (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))
10524 ;; not consider subprogram declarations
10525 (or (and (match-string 5)
10526 (save-match-data
10527 (save-excursion
10528 (goto-char (match-end 5))
10529 (forward-word 1)
10530 (vhdl-forward-syntactic-ws)
10531 (when (looking-at "(")
10532 (forward-sexp))
10533 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10534 (match-string 1)))
10535 ;; not consider configuration specifications
10536 (and (match-string 6)
10537 (save-match-data
10538 (save-excursion
10539 (vhdl-end-of-block)
10540 (beginning-of-line)
10541 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10542 (match-string 2))
10543 ;; skip subblock if block end found
10544 (vhdl-beginning-of-block)))
10545 (when pos (goto-char pos))))
10547 (defun vhdl-end-of-block ()
10548 "Move cursor to the end of the enclosing block."
10549 (let (pos)
10550 (save-excursion
10551 (end-of-line)
10552 ;; search forward for block beginning or end
10553 (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))
10554 ;; not consider subprogram declarations
10555 (or (and (match-string 5)
10556 (save-match-data
10557 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10558 (match-string 1)))
10559 ;; not consider configuration specifications
10560 (and (match-string 6)
10561 (save-match-data
10562 (save-excursion
10563 (vhdl-end-of-block)
10564 (beginning-of-line)
10565 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10566 (not (match-string 2)))
10567 ;; skip subblock if block beginning found
10568 (vhdl-end-of-block)))
10569 (when pos (goto-char pos))))
10571 (defun vhdl-sequential-statement-p ()
10572 "Check if point is within sequential statement part."
10573 (let ((start (point)))
10574 (save-excursion
10575 (vhdl-prepare-search-2
10576 ;; is sequential statement if ...
10577 (and (re-search-backward "^\\s-*begin\\>" nil t)
10578 ;; ... point is between "begin" and "end" of ...
10579 (progn (vhdl-end-of-block)
10580 (< start (point)))
10581 ;; ... a sequential block
10582 (progn (vhdl-beginning-of-block)
10583 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10585 (defun vhdl-in-argument-list-p ()
10586 "Check if within an argument list."
10587 (save-excursion
10588 (vhdl-prepare-search-2
10589 (or (string-match "arglist"
10590 (format "%s" (caar (vhdl-get-syntactic-context))))
10591 (progn (beginning-of-line)
10592 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10595 ;; Abbrev hooks
10597 (defun vhdl-hooked-abbrev (func)
10598 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10599 but not if inside a comment or quote."
10600 (if (or (vhdl-in-literal)
10601 (save-excursion
10602 (forward-word -1)
10603 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10604 (progn
10605 (insert " ")
10606 (unexpand-abbrev)
10607 (delete-char -1))
10608 (if (not vhdl-electric-mode)
10609 (progn
10610 (insert " ")
10611 (unexpand-abbrev)
10612 (backward-word 1)
10613 (vhdl-case-word 1)
10614 (delete-char 1))
10615 (let ((invoke-char last-command-char)
10616 (abbrev-mode -1)
10617 (vhdl-template-invoked-by-hook t))
10618 (let ((caught (catch 'abort
10619 (funcall func))))
10620 (when (stringp caught) (message "%s" caught)))
10621 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10622 ;; delete CR which is still in event queue
10623 (if (fboundp 'enqueue-eval-event)
10624 (enqueue-eval-event 'delete-char -1)
10625 (setq unread-command-events ; push back a delete char
10626 (list (vhdl-character-to-event ?\177))))))))
10628 (defun vhdl-template-alias-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-alias))
10630 (defun vhdl-template-architecture-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10632 (defun vhdl-template-assert-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-assert))
10634 (defun vhdl-template-attribute-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10636 (defun vhdl-template-block-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-block))
10638 (defun vhdl-template-break-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-break))
10640 (defun vhdl-template-case-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-case))
10642 (defun vhdl-template-component-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-component))
10644 (defun vhdl-template-instance-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-instance))
10646 (defun vhdl-template-conditional-signal-asst-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10648 (defun vhdl-template-configuration-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10650 (defun vhdl-template-constant-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-constant))
10652 (defun vhdl-template-disconnect-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10654 (defun vhdl-template-display-comment-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-comment-display))
10656 (defun vhdl-template-else-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-else))
10658 (defun vhdl-template-elsif-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10660 (defun vhdl-template-entity-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-entity))
10662 (defun vhdl-template-exit-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-exit))
10664 (defun vhdl-template-file-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-file))
10666 (defun vhdl-template-for-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-for))
10668 (defun vhdl-template-function-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-function))
10670 (defun vhdl-template-generic-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-generic))
10672 (defun vhdl-template-group-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-group))
10674 (defun vhdl-template-library-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-library))
10676 (defun vhdl-template-limit-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-limit))
10678 (defun vhdl-template-if-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-if))
10680 (defun vhdl-template-bare-loop-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10682 (defun vhdl-template-map-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-map))
10684 (defun vhdl-template-nature-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-nature))
10686 (defun vhdl-template-next-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-next))
10688 (defun vhdl-template-others-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-others))
10690 (defun vhdl-template-package-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-package))
10692 (defun vhdl-template-port-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-port))
10694 (defun vhdl-template-procedural-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10696 (defun vhdl-template-procedure-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10698 (defun vhdl-template-process-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-process))
10700 (defun vhdl-template-quantity-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10702 (defun vhdl-template-report-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-report))
10704 (defun vhdl-template-return-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-return))
10706 (defun vhdl-template-selected-signal-asst-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10708 (defun vhdl-template-signal-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-signal))
10710 (defun vhdl-template-subnature-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10712 (defun vhdl-template-subtype-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10714 (defun vhdl-template-terminal-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10716 (defun vhdl-template-type-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-type))
10718 (defun vhdl-template-use-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-use))
10720 (defun vhdl-template-variable-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-variable))
10722 (defun vhdl-template-wait-hook ()
10723 (vhdl-hooked-abbrev 'vhdl-template-wait))
10724 (defun vhdl-template-when-hook ()
10725 (vhdl-hooked-abbrev 'vhdl-template-when))
10726 (defun vhdl-template-while-loop-hook ()
10727 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10728 (defun vhdl-template-with-hook ()
10729 (vhdl-hooked-abbrev 'vhdl-template-with))
10730 (defun vhdl-template-and-hook ()
10731 (vhdl-hooked-abbrev 'vhdl-template-and))
10732 (defun vhdl-template-or-hook ()
10733 (vhdl-hooked-abbrev 'vhdl-template-or))
10734 (defun vhdl-template-nand-hook ()
10735 (vhdl-hooked-abbrev 'vhdl-template-nand))
10736 (defun vhdl-template-nor-hook ()
10737 (vhdl-hooked-abbrev 'vhdl-template-nor))
10738 (defun vhdl-template-xor-hook ()
10739 (vhdl-hooked-abbrev 'vhdl-template-xor))
10740 (defun vhdl-template-xnor-hook ()
10741 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10742 (defun vhdl-template-not-hook ()
10743 (vhdl-hooked-abbrev 'vhdl-template-not))
10745 (defun vhdl-template-default-hook ()
10746 (vhdl-hooked-abbrev 'vhdl-template-default))
10747 (defun vhdl-template-default-indent-hook ()
10748 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10751 ;; Template insertion from completion list
10753 (defun vhdl-template-insert-construct (name)
10754 "Insert the built-in construct template with NAME."
10755 (interactive
10756 (list (let ((completion-ignore-case t))
10757 (completing-read "Construct name: "
10758 vhdl-template-construct-alist nil t))))
10759 (vhdl-template-insert-fun
10760 (cadr (assoc name vhdl-template-construct-alist))))
10762 (defun vhdl-template-insert-package (name)
10763 "Insert the built-in package template with NAME."
10764 (interactive
10765 (list (let ((completion-ignore-case t))
10766 (completing-read "Package name: "
10767 vhdl-template-package-alist nil t))))
10768 (vhdl-template-insert-fun
10769 (cadr (assoc name vhdl-template-package-alist))))
10771 (defun vhdl-template-insert-directive (name)
10772 "Insert the built-in directive template with NAME."
10773 (interactive
10774 (list (let ((completion-ignore-case t))
10775 (completing-read "Directive name: "
10776 vhdl-template-directive-alist nil t))))
10777 (vhdl-template-insert-fun
10778 (cadr (assoc name vhdl-template-directive-alist))))
10780 (defun vhdl-template-insert-fun (fun)
10781 "Call FUN to insert a built-in template."
10782 (let ((caught (catch 'abort (when fun (funcall fun)))))
10783 (when (stringp caught) (message "%s" caught))))
10786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10787 ;;; Models
10788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10790 (defun vhdl-model-insert (model-name)
10791 "Insert the user model with name MODEL-NAME."
10792 (interactive
10793 (let ((completion-ignore-case t))
10794 (list (completing-read "Model name: " vhdl-model-alist))))
10795 (indent-according-to-mode)
10796 (let ((start (point-marker))
10797 (margin (current-indentation))
10798 model position prompt string end)
10799 (vhdl-prepare-search-2
10800 (when (setq model (assoc model-name vhdl-model-alist))
10801 ;; insert model
10802 (beginning-of-line)
10803 (delete-horizontal-space)
10804 (goto-char start)
10805 (vhdl-insert-string-or-file (nth 1 model))
10806 (setq end (point-marker))
10807 ;; indent code
10808 (goto-char start)
10809 (beginning-of-line)
10810 (while (< (point) end)
10811 (unless (looking-at "^$")
10812 (insert-char ? margin))
10813 (beginning-of-line 2))
10814 (goto-char start)
10815 ;; insert clock
10816 (unless (equal "" vhdl-clock-name)
10817 (while (re-search-forward "<clock>" end t)
10818 (replace-match vhdl-clock-name)))
10819 (goto-char start)
10820 ;; insert reset
10821 (unless (equal "" vhdl-reset-name)
10822 (while (re-search-forward "<reset>" end t)
10823 (replace-match vhdl-reset-name)))
10824 ;; replace header prompts
10825 (vhdl-template-replace-header-keywords start end nil t)
10826 (goto-char start)
10827 ;; query other prompts
10828 (while (re-search-forward
10829 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10830 (unless (equal "cursor" (match-string 1))
10831 (setq position (match-beginning 1))
10832 (setq prompt (match-string 1))
10833 (replace-match "")
10834 (setq string (vhdl-template-field prompt nil t))
10835 ;; replace occurrences of same prompt
10836 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10837 (replace-match (or string "")))
10838 (goto-char position)))
10839 (goto-char start)
10840 ;; goto final position
10841 (if (re-search-forward "<cursor>" end t)
10842 (replace-match "")
10843 (goto-char end))))))
10845 (defun vhdl-model-defun ()
10846 "Define help and hook functions for user models."
10847 (let ((model-alist vhdl-model-alist)
10848 model-name model-keyword)
10849 (while model-alist
10850 ;; define functions for user models that can be invoked from menu and key
10851 ;; bindings and which themselves call `vhdl-model-insert' with the model
10852 ;; name as argument
10853 (setq model-name (nth 0 (car model-alist)))
10854 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10855 ,(concat "Insert model for \"" model-name "\".")
10856 (interactive)
10857 (vhdl-model-insert ,model-name)))
10858 ;; define hooks for user models that are invoked from keyword abbrevs
10859 (setq model-keyword (nth 3 (car model-alist)))
10860 (unless (equal model-keyword "")
10861 (eval `(defun
10862 ,(vhdl-function-name
10863 "vhdl-model" model-name "hook") ()
10864 (vhdl-hooked-abbrev
10865 ',(vhdl-function-name "vhdl-model" model-name)))))
10866 (setq model-alist (cdr model-alist)))))
10868 (vhdl-model-defun)
10871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10872 ;;; Port translation
10873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10875 (defvar vhdl-port-list nil
10876 "Variable to hold last port map parsed.")
10877 ;; structure: (parenthesised expression means list of such entries)
10878 ;; (ent-name
10879 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10880 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10881 ;; (lib-name pack-key))
10883 (defun vhdl-parse-string (string &optional optional)
10884 "Check that the text following point matches the regexp in STRING."
10885 (if (looking-at string)
10886 (goto-char (match-end 0))
10887 (unless optional
10888 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10889 (vhdl-current-line) string)))
10890 nil))
10892 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10893 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10894 (vhdl-prepare-search-1
10895 (if (string-match (car regexp-cons) string)
10896 (if adjust-case
10897 (funcall vhdl-file-name-case
10898 (replace-match (cdr regexp-cons) t nil string))
10899 (replace-match (cdr regexp-cons) t nil string))
10900 string)))
10902 (defun vhdl-parse-group-comment ()
10903 "Parse comment and empty lines between groups of lines."
10904 (let ((start (point))
10905 string)
10906 (vhdl-forward-comment (point-max))
10907 (setq string (buffer-substring-no-properties start (point)))
10908 (vhdl-forward-syntactic-ws)
10909 ;; strip off leading blanks and first newline
10910 (while (string-match "^\\(\\s-+\\)" string)
10911 (setq string (concat (substring string 0 (match-beginning 1))
10912 (substring string (match-end 1)))))
10913 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10914 (substring string 1)
10915 string)))
10917 (defun vhdl-paste-group-comment (string indent)
10918 "Paste comment and empty lines from STRING between groups of lines
10919 with INDENT."
10920 (let ((pos (point-marker)))
10921 (when (> indent 0)
10922 (while (string-match "^\\(--\\)" string)
10923 (setq string (concat (substring string 0 (match-beginning 1))
10924 (make-string indent ? )
10925 (substring string (match-beginning 1))))))
10926 (beginning-of-line)
10927 (insert string)
10928 (goto-char pos)))
10930 (defvar vhdl-port-flattened nil
10931 "Indicates whether a port has been flattened.")
10933 (defun vhdl-port-flatten (&optional as-alist)
10934 "Flatten port list so that only one generic/port exists per line.
10935 This operation is performed on an internally stored port and is only
10936 reflected in a subsequent paste operation."
10937 (interactive)
10938 (if (not vhdl-port-list)
10939 (error "ERROR: No port has been read")
10940 (message "Flattening port for next paste...")
10941 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10942 (old-vhdl-port-list (cdr vhdl-port-list))
10943 old-port-list new-port-list old-port new-port names)
10944 ;; traverse port list and flatten entries
10945 (while (cdr old-vhdl-port-list)
10946 (setq old-port-list (car old-vhdl-port-list))
10947 (setq new-port-list nil)
10948 (while old-port-list
10949 (setq old-port (car old-port-list))
10950 (setq names (car old-port))
10951 (while names
10952 (setq new-port (cons (if as-alist (car names) (list (car names)))
10953 (cdr old-port)))
10954 (setq new-port-list (append new-port-list (list new-port)))
10955 (setq names (cdr names)))
10956 (setq old-port-list (cdr old-port-list)))
10957 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10958 (setq new-vhdl-port-list (append new-vhdl-port-list
10959 (list new-port-list))))
10960 (setq vhdl-port-list
10961 (append new-vhdl-port-list (list old-vhdl-port-list))
10962 vhdl-port-flattened t)
10963 (message "Flattening port for next paste...done"))))
10965 (defvar vhdl-port-reversed-direction nil
10966 "Indicates whether port directions are reversed.")
10968 (defun vhdl-port-reverse-direction ()
10969 "Reverse direction for all ports (useful in testbenches).
10970 This operation is performed on an internally stored port and is only
10971 reflected in a subsequent paste operation."
10972 (interactive)
10973 (if (not vhdl-port-list)
10974 (error "ERROR: No port has been read")
10975 (message "Reversing port directions for next paste...")
10976 (let ((port-list (nth 2 vhdl-port-list))
10977 port-dir-car port-dir)
10978 ;; traverse port list and reverse directions
10979 (while port-list
10980 (setq port-dir-car (cddr (car port-list))
10981 port-dir (car port-dir-car))
10982 (setcar port-dir-car
10983 (cond ((equal port-dir "in") "out")
10984 ((equal port-dir "out") "in")
10985 (t port-dir)))
10986 (setq port-list (cdr port-list)))
10987 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10988 (message "Reversing port directions for next paste...done"))))
10990 (defun vhdl-port-copy ()
10991 "Get generic and port information from an entity or component declaration."
10992 (interactive)
10993 (save-excursion
10994 (let (parse-error end-of-list
10995 decl-type name generic-list port-list context-clause
10996 object names direct type init comment group-comment)
10997 (vhdl-prepare-search-2
10998 (setq
10999 parse-error
11000 (catch 'parse
11001 ;; check if within entity or component declaration
11002 (end-of-line)
11003 (when (or (not (re-search-backward
11004 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11005 (equal "END" (upcase (match-string 1))))
11006 (throw 'parse "ERROR: Not within an entity or component declaration"))
11007 (setq decl-type (downcase (match-string-no-properties 1)))
11008 (forward-word 1)
11009 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11010 (setq name (match-string-no-properties 1))
11011 (message "Reading port of %s \"%s\"..." decl-type name)
11012 (vhdl-forward-syntactic-ws)
11013 ;; parse generic clause
11014 (when (vhdl-parse-string "generic[ \t\n]*(" t)
11015 ;; parse group comment and spacing
11016 (setq group-comment (vhdl-parse-group-comment))
11017 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11018 (while (not end-of-list)
11019 ;; parse names (accept extended identifiers)
11020 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11021 (setq names (list (match-string-no-properties 1)))
11022 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11023 (setq names
11024 (append names (list (match-string-no-properties 1)))))
11025 ;; parse type
11026 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11027 (setq type (match-string-no-properties 1))
11028 (setq comment nil)
11029 (while (looking-at "(")
11030 (setq type
11031 (concat type
11032 (buffer-substring-no-properties
11033 (point) (progn (forward-sexp) (point)))
11034 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11035 (match-string-no-properties 1)))))
11036 ;; special case: closing parenthesis is on separate line
11037 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11038 (setq comment (substring type (match-beginning 2)))
11039 (setq type (substring type 0 (match-beginning 1))))
11040 ;; strip of trailing group-comment
11041 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11042 (setq type (substring type 0 (match-end 1)))
11043 ;; parse initialization expression
11044 (setq init nil)
11045 (when (vhdl-parse-string ":=[ \t\n]*" t)
11046 (vhdl-parse-string "\\([^();\n]*\\)")
11047 (setq init (match-string-no-properties 1))
11048 (while (looking-at "(")
11049 (setq init
11050 (concat init
11051 (buffer-substring-no-properties
11052 (point) (progn (forward-sexp) (point)))
11053 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11054 (match-string-no-properties 1))))))
11055 ;; special case: closing parenthesis is on separate line
11056 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11057 (setq comment (substring init (match-beginning 2)))
11058 (setq init (substring init 0 (match-beginning 1)))
11059 (vhdl-forward-syntactic-ws))
11060 (skip-chars-forward " \t")
11061 ;; parse inline comment, special case: as above, no initial.
11062 (unless comment
11063 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11064 (match-string-no-properties 1))))
11065 (vhdl-forward-syntactic-ws)
11066 (setq end-of-list (vhdl-parse-string ")" t))
11067 (vhdl-parse-string "\\s-*;\\s-*")
11068 ;; parse inline comment
11069 (unless comment
11070 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11071 (match-string-no-properties 1))))
11072 ;; save everything in list
11073 (setq generic-list (append generic-list
11074 (list (list names type init
11075 comment group-comment))))
11076 ;; parse group comment and spacing
11077 (setq group-comment (vhdl-parse-group-comment))))
11078 ;; parse port clause
11079 (when (vhdl-parse-string "port[ \t\n]*(" t)
11080 ;; parse group comment and spacing
11081 (setq group-comment (vhdl-parse-group-comment))
11082 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11083 (while (not end-of-list)
11084 ;; parse object
11085 (setq object
11086 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11087 (match-string-no-properties 1)))
11088 ;; parse names (accept extended identifiers)
11089 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11090 (setq names (list (match-string-no-properties 1)))
11091 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11092 (setq names (append names (list (match-string-no-properties 1)))))
11093 ;; parse direction
11094 (vhdl-parse-string ":[ \t\n]*")
11095 (setq direct
11096 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11097 (match-string-no-properties 1)))
11098 ;; parse type
11099 (vhdl-parse-string "\\([^();\n]+\\)")
11100 (setq type (match-string-no-properties 1))
11101 (setq comment nil)
11102 (while (looking-at "(")
11103 (setq type (concat type
11104 (buffer-substring-no-properties
11105 (point) (progn (forward-sexp) (point)))
11106 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11107 (match-string-no-properties 1)))))
11108 ;; special case: closing parenthesis is on separate line
11109 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11110 (setq comment (substring type (match-beginning 2)))
11111 (setq type (substring type 0 (match-beginning 1))))
11112 ;; strip of trailing group-comment
11113 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11114 (setq type (substring type 0 (match-end 1)))
11115 (vhdl-forward-syntactic-ws)
11116 (setq end-of-list (vhdl-parse-string ")" t))
11117 (vhdl-parse-string "\\s-*;\\s-*")
11118 ;; parse inline comment
11119 (unless comment
11120 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11121 (match-string-no-properties 1))))
11122 ;; save everything in list
11123 (setq port-list (append port-list
11124 (list (list names object direct type
11125 comment group-comment))))
11126 ;; parse group comment and spacing
11127 (setq group-comment (vhdl-parse-group-comment))))
11128 ; (vhdl-parse-string "end\\>")
11129 ;; parse context clause
11130 (setq context-clause (vhdl-scan-context-clause))
11131 ; ;; add surrounding package to context clause
11132 ; (when (and (equal decl-type "component")
11133 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11134 ; (setq context-clause
11135 ; (append context-clause
11136 ; (list (cons (vhdl-work-library)
11137 ; (match-string-no-properties 1))))))
11138 (message "Reading port of %s \"%s\"...done" decl-type name)
11139 nil)))
11140 ;; finish parsing
11141 (if parse-error
11142 (error parse-error)
11143 (setq vhdl-port-list (list name generic-list port-list context-clause)
11144 vhdl-port-reversed-direction nil
11145 vhdl-port-flattened nil)))))
11147 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11148 "Paste a context clause."
11149 (let ((margin (current-indentation))
11150 (clause-list (nth 3 vhdl-port-list))
11151 clause)
11152 (while clause-list
11153 (setq clause (car clause-list))
11154 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11155 (downcase exclude-pack-name)))
11156 (save-excursion
11157 (re-search-backward
11158 (concat "^\\s-*use\\s-+" (car clause)
11159 "\." (cdr clause) "\\>") nil t)))
11160 (vhdl-template-standard-package (car clause) (cdr clause))
11161 (insert "\n"))
11162 (setq clause-list (cdr clause-list)))))
11164 (defun vhdl-port-paste-generic (&optional no-init)
11165 "Paste a generic clause."
11166 (let ((margin (current-indentation))
11167 (generic-list (nth 1 vhdl-port-list))
11168 list-margin start names generic)
11169 ;; paste generic clause
11170 (when generic-list
11171 (setq start (point))
11172 (vhdl-insert-keyword "GENERIC (")
11173 (unless vhdl-argument-list-indent
11174 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11175 (setq list-margin (current-column))
11176 (while generic-list
11177 (setq generic (car generic-list))
11178 ;; paste group comment and spacing
11179 (when (memq vhdl-include-group-comments '(decl always))
11180 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11181 ;; paste names
11182 (setq names (nth 0 generic))
11183 (while names
11184 (insert (car names))
11185 (setq names (cdr names))
11186 (when names (insert ", ")))
11187 ;; paste type
11188 (insert " : " (nth 1 generic))
11189 ;; paste initialization
11190 (when (and (not no-init) (nth 2 generic))
11191 (insert " := " (nth 2 generic)))
11192 (unless (cdr generic-list) (insert ")"))
11193 (insert ";")
11194 ;; paste comment
11195 (when (and vhdl-include-port-comments (nth 3 generic))
11196 (vhdl-comment-insert-inline (nth 3 generic) t))
11197 (setq generic-list (cdr generic-list))
11198 (when generic-list (insert "\n") (indent-to list-margin)))
11199 ;; align generic clause
11200 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11202 (defun vhdl-port-paste-port ()
11203 "Paste a port clause."
11204 (let ((margin (current-indentation))
11205 (port-list (nth 2 vhdl-port-list))
11206 list-margin start names port)
11207 ;; paste port clause
11208 (when port-list
11209 (setq start (point))
11210 (vhdl-insert-keyword "PORT (")
11211 (unless vhdl-argument-list-indent
11212 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11213 (setq list-margin (current-column))
11214 (while port-list
11215 (setq port (car port-list))
11216 ;; paste group comment and spacing
11217 (when (memq vhdl-include-group-comments '(decl always))
11218 (vhdl-paste-group-comment (nth 5 port) list-margin))
11219 ;; paste object
11220 (when (nth 1 port) (insert (nth 1 port) " "))
11221 ;; paste names
11222 (setq names (nth 0 port))
11223 (while names
11224 (insert (car names))
11225 (setq names (cdr names))
11226 (when names (insert ", ")))
11227 ;; paste direction
11228 (insert " : ")
11229 (when (nth 2 port) (insert (nth 2 port) " "))
11230 ;; paste type
11231 (insert (nth 3 port))
11232 (unless (cdr port-list) (insert ")"))
11233 (insert ";")
11234 ;; paste comment
11235 (when (and vhdl-include-port-comments (nth 4 port))
11236 (vhdl-comment-insert-inline (nth 4 port) t))
11237 (setq port-list (cdr port-list))
11238 (when port-list (insert "\n") (indent-to list-margin)))
11239 ;; align port clause
11240 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11242 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11243 "Paste as an entity or component declaration."
11244 (unless no-indent (indent-according-to-mode))
11245 (let ((margin (current-indentation))
11246 (name (nth 0 vhdl-port-list)))
11247 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11248 (insert name)
11249 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11250 (vhdl-insert-keyword " IS"))
11251 ;; paste generic and port clause
11252 (when (nth 1 vhdl-port-list)
11253 (insert "\n")
11254 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11255 (insert "\n"))
11256 (indent-to (+ margin vhdl-basic-offset))
11257 (vhdl-port-paste-generic (eq kind 'component)))
11258 (when (nth 2 vhdl-port-list)
11259 (insert "\n")
11260 (when (and (memq vhdl-insert-empty-lines '(unit all))
11261 (eq kind 'entity))
11262 (insert "\n"))
11263 (indent-to (+ margin vhdl-basic-offset)))
11264 (vhdl-port-paste-port)
11265 (insert "\n")
11266 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11267 (insert "\n"))
11268 (indent-to margin)
11269 (vhdl-insert-keyword "END")
11270 (if (eq kind 'entity)
11271 (progn
11272 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11273 (insert " " name))
11274 (vhdl-insert-keyword " COMPONENT")
11275 (unless (vhdl-standard-p '87) (insert " " name)))
11276 (insert ";")))
11278 (defun vhdl-port-paste-entity (&optional no-indent)
11279 "Paste as an entity declaration."
11280 (interactive)
11281 (if (not vhdl-port-list)
11282 (error "ERROR: No port read")
11283 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11284 (vhdl-port-paste-declaration 'entity no-indent)
11285 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11287 (defun vhdl-port-paste-component (&optional no-indent)
11288 "Paste as a component declaration."
11289 (interactive)
11290 (if (not vhdl-port-list)
11291 (error "ERROR: No port read")
11292 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11293 (vhdl-port-paste-declaration 'component no-indent)
11294 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11296 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11297 "Paste as a generic map."
11298 (interactive)
11299 (unless secondary (indent-according-to-mode))
11300 (let ((margin (current-indentation))
11301 list-margin start generic
11302 (generic-list (nth 1 vhdl-port-list)))
11303 (when generic-list
11304 (setq start (point))
11305 (vhdl-insert-keyword "GENERIC MAP (")
11306 (if (not vhdl-association-list-with-formals)
11307 ;; paste list of actual generics
11308 (while generic-list
11309 (insert (if no-constants
11310 (car (nth 0 (car generic-list)))
11311 (or (nth 2 (car generic-list)) " ")))
11312 (setq generic-list (cdr generic-list))
11313 (insert (if generic-list ", " ")"))
11314 (when (and (not generic-list) secondary
11315 (null (nth 2 vhdl-port-list)))
11316 (insert ";")))
11317 (unless vhdl-argument-list-indent
11318 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11319 (setq list-margin (current-column))
11320 (while generic-list
11321 (setq generic (car generic-list))
11322 ;; paste group comment and spacing
11323 (when (eq vhdl-include-group-comments 'always)
11324 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11325 ;; paste formal and actual generic
11326 (insert (car (nth 0 generic)) " => "
11327 (if no-constants
11328 (car (nth 0 generic))
11329 (or (nth 2 generic) "")))
11330 (setq generic-list (cdr generic-list))
11331 (insert (if generic-list "," ")"))
11332 (when (and (not generic-list) secondary
11333 (null (nth 2 vhdl-port-list)))
11334 (insert ";"))
11335 ;; paste comment
11336 (when (or vhdl-include-type-comments
11337 (and vhdl-include-port-comments (nth 3 generic)))
11338 (vhdl-comment-insert-inline
11339 (concat
11340 (when vhdl-include-type-comments
11341 (concat "[" (nth 1 generic) "] "))
11342 (when vhdl-include-port-comments (nth 3 generic))) t))
11343 (when generic-list (insert "\n") (indent-to list-margin)))
11344 ;; align generic map
11345 (when vhdl-auto-align
11346 (vhdl-align-region-groups start (point) 1 t))))))
11348 (defun vhdl-port-paste-port-map ()
11349 "Paste as a port map."
11350 (let ((margin (current-indentation))
11351 list-margin start port
11352 (port-list (nth 2 vhdl-port-list)))
11353 (when port-list
11354 (setq start (point))
11355 (vhdl-insert-keyword "PORT MAP (")
11356 (if (not vhdl-association-list-with-formals)
11357 ;; paste list of actual ports
11358 (while port-list
11359 (insert (vhdl-replace-string vhdl-actual-port-name
11360 (car (nth 0 (car port-list)))))
11361 (setq port-list (cdr port-list))
11362 (insert (if port-list ", " ")")))
11363 (unless vhdl-argument-list-indent
11364 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11365 (setq list-margin (current-column))
11366 (while port-list
11367 (setq port (car port-list))
11368 ;; paste group comment and spacing
11369 (when (eq vhdl-include-group-comments 'always)
11370 (vhdl-paste-group-comment (nth 5 port) list-margin))
11371 ;; paste formal and actual port
11372 (insert (car (nth 0 port)) " => ")
11373 (insert (vhdl-replace-string vhdl-actual-port-name
11374 (car (nth 0 port))))
11375 (setq port-list (cdr port-list))
11376 (insert (if port-list "," ");"))
11377 ;; paste comment
11378 (when (or vhdl-include-direction-comments
11379 vhdl-include-type-comments
11380 (and vhdl-include-port-comments (nth 4 port)))
11381 (vhdl-comment-insert-inline
11382 (concat
11383 (cond ((and vhdl-include-direction-comments
11384 vhdl-include-type-comments)
11385 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11386 (nth 3 port) "] "))
11387 ((and vhdl-include-direction-comments (nth 2 port))
11388 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11389 (vhdl-include-direction-comments " ")
11390 (vhdl-include-type-comments
11391 (concat "[" (nth 3 port) "] ")))
11392 (when vhdl-include-port-comments (nth 4 port))) t))
11393 (when port-list (insert "\n") (indent-to list-margin)))
11394 ;; align port clause
11395 (when vhdl-auto-align
11396 (vhdl-align-region-groups start (point) 1))))))
11398 (defun vhdl-port-paste-instance (&optional name no-indent title)
11399 "Paste as an instantiation."
11400 (interactive)
11401 (if (not vhdl-port-list)
11402 (error "ERROR: No port read")
11403 (let ((orig-vhdl-port-list vhdl-port-list))
11404 ;; flatten local copy of port list (must be flat for port mapping)
11405 (vhdl-port-flatten)
11406 (unless no-indent (indent-according-to-mode))
11407 (let ((margin (current-indentation)))
11408 ;; paste instantiation
11409 (cond (name
11410 (insert name))
11411 ((equal (cdr vhdl-instance-name) "")
11412 (setq name (vhdl-template-field "instance name")))
11413 ((string-match "\%d" (cdr vhdl-instance-name))
11414 (let ((n 1))
11415 (while (save-excursion
11416 (setq name (format (vhdl-replace-string
11417 vhdl-instance-name
11418 (nth 0 vhdl-port-list)) n))
11419 (goto-char (point-min))
11420 (vhdl-re-search-forward name nil t))
11421 (setq n (1+ n)))
11422 (insert name)))
11423 (t (insert (vhdl-replace-string vhdl-instance-name
11424 (nth 0 vhdl-port-list)))))
11425 (message "Pasting port as instantiation \"%s\"..." name)
11426 (insert ": ")
11427 (when title
11428 (save-excursion
11429 (beginning-of-line)
11430 (indent-to vhdl-basic-offset)
11431 (insert "-- instance \"" name "\"\n")))
11432 (if (not (vhdl-use-direct-instantiation))
11433 (insert (nth 0 vhdl-port-list))
11434 (vhdl-insert-keyword "ENTITY ")
11435 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11436 (when (nth 1 vhdl-port-list)
11437 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11438 (vhdl-port-paste-generic-map t t))
11439 (when (nth 2 vhdl-port-list)
11440 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11441 (vhdl-port-paste-port-map))
11442 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11443 (insert ";"))
11444 (message "Pasting port as instantiation \"%s\"...done" name))
11445 (setq vhdl-port-list orig-vhdl-port-list))))
11447 (defun vhdl-port-paste-constants (&optional no-indent)
11448 "Paste generics as constants."
11449 (interactive)
11450 (if (not vhdl-port-list)
11451 (error "ERROR: No port read")
11452 (let ((orig-vhdl-port-list vhdl-port-list))
11453 (message "Pasting port as constants...")
11454 ;; flatten local copy of port list (must be flat for constant initial.)
11455 (vhdl-port-flatten)
11456 (unless no-indent (indent-according-to-mode))
11457 (let ((margin (current-indentation))
11458 start generic name
11459 (generic-list (nth 1 vhdl-port-list)))
11460 (when generic-list
11461 (setq start (point))
11462 (while generic-list
11463 (setq generic (car generic-list))
11464 ;; paste group comment and spacing
11465 (when (memq vhdl-include-group-comments '(decl always))
11466 (vhdl-paste-group-comment (nth 4 generic) margin))
11467 (vhdl-insert-keyword "CONSTANT ")
11468 ;; paste generic constants
11469 (setq name (nth 0 generic))
11470 (when name
11471 (insert (car name))
11472 ;; paste type
11473 (insert " : " (nth 1 generic))
11474 ;; paste initialization
11475 (when (nth 2 generic)
11476 (insert " := " (nth 2 generic)))
11477 (insert ";")
11478 ;; paste comment
11479 (when (and vhdl-include-port-comments (nth 3 generic))
11480 (vhdl-comment-insert-inline (nth 3 generic) t))
11481 (setq generic-list (cdr generic-list))
11482 (when generic-list (insert "\n") (indent-to margin))))
11483 ;; align signal list
11484 (when vhdl-auto-align
11485 (vhdl-align-region-groups start (point) 1))))
11486 (message "Pasting port as constants...done")
11487 (setq vhdl-port-list orig-vhdl-port-list))))
11489 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11490 "Paste ports as internal signals."
11491 (interactive)
11492 (if (not vhdl-port-list)
11493 (error "ERROR: No port read")
11494 (message "Pasting port as signals...")
11495 (unless no-indent (indent-according-to-mode))
11496 (let ((margin (current-indentation))
11497 start port names
11498 (port-list (nth 2 vhdl-port-list)))
11499 (when port-list
11500 (setq start (point))
11501 (while port-list
11502 (setq port (car port-list))
11503 ;; paste group comment and spacing
11504 (when (memq vhdl-include-group-comments '(decl always))
11505 (vhdl-paste-group-comment (nth 5 port) margin))
11506 ;; paste object
11507 (if (nth 1 port)
11508 (insert (nth 1 port) " ")
11509 (vhdl-insert-keyword "SIGNAL "))
11510 ;; paste actual port signals
11511 (setq names (nth 0 port))
11512 (while names
11513 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11514 (setq names (cdr names))
11515 (when names (insert ", ")))
11516 ;; paste type
11517 (insert " : " (nth 3 port))
11518 ;; paste initialization (inputs only)
11519 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11520 (insert " := " (if (string-match "(.+)" (nth 3 port))
11521 "(others => '0')" "'0'")))
11522 (insert ";")
11523 ;; paste comment
11524 (when (or vhdl-include-direction-comments
11525 (and vhdl-include-port-comments (nth 4 port)))
11526 (vhdl-comment-insert-inline
11527 (concat
11528 (cond ((and vhdl-include-direction-comments (nth 2 port))
11529 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11530 (vhdl-include-direction-comments " "))
11531 (when vhdl-include-port-comments (nth 4 port))) t))
11532 (setq port-list (cdr port-list))
11533 (when port-list (insert "\n") (indent-to margin)))
11534 ;; align signal list
11535 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11536 (message "Pasting port as signals...done")))
11538 (defun vhdl-port-paste-initializations (&optional no-indent)
11539 "Paste ports as signal initializations."
11540 (interactive)
11541 (if (not vhdl-port-list)
11542 (error "ERROR: No port read")
11543 (let ((orig-vhdl-port-list vhdl-port-list))
11544 (message "Pasting port as initializations...")
11545 ;; flatten local copy of port list (must be flat for signal initial.)
11546 (vhdl-port-flatten)
11547 (unless no-indent (indent-according-to-mode))
11548 (let ((margin (current-indentation))
11549 start port name
11550 (port-list (nth 2 vhdl-port-list)))
11551 (when port-list
11552 (setq start (point))
11553 (while port-list
11554 (setq port (car port-list))
11555 ;; paste actual port signal (inputs only)
11556 (when (equal "IN" (upcase (nth 2 port)))
11557 (setq name (car (nth 0 port)))
11558 (insert (vhdl-replace-string vhdl-actual-port-name name))
11559 ;; paste initialization
11560 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11561 "(others => '0')" "'0'") ";"))
11562 (setq port-list (cdr port-list))
11563 (when (and port-list
11564 (equal "IN" (upcase (nth 2 (car port-list)))))
11565 (insert "\n") (indent-to margin)))
11566 ;; align signal list
11567 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11568 (message "Pasting port as initializations...done")
11569 (setq vhdl-port-list orig-vhdl-port-list))))
11571 (defun vhdl-port-paste-testbench ()
11572 "Paste as a bare-bones testbench."
11573 (interactive)
11574 (if (not vhdl-port-list)
11575 (error "ERROR: No port read")
11576 (let ((case-fold-search t)
11577 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11578 (nth 0 vhdl-port-list)))
11579 (source-buffer (current-buffer))
11580 arch-name config-name ent-file-name arch-file-name
11581 ent-buffer arch-buffer position)
11582 ;; open entity file
11583 (unless (eq vhdl-testbench-create-files 'none)
11584 (setq ent-file-name
11585 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11586 ent-name t)
11587 "." (file-name-extension (buffer-file-name))))
11588 (if (file-exists-p ent-file-name)
11589 (if (y-or-n-p
11590 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11591 (progn (find-file ent-file-name)
11592 (erase-buffer)
11593 (set-buffer-modified-p nil))
11594 (if (eq vhdl-testbench-create-files 'separate)
11595 (setq ent-file-name nil)
11596 (error "ERROR: Pasting port as testbench...aborted")))
11597 (find-file ent-file-name)))
11598 (unless (and (eq vhdl-testbench-create-files 'separate)
11599 (null ent-file-name))
11600 ;; paste entity header
11601 (if vhdl-testbench-include-header
11602 (progn (vhdl-template-header
11603 (concat "Testbench for design \""
11604 (nth 0 vhdl-port-list) "\""))
11605 (goto-char (point-max)))
11606 (vhdl-comment-display-line) (insert "\n\n"))
11607 ;; paste std_logic_1164 package
11608 (when vhdl-testbench-include-library
11609 (vhdl-template-package-std-logic-1164)
11610 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11611 ;; paste entity declaration
11612 (vhdl-insert-keyword "ENTITY ")
11613 (insert ent-name)
11614 (vhdl-insert-keyword " IS")
11615 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11616 (insert "\n")
11617 (vhdl-insert-keyword "END ")
11618 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11619 (insert ent-name ";")
11620 (insert "\n\n")
11621 (vhdl-comment-display-line) (insert "\n"))
11622 ;; get architecture name
11623 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11624 (read-from-minibuffer "architecture name: "
11625 nil vhdl-minibuffer-local-map)
11626 (vhdl-replace-string vhdl-testbench-architecture-name
11627 (nth 0 vhdl-port-list))))
11628 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11629 ;; open architecture file
11630 (if (not (eq vhdl-testbench-create-files 'separate))
11631 (insert "\n")
11632 (setq ent-buffer (current-buffer))
11633 (setq arch-file-name
11634 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11635 (concat ent-name " " arch-name) t)
11636 "." (file-name-extension (buffer-file-name))))
11637 (when (and (file-exists-p arch-file-name)
11638 (not (y-or-n-p (concat "File \"" arch-file-name
11639 "\" exists; overwrite? "))))
11640 (error "ERROR: Pasting port as testbench...aborted"))
11641 (find-file arch-file-name)
11642 (erase-buffer)
11643 (set-buffer-modified-p nil)
11644 ;; paste architecture header
11645 (if vhdl-testbench-include-header
11646 (progn (vhdl-template-header
11647 (concat "Testbench architecture for design \""
11648 (nth 0 vhdl-port-list) "\""))
11649 (goto-char (point-max)))
11650 (vhdl-comment-display-line) (insert "\n\n")))
11651 ;; paste architecture body
11652 (vhdl-insert-keyword "ARCHITECTURE ")
11653 (insert arch-name)
11654 (vhdl-insert-keyword " OF ")
11655 (insert ent-name)
11656 (vhdl-insert-keyword " IS")
11657 (insert "\n\n") (indent-to vhdl-basic-offset)
11658 ;; paste component declaration
11659 (unless (vhdl-use-direct-instantiation)
11660 (vhdl-port-paste-component t)
11661 (insert "\n\n") (indent-to vhdl-basic-offset))
11662 ;; paste constants
11663 (when (nth 1 vhdl-port-list)
11664 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11665 (vhdl-port-paste-constants t)
11666 (insert "\n\n") (indent-to vhdl-basic-offset))
11667 ;; paste internal signals
11668 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11669 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11670 (insert "\n")
11671 ;; paste custom declarations
11672 (unless (equal "" vhdl-testbench-declarations)
11673 (insert "\n")
11674 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11675 (setq position (point))
11676 (insert "\n\n")
11677 (vhdl-comment-display-line) (insert "\n")
11678 (when vhdl-testbench-include-configuration
11679 (setq config-name (vhdl-replace-string
11680 vhdl-testbench-configuration-name
11681 (concat ent-name " " arch-name)))
11682 (insert "\n")
11683 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11684 (vhdl-insert-keyword " OF ") (insert ent-name)
11685 (vhdl-insert-keyword " IS\n")
11686 (indent-to vhdl-basic-offset)
11687 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11688 (indent-to vhdl-basic-offset)
11689 (vhdl-insert-keyword "END FOR;\n")
11690 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11691 (vhdl-comment-display-line) (insert "\n"))
11692 (goto-char position)
11693 (vhdl-template-begin-end
11694 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11695 ;; paste instantiation
11696 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11697 (vhdl-port-paste-instance
11698 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11699 (insert "\n")
11700 ;; paste custom statements
11701 (unless (equal "" vhdl-testbench-statements)
11702 (insert "\n")
11703 (vhdl-insert-string-or-file vhdl-testbench-statements))
11704 (insert "\n")
11705 (indent-to vhdl-basic-offset)
11706 (unless (eq vhdl-testbench-create-files 'none)
11707 (setq arch-buffer (current-buffer))
11708 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11709 (set-buffer arch-buffer) (save-buffer))
11710 (message "%s"
11711 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11712 ent-name arch-name)
11713 (and ent-file-name
11714 (format "\n File created: \"%s\"" ent-file-name))
11715 (and arch-file-name
11716 (format "\n File created: \"%s\"" arch-file-name)))))))
11719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11720 ;;; Subprogram interface translation
11721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11723 (defvar vhdl-subprog-list nil
11724 "Variable to hold last subprogram interface parsed.")
11725 ;; structure: (parenthesised expression means list of such entries)
11726 ;; (subprog-name kind
11727 ;; ((names) object direct type init comment group-comment)
11728 ;; return-type return-comment group-comment)
11730 (defvar vhdl-subprog-flattened nil
11731 "Indicates whether an subprogram interface has been flattened.")
11733 (defun vhdl-subprog-flatten ()
11734 "Flatten interface list so that only one parameter exists per line."
11735 (interactive)
11736 (if (not vhdl-subprog-list)
11737 (error "ERROR: No subprogram interface has been read")
11738 (message "Flattening subprogram interface...")
11739 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11740 new-subprog-list old-subprog new-subprog names)
11741 ;; traverse parameter list and flatten entries
11742 (while old-subprog-list
11743 (setq old-subprog (car old-subprog-list))
11744 (setq names (car old-subprog))
11745 (while names
11746 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11747 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11748 (setq names (cdr names)))
11749 (setq old-subprog-list (cdr old-subprog-list)))
11750 (setq vhdl-subprog-list
11751 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11752 new-subprog-list (nth 3 vhdl-subprog-list)
11753 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11754 vhdl-subprog-flattened t)
11755 (message "Flattening subprogram interface...done"))))
11757 (defun vhdl-subprog-copy ()
11758 "Get interface information from a subprogram specification."
11759 (interactive)
11760 (save-excursion
11761 (let (parse-error pos end-of-list
11762 name kind param-list object names direct type init
11763 comment group-comment
11764 return-type return-comment return-group-comment)
11765 (vhdl-prepare-search-2
11766 (setq
11767 parse-error
11768 (catch 'parse
11769 ;; check if within function declaration
11770 (setq pos (point))
11771 (end-of-line)
11772 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11773 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11774 (goto-char (match-end 0))
11775 (save-excursion (backward-char)
11776 (forward-sexp)
11777 (<= pos (point))))
11778 (throw 'parse "ERROR: Not within a subprogram specification"))
11779 (setq name (match-string-no-properties 5))
11780 (setq kind (if (match-string 2) 'procedure 'function))
11781 (setq end-of-list (not (match-string 7)))
11782 (message "Reading interface of subprogram \"%s\"..." name)
11783 ;; parse parameter list
11784 (setq group-comment (vhdl-parse-group-comment))
11785 (setq end-of-list (or end-of-list
11786 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11787 (while (not end-of-list)
11788 ;; parse object
11789 (setq object
11790 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11791 (match-string-no-properties 1)))
11792 ;; parse names (accept extended identifiers)
11793 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11794 (setq names (list (match-string-no-properties 1)))
11795 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11796 (setq names (append names (list (match-string-no-properties 1)))))
11797 ;; parse direction
11798 (vhdl-parse-string ":[ \t\n]*")
11799 (setq direct
11800 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11801 (match-string-no-properties 1)))
11802 ;; parse type
11803 (vhdl-parse-string "\\([^():;\n]+\\)")
11804 (setq type (match-string-no-properties 1))
11805 (setq comment nil)
11806 (while (looking-at "(")
11807 (setq type
11808 (concat type
11809 (buffer-substring-no-properties
11810 (point) (progn (forward-sexp) (point)))
11811 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11812 (match-string-no-properties 1)))))
11813 ;; special case: closing parenthesis is on separate line
11814 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11815 (setq comment (substring type (match-beginning 2)))
11816 (setq type (substring type 0 (match-beginning 1))))
11817 ;; strip off trailing group-comment
11818 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11819 (setq type (substring type 0 (match-end 1)))
11820 ;; parse initialization expression
11821 (setq init nil)
11822 (when (vhdl-parse-string ":=[ \t\n]*" t)
11823 (vhdl-parse-string "\\([^();\n]*\\)")
11824 (setq init (match-string-no-properties 1))
11825 (while (looking-at "(")
11826 (setq init
11827 (concat init
11828 (buffer-substring-no-properties
11829 (point) (progn (forward-sexp) (point)))
11830 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11831 (match-string-no-properties 1))))))
11832 ;; special case: closing parenthesis is on separate line
11833 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11834 (setq comment (substring init (match-beginning 2)))
11835 (setq init (substring init 0 (match-beginning 1)))
11836 (vhdl-forward-syntactic-ws))
11837 (skip-chars-forward " \t")
11838 ;; parse inline comment, special case: as above, no initial.
11839 (unless comment
11840 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11841 (match-string-no-properties 1))))
11842 (vhdl-forward-syntactic-ws)
11843 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11844 ;; parse inline comment
11845 (unless comment
11846 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11847 (match-string-no-properties 1))))
11848 (setq return-group-comment (vhdl-parse-group-comment))
11849 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11850 ;; parse return type
11851 (when (match-string 3)
11852 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11853 (setq return-type (match-string-no-properties 1))
11854 (when (and return-type
11855 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11856 (setq return-comment (substring return-type (match-beginning 2)))
11857 (setq return-type (substring return-type 0 (match-beginning 1))))
11858 ;; strip of trailing group-comment
11859 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11860 (setq return-type (substring return-type 0 (match-end 1)))
11861 ;; parse return comment
11862 (unless return-comment
11863 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11864 (match-string-no-properties 1)))))
11865 ;; parse inline comment
11866 (unless comment
11867 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11868 (match-string-no-properties 1))))
11869 ;; save everything in list
11870 (setq param-list (append param-list
11871 (list (list names object direct type init
11872 comment group-comment))))
11873 ;; parse group comment and spacing
11874 (setq group-comment (vhdl-parse-group-comment)))
11875 (message "Reading interface of subprogram \"%s\"...done" name)
11876 nil)))
11877 ;; finish parsing
11878 (if parse-error
11879 (error parse-error)
11880 (setq vhdl-subprog-list
11881 (list name kind param-list return-type return-comment
11882 return-group-comment)
11883 vhdl-subprog-flattened nil)))))
11885 (defun vhdl-subprog-paste-specification (kind)
11886 "Paste as a subprogram specification."
11887 (indent-according-to-mode)
11888 (let ((margin (current-column))
11889 (param-list (nth 2 vhdl-subprog-list))
11890 list-margin start names param)
11891 ;; paste keyword and name
11892 (vhdl-insert-keyword
11893 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11894 (insert (nth 0 vhdl-subprog-list))
11895 (if (not param-list)
11896 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11897 (setq start (point))
11898 ;; paste parameter list
11899 (insert " (")
11900 (unless vhdl-argument-list-indent
11901 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11902 (setq list-margin (current-column))
11903 (while param-list
11904 (setq param (car param-list))
11905 ;; paste group comment and spacing
11906 (when (memq vhdl-include-group-comments (list kind 'always))
11907 (vhdl-paste-group-comment (nth 6 param) list-margin))
11908 ;; paste object
11909 (when (nth 1 param) (insert (nth 1 param) " "))
11910 ;; paste names
11911 (setq names (nth 0 param))
11912 (while names
11913 (insert (car names))
11914 (setq names (cdr names))
11915 (when names (insert ", ")))
11916 ;; paste direction
11917 (insert " : ")
11918 (when (nth 2 param) (insert (nth 2 param) " "))
11919 ;; paste type
11920 (insert (nth 3 param))
11921 ;; paste initialization
11922 (when (nth 4 param) (insert " := " (nth 4 param)))
11923 ;; terminate line
11924 (if (cdr param-list)
11925 (insert ";")
11926 (insert ")")
11927 (when (null (nth 3 vhdl-subprog-list))
11928 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11929 ;; paste comment
11930 (when (and vhdl-include-port-comments (nth 5 param))
11931 (vhdl-comment-insert-inline (nth 5 param) t))
11932 (setq param-list (cdr param-list))
11933 (when param-list (insert "\n") (indent-to list-margin)))
11934 (when (nth 3 vhdl-subprog-list)
11935 (insert "\n") (indent-to list-margin)
11936 ;; paste group comment and spacing
11937 (when (memq vhdl-include-group-comments (list kind 'always))
11938 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11939 ;; paste return type
11940 (insert "return " (nth 3 vhdl-subprog-list))
11941 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11942 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11943 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11944 ;; align parameter list
11945 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11946 ;; paste body
11947 (when (eq kind 'body)
11948 (insert "\n")
11949 (vhdl-template-begin-end
11950 (unless (vhdl-standard-p '87)
11951 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11952 (nth 0 vhdl-subprog-list) margin))))
11954 (defun vhdl-subprog-paste-declaration ()
11955 "Paste as a subprogram declaration."
11956 (interactive)
11957 (if (not vhdl-subprog-list)
11958 (error "ERROR: No subprogram interface read")
11959 (message "Pasting interface as subprogram declaration \"%s\"..."
11960 (car vhdl-subprog-list))
11961 ;; paste specification
11962 (vhdl-subprog-paste-specification 'decl)
11963 (message "Pasting interface as subprogram declaration \"%s\"...done"
11964 (car vhdl-subprog-list))))
11966 (defun vhdl-subprog-paste-body ()
11967 "Paste as a subprogram body."
11968 (interactive)
11969 (if (not vhdl-subprog-list)
11970 (error "ERROR: No subprogram interface read")
11971 (message "Pasting interface as subprogram body \"%s\"..."
11972 (car vhdl-subprog-list))
11973 ;; paste specification and body
11974 (vhdl-subprog-paste-specification 'body)
11975 (message "Pasting interface as subprogram body \"%s\"...done"
11976 (car vhdl-subprog-list))))
11978 (defun vhdl-subprog-paste-call ()
11979 "Paste as a subprogram call."
11980 (interactive)
11981 (if (not vhdl-subprog-list)
11982 (error "ERROR: No subprogram interface read")
11983 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11984 param-list margin list-margin param start)
11985 ;; flatten local copy of interface list (must be flat for parameter mapping)
11986 (vhdl-subprog-flatten)
11987 (setq param-list (nth 2 vhdl-subprog-list))
11988 (indent-according-to-mode)
11989 (setq margin (current-indentation))
11990 (message "Pasting interface as subprogram call \"%s\"..."
11991 (car vhdl-subprog-list))
11992 ;; paste name
11993 (insert (nth 0 vhdl-subprog-list))
11994 (if (not param-list)
11995 (insert ";")
11996 (setq start (point))
11997 ;; paste parameter list
11998 (insert " (")
11999 (unless vhdl-argument-list-indent
12000 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12001 (setq list-margin (current-column))
12002 (while param-list
12003 (setq param (car param-list))
12004 ;; paste group comment and spacing
12005 (when (eq vhdl-include-group-comments 'always)
12006 (vhdl-paste-group-comment (nth 6 param) list-margin))
12007 ;; paste formal port
12008 (insert (car (nth 0 param)) " => ")
12009 (setq param-list (cdr param-list))
12010 (insert (if param-list "," ");"))
12011 ;; paste comment
12012 (when (and vhdl-include-port-comments (nth 5 param))
12013 (vhdl-comment-insert-inline (nth 5 param)))
12014 (when param-list (insert "\n") (indent-to list-margin)))
12015 ;; align parameter list
12016 (when vhdl-auto-align
12017 (vhdl-align-region-groups start (point) 1)))
12018 (message "Pasting interface as subprogram call \"%s\"...done"
12019 (car vhdl-subprog-list))
12020 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12024 ;;; Miscellaneous
12025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12028 ;; Hippie expand customization
12030 (defvar vhdl-expand-upper-case nil)
12032 (defun vhdl-try-expand-abbrev (old)
12033 "Try expanding abbreviations from `vhdl-abbrev-list'."
12034 (unless old
12035 (he-init-string (he-dabbrev-beg) (point))
12036 (setq he-expand-list
12037 (let ((abbrev-list vhdl-abbrev-list)
12038 (sel-abbrev-list '()))
12039 (while abbrev-list
12040 (when (or (not (stringp (car abbrev-list)))
12041 (string-match
12042 (concat "^" he-search-string) (car abbrev-list)))
12043 (setq sel-abbrev-list
12044 (cons (car abbrev-list) sel-abbrev-list)))
12045 (setq abbrev-list (cdr abbrev-list)))
12046 (nreverse sel-abbrev-list))))
12047 (while (and he-expand-list
12048 (or (not (stringp (car he-expand-list)))
12049 (he-string-member (car he-expand-list) he-tried-table t)))
12050 ; (equal (car he-expand-list) he-search-string)))
12051 (unless (stringp (car he-expand-list))
12052 (setq vhdl-expand-upper-case (car he-expand-list)))
12053 (setq he-expand-list (cdr he-expand-list)))
12054 (if (null he-expand-list)
12055 (progn (when old (he-reset-string))
12056 nil)
12057 (he-substitute-string
12058 (if vhdl-expand-upper-case
12059 (upcase (car he-expand-list))
12060 (car he-expand-list))
12062 (setq he-expand-list (cdr he-expand-list))
12065 (defun vhdl-he-list-beg ()
12066 "Also looks at the word before `(' in order to better match parenthesized
12067 expressions (e.g. for index ranges of types and signals)."
12068 (save-excursion
12069 (condition-case ()
12070 (progn (backward-up-list 1)
12071 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12072 (error ()))
12073 (point)))
12075 ;; override `he-list-beg' from `hippie-exp'
12076 (unless (and (boundp 'viper-mode) viper-mode)
12077 (defalias 'he-list-beg 'vhdl-he-list-beg))
12079 ;; function for expanding abbrevs and dabbrevs
12080 (defun vhdl-expand-abbrev (arg))
12081 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12082 '(try-expand-dabbrev
12083 try-expand-dabbrev-all-buffers
12084 vhdl-try-expand-abbrev)))
12086 ;; function for expanding parenthesis
12087 (defun vhdl-expand-paren (arg))
12088 (fset 'vhdl-expand-paren (make-hippie-expand-function
12089 '(try-expand-list
12090 try-expand-list-all-buffers)))
12092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12093 ;; Case fixing
12095 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12096 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12097 depending on parameter UPPER-CASE."
12098 (let ((case-replace nil)
12099 (last-update 0))
12100 (vhdl-prepare-search-2
12101 (save-excursion
12102 (goto-char end)
12103 (setq end (point-marker))
12104 (goto-char beg)
12105 (while (re-search-forward word-regexp end t)
12106 (or (vhdl-in-literal)
12107 (if upper-case
12108 (upcase-word -1)
12109 (downcase-word -1)))
12110 (when (and count vhdl-progress-interval (not noninteractive)
12111 (< vhdl-progress-interval
12112 (- (nth 1 (current-time)) last-update)))
12113 (message "Fixing case... (%2d%s)"
12114 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12115 "%")
12116 (setq last-update (nth 1 (current-time)))))
12117 (goto-char end)))))
12119 (defun vhdl-fix-case-region (beg end &optional arg)
12120 "Convert all VHDL words in region to lower or upper case, depending on
12121 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12122 (interactive "r\nP")
12123 (vhdl-fix-case-region-1
12124 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12125 (vhdl-fix-case-region-1
12126 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12127 (vhdl-fix-case-region-1
12128 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12129 (vhdl-fix-case-region-1
12130 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12131 (when vhdl-progress-interval (message "Fixing case...done")))
12133 (defun vhdl-fix-case-buffer ()
12134 "Convert all VHDL words in buffer to lower or upper case, depending on
12135 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12136 (interactive)
12137 (vhdl-fix-case-region (point-min) (point-max)))
12139 (defun vhdl-fix-case-word (&optional arg)
12140 "Convert word after cursor to upper case if necessary."
12141 (interactive "p")
12142 (save-excursion
12143 (when arg (backward-word 1))
12144 (vhdl-prepare-search-1
12145 (when (and vhdl-upper-case-keywords
12146 (looking-at vhdl-keywords-regexp))
12147 (upcase-word 1))
12148 (when (and vhdl-upper-case-types
12149 (looking-at vhdl-types-regexp))
12150 (upcase-word 1))
12151 (when (and vhdl-upper-case-attributes
12152 (looking-at vhdl-attributes-regexp))
12153 (upcase-word 1))
12154 (when (and vhdl-upper-case-enum-values
12155 (looking-at vhdl-enum-values-regexp))
12156 (upcase-word 1)))))
12158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12159 ;; Line handling functions
12161 (defun vhdl-current-line ()
12162 "Return the line number of the line containing point."
12163 (save-restriction
12164 (widen)
12165 (save-excursion
12166 (beginning-of-line)
12167 (1+ (count-lines 1 (point))))))
12169 (defun vhdl-line-kill-entire (&optional arg)
12170 "Delete entire line."
12171 (interactive "p")
12172 (beginning-of-line)
12173 (kill-line (or arg 1)))
12175 (defun vhdl-line-kill (&optional arg)
12176 "Kill current line."
12177 (interactive "p")
12178 (vhdl-line-kill-entire arg))
12180 (defun vhdl-line-copy (&optional arg)
12181 "Copy current line."
12182 (interactive "p")
12183 (save-excursion
12184 (beginning-of-line)
12185 (let ((position (point)))
12186 (forward-line (or arg 1))
12187 (copy-region-as-kill position (point)))))
12189 (defun vhdl-line-yank ()
12190 "Yank entire line."
12191 (interactive)
12192 (beginning-of-line)
12193 (yank))
12195 (defun vhdl-line-expand (&optional prefix-arg)
12196 "Hippie-expand current line."
12197 (interactive "P")
12198 (let ((case-fold-search t) (case-replace nil)
12199 (hippie-expand-try-functions-list
12200 '(try-expand-line try-expand-line-all-buffers)))
12201 (hippie-expand prefix-arg)))
12203 (defun vhdl-line-transpose-next (&optional arg)
12204 "Interchange this line with next line."
12205 (interactive "p")
12206 (forward-line 1)
12207 (transpose-lines (or arg 1))
12208 (forward-line -1))
12210 (defun vhdl-line-transpose-previous (&optional arg)
12211 "Interchange this line with previous line."
12212 (interactive "p")
12213 (forward-line 1)
12214 (transpose-lines (- 0 (or arg 0)))
12215 (forward-line -1))
12217 (defun vhdl-line-open ()
12218 "Open a new line and indent."
12219 (interactive)
12220 (end-of-line -0)
12221 (newline-and-indent))
12223 (defun vhdl-delete-indentation ()
12224 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12225 it works within comments too."
12226 (interactive)
12227 (let ((fill-prefix "-- "))
12228 (delete-indentation)))
12230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12231 ;; Move functions
12233 (defun vhdl-forward-same-indent ()
12234 "Move forward to next line with same indent."
12235 (interactive)
12236 (let ((pos (point))
12237 (indent (current-indentation)))
12238 (beginning-of-line 2)
12239 (while (and (not (eobp))
12240 (or (looking-at "^\\s-*\\(--.*\\)?$")
12241 (> (current-indentation) indent)))
12242 (beginning-of-line 2))
12243 (if (= (current-indentation) indent)
12244 (back-to-indentation)
12245 (message "No following line with same indent found in this block")
12246 (goto-char pos)
12247 nil)))
12249 (defun vhdl-backward-same-indent ()
12250 "Move backward to previous line with same indent."
12251 (interactive)
12252 (let ((pos (point))
12253 (indent (current-indentation)))
12254 (beginning-of-line -0)
12255 (while (and (not (bobp))
12256 (or (looking-at "^\\s-*\\(--.*\\)?$")
12257 (> (current-indentation) indent)))
12258 (beginning-of-line -0))
12259 (if (= (current-indentation) indent)
12260 (back-to-indentation)
12261 (message "No preceding line with same indent found in this block")
12262 (goto-char pos)
12263 nil)))
12265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12266 ;; Statistics
12268 (defun vhdl-statistics-buffer ()
12269 "Get some file statistics."
12270 (interactive)
12271 (let ((no-stats 0)
12272 (no-code-lines 0)
12273 (no-lines (count-lines (point-min) (point-max))))
12274 (save-excursion
12275 ;; count statements
12276 (goto-char (point-min))
12277 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12278 (if (match-string 1)
12279 (goto-char (match-end 1))
12280 (setq no-stats (1+ no-stats))))
12281 ;; count code lines
12282 (goto-char (point-min))
12283 (while (not (eobp))
12284 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12285 (setq no-code-lines (1+ no-code-lines)))
12286 (beginning-of-line 2)))
12287 ;; print results
12288 (message "\n\
12289 File statistics: \"%s\"\n\
12290 ---------------------\n\
12291 # statements : %5d\n\
12292 # code lines : %5d\n\
12293 # total lines : %5d\n\ "
12294 (buffer-file-name) no-stats no-code-lines no-lines)
12295 (unless vhdl-emacs-21 (vhdl-show-messages))))
12297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12298 ;; Help functions
12300 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12301 "Like `re-search-forward', but does not match within literals."
12302 (let (pos)
12303 (save-excursion
12304 (while (and (setq pos (re-search-forward regexp bound noerror count))
12305 (vhdl-in-literal))))
12306 (when pos (goto-char pos))
12307 pos))
12309 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12310 "Like `re-search-backward', but does not match within literals."
12311 (let (pos)
12312 (save-excursion
12313 (while (and (setq pos (re-search-backward regexp bound noerror count))
12314 (vhdl-in-literal))))
12315 (when pos (goto-char pos))
12316 pos))
12319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12320 ;;; Project
12321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12323 (defun vhdl-set-project (name)
12324 "Set current project to NAME."
12325 (interactive
12326 (list (let ((completion-ignore-case t))
12327 (completing-read "Project name: " vhdl-project-alist nil t))))
12328 (cond ((equal name "")
12329 (setq vhdl-project nil)
12330 (message "Current VHDL project: None"))
12331 ((assoc name vhdl-project-alist)
12332 (setq vhdl-project name)
12333 (message "Current VHDL project: \"%s\"" name))
12335 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12336 (vhdl-speedbar-update-current-project))
12338 (defun vhdl-set-default-project ()
12339 "Set current project as default on startup."
12340 (interactive)
12341 (customize-set-variable 'vhdl-project vhdl-project)
12342 (customize-save-customized))
12344 (defun vhdl-toggle-project (name token indent)
12345 "Set current project to NAME or unset if NAME is current project."
12346 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12348 (defun vhdl-export-project (file-name)
12349 "Write project setup for current project."
12350 (interactive
12351 (let ((name (vhdl-resolve-env-variable
12352 (vhdl-replace-string
12353 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12354 (concat (subst-char-in-string
12355 ? ?_ (or (vhdl-project-p)
12356 (error "ERROR: No current project")))
12357 " " (user-login-name))))))
12358 (list (read-file-name
12359 "Write project file: "
12360 (when (file-name-absolute-p name) "") nil nil name))))
12361 (setq file-name (abbreviate-file-name file-name))
12362 (let ((orig-buffer (current-buffer)))
12363 (unless (file-exists-p (file-name-directory file-name))
12364 (make-directory (file-name-directory file-name) t))
12365 (if (not (file-writable-p file-name))
12366 (error "ERROR: File not writable: \"%s\"" file-name)
12367 (set-buffer (find-file-noselect file-name t t))
12368 (erase-buffer)
12369 (insert ";; -*- Emacs-Lisp -*-\n\n"
12370 ";;; " (file-name-nondirectory file-name)
12371 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12372 ";; Project : " vhdl-project "\n"
12373 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12374 (user-login-name) "\n\n\n"
12375 ";; project name\n"
12376 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12377 ";; project setup\n"
12378 "(aput 'vhdl-project-alist vhdl-project\n'")
12379 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12380 (insert ")\n")
12381 (save-buffer)
12382 (kill-buffer (current-buffer))
12383 (set-buffer orig-buffer))))
12385 (defun vhdl-import-project (file-name &optional auto not-make-current)
12386 "Read project setup and set current project."
12387 (interactive
12388 (let ((name (vhdl-resolve-env-variable
12389 (vhdl-replace-string
12390 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12391 (concat "" " " (user-login-name))))))
12392 (list (read-file-name
12393 "Read project file: " (when (file-name-absolute-p name) "") nil t
12394 (file-name-directory name)))))
12395 (when (file-exists-p file-name)
12396 (condition-case ()
12397 (let ((current-project vhdl-project))
12398 (load-file file-name)
12399 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12400 (adelete 'vhdl-project-alist vhdl-project)
12401 (error ""))
12402 (when not-make-current
12403 (setq vhdl-project current-project))
12404 (vhdl-update-mode-menu)
12405 (vhdl-speedbar-refresh)
12406 (unless not-make-current
12407 (message "Current VHDL project: \"%s\"%s"
12408 vhdl-project (if auto " (auto-loaded)" ""))))
12409 (error (vhdl-warning
12410 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12412 (defun vhdl-duplicate-project ()
12413 "Duplicate setup of current project."
12414 (interactive)
12415 (let ((new-name (read-from-minibuffer "New project name: "))
12416 (project-entry (aget vhdl-project-alist vhdl-project t)))
12417 (setq vhdl-project-alist
12418 (append vhdl-project-alist
12419 (list (cons new-name project-entry))))
12420 (vhdl-update-mode-menu)))
12422 (defun vhdl-auto-load-project ()
12423 "Automatically load project setup at startup."
12424 (let ((file-name-list vhdl-project-file-name)
12425 file-list list-length)
12426 (while file-name-list
12427 (setq file-list
12428 (append file-list
12429 (file-expand-wildcards
12430 (vhdl-resolve-env-variable
12431 (vhdl-replace-string
12432 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12433 (concat "\*" " " (user-login-name)))))))
12434 (setq list-length (or list-length (length file-list)))
12435 (setq file-name-list (cdr file-name-list)))
12436 (while file-list
12437 (vhdl-import-project (expand-file-name (car file-list)) t
12438 (not (> list-length 0)))
12439 (setq list-length (1- list-length))
12440 (setq file-list (cdr file-list)))))
12442 ;; automatically load project setup when idle after startup
12443 (when (memq 'startup vhdl-project-auto-load)
12444 (if noninteractive
12445 (vhdl-auto-load-project)
12446 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12450 ;;; Hideshow
12451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12452 ;; (using `hideshow.el')
12454 (defconst vhdl-hs-start-regexp
12455 (concat
12456 "\\(^\\)\\s-*\\("
12457 ;; generic/port clause
12458 "\\(generic\\|port\\)[ \t\n]*(\\|"
12459 ;; component
12460 "component\\>\\|"
12461 ;; component instantiation
12462 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12463 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12464 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12465 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12466 ;; subprogram
12467 "\\(function\\|procedure\\)\\>\\|"
12468 ;; process, block
12469 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12470 ;; configuration declaration
12471 "configuration\\>"
12472 "\\)")
12473 "Regexp to match start of construct to hide.")
12475 (defun vhdl-hs-forward-sexp-func (count)
12476 "Find end of construct to hide (for hideshow). Only searches forward."
12477 (let ((pos (point)))
12478 (vhdl-prepare-search-2
12479 (beginning-of-line)
12480 (cond
12481 ;; generic/port clause
12482 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12483 (goto-char (match-end 0))
12484 (backward-char)
12485 (forward-sexp))
12486 ;; component declaration
12487 ((looking-at "^\\s-*component\\>")
12488 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12489 ;; component instantiation
12490 ((looking-at
12491 (concat
12492 "^\\s-*\\w+\\s-*:[ \t\n]*"
12493 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12494 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12495 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12496 (goto-char (match-end 0))
12497 (backward-char)
12498 (forward-sexp)
12499 (setq pos (point))
12500 (vhdl-forward-syntactic-ws)
12501 (when (looking-at "port\\s-+map[ \t\n]*(")
12502 (goto-char (match-end 0))
12503 (backward-char)
12504 (forward-sexp)
12505 (setq pos (point)))
12506 (goto-char pos))
12507 ;; subprogram declaration/body
12508 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12509 (goto-char (match-end 0))
12510 (vhdl-forward-syntactic-ws)
12511 (when (looking-at "(")
12512 (forward-sexp))
12513 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12514 (vhdl-in-literal)))
12515 ;; subprogram body
12516 (when (match-string 2)
12517 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12518 (backward-word 1)
12519 (vhdl-forward-sexp)))
12520 ;; block (recursive)
12521 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12522 (goto-char (match-end 0))
12523 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12524 (match-beginning 2))
12525 (vhdl-hs-forward-sexp-func count)))
12526 ;; process
12527 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12528 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12529 ;; configuration declaration
12530 ((looking-at "^\\s-*configuration\\>")
12531 (forward-word 4)
12532 (vhdl-forward-sexp))
12533 (t (goto-char pos))))))
12535 (defun vhdl-hideshow-init ()
12536 "Initialize `hideshow'."
12537 (when vhdl-hideshow-menu
12538 (vhdl-hs-minor-mode 1)))
12540 (defun vhdl-hs-minor-mode (&optional arg)
12541 "Toggle hideshow minor mode and update menu bar."
12542 (interactive "P")
12543 (require 'hideshow)
12544 ;; check for hideshow version 5.x
12545 (if (not (boundp 'hs-block-start-mdata-select))
12546 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12547 ;; initialize hideshow
12548 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12549 (setq hs-special-modes-alist
12550 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12551 'vhdl-hs-forward-sexp-func nil)
12552 hs-special-modes-alist)))
12553 (make-local-variable 'hs-minor-mode-hook)
12554 (if vhdl-hide-all-init
12555 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12556 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12557 (hs-minor-mode arg)
12558 (vhdl-mode-line-update))) ; hack to update menu bar
12561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12562 ;;; Font locking
12563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12564 ;; (using `font-lock.el')
12566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12567 ;; Help functions
12569 (defun vhdl-within-translate-off ()
12570 "Return point if within translate-off region, else nil."
12571 (and (save-excursion
12572 (re-search-backward
12573 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12574 (equal "off" (match-string 1))
12575 (point)))
12577 (defun vhdl-start-translate-off (limit)
12578 "Return point before translate-off pragma if before LIMIT, else nil."
12579 (when (re-search-forward
12580 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12581 (match-beginning 0)))
12583 (defun vhdl-end-translate-off (limit)
12584 "Return point after translate-on pragma if before LIMIT, else nil."
12585 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12587 (defun vhdl-match-translate-off (limit)
12588 "Match a translate-off block, setting match-data and returning t, else nil."
12589 (when (< (point) limit)
12590 (let ((start (or (vhdl-within-translate-off)
12591 (vhdl-start-translate-off limit)))
12592 (case-fold-search t))
12593 (when start
12594 (let ((end (or (vhdl-end-translate-off limit) limit)))
12595 (set-match-data (list start end))
12596 (goto-char end))))))
12598 (defun vhdl-font-lock-match-item (limit)
12599 "Match, and move over, any declaration item after point. Adapted from
12600 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12601 (condition-case nil
12602 (save-restriction
12603 (narrow-to-region (point-min) limit)
12604 ;; match item
12605 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12606 (save-match-data
12607 (goto-char (match-end 1))
12608 ;; move to next item
12609 (if (looking-at "\\(\\s-*,\\)")
12610 (goto-char (match-end 1))
12611 (end-of-line) t))))
12612 (error t)))
12614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12615 ;; Syntax definitions
12617 (defconst vhdl-font-lock-syntactic-keywords
12618 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12619 "Mark single quotes as having string quote syntax in 'c' instances.")
12621 (defvar vhdl-font-lock-keywords nil
12622 "Regular expressions to highlight in VHDL Mode.")
12624 (defvar vhdl-font-lock-keywords-0
12625 ;; set in `vhdl-font-lock-init' because dependent on user options
12626 "For consideration as a value of `vhdl-font-lock-keywords'.
12627 This does highlighting of template prompts and directives (pragmas).")
12629 (defvar vhdl-font-lock-keywords-1 nil
12630 ;; set in `vhdl-font-lock-init' because dependent on user options
12631 "For consideration as a value of `vhdl-font-lock-keywords'.
12632 This does highlighting of keywords and standard identifiers.")
12634 (defconst vhdl-font-lock-keywords-2
12635 (list
12636 ;; highlight names of units, subprograms, and components when declared
12637 (list
12638 (concat
12639 "^\\s-*\\("
12640 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12641 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12642 "\\)\\s-+\\(\\w+\\)")
12643 5 'font-lock-function-name-face)
12645 ;; highlight entity names of architectures and configurations
12646 (list
12647 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12648 2 'font-lock-function-name-face)
12650 ;; highlight labels of common constructs
12651 (list
12652 (concat
12653 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12654 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12655 "postponed\\|process\\|"
12656 (when (vhdl-standard-p 'ams) "procedural\\|")
12657 "with\\|while"
12658 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12659 1 'font-lock-function-name-face)
12661 ;; highlight label and component name of component instantiations
12662 (list
12663 (concat
12664 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12665 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12666 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12668 ;; highlight label and instantiated unit of component instantiations
12669 (list
12670 (concat
12671 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12672 "\\(component\\|configuration\\|entity\\)\\s-+"
12673 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12674 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12675 '(5 font-lock-function-name-face nil t)
12676 '(7 font-lock-function-name-face nil t))
12678 ;; highlight names and labels at end of constructs
12679 (list
12680 (concat
12681 "^\\s-*end\\s-+\\(\\("
12682 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12683 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12684 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12685 (when (vhdl-standard-p 'ams) "procedural\\|")
12686 "units"
12687 "\\)\\s-+\\)?\\(\\w*\\)")
12688 5 'font-lock-function-name-face)
12690 ;; highlight labels in exit and next statements
12691 (list
12692 (concat
12693 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12694 3 'font-lock-function-name-face)
12696 ;; highlight entity name in attribute specifications
12697 (list
12698 (concat
12699 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12700 1 'font-lock-function-name-face)
12702 ;; highlight labels in block and component specifications
12703 (list
12704 (concat
12705 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12706 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12707 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12709 ;; highlight names in library clauses
12710 (list "^\\s-*library\\>"
12711 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12713 ;; highlight names in use clauses
12714 (list
12715 (concat
12716 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12717 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12718 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12719 '(7 font-lock-function-name-face nil t))
12721 ;; highlight attribute name in attribute declarations/specifications
12722 (list
12723 (concat
12724 "^\\s-*attribute\\s-+\\(\\w+\\)")
12725 1 'vhdl-font-lock-attribute-face)
12727 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12728 (list
12729 (concat
12730 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12731 3 'font-lock-type-face)
12733 ;; highlight signal/variable/constant declaration names
12734 (list "\\(:[^=]\\)"
12735 '(vhdl-font-lock-match-item
12736 (progn (goto-char (match-beginning 1))
12737 (skip-syntax-backward " ")
12738 (skip-syntax-backward "w_")
12739 (skip-syntax-backward " ")
12740 (while (= (preceding-char) ?,)
12741 (backward-char 1)
12742 (skip-syntax-backward " ")
12743 (skip-syntax-backward "w_")
12744 (skip-syntax-backward " ")))
12745 ; (skip-chars-backward "^-(\n\";")
12746 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12748 ;; highlight formal parameters in component instantiations and subprogram
12749 ;; calls
12750 (list "\\(=>\\)"
12751 '(vhdl-font-lock-match-item
12752 (progn (goto-char (match-beginning 1))
12753 (skip-syntax-backward " ")
12754 (while (= (preceding-char) ?\)) (backward-sexp))
12755 (skip-syntax-backward "w_")
12756 (skip-syntax-backward " ")
12757 (when (memq (preceding-char) '(?n ?N ?|))
12758 (goto-char (point-max))))
12759 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12761 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12762 ;; variables
12763 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12764 '(vhdl-font-lock-match-item
12765 (progn (goto-char (match-end 1)) (match-beginning 2))
12766 nil (1 font-lock-variable-name-face)))
12768 "For consideration as a value of `vhdl-font-lock-keywords'.
12769 This does context sensitive highlighting of names and labels.")
12771 (defvar vhdl-font-lock-keywords-3 nil
12772 ;; set in `vhdl-font-lock-init' because dependent on user options
12773 "For consideration as a value of `vhdl-font-lock-keywords'.
12774 This does highlighting of words with special syntax.")
12776 (defvar vhdl-font-lock-keywords-4 nil
12777 ;; set in `vhdl-font-lock-init' because dependent on user options
12778 "For consideration as a value of `vhdl-font-lock-keywords'.
12779 This does highlighting of additional reserved words.")
12781 (defconst vhdl-font-lock-keywords-5
12782 ;; background highlight translate-off regions
12783 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12784 "For consideration as a value of `vhdl-font-lock-keywords'.
12785 This does background highlighting of translate-off regions.")
12787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12788 ;; Font and color definitions
12790 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12791 "Face name to use for prompts.")
12793 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12794 "Face name to use for standardized attributes.")
12796 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12797 "Face name to use for standardized enumeration values.")
12799 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12800 "Face name to use for standardized functions and packages.")
12802 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12803 "Face name to use for directives.")
12805 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12806 "Face name to use for additional reserved words.")
12808 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12809 "Face name to use for translate-off regions.")
12811 ;; face names to use for words with special syntax.
12812 (let ((syntax-alist vhdl-special-syntax-alist)
12813 name)
12814 (while syntax-alist
12815 (setq name (vhdl-function-name
12816 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12817 (eval `(defvar ,name ',name
12818 ,(concat "Face name to use for "
12819 (nth 0 (car syntax-alist)) ".")))
12820 (setq syntax-alist (cdr syntax-alist))))
12822 (defgroup vhdl-highlight-faces nil
12823 "Faces for highlighting."
12824 :group 'vhdl-highlight)
12826 ;; add faces used from `font-lock'
12827 (custom-add-to-group
12828 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12829 (custom-add-to-group
12830 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12831 (custom-add-to-group
12832 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12833 (custom-add-to-group
12834 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12835 (custom-add-to-group
12836 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12837 (custom-add-to-group
12838 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12840 (defface vhdl-font-lock-prompt-face
12841 '((((min-colors 88) (class color) (background light))
12842 (:foreground "Red1" :bold t))
12843 (((class color) (background light)) (:foreground "Red" :bold t))
12844 (((class color) (background dark)) (:foreground "Pink" :bold t))
12845 (t (:inverse-video t)))
12846 "Font lock mode face used to highlight prompts."
12847 :group 'vhdl-highlight-faces)
12849 (defface vhdl-font-lock-attribute-face
12850 '((((class color) (background light)) (:foreground "Orchid"))
12851 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12852 (t (:italic t :bold t)))
12853 "Font lock mode face used to highlight standardized attributes."
12854 :group 'vhdl-highlight-faces)
12856 (defface vhdl-font-lock-enumvalue-face
12857 '((((class color) (background light)) (:foreground "SaddleBrown"))
12858 (((class color) (background dark)) (:foreground "BurlyWood"))
12859 (t (:italic t :bold t)))
12860 "Font lock mode face used to highlight standardized enumeration values."
12861 :group 'vhdl-highlight-faces)
12863 (defface vhdl-font-lock-function-face
12864 '((((class color) (background light)) (:foreground "Cyan4"))
12865 (((class color) (background dark)) (:foreground "Orchid1"))
12866 (t (:italic t :bold t)))
12867 "Font lock mode face used to highlight standardized functions and packages."
12868 :group 'vhdl-highlight-faces)
12870 (defface vhdl-font-lock-directive-face
12871 '((((class color) (background light)) (:foreground "CadetBlue"))
12872 (((class color) (background dark)) (:foreground "Aquamarine"))
12873 (t (:italic t :bold t)))
12874 "Font lock mode face used to highlight directives."
12875 :group 'vhdl-highlight-faces)
12877 (defface vhdl-font-lock-reserved-words-face
12878 '((((class color) (background light)) (:foreground "Orange" :bold t))
12879 (((min-colors 88) (class color) (background dark))
12880 (:foreground "Yellow1" :bold t))
12881 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12882 (t ()))
12883 "Font lock mode face used to highlight additional reserved words."
12884 :group 'vhdl-highlight-faces)
12886 (defface vhdl-font-lock-translate-off-face
12887 '((((class color) (background light)) (:background "LightGray"))
12888 (((class color) (background dark)) (:background "DimGray"))
12889 (t ()))
12890 "Font lock mode face used to background highlight translate-off regions."
12891 :group 'vhdl-highlight-faces)
12893 ;; font lock mode faces used to highlight words with special syntax.
12894 (let ((syntax-alist vhdl-special-syntax-alist))
12895 (while syntax-alist
12896 (eval `(defface ,(vhdl-function-name
12897 "vhdl-font-lock" (caar syntax-alist) "face")
12898 '((((class color) (background light))
12899 (:foreground ,(nth 2 (car syntax-alist))))
12900 (((class color) (background dark))
12901 (:foreground ,(nth 3 (car syntax-alist))))
12902 (t ()))
12903 ,(concat "Font lock mode face used to highlight "
12904 (nth 0 (car syntax-alist)) ".")
12905 :group 'vhdl-highlight-faces))
12906 (setq syntax-alist (cdr syntax-alist))))
12908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12909 ;; Font lock initialization
12911 (defun vhdl-font-lock-init ()
12912 "Initialize fontification."
12913 ;; highlight template prompts and directives
12914 (setq vhdl-font-lock-keywords-0
12915 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12916 vhdl-template-prompt-syntax ">\\)")
12917 2 'vhdl-font-lock-prompt-face t)
12918 (list (concat "--\\s-*"
12919 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12920 2 'vhdl-font-lock-directive-face t)
12921 ;; highlight c-preprocessor directives
12922 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12923 '(1 font-lock-builtin-face)
12924 '(3 font-lock-variable-name-face nil t))))
12925 ;; highlight keywords and standardized types, attributes, enumeration
12926 ;; values, and subprograms
12927 (setq vhdl-font-lock-keywords-1
12928 (list
12929 (list (concat "'" vhdl-attributes-regexp)
12930 1 'vhdl-font-lock-attribute-face)
12931 (list vhdl-types-regexp 1 'font-lock-type-face)
12932 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12933 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12934 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12935 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12936 ;; highlight words with special syntax.
12937 (setq vhdl-font-lock-keywords-3
12938 (let ((syntax-alist vhdl-special-syntax-alist)
12939 keywords)
12940 (while syntax-alist
12941 (setq keywords
12942 (cons
12943 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12944 (vhdl-function-name
12945 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12946 keywords))
12947 (setq syntax-alist (cdr syntax-alist)))
12948 keywords))
12949 ;; highlight additional reserved words
12950 (setq vhdl-font-lock-keywords-4
12951 (list (list vhdl-reserved-words-regexp 1
12952 'vhdl-font-lock-reserved-words-face)))
12953 ;; highlight everything together
12954 (setq vhdl-font-lock-keywords
12955 (append
12956 vhdl-font-lock-keywords-0
12957 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12958 (when (or vhdl-highlight-forbidden-words
12959 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12960 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12961 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12962 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12964 ;; initialize fontification for VHDL Mode
12965 (vhdl-font-lock-init)
12967 (defun vhdl-fontify-buffer ()
12968 "Re-initialize fontification and fontify buffer."
12969 (interactive)
12970 (setq font-lock-defaults
12971 (list
12972 'vhdl-font-lock-keywords nil
12973 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12974 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12975 (when (fboundp 'font-lock-unset-defaults)
12976 (font-lock-unset-defaults)) ; not implemented in XEmacs
12977 (font-lock-set-defaults)
12978 (font-lock-mode nil)
12979 (font-lock-mode t))
12981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12982 ;; Initialization for postscript printing
12984 (defun vhdl-ps-print-settings ()
12985 "Initialize custom face and page settings for postscript printing."
12986 ;; define custom face settings
12987 (unless (or (not vhdl-print-customize-faces)
12988 ps-print-color-p)
12989 (set (make-local-variable 'ps-bold-faces)
12990 '(font-lock-keyword-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-italic-faces)
12996 '(font-lock-comment-face
12997 font-lock-function-name-face
12998 font-lock-type-face
12999 vhdl-font-lock-attribute-face
13000 vhdl-font-lock-enumvalue-face
13001 vhdl-font-lock-directive-face))
13002 (set (make-local-variable 'ps-underlined-faces)
13003 '(font-lock-string-face))
13004 (setq ps-always-build-face-reference t))
13005 ;; define page settings, so that a line containing 79 characters (default)
13006 ;; fits into one column
13007 (when vhdl-print-two-column
13008 (set (make-local-variable 'ps-landscape-mode) t)
13009 (set (make-local-variable 'ps-number-of-columns) 2)
13010 (set (make-local-variable 'ps-font-size) 7.0)
13011 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13012 (set (make-local-variable 'ps-header-font-size) 9.0)
13013 (set (make-local-variable 'ps-header-offset) 12.0)
13014 (when (eq ps-paper-type 'letter)
13015 (set (make-local-variable 'ps-inter-column) 40.0)
13016 (set (make-local-variable 'ps-left-margin) 40.0)
13017 (set (make-local-variable 'ps-right-margin) 40.0))))
13019 (defun vhdl-ps-print-init ()
13020 "Initialize postscript printing."
13021 (if (featurep 'xemacs)
13022 (when (boundp 'ps-print-color-p)
13023 (vhdl-ps-print-settings))
13024 (make-local-variable 'ps-print-hook)
13025 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13029 ;;; Hierarchy browser (using `speedbar.el')
13030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13031 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13032 ;; directory by using the speedbar.
13034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13035 ;; Variables
13037 (defvar vhdl-entity-alist nil
13038 "Cache with entities and corresponding architectures for each
13039 project/directory.")
13040 ;; structure: (parenthesised expression means list of such entries)
13041 ;; (cache-key
13042 ;; (ent-key ent-name ent-file ent-line
13043 ;; (arch-key arch-name arch-file arch-line
13044 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13045 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13046 ;; (lib-name pack-key))
13047 ;; mra-key (lib-name pack-key))
13049 (defvar vhdl-config-alist nil
13050 "Cache with configurations for each project/directory.")
13051 ;; structure: (parenthesised expression means list of such entries)
13052 ;; (cache-key
13053 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13054 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13055 ;; inst-conf-key inst-lib-key)
13056 ;; (lib-name pack-key)))
13058 (defvar vhdl-package-alist nil
13059 "Cache with packages for each project/directory.")
13060 ;; structure: (parenthesised expression means list of such entries)
13061 ;; (cache-key
13062 ;; (pack-key pack-name pack-file pack-line
13063 ;; (comp-key comp-name comp-file comp-line)
13064 ;; (func-key func-name func-file func-line)
13065 ;; (lib-name pack-key)
13066 ;; pack-body-file pack-body-line
13067 ;; (func-key func-name func-body-file func-body-line)
13068 ;; (lib-name pack-key)))
13070 (defvar vhdl-ent-inst-alist nil
13071 "Cache with instantiated entities for each project/directory.")
13072 ;; structure: (parenthesised expression means list of such entries)
13073 ;; (cache-key (inst-ent-key))
13075 (defvar vhdl-file-alist nil
13076 "Cache with design units in each file for each project/directory.")
13077 ;; structure: (parenthesised expression means list of such entries)
13078 ;; (cache-key
13079 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13080 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13082 (defvar vhdl-directory-alist nil
13083 "Cache with source directories for each project.")
13084 ;; structure: (parenthesised expression means list of such entries)
13085 ;; (cache-key (directory))
13087 (defvar vhdl-speedbar-shown-unit-alist nil
13088 "Alist of design units simultaneously open in the current speedbar for each
13089 directory and project.")
13091 (defvar vhdl-speedbar-shown-project-list nil
13092 "List of projects simultaneously open in the current speedbar.")
13094 (defvar vhdl-updated-project-list nil
13095 "List of projects and directories with updated files.")
13097 (defvar vhdl-modified-file-list nil
13098 "List of modified files to be rescanned for hierarchy updating.")
13100 (defvar vhdl-speedbar-hierarchy-depth 0
13101 "Depth of instantiation hierarchy to display.")
13103 (defvar vhdl-speedbar-show-projects nil
13104 "Non-nil means project hierarchy is displayed in speedbar, directory
13105 hierarchy otherwise.")
13107 (defun vhdl-get-end-of-unit ()
13108 "Return position of end of current unit."
13109 (let ((pos (point)))
13110 (save-excursion
13111 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13112 (save-excursion
13113 (goto-char (match-beginning 0))
13114 (vhdl-backward-syntactic-ws)
13115 (and (/= (preceding-char) ?\;) (not (bobp))))))
13116 (re-search-backward "^[ \t]*end\\>" pos 1)
13117 (point))))
13119 (defun vhdl-match-string-downcase (num &optional string)
13120 "Like `match-string-no-properties' with down-casing."
13121 (let ((match (match-string-no-properties num string)))
13122 (and match (downcase match))))
13125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13126 ;; Scan functions
13128 (defun vhdl-scan-context-clause ()
13129 "Scan the context clause that preceeds a design unit."
13130 (let (lib-alist)
13131 (save-excursion
13132 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13133 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13134 (equal "USE" (upcase (match-string 1))))
13135 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13136 (setq lib-alist (cons (cons (match-string-no-properties 1)
13137 (vhdl-match-string-downcase 2))
13138 lib-alist))))))
13139 lib-alist))
13141 (defun vhdl-scan-directory-contents (name &optional project update num-string
13142 non-final)
13143 "Scan contents of VHDL files in directory or file pattern NAME."
13144 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13145 ; (unless (file-directory-p (match-string 1 name))
13146 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13147 (let* ((dir-name (match-string 1 name))
13148 (file-pattern (match-string 2 name))
13149 (is-directory (= 0 (length file-pattern)))
13150 (file-list
13151 (if update
13152 (list name)
13153 (if is-directory
13154 (vhdl-get-source-files t dir-name)
13155 (vhdl-directory-files
13156 dir-name t (wildcard-to-regexp file-pattern)))))
13157 (key (or project dir-name))
13158 (file-exclude-regexp
13159 (or (nth 3 (aget vhdl-project-alist project)) ""))
13160 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13161 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13162 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13163 ent-alist conf-alist pack-alist ent-inst-list file-alist
13164 tmp-list tmp-entry no-files files-exist big-files)
13165 (when (or project update)
13166 (setq ent-alist (aget vhdl-entity-alist key t)
13167 conf-alist (aget vhdl-config-alist key t)
13168 pack-alist (aget vhdl-package-alist key t)
13169 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13170 file-alist (aget vhdl-file-alist key t)))
13171 (when (and (not is-directory) (null file-list))
13172 (message "No such file: \"%s\"" name))
13173 (setq files-exist file-list)
13174 (when file-list
13175 (setq no-files (length file-list))
13176 (message "Scanning %s %s\"%s\"..."
13177 (if is-directory "directory" "files") (or num-string "") name)
13178 ;; exclude files
13179 (unless (equal file-exclude-regexp "")
13180 (let ((case-fold-search nil)
13181 file-tmp-list)
13182 (while file-list
13183 (unless (string-match file-exclude-regexp (car file-list))
13184 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13185 (setq file-list (cdr file-list)))
13186 (setq file-list (nreverse file-tmp-list))))
13187 ;; do for all files
13188 (while file-list
13189 (unless noninteractive
13190 (message "Scanning %s %s\"%s\"... (%2d%s)"
13191 (if is-directory "directory" "files")
13192 (or num-string "") name
13193 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13194 (let ((file-name (abbreviate-file-name (car file-list)))
13195 ent-list arch-list arch-ent-list conf-list
13196 pack-list pack-body-list inst-list inst-ent-list)
13197 ;; scan file
13198 (vhdl-visit-file
13199 file-name nil
13200 (vhdl-prepare-search-2
13201 (save-excursion
13202 ;; scan for design units
13203 (if (and limit-design-file-size
13204 (< limit-design-file-size (buffer-size)))
13205 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13206 (setq big-files t))
13207 ;; scan for entities
13208 (goto-char (point-min))
13209 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13210 (let* ((ent-name (match-string-no-properties 1))
13211 (ent-key (downcase ent-name))
13212 (ent-entry (aget ent-alist ent-key t))
13213 (lib-alist (vhdl-scan-context-clause)))
13214 (if (nth 1 ent-entry)
13215 (vhdl-warning-when-idle
13216 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13217 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13218 file-name (vhdl-current-line))
13219 (setq ent-list (cons ent-key ent-list))
13220 (aput 'ent-alist ent-key
13221 (list ent-name file-name (vhdl-current-line)
13222 (nth 3 ent-entry) (nth 4 ent-entry)
13223 lib-alist)))))
13224 ;; scan for architectures
13225 (goto-char (point-min))
13226 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13227 (let* ((arch-name (match-string-no-properties 1))
13228 (arch-key (downcase arch-name))
13229 (ent-name (match-string-no-properties 2))
13230 (ent-key (downcase ent-name))
13231 (ent-entry (aget ent-alist ent-key t))
13232 (arch-alist (nth 3 ent-entry))
13233 (arch-entry (aget arch-alist arch-key t))
13234 (lib-arch-alist (vhdl-scan-context-clause)))
13235 (if arch-entry
13236 (vhdl-warning-when-idle
13237 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13238 arch-name ent-name (nth 1 arch-entry)
13239 (nth 2 arch-entry) file-name (vhdl-current-line))
13240 (setq arch-list (cons arch-key arch-list)
13241 arch-ent-list (cons ent-key arch-ent-list))
13242 (aput 'arch-alist arch-key
13243 (list arch-name file-name (vhdl-current-line) nil
13244 lib-arch-alist))
13245 (aput 'ent-alist ent-key
13246 (list (or (nth 0 ent-entry) ent-name)
13247 (nth 1 ent-entry) (nth 2 ent-entry)
13248 (vhdl-sort-alist arch-alist)
13249 arch-key (nth 5 ent-entry))))))
13250 ;; scan for configurations
13251 (goto-char (point-min))
13252 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13253 (let* ((conf-name (match-string-no-properties 1))
13254 (conf-key (downcase conf-name))
13255 (conf-entry (aget conf-alist conf-key t))
13256 (ent-name (match-string-no-properties 2))
13257 (ent-key (downcase ent-name))
13258 (lib-alist (vhdl-scan-context-clause))
13259 (conf-line (vhdl-current-line))
13260 (end-of-unit (vhdl-get-end-of-unit))
13261 arch-key comp-conf-list inst-key-list
13262 inst-comp-key inst-ent-key inst-arch-key
13263 inst-conf-key inst-lib-key)
13264 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13265 (setq arch-key (vhdl-match-string-downcase 1)))
13266 (if conf-entry
13267 (vhdl-warning-when-idle
13268 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13269 conf-name ent-name (nth 1 conf-entry)
13270 (nth 2 conf-entry) file-name conf-line)
13271 (setq conf-list (cons conf-key conf-list))
13272 ;; scan for subconfigurations and subentities
13273 (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)
13274 (setq inst-comp-key (vhdl-match-string-downcase 3)
13275 inst-key-list (split-string
13276 (vhdl-match-string-downcase 1)
13277 "[ \t\n]*,[ \t\n]*"))
13278 (vhdl-forward-syntactic-ws)
13279 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13280 (setq
13281 inst-lib-key (vhdl-match-string-downcase 3)
13282 inst-ent-key (and (match-string 2)
13283 (vhdl-match-string-downcase 4))
13284 inst-arch-key (and (match-string 2)
13285 (vhdl-match-string-downcase 6))
13286 inst-conf-key (and (not (match-string 2))
13287 (vhdl-match-string-downcase 4)))
13288 (while inst-key-list
13289 (setq comp-conf-list
13290 (cons (list (car inst-key-list)
13291 inst-comp-key inst-ent-key
13292 inst-arch-key inst-conf-key
13293 inst-lib-key)
13294 comp-conf-list))
13295 (setq inst-key-list (cdr inst-key-list)))))
13296 (aput 'conf-alist conf-key
13297 (list conf-name file-name conf-line ent-key
13298 arch-key comp-conf-list lib-alist)))))
13299 ;; scan for packages
13300 (goto-char (point-min))
13301 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13302 (let* ((pack-name (match-string-no-properties 2))
13303 (pack-key (downcase pack-name))
13304 (is-body (match-string-no-properties 1))
13305 (pack-entry (aget pack-alist pack-key t))
13306 (pack-line (vhdl-current-line))
13307 (end-of-unit (vhdl-get-end-of-unit))
13308 comp-name func-name comp-alist func-alist lib-alist)
13309 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13310 (vhdl-warning-when-idle
13311 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13312 (if is-body " body" "") pack-name
13313 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13314 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13315 file-name (vhdl-current-line))
13316 ;; scan for context clauses
13317 (setq lib-alist (vhdl-scan-context-clause))
13318 ;; scan for component and subprogram declarations/bodies
13319 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13320 (if (equal (upcase (match-string 1)) "COMPONENT")
13321 (setq comp-name (match-string-no-properties 2)
13322 comp-alist
13323 (cons (list (downcase comp-name) comp-name
13324 file-name (vhdl-current-line))
13325 comp-alist))
13326 (setq func-name (match-string-no-properties 2)
13327 func-alist
13328 (cons (list (downcase func-name) func-name
13329 file-name (vhdl-current-line))
13330 func-alist))))
13331 (setq func-alist (nreverse func-alist))
13332 (setq comp-alist (nreverse comp-alist))
13333 (if is-body
13334 (setq pack-body-list (cons pack-key pack-body-list))
13335 (setq pack-list (cons pack-key pack-list)))
13336 (aput
13337 'pack-alist pack-key
13338 (if is-body
13339 (list (or (nth 0 pack-entry) pack-name)
13340 (nth 1 pack-entry) (nth 2 pack-entry)
13341 (nth 3 pack-entry) (nth 4 pack-entry)
13342 (nth 5 pack-entry)
13343 file-name pack-line func-alist lib-alist)
13344 (list pack-name file-name pack-line
13345 comp-alist func-alist lib-alist
13346 (nth 6 pack-entry) (nth 7 pack-entry)
13347 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13348 ;; scan for hierarchy
13349 (if (and limit-hier-file-size
13350 (< limit-hier-file-size (buffer-size)))
13351 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13352 (setq big-files t))
13353 ;; scan for architectures
13354 (goto-char (point-min))
13355 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13356 (let* ((ent-name (match-string-no-properties 2))
13357 (ent-key (downcase ent-name))
13358 (arch-name (match-string-no-properties 1))
13359 (arch-key (downcase arch-name))
13360 (ent-entry (aget ent-alist ent-key t))
13361 (arch-alist (nth 3 ent-entry))
13362 (arch-entry (aget arch-alist arch-key t))
13363 (beg-of-unit (point))
13364 (end-of-unit (vhdl-get-end-of-unit))
13365 (inst-no 0)
13366 inst-alist inst-path)
13367 ;; scan for contained instantiations
13368 (while (and (re-search-forward
13369 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13370 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13371 "component[ \t\n]+\\(\\w+\\)\\|"
13372 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13373 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13374 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13375 (or (not limit-hier-inst-no)
13376 (<= (setq inst-no (1+ inst-no))
13377 limit-hier-inst-no)))
13378 (cond
13379 ;; block/generate beginning found
13380 ((match-string 14)
13381 (setq inst-path
13382 (cons (match-string-no-properties 1) inst-path)))
13383 ;; block/generate end found
13384 ((match-string 16)
13385 (setq inst-path (cdr inst-path)))
13386 ;; instantiation found
13388 (let* ((inst-name (match-string-no-properties 1))
13389 (inst-key (downcase inst-name))
13390 (inst-comp-name
13391 (or (match-string-no-properties 3)
13392 (match-string-no-properties 6)))
13393 (inst-ent-key
13394 (or (and (match-string 8)
13395 (vhdl-match-string-downcase 11))
13396 (and inst-comp-name
13397 (downcase inst-comp-name))))
13398 (inst-arch-key (vhdl-match-string-downcase 13))
13399 (inst-conf-key
13400 (and (not (match-string 8))
13401 (vhdl-match-string-downcase 11)))
13402 (inst-lib-key (vhdl-match-string-downcase 10)))
13403 (goto-char (match-end 1))
13404 (setq inst-list (cons inst-key inst-list)
13405 inst-ent-list
13406 (cons inst-ent-key inst-ent-list))
13407 (setq inst-alist
13408 (append
13409 inst-alist
13410 (list (list inst-key inst-name file-name
13411 (vhdl-current-line) inst-comp-name
13412 inst-ent-key inst-arch-key
13413 inst-conf-key inst-lib-key
13414 (reverse inst-path)))))))))
13415 ;; scan for contained configuration specifications
13416 (goto-char beg-of-unit)
13417 (while (re-search-forward
13418 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13419 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13420 (let* ((inst-comp-name (match-string-no-properties 3))
13421 (inst-ent-key
13422 (and (match-string 6)
13423 (vhdl-match-string-downcase 9)))
13424 (inst-arch-key (vhdl-match-string-downcase 11))
13425 (inst-conf-key
13426 (and (not (match-string 6))
13427 (vhdl-match-string-downcase 9)))
13428 (inst-lib-key (vhdl-match-string-downcase 8))
13429 (inst-key-list
13430 (split-string (vhdl-match-string-downcase 1)
13431 "[ \t\n]*,[ \t\n]*"))
13432 (tmp-inst-alist inst-alist)
13433 inst-entry)
13434 (while tmp-inst-alist
13435 (when (and (or (equal "all" (car inst-key-list))
13436 (member (nth 0 (car tmp-inst-alist))
13437 inst-key-list))
13438 (equal
13439 (downcase
13440 (or (nth 4 (car tmp-inst-alist)) ""))
13441 (downcase inst-comp-name)))
13442 (setq inst-entry (car tmp-inst-alist))
13443 (setq inst-ent-list
13444 (cons (or inst-ent-key (nth 5 inst-entry))
13445 (vhdl-delete
13446 (nth 5 inst-entry) inst-ent-list)))
13447 (setq inst-entry
13448 (list (nth 0 inst-entry) (nth 1 inst-entry)
13449 (nth 2 inst-entry) (nth 3 inst-entry)
13450 (nth 4 inst-entry)
13451 (or inst-ent-key (nth 5 inst-entry))
13452 (or inst-arch-key (nth 6 inst-entry))
13453 inst-conf-key inst-lib-key))
13454 (setcar tmp-inst-alist inst-entry))
13455 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13456 ;; save in cache
13457 (aput 'arch-alist arch-key
13458 (list (nth 0 arch-entry) (nth 1 arch-entry)
13459 (nth 2 arch-entry) inst-alist
13460 (nth 4 arch-entry)))
13461 (aput 'ent-alist ent-key
13462 (list (nth 0 ent-entry) (nth 1 ent-entry)
13463 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13464 (nth 4 ent-entry) (nth 5 ent-entry)))
13465 (when (and limit-hier-inst-no
13466 (> inst-no limit-hier-inst-no))
13467 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13468 (setq big-files t))
13469 (goto-char end-of-unit))))
13470 ;; remember design units for this file
13471 (aput 'file-alist file-name
13472 (list ent-list arch-list arch-ent-list conf-list
13473 pack-list pack-body-list inst-list inst-ent-list))
13474 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13475 (setq file-list (cdr file-list))))
13476 (when (or (and (not project) files-exist)
13477 (and project (not non-final)))
13478 ;; consistency checks:
13479 ;; check whether each architecture has a corresponding entity
13480 (setq tmp-list ent-alist)
13481 (while tmp-list
13482 (when (null (nth 2 (car tmp-list)))
13483 (setq tmp-entry (car (nth 4 (car tmp-list))))
13484 (vhdl-warning-when-idle
13485 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13486 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13487 (nth 3 tmp-entry)))
13488 (setq tmp-list (cdr tmp-list)))
13489 ;; check whether configuration has a corresponding entity/architecture
13490 (setq tmp-list conf-alist)
13491 (while tmp-list
13492 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13493 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13494 (setq tmp-entry (car tmp-list))
13495 (vhdl-warning-when-idle
13496 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13497 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13498 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13499 (setq tmp-entry (car tmp-list))
13500 (vhdl-warning-when-idle
13501 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13502 (nth 1 tmp-entry) (nth 4 tmp-entry)
13503 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13504 (setq tmp-list (cdr tmp-list)))
13505 ;; check whether each package body has a package declaration
13506 (setq tmp-list pack-alist)
13507 (while tmp-list
13508 (when (null (nth 2 (car tmp-list)))
13509 (setq tmp-entry (car tmp-list))
13510 (vhdl-warning-when-idle
13511 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13512 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13513 (setq tmp-list (cdr tmp-list)))
13514 ;; sort lists
13515 (setq ent-alist (vhdl-sort-alist ent-alist))
13516 (setq conf-alist (vhdl-sort-alist conf-alist))
13517 (setq pack-alist (vhdl-sort-alist pack-alist))
13518 ;; remember updated directory/project
13519 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13520 ;; clear directory alists
13521 (unless project
13522 (adelete 'vhdl-entity-alist key)
13523 (adelete 'vhdl-config-alist key)
13524 (adelete 'vhdl-package-alist key)
13525 (adelete 'vhdl-ent-inst-alist key)
13526 (adelete 'vhdl-file-alist key))
13527 ;; put directory contents into cache
13528 (aput 'vhdl-entity-alist key ent-alist)
13529 (aput 'vhdl-config-alist key conf-alist)
13530 (aput 'vhdl-package-alist key pack-alist)
13531 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13532 (aput 'vhdl-file-alist key file-alist)
13533 ;; final messages
13534 (message "Scanning %s %s\"%s\"...done"
13535 (if is-directory "directory" "files") (or num-string "") name)
13536 (unless project (message "Scanning directory...done"))
13537 (when big-files
13538 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13539 ;; save cache when scanned non-interactively
13540 (when (or (not project) (not non-final))
13541 (when (and noninteractive vhdl-speedbar-save-cache)
13542 (vhdl-save-cache key)))
13545 (defun vhdl-scan-project-contents (project)
13546 "Scan the contents of all VHDL files found in the directories and files
13547 of PROJECT."
13548 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13549 (default-dir (vhdl-resolve-env-variable
13550 (nth 1 (aget vhdl-project-alist project))))
13551 (file-exclude-regexp
13552 (or (nth 3 (aget vhdl-project-alist project)) ""))
13553 dir-list-tmp dir dir-name num-dir act-dir recursive)
13554 ;; clear project alists
13555 (adelete 'vhdl-entity-alist project)
13556 (adelete 'vhdl-config-alist project)
13557 (adelete 'vhdl-package-alist project)
13558 (adelete 'vhdl-ent-inst-alist project)
13559 (adelete 'vhdl-file-alist project)
13560 ;; expand directory names by default-directory
13561 (message "Collecting source files...")
13562 (while dir-list
13563 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13564 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13565 (setq recursive (match-string 1 dir)
13566 dir-name (match-string 3 dir))
13567 (setq dir-list-tmp
13568 (cons (concat recursive
13569 (if (file-name-absolute-p dir-name) "" default-dir)
13570 dir-name)
13571 dir-list-tmp))
13572 (setq dir-list (cdr dir-list)))
13573 ;; resolve path wildcards
13574 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13575 ;; expand directories
13576 (while dir-list-tmp
13577 (setq dir (car dir-list-tmp))
13578 ;; get subdirectories
13579 (if (string-match "-r \\(.*[/\\]\\)" dir)
13580 (setq dir-list (append dir-list (vhdl-get-subdirs
13581 (match-string 1 dir))))
13582 (setq dir-list (append dir-list (list dir))))
13583 (setq dir-list-tmp (cdr dir-list-tmp)))
13584 ;; exclude files
13585 (unless (equal file-exclude-regexp "")
13586 (let ((case-fold-search nil))
13587 (while dir-list
13588 (unless (string-match file-exclude-regexp (car dir-list))
13589 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13590 (setq dir-list (cdr dir-list)))
13591 (setq dir-list (nreverse dir-list-tmp))))
13592 (message "Collecting source files...done")
13593 ;; scan for design units for each directory in DIR-LIST
13594 (setq dir-list-tmp nil
13595 num-dir (length dir-list)
13596 act-dir 1)
13597 (while dir-list
13598 (setq dir-name (abbreviate-file-name
13599 (expand-file-name (car dir-list))))
13600 (vhdl-scan-directory-contents dir-name project nil
13601 (format "(%s/%s) " act-dir num-dir)
13602 (cdr dir-list))
13603 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13604 (setq dir-list (cdr dir-list)
13605 act-dir (1+ act-dir)))
13606 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13607 (message "Scanning project \"%s\"...done" project)))
13609 (defun vhdl-update-file-contents (file-name)
13610 "Update hierarchy information by contents of current buffer."
13611 (setq file-name (abbreviate-file-name file-name))
13612 (let* ((dir-name (file-name-directory file-name))
13613 (directory-alist vhdl-directory-alist)
13614 updated)
13615 (while directory-alist
13616 (when (member dir-name (nth 1 (car directory-alist)))
13617 (let* ((vhdl-project (nth 0 (car directory-alist)))
13618 (project (vhdl-project-p))
13619 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13620 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13621 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13622 (ent-inst-list (car (aget vhdl-ent-inst-alist
13623 (or project dir-name) t)))
13624 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13625 (file-entry (aget file-alist file-name t))
13626 (ent-list (nth 0 file-entry))
13627 (arch-list (nth 1 file-entry))
13628 (arch-ent-list (nth 2 file-entry))
13629 (conf-list (nth 3 file-entry))
13630 (pack-list (nth 4 file-entry))
13631 (pack-body-list (nth 5 file-entry))
13632 (inst-ent-list (nth 7 file-entry))
13633 (cache-key (or project dir-name))
13634 arch-alist key ent-key entry)
13635 ;; delete design units previously contained in this file:
13636 ;; entities
13637 (while ent-list
13638 (setq key (car ent-list)
13639 entry (aget ent-alist key t))
13640 (when (equal file-name (nth 1 entry))
13641 (if (nth 3 entry)
13642 (aput 'ent-alist key
13643 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13644 (adelete 'ent-alist key)))
13645 (setq ent-list (cdr ent-list)))
13646 ;; architectures
13647 (while arch-list
13648 (setq key (car arch-list)
13649 ent-key (car arch-ent-list)
13650 entry (aget ent-alist ent-key t)
13651 arch-alist (nth 3 entry))
13652 (when (equal file-name (nth 1 (aget arch-alist key t)))
13653 (adelete 'arch-alist key)
13654 (if (or (nth 1 entry) arch-alist)
13655 (aput 'ent-alist ent-key
13656 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13657 arch-alist (nth 4 entry) (nth 5 entry)))
13658 (adelete 'ent-alist ent-key)))
13659 (setq arch-list (cdr arch-list)
13660 arch-ent-list (cdr arch-ent-list)))
13661 ;; configurations
13662 (while conf-list
13663 (setq key (car conf-list))
13664 (when (equal file-name (nth 1 (aget conf-alist key t)))
13665 (adelete 'conf-alist key))
13666 (setq conf-list (cdr conf-list)))
13667 ;; package declarations
13668 (while pack-list
13669 (setq key (car pack-list)
13670 entry (aget pack-alist key t))
13671 (when (equal file-name (nth 1 entry))
13672 (if (nth 6 entry)
13673 (aput 'pack-alist key
13674 (list (nth 0 entry) nil nil nil nil nil
13675 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13676 (nth 9 entry)))
13677 (adelete 'pack-alist key)))
13678 (setq pack-list (cdr pack-list)))
13679 ;; package bodies
13680 (while pack-body-list
13681 (setq key (car pack-body-list)
13682 entry (aget pack-alist key t))
13683 (when (equal file-name (nth 6 entry))
13684 (if (nth 1 entry)
13685 (aput 'pack-alist key
13686 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13687 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13688 nil nil nil nil))
13689 (adelete 'pack-alist key)))
13690 (setq pack-body-list (cdr pack-body-list)))
13691 ;; instantiated entities
13692 (while inst-ent-list
13693 (setq ent-inst-list
13694 (vhdl-delete (car inst-ent-list) ent-inst-list))
13695 (setq inst-ent-list (cdr inst-ent-list)))
13696 ;; update caches
13697 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13698 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13699 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13700 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13701 ;; scan file
13702 (vhdl-scan-directory-contents file-name project t)
13703 (when (or (and vhdl-speedbar-show-projects project)
13704 (and (not vhdl-speedbar-show-projects) (not project)))
13705 (vhdl-speedbar-refresh project))
13706 (setq updated t)))
13707 (setq directory-alist (cdr directory-alist)))
13708 updated))
13710 (defun vhdl-update-hierarchy ()
13711 "Update directory and hierarchy information in speedbar."
13712 (let ((file-list (reverse vhdl-modified-file-list))
13713 updated)
13714 (when (and vhdl-speedbar-update-on-saving file-list)
13715 (while file-list
13716 (setq updated
13717 (or (vhdl-update-file-contents (car file-list))
13718 updated))
13719 (setq file-list (cdr file-list)))
13720 (setq vhdl-modified-file-list nil)
13721 (vhdl-speedbar-update-current-unit)
13722 (when updated (message "Updating hierarchy...done")))))
13724 ;; structure (parenthesised expression means list of such entries)
13725 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13726 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13727 ;; comp-lib-name level)
13728 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13729 conf-inst-alist level indent
13730 &optional include-top ent-hier)
13731 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13732 entity ENT-KEY."
13733 (let* ((ent-entry (aget ent-alist ent-key t))
13734 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13735 (cdar (last (nth 3 ent-entry)))))
13736 (inst-alist (nth 3 arch-entry))
13737 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13738 hier-list subcomp-list tmp-list inst-key inst-comp-name
13739 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13740 (when (= level 0) (message "Extract design hierarchy..."))
13741 (when include-top
13742 (setq level (1+ level)))
13743 (when (member ent-key ent-hier)
13744 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13745 ;; check configured architecture (already checked during scanning)
13746 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13747 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13748 ;; process all instances
13749 (while inst-alist
13750 (setq inst-entry (car inst-alist)
13751 inst-key (nth 0 inst-entry)
13752 inst-comp-name (nth 4 inst-entry)
13753 inst-conf-key (nth 7 inst-entry))
13754 ;; search entry in configuration's instantiations list
13755 (setq tmp-list conf-inst-alist)
13756 (while (and tmp-list
13757 (not (and (member (nth 0 (car tmp-list))
13758 (list "all" inst-key))
13759 (equal (nth 1 (car tmp-list))
13760 (downcase (or inst-comp-name ""))))))
13761 (setq tmp-list (cdr tmp-list)))
13762 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13763 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13764 (when (and inst-conf-key (not inst-conf-entry))
13765 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13766 ;; determine entity
13767 (setq inst-ent-key
13768 (or (nth 2 (car tmp-list)) ; from configuration
13769 (nth 3 inst-conf-entry) ; from subconfiguration
13770 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13771 ; from configuration spec.
13772 (nth 5 inst-entry))) ; from direct instantiation
13773 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13774 ;; determine architecture
13775 (setq inst-arch-key
13776 (or (nth 3 (car tmp-list)) ; from configuration
13777 (nth 4 inst-conf-entry) ; from subconfiguration
13778 (nth 6 inst-entry) ; from direct instantiation
13779 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13780 ; from configuration spec.
13781 (nth 4 inst-ent-entry) ; MRA
13782 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13783 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13784 ;; set library
13785 (setq inst-lib-key
13786 (or (nth 5 (car tmp-list)) ; from configuration
13787 (nth 8 inst-entry))) ; from direct instantiation
13788 ;; gather information for this instance
13789 (setq comp-entry
13790 (list (nth 1 inst-entry)
13791 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13792 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13793 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13794 (or (nth 0 inst-arch-entry) inst-arch-key)
13795 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13796 (or (nth 0 inst-conf-entry) inst-conf-key)
13797 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13798 inst-lib-key level))
13799 ;; get subcomponent hierarchy
13800 (setq subcomp-list (vhdl-get-hierarchy
13801 ent-alist conf-alist
13802 inst-ent-key inst-arch-key inst-conf-key
13803 (nth 5 inst-conf-entry)
13804 (1+ level) indent nil (cons ent-key ent-hier)))
13805 ;; add to list
13806 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13807 (setq inst-alist (cdr inst-alist)))
13808 (when include-top
13809 (setq hier-list
13810 (cons (list nil nil (nth 0 ent-entry)
13811 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13812 (nth 0 arch-entry)
13813 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13814 nil nil
13815 nil (1- level))
13816 hier-list)))
13817 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13818 hier-list))
13820 (defun vhdl-get-instantiations (ent-key indent)
13821 "Get all instantiations of entity ENT-KEY."
13822 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13823 arch-alist inst-alist ent-inst-list
13824 ent-entry arch-entry inst-entry)
13825 (while ent-alist
13826 (setq ent-entry (car ent-alist))
13827 (setq arch-alist (nth 4 ent-entry))
13828 (while arch-alist
13829 (setq arch-entry (car arch-alist))
13830 (setq inst-alist (nth 4 arch-entry))
13831 (while inst-alist
13832 (setq inst-entry (car inst-alist))
13833 (when (equal ent-key (nth 5 inst-entry))
13834 (setq ent-inst-list
13835 (cons (list (nth 1 inst-entry)
13836 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13837 (nth 1 ent-entry)
13838 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13839 (nth 1 arch-entry)
13840 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13841 ent-inst-list)))
13842 (setq inst-alist (cdr inst-alist)))
13843 (setq arch-alist (cdr arch-alist)))
13844 (setq ent-alist (cdr ent-alist)))
13845 (nreverse ent-inst-list)))
13847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13848 ;; Caching in file
13850 (defun vhdl-save-caches ()
13851 "Save all updated hierarchy caches to file."
13852 (interactive)
13853 (condition-case nil
13854 (when vhdl-speedbar-save-cache
13855 ;; update hierarchy
13856 (vhdl-update-hierarchy)
13857 (let ((project-list vhdl-updated-project-list))
13858 (message "Saving hierarchy caches...")
13859 ;; write updated project caches
13860 (while project-list
13861 (vhdl-save-cache (car project-list))
13862 (setq project-list (cdr project-list)))
13863 (message "Saving hierarchy caches...done")))
13864 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13865 (sit-for 2)))))
13867 (defun vhdl-save-cache (key)
13868 "Save current hierarchy cache to file."
13869 (let* ((orig-buffer (current-buffer))
13870 (vhdl-project key)
13871 (project (vhdl-project-p))
13872 (default-directory key)
13873 (directory (abbreviate-file-name (vhdl-default-directory)))
13874 (file-name (vhdl-resolve-env-variable
13875 (vhdl-replace-string
13876 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13877 (concat
13878 (subst-char-in-string ? ?_ (or project "dir"))
13879 " " (user-login-name)))))
13880 (file-dir-name (expand-file-name file-name directory))
13881 (cache-key (or project directory))
13882 (key (if project "project" "directory")))
13883 (unless (file-exists-p (file-name-directory file-dir-name))
13884 (make-directory (file-name-directory file-dir-name) t))
13885 (if (not (file-writable-p file-dir-name))
13886 (progn (vhdl-warning (format "File not writable: \"%s\""
13887 (abbreviate-file-name file-dir-name)))
13888 (sit-for 2))
13889 (message "Saving cache: \"%s\"" file-dir-name)
13890 (set-buffer (find-file-noselect file-dir-name t t))
13891 (erase-buffer)
13892 (insert ";; -*- Emacs-Lisp -*-\n\n"
13893 ";;; " (file-name-nondirectory file-name)
13894 " - design hierarchy cache file for Emacs VHDL Mode "
13895 vhdl-version "\n")
13896 (insert "\n;; " (if project "Project " "Directory") " : ")
13897 (if project (insert project) (prin1 directory (current-buffer)))
13898 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13899 (user-login-name) "\n\n"
13900 "\n;; version number\n"
13901 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13902 "\n;; " (if project "project" "directory") " name"
13903 "\n(setq " key " ")
13904 (prin1 (or project directory) (current-buffer))
13905 (insert ")\n")
13906 (when (member 'hierarchy vhdl-speedbar-save-cache)
13907 (insert "\n;; entity and architecture cache\n"
13908 "(aput 'vhdl-entity-alist " key " '")
13909 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13910 (insert ")\n\n;; configuration cache\n"
13911 "(aput 'vhdl-config-alist " key " '")
13912 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13913 (insert ")\n\n;; package cache\n"
13914 "(aput 'vhdl-package-alist " key " '")
13915 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13916 (insert ")\n\n;; instantiated entities cache\n"
13917 "(aput 'vhdl-ent-inst-alist " key " '")
13918 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13919 (insert ")\n\n;; design units per file cache\n"
13920 "(aput 'vhdl-file-alist " key " '")
13921 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13922 (when project
13923 (insert ")\n\n;; source directories in project cache\n"
13924 "(aput 'vhdl-directory-alist " key " '")
13925 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13926 (insert ")\n"))
13927 (when (member 'display vhdl-speedbar-save-cache)
13928 (insert "\n;; shown design units cache\n"
13929 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13930 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13931 (current-buffer))
13932 (insert ")\n"))
13933 (setq vhdl-updated-project-list
13934 (delete cache-key vhdl-updated-project-list))
13935 (save-buffer)
13936 (kill-buffer (current-buffer))
13937 (set-buffer orig-buffer))))
13939 (defun vhdl-load-cache (key)
13940 "Load hierarchy cache information from file."
13941 (let* ((vhdl-project key)
13942 (default-directory key)
13943 (directory (vhdl-default-directory))
13944 (file-name (vhdl-resolve-env-variable
13945 (vhdl-replace-string
13946 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13947 (concat
13948 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13949 " " (user-login-name)))))
13950 (file-dir-name (expand-file-name file-name directory))
13951 vhdl-cache-version)
13952 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13953 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13954 (when (file-exists-p file-dir-name)
13955 (condition-case ()
13956 (progn (load-file file-dir-name)
13957 (string< (mapconcat
13958 (lambda (a) (format "%3d" (string-to-number a)))
13959 (split-string "3.33" "\\.") "")
13960 (mapconcat
13961 (lambda (a) (format "%3d" (string-to-number a)))
13962 (split-string vhdl-cache-version "\\.") "")))
13963 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13964 nil))))))
13966 (defun vhdl-require-hierarchy-info ()
13967 "Make sure that hierarchy information is available. Load cache or scan files
13968 if required."
13969 (if (vhdl-project-p)
13970 (unless (or (assoc vhdl-project vhdl-file-alist)
13971 (vhdl-load-cache vhdl-project))
13972 (vhdl-scan-project-contents vhdl-project))
13973 (let ((directory (abbreviate-file-name default-directory)))
13974 (unless (or (assoc directory vhdl-file-alist)
13975 (vhdl-load-cache directory))
13976 (vhdl-scan-directory-contents directory)))))
13978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13979 ;; Add hierarchy browser functionality to speedbar
13981 (defvar vhdl-speedbar-key-map nil
13982 "Keymap used when in the VHDL hierarchy browser mode.")
13984 (defvar vhdl-speedbar-menu-items nil
13985 "Additional menu-items to add to speedbar frame.")
13987 (defun vhdl-speedbar-initialize ()
13988 "Initialize speedbar."
13989 ;; general settings
13990 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13991 ;; VHDL file extensions (extracted from `auto-mode-alist')
13992 (let ((mode-alist auto-mode-alist))
13993 (while mode-alist
13994 (when (eq (cdar mode-alist) 'vhdl-mode)
13995 (speedbar-add-supported-extension (caar mode-alist)))
13996 (setq mode-alist (cdr mode-alist))))
13997 ;; hierarchy browser settings
13998 (when (boundp 'speedbar-mode-functions-list)
13999 ;; special functions
14000 (speedbar-add-mode-functions-list
14001 '("vhdl directory"
14002 (speedbar-item-info . vhdl-speedbar-item-info)
14003 (speedbar-line-directory . speedbar-files-line-path)))
14004 (speedbar-add-mode-functions-list
14005 '("vhdl project"
14006 (speedbar-item-info . vhdl-speedbar-item-info)
14007 (speedbar-line-directory . vhdl-speedbar-line-project)))
14008 ;; keymap
14009 (unless vhdl-speedbar-key-map
14010 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14011 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14012 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14013 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14014 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14015 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14016 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14017 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14018 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14019 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14020 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14021 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14022 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14023 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14024 (let ((key 0))
14025 (while (<= key 9)
14026 (define-key vhdl-speedbar-key-map (int-to-string key)
14027 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14028 (setq key (1+ key)))))
14029 (define-key speedbar-key-map "h"
14030 (lambda () (interactive)
14031 (speedbar-change-initial-expansion-list "vhdl directory")))
14032 (define-key speedbar-key-map "H"
14033 (lambda () (interactive)
14034 (speedbar-change-initial-expansion-list "vhdl project")))
14035 ;; menu
14036 (unless vhdl-speedbar-menu-items
14037 (setq
14038 vhdl-speedbar-menu-items
14039 `(["Edit" speedbar-edit-line t]
14040 ["Expand" speedbar-expand-line
14041 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14042 ["Contract" vhdl-speedbar-contract-level t]
14043 ["Expand All" vhdl-speedbar-expand-all t]
14044 ["Contract All" vhdl-speedbar-contract-all t]
14045 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14046 (while (<= key 9)
14047 (setq menu-list
14048 (cons `[,(if (= key 0) "All" (int-to-string key))
14049 (vhdl-speedbar-set-depth ,key)
14050 :style radio
14051 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14052 :keys ,(int-to-string key)]
14053 menu-list))
14054 (setq key (1+ key)))
14055 (nreverse menu-list))
14056 "--"
14057 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14058 (or (vhdl-speedbar-check-unit 'entity)
14059 (vhdl-speedbar-check-unit 'subprogram))]
14060 ["Place Component" vhdl-speedbar-place-component
14061 (vhdl-speedbar-check-unit 'entity)]
14062 ["Generate Configuration" vhdl-speedbar-configuration
14063 (vhdl-speedbar-check-unit 'architecture)]
14064 ["Select as MRA" vhdl-speedbar-select-mra
14065 (vhdl-speedbar-check-unit 'architecture)]
14066 ["Make" vhdl-speedbar-make-design
14067 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14068 ["Generate Makefile" vhdl-speedbar-generate-makefile
14069 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14070 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14071 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14072 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14073 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14074 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14075 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14076 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14077 ;; hook-ups
14078 (speedbar-add-expansion-list
14079 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14080 vhdl-speedbar-display-directory))
14081 (speedbar-add-expansion-list
14082 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14083 vhdl-speedbar-display-projects))
14084 (setq speedbar-stealthy-function-list
14085 (append
14086 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14087 ("vhdl project" vhdl-speedbar-update-current-project
14088 vhdl-speedbar-update-current-unit)
14089 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14090 ; (speedbar-extension-list-to-regex
14091 ; speedbar-ignored-path-expressions))))
14093 speedbar-stealthy-function-list))
14094 (when (eq vhdl-speedbar-display-mode 'directory)
14095 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14096 (when (eq vhdl-speedbar-display-mode 'project)
14097 (setq speedbar-initial-expansion-list-name "vhdl project"))
14098 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14100 (defun vhdl-speedbar (&optional arg)
14101 "Open/close speedbar."
14102 (interactive)
14103 (if (not (fboundp 'speedbar))
14104 (error "WARNING: Speedbar is not available or not installed")
14105 (condition-case ()
14106 (speedbar-frame-mode arg)
14107 (error (error "WARNING: An error occurred while opening speedbar")))))
14109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14110 ;; Display functions
14112 (defvar vhdl-speedbar-last-selected-project nil
14113 "Name of last selected project.")
14115 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14116 (defmacro speedbar-with-writable (&rest forms)
14117 "Allow the buffer to be writable and evaluate FORMS."
14118 (list 'let '((inhibit-read-only t))
14119 (cons 'progn forms)))
14120 (put 'speedbar-with-writable 'lisp-indent-function 0)
14122 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14123 "Display directory and hierarchy information in speedbar."
14124 (setq vhdl-speedbar-show-projects nil)
14125 (setq speedbar-ignored-directory-regexp
14126 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14127 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14128 (setq speedbar-last-selected-file nil)
14129 (speedbar-with-writable
14130 (condition-case nil
14131 (progn
14132 ;; insert directory path
14133 (speedbar-directory-buttons directory depth)
14134 ;; insert subdirectories
14135 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14136 ;; scan and insert hierarchy of current directory
14137 (vhdl-speedbar-insert-dir-hierarchy directory depth
14138 speedbar-power-click)
14139 ;; expand subdirectories
14140 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14141 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14143 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14144 "Display projects and hierarchy information in speedbar."
14145 (setq vhdl-speedbar-show-projects t)
14146 (setq speedbar-ignored-directory-regexp ".")
14147 (setq speedbar-last-selected-file nil)
14148 (setq vhdl-speedbar-last-selected-project nil)
14149 (speedbar-with-writable
14150 (condition-case nil
14151 ;; insert projects
14152 (vhdl-speedbar-insert-projects)
14153 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14154 (setq speedbar-full-text-cache nil)) ; prevent caching
14156 (defun vhdl-speedbar-insert-projects ()
14157 "Insert all projects in speedbar."
14158 (vhdl-speedbar-make-title-line "Projects:")
14159 (let ((project-alist (if vhdl-project-sort
14160 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14161 vhdl-project-alist))
14162 (vhdl-speedbar-update-current-unit nil))
14163 ;; insert projects
14164 (while project-alist
14165 (speedbar-make-tag-line
14166 'angle ?+ 'vhdl-speedbar-expand-project
14167 (caar project-alist) (caar project-alist)
14168 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14169 (setq project-alist (cdr project-alist)))
14170 (setq project-alist vhdl-project-alist)
14171 ;; expand projects
14172 (while project-alist
14173 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14174 (goto-char (point-min))
14175 (when (re-search-forward
14176 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14177 (goto-char (match-end 1))
14178 (speedbar-do-function-pointer)))
14179 (setq project-alist (cdr project-alist))))
14180 ; (vhdl-speedbar-update-current-project)
14181 ; (vhdl-speedbar-update-current-unit nil t)
14184 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14185 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14186 otherwise use cached data."
14187 (when (or rescan (and (not (assoc project vhdl-file-alist))
14188 (not (vhdl-load-cache project))))
14189 (vhdl-scan-project-contents project))
14190 ;; insert design hierarchy
14191 (vhdl-speedbar-insert-hierarchy
14192 (aget vhdl-entity-alist project t)
14193 (aget vhdl-config-alist project t)
14194 (aget vhdl-package-alist project t)
14195 (car (aget vhdl-ent-inst-alist project t)) indent)
14196 (insert (int-to-string indent) ":\n")
14197 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14198 (put-text-property (1- (point)) (point) 'invisible nil)
14199 ;; expand design units
14200 (vhdl-speedbar-expand-units project))
14202 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14203 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14204 otherwise use cached data."
14205 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14206 (not (vhdl-load-cache directory))))
14207 (vhdl-scan-directory-contents directory))
14208 ;; insert design hierarchy
14209 (vhdl-speedbar-insert-hierarchy
14210 (aget vhdl-entity-alist directory t)
14211 (aget vhdl-config-alist directory t)
14212 (aget vhdl-package-alist directory t)
14213 (car (aget vhdl-ent-inst-alist directory t)) depth)
14214 ;; expand design units
14215 (vhdl-speedbar-expand-units directory)
14216 (aput 'vhdl-directory-alist directory (list (list directory))))
14218 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14219 ent-inst-list depth)
14220 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14221 (if (not (or ent-alist conf-alist pack-alist))
14222 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14223 (let (ent-entry conf-entry pack-entry)
14224 ;; insert entities
14225 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14226 (while ent-alist
14227 (setq ent-entry (car ent-alist))
14228 (speedbar-make-tag-line
14229 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14230 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14231 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14232 'vhdl-speedbar-entity-face depth)
14233 (unless (nth 2 ent-entry)
14234 (end-of-line 0) (insert "!") (forward-char 1))
14235 (unless (member (nth 0 ent-entry) ent-inst-list)
14236 (end-of-line 0) (insert " (top)") (forward-char 1))
14237 (setq ent-alist (cdr ent-alist)))
14238 ;; insert configurations
14239 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14240 (while conf-alist
14241 (setq conf-entry (car conf-alist))
14242 (speedbar-make-tag-line
14243 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14244 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14245 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14246 'vhdl-speedbar-configuration-face depth)
14247 (setq conf-alist (cdr conf-alist)))
14248 ;; insert packages
14249 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14250 (while pack-alist
14251 (setq pack-entry (car pack-alist))
14252 (vhdl-speedbar-make-pack-line
14253 (nth 0 pack-entry) (nth 1 pack-entry)
14254 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14255 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14256 depth)
14257 (setq pack-alist (cdr pack-alist))))))
14259 (defun vhdl-speedbar-rescan-hierarchy ()
14260 "Rescan hierarchy for the directory or project under the cursor."
14261 (interactive)
14262 (let (key path)
14263 (cond
14264 ;; current project
14265 (vhdl-speedbar-show-projects
14266 (setq key (vhdl-speedbar-line-project))
14267 (vhdl-scan-project-contents key))
14268 ;; top-level directory
14269 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14270 (re-search-forward "[0-9]+:" nil t)
14271 (vhdl-scan-directory-contents
14272 (abbreviate-file-name (speedbar-line-directory))))
14273 ;; current directory
14274 (t (setq path (speedbar-line-directory))
14275 (string-match "^\\(.+[/\\]\\)" path)
14276 (vhdl-scan-directory-contents
14277 (abbreviate-file-name (match-string 1 path)))))
14278 (vhdl-speedbar-refresh key)))
14280 (defun vhdl-speedbar-expand-dirs (directory)
14281 "Expand subdirectories in DIRECTORY according to
14282 `speedbar-shown-directories'."
14283 ;; (nicked from `speedbar-default-directory-list')
14284 (let ((sf (cdr (reverse speedbar-shown-directories)))
14285 (vhdl-speedbar-update-current-unit nil))
14286 (setq speedbar-shown-directories
14287 (list (expand-file-name default-directory)))
14288 (while sf
14289 (when (speedbar-goto-this-file (car sf))
14290 (beginning-of-line)
14291 (when (looking-at "[0-9]+:\\s-*<")
14292 (goto-char (match-end 0))
14293 (speedbar-do-function-pointer)))
14294 (setq sf (cdr sf))))
14295 (vhdl-speedbar-update-current-unit nil t))
14297 (defun vhdl-speedbar-expand-units (key)
14298 "Expand design units in directory/project KEY according to
14299 `vhdl-speedbar-shown-unit-alist'."
14300 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14301 (vhdl-speedbar-update-current-unit nil)
14302 vhdl-updated-project-list)
14303 (adelete 'vhdl-speedbar-shown-unit-alist key)
14304 (vhdl-prepare-search-1
14305 (while unit-alist ; expand units
14306 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14307 (beginning-of-line)
14308 (let ((arch-alist (nth 1 (car unit-alist)))
14309 position)
14310 (when (looking-at "^[0-9]+:\\s-*\\[")
14311 (goto-char (match-end 0))
14312 (setq position (point))
14313 (speedbar-do-function-pointer)
14314 (select-frame speedbar-frame)
14315 (while arch-alist ; expand architectures
14316 (goto-char position)
14317 (when (re-search-forward
14318 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14319 (car arch-alist) "\\>\\)") nil t)
14320 (beginning-of-line)
14321 (when (looking-at "^[0-9]+:\\s-*{")
14322 (goto-char (match-end 0))
14323 (speedbar-do-function-pointer)
14324 (select-frame speedbar-frame)))
14325 (setq arch-alist (cdr arch-alist))))
14326 (setq unit-alist (cdr unit-alist))))))
14327 (vhdl-speedbar-update-current-unit nil t))
14329 (defun vhdl-speedbar-contract-level ()
14330 "Contract current level in current directory/project."
14331 (interactive)
14332 (when (or (save-excursion
14333 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14334 (and (save-excursion
14335 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14336 (re-search-backward
14337 (format "^[0-%d]:\\s-*[[{<]-"
14338 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14339 (goto-char (match-end 0))
14340 (speedbar-do-function-pointer)
14341 (speedbar-center-buffer-smartly)))
14343 (defun vhdl-speedbar-contract-all ()
14344 "Contract all expanded design units in current directory/project."
14345 (interactive)
14346 (if (and vhdl-speedbar-show-projects
14347 (save-excursion (beginning-of-line) (looking-at "^0:")))
14348 (progn (setq vhdl-speedbar-shown-project-list nil)
14349 (vhdl-speedbar-refresh))
14350 (let ((key (vhdl-speedbar-line-key)))
14351 (adelete 'vhdl-speedbar-shown-unit-alist key)
14352 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14353 (when (memq 'display vhdl-speedbar-save-cache)
14354 (add-to-list 'vhdl-updated-project-list key)))))
14356 (defun vhdl-speedbar-expand-all ()
14357 "Expand all design units in current directory/project."
14358 (interactive)
14359 (let* ((key (vhdl-speedbar-line-key))
14360 (ent-alist (aget vhdl-entity-alist key t))
14361 (conf-alist (aget vhdl-config-alist key t))
14362 (pack-alist (aget vhdl-package-alist key t))
14363 arch-alist unit-alist subunit-alist)
14364 (add-to-list 'vhdl-speedbar-shown-project-list key)
14365 (while ent-alist
14366 (setq arch-alist (nth 4 (car ent-alist)))
14367 (setq subunit-alist nil)
14368 (while arch-alist
14369 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14370 (setq arch-alist (cdr arch-alist)))
14371 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14372 (setq ent-alist (cdr ent-alist)))
14373 (while conf-alist
14374 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14375 (setq conf-alist (cdr conf-alist)))
14376 (while pack-alist
14377 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14378 (setq pack-alist (cdr pack-alist)))
14379 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14380 (vhdl-speedbar-refresh)
14381 (when (memq 'display vhdl-speedbar-save-cache)
14382 (add-to-list 'vhdl-updated-project-list key))))
14384 (defun vhdl-speedbar-expand-project (text token indent)
14385 "Expand/contract the project under the cursor."
14386 (cond
14387 ((string-match "+" text) ; expand project
14388 (speedbar-change-expand-button-char ?-)
14389 (unless (member token vhdl-speedbar-shown-project-list)
14390 (setq vhdl-speedbar-shown-project-list
14391 (cons token vhdl-speedbar-shown-project-list)))
14392 (speedbar-with-writable
14393 (save-excursion
14394 (end-of-line) (forward-char 1)
14395 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14396 speedbar-power-click))))
14397 ((string-match "-" text) ; contract project
14398 (speedbar-change-expand-button-char ?+)
14399 (setq vhdl-speedbar-shown-project-list
14400 (delete token vhdl-speedbar-shown-project-list))
14401 (speedbar-delete-subblock indent))
14402 (t (error "Nothing to display")))
14403 (when (equal (selected-frame) speedbar-frame)
14404 (speedbar-center-buffer-smartly)))
14406 (defun vhdl-speedbar-expand-entity (text token indent)
14407 "Expand/contract the entity under the cursor."
14408 (cond
14409 ((string-match "+" text) ; expand entity
14410 (let* ((key (vhdl-speedbar-line-key indent))
14411 (ent-alist (aget vhdl-entity-alist key t))
14412 (ent-entry (aget ent-alist token t))
14413 (arch-alist (nth 3 ent-entry))
14414 (inst-alist (vhdl-get-instantiations token indent))
14415 (subpack-alist (nth 5 ent-entry))
14416 (multiple-arch (> (length arch-alist) 1))
14417 arch-entry inst-entry)
14418 (if (not (or arch-alist inst-alist subpack-alist))
14419 (speedbar-change-expand-button-char ??)
14420 (speedbar-change-expand-button-char ?-)
14421 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14422 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14423 (aput 'unit-alist token nil)
14424 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14425 (speedbar-with-writable
14426 (save-excursion
14427 (end-of-line) (forward-char 1)
14428 ;; insert architectures
14429 (when arch-alist
14430 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14431 (while arch-alist
14432 (setq arch-entry (car arch-alist))
14433 (speedbar-make-tag-line
14434 'curly ?+ 'vhdl-speedbar-expand-architecture
14435 (cons token (nth 0 arch-entry))
14436 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14437 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14438 'vhdl-speedbar-architecture-face (1+ indent))
14439 (when (and multiple-arch
14440 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14441 (end-of-line 0) (insert " (mra)") (forward-char 1))
14442 (setq arch-alist (cdr arch-alist)))
14443 ;; insert instantiations
14444 (when inst-alist
14445 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14446 (while inst-alist
14447 (setq inst-entry (car inst-alist))
14448 (vhdl-speedbar-make-inst-line
14449 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14450 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14451 nil nil nil (1+ indent) 0 " in ")
14452 (setq inst-alist (cdr inst-alist)))
14453 ;; insert required packages
14454 (vhdl-speedbar-insert-subpackages
14455 subpack-alist (1+ indent) indent)))
14456 (when (memq 'display vhdl-speedbar-save-cache)
14457 (add-to-list 'vhdl-updated-project-list key))
14458 (vhdl-speedbar-update-current-unit t t))))
14459 ((string-match "-" text) ; contract entity
14460 (speedbar-change-expand-button-char ?+)
14461 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14462 (let* ((key (vhdl-speedbar-line-key indent))
14463 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14464 (adelete 'unit-alist token)
14465 (if unit-alist
14466 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14467 (adelete 'vhdl-speedbar-shown-unit-alist key))
14468 (speedbar-delete-subblock indent)
14469 (when (memq 'display vhdl-speedbar-save-cache)
14470 (add-to-list 'vhdl-updated-project-list key))))
14471 (t (error "Nothing to display")))
14472 (when (equal (selected-frame) speedbar-frame)
14473 (speedbar-center-buffer-smartly)))
14475 (defun vhdl-speedbar-expand-architecture (text token indent)
14476 "Expand/contract the architecture under the cursor."
14477 (cond
14478 ((string-match "+" text) ; expand architecture
14479 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14480 (ent-alist (aget vhdl-entity-alist key t))
14481 (conf-alist (aget vhdl-config-alist key t))
14482 (hier-alist (vhdl-get-hierarchy
14483 ent-alist conf-alist (car token) (cdr token) nil nil
14484 0 (1- indent)))
14485 (ent-entry (aget ent-alist (car token) t))
14486 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14487 (subpack-alist (nth 4 arch-entry))
14488 entry)
14489 (if (not (or hier-alist subpack-alist))
14490 (speedbar-change-expand-button-char ??)
14491 (speedbar-change-expand-button-char ?-)
14492 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14493 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14494 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14495 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14496 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14497 (speedbar-with-writable
14498 (save-excursion
14499 (end-of-line) (forward-char 1)
14500 ;; insert instance hierarchy
14501 (when hier-alist
14502 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14503 (1+ indent)))
14504 (while hier-alist
14505 (setq entry (car hier-alist))
14506 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14507 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14508 (vhdl-speedbar-make-inst-line
14509 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14510 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14511 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14512 (setq hier-alist (cdr hier-alist)))
14513 ;; insert required packages
14514 (vhdl-speedbar-insert-subpackages
14515 subpack-alist (1+ indent) (1- indent))))
14516 (when (memq 'display vhdl-speedbar-save-cache)
14517 (add-to-list 'vhdl-updated-project-list key))
14518 (vhdl-speedbar-update-current-unit t t))))
14519 ((string-match "-" text) ; contract architecture
14520 (speedbar-change-expand-button-char ?+)
14521 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14522 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14523 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14524 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14525 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14526 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14527 (speedbar-delete-subblock indent)
14528 (when (memq 'display vhdl-speedbar-save-cache)
14529 (add-to-list 'vhdl-updated-project-list key))))
14530 (t (error "Nothing to display")))
14531 (when (equal (selected-frame) speedbar-frame)
14532 (speedbar-center-buffer-smartly)))
14534 (defun vhdl-speedbar-expand-config (text token indent)
14535 "Expand/contract the configuration under the cursor."
14536 (cond
14537 ((string-match "+" text) ; expand configuration
14538 (let* ((key (vhdl-speedbar-line-key indent))
14539 (conf-alist (aget vhdl-config-alist key t))
14540 (conf-entry (aget conf-alist token))
14541 (ent-alist (aget vhdl-entity-alist key t))
14542 (hier-alist (vhdl-get-hierarchy
14543 ent-alist conf-alist (nth 3 conf-entry)
14544 (nth 4 conf-entry) token (nth 5 conf-entry)
14545 0 indent t))
14546 (subpack-alist (nth 6 conf-entry))
14547 entry)
14548 (if (not (or hier-alist subpack-alist))
14549 (speedbar-change-expand-button-char ??)
14550 (speedbar-change-expand-button-char ?-)
14551 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14552 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14553 (aput 'unit-alist token nil)
14554 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14555 (speedbar-with-writable
14556 (save-excursion
14557 (end-of-line) (forward-char 1)
14558 ;; insert instance hierarchy
14559 (when hier-alist
14560 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14561 (while hier-alist
14562 (setq entry (car hier-alist))
14563 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14564 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14565 (vhdl-speedbar-make-inst-line
14566 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14567 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14568 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14569 (setq hier-alist (cdr hier-alist)))
14570 ;; insert required packages
14571 (vhdl-speedbar-insert-subpackages
14572 subpack-alist (1+ indent) indent)))
14573 (when (memq 'display vhdl-speedbar-save-cache)
14574 (add-to-list 'vhdl-updated-project-list key))
14575 (vhdl-speedbar-update-current-unit t t))))
14576 ((string-match "-" text) ; contract configuration
14577 (speedbar-change-expand-button-char ?+)
14578 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14579 (let* ((key (vhdl-speedbar-line-key indent))
14580 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14581 (adelete 'unit-alist token)
14582 (if unit-alist
14583 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14584 (adelete 'vhdl-speedbar-shown-unit-alist key))
14585 (speedbar-delete-subblock indent)
14586 (when (memq 'display vhdl-speedbar-save-cache)
14587 (add-to-list 'vhdl-updated-project-list key))))
14588 (t (error "Nothing to display")))
14589 (when (equal (selected-frame) speedbar-frame)
14590 (speedbar-center-buffer-smartly)))
14592 (defun vhdl-speedbar-expand-package (text token indent)
14593 "Expand/contract the package under the cursor."
14594 (cond
14595 ((string-match "+" text) ; expand package
14596 (let* ((key (vhdl-speedbar-line-key indent))
14597 (pack-alist (aget vhdl-package-alist key t))
14598 (pack-entry (aget pack-alist token t))
14599 (comp-alist (nth 3 pack-entry))
14600 (func-alist (nth 4 pack-entry))
14601 (func-body-alist (nth 8 pack-entry))
14602 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14603 comp-entry func-entry func-body-entry)
14604 (if (not (or comp-alist func-alist subpack-alist))
14605 (speedbar-change-expand-button-char ??)
14606 (speedbar-change-expand-button-char ?-)
14607 ;; add package to `vhdl-speedbar-shown-unit-alist'
14608 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14609 (aput 'unit-alist token nil)
14610 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14611 (speedbar-with-writable
14612 (save-excursion
14613 (end-of-line) (forward-char 1)
14614 ;; insert components
14615 (when comp-alist
14616 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14617 (while comp-alist
14618 (setq comp-entry (car comp-alist))
14619 (speedbar-make-tag-line
14620 nil nil nil
14621 (cons token (nth 0 comp-entry))
14622 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14623 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14624 'vhdl-speedbar-entity-face (1+ indent))
14625 (setq comp-alist (cdr comp-alist)))
14626 ;; insert subprograms
14627 (when func-alist
14628 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14629 (while func-alist
14630 (setq func-entry (car func-alist)
14631 func-body-entry (aget func-body-alist (car func-entry) t))
14632 (when (nth 2 func-entry)
14633 (vhdl-speedbar-make-subprogram-line
14634 (nth 1 func-entry)
14635 (cons (nth 2 func-entry) (nth 3 func-entry))
14636 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14637 (1+ indent)))
14638 (setq func-alist (cdr func-alist)))
14639 ;; insert required packages
14640 (vhdl-speedbar-insert-subpackages
14641 subpack-alist (1+ indent) indent)))
14642 (when (memq 'display vhdl-speedbar-save-cache)
14643 (add-to-list 'vhdl-updated-project-list key))
14644 (vhdl-speedbar-update-current-unit t t))))
14645 ((string-match "-" text) ; contract package
14646 (speedbar-change-expand-button-char ?+)
14647 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14648 (let* ((key (vhdl-speedbar-line-key indent))
14649 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14650 (adelete 'unit-alist token)
14651 (if unit-alist
14652 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14653 (adelete 'vhdl-speedbar-shown-unit-alist key))
14654 (speedbar-delete-subblock indent)
14655 (when (memq 'display vhdl-speedbar-save-cache)
14656 (add-to-list 'vhdl-updated-project-list key))))
14657 (t (error "Nothing to display")))
14658 (when (equal (selected-frame) speedbar-frame)
14659 (speedbar-center-buffer-smartly)))
14661 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14662 "Insert required packages."
14663 (let* ((pack-alist (aget vhdl-package-alist
14664 (vhdl-speedbar-line-key dir-indent) t))
14665 pack-key lib-name pack-entry)
14666 (when subpack-alist
14667 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14668 (while subpack-alist
14669 (setq pack-key (cdar subpack-alist)
14670 lib-name (caar subpack-alist))
14671 (setq pack-entry (aget pack-alist pack-key t))
14672 (vhdl-speedbar-make-subpack-line
14673 (or (nth 0 pack-entry) pack-key) lib-name
14674 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14675 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14676 (setq subpack-alist (cdr subpack-alist)))))
14678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14679 ;; Display help functions
14681 (defvar vhdl-speedbar-update-current-unit t
14682 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14684 (defun vhdl-speedbar-update-current-project ()
14685 "Highlight project that is currently active."
14686 (when (and vhdl-speedbar-show-projects
14687 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14688 (and (boundp 'speedbar-frame)
14689 (frame-live-p speedbar-frame)))
14690 (let ((last-frame (selected-frame))
14691 (project-alist vhdl-project-alist)
14692 pos)
14693 (select-frame speedbar-frame)
14694 (speedbar-with-writable
14695 (save-excursion
14696 (while project-alist
14697 (goto-char (point-min))
14698 (when (re-search-forward
14699 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14700 (put-text-property (match-beginning 1) (match-end 1) 'face
14701 (if (equal (caar project-alist) vhdl-project)
14702 'speedbar-selected-face
14703 'speedbar-directory-face))
14704 (when (equal (caar project-alist) vhdl-project)
14705 (setq pos (1- (match-beginning 1)))))
14706 (setq project-alist (cdr project-alist))))
14707 (when pos (goto-char pos)))
14708 (select-frame last-frame)
14709 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14712 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14713 "Highlight all design units that are contained in the current file.
14714 NO-POSITION non-nil means do not re-position cursor."
14715 (let ((last-frame (selected-frame))
14716 (project-list vhdl-speedbar-shown-project-list)
14717 file-alist pos file-name)
14718 ;; get current file name
14719 (if (fboundp 'speedbar-select-attached-frame)
14720 (speedbar-select-attached-frame)
14721 (select-frame speedbar-attached-frame))
14722 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14723 (when (and vhdl-speedbar-update-current-unit
14724 (or always (not (equal file-name speedbar-last-selected-file))))
14725 (if vhdl-speedbar-show-projects
14726 (while project-list
14727 (setq file-alist (append file-alist (aget vhdl-file-alist
14728 (car project-list) t)))
14729 (setq project-list (cdr project-list)))
14730 (setq file-alist (aget vhdl-file-alist
14731 (abbreviate-file-name default-directory) t)))
14732 (select-frame speedbar-frame)
14733 (set-buffer speedbar-buffer)
14734 (speedbar-with-writable
14735 (vhdl-prepare-search-1
14736 (save-excursion
14737 ;; unhighlight last units
14738 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14739 (vhdl-speedbar-update-units
14740 "\\[.\\] " (nth 0 file-entry)
14741 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14742 (vhdl-speedbar-update-units
14743 "{.} " (nth 1 file-entry)
14744 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14745 (vhdl-speedbar-update-units
14746 "\\[.\\] " (nth 3 file-entry)
14747 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14748 (vhdl-speedbar-update-units
14749 "[]>] " (nth 4 file-entry)
14750 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14751 (vhdl-speedbar-update-units
14752 "\\[.\\].+(" '("body")
14753 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14754 (vhdl-speedbar-update-units
14755 "> " (nth 6 file-entry)
14756 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14757 ;; highlight current units
14758 (let* ((file-entry (aget file-alist file-name t)))
14759 (setq
14760 pos (vhdl-speedbar-update-units
14761 "\\[.\\] " (nth 0 file-entry)
14762 file-name 'vhdl-speedbar-entity-selected-face pos)
14763 pos (vhdl-speedbar-update-units
14764 "{.} " (nth 1 file-entry)
14765 file-name 'vhdl-speedbar-architecture-selected-face pos)
14766 pos (vhdl-speedbar-update-units
14767 "\\[.\\] " (nth 3 file-entry)
14768 file-name 'vhdl-speedbar-configuration-selected-face pos)
14769 pos (vhdl-speedbar-update-units
14770 "[]>] " (nth 4 file-entry)
14771 file-name 'vhdl-speedbar-package-selected-face pos)
14772 pos (vhdl-speedbar-update-units
14773 "\\[.\\].+(" '("body")
14774 file-name 'vhdl-speedbar-package-selected-face pos)
14775 pos (vhdl-speedbar-update-units
14776 "> " (nth 6 file-entry)
14777 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14778 ;; move speedbar so the first highlighted unit is visible
14779 (when (and pos (not no-position))
14780 (goto-char pos)
14781 (speedbar-center-buffer-smartly)
14782 (speedbar-position-cursor-on-line))
14783 (setq speedbar-last-selected-file file-name))
14784 (select-frame last-frame)
14787 (defun vhdl-speedbar-update-units (text unit-list file-name face
14788 &optional pos)
14789 "Help function to highlight design units."
14790 (while unit-list
14791 (goto-char (point-min))
14792 (while (re-search-forward
14793 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14794 (when (equal file-name (car (get-text-property
14795 (match-beginning 1) 'speedbar-token)))
14796 (setq pos (or pos (point-marker)))
14797 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14798 (setq unit-list (cdr unit-list)))
14799 pos)
14801 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14802 ent-name ent-file-marker
14803 arch-name arch-file-marker
14804 conf-name conf-file-marker
14805 lib-name depth offset delimiter)
14806 "Insert instantiation entry."
14807 (let ((start (point))
14808 visible-start)
14809 (insert (int-to-string depth) ":")
14810 (put-text-property start (point) 'invisible t)
14811 (setq visible-start (point))
14812 (insert-char ? (* depth speedbar-indentation-width))
14813 (while (> offset 0)
14814 (insert "|")
14815 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14816 (setq offset (1- offset)))
14817 (put-text-property visible-start (point) 'invisible nil)
14818 (setq start (point))
14819 (insert ">")
14820 (speedbar-make-button start (point) nil nil nil)
14821 (setq visible-start (point))
14822 (insert " ")
14823 (setq start (point))
14824 (if (not inst-name)
14825 (insert "(top)")
14826 (insert inst-name)
14827 (speedbar-make-button
14828 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14829 'vhdl-speedbar-find-file inst-file-marker))
14830 (insert delimiter)
14831 (when ent-name
14832 (setq start (point))
14833 (insert ent-name)
14834 (speedbar-make-button
14835 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14836 'vhdl-speedbar-find-file ent-file-marker)
14837 (when arch-name
14838 (insert " (")
14839 (setq start (point))
14840 (insert arch-name)
14841 (speedbar-make-button
14842 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14843 'vhdl-speedbar-find-file arch-file-marker)
14844 (insert ")"))
14845 (when conf-name
14846 (insert " (")
14847 (setq start (point))
14848 (insert conf-name)
14849 (speedbar-make-button
14850 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14851 'vhdl-speedbar-find-file conf-file-marker)
14852 (insert ")")))
14853 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14854 (setq start (point))
14855 (insert " (" lib-name ")")
14856 (put-text-property (+ 2 start) (1- (point)) 'face
14857 'vhdl-speedbar-library-face))
14858 (insert-char ?\n 1)
14859 (put-text-property visible-start (point) 'invisible nil)))
14861 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14862 body-file-marker depth)
14863 "Insert package entry."
14864 (let ((start (point))
14865 visible-start)
14866 (insert (int-to-string depth) ":")
14867 (put-text-property start (point) 'invisible t)
14868 (setq visible-start (point))
14869 (insert-char ? (* depth speedbar-indentation-width))
14870 (put-text-property visible-start (point) 'invisible nil)
14871 (setq start (point))
14872 (insert "[+]")
14873 (speedbar-make-button
14874 start (point) 'speedbar-button-face 'speedbar-highlight-face
14875 'vhdl-speedbar-expand-package pack-key)
14876 (setq visible-start (point))
14877 (insert-char ? 1 nil)
14878 (setq start (point))
14879 (insert pack-name)
14880 (speedbar-make-button
14881 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14882 'vhdl-speedbar-find-file pack-file-marker)
14883 (unless (car pack-file-marker)
14884 (insert "!"))
14885 (when (car body-file-marker)
14886 (insert " (")
14887 (setq start (point))
14888 (insert "body")
14889 (speedbar-make-button
14890 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14891 'vhdl-speedbar-find-file body-file-marker)
14892 (insert ")"))
14893 (insert-char ?\n 1)
14894 (put-text-property visible-start (point) 'invisible nil)))
14896 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14897 pack-body-file-marker depth)
14898 "Insert used package entry."
14899 (let ((start (point))
14900 visible-start)
14901 (insert (int-to-string depth) ":")
14902 (put-text-property start (point) 'invisible t)
14903 (setq visible-start (point))
14904 (insert-char ? (* depth speedbar-indentation-width))
14905 (put-text-property visible-start (point) 'invisible nil)
14906 (setq start (point))
14907 (insert ">")
14908 (speedbar-make-button start (point) nil nil nil)
14909 (setq visible-start (point))
14910 (insert " ")
14911 (setq start (point))
14912 (insert pack-name)
14913 (speedbar-make-button
14914 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14915 'vhdl-speedbar-find-file pack-file-marker)
14916 (when (car pack-body-file-marker)
14917 (insert " (")
14918 (setq start (point))
14919 (insert "body")
14920 (speedbar-make-button
14921 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14922 'vhdl-speedbar-find-file pack-body-file-marker)
14923 (insert ")"))
14924 (setq start (point))
14925 (insert " (" lib-name ")")
14926 (put-text-property (+ 2 start) (1- (point)) 'face
14927 'vhdl-speedbar-library-face)
14928 (insert-char ?\n 1)
14929 (put-text-property visible-start (point) 'invisible nil)))
14931 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14932 func-body-file-marker
14933 depth)
14934 "Insert subprogram entry."
14935 (let ((start (point))
14936 visible-start)
14937 (insert (int-to-string depth) ":")
14938 (put-text-property start (point) 'invisible t)
14939 (setq visible-start (point))
14940 (insert-char ? (* depth speedbar-indentation-width))
14941 (put-text-property visible-start (point) 'invisible nil)
14942 (setq start (point))
14943 (insert ">")
14944 (speedbar-make-button start (point) nil nil nil)
14945 (setq visible-start (point))
14946 (insert " ")
14947 (setq start (point))
14948 (insert func-name)
14949 (speedbar-make-button
14950 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14951 'vhdl-speedbar-find-file func-file-marker)
14952 (when (car func-body-file-marker)
14953 (insert " (")
14954 (setq start (point))
14955 (insert "body")
14956 (speedbar-make-button
14957 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14958 'vhdl-speedbar-find-file func-body-file-marker)
14959 (insert ")"))
14960 (insert-char ?\n 1)
14961 (put-text-property visible-start (point) 'invisible nil)))
14963 (defun vhdl-speedbar-make-title-line (text &optional depth)
14964 "Insert design unit title entry."
14965 (let ((start (point))
14966 visible-start)
14967 (when depth
14968 (insert (int-to-string depth) ":")
14969 (put-text-property start (point) 'invisible t))
14970 (setq visible-start (point))
14971 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14972 (setq start (point))
14973 (insert text)
14974 (speedbar-make-button start (point) nil nil nil nil)
14975 (insert-char ?\n 1)
14976 (put-text-property visible-start (point) 'invisible nil)))
14978 (defun vhdl-speedbar-insert-dirs (files level)
14979 "Insert subdirectories."
14980 (let ((dirs (car files)))
14981 (while dirs
14982 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14983 (car dirs) 'speedbar-dir-follow nil
14984 'speedbar-directory-face level)
14985 (setq dirs (cdr dirs)))))
14987 (defun vhdl-speedbar-dired (text token indent)
14988 "Speedbar click handler for directory expand button in hierarchy mode."
14989 (cond ((string-match "+" text) ; we have to expand this dir
14990 (setq speedbar-shown-directories
14991 (cons (expand-file-name
14992 (concat (speedbar-line-directory indent) token "/"))
14993 speedbar-shown-directories))
14994 (speedbar-change-expand-button-char ?-)
14995 (speedbar-reset-scanners)
14996 (speedbar-with-writable
14997 (save-excursion
14998 (end-of-line) (forward-char 1)
14999 (vhdl-speedbar-insert-dirs
15000 (speedbar-file-lists
15001 (concat (speedbar-line-directory indent) token "/"))
15002 (1+ indent))
15003 (speedbar-reset-scanners)
15004 (vhdl-speedbar-insert-dir-hierarchy
15005 (abbreviate-file-name
15006 (concat (speedbar-line-directory indent) token "/"))
15007 (1+ indent) speedbar-power-click)))
15008 (vhdl-speedbar-update-current-unit t t))
15009 ((string-match "-" text) ; we have to contract this node
15010 (speedbar-reset-scanners)
15011 (let ((oldl speedbar-shown-directories)
15012 (newl nil)
15013 (td (expand-file-name
15014 (concat (speedbar-line-directory indent) token))))
15015 (while oldl
15016 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15017 (setq newl (cons (car oldl) newl)))
15018 (setq oldl (cdr oldl)))
15019 (setq speedbar-shown-directories (nreverse newl)))
15020 (speedbar-change-expand-button-char ?+)
15021 (speedbar-delete-subblock indent))
15022 (t (error "Nothing to display")))
15023 (when (equal (selected-frame) speedbar-frame)
15024 (speedbar-center-buffer-smartly)))
15026 (defun vhdl-speedbar-item-info ()
15027 "Derive and display information about this line item."
15028 (save-excursion
15029 (beginning-of-line)
15030 ;; skip invisible number info
15031 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15032 (cond
15033 ;; project/directory entry
15034 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15035 (if vhdl-speedbar-show-projects
15036 (message "Project \"%s\"" (match-string-no-properties 1))
15037 (speedbar-files-item-info)))
15038 ;; design unit entry
15039 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15040 (goto-char (match-end 1))
15041 (let ((face (get-text-property (point) 'face)))
15042 (message
15043 "%s \"%s\" in \"%s\""
15044 ;; design unit kind
15045 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15046 (eq face 'vhdl-speedbar-entity-selected-face))
15047 (if (equal (match-string 2) ">") "Component" "Entity"))
15048 ((or (eq face 'vhdl-speedbar-architecture-face)
15049 (eq face 'vhdl-speedbar-architecture-selected-face))
15050 "Architecture")
15051 ((or (eq face 'vhdl-speedbar-configuration-face)
15052 (eq face 'vhdl-speedbar-configuration-selected-face))
15053 "Configuration")
15054 ((or (eq face 'vhdl-speedbar-package-face)
15055 (eq face 'vhdl-speedbar-package-selected-face))
15056 "Package")
15057 ((or (eq face 'vhdl-speedbar-instantiation-face)
15058 (eq face 'vhdl-speedbar-instantiation-selected-face))
15059 "Instantiation")
15060 ((eq face 'vhdl-speedbar-subprogram-face)
15061 "Subprogram")
15062 (t ""))
15063 ;; design unit name
15064 (buffer-substring-no-properties
15065 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15066 (match-end 1))
15067 ;; file name
15068 (file-relative-name
15069 (or (car (get-text-property (point) 'speedbar-token))
15070 "?")
15071 (vhdl-default-directory)))))
15072 (t (message "")))))
15074 (defun vhdl-speedbar-line-text ()
15075 "Calls `speedbar-line-text' and removes text properties."
15076 (let ((string (speedbar-line-text)))
15077 (set-text-properties 0 (length string) nil string)
15078 string))
15080 (defun vhdl-speedbar-higher-text ()
15081 "Get speedbar-line-text of higher level."
15082 (let (depth string)
15083 (save-excursion
15084 (beginning-of-line)
15085 (looking-at "^\\([0-9]+\\):")
15086 (setq depth (string-to-number (match-string 1)))
15087 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15088 (setq string (match-string 1))
15089 (set-text-properties 0 (length string) nil string)
15090 string))))
15092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15093 ;; Help functions
15095 (defun vhdl-speedbar-line-key (&optional indent)
15096 "Get currently displayed directory of project name."
15097 (if vhdl-speedbar-show-projects
15098 (vhdl-speedbar-line-project)
15099 (abbreviate-file-name
15100 (file-name-as-directory (speedbar-line-directory indent)))))
15102 (defun vhdl-speedbar-line-project (&optional indent)
15103 "Get currently displayed project name."
15104 (and vhdl-speedbar-show-projects
15105 (save-excursion
15106 (end-of-line)
15107 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15108 (match-string-no-properties 1))))
15110 (defun vhdl-add-modified-file ()
15111 "Add file to `vhdl-modified-file-list'."
15112 (when vhdl-file-alist
15113 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15114 nil)
15116 (defun vhdl-resolve-paths (path-list)
15117 "Resolve path wildcards in PATH-LIST."
15118 (let (path-list-1 path-list-2 path-beg path-end dir)
15119 ;; eliminate non-existent directories
15120 (while path-list
15121 (setq dir (car path-list))
15122 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15123 (if (file-directory-p (match-string 2 dir))
15124 (setq path-list-1 (cons dir path-list-1))
15125 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15126 (setq path-list (cdr path-list)))
15127 ;; resolve path wildcards
15128 (while path-list-1
15129 (setq dir (car path-list-1))
15130 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15131 (progn
15132 (setq path-beg (match-string 1 dir)
15133 path-end (match-string 5 dir))
15134 (setq path-list-1
15135 (append
15136 (mapcar
15137 (function
15138 (lambda (var) (concat path-beg var path-end)))
15139 (let ((all-list (vhdl-directory-files
15140 (match-string 2 dir) t
15141 (concat "\\<" (wildcard-to-regexp
15142 (match-string 4 dir)))))
15143 dir-list)
15144 (while all-list
15145 (when (file-directory-p (car all-list))
15146 (setq dir-list (cons (car all-list) dir-list)))
15147 (setq all-list (cdr all-list)))
15148 dir-list))
15149 (cdr path-list-1))))
15150 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15151 (when (file-directory-p (match-string 2 dir))
15152 (setq path-list-2 (cons dir path-list-2)))
15153 (setq path-list-1 (cdr path-list-1))))
15154 (nreverse path-list-2)))
15156 (defun vhdl-speedbar-goto-this-unit (directory unit)
15157 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15158 (let ((dest (point)))
15159 (if (and (if vhdl-speedbar-show-projects
15160 (progn (goto-char (point-min)) t)
15161 (speedbar-goto-this-file directory))
15162 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15163 (progn (speedbar-position-cursor-on-line)
15165 (goto-char dest)
15166 nil)))
15168 (defun vhdl-speedbar-find-file (text token indent)
15169 "When user clicks on TEXT, load file with name and position in TOKEN.
15170 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15171 is already shown in a buffer."
15172 (if (not (car token))
15173 (error "ERROR: File cannot be found")
15174 (let ((buffer (get-file-buffer (car token))))
15175 (speedbar-find-file-in-frame (car token))
15176 (when (or vhdl-speedbar-jump-to-unit buffer)
15177 (goto-line (cdr token))
15178 (recenter))
15179 (vhdl-speedbar-update-current-unit t t)
15180 (speedbar-set-timer dframe-update-speed)
15181 (speedbar-maybee-jump-to-attached-frame))))
15183 (defun vhdl-speedbar-port-copy ()
15184 "Copy the port of the entity/component or subprogram under the cursor."
15185 (interactive)
15186 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15187 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15188 (error "ERROR: No entity/component or subprogram under cursor")
15189 (beginning-of-line)
15190 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15191 (condition-case info
15192 (let ((token (get-text-property
15193 (match-beginning 3) 'speedbar-token)))
15194 (vhdl-visit-file (car token) t
15195 (progn (goto-line (cdr token))
15196 (end-of-line)
15197 (if is-entity
15198 (vhdl-port-copy)
15199 (vhdl-subprog-copy)))))
15200 (error (error "ERROR: %s not scanned successfully\n (%s)"
15201 (if is-entity "Port" "Interface") (cadr info))))
15202 (error "ERROR: No entity/component or subprogram on current line")))))
15204 (defun vhdl-speedbar-place-component ()
15205 "Place the entity/component under the cursor as component."
15206 (interactive)
15207 (if (not (vhdl-speedbar-check-unit 'entity))
15208 (error "ERROR: No entity/component under cursor")
15209 (vhdl-speedbar-port-copy)
15210 (if (fboundp 'speedbar-select-attached-frame)
15211 (speedbar-select-attached-frame)
15212 (select-frame speedbar-attached-frame))
15213 (vhdl-compose-place-component)
15214 (select-frame speedbar-frame)))
15216 (defun vhdl-speedbar-configuration ()
15217 "Generate configuration for the architecture under the cursor."
15218 (interactive)
15219 (if (not (vhdl-speedbar-check-unit 'architecture))
15220 (error "ERROR: No architecture under cursor")
15221 (let ((arch-name (vhdl-speedbar-line-text))
15222 (ent-name (vhdl-speedbar-higher-text)))
15223 (if (fboundp 'speedbar-select-attached-frame)
15224 (speedbar-select-attached-frame)
15225 (select-frame speedbar-attached-frame))
15226 (vhdl-compose-configuration ent-name arch-name))))
15228 (defun vhdl-speedbar-select-mra ()
15229 "Select the architecture under the cursor as MRA."
15230 (interactive)
15231 (if (not (vhdl-speedbar-check-unit 'architecture))
15232 (error "ERROR: No architecture under cursor")
15233 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15234 (ent-key (downcase (vhdl-speedbar-higher-text)))
15235 (ent-alist (aget vhdl-entity-alist
15236 (or (vhdl-project-p) default-directory) t))
15237 (ent-entry (aget ent-alist ent-key t)))
15238 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15239 (speedbar-refresh))))
15241 (defun vhdl-speedbar-make-design ()
15242 "Make (compile) design unit or directory/project under the cursor."
15243 (interactive)
15244 (if (not (save-excursion (beginning-of-line)
15245 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15246 (error "ERROR: No primary design unit or directory/project under cursor")
15247 (let ((is-unit (match-string 2))
15248 (unit-name (vhdl-speedbar-line-text))
15249 (vhdl-project (vhdl-speedbar-line-project))
15250 (directory (file-name-as-directory
15251 (or (speedbar-line-file) (speedbar-line-directory)))))
15252 (if (fboundp 'speedbar-select-attached-frame)
15253 (speedbar-select-attached-frame)
15254 (select-frame speedbar-attached-frame))
15255 (let ((default-directory directory))
15256 (vhdl-make (and is-unit unit-name))))))
15258 (defun vhdl-speedbar-generate-makefile ()
15259 "Generate Makefile for directory/project under the cursor."
15260 (interactive)
15261 (let ((vhdl-project (vhdl-speedbar-line-project))
15262 (default-directory (file-name-as-directory
15263 (or (speedbar-line-file) (speedbar-line-directory)))))
15264 (vhdl-generate-makefile)))
15266 (defun vhdl-speedbar-check-unit (design-unit)
15267 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15268 expansion function)."
15269 (save-excursion
15270 (speedbar-position-cursor-on-line)
15271 (cond ((eq design-unit 'entity)
15272 (memq (get-text-property (match-end 0) 'face)
15273 '(vhdl-speedbar-entity-face
15274 vhdl-speedbar-entity-selected-face)))
15275 ((eq design-unit 'architecture)
15276 (memq (get-text-property (match-end 0) 'face)
15277 '(vhdl-speedbar-architecture-face
15278 vhdl-speedbar-architecture-selected-face)))
15279 ((eq design-unit 'subprogram)
15280 (eq (get-text-property (match-end 0) 'face)
15281 'vhdl-speedbar-subprogram-face))
15282 (t nil))))
15284 (defun vhdl-speedbar-set-depth (depth)
15285 "Set hierarchy display depth to DEPTH and refresh speedbar."
15286 (setq vhdl-speedbar-hierarchy-depth depth)
15287 (speedbar-refresh))
15289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15290 ;; Fontification
15292 (defface vhdl-speedbar-entity-face
15293 '((((class color) (background light)) (:foreground "ForestGreen"))
15294 (((class color) (background dark)) (:foreground "PaleGreen")))
15295 "Face used for displaying entity names."
15296 :group 'speedbar-faces)
15298 (defface vhdl-speedbar-architecture-face
15299 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15300 (((class color) (background light)) (:foreground "Blue"))
15302 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15303 "Face used for displaying architecture names."
15304 :group 'speedbar-faces)
15306 (defface vhdl-speedbar-configuration-face
15307 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15308 (((class color) (background dark)) (:foreground "Salmon")))
15309 "Face used for displaying configuration names."
15310 :group 'speedbar-faces)
15312 (defface vhdl-speedbar-package-face
15313 '((((class color) (background light)) (:foreground "Grey50"))
15314 (((class color) (background dark)) (:foreground "Grey80")))
15315 "Face used for displaying package names."
15316 :group 'speedbar-faces)
15318 (defface vhdl-speedbar-library-face
15319 '((((class color) (background light)) (:foreground "Purple"))
15320 (((class color) (background dark)) (:foreground "Orchid1")))
15321 "Face used for displaying library names."
15322 :group 'speedbar-faces)
15324 (defface vhdl-speedbar-instantiation-face
15325 '((((class color) (background light)) (:foreground "Brown"))
15326 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15327 (((class color) (background dark)) (:foreground "Yellow")))
15328 "Face used for displaying instantiation names."
15329 :group 'speedbar-faces)
15331 (defface vhdl-speedbar-subprogram-face
15332 '((((class color) (background light)) (:foreground "Orchid4"))
15333 (((class color) (background dark)) (:foreground "BurlyWood2")))
15334 "Face used for displaying subprogram names."
15335 :group 'speedbar-faces)
15337 (defface vhdl-speedbar-entity-selected-face
15338 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15339 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15340 "Face used for displaying entity names."
15341 :group 'speedbar-faces)
15343 (defface vhdl-speedbar-architecture-selected-face
15344 '((((min-colors 88) (class color) (background light)) (:foreground
15345 "Blue1" :underline t))
15346 (((class color) (background light)) (:foreground "Blue" :underline t))
15347 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15348 "Face used for displaying architecture names."
15349 :group 'speedbar-faces)
15351 (defface vhdl-speedbar-configuration-selected-face
15352 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15353 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15354 "Face used for displaying configuration names."
15355 :group 'speedbar-faces)
15357 (defface vhdl-speedbar-package-selected-face
15358 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15359 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15360 "Face used for displaying package names."
15361 :group 'speedbar-faces)
15363 (defface vhdl-speedbar-instantiation-selected-face
15364 '((((class color) (background light)) (:foreground "Brown" :underline t))
15365 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15366 "Face used for displaying instantiation names."
15367 :group 'speedbar-faces)
15369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15370 ;; Initialization
15372 ;; add speedbar
15373 (when (fboundp 'speedbar)
15374 (condition-case ()
15375 (when (and vhdl-speedbar-auto-open
15376 (not (and (boundp 'speedbar-frame)
15377 (frame-live-p speedbar-frame))))
15378 (speedbar-frame-mode 1)
15379 (if (fboundp 'speedbar-select-attached-frame)
15380 (speedbar-select-attached-frame)
15381 (select-frame speedbar-attached-frame)))
15382 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15384 ;; initialize speedbar
15385 (if (not (boundp 'speedbar-frame))
15386 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15387 (vhdl-speedbar-initialize)
15388 (when speedbar-frame (vhdl-speedbar-refresh)))
15391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15392 ;;; Structural composition
15393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15395 (defun vhdl-get-components-package-name ()
15396 "Return the name of the components package."
15397 (let ((project (vhdl-project-p)))
15398 (if project
15399 (vhdl-replace-string (car vhdl-components-package-name)
15400 (subst-char-in-string ? ?_ project))
15401 (cdr vhdl-components-package-name))))
15403 (defun vhdl-compose-new-component ()
15404 "Create entity and architecture for new component."
15405 (interactive)
15406 (let* ((case-fold-search t)
15407 (ent-name (read-from-minibuffer "entity name: "
15408 nil vhdl-minibuffer-local-map))
15409 (arch-name
15410 (if (equal (cdr vhdl-compose-architecture-name) "")
15411 (read-from-minibuffer "architecture name: "
15412 nil vhdl-minibuffer-local-map)
15413 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15414 ent-file-name arch-file-name ent-buffer arch-buffer project)
15415 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15416 ;; open entity file
15417 (unless (eq vhdl-compose-create-files 'none)
15418 (setq ent-file-name
15419 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15420 "." (file-name-extension (buffer-file-name))))
15421 (when (and (file-exists-p ent-file-name)
15422 (not (y-or-n-p (concat "File \"" ent-file-name
15423 "\" exists; overwrite? "))))
15424 (error "ERROR: Creating component...aborted"))
15425 (find-file ent-file-name)
15426 (erase-buffer)
15427 (set-buffer-modified-p nil))
15428 ;; insert header
15429 (if vhdl-compose-include-header
15430 (progn (vhdl-template-header)
15431 (goto-char (point-max)))
15432 (vhdl-comment-display-line) (insert "\n\n"))
15433 ;; insert library clause
15434 (vhdl-template-package-std-logic-1164)
15435 (when vhdl-use-components-package
15436 (insert "\n")
15437 (vhdl-template-standard-package (vhdl-work-library)
15438 (vhdl-get-components-package-name)))
15439 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15440 ;; insert entity declaration
15441 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15442 (vhdl-insert-keyword " IS\n")
15443 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15444 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15445 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15446 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15447 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15448 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15449 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15450 (vhdl-insert-keyword "END ")
15451 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15452 (insert ent-name ";\n\n")
15453 (vhdl-comment-display-line) (insert "\n")
15454 ;; open architecture file
15455 (if (not (eq vhdl-compose-create-files 'separate))
15456 (insert "\n")
15457 (setq ent-buffer (current-buffer))
15458 (setq arch-file-name
15459 (concat (vhdl-replace-string vhdl-architecture-file-name
15460 (concat ent-name " " arch-name) t)
15461 "." (file-name-extension (buffer-file-name))))
15462 (when (and (file-exists-p arch-file-name)
15463 (not (y-or-n-p (concat "File \"" arch-file-name
15464 "\" exists; overwrite? "))))
15465 (error "ERROR: Creating component...aborted"))
15466 (find-file arch-file-name)
15467 (erase-buffer)
15468 (set-buffer-modified-p nil)
15469 ;; insert header
15470 (if vhdl-compose-include-header
15471 (progn (vhdl-template-header)
15472 (goto-char (point-max)))
15473 (vhdl-comment-display-line) (insert "\n\n")))
15474 ;; insert architecture body
15475 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15476 (vhdl-insert-keyword " OF ") (insert ent-name)
15477 (vhdl-insert-keyword " IS\n\n")
15478 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15479 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15480 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15481 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15482 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15483 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15484 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15485 (vhdl-insert-keyword "BEGIN")
15486 (when vhdl-self-insert-comments
15487 (insert " -- ")
15488 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15489 (insert arch-name))
15490 (insert "\n\n")
15491 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15492 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15493 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15494 (vhdl-insert-keyword "END ")
15495 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15496 (insert arch-name ";\n\n")
15497 ;; insert footer and save
15498 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15499 (vhdl-template-footer)
15500 (vhdl-comment-display-line) (insert "\n"))
15501 (goto-char (point-min))
15502 (setq arch-buffer (current-buffer))
15503 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15504 (set-buffer arch-buffer) (save-buffer)
15505 (message "%s"
15506 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15507 (and ent-file-name
15508 (format "\n File created: \"%s\"" ent-file-name))
15509 (and arch-file-name
15510 (format "\n File created: \"%s\"" arch-file-name))))))
15512 (defun vhdl-compose-place-component ()
15513 "Place new component by pasting current port as component declaration and
15514 component instantiation."
15515 (interactive)
15516 (if (not vhdl-port-list)
15517 (error "ERROR: No port has been read")
15518 (save-excursion
15519 (vhdl-prepare-search-2
15520 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15521 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15522 (error "ERROR: No architecture found"))
15523 (let* ((ent-name (match-string 1))
15524 (ent-file-name
15525 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15526 "." (file-name-extension (buffer-file-name))))
15527 (orig-buffer (current-buffer)))
15528 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15529 ;; place component declaration
15530 (unless (or vhdl-use-components-package
15531 (vhdl-use-direct-instantiation)
15532 (save-excursion
15533 (re-search-forward
15534 (concat "^\\s-*component\\s-+"
15535 (car vhdl-port-list) "\\>") nil t)))
15536 (re-search-forward "^begin\\>" nil)
15537 (beginning-of-line)
15538 (skip-chars-backward " \t\n")
15539 (insert "\n\n") (indent-to vhdl-basic-offset)
15540 (vhdl-port-paste-component t))
15541 ;; place component instantiation
15542 (re-search-forward "^end\\>" nil)
15543 (beginning-of-line)
15544 (skip-chars-backward " \t\n")
15545 (insert "\n\n") (indent-to vhdl-basic-offset)
15546 (vhdl-port-paste-instance nil t t)
15547 ;; place use clause for used packages
15548 (when (nth 3 vhdl-port-list)
15549 ;; open entity file
15550 (when (file-exists-p ent-file-name)
15551 (find-file ent-file-name))
15552 (goto-char (point-min))
15553 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15554 (error "ERROR: Entity not found: \"%s\"" ent-name))
15555 (goto-char (match-beginning 0))
15556 (if (and (save-excursion
15557 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15558 (match-string 1))
15559 (progn (goto-char (match-end 0))
15560 (beginning-of-line 2))
15561 (insert "\n")
15562 (backward-char))
15563 (vhdl-port-paste-context-clause)
15564 (switch-to-buffer orig-buffer))
15565 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15567 (defun vhdl-compose-wire-components ()
15568 "Connect components."
15569 (interactive)
15570 (save-excursion
15571 (vhdl-prepare-search-2
15572 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15573 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15574 (error "ERROR: No architecture found"))
15575 (let* ((ent-name (match-string 1))
15576 (ent-file-name
15577 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15578 "." (file-name-extension (buffer-file-name))))
15579 (arch-decl-pos (point-marker))
15580 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15581 (arch-end-pos (re-search-forward "^end\\>" nil))
15582 (pack-name (vhdl-get-components-package-name))
15583 (pack-file-name
15584 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15585 "." (file-name-extension (buffer-file-name))))
15586 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15587 port-alist generic-alist inst-alist
15588 signal-name signal-entry signal-alist local-list written-list
15589 single-in-list multi-in-list single-out-list multi-out-list
15590 constant-name constant-entry constant-alist single-list multi-list
15591 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15592 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15593 signal-beg-pos signal-pos
15594 constant-temp-pos port-temp-pos signal-temp-pos)
15595 (message "Wiring components...")
15596 ;; process all instances
15597 (goto-char arch-stat-pos)
15598 (while (re-search-forward
15599 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15600 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15601 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15602 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15603 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15604 (setq inst-name (match-string-no-properties 1)
15605 comp-name (match-string-no-properties 4)
15606 comp-ent-name (match-string-no-properties 12)
15607 has-generic (or (match-string 7) (match-string 17)))
15608 ;; get port ...
15609 (if comp-name
15610 ;; ... from component declaration
15611 (vhdl-visit-file
15612 (when vhdl-use-components-package pack-file-name) t
15613 (save-excursion
15614 (goto-char (point-min))
15615 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15616 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15617 (vhdl-port-copy)))
15618 ;; ... from entity declaration (direct instantiation)
15619 (setq comp-ent-file-name
15620 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15621 "." (file-name-extension (buffer-file-name))))
15622 (vhdl-visit-file
15623 comp-ent-file-name t
15624 (save-excursion
15625 (goto-char (point-min))
15626 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15627 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15628 (vhdl-port-copy))))
15629 (vhdl-port-flatten t)
15630 (setq generic-alist (nth 1 vhdl-port-list)
15631 port-alist (nth 2 vhdl-port-list)
15632 vhdl-port-list nil)
15633 (setq constant-alist nil
15634 signal-alist nil)
15635 (when has-generic
15636 ;; process all constants in generic map
15637 (vhdl-forward-syntactic-ws)
15638 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15639 (setq constant-name (match-string-no-properties 3))
15640 (setq constant-entry
15641 (cons constant-name
15642 (if (match-string 1)
15643 (or (aget generic-alist (match-string 2) t)
15644 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15645 (cdar generic-alist))))
15646 (setq constant-alist (cons constant-entry constant-alist))
15647 (setq constant-name (downcase constant-name))
15648 (if (or (member constant-name single-list)
15649 (member constant-name multi-list))
15650 (progn (setq single-list (delete constant-name single-list))
15651 (add-to-list 'multi-list constant-name))
15652 (add-to-list 'single-list constant-name))
15653 (unless (match-string 1)
15654 (setq generic-alist (cdr generic-alist)))
15655 (vhdl-forward-syntactic-ws))
15656 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15657 ;; process all signals in port map
15658 (vhdl-forward-syntactic-ws)
15659 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15660 (setq signal-name (match-string-no-properties 3))
15661 (setq signal-entry (cons signal-name
15662 (if (match-string 1)
15663 (or (aget port-alist (match-string 2) t)
15664 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15665 (cdar port-alist))))
15666 (setq signal-alist (cons signal-entry signal-alist))
15667 (setq signal-name (downcase signal-name))
15668 (if (equal (upcase (nth 2 signal-entry)) "IN")
15669 ;; input signal
15670 (cond
15671 ((member signal-name local-list)
15672 nil)
15673 ((or (member signal-name single-out-list)
15674 (member signal-name multi-out-list))
15675 (setq single-out-list (delete signal-name single-out-list))
15676 (setq multi-out-list (delete signal-name multi-out-list))
15677 (add-to-list 'local-list signal-name))
15678 ((member signal-name single-in-list)
15679 (setq single-in-list (delete signal-name single-in-list))
15680 (add-to-list 'multi-in-list signal-name))
15681 ((not (member signal-name multi-in-list))
15682 (add-to-list 'single-in-list signal-name)))
15683 ;; output signal
15684 (cond
15685 ((member signal-name local-list)
15686 nil)
15687 ((or (member signal-name single-in-list)
15688 (member signal-name multi-in-list))
15689 (setq single-in-list (delete signal-name single-in-list))
15690 (setq multi-in-list (delete signal-name multi-in-list))
15691 (add-to-list 'local-list signal-name))
15692 ((member signal-name single-out-list)
15693 (setq single-out-list (delete signal-name single-out-list))
15694 (add-to-list 'multi-out-list signal-name))
15695 ((not (member signal-name multi-out-list))
15696 (add-to-list 'single-out-list signal-name))))
15697 (unless (match-string 1)
15698 (setq port-alist (cdr port-alist)))
15699 (vhdl-forward-syntactic-ws))
15700 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15701 (nreverse signal-alist)) inst-alist)))
15702 ;; prepare signal insertion
15703 (vhdl-goto-marker arch-decl-pos)
15704 (forward-line 1)
15705 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15706 (setq signal-pos (point-marker))
15707 (while (progn (vhdl-forward-syntactic-ws)
15708 (looking-at "signal\\>"))
15709 (beginning-of-line 2)
15710 (delete-region signal-pos (point)))
15711 (setq signal-beg-pos signal-pos)
15712 ;; open entity file
15713 (when (file-exists-p ent-file-name)
15714 (find-file ent-file-name))
15715 (goto-char (point-min))
15716 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15717 (error "ERROR: Entity not found: \"%s\"" ent-name))
15718 ;; prepare generic clause insertion
15719 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15720 (match-string 1))
15721 (goto-char (match-beginning 0))
15722 (indent-to vhdl-basic-offset)
15723 (insert "generic ();\n\n")
15724 (backward-char 4))
15725 (backward-char)
15726 (setq generic-pos (point-marker))
15727 (forward-sexp) (end-of-line)
15728 (delete-region generic-pos (point)) (delete-char 1)
15729 (insert "(\n")
15730 (when multi-list
15731 (insert "\n")
15732 (indent-to (* 2 vhdl-basic-offset))
15733 (insert "-- global generics\n"))
15734 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15735 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15736 ;; prepare port clause insertion
15737 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15738 (match-string 1))
15739 (goto-char (match-beginning 0))
15740 (indent-to vhdl-basic-offset)
15741 (insert "port ();\n\n")
15742 (backward-char 4))
15743 (backward-char)
15744 (setq port-in-pos (point-marker))
15745 (forward-sexp) (end-of-line)
15746 (delete-region port-in-pos (point)) (delete-char 1)
15747 (insert "(\n")
15748 (when (or multi-in-list multi-out-list)
15749 (insert "\n")
15750 (indent-to (* 2 vhdl-basic-offset))
15751 (insert "-- global ports\n"))
15752 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15753 port-out-pos (point-marker) port-inst-pos (point-marker)
15754 port-end-pos (point-marker))
15755 ;; insert generics, ports and signals
15756 (setq inst-alist (nreverse inst-alist))
15757 (while inst-alist
15758 (setq inst-name (nth 0 (car inst-alist))
15759 constant-alist (nth 1 (car inst-alist))
15760 signal-alist (nth 2 (car inst-alist))
15761 constant-temp-pos generic-inst-pos
15762 port-temp-pos port-inst-pos
15763 signal-temp-pos signal-pos)
15764 ;; generics
15765 (while constant-alist
15766 (setq constant-name (downcase (caar constant-alist))
15767 constant-entry (car constant-alist))
15768 (cond ((member constant-name written-list)
15769 nil)
15770 ((member constant-name multi-list)
15771 (vhdl-goto-marker generic-pos)
15772 (setq generic-end-pos
15773 (vhdl-max-marker
15774 generic-end-pos
15775 (vhdl-compose-insert-generic constant-entry)))
15776 (setq generic-pos (point-marker))
15777 (add-to-list 'written-list constant-name))
15779 (vhdl-goto-marker
15780 (vhdl-max-marker generic-inst-pos generic-pos))
15781 (setq generic-end-pos
15782 (vhdl-compose-insert-generic constant-entry))
15783 (setq generic-inst-pos (point-marker))
15784 (add-to-list 'written-list constant-name)))
15785 (setq constant-alist (cdr constant-alist)))
15786 (when (/= constant-temp-pos generic-inst-pos)
15787 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15788 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15789 (insert "-- generics for \"" inst-name "\"\n")
15790 (vhdl-goto-marker generic-inst-pos))
15791 ;; ports and signals
15792 (while signal-alist
15793 (setq signal-name (downcase (caar signal-alist))
15794 signal-entry (car signal-alist))
15795 (cond ((member signal-name written-list)
15796 nil)
15797 ((member signal-name multi-in-list)
15798 (vhdl-goto-marker port-in-pos)
15799 (setq port-end-pos
15800 (vhdl-max-marker
15801 port-end-pos (vhdl-compose-insert-port signal-entry)))
15802 (setq port-in-pos (point-marker))
15803 (add-to-list 'written-list signal-name))
15804 ((member signal-name multi-out-list)
15805 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15806 (setq port-end-pos
15807 (vhdl-max-marker
15808 port-end-pos (vhdl-compose-insert-port signal-entry)))
15809 (setq port-out-pos (point-marker))
15810 (add-to-list 'written-list signal-name))
15811 ((or (member signal-name single-in-list)
15812 (member signal-name single-out-list))
15813 (vhdl-goto-marker
15814 (vhdl-max-marker
15815 port-inst-pos
15816 (vhdl-max-marker port-out-pos port-in-pos)))
15817 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15818 (setq port-inst-pos (point-marker))
15819 (add-to-list 'written-list signal-name))
15820 ((equal (upcase (nth 2 signal-entry)) "OUT")
15821 (vhdl-goto-marker signal-pos)
15822 (vhdl-compose-insert-signal signal-entry)
15823 (setq signal-pos (point-marker))
15824 (add-to-list 'written-list signal-name)))
15825 (setq signal-alist (cdr signal-alist)))
15826 (when (/= port-temp-pos port-inst-pos)
15827 (vhdl-goto-marker
15828 (vhdl-max-marker port-temp-pos
15829 (vhdl-max-marker port-in-pos port-out-pos)))
15830 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15831 (insert "-- ports to \"" inst-name "\"\n")
15832 (vhdl-goto-marker port-inst-pos))
15833 (when (/= signal-temp-pos signal-pos)
15834 (vhdl-goto-marker signal-temp-pos)
15835 (insert "\n") (indent-to vhdl-basic-offset)
15836 (insert "-- outputs of \"" inst-name "\"\n")
15837 (vhdl-goto-marker signal-pos))
15838 (setq inst-alist (cdr inst-alist)))
15839 ;; finalize generic/port clause
15840 (vhdl-goto-marker generic-end-pos) (backward-char)
15841 (when (= generic-beg-pos generic-end-pos)
15842 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15843 (insert ";") (backward-char))
15844 (insert ")")
15845 (vhdl-goto-marker port-end-pos) (backward-char)
15846 (when (= port-beg-pos port-end-pos)
15847 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15848 (insert ";") (backward-char))
15849 (insert ")")
15850 ;; align everything
15851 (when vhdl-auto-align
15852 (vhdl-goto-marker generic-beg-pos)
15853 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15854 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15855 (vhdl-goto-marker signal-beg-pos)
15856 (vhdl-align-region-groups signal-beg-pos signal-pos))
15857 (switch-to-buffer (marker-buffer signal-beg-pos))
15858 (message "Wiring components...done")))))
15860 (defun vhdl-compose-insert-generic (entry)
15861 "Insert ENTRY as generic declaration."
15862 (let (pos)
15863 (indent-to (* 2 vhdl-basic-offset))
15864 (insert (nth 0 entry) " : " (nth 1 entry))
15865 (when (nth 2 entry)
15866 (insert " := " (nth 2 entry)))
15867 (insert ";")
15868 (setq pos (point-marker))
15869 (when (and vhdl-include-port-comments (nth 3 entry))
15870 (vhdl-comment-insert-inline (nth 3 entry) t))
15871 (insert "\n")
15872 pos))
15874 (defun vhdl-compose-insert-port (entry)
15875 "Insert ENTRY as port declaration."
15876 (let (pos)
15877 (indent-to (* 2 vhdl-basic-offset))
15878 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15879 (setq pos (point-marker))
15880 (when (and vhdl-include-port-comments (nth 4 entry))
15881 (vhdl-comment-insert-inline (nth 4 entry) t))
15882 (insert "\n")
15883 pos))
15885 (defun vhdl-compose-insert-signal (entry)
15886 "Insert ENTRY as signal declaration."
15887 (indent-to vhdl-basic-offset)
15888 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15889 (when (and vhdl-include-port-comments (nth 4 entry))
15890 (vhdl-comment-insert-inline (nth 4 entry) t))
15891 (insert "\n"))
15893 (defun vhdl-compose-components-package ()
15894 "Generate a package containing component declarations for all entities in the
15895 current project/directory."
15896 (interactive)
15897 (vhdl-require-hierarchy-info)
15898 (let* ((project (vhdl-project-p))
15899 (pack-name (vhdl-get-components-package-name))
15900 (pack-file-name
15901 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15902 "." (file-name-extension (buffer-file-name))))
15903 (ent-alist (aget vhdl-entity-alist
15904 (or project default-directory) t))
15905 (lazy-lock-minimum-size 0)
15906 clause-pos component-pos)
15907 (message "Generating components package \"%s\"..." pack-name)
15908 ;; open package file
15909 (when (and (file-exists-p pack-file-name)
15910 (not (y-or-n-p (concat "File \"" pack-file-name
15911 "\" exists; overwrite? "))))
15912 (error "ERROR: Generating components package...aborted"))
15913 (find-file pack-file-name)
15914 (erase-buffer)
15915 ;; insert header
15916 (if vhdl-compose-include-header
15917 (progn (vhdl-template-header
15918 (concat "Components package (generated by Emacs VHDL Mode "
15919 vhdl-version ")"))
15920 (goto-char (point-max)))
15921 (vhdl-comment-display-line) (insert "\n\n"))
15922 ;; insert std_logic_1164 package
15923 (vhdl-template-package-std-logic-1164)
15924 (insert "\n") (setq clause-pos (point-marker))
15925 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15926 ;; insert package declaration
15927 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15928 (vhdl-insert-keyword " IS\n\n")
15929 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15930 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15931 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15932 (indent-to vhdl-basic-offset)
15933 (setq component-pos (point-marker))
15934 (insert "\n\n") (vhdl-insert-keyword "END ")
15935 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15936 (insert pack-name ";\n\n")
15937 ;; insert footer
15938 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15939 (vhdl-template-footer)
15940 (vhdl-comment-display-line) (insert "\n"))
15941 ;; insert component declarations
15942 (while ent-alist
15943 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15944 (progn (goto-line (nth 3 (car ent-alist)))
15945 (end-of-line)
15946 (vhdl-port-copy)))
15947 (goto-char component-pos)
15948 (vhdl-port-paste-component t)
15949 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15950 (setq component-pos (point-marker))
15951 (goto-char clause-pos)
15952 (vhdl-port-paste-context-clause pack-name)
15953 (setq clause-pos (point-marker))
15954 (setq ent-alist (cdr ent-alist)))
15955 (goto-char (point-min))
15956 (save-buffer)
15957 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15958 pack-name pack-file-name)))
15960 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15961 &optional insert-conf)
15962 "Generate block configuration for architecture."
15963 (let ((margin (current-indentation))
15964 (beg (save-excursion (beginning-of-line) (point)))
15965 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15966 ;; insert block configuration (for architecture)
15967 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15968 (setq margin (+ margin vhdl-basic-offset))
15969 ;; process all instances
15970 (while inst-alist
15971 (setq inst-entry (car inst-alist))
15972 ;; is component?
15973 (when (nth 4 inst-entry)
15974 (setq insert-conf t)
15975 (setq inst-path (nth 9 inst-entry))
15976 ;; skip common path with previous instance
15977 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15978 (setq inst-path (cdr inst-path)
15979 inst-prev-path (cdr inst-prev-path)))
15980 ;; insert block configuration end (for previous block/generate)
15981 (while inst-prev-path
15982 (setq margin (- margin vhdl-basic-offset))
15983 (indent-to margin)
15984 (vhdl-insert-keyword "END FOR;\n")
15985 (setq inst-prev-path (cdr inst-prev-path)))
15986 ;; insert block configuration beginning (for current block/generate)
15987 (indent-to margin)
15988 (while inst-path
15989 (setq margin (+ margin vhdl-basic-offset))
15990 (vhdl-insert-keyword "FOR ")
15991 (insert (car inst-path) "\n")
15992 (indent-to margin)
15993 (setq inst-path (cdr inst-path)))
15994 ;; insert component configuration beginning
15995 (vhdl-insert-keyword "FOR ")
15996 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15997 ;; find subconfiguration
15998 (setq conf-key (nth 7 inst-entry))
15999 (setq tmp-alist conf-alist)
16000 ;; use first configuration found for instance's entity
16001 (while (and tmp-alist (null conf-key))
16002 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16003 (setq conf-key (nth 0 (car tmp-alist))))
16004 (setq tmp-alist (cdr tmp-alist)))
16005 (setq conf-entry (aget conf-alist conf-key t))
16006 ;; insert binding indication ...
16007 ;; ... with subconfiguration (if exists)
16008 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16009 (progn
16010 (indent-to (+ margin vhdl-basic-offset))
16011 (vhdl-insert-keyword "USE CONFIGURATION ")
16012 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16013 (insert ";\n"))
16014 ;; ... with entity (if exists)
16015 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16016 (when ent-entry
16017 (indent-to (+ margin vhdl-basic-offset))
16018 (vhdl-insert-keyword "USE ENTITY ")
16019 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16020 ;; insert architecture name (if architecture exists)
16021 (when (nth 3 ent-entry)
16022 (setq arch-name
16023 ;; choose architecture name a) from configuration,
16024 ;; b) from mra, or c) from first architecture
16025 (or (nth 0 (aget (nth 3 ent-entry)
16026 (or (nth 6 inst-entry)
16027 (nth 4 ent-entry)) t))
16028 (nth 1 (car (nth 3 ent-entry)))))
16029 (insert "(" arch-name ")"))
16030 (insert ";\n")
16031 ;; insert block configuration (for architecture of subcomponent)
16032 (when (and vhdl-compose-configuration-hierarchical
16033 (nth 3 ent-entry))
16034 (indent-to (+ margin vhdl-basic-offset))
16035 (vhdl-compose-configuration-architecture
16036 (nth 0 ent-entry) arch-name
16037 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16038 ;; insert component configuration end
16039 (indent-to margin)
16040 (vhdl-insert-keyword "END FOR;\n")
16041 (setq inst-prev-path (nth 9 inst-entry)))
16042 (setq inst-alist (cdr inst-alist)))
16043 ;; insert block configuration end (for block/generate)
16044 (while inst-prev-path
16045 (setq margin (- margin vhdl-basic-offset))
16046 (indent-to margin)
16047 (vhdl-insert-keyword "END FOR;\n")
16048 (setq inst-prev-path (cdr inst-prev-path)))
16049 (indent-to (- margin vhdl-basic-offset))
16050 ;; insert block configuration end or remove beginning (for architecture)
16051 (if insert-conf
16052 (vhdl-insert-keyword "END FOR;\n")
16053 (delete-region beg (point)))))
16055 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16056 "Generate configuration declaration."
16057 (interactive)
16058 (vhdl-require-hierarchy-info)
16059 (let ((ent-alist (aget vhdl-entity-alist
16060 (or (vhdl-project-p) default-directory) t))
16061 (conf-alist (aget vhdl-config-alist
16062 (or (vhdl-project-p) default-directory) t))
16063 (from-speedbar ent-name)
16064 inst-alist conf-name conf-file-name pos)
16065 (vhdl-prepare-search-2
16066 ;; get entity and architecture name
16067 (unless ent-name
16068 (save-excursion
16069 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16070 (not (equal "END" (upcase (match-string 1))))
16071 (setq ent-name (match-string-no-properties 3))
16072 (setq arch-name (match-string-no-properties 2)))
16073 (error "ERROR: Not within an architecture"))))
16074 (setq conf-name (vhdl-replace-string
16075 vhdl-compose-configuration-name
16076 (concat ent-name " " arch-name)))
16077 (setq inst-alist
16078 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16079 (downcase arch-name) t))))
16080 (message "Generating configuration \"%s\"..." conf-name)
16081 (if vhdl-compose-configuration-create-file
16082 ;; open configuration file
16083 (progn
16084 (setq conf-file-name
16085 (concat (vhdl-replace-string vhdl-configuration-file-name
16086 conf-name t)
16087 "." (file-name-extension (buffer-file-name))))
16088 (when (and (file-exists-p conf-file-name)
16089 (not (y-or-n-p (concat "File \"" conf-file-name
16090 "\" exists; overwrite? "))))
16091 (error "ERROR: Creating configuration...aborted"))
16092 (find-file conf-file-name)
16093 (erase-buffer)
16094 (set-buffer-modified-p nil)
16095 ;; insert header
16096 (if vhdl-compose-include-header
16097 (progn (vhdl-template-header
16098 (concat "Configuration declaration for design \""
16099 ent-name "(" arch-name ")\""))
16100 (goto-char (point-max)))
16101 (vhdl-comment-display-line) (insert "\n\n")))
16102 ;; goto end of architecture
16103 (unless from-speedbar
16104 (re-search-forward "^end\\>" nil)
16105 (end-of-line) (insert "\n\n")
16106 (vhdl-comment-display-line) (insert "\n\n")))
16107 ;; insert library clause
16108 (setq pos (point))
16109 (vhdl-template-standard-package (vhdl-work-library) nil)
16110 (when (/= pos (point))
16111 (insert "\n\n"))
16112 ;; insert configuration
16113 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16114 (vhdl-insert-keyword " OF ") (insert ent-name)
16115 (vhdl-insert-keyword " IS\n")
16116 (indent-to vhdl-basic-offset)
16117 ;; insert block configuration (for architecture)
16118 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16119 (vhdl-insert-keyword "END ") (insert conf-name ";")
16120 (when conf-file-name
16121 ;; insert footer and save
16122 (insert "\n\n")
16123 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16124 (vhdl-template-footer)
16125 (vhdl-comment-display-line) (insert "\n"))
16126 (save-buffer))
16127 (message "%s"
16128 (concat (format "Generating configuration \"%s\"...done" conf-name)
16129 (and conf-file-name
16130 (format "\n File created: \"%s\"" conf-file-name))))))
16133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16134 ;;; Compilation / Makefile generation
16135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16136 ;; (using `compile.el')
16138 (defun vhdl-makefile-name ()
16139 "Return the Makefile name of the current project or the current compiler if
16140 no project is defined."
16141 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16142 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16143 (vhdl-replace-string
16144 (cons "\\(.*\\)\n\\(.*\\)"
16145 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16146 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16148 (defun vhdl-compile-directory ()
16149 "Return the directory where compilation/make should be run."
16150 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16151 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16152 (directory (vhdl-resolve-env-variable
16153 (if project
16154 (vhdl-replace-string
16155 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16156 (nth 6 compiler)))))
16157 (file-name-as-directory
16158 (if (file-name-absolute-p directory)
16159 directory
16160 (expand-file-name directory (vhdl-default-directory))))))
16162 (defun vhdl-uniquify (in-list)
16163 "Remove duplicate elements from IN-LIST."
16164 (let (out-list)
16165 (while in-list
16166 (add-to-list 'out-list (car in-list))
16167 (setq in-list (cdr in-list)))
16168 out-list))
16170 (defun vhdl-set-compiler (name)
16171 "Set current compiler to NAME."
16172 (interactive
16173 (list (let ((completion-ignore-case t))
16174 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16175 (if (assoc name vhdl-compiler-alist)
16176 (progn (setq vhdl-compiler name)
16177 (message "Current compiler: \"%s\"" vhdl-compiler))
16178 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16181 ;; Compilation
16183 (defun vhdl-compile-init ()
16184 "Initialize for compilation."
16185 (when (or (null compilation-error-regexp-alist)
16186 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16187 compilation-error-regexp-alist)))
16188 ;; `compilation-error-regexp-alist'
16189 (let ((commands-alist vhdl-compiler-alist)
16190 regexp-alist sublist)
16191 (while commands-alist
16192 (setq sublist (nth 11 (car commands-alist)))
16193 (unless (or (equal "" (car sublist))
16194 (assoc (car sublist) regexp-alist))
16195 (setq regexp-alist (cons (list (nth 0 sublist)
16196 (if (= 0 (nth 1 sublist))
16197 (if (featurep 'xemacs) 9 nil)
16198 (nth 1 sublist))
16199 (nth 2 sublist) (nth 3 sublist))
16200 regexp-alist)))
16201 (setq commands-alist (cdr commands-alist)))
16202 (setq compilation-error-regexp-alist
16203 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16204 ;; `compilation-file-regexp-alist'
16205 (let ((commands-alist vhdl-compiler-alist)
16206 regexp-alist sublist)
16207 ;; matches vhdl-mode file name output
16208 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16209 (while commands-alist
16210 (setq sublist (nth 12 (car commands-alist)))
16211 (unless (or (equal "" (car sublist))
16212 (assoc (car sublist) regexp-alist))
16213 (setq regexp-alist (cons sublist regexp-alist)))
16214 (setq commands-alist (cdr commands-alist)))
16215 (setq compilation-file-regexp-alist
16216 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16218 (defvar vhdl-compile-file-name nil
16219 "Name of file to be compiled.")
16221 (defun vhdl-compile-print-file-name ()
16222 "Function called within `compile' to print out file name for compilers that
16223 do not print any file names."
16224 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16226 (defun vhdl-get-compile-options (project compiler file-name
16227 &optional file-options-only)
16228 "Get compiler options. Returning nil means do not compile this file."
16229 (let* ((compiler-options (nth 1 compiler))
16230 (project-entry (aget (nth 4 project) vhdl-compiler))
16231 (project-options (nth 0 project-entry))
16232 (exception-list (and file-name (nth 2 project-entry)))
16233 (work-library (vhdl-work-library))
16234 (case-fold-search nil)
16235 file-options)
16236 (while (and exception-list
16237 (not (string-match (caar exception-list) file-name)))
16238 (setq exception-list (cdr exception-list)))
16239 (if (and exception-list (not (cdar exception-list)))
16241 (if (and file-options-only (not exception-list))
16242 'default
16243 (setq file-options (cdar exception-list))
16244 ;; insert library name in compiler-specific options
16245 (setq compiler-options
16246 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16247 work-library))
16248 ;; insert compiler-specific options in project-specific options
16249 (when project-options
16250 (setq project-options
16251 (vhdl-replace-string
16252 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16253 (concat work-library "\n" compiler-options))))
16254 ;; insert project-specific options in file-specific options
16255 (when file-options
16256 (setq file-options
16257 (vhdl-replace-string
16258 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16259 (concat work-library "\n" compiler-options "\n"
16260 project-options))))
16261 ;; return options
16262 (or file-options project-options compiler-options)))))
16264 (defun vhdl-get-make-options (project compiler)
16265 "Get make options."
16266 (let* ((compiler-options (nth 3 compiler))
16267 (project-entry (aget (nth 4 project) vhdl-compiler))
16268 (project-options (nth 1 project-entry))
16269 (makefile-name (vhdl-makefile-name)))
16270 ;; insert Makefile name in compiler-specific options
16271 (setq compiler-options
16272 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16273 makefile-name))
16274 ;; insert compiler-specific options in project-specific options
16275 (when project-options
16276 (setq project-options
16277 (vhdl-replace-string
16278 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16279 (concat makefile-name "\n" compiler-options))))
16280 ;; return options
16281 (or project-options compiler-options)))
16283 (defun vhdl-compile ()
16284 "Compile current buffer using the VHDL compiler specified in
16285 `vhdl-compiler'."
16286 (interactive)
16287 (vhdl-compile-init)
16288 (let* ((project (aget vhdl-project-alist vhdl-project))
16289 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16290 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16291 (command (nth 0 compiler))
16292 (file-name (buffer-file-name))
16293 (options (vhdl-get-compile-options project compiler file-name))
16294 (default-directory (vhdl-compile-directory))
16295 compilation-process-setup-function)
16296 (unless (file-directory-p default-directory)
16297 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16298 ;; put file name into quotes if it contains spaces
16299 (when (string-match " " file-name)
16300 (setq file-name (concat "\"" file-name "\"")))
16301 ;; print out file name if compiler does not
16302 (setq vhdl-compile-file-name (buffer-file-name))
16303 (when (and (= 0 (nth 1 (nth 10 compiler)))
16304 (= 0 (nth 1 (nth 11 compiler))))
16305 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16306 ;; run compilation
16307 (if options
16308 (when command
16309 (compile (concat command " " options " " file-name)))
16310 (vhdl-warning "Your project settings tell me not to compile this file"))))
16312 (defvar vhdl-make-target "all"
16313 "Default target for `vhdl-make' command.")
16315 (defun vhdl-make (&optional target)
16316 "Call make command for compilation of all updated source files (requires
16317 `Makefile'). Optional argument TARGET allows to compile the design
16318 specified by a target."
16319 (interactive)
16320 (setq vhdl-make-target
16321 (or target (read-from-minibuffer "Target: " vhdl-make-target
16322 vhdl-minibuffer-local-map)))
16323 (vhdl-compile-init)
16324 (let* ((project (aget vhdl-project-alist vhdl-project))
16325 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16326 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16327 (command (nth 2 compiler))
16328 (options (vhdl-get-make-options project compiler))
16329 (default-directory (vhdl-compile-directory)))
16330 (unless (file-directory-p default-directory)
16331 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16332 ;; run make
16333 (compile (concat (if (equal command "") "make" command)
16334 " " options " " vhdl-make-target))))
16336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16337 ;; Makefile generation
16339 (defun vhdl-generate-makefile ()
16340 "Generate `Makefile'."
16341 (interactive)
16342 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16343 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16344 (command (nth 4 compiler)))
16345 ;; generate makefile
16346 (if command
16347 (let ((default-directory (vhdl-compile-directory)))
16348 (compile (vhdl-replace-string
16349 (cons "\\(.*\\) \\(.*\\)" command)
16350 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16351 (vhdl-generate-makefile-1))))
16353 (defun vhdl-get-packages (lib-alist work-library)
16354 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16355 (let (pack-list)
16356 (while lib-alist
16357 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16358 (setq pack-list (cons (cdar lib-alist) pack-list)))
16359 (setq lib-alist (cdr lib-alist)))
16360 pack-list))
16362 (defun vhdl-generate-makefile-1 ()
16363 "Generate Makefile for current project or directory."
16364 ;; scan hierarchy if required
16365 (if (vhdl-project-p)
16366 (unless (or (assoc vhdl-project vhdl-file-alist)
16367 (vhdl-load-cache vhdl-project))
16368 (vhdl-scan-project-contents vhdl-project))
16369 (let ((directory (abbreviate-file-name default-directory)))
16370 (unless (or (assoc directory vhdl-file-alist)
16371 (vhdl-load-cache directory))
16372 (vhdl-scan-directory-contents directory))))
16373 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16374 (project (vhdl-project-p))
16375 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16376 (conf-alist (aget vhdl-config-alist (or project directory) t))
16377 (pack-alist (aget vhdl-package-alist (or project directory) t))
16378 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16379 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16380 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16381 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16382 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16383 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16384 (adjust-case (nth 5 regexp-list))
16385 (work-library (downcase (vhdl-work-library)))
16386 (compile-directory (expand-file-name (vhdl-compile-directory)
16387 default-directory))
16388 (makefile-name (vhdl-makefile-name))
16389 rule-alist arch-alist inst-alist
16390 target-list depend-list unit-list prim-list second-list subcomp-list
16391 lib-alist lib-body-alist pack-list all-pack-list
16392 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16393 conf-key conf-file-name pack-key pack-file-name
16394 ent-entry arch-entry conf-entry pack-entry inst-entry
16395 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16396 tmp-key tmp-list rule)
16397 ;; check prerequisites
16398 (unless (file-exists-p compile-directory)
16399 (make-directory compile-directory t))
16400 (unless regexp-list
16401 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16402 vhdl-compiler))
16403 (message "Generating makefile \"%s\"..." makefile-name)
16404 ;; rules for all entities
16405 (setq tmp-list ent-alist)
16406 (while ent-alist
16407 (setq ent-entry (car ent-alist)
16408 ent-key (nth 0 ent-entry))
16409 (when (nth 2 ent-entry)
16410 (setq ent-file-name (file-relative-name
16411 (nth 2 ent-entry) compile-directory)
16412 arch-alist (nth 4 ent-entry)
16413 lib-alist (nth 6 ent-entry)
16414 rule (aget rule-alist ent-file-name)
16415 target-list (nth 0 rule)
16416 depend-list (nth 1 rule)
16417 second-list nil
16418 subcomp-list nil)
16419 (setq tmp-key (vhdl-replace-string
16420 ent-regexp (funcall adjust-case ent-key)))
16421 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16422 ;; rule target for this entity
16423 (setq target-list (cons ent-key target-list))
16424 ;; rule dependencies for all used packages
16425 (setq pack-list (vhdl-get-packages lib-alist work-library))
16426 (setq depend-list (append depend-list pack-list))
16427 (setq all-pack-list pack-list)
16428 ;; add rule
16429 (aput 'rule-alist ent-file-name (list target-list depend-list))
16430 ;; rules for all corresponding architectures
16431 (while arch-alist
16432 (setq arch-entry (car arch-alist)
16433 arch-key (nth 0 arch-entry)
16434 ent-arch-key (concat ent-key "-" arch-key)
16435 arch-file-name (file-relative-name (nth 2 arch-entry)
16436 compile-directory)
16437 inst-alist (nth 4 arch-entry)
16438 lib-alist (nth 5 arch-entry)
16439 rule (aget rule-alist arch-file-name)
16440 target-list (nth 0 rule)
16441 depend-list (nth 1 rule))
16442 (setq tmp-key (vhdl-replace-string
16443 arch-regexp
16444 (funcall adjust-case (concat arch-key " " ent-key))))
16445 (setq unit-list
16446 (cons (cons ent-arch-key tmp-key) unit-list))
16447 (setq second-list (cons ent-arch-key second-list))
16448 ;; rule target for this architecture
16449 (setq target-list (cons ent-arch-key target-list))
16450 ;; rule dependency for corresponding entity
16451 (setq depend-list (cons ent-key depend-list))
16452 ;; rule dependencies for contained component instantiations
16453 (while inst-alist
16454 (setq inst-entry (car inst-alist))
16455 (when (or (null (nth 8 inst-entry))
16456 (equal (downcase (nth 8 inst-entry)) work-library))
16457 (setq inst-ent-key (or (nth 7 inst-entry)
16458 (nth 5 inst-entry)))
16459 (setq depend-list (cons inst-ent-key depend-list)
16460 subcomp-list (cons inst-ent-key subcomp-list)))
16461 (setq inst-alist (cdr inst-alist)))
16462 ;; rule dependencies for all used packages
16463 (setq pack-list (vhdl-get-packages lib-alist work-library))
16464 (setq depend-list (append depend-list pack-list))
16465 (setq all-pack-list (append all-pack-list pack-list))
16466 ;; add rule
16467 (aput 'rule-alist arch-file-name (list target-list depend-list))
16468 (setq arch-alist (cdr arch-alist)))
16469 (setq prim-list (cons (list ent-key second-list
16470 (append subcomp-list all-pack-list))
16471 prim-list)))
16472 (setq ent-alist (cdr ent-alist)))
16473 (setq ent-alist tmp-list)
16474 ;; rules for all configurations
16475 (setq tmp-list conf-alist)
16476 (while conf-alist
16477 (setq conf-entry (car conf-alist)
16478 conf-key (nth 0 conf-entry)
16479 conf-file-name (file-relative-name
16480 (nth 2 conf-entry) compile-directory)
16481 ent-key (nth 4 conf-entry)
16482 arch-key (nth 5 conf-entry)
16483 inst-alist (nth 6 conf-entry)
16484 lib-alist (nth 7 conf-entry)
16485 rule (aget rule-alist conf-file-name)
16486 target-list (nth 0 rule)
16487 depend-list (nth 1 rule)
16488 subcomp-list (list ent-key))
16489 (setq tmp-key (vhdl-replace-string
16490 conf-regexp (funcall adjust-case conf-key)))
16491 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16492 ;; rule target for this configuration
16493 (setq target-list (cons conf-key target-list))
16494 ;; rule dependency for corresponding entity and architecture
16495 (setq depend-list
16496 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16497 ;; rule dependencies for used packages
16498 (setq pack-list (vhdl-get-packages lib-alist work-library))
16499 (setq depend-list (append depend-list pack-list))
16500 ;; rule dependencies for contained component configurations
16501 (while inst-alist
16502 (setq inst-entry (car inst-alist))
16503 (setq inst-ent-key (nth 2 inst-entry)
16504 ; comp-arch-key (nth 2 inst-entry))
16505 inst-conf-key (nth 4 inst-entry))
16506 (when (equal (downcase (nth 5 inst-entry)) work-library)
16507 (when inst-ent-key
16508 (setq depend-list (cons inst-ent-key depend-list)
16509 subcomp-list (cons inst-ent-key subcomp-list)))
16510 ; (when comp-arch-key
16511 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16512 ; depend-list)))
16513 (when inst-conf-key
16514 (setq depend-list (cons inst-conf-key depend-list)
16515 subcomp-list (cons inst-conf-key subcomp-list))))
16516 (setq inst-alist (cdr inst-alist)))
16517 ;; add rule
16518 (aput 'rule-alist conf-file-name (list target-list depend-list))
16519 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16520 prim-list))
16521 (setq conf-alist (cdr conf-alist)))
16522 (setq conf-alist tmp-list)
16523 ;; rules for all packages
16524 (setq tmp-list pack-alist)
16525 (while pack-alist
16526 (setq pack-entry (car pack-alist)
16527 pack-key (nth 0 pack-entry)
16528 pack-body-key nil)
16529 (when (nth 2 pack-entry)
16530 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16531 compile-directory)
16532 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16533 rule (aget rule-alist pack-file-name)
16534 target-list (nth 0 rule) depend-list (nth 1 rule))
16535 (setq tmp-key (vhdl-replace-string
16536 pack-regexp (funcall adjust-case pack-key)))
16537 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16538 ;; rule target for this package
16539 (setq target-list (cons pack-key target-list))
16540 ;; rule dependencies for all used packages
16541 (setq pack-list (vhdl-get-packages lib-alist work-library))
16542 (setq depend-list (append depend-list pack-list))
16543 (setq all-pack-list pack-list)
16544 ;; add rule
16545 (aput 'rule-alist pack-file-name (list target-list depend-list))
16546 ;; rules for this package's body
16547 (when (nth 7 pack-entry)
16548 (setq pack-body-key (concat pack-key "-body")
16549 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16550 compile-directory)
16551 rule (aget rule-alist pack-body-file-name)
16552 target-list (nth 0 rule)
16553 depend-list (nth 1 rule))
16554 (setq tmp-key (vhdl-replace-string
16555 pack-body-regexp (funcall adjust-case pack-key)))
16556 (setq unit-list
16557 (cons (cons pack-body-key tmp-key) unit-list))
16558 ;; rule target for this package's body
16559 (setq target-list (cons pack-body-key target-list))
16560 ;; rule dependency for corresponding package declaration
16561 (setq depend-list (cons pack-key depend-list))
16562 ;; rule dependencies for all used packages
16563 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16564 (setq depend-list (append depend-list pack-list))
16565 (setq all-pack-list (append all-pack-list pack-list))
16566 ;; add rule
16567 (aput 'rule-alist pack-body-file-name
16568 (list target-list depend-list)))
16569 (setq prim-list
16570 (cons (list pack-key (when pack-body-key (list pack-body-key))
16571 all-pack-list)
16572 prim-list)))
16573 (setq pack-alist (cdr pack-alist)))
16574 (setq pack-alist tmp-list)
16575 ;; generate Makefile
16576 (let* ((project (aget vhdl-project-alist project))
16577 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16578 (compiler-id (nth 9 compiler))
16579 (library-directory
16580 (vhdl-resolve-env-variable
16581 (vhdl-replace-string
16582 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16583 compiler-id)))
16584 (makefile-path-name (expand-file-name
16585 makefile-name compile-directory))
16586 (orig-buffer (current-buffer))
16587 cell second-list subcomp-list options unit-key unit-name)
16588 ;; sort lists
16589 (setq unit-list (vhdl-sort-alist unit-list))
16590 (setq prim-list (vhdl-sort-alist prim-list))
16591 (setq tmp-list rule-alist)
16592 (while tmp-list ; pre-sort rule targets
16593 (setq cell (cdar tmp-list))
16594 (setcar cell (sort (car cell) 'string<))
16595 (setq tmp-list (cdr tmp-list)))
16596 (setq rule-alist ; sort by first rule target
16597 (sort rule-alist
16598 (function (lambda (a b)
16599 (string< (car (cadr a)) (car (cadr b)))))))
16600 ;; open and clear Makefile
16601 (set-buffer (find-file-noselect makefile-path-name t t))
16602 (erase-buffer)
16603 (insert "# -*- Makefile -*-\n"
16604 "### " (file-name-nondirectory makefile-name)
16605 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16606 "\n")
16607 (if project
16608 (insert "\n# Project : " (nth 0 project))
16609 (insert "\n# Directory : \"" directory "\""))
16610 (insert "\n# Platform : " vhdl-compiler
16611 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16612 (user-login-name) "\n")
16613 ;; insert compile and option variable settings
16614 (insert "\n\n# Define compilation command and options\n"
16615 "\nCOMPILE = " (nth 0 compiler)
16616 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16617 "\n")
16618 ;; insert library paths
16619 (setq library-directory
16620 (directory-file-name
16621 (if (file-name-absolute-p library-directory)
16622 library-directory
16623 (file-relative-name
16624 (expand-file-name library-directory directory)
16625 compile-directory))))
16626 (insert "\n\n# Define library paths\n"
16627 "\nLIBRARY-" work-library " = " library-directory "\n")
16628 ;; insert variable definitions for all library unit files
16629 (insert "\n\n# Define library unit files\n")
16630 (setq tmp-list unit-list)
16631 (while unit-list
16632 (insert "\nUNIT-" work-library "-" (caar unit-list)
16633 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16634 (setq unit-list (cdr unit-list)))
16635 ;; insert variable definition for list of all library unit files
16636 (insert "\n\n\n# Define list of all library unit files\n"
16637 "\nALL_UNITS =")
16638 (setq unit-list tmp-list)
16639 (while unit-list
16640 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16641 (setq unit-list (cdr unit-list)))
16642 (insert "\n")
16643 (setq unit-list tmp-list)
16644 ;; insert `make all' rule
16645 (insert "\n\n\n# Rule for compiling entire design\n"
16646 "\nall :"
16647 " \\\n\t\tlibrary"
16648 " \\\n\t\t$(ALL_UNITS)\n")
16649 ;; insert `make clean' rule
16650 (insert "\n\n# Rule for cleaning entire design\n"
16651 "\nclean : "
16652 "\n\t-rm -f $(ALL_UNITS)\n")
16653 ;; insert `make library' rule
16654 (insert "\n\n# Rule for creating library directory\n"
16655 "\nlibrary :"
16656 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16657 "\n$(LIBRARY-" work-library ") :"
16658 "\n\t"
16659 (vhdl-replace-string
16660 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16661 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16662 "\n")
16663 ;; insert rule for each library unit
16664 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16665 (while prim-list
16666 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16667 (setq subcomp-list
16668 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16669 (setq unit-key (caar prim-list)
16670 unit-name (or (nth 0 (aget ent-alist unit-key t))
16671 (nth 0 (aget conf-alist unit-key t))
16672 (nth 0 (aget pack-alist unit-key t))))
16673 (insert "\n" unit-key)
16674 (unless (equal unit-key unit-name)
16675 (insert " \\\n" unit-name))
16676 (insert " :"
16677 " \\\n\t\tlibrary"
16678 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16679 (while second-list
16680 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16681 (setq second-list (cdr second-list)))
16682 (while subcomp-list
16683 (when (and (assoc (car subcomp-list) unit-list)
16684 (not (equal unit-key (car subcomp-list))))
16685 (insert " \\\n\t\t" (car subcomp-list)))
16686 (setq subcomp-list (cdr subcomp-list)))
16687 (insert "\n")
16688 (setq prim-list (cdr prim-list)))
16689 ;; insert rule for each library unit file
16690 (insert "\n\n# Rules for compiling single library unit files\n")
16691 (while rule-alist
16692 (setq rule (car rule-alist))
16693 ;; get compiler options for this file
16694 (setq options
16695 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16696 ;; insert rule if file is supposed to be compiled
16697 (setq target-list (nth 1 rule)
16698 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16699 ;; insert targets
16700 (setq tmp-list target-list)
16701 (while target-list
16702 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16703 (if (cdr target-list) " \\" " :"))
16704 (setq target-list (cdr target-list)))
16705 (setq target-list tmp-list)
16706 ;; insert file name as first dependency
16707 (insert " \\\n\t\t" (nth 0 rule))
16708 ;; insert dependencies (except if also target or unit does not exist)
16709 (while depend-list
16710 (when (and (not (member (car depend-list) target-list))
16711 (assoc (car depend-list) unit-list))
16712 (insert " \\\n\t\t"
16713 "$(UNIT-" work-library "-" (car depend-list) ")"))
16714 (setq depend-list (cdr depend-list)))
16715 ;; insert compile command
16716 (if options
16717 (insert "\n\t$(COMPILE) "
16718 (if (eq options 'default) "$(OPTIONS)" options) " "
16719 (nth 0 rule) "\n")
16720 (setq tmp-list target-list)
16721 (while target-list
16722 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16723 (if (cdr target-list) " \\" "\n"))
16724 (setq target-list (cdr target-list)))
16725 (setq target-list tmp-list))
16726 (setq rule-alist (cdr rule-alist)))
16727 (insert "\n\n### " makefile-name " ends here\n")
16728 ;; run Makefile generation hook
16729 (run-hooks 'vhdl-makefile-generation-hook)
16730 (message "Generating makefile \"%s\"...done" makefile-name)
16731 ;; save and close file
16732 (if (file-writable-p makefile-path-name)
16733 (progn (save-buffer)
16734 (kill-buffer (current-buffer))
16735 (set-buffer orig-buffer)
16736 (add-to-history 'file-name-history makefile-path-name))
16737 (vhdl-warning-when-idle
16738 (format "File not writable: \"%s\""
16739 (abbreviate-file-name makefile-path-name)))
16740 (switch-to-buffer (current-buffer))))))
16743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16744 ;;; Bug reports
16745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16746 ;; (using `reporter.el')
16748 (defconst vhdl-mode-help-address
16749 "Reto Zimmermann <reto@gnu.org>"
16750 "Address for VHDL Mode bug reports.")
16752 (defun vhdl-submit-bug-report ()
16753 "Submit via mail a bug report on VHDL Mode."
16754 (interactive)
16755 ;; load in reporter
16756 (and
16757 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16758 (let ((reporter-prompt-for-summary-p t))
16759 (reporter-submit-bug-report
16760 vhdl-mode-help-address
16761 (concat "VHDL Mode " vhdl-version)
16762 (list
16763 ;; report all important user options
16764 'vhdl-offsets-alist
16765 'vhdl-comment-only-line-offset
16766 'tab-width
16767 'vhdl-electric-mode
16768 'vhdl-stutter-mode
16769 'vhdl-indent-tabs-mode
16770 'vhdl-project-alist
16771 'vhdl-project
16772 'vhdl-project-file-name
16773 'vhdl-project-auto-load
16774 'vhdl-project-sort
16775 'vhdl-compiler-alist
16776 'vhdl-compiler
16777 'vhdl-compile-use-local-error-regexp
16778 'vhdl-makefile-generation-hook
16779 'vhdl-default-library
16780 'vhdl-standard
16781 'vhdl-basic-offset
16782 'vhdl-upper-case-keywords
16783 'vhdl-upper-case-types
16784 'vhdl-upper-case-attributes
16785 'vhdl-upper-case-enum-values
16786 'vhdl-upper-case-constants
16787 'vhdl-use-direct-instantiation
16788 'vhdl-compose-configuration-name
16789 'vhdl-entity-file-name
16790 'vhdl-architecture-file-name
16791 'vhdl-configuration-file-name
16792 'vhdl-package-file-name
16793 'vhdl-file-name-case
16794 'vhdl-electric-keywords
16795 'vhdl-optional-labels
16796 'vhdl-insert-empty-lines
16797 'vhdl-argument-list-indent
16798 'vhdl-association-list-with-formals
16799 'vhdl-conditions-in-parenthesis
16800 'vhdl-zero-string
16801 'vhdl-one-string
16802 'vhdl-file-header
16803 'vhdl-file-footer
16804 'vhdl-company-name
16805 'vhdl-copyright-string
16806 'vhdl-platform-spec
16807 'vhdl-date-format
16808 'vhdl-modify-date-prefix-string
16809 'vhdl-modify-date-on-saving
16810 'vhdl-reset-kind
16811 'vhdl-reset-active-high
16812 'vhdl-clock-rising-edge
16813 'vhdl-clock-edge-condition
16814 'vhdl-clock-name
16815 'vhdl-reset-name
16816 'vhdl-model-alist
16817 'vhdl-include-port-comments
16818 'vhdl-include-direction-comments
16819 'vhdl-include-type-comments
16820 'vhdl-include-group-comments
16821 'vhdl-actual-port-name
16822 'vhdl-instance-name
16823 'vhdl-testbench-entity-name
16824 'vhdl-testbench-architecture-name
16825 'vhdl-testbench-configuration-name
16826 'vhdl-testbench-dut-name
16827 'vhdl-testbench-include-header
16828 'vhdl-testbench-declarations
16829 'vhdl-testbench-statements
16830 'vhdl-testbench-initialize-signals
16831 'vhdl-testbench-include-library
16832 'vhdl-testbench-include-configuration
16833 'vhdl-testbench-create-files
16834 'vhdl-testbench-entity-file-name
16835 'vhdl-testbench-architecture-file-name
16836 'vhdl-compose-create-files
16837 'vhdl-compose-configuration-create-file
16838 'vhdl-compose-configuration-hierarchical
16839 'vhdl-compose-configuration-use-subconfiguration
16840 'vhdl-compose-include-header
16841 'vhdl-compose-architecture-name
16842 'vhdl-components-package-name
16843 'vhdl-use-components-package
16844 'vhdl-self-insert-comments
16845 'vhdl-prompt-for-comments
16846 'vhdl-inline-comment-column
16847 'vhdl-end-comment-column
16848 'vhdl-auto-align
16849 'vhdl-align-groups
16850 'vhdl-align-group-separate
16851 'vhdl-align-same-indent
16852 'vhdl-highlight-keywords
16853 'vhdl-highlight-names
16854 'vhdl-highlight-special-words
16855 'vhdl-highlight-forbidden-words
16856 'vhdl-highlight-verilog-keywords
16857 'vhdl-highlight-translate-off
16858 'vhdl-highlight-case-sensitive
16859 'vhdl-special-syntax-alist
16860 'vhdl-forbidden-words
16861 'vhdl-forbidden-syntax
16862 'vhdl-directive-keywords
16863 'vhdl-speedbar-auto-open
16864 'vhdl-speedbar-display-mode
16865 'vhdl-speedbar-scan-limit
16866 'vhdl-speedbar-jump-to-unit
16867 'vhdl-speedbar-update-on-saving
16868 'vhdl-speedbar-save-cache
16869 'vhdl-speedbar-cache-file-name
16870 'vhdl-index-menu
16871 'vhdl-source-file-menu
16872 'vhdl-hideshow-menu
16873 'vhdl-hide-all-init
16874 'vhdl-print-two-column
16875 'vhdl-print-customize-faces
16876 'vhdl-intelligent-tab
16877 'vhdl-indent-syntax-based
16878 'vhdl-word-completion-case-sensitive
16879 'vhdl-word-completion-in-minibuffer
16880 'vhdl-underscore-is-part-of-word
16881 'vhdl-mode-hook)
16882 (function
16883 (lambda ()
16884 (insert
16885 (if vhdl-special-indent-hook
16886 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16887 "vhdl-special-indent-hook is set to '"
16888 (format "%s" vhdl-special-indent-hook)
16889 ".\nPerhaps this is your problem?\n"
16890 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16891 "\n"))))
16893 "Hi Reto,"))))
16896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16897 ;;; Documentation
16898 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16900 (defconst vhdl-doc-release-notes nil
16902 Release Notes for VHDL Mode 3.33
16903 ================================
16905 - New Features
16906 - User Options
16909 New Features
16910 ------------
16912 CONFIGURATION DECLARATION GENERATION:
16913 - Automatic generation of a configuration declaration for a design.
16914 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16917 User Options
16918 ------------
16920 `vhdl-configuration-file-name': (new)
16921 Specify how the configuration file name is obtained.
16922 `vhdl-compose-configuration-name': (new)
16923 Specify how the configuration name is optained.
16924 `vhdl-compose-configuration-create-file': (new)
16925 Specify whether a new file should be created for a configuration.
16926 `vhdl-compose-configuration-hierarchical': (new)
16927 Specify whether hierarchical configurations should be created.
16928 `vhdl-compose-configuration-use-subconfiguration': (new)
16929 Specify whether subconfigurations should be used inside configurations.
16933 (defconst vhdl-doc-keywords nil
16935 Reserved words in VHDL
16936 ----------------------
16938 VHDL'93 (IEEE Std 1076-1993):
16939 `vhdl-93-keywords' : keywords
16940 `vhdl-93-types' : standardized types
16941 `vhdl-93-attributes' : standardized attributes
16942 `vhdl-93-enum-values' : standardized enumeration values
16943 `vhdl-93-functions' : standardized functions
16944 `vhdl-93-packages' : standardized packages and libraries
16946 VHDL-AMS (IEEE Std 1076.1):
16947 `vhdl-ams-keywords' : keywords
16948 `vhdl-ams-types' : standardized types
16949 `vhdl-ams-attributes' : standardized attributes
16950 `vhdl-ams-enum-values' : standardized enumeration values
16951 `vhdl-ams-functions' : standardized functions
16953 Math Packages (IEEE Std 1076.2):
16954 `vhdl-math-types' : standardized types
16955 `vhdl-math-constants' : standardized constants
16956 `vhdl-math-functions' : standardized functions
16957 `vhdl-math-packages' : standardized packages
16959 Forbidden words:
16960 `vhdl-verilog-keywords' : Verilog reserved words
16962 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16965 (defconst vhdl-doc-coding-style nil
16967 For VHDL coding style and naming convention guidelines, see the following
16968 references:
16970 \[1] Ben Cohen.
16971 \"VHDL Coding Styles and Methodologies\".
16972 Kluwer Academic Publishers, 1999.
16973 http://members.aol.com/vhdlcohen/vhdl/
16975 \[2] Michael Keating and Pierre Bricaud.
16976 \"Reuse Methodology Manual, Second Edition\".
16977 Kluwer Academic Publishers, 1999.
16978 http://www.openmore.com/openmore/rmm2.html
16980 \[3] European Space Agency.
16981 \"VHDL Modelling Guidelines\".
16982 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16984 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16985 to visually support naming conventions.")
16988 (defun vhdl-version ()
16989 "Echo the current version of VHDL Mode in the minibuffer."
16990 (interactive)
16991 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16992 (vhdl-keep-region-active))
16994 (defun vhdl-doc-variable (variable)
16995 "Display VARIABLE's documentation in *Help* buffer."
16996 (interactive)
16997 (unless (featurep 'xemacs)
16998 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16999 (with-output-to-temp-buffer
17000 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17001 (princ (documentation-property variable 'variable-documentation))
17002 (with-current-buffer standard-output
17003 (help-mode))
17004 (print-help-return-message)))
17006 (defun vhdl-doc-mode ()
17007 "Display VHDL Mode documentation in *Help* buffer."
17008 (interactive)
17009 (unless (featurep 'xemacs)
17010 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17011 (with-output-to-temp-buffer
17012 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17013 (princ mode-name)
17014 (princ " mode:\n")
17015 (princ (documentation 'vhdl-mode))
17016 (with-current-buffer standard-output
17017 (help-mode))
17018 (print-help-return-message)))
17021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17023 (provide 'vhdl-mode)
17025 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17026 ;;; vhdl-mode.el ends here