Merge from emacs-23 branch, up to 2010-05-20T21:33:58Z!juri@jurta.org.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 ;; Free Software Foundation, Inc.
6
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
12
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.
17
18 (defconst vhdl-version "3.33.6"
19 "VHDL Mode version number.")
20
21 (defconst vhdl-time-stamp "2005-08-30"
22 "VHDL Mode time stamp for last update.")
23
24 ;; This file is part of GNU Emacs.
25
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.
30
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.
35
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/>.
38
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;; Commentary:
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42
43 ;; This package provides an Emacs major mode for editing VHDL code.
44 ;; It includes the following features:
45
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
68
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; Documentation
71
72 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
73
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; Emacs Versions
76
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)
79
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;; Installation
82
83 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
84
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':
88
89 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
90
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
95
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):
99
100 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
101 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
102
103 ;; More detailed installation instructions are included in the official
104 ;; VHDL Mode distribution.
105
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;; Acknowledgements
108
109 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
110 ;; and Steve Grout.
111
112 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
113 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
114
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.
121
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.
127
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129
130 ;;; Code:
131
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.")
137
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)
148
149
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 ;;; Variables
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153
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))))
163
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)))
171
172 ;; help string for user options
173 (defconst vhdl-name-doc-string "
174
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")
187
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 ;; User variables
190
191 (defgroup vhdl nil
192 "Customizations for VHDL Mode."
193 :prefix "vhdl-"
194 :group 'languages
195 ; :version "21.2" ; comment out for XEmacs
196 )
197
198 (defgroup vhdl-mode nil
199 "Customizations for modes."
200 :group 'vhdl)
201
202 (defcustom vhdl-indent-tabs-mode nil
203 "*Non-nil means indentation can insert tabs.
204 Overrides local variable `indent-tabs-mode'."
205 :type 'boolean
206 :group 'vhdl-mode)
207
208
209 (defgroup vhdl-compile nil
210 "Customizations for compilation."
211 :group 'vhdl)
212
213 (defcustom vhdl-compiler-alist
214 '(
215 ;; Cadence Leapfrog: cv -file test.vhd
216 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
217 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
218 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
219 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
220 ("\\1/entity" "\\2/\\1" "\\1/configuration"
221 "\\1/package" "\\1/body" downcase))
222 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
223 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
224 ;; (PLL_400X_TOP) is not declared [10.3].
225 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
226 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
227 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
228 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
229 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
230 ;; Ikos Voyager: analyze test.vhd
231 ;; analyze test.vhd
232 ;; E L4/C5: this library unit is inaccessible
233 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
234 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
235 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
236 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
237 nil)
238 ;; ModelSim, Model Technology: vcom test.vhd
239 ;; ERROR: test.vhd(14): Unknown identifier: positiv
240 ;; WARNING[2]: test.vhd(85): Possible infinite loop
241 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
242 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
243 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
244 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
245 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
246 "\\1/_primary.dat" "\\1/body.dat" downcase))
247 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
248 ;; test.vhd:34: error message
249 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
250 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
251 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
252 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
253 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
254 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
255 ;; ERROR: test.vhd(24): near "dnd": expecting: END
256 ;; WARNING[4]: test.vhd(30): A space is required between ...
257 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
258 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
259 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase))
262 ;; Savant: scram -publish-cc test.vhd
263 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
264 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
265 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
268 "\\1_config.vhdl" "\\1_package.vhdl"
269 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
270 ;; Simili: vhdlp -work test.vhd
271 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
272 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
273 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
274 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
275 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
276 "\\1/prim.var" "\\1/_body.var" downcase))
277 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
278 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
279 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
280 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
281 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
282 nil)
283 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
284 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
285 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
286 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
287 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
288 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
289 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
290 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
291 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
292 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
293 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
294 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
295 ;; Synplify:
296 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
297 ("Synplify" "n/a" "n/a" "make" "-f \\1"
298 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
299 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
300 nil)
301 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
302 ;; Compiling "test.vhd" line 1...
303 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
304 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
305 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
306 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
307 ("^ *Compiling \"\\(.+\\)\" " 1)
308 nil)
309 ;; VeriBest: vc vhdl test.vhd
310 ;; (no file name printed out!)
311 ;; 32: Z <= A and BitA ;
312 ;; ^^^^
313 ;; [Error] Name BITA is unknown
314 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
316 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
317 nil)
318 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
319 ;; Compiling "test.vhd" line 1...
320 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
321 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
323 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
324 ("^ *Compiling \"\\(.+\\)\" " 1)
325 nil)
326 )
327 "*List of available VHDL compilers and their properties.
328 Each list entry specifies the following items for a compiler:
329 Compiler:
330 Compiler name : name used in option `vhdl-compiler' to choose compiler
331 Compile command : command used for source file compilation
332 Compile options : compile options (\"\\1\" inserts library name)
333 Make command : command used for compilation using a Makefile
334 Make options : make options (\"\\1\" inserts Makefile name)
335 Generate Makefile: use built-in function or command to generate a Makefile
336 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
337 Library command : command to create library directory \(\"\\1\" inserts
338 library directory, \"\\2\" inserts library name)
339 Compile directory: where compilation is run and the Makefile is placed
340 Library directory: directory of default library
341 Makefile name : name of Makefile (default is \"Makefile\")
342 ID string : compiler identification string (see `vhdl-project-alist')
343 Error message:
344 Regexp : regular expression to match error messages (*)
345 File subexp index: index of subexpression that matches the file name
346 Line subexp index: index of subexpression that matches the line number
347 Column subexp idx: index of subexpression that matches the column number
348 File message:
349 Regexp : regular expression to match a file name message
350 File subexp index: index of subexpression that matches the file name
351 Unit-to-file name mapping: mapping of library unit names to names of files
352 generated by the compiler (used for Makefile generation)
353 To string : string a name is mapped to (\"\\1\" inserts the unit name,
354 \"\\2\" inserts the entity name for architectures)
355 Case adjustment : adjust case of inserted unit names
356
357 \(*) The regular expression must match the error message starting from the
358 beginning of the line (but not necessarily to the end of the line).
359
360 Compile options allows insertion of the library name (see `vhdl-project-alist')
361 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
362
363 For Makefile generation, the built-in function can be used (requires
364 specification of the unit-to-file name mapping). Alternatively, an
365 external command can be specified. Work directory allows specification of
366 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
367 used for Makefile generation). To use another library name than \"work\",
368 customize `vhdl-project-alist'. The library command is inserted in Makefiles
369 to automatically create the library directory if not existent.
370
371 Compile options, compile directory, library directory, and Makefile name are
372 overwritten by the project settings if a project is defined (see
373 `vhdl-project-alist'). Directory paths are relative to the source file
374 directory.
375
376 Some compilers do not include the file name in the error message, but print
377 out a file name message in advance. In this case, set \"File Subexp Index\"
378 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
379 If no file name at all is printed out, set both \"File Message\" entries to 0
380 \(a default file name message will be printed out instead, does not work in
381 XEmacs).
382
383 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
384 assigning its name to option `vhdl-compiler'.
385
386 Please send any missing or erroneous compiler properties to the maintainer for
387 updating.
388
389 NOTE: Activate new error and file message regexps and reflect the new setting
390 in the choice list of option `vhdl-compiler' by restarting Emacs."
391 :type '(repeat
392 (list :tag "Compiler" :indent 2
393 (string :tag "Compiler name ")
394 (string :tag "Compile command ")
395 (string :tag "Compile options " "-work \\1")
396 (string :tag "Make command " "make")
397 (string :tag "Make options " "-f \\1")
398 (choice :tag "Generate Makefile "
399 (const :tag "Built-in function" nil)
400 (string :tag "Command" "vmake \\2 > \\1"))
401 (string :tag "Library command " "mkdir \\1")
402 (directory :tag "Compile directory "
403 :validate vhdl-widget-directory-validate "./")
404 (directory :tag "Library directory "
405 :validate vhdl-widget-directory-validate "work/")
406 (file :tag "Makefile name " "Makefile")
407 (string :tag "ID string ")
408 (list :tag "Error message" :indent 4
409 (regexp :tag "Regexp ")
410 (integer :tag "File subexp index")
411 (integer :tag "Line subexp index")
412 (integer :tag "Column subexp idx"))
413 (list :tag "File message" :indent 4
414 (regexp :tag "Regexp ")
415 (integer :tag "File subexp index"))
416 (choice :tag "Unit-to-file name mapping"
417 :format "%t: %[Value Menu%] %v\n"
418 (const :tag "Not defined" nil)
419 (list :tag "To string" :indent 4
420 (string :tag "Entity " "\\1.vhd")
421 (string :tag "Architecture " "\\2_\\1.vhd")
422 (string :tag "Configuration " "\\1.vhd")
423 (string :tag "Package " "\\1.vhd")
424 (string :tag "Package Body " "\\1_body.vhd")
425 (choice :tag "Case adjustment "
426 (const :tag "None" identity)
427 (const :tag "Upcase" upcase)
428 (const :tag "Downcase" downcase))))))
429 :set (lambda (variable value)
430 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
431 :group 'vhdl-compile)
432
433 (defcustom vhdl-compiler "ModelSim"
434 "*Specifies the VHDL compiler to be used for syntax analysis.
435 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
436 :type (let ((alist vhdl-compiler-alist) list)
437 (while alist
438 (setq list (cons (list 'const (caar alist)) list))
439 (setq alist (cdr alist)))
440 (append '(choice) (nreverse list)))
441 :group 'vhdl-compile)
442
443 (defcustom vhdl-compile-use-local-error-regexp t
444 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
445 In this case, only error message regexps for VHDL compilers are active if
446 compilation is started from a VHDL buffer. Otherwise, the error message
447 regexps are appended to the predefined global regexps, and all regexps are
448 active all the time. Note that by doing that, the predefined global regexps
449 might result in erroneous parsing of error messages for some VHDL compilers.
450
451 NOTE: Activate the new setting by restarting Emacs."
452 :type 'boolean
453 :group 'vhdl-compile)
454
455 (defcustom vhdl-makefile-generation-hook nil
456 "*Functions to run at the end of Makefile generation.
457 Allows to insert user specific parts into a Makefile.
458
459 Example:
460 \(lambda nil
461 \(re-search-backward \"^# Rule for compiling entire design\")
462 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
463 :type 'hook
464 :group 'vhdl-compile)
465
466 (defcustom vhdl-default-library "work"
467 "*Name of default library.
468 Is overwritten by project settings if a project is active."
469 :type 'string
470 :group 'vhdl-compile)
471
472
473 (defgroup vhdl-project nil
474 "Customizations for projects."
475 :group 'vhdl)
476
477 (defcustom vhdl-project-alist
478 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
479 "~/example1/" ("src/system/" "src/components/") ""
480 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
481 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
482 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
483 ("Example 2" "Individual source files, multiple compilers in different directories"
484 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
485 nil "\\1/" "work" "\\1/work/" "Makefile" "")
486 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
487 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
488 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
489 -------------------------------------------------------------------------------
490 -- This is a multi-line project description
491 -- that can be used as a project dependent part of the file header.
492 "))
493 "*List of projects and their properties.
494 Name : name used in option `vhdl-project' to choose project
495 Title : title of project (single-line string)
496 Default directory: default project directory (absolute path)
497 Sources : a) source files : path + \"/\" + file name
498 b) directory : path + \"/\"
499 c) directory tree: \"-r \" + path + \"/\"
500 Exclude regexp : matches file/directory names to be excluded as sources
501 Compile options : project-specific options for each compiler
502 Compiler name : name of compiler for which these options are valid
503 Compile options: project-specific compiler options
504 (\"\\1\" inserts library name, \"\\2\" default options)
505 Make options: project-specific make options
506 (\"\\1\" inserts Makefile name, \"\\2\" default options)
507 Exceptions : file-specific exceptions
508 File name regexp: matches file names for which exceptions are valid
509 - Options : file-specific compiler options string
510 (\"\\1\" inserts library name, \"\\2\" default options,
511 \"\\3\" project-specific options)
512 - Do not compile: do not compile this file (in Makefile)
513 Compile directory: where compilation is run and the Makefile is placed
514 \(\"\\1\" inserts compiler ID string)
515 Library name : name of library (default is \"work\")
516 Library directory: path to library (\"\\1\" inserts compiler ID string)
517 Makefile name : name of Makefile
518 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
519 Description : description of project (multi-line string)
520
521 Project title and description are used to insert into the file header (see
522 option `vhdl-file-header').
523
524 The default directory must have an absolute path (use `M-TAB' for completion).
525 All other paths can be absolute or relative to the default directory. All
526 paths must end with '/'.
527
528 The design units found in the sources (files and directories) are shown in the
529 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
530 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
531 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
532 specified, the default directory is taken as source directory. Otherwise,
533 the default directory is only taken as source directory if there is a sources
534 entry with the empty string or \"./\". Exclude regexp allows to filter out
535 specific file and directory names from the list of sources (e.g. CVS
536 directories).
537
538 Files are compiled in the compile directory. Makefiles are also placed into
539 the compile directory. Library directory specifies which directory the
540 compiler compiles into (used to generate the Makefile).
541
542 Since different compile/library directories and Makefiles may exist for
543 different compilers within one project, these paths and names allow the
544 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
545 Compile options, compile directory, library directory, and Makefile name
546 overwrite the settings of the current compiler.
547
548 File-specific compiler options (highest priority) overwrite project-specific
549 options which overwrite default options (lowest priority). Lower priority
550 options can be inserted in higher priority options. This allows to reuse
551 default options (e.g. \"-file\") in project- or file-specific options (e.g.
552 \"-93 -file\").
553
554 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
555 by restarting Emacs."
556 :type `(repeat
557 (list :tag "Project" :indent 2
558 (string :tag "Name ")
559 (string :tag "Title ")
560 (directory :tag "Default directory"
561 :validate vhdl-widget-directory-validate
562 ,(abbreviate-file-name default-directory))
563 (repeat :tag "Sources " :indent 4
564 (directory :format " %v" "./"))
565 (regexp :tag "Exclude regexp ")
566 (repeat
567 :tag "Compile options " :indent 4
568 (list :tag "Compiler" :indent 6
569 ,(let ((alist vhdl-compiler-alist) list)
570 (while alist
571 (setq list (cons (list 'const (caar alist)) list))
572 (setq alist (cdr alist)))
573 (append '(choice :tag "Compiler name")
574 (nreverse list)))
575 (string :tag "Compile options" "\\2")
576 (string :tag "Make options " "\\2")
577 (repeat
578 :tag "Exceptions " :indent 8
579 (cons :format "%v"
580 (regexp :tag "File name regexp ")
581 (choice :format "%[Value Menu%] %v"
582 (string :tag "Options" "\\3")
583 (const :tag "Do not compile" nil))))))
584 (directory :tag "Compile directory"
585 :validate vhdl-widget-directory-validate "./")
586 (string :tag "Library name " "work")
587 (directory :tag "Library directory"
588 :validate vhdl-widget-directory-validate "work/")
589 (file :tag "Makefile name " "Makefile")
590 (string :tag "Description: (type `C-j' for newline)"
591 :format "%t\n%v\n")))
592 :set (lambda (variable value)
593 (vhdl-custom-set variable value
594 'vhdl-update-mode-menu
595 'vhdl-speedbar-refresh))
596 :group 'vhdl-project)
597
598 (defcustom vhdl-project nil
599 "*Specifies the default for the current project.
600 Select a project name from the ones defined in option `vhdl-project-alist'.
601 Is used to determine the project title and description to be inserted in file
602 headers and the source files/directories to be scanned in the hierarchy
603 browser. The current project can also be changed temporarily in the menu."
604 :type (let ((alist vhdl-project-alist) list)
605 (while alist
606 (setq list (cons (list 'const (caar alist)) list))
607 (setq alist (cdr alist)))
608 (append '(choice (const :tag "None" nil) (const :tag "--"))
609 (nreverse list)))
610 :group 'vhdl-project)
611
612 (defcustom vhdl-project-file-name '("\\1.prj")
613 "*List of file names/paths for importing/exporting project setups.
614 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
615 replaced by the user name (allows to have user-specific project setups).
616 The first entry is used as file name to import/export individual project
617 setups. All entries are used to automatically import project setups at
618 startup (see option `vhdl-project-auto-load'). Projects loaded from the
619 first entry are automatically made current. Hint: specify local project
620 setups in first entry, global setups in following entries; loading a local
621 project setup will make it current, while loading the global setups
622 is done without changing the current project.
623 Names can also have an absolute path (i.e. project setups can be stored
624 in global directories)."
625 :type '(repeat (string :tag "File name" "\\1.prj"))
626 :group 'vhdl-project)
627
628 (defcustom vhdl-project-auto-load '(startup)
629 "*Automatically load project setups from files.
630 All project setup files that match the file names specified in option
631 `vhdl-project-file-name' are automatically loaded. The project of the
632 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
633 entry is activated.
634 A project setup file can be obtained by exporting a project (see menu).
635 At startup: project setup file is loaded at Emacs startup"
636 :type '(set (const :tag "At startup" startup))
637 :group 'vhdl-project)
638
639 (defcustom vhdl-project-sort t
640 "*Non-nil means projects are displayed in alphabetical order."
641 :type 'boolean
642 :group 'vhdl-project)
643
644
645 (defgroup vhdl-style nil
646 "Customizations for coding styles."
647 :group 'vhdl
648 :group 'vhdl-template
649 :group 'vhdl-port
650 :group 'vhdl-compose)
651
652 (defcustom vhdl-standard '(87 nil)
653 "*VHDL standards used.
654 Basic standard:
655 VHDL'87 : IEEE Std 1076-1987
656 VHDL'93 : IEEE Std 1076-1993
657 Additional standards:
658 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
659 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
660
661 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
662 \"Activate Options\"."
663 :type '(list (choice :tag "Basic standard"
664 (const :tag "VHDL'87" 87)
665 (const :tag "VHDL'93" 93))
666 (set :tag "Additional standards" :indent 2
667 (const :tag "VHDL-AMS" ams)
668 (const :tag "Math packages" math)))
669 :set (lambda (variable value)
670 (vhdl-custom-set variable value
671 'vhdl-template-map-init
672 'vhdl-mode-abbrev-table-init
673 'vhdl-template-construct-alist-init
674 'vhdl-template-package-alist-init
675 'vhdl-update-mode-menu
676 'vhdl-words-init 'vhdl-font-lock-init))
677 :group 'vhdl-style)
678
679 (defcustom vhdl-basic-offset 2
680 "*Amount of basic offset used for indentation.
681 This value is used by + and - symbols in `vhdl-offsets-alist'."
682 :type 'integer
683 :group 'vhdl-style)
684
685 (defcustom vhdl-upper-case-keywords nil
686 "*Non-nil means convert keywords to upper case.
687 This is done when typed or expanded or by the fix case functions."
688 :type 'boolean
689 :set (lambda (variable value)
690 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
691 :group 'vhdl-style)
692
693 (defcustom vhdl-upper-case-types nil
694 "*Non-nil means convert standardized types to upper case.
695 This is done when expanded or by the fix case functions."
696 :type 'boolean
697 :set (lambda (variable value)
698 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
699 :group 'vhdl-style)
700
701 (defcustom vhdl-upper-case-attributes nil
702 "*Non-nil means convert standardized attributes to upper case.
703 This is done when expanded or by the fix case functions."
704 :type 'boolean
705 :set (lambda (variable value)
706 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
707 :group 'vhdl-style)
708
709 (defcustom vhdl-upper-case-enum-values nil
710 "*Non-nil means convert standardized enumeration values to upper case.
711 This is done when expanded or by the fix case functions."
712 :type 'boolean
713 :set (lambda (variable value)
714 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
715 :group 'vhdl-style)
716
717 (defcustom vhdl-upper-case-constants t
718 "*Non-nil means convert standardized constants to upper case.
719 This is done when expanded."
720 :type 'boolean
721 :set (lambda (variable value)
722 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
723 :group 'vhdl-style)
724
725 (defcustom vhdl-use-direct-instantiation 'standard
726 "*Non-nil means use VHDL'93 direct component instantiation.
727 Never : never
728 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
729 Always : always"
730 :type '(choice (const :tag "Never" never)
731 (const :tag "Standard" standard)
732 (const :tag "Always" always))
733 :group 'vhdl-style)
734
735
736 (defgroup vhdl-naming nil
737 "Customizations for naming conventions."
738 :group 'vhdl)
739
740 (defcustom vhdl-entity-file-name '(".*" . "\\&")
741 (concat
742 "*Specifies how the entity file name is obtained.
743 The entity file name can be obtained by modifying the entity name (e.g.
744 attaching or stripping off a substring). The file extension is automatically
745 taken from the file name of the current buffer."
746 vhdl-name-doc-string)
747 :type '(cons (regexp :tag "From regexp")
748 (string :tag "To string "))
749 :group 'vhdl-naming
750 :group 'vhdl-compose)
751
752 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
753 (concat
754 "*Specifies how the architecture file name is obtained.
755 The architecture file name can be obtained by modifying the entity
756 and/or architecture name (e.g. attaching or stripping off a substring). The
757 file extension is automatically taken from the file name of the current
758 buffer. The string that is matched against the regexp is the concatenation
759 of the entity and the architecture name separated by a space. This gives
760 access to both names (see default setting as example)."
761 vhdl-name-doc-string)
762 :type '(cons (regexp :tag "From regexp")
763 (string :tag "To string "))
764 :group 'vhdl-naming
765 :group 'vhdl-compose)
766
767 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
768 (concat
769 "*Specifies how the configuration file name is obtained.
770 The configuration file name can be obtained by modifying the configuration
771 name (e.g. attaching or stripping off a substring). The file extension is
772 automatically taken from the file name of the current buffer."
773 vhdl-name-doc-string)
774 :type '(cons (regexp :tag "From regexp")
775 (string :tag "To string "))
776 :group 'vhdl-naming
777 :group 'vhdl-compose)
778
779 (defcustom vhdl-package-file-name '(".*" . "\\&")
780 (concat
781 "*Specifies how the package file name is obtained.
782 The package file name can be obtained by modifying the package name (e.g.
783 attaching or stripping off a substring). The file extension is automatically
784 taken from the file name of the current buffer. Package files can be created
785 in a different directory by prepending a relative or absolute path to the
786 file name."
787 vhdl-name-doc-string)
788 :type '(cons (regexp :tag "From regexp")
789 (string :tag "To string "))
790 :group 'vhdl-naming
791 :group 'vhdl-compose)
792
793 (defcustom vhdl-file-name-case 'identity
794 "*Specifies how to change case for obtaining file names.
795 When deriving a file name from a VHDL unit name, case can be changed as
796 follows:
797 As Is: case is not changed (taken as is)
798 Lower Case: whole name is changed to lower case
799 Upper Case: whole name is changed to upper case
800 Capitalize: first letter of each word in name is capitalized"
801 :type '(choice (const :tag "As Is" identity)
802 (const :tag "Lower Case" downcase)
803 (const :tag "Upper Case" upcase)
804 (const :tag "Capitalize" capitalize))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
807
808
809 (defgroup vhdl-template nil
810 "Customizations for electrification."
811 :group 'vhdl)
812
813 (defcustom vhdl-electric-keywords '(vhdl user)
814 "*Type of keywords for which electrification is enabled.
815 VHDL keywords: invoke built-in templates
816 User keywords: invoke user models (see option `vhdl-model-alist')"
817 :type '(set (const :tag "VHDL keywords" vhdl)
818 (const :tag "User model keywords" user))
819 :set (lambda (variable value)
820 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
821 :group 'vhdl-template)
822
823 (defcustom vhdl-optional-labels 'process
824 "*Constructs for which labels are to be queried.
825 Template generators prompt for optional labels for:
826 None : no constructs
827 Processes only: processes only (also procedurals in VHDL-AMS)
828 All constructs: all constructs with optional labels and keyword END"
829 :type '(choice (const :tag "None" none)
830 (const :tag "Processes only" process)
831 (const :tag "All constructs" all))
832 :group 'vhdl-template)
833
834 (defcustom vhdl-insert-empty-lines 'unit
835 "*Specifies whether to insert empty lines in some templates.
836 This improves readability of code. Empty lines are inserted in:
837 None : no constructs
838 Design units only: entities, architectures, configurations, packages only
839 All constructs : also all constructs with BEGIN...END parts
840
841 Replaces option `vhdl-additional-empty-lines'."
842 :type '(choice (const :tag "None" none)
843 (const :tag "Design units only" unit)
844 (const :tag "All constructs" all))
845 :group 'vhdl-template
846 :group 'vhdl-port
847 :group 'vhdl-compose)
848
849 (defcustom vhdl-argument-list-indent nil
850 "*Non-nil means indent argument lists relative to opening parenthesis.
851 That is, argument, association, and port lists start on the same line as the
852 opening parenthesis and subsequent lines are indented accordingly.
853 Otherwise, lists start on a new line and are indented as normal code."
854 :type 'boolean
855 :group 'vhdl-template
856 :group 'vhdl-port
857 :group 'vhdl-compose)
858
859 (defcustom vhdl-association-list-with-formals t
860 "*Non-nil means write association lists with formal parameters.
861 Templates prompt for formal and actual parameters (ports/generics).
862 When pasting component instantiations, formals are included.
863 If nil, only a list of actual parameters is entered."
864 :type 'boolean
865 :group 'vhdl-template
866 :group 'vhdl-port
867 :group 'vhdl-compose)
868
869 (defcustom vhdl-conditions-in-parenthesis nil
870 "*Non-nil means place parenthesis around condition expressions."
871 :type 'boolean
872 :group 'vhdl-template)
873
874 (defcustom vhdl-zero-string "'0'"
875 "*String to use for a logic zero."
876 :type 'string
877 :group 'vhdl-template)
878
879 (defcustom vhdl-one-string "'1'"
880 "*String to use for a logic one."
881 :type 'string
882 :group 'vhdl-template)
883
884
885 (defgroup vhdl-header nil
886 "Customizations for file header."
887 :group 'vhdl-template
888 :group 'vhdl-compose)
889
890 (defcustom vhdl-file-header "\
891 -------------------------------------------------------------------------------
892 -- Title : <title string>
893 -- Project : <project>
894 -------------------------------------------------------------------------------
895 -- File : <filename>
896 -- Author : <author>
897 -- Company : <company>
898 -- Created : <date>
899 -- Last update: <date>
900 -- Platform : <platform>
901 -- Standard : <standard>
902 <projectdesc>-------------------------------------------------------------------------------
903 -- Description: <cursor>
904 <copyright>-------------------------------------------------------------------------------
905 -- Revisions :
906 -- Date Version Author Description
907 -- <date> 1.0 <login>\tCreated
908 -------------------------------------------------------------------------------
909
910 "
911 "*String or file to insert as file header.
912 If the string specifies an existing file name, the contents of the file is
913 inserted, otherwise the string itself is inserted as file header.
914 Type `C-j' for newlines.
915 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
916 if the header needs to be version controlled.
917
918 The following keywords for template generation are supported:
919 <filename> : replaced by the name of the buffer
920 <author> : replaced by the user name and email address
921 \(`user-full-name', `mail-host-address', `user-mail-address')
922 <login> : replaced by user login name (`user-login-name')
923 <company> : replaced by contents of option `vhdl-company-name'
924 <date> : replaced by the current date
925 <year> : replaced by the current year
926 <project> : replaced by title of current project (`vhdl-project')
927 <projectdesc> : replaced by description of current project (`vhdl-project')
928 <copyright> : replaced by copyright string (`vhdl-copyright-string')
929 <platform> : replaced by contents of option `vhdl-platform-spec'
930 <standard> : replaced by the VHDL language standard(s) used
931 <... string> : replaced by a queried string (\"...\" is the prompt word)
932 <title string>: replaced by file title in automatically generated files
933 <cursor> : final cursor position
934
935 The (multi-line) project description <projectdesc> can be used as a project
936 dependent part of the file header and can also contain the above keywords."
937 :type 'string
938 :group 'vhdl-header)
939
940 (defcustom vhdl-file-footer ""
941 "*String or file to insert as file footer.
942 If the string specifies an existing file name, the contents of the file is
943 inserted, otherwise the string itself is inserted as file footer (i.e. at
944 the end of the file).
945 Type `C-j' for newlines.
946 The same keywords as in option `vhdl-file-header' can be used."
947 :type 'string
948 :group 'vhdl-header)
949
950 (defcustom vhdl-company-name ""
951 "*Name of company to insert in file header.
952 See option `vhdl-file-header'."
953 :type 'string
954 :group 'vhdl-header)
955
956 (defcustom vhdl-copyright-string "\
957 -------------------------------------------------------------------------------
958 -- Copyright (c) <year> <company>
959 "
960 "*Copyright string to insert in file header.
961 Can be multi-line string (type `C-j' for newline) and contain other file
962 header keywords (see option `vhdl-file-header')."
963 :type 'string
964 :group 'vhdl-header)
965
966 (defcustom vhdl-platform-spec ""
967 "*Specification of VHDL platform to insert in file header.
968 The platform specification should contain names and versions of the
969 simulation and synthesis tools used.
970 See option `vhdl-file-header'."
971 :type 'string
972 :group 'vhdl-header)
973
974 (defcustom vhdl-date-format "%Y-%m-%d"
975 "*Specifies the date format to use in the header.
976 This string is passed as argument to the command `format-time-string'.
977 For more information on format strings, see the documentation for the
978 `format-time-string' command (C-h f `format-time-string')."
979 :type 'string
980 :group 'vhdl-header)
981
982 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
983 "*Prefix string of modification date in VHDL file header.
984 If actualization of the modification date is called (menu,
985 `\\[vhdl-template-modify]'), this string is searched and the rest
986 of the line replaced by the current date."
987 :type 'string
988 :group 'vhdl-header)
989
990 (defcustom vhdl-modify-date-on-saving t
991 "*Non-nil means update the modification date when the buffer is saved.
992 Calls function `\\[vhdl-template-modify]').
993
994 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
995 \"Activate Options\"."
996 :type 'boolean
997 :group 'vhdl-header)
998
999
1000 (defgroup vhdl-sequential-process nil
1001 "Customizations for sequential processes."
1002 :group 'vhdl-template)
1003
1004 (defcustom vhdl-reset-kind 'async
1005 "*Specifies which kind of reset to use in sequential processes."
1006 :type '(choice (const :tag "None" none)
1007 (const :tag "Synchronous" sync)
1008 (const :tag "Asynchronous" async))
1009 :group 'vhdl-sequential-process)
1010
1011 (defcustom vhdl-reset-active-high nil
1012 "*Non-nil means reset in sequential processes is active high.
1013 Otherwise, reset is active low."
1014 :type 'boolean
1015 :group 'vhdl-sequential-process)
1016
1017 (defcustom vhdl-clock-rising-edge t
1018 "*Non-nil means rising edge of clock triggers sequential processes.
1019 Otherwise, falling edge triggers."
1020 :type 'boolean
1021 :group 'vhdl-sequential-process)
1022
1023 (defcustom vhdl-clock-edge-condition 'standard
1024 "*Syntax of the clock edge condition.
1025 Standard: \"clk'event and clk = '1'\"
1026 Function: \"rising_edge(clk)\""
1027 :type '(choice (const :tag "Standard" standard)
1028 (const :tag "Function" function))
1029 :group 'vhdl-sequential-process)
1030
1031 (defcustom vhdl-clock-name ""
1032 "*Name of clock signal to use in templates."
1033 :type 'string
1034 :group 'vhdl-sequential-process)
1035
1036 (defcustom vhdl-reset-name ""
1037 "*Name of reset signal to use in templates."
1038 :type 'string
1039 :group 'vhdl-sequential-process)
1040
1041
1042 (defgroup vhdl-model nil
1043 "Customizations for user models."
1044 :group 'vhdl)
1045
1046 (defcustom vhdl-model-alist
1047 '(("Example Model"
1048 "<label> : process (<clock>, <reset>)
1049 begin -- process <label>
1050 if <reset> = '0' then -- asynchronous reset (active low)
1051 <cursor>
1052 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1053 if <enable> = '1' then -- synchronous load
1054
1055 end if;
1056 end if;
1057 end process <label>;"
1058 "e" ""))
1059 "*List of user models.
1060 VHDL models (templates) can be specified by the user in this list. They can be
1061 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1062 electrification (i.e. overriding existing or creating new keywords, see
1063 option `vhdl-electric-keywords').
1064 Name : name of model (string of words and spaces)
1065 String : string or name of file to be inserted as model (newline: `C-j')
1066 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1067 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1068 Keyword : keyword to invoke model
1069
1070 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1071 A prompt that appears several times is queried once and replaced throughout
1072 the model. Special prompts are:
1073 <clock> : name specified in `vhdl-clock-name' (if not empty)
1074 <reset> : name specified in `vhdl-reset-name' (if not empty)
1075 <cursor>: final cursor position
1076 File header prompts (see variable `vhdl-file-header') are automatically
1077 replaced, so that user models can also be used to insert different types of
1078 headers.
1079
1080 If the string specifies an existing file name, the contents of the file is
1081 inserted, otherwise the string itself is inserted.
1082 The code within the models should be correctly indented.
1083 Type `C-j' for newlines.
1084
1085 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1086 \"Activate Options\"."
1087 :type '(repeat (list :tag "Model" :indent 2
1088 (string :tag "Name ")
1089 (string :tag "String : (type `C-j' for newline)"
1090 :format "%t\n%v")
1091 (sexp :tag "Key binding" x)
1092 (string :tag "Keyword " :format "%t: %v\n")))
1093 :set (lambda (variable value)
1094 (vhdl-custom-set variable value
1095 'vhdl-model-map-init
1096 'vhdl-model-defun
1097 'vhdl-mode-abbrev-table-init
1098 'vhdl-update-mode-menu))
1099 :group 'vhdl-model)
1100
1101
1102 (defgroup vhdl-compose nil
1103 "Customizations for structural composition."
1104 :group 'vhdl)
1105
1106 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1107 (concat
1108 "*Specifies how the component architecture name is obtained.
1109 The component architecture name can be obtained by modifying the entity name
1110 \(e.g. attaching or stripping off a substring).
1111 If TO STRING is empty, the architecture name is queried."
1112 vhdl-name-doc-string)
1113 :type '(cons (regexp :tag "From regexp")
1114 (string :tag "To string "))
1115 :group 'vhdl-compose)
1116
1117 (defcustom vhdl-compose-configuration-name
1118 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1119 (concat
1120 "*Specifies how the configuration name is obtained.
1121 The configuration name can be obtained by modifying the entity and/or
1122 architecture name (e.g. attaching or stripping off a substring). The string
1123 that is matched against the regexp is the concatenation of the entity and the
1124 architecture name separated by a space. This gives access to both names (see
1125 default setting as example)."
1126 vhdl-name-doc-string)
1127 :type '(cons (regexp :tag "From regexp")
1128 (string :tag "To string "))
1129 :group 'vhdl-compose)
1130
1131 (defcustom vhdl-components-package-name
1132 '((".*" . "\\&_components") . "components")
1133 (concat
1134 "*Specifies how the name for the components package is obtained.
1135 The components package is a package containing all component declarations for
1136 the current design. Its name can be obtained by modifying the project name
1137 \(e.g. attaching or stripping off a substring). If no project is defined, the
1138 DIRECTORY entry is chosen."
1139 vhdl-name-doc-string)
1140 :type '(cons (cons :tag "Project" :indent 2
1141 (regexp :tag "From regexp")
1142 (string :tag "To string "))
1143 (string :tag "Directory:\n String "))
1144 :group 'vhdl-compose)
1145
1146 (defcustom vhdl-use-components-package nil
1147 "*Non-nil means use a separate components package for component declarations.
1148 Otherwise, component declarations are inserted and searched for in the
1149 architecture declarative parts."
1150 :type 'boolean
1151 :group 'vhdl-compose)
1152
1153 (defcustom vhdl-compose-include-header t
1154 "*Non-nil means include a header in automatically generated files."
1155 :type 'boolean
1156 :group 'vhdl-compose)
1157
1158 (defcustom vhdl-compose-create-files 'single
1159 "*Specifies whether new files should be created for the new component.
1160 The component's entity and architecture are inserted:
1161 None : in current buffer
1162 Single file : in new single file
1163 Separate files: in two separate files
1164 The file names are obtained from variables `vhdl-entity-file-name' and
1165 `vhdl-architecture-file-name'."
1166 :type '(choice (const :tag "None" none)
1167 (const :tag "Single file" single)
1168 (const :tag "Separate files" separate))
1169 :group 'vhdl-compose)
1170
1171 (defcustom vhdl-compose-configuration-create-file nil
1172 "*Specifies whether a new file should be created for the configuration.
1173 If non-nil, a new file is created for the configuration.
1174 The file name is obtained from variable `vhdl-configuration-file-name'."
1175 :type 'boolean
1176 :group 'vhdl-compose)
1177
1178 (defcustom vhdl-compose-configuration-hierarchical t
1179 "*Specifies whether hierarchical configurations should be created.
1180 If non-nil, automatically created configurations are hierarchical and include
1181 the whole hierarchy of subcomponents. Otherwise the configuration only
1182 includes one level of subcomponents."
1183 :type 'boolean
1184 :group 'vhdl-compose)
1185
1186 (defcustom vhdl-compose-configuration-use-subconfiguration t
1187 "*Specifies whether subconfigurations should be used inside configurations.
1188 If non-nil, automatically created configurations use configurations in binding
1189 indications for subcomponents, if such configurations exist. Otherwise,
1190 entities are used in binding indications for subcomponents."
1191 :type 'boolean
1192 :group 'vhdl-compose)
1193
1194
1195 (defgroup vhdl-port nil
1196 "Customizations for port translation functions."
1197 :group 'vhdl
1198 :group 'vhdl-compose)
1199
1200 (defcustom vhdl-include-port-comments nil
1201 "*Non-nil means include port comments when a port is pasted."
1202 :type 'boolean
1203 :group 'vhdl-port)
1204
1205 (defcustom vhdl-include-direction-comments nil
1206 "*Non-nil means include port direction in instantiations as comments."
1207 :type 'boolean
1208 :group 'vhdl-port)
1209
1210 (defcustom vhdl-include-type-comments nil
1211 "*Non-nil means include generic/port type in instantiations as comments."
1212 :type 'boolean
1213 :group 'vhdl-port)
1214
1215 (defcustom vhdl-include-group-comments 'never
1216 "*Specifies whether to include group comments and spacings.
1217 The comments and empty lines between groups of ports are pasted:
1218 Never : never
1219 Declarations: in entity/component/constant/signal declarations only
1220 Always : also in generic/port maps"
1221 :type '(choice (const :tag "Never" never)
1222 (const :tag "Declarations" decl)
1223 (const :tag "Always" always))
1224 :group 'vhdl-port)
1225
1226 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1227 (concat
1228 "*Specifies how actual port names are obtained from formal port names.
1229 In a component instantiation, an actual port name can be obtained by
1230 modifying the formal port name (e.g. attaching or stripping off a substring)."
1231 vhdl-name-doc-string)
1232 :type '(cons (regexp :tag "From regexp")
1233 (string :tag "To string "))
1234 :group 'vhdl-port)
1235
1236 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1237 (concat
1238 "*Specifies how an instance name is obtained.
1239 The instance name can be obtained by modifying the name of the component to be
1240 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1241 by a unique number (starting with 1).
1242 If TO STRING is empty, the instance name is queried."
1243 vhdl-name-doc-string)
1244 :type '(cons (regexp :tag "From regexp")
1245 (string :tag "To string "))
1246 :group 'vhdl-port)
1247
1248
1249 (defgroup vhdl-testbench nil
1250 "Customizations for testbench generation."
1251 :group 'vhdl-port)
1252
1253 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1254 (concat
1255 "*Specifies how the testbench entity name is obtained.
1256 The entity name of a testbench can be obtained by modifying the name of
1257 the component to be tested (e.g. attaching or stripping off a substring)."
1258 vhdl-name-doc-string)
1259 :type '(cons (regexp :tag "From regexp")
1260 (string :tag "To string "))
1261 :group 'vhdl-testbench)
1262
1263 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1264 (concat
1265 "*Specifies how the testbench architecture name is obtained.
1266 The testbench architecture name can be obtained by modifying the name of
1267 the component to be tested (e.g. attaching or stripping off a substring).
1268 If TO STRING is empty, the architecture name is queried."
1269 vhdl-name-doc-string)
1270 :type '(cons (regexp :tag "From regexp")
1271 (string :tag "To string "))
1272 :group 'vhdl-testbench)
1273
1274 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1275 (concat
1276 "*Specifies how the testbench configuration name is obtained.
1277 The configuration name of a testbench can be obtained by modifying the entity
1278 and/or architecture name (e.g. attaching or stripping off a substring). The
1279 string that is matched against the regexp is the concatenation of the entity
1280 and the architecture name separated by a space. This gives access to both
1281 names (see default setting as example)."
1282 vhdl-name-doc-string)
1283 :type '(cons (regexp :tag "From regexp")
1284 (string :tag "To string "))
1285 :group 'vhdl-testbench)
1286
1287 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1288 (concat
1289 "*Specifies how a DUT instance name is obtained.
1290 The design-under-test instance name (i.e. the component instantiated in the
1291 testbench) can be obtained by modifying the component name (e.g. attaching
1292 or stripping off a substring)."
1293 vhdl-name-doc-string)
1294 :type '(cons (regexp :tag "From regexp")
1295 (string :tag "To string "))
1296 :group 'vhdl-testbench)
1297
1298 (defcustom vhdl-testbench-include-header t
1299 "*Non-nil means include a header in automatically generated files."
1300 :type 'boolean
1301 :group 'vhdl-testbench)
1302
1303 (defcustom vhdl-testbench-declarations "\
1304 -- clock
1305 signal Clk : std_logic := '1';
1306 "
1307 "*String or file to be inserted in the testbench declarative part.
1308 If the string specifies an existing file name, the contents of the file is
1309 inserted, otherwise the string itself is inserted in the testbench
1310 architecture before the BEGIN keyword.
1311 Type `C-j' for newlines."
1312 :type 'string
1313 :group 'vhdl-testbench)
1314
1315 (defcustom vhdl-testbench-statements "\
1316 -- clock generation
1317 Clk <= not Clk after 10 ns;
1318
1319 -- waveform generation
1320 WaveGen_Proc: process
1321 begin
1322 -- insert signal assignments here
1323
1324 wait until Clk = '1';
1325 end process WaveGen_Proc;
1326 "
1327 "*String or file to be inserted in the testbench statement part.
1328 If the string specifies an existing file name, the contents of the file is
1329 inserted, otherwise the string itself is inserted in the testbench
1330 architecture before the END keyword.
1331 Type `C-j' for newlines."
1332 :type 'string
1333 :group 'vhdl-testbench)
1334
1335 (defcustom vhdl-testbench-initialize-signals nil
1336 "*Non-nil means initialize signals with `0' when declared in testbench."
1337 :type 'boolean
1338 :group 'vhdl-testbench)
1339
1340 (defcustom vhdl-testbench-include-library t
1341 "*Non-nil means a library/use clause for std_logic_1164 is included."
1342 :type 'boolean
1343 :group 'vhdl-testbench)
1344
1345 (defcustom vhdl-testbench-include-configuration t
1346 "*Non-nil means a testbench configuration is attached at the end."
1347 :type 'boolean
1348 :group 'vhdl-testbench)
1349
1350 (defcustom vhdl-testbench-create-files 'single
1351 "*Specifies whether new files should be created for the testbench.
1352 testbench entity and architecture are inserted:
1353 None : in current buffer
1354 Single file : in new single file
1355 Separate files: in two separate files
1356 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1357 and `vhdl-testbench-architecture-file-name'."
1358 :type '(choice (const :tag "None" none)
1359 (const :tag "Single file" single)
1360 (const :tag "Separate files" separate))
1361 :group 'vhdl-testbench)
1362
1363 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1364 (concat
1365 "*Specifies how the testbench entity file name is obtained.
1366 The entity file name can be obtained by modifying the testbench entity name
1367 \(e.g. attaching or stripping off a substring). The file extension is
1368 automatically taken from the file name of the current buffer. Testbench
1369 files can be created in a different directory by prepending a relative or
1370 absolute path to the file name."
1371 vhdl-name-doc-string)
1372 :type '(cons (regexp :tag "From regexp")
1373 (string :tag "To string "))
1374 :group 'vhdl-testbench)
1375
1376 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1377 (concat
1378 "*Specifies how the testbench architecture file name is obtained.
1379 The architecture file name can be obtained by modifying the testbench entity
1380 and/or architecture name (e.g. attaching or stripping off a substring). The
1381 string that is matched against the regexp is the concatenation of the entity
1382 and the architecture name separated by a space. This gives access to both
1383 names (see default setting as example). Testbench files can be created in
1384 a different directory by prepending a relative or absolute path to the file
1385 name."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1390
1391
1392 (defgroup vhdl-comment nil
1393 "Customizations for comments."
1394 :group 'vhdl)
1395
1396 (defcustom vhdl-self-insert-comments t
1397 "*Non-nil means various templates automatically insert help comments."
1398 :type 'boolean
1399 :group 'vhdl-comment)
1400
1401 (defcustom vhdl-prompt-for-comments t
1402 "*Non-nil means various templates prompt for user definable comments."
1403 :type 'boolean
1404 :group 'vhdl-comment)
1405
1406 (defcustom vhdl-inline-comment-column 40
1407 "*Column to indent and align inline comments to.
1408 Overrides local option `comment-column'.
1409
1410 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1411 \"Activate Options\"."
1412 :type 'integer
1413 :group 'vhdl-comment)
1414
1415 (defcustom vhdl-end-comment-column 79
1416 "*End of comment column.
1417 Comments that exceed this column number are wrapped.
1418
1419 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1420 \"Activate Options\"."
1421 :type 'integer
1422 :group 'vhdl-comment)
1423
1424 (defvar end-comment-column)
1425
1426
1427 (defgroup vhdl-align nil
1428 "Customizations for alignment."
1429 :group 'vhdl)
1430
1431 (defcustom vhdl-auto-align t
1432 "*Non-nil means align some templates automatically after generation."
1433 :type 'boolean
1434 :group 'vhdl-align)
1435
1436 (defcustom vhdl-align-groups t
1437 "*Non-nil means align groups of code lines separately.
1438 A group of code lines is a region of consecutive lines between two lines that
1439 match the regexp in option `vhdl-align-group-separate'."
1440 :type 'boolean
1441 :group 'vhdl-align)
1442
1443 (defcustom vhdl-align-group-separate "^\\s-*$"
1444 "*Regexp for matching a line that separates groups of lines for alignment.
1445 Examples:
1446 \"^\\s-*$\": matches an empty line
1447 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1448 :type 'regexp
1449 :group 'vhdl-align)
1450
1451 (defcustom vhdl-align-same-indent t
1452 "*Non-nil means align blocks with same indent separately.
1453 When a region or the entire buffer is aligned, the code is divided into
1454 blocks of same indent which are aligned separately (except for argument/port
1455 lists). This gives nicer alignment in most cases.
1456 Option `vhdl-align-groups' still applies within these blocks."
1457 :type 'boolean
1458 :group 'vhdl-align)
1459
1460
1461 (defgroup vhdl-highlight nil
1462 "Customizations for highlighting."
1463 :group 'vhdl)
1464
1465 (defcustom vhdl-highlight-keywords t
1466 "*Non-nil means highlight VHDL keywords and other standardized words.
1467 The following faces are used:
1468 `font-lock-keyword-face' : keywords
1469 `font-lock-type-face' : standardized types
1470 `vhdl-font-lock-attribute-face': standardized attributes
1471 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1472 `vhdl-font-lock-function-face' : standardized function and package names
1473
1474 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1475 entry \"Fontify Buffer\")."
1476 :type 'boolean
1477 :set (lambda (variable value)
1478 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1479 :group 'vhdl-highlight)
1480
1481 (defcustom vhdl-highlight-names t
1482 "*Non-nil means highlight declaration names and construct labels.
1483 The following faces are used:
1484 `font-lock-function-name-face' : names in declarations of units,
1485 subprograms, components, as well as labels of VHDL constructs
1486 `font-lock-type-face' : names in type/nature declarations
1487 `vhdl-font-lock-attribute-face': names in attribute declarations
1488 `font-lock-variable-name-face' : names in declarations of signals,
1489 variables, constants, subprogram parameters, generics, and ports
1490
1491 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1492 entry \"Fontify Buffer\")."
1493 :type 'boolean
1494 :set (lambda (variable value)
1495 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1496 :group 'vhdl-highlight)
1497
1498 (defcustom vhdl-highlight-special-words nil
1499 "*Non-nil means highlight words with special syntax.
1500 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1501 are highlighted accordingly.
1502 Can be used for visual support of naming conventions.
1503
1504 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1505 entry \"Fontify Buffer\")."
1506 :type 'boolean
1507 :set (lambda (variable value)
1508 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1509 :group 'vhdl-highlight)
1510
1511 (defcustom vhdl-highlight-forbidden-words nil
1512 "*Non-nil means highlight forbidden words.
1513 The reserved words specified in option `vhdl-forbidden-words' or having the
1514 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1515 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1516 use them.
1517
1518 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1519 entry \"Fontify Buffer\")."
1520 :type 'boolean
1521 :set (lambda (variable value)
1522 (vhdl-custom-set variable value
1523 'vhdl-words-init 'vhdl-font-lock-init))
1524 :group 'vhdl-highlight)
1525
1526 (defcustom vhdl-highlight-verilog-keywords nil
1527 "*Non-nil means highlight Verilog keywords as reserved words.
1528 Verilog keywords are highlighted in a warning color (face
1529 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1530
1531 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1532 entry \"Fontify Buffer\")."
1533 :type 'boolean
1534 :set (lambda (variable value)
1535 (vhdl-custom-set variable value
1536 'vhdl-words-init 'vhdl-font-lock-init))
1537 :group 'vhdl-highlight)
1538
1539 (defcustom vhdl-highlight-translate-off nil
1540 "*Non-nil means background-highlight code excluded from translation.
1541 That is, all code between \"-- pragma translate_off\" and
1542 \"-- pragma translate_on\" is highlighted using a different background color
1543 \(face `vhdl-font-lock-translate-off-face').
1544 Note: this might slow down on-the-fly fontification (and thus editing).
1545
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 'vhdl-font-lock-init))
1551 :group 'vhdl-highlight)
1552
1553 (defcustom vhdl-highlight-case-sensitive nil
1554 "*Non-nil means consider case for highlighting.
1555 Possible trade-off:
1556 non-nil also upper-case VHDL words are highlighted, but case of words with
1557 special syntax is not considered
1558 nil only lower-case VHDL words are highlighted, but case of words with
1559 special syntax is considered
1560 Overrides local option `font-lock-keywords-case-fold-search'.
1561
1562 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1563 entry \"Fontify Buffer\")."
1564 :type 'boolean
1565 :group 'vhdl-highlight)
1566
1567 (defcustom vhdl-special-syntax-alist
1568 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1569 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1570 ("variable" "\\w+_v" "Grey50" "Grey80"))
1571 "*List of special syntax to be highlighted.
1572 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1573 syntax (as regular expression) are highlighted in the corresponding color.
1574
1575 Name : string of words and spaces
1576 Regexp : regular expression describing word syntax
1577 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1578 Color (light): foreground color for light background
1579 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1580 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1581 Color (dark) : foreground color for dark background
1582 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1583 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1584
1585 Can be used for visual support of naming conventions, such as highlighting
1586 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1587 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1588 common substrings or name suffices.
1589 For each entry, a new face is generated with the specified colors and name
1590 \"vhdl-font-lock-\" + name + \"-face\".
1591
1592 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1593 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1594 :type '(repeat (list :tag "Face" :indent 2
1595 (string :tag "Name ")
1596 (regexp :tag "Regexp " "\\w+_")
1597 (string :tag "Color (light)")
1598 (string :tag "Color (dark) ")))
1599 :set (lambda (variable value)
1600 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1601 :group 'vhdl-highlight)
1602
1603 (defcustom vhdl-forbidden-words '()
1604 "*List of forbidden words to be highlighted.
1605 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1606 words are highlighted in a warning color to indicate not to use them.
1607
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type '(repeat (string :format "%v"))
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value
1613 'vhdl-words-init 'vhdl-font-lock-init))
1614 :group 'vhdl-highlight)
1615
1616 (defcustom vhdl-forbidden-syntax ""
1617 "*Syntax of forbidden words to be highlighted.
1618 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1619 syntax are highlighted in a warning color to indicate not to use them.
1620 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1621 highlights identifiers with 10 or more characters).
1622
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type 'regexp
1626 :set (lambda (variable value)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
1630
1631 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1632 "*List of compiler directive keywords recognized for highlighting.
1633
1634 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1635 entry \"Fontify Buffer\")."
1636 :type '(repeat (string :format "%v"))
1637 :set (lambda (variable value)
1638 (vhdl-custom-set variable value
1639 'vhdl-words-init 'vhdl-font-lock-init))
1640 :group 'vhdl-highlight)
1641
1642
1643 (defgroup vhdl-speedbar nil
1644 "Customizations for speedbar."
1645 :group 'vhdl)
1646
1647 (defcustom vhdl-speedbar-auto-open nil
1648 "*Non-nil means automatically open speedbar at startup.
1649 Alternatively, the speedbar can be opened from the VHDL menu."
1650 :type 'boolean
1651 :group 'vhdl-speedbar)
1652
1653 (defcustom vhdl-speedbar-display-mode 'files
1654 "*Specifies the default displaying mode when opening speedbar.
1655 Alternatively, the displaying mode can be selected from the speedbar menu or
1656 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1657 :type '(choice (const :tag "Files" files)
1658 (const :tag "Directory hierarchy" directory)
1659 (const :tag "Project hierarchy" project))
1660 :group 'vhdl-speedbar)
1661
1662 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1663 "*Limits scanning of large files and netlists.
1664 Design units: maximum file size to scan for design units
1665 Hierarchy (instances of subcomponents):
1666 File size: maximum file size to scan for instances (in bytes)
1667 Instances per arch: maximum number of instances to scan per architecture
1668
1669 \"None\" always means that there is no limit.
1670 In case of files not or incompletely scanned, a warning message and the file
1671 names are printed out.
1672 Background: scanning for instances is considerably slower than scanning for
1673 design units, especially when there are many instances. These limits should
1674 prevent the scanning of large netlists."
1675 :type '(list (choice :tag "Design units"
1676 :format "%t : %[Value Menu%] %v"
1677 (const :tag "None" nil)
1678 (integer :tag "File size"))
1679 (list :tag "Hierarchy" :indent 2
1680 (choice :tag "File size"
1681 :format "%t : %[Value Menu%] %v"
1682 (const :tag "None" nil)
1683 (integer :tag "Size "))
1684 (choice :tag "Instances per arch"
1685 (const :tag "None" nil)
1686 (integer :tag "Number "))))
1687 :group 'vhdl-speedbar)
1688
1689 (defcustom vhdl-speedbar-jump-to-unit t
1690 "*Non-nil means jump to the design unit code when opened in a buffer.
1691 The buffer cursor position is left unchanged otherwise."
1692 :type 'boolean
1693 :group 'vhdl-speedbar)
1694
1695 (defcustom vhdl-speedbar-update-on-saving t
1696 "*Automatically update design hierarchy when buffer is saved."
1697 :type 'boolean
1698 :group 'vhdl-speedbar)
1699
1700 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1701 "*Automatically save modified hierarchy caches when exiting Emacs.
1702 Hierarchy: design hierarchy information
1703 Display: displaying information (which design units to expand)"
1704 :type '(set (const :tag "Hierarchy" hierarchy)
1705 (const :tag "Display" display))
1706 :group 'vhdl-speedbar)
1707
1708 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1709 "*Name of file for saving hierarchy cache.
1710 \"\\1\" is replaced by the project name if a project is specified,
1711 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1712 different users to have cache files in the same directory). Can also have
1713 an absolute path (i.e. all caches can be stored in one global directory)."
1714 :type 'string
1715 :group 'vhdl-speedbar)
1716
1717
1718 (defgroup vhdl-menu nil
1719 "Customizations for menues."
1720 :group 'vhdl)
1721
1722 (defcustom vhdl-index-menu nil
1723 "*Non-nil means add an index menu for a source file when loading.
1724 Alternatively, the speedbar can be used. Note that the index menu scans a file
1725 when it is opened, while speedbar only scans the file upon request."
1726 :type 'boolean
1727 :group 'vhdl-menu)
1728
1729 (defcustom vhdl-source-file-menu nil
1730 "*Non-nil means add a menu of all source files in current directory.
1731 Alternatively, the speedbar can be used."
1732 :type 'boolean
1733 :group 'vhdl-menu)
1734
1735 (defcustom vhdl-hideshow-menu nil
1736 "*Non-nil means add hideshow menu and functionality at startup.
1737 Hideshow can also be enabled from the VHDL Mode menu.
1738 Hideshow allows hiding code of various VHDL constructs.
1739
1740 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1741 \"Activate Options\"."
1742 :type 'boolean
1743 :group 'vhdl-menu)
1744
1745 (defcustom vhdl-hide-all-init nil
1746 "*Non-nil means hide all design units initially after a file is loaded."
1747 :type 'boolean
1748 :group 'vhdl-menu)
1749
1750
1751 (defgroup vhdl-print nil
1752 "Customizations for printing."
1753 :group 'vhdl)
1754
1755 (defcustom vhdl-print-two-column t
1756 "*Non-nil means print code in two columns and landscape format.
1757 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1758 prints VHDL files in a nice two-column landscape style.
1759
1760 NOTE: Activate the new setting by restarting Emacs.
1761 Overrides `ps-print' settings locally."
1762 :type 'boolean
1763 :group 'vhdl-print)
1764
1765 (defcustom vhdl-print-customize-faces t
1766 "*Non-nil means use an optimized set of faces for postscript printing.
1767
1768 NOTE: Activate the new setting by restarting Emacs.
1769 Overrides `ps-print' settings locally."
1770 :type 'boolean
1771 :group 'vhdl-print)
1772
1773
1774 (defgroup vhdl-misc nil
1775 "Miscellaneous customizations."
1776 :group 'vhdl)
1777
1778 (defcustom vhdl-intelligent-tab t
1779 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1780 That is, if preceeding character is part of a word then complete word,
1781 else if not at beginning of line then insert tab,
1782 else if last command was a `TAB' or `RET' then dedent one step,
1783 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1784 If nil, TAB always indents current line (i.e. `TAB' is bound to
1785 `indent-according-to-mode').
1786
1787 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1789 :type 'boolean
1790 :group 'vhdl-misc)
1791
1792 (defcustom vhdl-indent-syntax-based t
1793 "*Non-nil means indent lines of code based on their syntactic context.
1794 Otherwise, a line is indented like the previous nonblank line. This can be
1795 useful in large files where syntax-based indentation gets very slow."
1796 :type 'boolean
1797 :group 'vhdl-misc)
1798
1799 (defcustom vhdl-word-completion-case-sensitive nil
1800 "*Non-nil means word completion using `TAB' is case sensitive.
1801 That is, `TAB' completes words that start with the same letters and case.
1802 Otherwise, case is ignored."
1803 :type 'boolean
1804 :group 'vhdl-misc)
1805
1806 (defcustom vhdl-word-completion-in-minibuffer t
1807 "*Non-nil enables word completion in minibuffer (for template prompts).
1808
1809 NOTE: Activate the new setting by restarting Emacs."
1810 :type 'boolean
1811 :group 'vhdl-misc)
1812
1813 (defcustom vhdl-underscore-is-part-of-word nil
1814 "*Non-nil means consider the underscore character `_' as part of word.
1815 An identifier containing underscores is then treated as a single word in
1816 select and move operations. All parts of an identifier separated by underscore
1817 are treated as single words otherwise.
1818
1819 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1820 \"Activate Options\"."
1821 :type 'boolean
1822 :set (lambda (variable value)
1823 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1824 :group 'vhdl-misc)
1825
1826
1827 (defgroup vhdl-related nil
1828 "Related general customizations."
1829 :group 'vhdl)
1830
1831 ;; add related general customizations
1832 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1833 (if (featurep 'xemacs)
1834 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1835 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1836 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1837 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1838 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1839 (unless (featurep 'xemacs)
1840 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1841 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1842 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1843 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1844
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846 ;; Internal variables
1847
1848 (defvar vhdl-menu-max-size 20
1849 "*Specifies the maximum size of a menu before splitting it into submenues.")
1850
1851 (defvar vhdl-progress-interval 1
1852 "*Interval used to update progress status during long operations.
1853 If a number, percentage complete gets updated after each interval of
1854 that many seconds. To inhibit all messages, set this option to nil.")
1855
1856 (defvar vhdl-inhibit-startup-warnings-p nil
1857 "*If non-nil, inhibits start up compatibility warnings.")
1858
1859 (defvar vhdl-strict-syntax-p nil
1860 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1861 If the syntactic symbol for a particular line does not match a symbol
1862 in the offsets alist, an error is generated, otherwise no error is
1863 reported and the syntactic symbol is ignored.")
1864
1865 (defvar vhdl-echo-syntactic-information-p nil
1866 "*If non-nil, syntactic info is echoed when the line is indented.")
1867
1868 (defconst vhdl-offsets-alist-default
1869 '((string . -1000)
1870 (cpp-macro . -1000)
1871 (block-open . 0)
1872 (block-close . 0)
1873 (statement . 0)
1874 (statement-cont . vhdl-lineup-statement-cont)
1875 (statement-block-intro . +)
1876 (statement-case-intro . +)
1877 (case-alternative . +)
1878 (comment . vhdl-lineup-comment)
1879 (arglist-intro . +)
1880 (arglist-cont . 0)
1881 (arglist-cont-nonempty . vhdl-lineup-arglist)
1882 (arglist-close . vhdl-lineup-arglist)
1883 (entity . 0)
1884 (configuration . 0)
1885 (package . 0)
1886 (architecture . 0)
1887 (package-body . 0)
1888 )
1889 "Default settings for offsets of syntactic elements.
1890 Do not change this constant! See the variable `vhdl-offsets-alist' for
1891 more information.")
1892
1893 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1894 "*Association list of syntactic element symbols and indentation offsets.
1895 As described below, each cons cell in this list has the form:
1896
1897 (SYNTACTIC-SYMBOL . OFFSET)
1898
1899 When a line is indented, `vhdl-mode' first determines the syntactic
1900 context of the line by generating a list of symbols called syntactic
1901 elements. This list can contain more than one syntactic element and
1902 the global variable `vhdl-syntactic-context' contains the context list
1903 for the line being indented. Each element in this list is actually a
1904 cons cell of the syntactic symbol and a buffer position. This buffer
1905 position is call the relative indent point for the line. Some
1906 syntactic symbols may not have a relative indent point associated with
1907 them.
1908
1909 After the syntactic context list for a line is generated, `vhdl-mode'
1910 calculates the absolute indentation for the line by looking at each
1911 syntactic element in the list. First, it compares the syntactic
1912 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1913 finds a match, it adds the OFFSET to the column of the relative indent
1914 point. The sum of this calculation for each element in the syntactic
1915 list is the absolute offset for line being indented.
1916
1917 If the syntactic element does not match any in the `vhdl-offsets-alist',
1918 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1919 the element is ignored.
1920
1921 Actually, OFFSET can be an integer, a function, a variable, or one of
1922 the following symbols: `+', `-', `++', or `--'. These latter
1923 designate positive or negative multiples of `vhdl-basic-offset',
1924 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1925 called with a single argument containing the cons of the syntactic
1926 element symbol and the relative indent point. The function should
1927 return an integer offset.
1928
1929 Here is the current list of valid syntactic element symbols:
1930
1931 string -- inside multi-line string
1932 block-open -- statement block open
1933 block-close -- statement block close
1934 statement -- a VHDL statement
1935 statement-cont -- a continuation of a VHDL statement
1936 statement-block-intro -- the first line in a new statement block
1937 statement-case-intro -- the first line in a case alternative block
1938 case-alternative -- a case statement alternative clause
1939 comment -- a line containing only a comment
1940 arglist-intro -- the first line in an argument list
1941 arglist-cont -- subsequent argument list lines when no
1942 arguments follow on the same line as the
1943 the arglist opening paren
1944 arglist-cont-nonempty -- subsequent argument list lines when at
1945 least one argument follows on the same
1946 line as the arglist opening paren
1947 arglist-close -- the solo close paren of an argument list
1948 entity -- inside an entity declaration
1949 configuration -- inside a configuration declaration
1950 package -- inside a package declaration
1951 architecture -- inside an architecture body
1952 package-body -- inside a package body")
1953
1954 (defvar vhdl-comment-only-line-offset 0
1955 "*Extra offset for line which contains only the start of a comment.
1956 Can contain an integer or a cons cell of the form:
1957
1958 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1959
1960 Where NON-ANCHORED-OFFSET is the amount of offset given to
1961 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1962 the amount of offset to give column-zero anchored comment-only lines.
1963 Just an integer as value is equivalent to (<val> . 0)")
1964
1965 (defvar vhdl-special-indent-hook nil
1966 "*Hook for user defined special indentation adjustments.
1967 This hook gets called after a line is indented by the mode.")
1968
1969 (defvar vhdl-style-alist
1970 '(("IEEE"
1971 (vhdl-basic-offset . 4)
1972 (vhdl-offsets-alist . ())))
1973 "Styles of Indentation.
1974 Elements of this alist are of the form:
1975
1976 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1977
1978 where STYLE-STRING is a short descriptive string used to select a
1979 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1980 value for that variable when using the selected style.
1981
1982 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1983 case, the VALUE is a list containing elements of the form:
1984
1985 (SYNTACTIC-SYMBOL . VALUE)
1986
1987 as described in `vhdl-offsets-alist'. These are passed directly to
1988 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1989 your style, only those that are different from the default.")
1990
1991 ;; dynamically append the default value of most variables
1992 (or (assoc "Default" vhdl-style-alist)
1993 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1994 vhdl-strict-syntax-p
1995 vhdl-echo-syntactic-information-p
1996 vhdl-basic-offset
1997 vhdl-offsets-alist
1998 vhdl-comment-only-line-offset))
1999 (default (cons "Default"
2000 (mapcar
2001 (function
2002 (lambda (var)
2003 (cons var (symbol-value var))))
2004 varlist))))
2005 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2006
2007 (defvar vhdl-mode-hook nil
2008 "*Hook called by `vhdl-mode'.")
2009
2010
2011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2012 ;;; Required packages
2013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2014
2015 ;; mandatory
2016 (require 'assoc)
2017 (require 'compile) ; XEmacs
2018 (require 'easymenu)
2019 (require 'hippie-exp)
2020
2021 ;; optional (minimize warning messages during compile)
2022 (eval-when-compile
2023 (require 'font-lock)
2024 (require 'ps-print)
2025 (require 'speedbar))
2026
2027
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029 ;;; Compatibility
2030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2031
2032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033 ;; XEmacs compatibility
2034
2035 ;; active regions
2036 (defun vhdl-keep-region-active ()
2037 "Do whatever is necessary to keep the region active in XEmacs.
2038 Ignore byte-compiler warnings you might see."
2039 (and (featurep 'xemacs)
2040 (setq zmacs-region-stays t)))
2041
2042 ;; `wildcard-to-regexp' is included only in XEmacs 21
2043 (unless (fboundp 'wildcard-to-regexp)
2044 (defun wildcard-to-regexp (wildcard)
2045 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2046 (let* ((i (string-match "[*?]" wildcard))
2047 (result (substring wildcard 0 i))
2048 (len (length wildcard)))
2049 (when i
2050 (while (< i len)
2051 (let ((ch (aref wildcard i)))
2052 (setq result (concat result
2053 (cond ((eq ch ?*) "[^\000]*")
2054 ((eq ch ??) "[^\000]")
2055 (t (char-to-string ch)))))
2056 (setq i (1+ i)))))
2057 (concat "\\`" result "\\'"))))
2058
2059 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2060 ;; `regexp-opt' accelerates fontification by 10-20%
2061 (unless (fboundp 'regexp-opt)
2062 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2063 (defun regexp-opt (strings &optional paren)
2064 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2065 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2066
2067 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2068 (unless (fboundp 'match-string-no-properties)
2069 (defalias 'match-string-no-properties 'match-string))
2070
2071 ;; `subst-char-in-string' undefined (XEmacs)
2072 (unless (fboundp 'subst-char-in-string)
2073 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2074 (let ((i (length string))
2075 (newstr (if inplace string (copy-sequence string))))
2076 (while (> i 0)
2077 (setq i (1- i))
2078 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2079 newstr)))
2080
2081 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2082 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2083 (not noninteractive))
2084 (load "itimer")
2085 (when (string< itimer-version "1.09")
2086 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2087 (beep) (sit-for 5)))
2088
2089 ;; `file-expand-wildcards' undefined (XEmacs)
2090 (unless (fboundp 'file-expand-wildcards)
2091 (defun file-expand-wildcards (pattern &optional full)
2092 "Taken from Emacs' `files.el'."
2093 (let* ((nondir (file-name-nondirectory pattern))
2094 (dirpart (file-name-directory pattern))
2095 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2096 (mapcar 'file-name-as-directory
2097 (file-expand-wildcards (directory-file-name dirpart)))
2098 (list dirpart)))
2099 contents)
2100 (while dirs
2101 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2102 (file-directory-p (directory-file-name (car dirs))))
2103 (let ((this-dir-contents
2104 (delq nil
2105 (mapcar #'(lambda (name)
2106 (unless (string-match "\\`\\.\\.?\\'"
2107 (file-name-nondirectory name))
2108 name))
2109 (directory-files (or (car dirs) ".") full
2110 (wildcard-to-regexp nondir))))))
2111 (setq contents
2112 (nconc
2113 (if (and (car dirs) (not full))
2114 (mapcar (function (lambda (name) (concat (car dirs) name)))
2115 this-dir-contents)
2116 this-dir-contents)
2117 contents))))
2118 (setq dirs (cdr dirs)))
2119 contents)))
2120
2121 ;; `member-ignore-case' undefined (XEmacs)
2122 (unless (fboundp 'member-ignore-case)
2123 (defalias 'member-ignore-case 'member))
2124
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2126 ;; Compatibility with older VHDL Mode versions
2127
2128 (defvar vhdl-warnings nil
2129 "Warnings to tell the user during start up.")
2130
2131 (defun vhdl-run-when-idle (secs repeat function)
2132 "Wait until idle, then run FUNCTION."
2133 (if (fboundp 'start-itimer)
2134 (start-itimer "vhdl-mode" function secs repeat t)
2135 ; (run-with-idle-timer secs repeat function)))
2136 ;; explicitely activate timer (necessary when Emacs is already idle)
2137 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2138
2139 (defun vhdl-warning-when-idle (&rest args)
2140 "Wait until idle, then print out warning STRING and beep."
2141 (if noninteractive
2142 (vhdl-warning (apply 'format args) t)
2143 (unless vhdl-warnings
2144 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2145 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2146
2147 (defun vhdl-warning (string &optional nobeep)
2148 "Print out warning STRING and beep."
2149 (message "WARNING: %s" string)
2150 (unless (or nobeep noninteractive) (beep)))
2151
2152 (defun vhdl-print-warnings ()
2153 "Print out messages in variable `vhdl-warnings'."
2154 (let ((no-warnings (length vhdl-warnings)))
2155 (setq vhdl-warnings (nreverse vhdl-warnings))
2156 (while vhdl-warnings
2157 (message "WARNING: %s" (car vhdl-warnings))
2158 (setq vhdl-warnings (cdr vhdl-warnings)))
2159 (beep)
2160 (when (> no-warnings 1)
2161 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2162
2163 ;; Backward compatibility checks and fixes
2164 ;; option `vhdl-compiler' changed format
2165 (unless (stringp vhdl-compiler)
2166 (setq vhdl-compiler "ModelSim")
2167 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2168
2169 ;; option `vhdl-standard' changed format
2170 (unless (listp vhdl-standard)
2171 (setq vhdl-standard '(87 nil))
2172 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2173
2174 ;; option `vhdl-model-alist' changed format
2175 (when (= (length (car vhdl-model-alist)) 3)
2176 (let ((old-alist vhdl-model-alist)
2177 new-alist)
2178 (while old-alist
2179 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2180 (setq old-alist (cdr old-alist)))
2181 (setq vhdl-model-alist (nreverse new-alist)))
2182 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2183
2184 ;; option `vhdl-project-alist' changed format
2185 (when (= (length (car vhdl-project-alist)) 3)
2186 (let ((old-alist vhdl-project-alist)
2187 new-alist)
2188 (while old-alist
2189 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2190 (setq old-alist (cdr old-alist)))
2191 (setq vhdl-project-alist (nreverse new-alist)))
2192 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2193
2194 ;; option `vhdl-project-alist' changed format (3.31.1)
2195 (when (= (length (car vhdl-project-alist)) 4)
2196 (let ((old-alist vhdl-project-alist)
2197 new-alist elem)
2198 (while old-alist
2199 (setq elem (car old-alist))
2200 (setq new-alist
2201 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2202 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2203 new-alist))
2204 (setq old-alist (cdr old-alist)))
2205 (setq vhdl-project-alist (nreverse new-alist)))
2206 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2207
2208 ;; option `vhdl-project-alist' changed format (3.31.12)
2209 (when (= (length (car vhdl-project-alist)) 10)
2210 (let ((tmp-alist vhdl-project-alist))
2211 (while tmp-alist
2212 (setcdr (nthcdr 3 (car tmp-alist))
2213 (cons "" (nthcdr 4 (car tmp-alist))))
2214 (setq tmp-alist (cdr tmp-alist))))
2215 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2216
2217 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2218 (when (= (length (car vhdl-compiler-alist)) 7)
2219 (let ((old-alist vhdl-compiler-alist)
2220 new-alist elem)
2221 (while old-alist
2222 (setq elem (car old-alist))
2223 (setq new-alist
2224 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2225 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2226 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2227 (nth 5 elem) (nth 6 elem) nil)
2228 new-alist))
2229 (setq old-alist (cdr old-alist)))
2230 (setq vhdl-compiler-alist (nreverse new-alist)))
2231 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2232
2233 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2234 (when (= (length (car vhdl-compiler-alist)) 12)
2235 (let ((tmp-alist vhdl-compiler-alist))
2236 (while tmp-alist
2237 (setcdr (nthcdr 4 (car tmp-alist))
2238 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2239 (setq tmp-alist (cdr tmp-alist))))
2240 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2241
2242 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2243 (when (= (length (car vhdl-compiler-alist)) 13)
2244 (let ((tmp-alist vhdl-compiler-alist))
2245 (while tmp-alist
2246 (setcdr (nthcdr 3 (car tmp-alist))
2247 (cons "" (nthcdr 4 (car tmp-alist))))
2248 (setq tmp-alist (cdr tmp-alist))))
2249 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2250
2251 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2252 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2253 (let ((tmp-alist vhdl-compiler-alist))
2254 (while tmp-alist
2255 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2256 '(0 . nil))
2257 (setq tmp-alist (cdr tmp-alist))))
2258 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2259
2260 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2261 (when (equal vhdl-project "")
2262 (setq vhdl-project nil)
2263 (customize-save-variable 'vhdl-project vhdl-project))
2264
2265 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2266 (when (stringp vhdl-project-file-name)
2267 (setq vhdl-project-file-name (list vhdl-project-file-name))
2268 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2269
2270 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2271 (if (not (boundp 'speedbar-indentation-width))
2272 (defvar speedbar-indentation-width 2)
2273 ;; set default to 2 if not already customized
2274 (unless (get 'speedbar-indentation-width 'saved-value)
2275 (setq speedbar-indentation-width 2)))
2276
2277
2278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279 ;;; Help functions / inline substitutions / macros
2280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2281
2282 (defun vhdl-standard-p (standard)
2283 "Check if STANDARD is specified as used standard."
2284 (or (eq standard (car vhdl-standard))
2285 (memq standard (cadr vhdl-standard))))
2286
2287 (defun vhdl-project-p (&optional warning)
2288 "Return non-nil if a project is displayed, i.e. directories or files are
2289 specified."
2290 (if (assoc vhdl-project vhdl-project-alist)
2291 vhdl-project
2292 (when (and vhdl-project warning)
2293 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2294 nil))
2295
2296 (defun vhdl-resolve-env-variable (string)
2297 "Resolve environment variables in STRING."
2298 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2299 (setq string (concat (match-string 1 string)
2300 (getenv (match-string 2 string))
2301 (match-string 4 string))))
2302 string)
2303
2304 (defun vhdl-default-directory ()
2305 "Return the default directory of the current project or the directory of the
2306 current buffer if no project is defined."
2307 (if (vhdl-project-p)
2308 (expand-file-name (vhdl-resolve-env-variable
2309 (nth 1 (aget vhdl-project-alist vhdl-project))))
2310 default-directory))
2311
2312 (defmacro vhdl-prepare-search-1 (&rest body)
2313 "Enable case insensitive search and switch to syntax table that includes '_',
2314 then execute BODY, and finally restore the old environment. Used for
2315 consistent searching."
2316 `(let ((case-fold-search t)) ; case insensitive search
2317 ;; use extended syntax table
2318 (with-syntax-table vhdl-mode-ext-syntax-table
2319 ,@body)))
2320
2321 (defmacro vhdl-prepare-search-2 (&rest body)
2322 "Enable case insensitive search, switch to syntax table that includes '_',
2323 and remove `intangible' overlays, then execute BODY, and finally restore the
2324 old environment. Used for consistent searching."
2325 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2326 `(let ((case-fold-search t) ; case insensitive search
2327 (current-syntax-table (syntax-table))
2328 overlay-all-list overlay-intangible-list overlay)
2329 ;; use extended syntax table
2330 (set-syntax-table vhdl-mode-ext-syntax-table)
2331 ;; remove `intangible' overlays
2332 (when (fboundp 'overlay-lists)
2333 (setq overlay-all-list (overlay-lists))
2334 (setq overlay-all-list
2335 (append (car overlay-all-list) (cdr overlay-all-list)))
2336 (while overlay-all-list
2337 (setq overlay (car overlay-all-list))
2338 (when (memq 'intangible (overlay-properties overlay))
2339 (setq overlay-intangible-list
2340 (cons overlay overlay-intangible-list))
2341 (overlay-put overlay 'intangible nil))
2342 (setq overlay-all-list (cdr overlay-all-list))))
2343 ;; execute BODY safely
2344 (unwind-protect
2345 (progn ,@body)
2346 ;; restore syntax table
2347 (set-syntax-table current-syntax-table)
2348 ;; restore `intangible' overlays
2349 (when (fboundp 'overlay-lists)
2350 (while overlay-intangible-list
2351 (overlay-put (car overlay-intangible-list) 'intangible t)
2352 (setq overlay-intangible-list
2353 (cdr overlay-intangible-list)))))))
2354
2355 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2356 "Visit file FILE-NAME and execute BODY."
2357 `(if (null ,file-name)
2358 (progn ,@body)
2359 (unless (file-directory-p ,file-name)
2360 (let ((source-buffer (current-buffer))
2361 (visiting-buffer (find-buffer-visiting ,file-name))
2362 file-opened)
2363 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2364 (condition-case ()
2365 (progn (set-buffer (create-file-buffer ,file-name))
2366 (setq file-opened t)
2367 (vhdl-insert-file-contents ,file-name)
2368 (modify-syntax-entry ?\- ". 12" (syntax-table))
2369 (modify-syntax-entry ?\n ">" (syntax-table))
2370 (modify-syntax-entry ?\^M ">" (syntax-table))
2371 (modify-syntax-entry ?_ "w" (syntax-table))
2372 t)
2373 (error
2374 (if ,issue-error
2375 (progn
2376 (when file-opened (kill-buffer (current-buffer)))
2377 (set-buffer source-buffer)
2378 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2379 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2380 nil))))
2381 (condition-case info
2382 (progn ,@body)
2383 (error
2384 (if ,issue-error
2385 (progn
2386 (when file-opened (kill-buffer (current-buffer)))
2387 (set-buffer source-buffer)
2388 (error (cadr info)))
2389 (vhdl-warning (cadr info))))))
2390 (when file-opened (kill-buffer (current-buffer)))
2391 (set-buffer source-buffer)))))
2392
2393 (defun vhdl-insert-file-contents (filename)
2394 "Nicked from `insert-file-contents-literally', but allow coding system
2395 conversion."
2396 (let ((format-alist nil)
2397 (after-insert-file-functions nil)
2398 (jka-compr-compression-info-list nil))
2399 (insert-file-contents filename t)))
2400
2401 (defun vhdl-sort-alist (alist)
2402 "Sort ALIST."
2403 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2404
2405 (defun vhdl-get-subdirs (directory)
2406 "Recursively get subdirectories of DIRECTORY."
2407 (let ((dir-list (list (file-name-as-directory directory)))
2408 file-list)
2409 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2410 (while file-list
2411 (when (file-directory-p (car file-list))
2412 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2413 (setq file-list (cdr file-list)))
2414 dir-list))
2415
2416 (defun vhdl-aput (alist-symbol key &optional value)
2417 "As `aput', but delete key-value pair if VALUE is nil."
2418 (if value
2419 (aput alist-symbol key value)
2420 (adelete alist-symbol key)))
2421
2422 (defun vhdl-delete (elt list)
2423 "Delete by side effect the first occurrence of ELT as a member of LIST."
2424 (setq list (cons nil list))
2425 (let ((list1 list))
2426 (while (and (cdr list1) (not (equal elt (cadr list1))))
2427 (setq list1 (cdr list1)))
2428 (when list
2429 (setcdr list1 (cddr list1))))
2430 (cdr list))
2431
2432 (defun vhdl-speedbar-refresh (&optional key)
2433 "Refresh directory or project with name KEY."
2434 (when (and (boundp 'speedbar-frame)
2435 (frame-live-p speedbar-frame))
2436 (let ((pos (point))
2437 (last-frame (selected-frame)))
2438 (if (null key)
2439 (speedbar-refresh)
2440 (select-frame speedbar-frame)
2441 (when (save-excursion
2442 (goto-char (point-min))
2443 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2444 (goto-char (match-end 1))
2445 (speedbar-do-function-pointer)
2446 (backward-char 2)
2447 (speedbar-do-function-pointer)
2448 (message "Refreshing speedbar...done"))
2449 (select-frame last-frame)))))
2450
2451 (defun vhdl-show-messages ()
2452 "Get *Messages* buffer to show recent messages."
2453 (interactive)
2454 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2455
2456 (defun vhdl-use-direct-instantiation ()
2457 "Return whether direct instantiation is used."
2458 (or (eq vhdl-use-direct-instantiation 'always)
2459 (and (eq vhdl-use-direct-instantiation 'standard)
2460 (not (vhdl-standard-p '87)))))
2461
2462 (defun vhdl-max-marker (marker1 marker2)
2463 "Return larger marker."
2464 (if (> marker1 marker2) marker1 marker2))
2465
2466 (defun vhdl-goto-marker (marker)
2467 "Goto marker in appropriate buffer."
2468 (when (markerp marker)
2469 (set-buffer (marker-buffer marker)))
2470 (goto-char marker))
2471
2472 (defun vhdl-menu-split (list title)
2473 "Split menu LIST into several submenues, if number of
2474 elements > `vhdl-menu-max-size'."
2475 (if (> (length list) vhdl-menu-max-size)
2476 (let ((remain list)
2477 (result '())
2478 (sublist '())
2479 (menuno 1)
2480 (i 0))
2481 (while remain
2482 (setq sublist (cons (car remain) sublist))
2483 (setq remain (cdr remain))
2484 (setq i (+ i 1))
2485 (if (= i vhdl-menu-max-size)
2486 (progn
2487 (setq result (cons (cons (format "%s %s" title menuno)
2488 (nreverse sublist)) result))
2489 (setq i 0)
2490 (setq menuno (+ menuno 1))
2491 (setq sublist '()))))
2492 (and sublist
2493 (setq result (cons (cons (format "%s %s" title menuno)
2494 (nreverse sublist)) result)))
2495 (nreverse result))
2496 list))
2497
2498
2499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2500 ;;; Bindings
2501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2502
2503 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2504 ;; Key bindings
2505
2506 (defvar vhdl-template-map nil
2507 "Keymap for VHDL templates.")
2508
2509 (defun vhdl-template-map-init ()
2510 "Initialize `vhdl-template-map'."
2511 (setq vhdl-template-map (make-sparse-keymap))
2512 ;; key bindings for VHDL templates
2513 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2514 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2515 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2516 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2517 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2518 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2519 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2520 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2521 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2522 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2523 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2524 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2525 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2526 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2527 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2528 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2529 (define-key vhdl-template-map "el" 'vhdl-template-else)
2530 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2531 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2532 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2533 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2534 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2535 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2536 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2537 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2538 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2539 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2540 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2541 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2542 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2543 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2544 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2545 (define-key vhdl-template-map "li" 'vhdl-template-library)
2546 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2547 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2548 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2549 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2550 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2551 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2552 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2553 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2554 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2555 (define-key vhdl-template-map "po" 'vhdl-template-port)
2556 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2557 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2558 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2559 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2560 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2561 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2562 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2563 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2564 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2565 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2566 (define-key vhdl-template-map "us" 'vhdl-template-use)
2567 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2568 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2569 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2570 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2571 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2572 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2573 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2574 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2575 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2576 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2577 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2578 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2579 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2580 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2581 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2582 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2583 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2584 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2585 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2586 (when (vhdl-standard-p 'ams)
2587 (define-key vhdl-template-map "br" 'vhdl-template-break)
2588 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2589 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2590 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2591 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2592 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2593 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2594 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2595 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2596 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2597 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2598 )
2599 (when (vhdl-standard-p 'math)
2600 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2601 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2602 ))
2603
2604 ;; initialize template map for VHDL Mode
2605 (vhdl-template-map-init)
2606
2607 (defun vhdl-function-name (prefix string &optional postfix)
2608 "Generate a Lisp function name.
2609 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2610 STRING are replaced by `-' and substrings are converted to lower case."
2611 (let ((name prefix))
2612 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2613 (setq name
2614 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2615 (setq string (substring string (match-beginning 2))))
2616 (when postfix (setq name (concat name "-" postfix)))
2617 (intern name)))
2618
2619 (defvar vhdl-model-map nil
2620 "Keymap for VHDL models.")
2621
2622 (defun vhdl-model-map-init ()
2623 "Initialize `vhdl-model-map'."
2624 (setq vhdl-model-map (make-sparse-keymap))
2625 ;; key bindings for VHDL models
2626 (let ((model-alist vhdl-model-alist) model)
2627 (while model-alist
2628 (setq model (car model-alist))
2629 (define-key vhdl-model-map (nth 2 model)
2630 (vhdl-function-name "vhdl-model" (nth 0 model)))
2631 (setq model-alist (cdr model-alist)))))
2632
2633 ;; initialize user model map for VHDL Mode
2634 (vhdl-model-map-init)
2635
2636 (defvar vhdl-mode-map nil
2637 "Keymap for VHDL Mode.")
2638
2639 (defun vhdl-mode-map-init ()
2640 "Initialize `vhdl-mode-map'."
2641 (setq vhdl-mode-map (make-sparse-keymap))
2642 ;; template key bindings
2643 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2644 ;; model key bindings
2645 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2646 ;; standard key bindings
2647 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2648 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2649 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2650 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2651 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2652 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2653 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2654 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2655 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2656 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2657 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2658 ;; backspace/delete key bindings
2659 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2660 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2661 (define-key vhdl-mode-map [delete] 'delete-char)
2662 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2663 ;; mode specific key bindings
2664 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2665 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2666 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2668 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2669 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2670 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2671 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2672 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2673 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2674 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2675 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2678 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2679 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2680 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2681 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2682 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2684 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2685 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2686 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2687 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2688 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2689 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2692 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2693 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2694 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2698 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2699 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2700 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2701 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2702 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2703 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2704 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2705 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2709 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2710 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2711 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2712 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2713 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2714 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2717 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2718 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2719 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2720 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2721 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2722 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2723 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2727 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2728 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2729 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2730 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2731 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2732 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2733 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2734 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2735 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2736 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2737 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2740 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2741 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2742 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2743 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2744 ;; insert commands bindings
2745 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2746 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2747 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2748 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2749 ;; electric key bindings
2750 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2751 (when vhdl-intelligent-tab
2752 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2753 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2754 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2755 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2756 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2757 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2758 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2759 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2760 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2761 (when (vhdl-standard-p 'ams)
2762 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2763
2764 ;; initialize mode map for VHDL Mode
2765 (vhdl-mode-map-init)
2766
2767 ;; define special minibuffer keymap for enabling word completion in minibuffer
2768 ;; (useful in template generator prompts)
2769 (defvar vhdl-minibuffer-local-map
2770 (let ((map (make-sparse-keymap)))
2771 (set-keymap-parent map minibuffer-local-map)
2772 (when vhdl-word-completion-in-minibuffer
2773 (define-key map "\t" 'vhdl-minibuffer-tab))
2774 map)
2775 "Keymap for minibuffer used in VHDL Mode.")
2776
2777 ;; set up electric character functions to work with
2778 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2779 (mapc
2780 (function
2781 (lambda (sym)
2782 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2783 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2784 '(vhdl-electric-space
2785 vhdl-electric-tab
2786 vhdl-electric-return
2787 vhdl-electric-dash
2788 vhdl-electric-open-bracket
2789 vhdl-electric-close-bracket
2790 vhdl-electric-quote
2791 vhdl-electric-semicolon
2792 vhdl-electric-comma
2793 vhdl-electric-period
2794 vhdl-electric-equal))
2795
2796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2797 ;; Syntax table
2798
2799 (defvar vhdl-mode-syntax-table nil
2800 "Syntax table used in `vhdl-mode' buffers.")
2801
2802 (defvar vhdl-mode-ext-syntax-table nil
2803 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2804
2805 (defun vhdl-mode-syntax-table-init ()
2806 "Initialize `vhdl-mode-syntax-table'."
2807 (setq vhdl-mode-syntax-table (make-syntax-table))
2808 ;; define punctuation
2809 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2810 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2811 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2812 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2813 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2814 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2815 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2816 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2817 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2818 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2819 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2820 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2821 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2822 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2823 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2824 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2825 ;; define string
2826 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2827 ;; define underscore
2828 (when vhdl-underscore-is-part-of-word
2829 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2830 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2831 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2832 ;; and \n and \^M end a comment
2833 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2835 ;; define parentheses to match
2836 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2839 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2840 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2841 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2842 ;; extended syntax table including '_' (for simpler search regexps)
2843 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2844 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2845
2846 ;; initialize syntax table for VHDL Mode
2847 (vhdl-mode-syntax-table-init)
2848
2849 (defvar vhdl-syntactic-context nil
2850 "Buffer local variable containing syntactic analysis list.")
2851 (make-variable-buffer-local 'vhdl-syntactic-context)
2852
2853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2854 ;; Abbrev ook bindings
2855
2856 (defvar vhdl-mode-abbrev-table nil
2857 "Abbrev table to use in `vhdl-mode' buffers.")
2858
2859 (defun vhdl-mode-abbrev-table-init ()
2860 "Initialize `vhdl-mode-abbrev-table'."
2861 (define-abbrev-table 'vhdl-mode-abbrev-table
2862 (append
2863 (when (memq 'vhdl vhdl-electric-keywords)
2864 ;; VHDL'93 keywords
2865 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2866 '(
2867 ("--" . vhdl-template-display-comment-hook)
2868 ("abs" . vhdl-template-default-hook)
2869 ("access" . vhdl-template-default-hook)
2870 ("after" . vhdl-template-default-hook)
2871 ("alias" . vhdl-template-alias-hook)
2872 ("all" . vhdl-template-default-hook)
2873 ("and" . vhdl-template-default-hook)
2874 ("arch" . vhdl-template-architecture-hook)
2875 ("architecture" . vhdl-template-architecture-hook)
2876 ("array" . vhdl-template-default-hook)
2877 ("assert" . vhdl-template-assert-hook)
2878 ("attr" . vhdl-template-attribute-hook)
2879 ("attribute" . vhdl-template-attribute-hook)
2880 ("begin" . vhdl-template-default-indent-hook)
2881 ("block" . vhdl-template-block-hook)
2882 ("body" . vhdl-template-default-hook)
2883 ("buffer" . vhdl-template-default-hook)
2884 ("bus" . vhdl-template-default-hook)
2885 ("case" . vhdl-template-case-hook)
2886 ("comp" . vhdl-template-component-hook)
2887 ("component" . vhdl-template-component-hook)
2888 ("cond" . vhdl-template-conditional-signal-asst-hook)
2889 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2890 ("conf" . vhdl-template-configuration-hook)
2891 ("configuration" . vhdl-template-configuration-hook)
2892 ("cons" . vhdl-template-constant-hook)
2893 ("constant" . vhdl-template-constant-hook)
2894 ("disconnect" . vhdl-template-disconnect-hook)
2895 ("downto" . vhdl-template-default-hook)
2896 ("else" . vhdl-template-else-hook)
2897 ("elseif" . vhdl-template-elsif-hook)
2898 ("elsif" . vhdl-template-elsif-hook)
2899 ("end" . vhdl-template-default-indent-hook)
2900 ("entity" . vhdl-template-entity-hook)
2901 ("exit" . vhdl-template-exit-hook)
2902 ("file" . vhdl-template-file-hook)
2903 ("for" . vhdl-template-for-hook)
2904 ("func" . vhdl-template-function-hook)
2905 ("function" . vhdl-template-function-hook)
2906 ("generic" . vhdl-template-generic-hook)
2907 ("group" . vhdl-template-group-hook)
2908 ("guarded" . vhdl-template-default-hook)
2909 ("if" . vhdl-template-if-hook)
2910 ("impure" . vhdl-template-default-hook)
2911 ("in" . vhdl-template-default-hook)
2912 ("inertial" . vhdl-template-default-hook)
2913 ("inout" . vhdl-template-default-hook)
2914 ("inst" . vhdl-template-instance-hook)
2915 ("instance" . vhdl-template-instance-hook)
2916 ("is" . vhdl-template-default-hook)
2917 ("label" . vhdl-template-default-hook)
2918 ("library" . vhdl-template-library-hook)
2919 ("linkage" . vhdl-template-default-hook)
2920 ("literal" . vhdl-template-default-hook)
2921 ("loop" . vhdl-template-bare-loop-hook)
2922 ("map" . vhdl-template-map-hook)
2923 ("mod" . vhdl-template-default-hook)
2924 ("nand" . vhdl-template-default-hook)
2925 ("new" . vhdl-template-default-hook)
2926 ("next" . vhdl-template-next-hook)
2927 ("nor" . vhdl-template-default-hook)
2928 ("not" . vhdl-template-default-hook)
2929 ("null" . vhdl-template-default-hook)
2930 ("of" . vhdl-template-default-hook)
2931 ("on" . vhdl-template-default-hook)
2932 ("open" . vhdl-template-default-hook)
2933 ("or" . vhdl-template-default-hook)
2934 ("others" . vhdl-template-others-hook)
2935 ("out" . vhdl-template-default-hook)
2936 ("pack" . vhdl-template-package-hook)
2937 ("package" . vhdl-template-package-hook)
2938 ("port" . vhdl-template-port-hook)
2939 ("postponed" . vhdl-template-default-hook)
2940 ("procedure" . vhdl-template-procedure-hook)
2941 ("process" . vhdl-template-process-hook)
2942 ("pure" . vhdl-template-default-hook)
2943 ("range" . vhdl-template-default-hook)
2944 ("record" . vhdl-template-default-hook)
2945 ("register" . vhdl-template-default-hook)
2946 ("reject" . vhdl-template-default-hook)
2947 ("rem" . vhdl-template-default-hook)
2948 ("report" . vhdl-template-report-hook)
2949 ("return" . vhdl-template-return-hook)
2950 ("rol" . vhdl-template-default-hook)
2951 ("ror" . vhdl-template-default-hook)
2952 ("select" . vhdl-template-selected-signal-asst-hook)
2953 ("severity" . vhdl-template-default-hook)
2954 ("shared" . vhdl-template-default-hook)
2955 ("sig" . vhdl-template-signal-hook)
2956 ("signal" . vhdl-template-signal-hook)
2957 ("sla" . vhdl-template-default-hook)
2958 ("sll" . vhdl-template-default-hook)
2959 ("sra" . vhdl-template-default-hook)
2960 ("srl" . vhdl-template-default-hook)
2961 ("subtype" . vhdl-template-subtype-hook)
2962 ("then" . vhdl-template-default-hook)
2963 ("to" . vhdl-template-default-hook)
2964 ("transport" . vhdl-template-default-hook)
2965 ("type" . vhdl-template-type-hook)
2966 ("unaffected" . vhdl-template-default-hook)
2967 ("units" . vhdl-template-default-hook)
2968 ("until" . vhdl-template-default-hook)
2969 ("use" . vhdl-template-use-hook)
2970 ("var" . vhdl-template-variable-hook)
2971 ("variable" . vhdl-template-variable-hook)
2972 ("wait" . vhdl-template-wait-hook)
2973 ("when" . vhdl-template-when-hook)
2974 ("while" . vhdl-template-while-loop-hook)
2975 ("with" . vhdl-template-with-hook)
2976 ("xnor" . vhdl-template-default-hook)
2977 ("xor" . vhdl-template-default-hook)
2978 )))
2979 ;; VHDL-AMS keywords
2980 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2981 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2982 '(
2983 ("across" . vhdl-template-default-hook)
2984 ("break" . vhdl-template-break-hook)
2985 ("limit" . vhdl-template-limit-hook)
2986 ("nature" . vhdl-template-nature-hook)
2987 ("noise" . vhdl-template-default-hook)
2988 ("procedural" . vhdl-template-procedural-hook)
2989 ("quantity" . vhdl-template-quantity-hook)
2990 ("reference" . vhdl-template-default-hook)
2991 ("spectrum" . vhdl-template-default-hook)
2992 ("subnature" . vhdl-template-subnature-hook)
2993 ("terminal" . vhdl-template-terminal-hook)
2994 ("through" . vhdl-template-default-hook)
2995 ("tolerance" . vhdl-template-default-hook)
2996 )))
2997 ;; user model keywords
2998 (when (memq 'user vhdl-electric-keywords)
2999 (let (abbrev-list keyword)
3000 (dolist (elem vhdl-model-alist)
3001 (setq keyword (nth 3 elem))
3002 (unless (equal keyword "")
3003 (push (list keyword ""
3004 (vhdl-function-name
3005 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3006 abbrev-list)))
3007 abbrev-list)))))
3008
3009 ;; initialize abbrev table for VHDL Mode
3010 (vhdl-mode-abbrev-table-init)
3011
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013 ;; Template completion lists
3014
3015 (defvar vhdl-template-construct-alist nil
3016 "List of built-in construct templates.")
3017
3018 (defun vhdl-template-construct-alist-init ()
3019 "Initialize `vhdl-template-construct-alist'."
3020 (setq
3021 vhdl-template-construct-alist
3022 (append
3023 '(
3024 ("alias declaration" vhdl-template-alias)
3025 ("architecture body" vhdl-template-architecture)
3026 ("assertion" vhdl-template-assert)
3027 ("attribute declaration" vhdl-template-attribute-decl)
3028 ("attribute specification" vhdl-template-attribute-spec)
3029 ("block configuration" vhdl-template-block-configuration)
3030 ("block statement" vhdl-template-block)
3031 ("case statement" vhdl-template-case-is)
3032 ("component configuration" vhdl-template-component-conf)
3033 ("component declaration" vhdl-template-component-decl)
3034 ("component instantiation statement" vhdl-template-component-inst)
3035 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3036 ("configuration declaration" vhdl-template-configuration-decl)
3037 ("configuration specification" vhdl-template-configuration-spec)
3038 ("constant declaration" vhdl-template-constant)
3039 ("disconnection specification" vhdl-template-disconnect)
3040 ("entity declaration" vhdl-template-entity)
3041 ("exit statement" vhdl-template-exit)
3042 ("file declaration" vhdl-template-file)
3043 ("generate statement" vhdl-template-generate)
3044 ("generic clause" vhdl-template-generic)
3045 ("group declaration" vhdl-template-group-decl)
3046 ("group template declaration" vhdl-template-group-template)
3047 ("if statement" vhdl-template-if-then)
3048 ("library clause" vhdl-template-library)
3049 ("loop statement" vhdl-template-loop)
3050 ("next statement" vhdl-template-next)
3051 ("package declaration" vhdl-template-package-decl)
3052 ("package body" vhdl-template-package-body)
3053 ("port clause" vhdl-template-port)
3054 ("process statement" vhdl-template-process)
3055 ("report statement" vhdl-template-report)
3056 ("return statement" vhdl-template-return)
3057 ("selected signal assignment" vhdl-template-selected-signal-asst)
3058 ("signal declaration" vhdl-template-signal)
3059 ("subprogram declaration" vhdl-template-subprogram-decl)
3060 ("subprogram body" vhdl-template-subprogram-body)
3061 ("subtype declaration" vhdl-template-subtype)
3062 ("type declaration" vhdl-template-type)
3063 ("use clause" vhdl-template-use)
3064 ("variable declaration" vhdl-template-variable)
3065 ("wait statement" vhdl-template-wait)
3066 )
3067 (when (vhdl-standard-p 'ams)
3068 '(
3069 ("break statement" vhdl-template-break)
3070 ("nature declaration" vhdl-template-nature)
3071 ("quantity declaration" vhdl-template-quantity)
3072 ("simultaneous case statement" vhdl-template-case-use)
3073 ("simultaneous if statement" vhdl-template-if-use)
3074 ("simultaneous procedural statement" vhdl-template-procedural)
3075 ("step limit specification" vhdl-template-limit)
3076 ("subnature declaration" vhdl-template-subnature)
3077 ("terminal declaration" vhdl-template-terminal)
3078 )))))
3079
3080 ;; initialize for VHDL Mode
3081 (vhdl-template-construct-alist-init)
3082
3083 (defvar vhdl-template-package-alist nil
3084 "List of built-in package templates.")
3085
3086 (defun vhdl-template-package-alist-init ()
3087 "Initialize `vhdl-template-package-alist'."
3088 (setq
3089 vhdl-template-package-alist
3090 (append
3091 '(
3092 ("numeric_bit" vhdl-template-package-numeric-bit)
3093 ("numeric_std" vhdl-template-package-numeric-std)
3094 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3095 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3096 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3097 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3098 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3099 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3100 ("textio" vhdl-template-package-textio)
3101 )
3102 (when (vhdl-standard-p 'math)
3103 '(
3104 ("math_complex" vhdl-template-package-math-complex)
3105 ("math_real" vhdl-template-package-math-real)
3106 )))))
3107
3108 ;; initialize for VHDL Mode
3109 (vhdl-template-package-alist-init)
3110
3111 (defvar vhdl-template-directive-alist
3112 '(
3113 ("translate_on" vhdl-template-directive-translate-on)
3114 ("translate_off" vhdl-template-directive-translate-off)
3115 ("synthesis_on" vhdl-template-directive-synthesis-on)
3116 ("synthesis_off" vhdl-template-directive-synthesis-off)
3117 )
3118 "List of built-in directive templates.")
3119
3120
3121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3122 ;;; Menues
3123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3124
3125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3126 ;; VHDL menu (using `easy-menu.el')
3127
3128 (defun vhdl-customize ()
3129 "Call the customize function with `vhdl' as argument."
3130 (interactive)
3131 (customize-browse 'vhdl))
3132
3133 (defun vhdl-create-mode-menu ()
3134 "Create VHDL Mode menu."
3135 `("VHDL"
3136 ,(append
3137 '("Project"
3138 ["None" (vhdl-set-project "")
3139 :style radio :selected (null vhdl-project)]
3140 "--")
3141 ;; add menu entries for defined projects
3142 (let ((project-alist vhdl-project-alist) menu-list name)
3143 (while project-alist
3144 (setq name (caar project-alist))
3145 (setq menu-list
3146 (cons `[,name (vhdl-set-project ,name)
3147 :style radio :selected (equal ,name vhdl-project)]
3148 menu-list))
3149 (setq project-alist (cdr project-alist)))
3150 (setq menu-list
3151 (if vhdl-project-sort
3152 (sort menu-list
3153 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3154 (nreverse menu-list)))
3155 (vhdl-menu-split menu-list "Project"))
3156 '("--" "--"
3157 ["Select Project..." vhdl-set-project t]
3158 ["Set As Default Project" vhdl-set-default-project t]
3159 "--"
3160 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3161 ["Import Project..." vhdl-import-project
3162 :keys "C-c C-p C-m" :active t]
3163 ["Export Project" vhdl-export-project vhdl-project]
3164 "--"
3165 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3166 "--"
3167 ("Compile"
3168 ["Compile Buffer" vhdl-compile t]
3169 ["Stop Compilation" kill-compilation t]
3170 "--"
3171 ["Make" vhdl-make t]
3172 ["Generate Makefile" vhdl-generate-makefile t]
3173 "--"
3174 ["Next Error" next-error t]
3175 ["Previous Error" previous-error t]
3176 ["First Error" first-error t]
3177 "--"
3178 ,(append
3179 '("Compiler")
3180 ;; add menu entries for defined compilers
3181 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3182 (while comp-alist
3183 (setq name (caar comp-alist))
3184 (setq menu-list
3185 (cons `[,name (setq vhdl-compiler ,name)
3186 :style radio :selected (equal ,name vhdl-compiler)]
3187 menu-list))
3188 (setq comp-alist (cdr comp-alist)))
3189 (setq menu-list (nreverse menu-list))
3190 (vhdl-menu-split menu-list "Compiler"))
3191 '("--" "--"
3192 ["Select Compiler..." vhdl-set-compiler t]
3193 "--"
3194 ["Customize Compiler..."
3195 (customize-option 'vhdl-compiler-alist) t])))
3196 "--"
3197 ,(append
3198 '("Template"
3199 ("VHDL Construct 1"
3200 ["Alias" vhdl-template-alias t]
3201 ["Architecture" vhdl-template-architecture t]
3202 ["Assert" vhdl-template-assert t]
3203 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3204 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3205 ["Block" vhdl-template-block t]
3206 ["Case" vhdl-template-case-is t]
3207 ["Component (Decl)" vhdl-template-component-decl t]
3208 ["(Component) Instance" vhdl-template-component-inst t]
3209 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3210 ["Configuration (Block)" vhdl-template-block-configuration t]
3211 ["Configuration (Comp)" vhdl-template-component-conf t]
3212 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3213 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3214 ["Constant" vhdl-template-constant t]
3215 ["Disconnect" vhdl-template-disconnect t]
3216 ["Else" vhdl-template-else t]
3217 ["Elsif" vhdl-template-elsif t]
3218 ["Entity" vhdl-template-entity t]
3219 ["Exit" vhdl-template-exit t]
3220 ["File" vhdl-template-file t]
3221 ["For (Generate)" vhdl-template-for-generate t]
3222 ["For (Loop)" vhdl-template-for-loop t]
3223 ["Function (Body)" vhdl-template-function-body t]
3224 ["Function (Decl)" vhdl-template-function-decl t]
3225 ["Generic" vhdl-template-generic t]
3226 ["Group (Decl)" vhdl-template-group-decl t]
3227 ["Group (Template)" vhdl-template-group-template t])
3228 ("VHDL Construct 2"
3229 ["If (Generate)" vhdl-template-if-generate t]
3230 ["If (Then)" vhdl-template-if-then t]
3231 ["Library" vhdl-template-library t]
3232 ["Loop" vhdl-template-bare-loop t]
3233 ["Map" vhdl-template-map t]
3234 ["Next" vhdl-template-next t]
3235 ["Others (Aggregate)" vhdl-template-others t]
3236 ["Package (Decl)" vhdl-template-package-decl t]
3237 ["Package (Body)" vhdl-template-package-body t]
3238 ["Port" vhdl-template-port t]
3239 ["Procedure (Body)" vhdl-template-procedure-body t]
3240 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3241 ["Process (Comb)" vhdl-template-process-comb t]
3242 ["Process (Seq)" vhdl-template-process-seq t]
3243 ["Report" vhdl-template-report t]
3244 ["Return" vhdl-template-return t]
3245 ["Select" vhdl-template-selected-signal-asst t]
3246 ["Signal" vhdl-template-signal t]
3247 ["Subtype" vhdl-template-subtype t]
3248 ["Type" vhdl-template-type t]
3249 ["Use" vhdl-template-use t]
3250 ["Variable" vhdl-template-variable t]
3251 ["Wait" vhdl-template-wait t]
3252 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3253 ["When" vhdl-template-when t]
3254 ["While (Loop)" vhdl-template-while-loop t]
3255 ["With" vhdl-template-with t]))
3256 (when (vhdl-standard-p 'ams)
3257 '(("VHDL-AMS Construct"
3258 ["Break" vhdl-template-break t]
3259 ["Case (Use)" vhdl-template-case-use t]
3260 ["If (Use)" vhdl-template-if-use t]
3261 ["Limit" vhdl-template-limit t]
3262 ["Nature" vhdl-template-nature t]
3263 ["Procedural" vhdl-template-procedural t]
3264 ["Quantity (Free)" vhdl-template-quantity-free t]
3265 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3266 ["Quantity (Source)" vhdl-template-quantity-source t]
3267 ["Subnature" vhdl-template-subnature t]
3268 ["Terminal" vhdl-template-terminal t])))
3269 '(["Insert Construct..." vhdl-template-insert-construct
3270 :keys "C-c C-i C-t"]
3271 "--")
3272 (list
3273 (append
3274 '("Package")
3275 (when (vhdl-standard-p 'math)
3276 '(["math_complex" vhdl-template-package-math-complex t]
3277 ["math_real" vhdl-template-package-math-real t]))
3278 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3279 ["numeric_std" vhdl-template-package-numeric-std t]
3280 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3281 ["textio" vhdl-template-package-textio t]
3282 "--"
3283 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3284 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3285 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3286 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3287 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3288 "--"
3289 ["Insert Package..." vhdl-template-insert-package
3290 :keys "C-c C-i C-p"])))
3291 '(("Directive"
3292 ["translate_on" vhdl-template-directive-translate-on t]
3293 ["translate_off" vhdl-template-directive-translate-off t]
3294 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3295 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3296 "--"
3297 ["Insert Directive..." vhdl-template-insert-directive
3298 :keys "C-c C-i C-d"])
3299 "--"
3300 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3301 ["Insert Footer" vhdl-template-footer t]
3302 ["Insert Date" vhdl-template-insert-date t]
3303 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3304 "--"
3305 ["Query Next Prompt" vhdl-template-search-prompt t]))
3306 ,(append
3307 '("Model")
3308 ;; add menu entries for defined models
3309 (let ((model-alist vhdl-model-alist) menu-list model)
3310 (while model-alist
3311 (setq model (car model-alist))
3312 (setq menu-list
3313 (cons
3314 (vector
3315 (nth 0 model)
3316 (vhdl-function-name "vhdl-model" (nth 0 model))
3317 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3318 menu-list))
3319 (setq model-alist (cdr model-alist)))
3320 (setq menu-list (nreverse menu-list))
3321 (vhdl-menu-split menu-list "Model"))
3322 '("--" "--"
3323 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3324 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3325 ("Port"
3326 ["Copy" vhdl-port-copy t]
3327 "--"
3328 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3329 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3330 ["Paste As Instance" vhdl-port-paste-instance
3331 :keys "C-c C-p C-i" :active vhdl-port-list]
3332 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3333 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3334 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3335 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3336 "--"
3337 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3338 "--"
3339 ["Flatten" vhdl-port-flatten
3340 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3341 ["Reverse Direction" vhdl-port-reverse-direction
3342 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3343 ("Compose"
3344 ["New Component" vhdl-compose-new-component t]
3345 ["Copy Component" vhdl-port-copy t]
3346 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3347 ["Wire Components" vhdl-compose-wire-components t]
3348 "--"
3349 ["Generate Configuration" vhdl-compose-configuration t]
3350 ["Generate Components Package" vhdl-compose-components-package t])
3351 ("Subprogram"
3352 ["Copy" vhdl-subprog-copy t]
3353 "--"
3354 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3355 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3356 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3357 "--"
3358 ["Flatten" vhdl-subprog-flatten
3359 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3360 "--"
3361 ("Comment"
3362 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3363 "--"
3364 ["Insert Inline Comment" vhdl-comment-append-inline t]
3365 ["Insert Horizontal Line" vhdl-comment-display-line t]
3366 ["Insert Display Comment" vhdl-comment-display t]
3367 "--"
3368 ["Fill Comment" fill-paragraph t]
3369 ["Fill Comment Region" fill-region (mark)]
3370 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3371 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3372 ("Line"
3373 ["Kill" vhdl-line-kill t]
3374 ["Copy" vhdl-line-copy t]
3375 ["Yank" vhdl-line-yank t]
3376 ["Expand" vhdl-line-expand t]
3377 "--"
3378 ["Transpose Next" vhdl-line-transpose-next t]
3379 ["Transpose Prev" vhdl-line-transpose-previous t]
3380 ["Open" vhdl-line-open t]
3381 ["Join" vhdl-delete-indentation t]
3382 "--"
3383 ["Goto" goto-line t]
3384 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3385 ("Move"
3386 ["Forward Statement" vhdl-end-of-statement t]
3387 ["Backward Statement" vhdl-beginning-of-statement t]
3388 ["Forward Expression" vhdl-forward-sexp t]
3389 ["Backward Expression" vhdl-backward-sexp t]
3390 ["Forward Same Indent" vhdl-forward-same-indent t]
3391 ["Backward Same Indent" vhdl-backward-same-indent t]
3392 ["Forward Function" vhdl-end-of-defun t]
3393 ["Backward Function" vhdl-beginning-of-defun t]
3394 ["Mark Function" vhdl-mark-defun t])
3395 "--"
3396 ("Indent"
3397 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3398 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3399 ["Region" vhdl-indent-region (mark)]
3400 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3401 ("Align"
3402 ["Group" vhdl-align-group t]
3403 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3404 ["List" vhdl-align-list t]
3405 ["Declarations" vhdl-align-declarations t]
3406 ["Region" vhdl-align-region (mark)]
3407 ["Buffer" vhdl-align-buffer t]
3408 "--"
3409 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3410 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3411 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3412 ("Fill"
3413 ["List" vhdl-fill-list t]
3414 ["Group" vhdl-fill-group t]
3415 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3416 ["Region" vhdl-fill-region (mark)])
3417 ("Beautify"
3418 ["Region" vhdl-beautify-region (mark)]
3419 ["Buffer" vhdl-beautify-buffer t])
3420 ("Fix"
3421 ["Generic/Port Clause" vhdl-fix-clause t]
3422 "--"
3423 ["Case Region" vhdl-fix-case-region (mark)]
3424 ["Case Buffer" vhdl-fix-case-buffer t]
3425 "--"
3426 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3427 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3428 "--"
3429 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3430 ("Update"
3431 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3432 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3433 "--"
3434 ["Fontify Buffer" vhdl-fontify-buffer t]
3435 ["Statistics Buffer" vhdl-statistics-buffer t]
3436 ["Show Messages" vhdl-show-messages t]
3437 ["Syntactic Info" vhdl-show-syntactic-information t]
3438 "--"
3439 ["Speedbar" vhdl-speedbar t]
3440 ["Hide/Show" vhdl-hs-minor-mode t]
3441 "--"
3442 ("Documentation"
3443 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3444 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3445 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3446 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3447 ["Version" vhdl-version t]
3448 ["Bug Report..." vhdl-submit-bug-report t]
3449 "--"
3450 ("Options"
3451 ("Mode"
3452 ["Electric Mode"
3453 (progn (customize-set-variable 'vhdl-electric-mode
3454 (not vhdl-electric-mode)))
3455 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3456 ["Stutter Mode"
3457 (progn (customize-set-variable 'vhdl-stutter-mode
3458 (not vhdl-stutter-mode)))
3459 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3460 ["Indent Tabs Mode"
3461 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3462 (not vhdl-indent-tabs-mode))
3463 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3464 :style toggle :selected vhdl-indent-tabs-mode]
3465 "--"
3466 ["Customize Group..." (customize-group 'vhdl-mode) t])
3467 ("Project"
3468 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3469 ,(append
3470 '("Selected Project at Startup"
3471 ["None" (progn (customize-set-variable 'vhdl-project nil)
3472 (vhdl-set-project ""))
3473 :style radio :selected (null vhdl-project)]
3474 "--")
3475 ;; add menu entries for defined projects
3476 (let ((project-alist vhdl-project-alist) menu-list name)
3477 (while project-alist
3478 (setq name (caar project-alist))
3479 (setq menu-list
3480 (cons `[,name (progn (customize-set-variable
3481 'vhdl-project ,name)
3482 (vhdl-set-project ,name))
3483 :style radio :selected (equal ,name vhdl-project)]
3484 menu-list))
3485 (setq project-alist (cdr project-alist)))
3486 (setq menu-list (nreverse menu-list))
3487 (vhdl-menu-split menu-list "Project")))
3488 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3489 ("Auto Load Setup File"
3490 ["At Startup"
3491 (customize-set-variable 'vhdl-project-auto-load
3492 (if (memq 'startup vhdl-project-auto-load)
3493 (delq 'startup vhdl-project-auto-load)
3494 (cons 'startup vhdl-project-auto-load)))
3495 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3496 ["Sort Projects"
3497 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3498 :style toggle :selected vhdl-project-sort]
3499 "--"
3500 ["Customize Group..." (customize-group 'vhdl-project) t])
3501 ("Compiler"
3502 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3503 ,(append
3504 '("Selected Compiler at Startup")
3505 ;; add menu entries for defined compilers
3506 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3507 (while comp-alist
3508 (setq name (caar comp-alist))
3509 (setq menu-list
3510 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3511 :style radio :selected (equal ,name vhdl-compiler)]
3512 menu-list))
3513 (setq comp-alist (cdr comp-alist)))
3514 (setq menu-list (nreverse menu-list))
3515 (vhdl-menu-split menu-list "Compler")))
3516 ["Use Local Error Regexp"
3517 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3518 (not vhdl-compile-use-local-error-regexp))
3519 :style toggle :selected vhdl-compile-use-local-error-regexp]
3520 ["Makefile Generation Hook..."
3521 (customize-option 'vhdl-makefile-generation-hook) t]
3522 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3523 "--"
3524 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3525 ("Style"
3526 ("VHDL Standard"
3527 ["VHDL'87"
3528 (progn (customize-set-variable 'vhdl-standard
3529 (list '87 (cadr vhdl-standard)))
3530 (vhdl-activate-customizations))
3531 :style radio :selected (eq '87 (car vhdl-standard))]
3532 ["VHDL'93"
3533 (progn (customize-set-variable 'vhdl-standard
3534 (list '93 (cadr vhdl-standard)))
3535 (vhdl-activate-customizations))
3536 :style radio :selected (eq '93 (car vhdl-standard))]
3537 "--"
3538 ["VHDL-AMS"
3539 (progn (customize-set-variable
3540 'vhdl-standard (list (car vhdl-standard)
3541 (if (memq 'ams (cadr vhdl-standard))
3542 (delq 'ams (cadr vhdl-standard))
3543 (cons 'ams (cadr vhdl-standard)))))
3544 (vhdl-activate-customizations))
3545 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3546 ["Math Packages"
3547 (progn (customize-set-variable
3548 'vhdl-standard (list (car vhdl-standard)
3549 (if (memq 'math (cadr vhdl-standard))
3550 (delq 'math (cadr vhdl-standard))
3551 (cons 'math (cadr vhdl-standard)))))
3552 (vhdl-activate-customizations))
3553 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3554 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3555 ["Upper Case Keywords"
3556 (customize-set-variable 'vhdl-upper-case-keywords
3557 (not vhdl-upper-case-keywords))
3558 :style toggle :selected vhdl-upper-case-keywords]
3559 ["Upper Case Types"
3560 (customize-set-variable 'vhdl-upper-case-types
3561 (not vhdl-upper-case-types))
3562 :style toggle :selected vhdl-upper-case-types]
3563 ["Upper Case Attributes"
3564 (customize-set-variable 'vhdl-upper-case-attributes
3565 (not vhdl-upper-case-attributes))
3566 :style toggle :selected vhdl-upper-case-attributes]
3567 ["Upper Case Enumeration Values"
3568 (customize-set-variable 'vhdl-upper-case-enum-values
3569 (not vhdl-upper-case-enum-values))
3570 :style toggle :selected vhdl-upper-case-enum-values]
3571 ["Upper Case Constants"
3572 (customize-set-variable 'vhdl-upper-case-constants
3573 (not vhdl-upper-case-constants))
3574 :style toggle :selected vhdl-upper-case-constants]
3575 ("Use Direct Instantiation"
3576 ["Never"
3577 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3578 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3579 ["Standard"
3580 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3581 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3582 ["Always"
3583 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3584 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3585 "--"
3586 ["Customize Group..." (customize-group 'vhdl-style) t])
3587 ("Naming"
3588 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3589 ["Architecture File Name..."
3590 (customize-option 'vhdl-architecture-file-name) t]
3591 ["Configuration File Name..."
3592 (customize-option 'vhdl-configuration-file-name) t]
3593 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3594 ("File Name Case"
3595 ["As Is"
3596 (customize-set-variable 'vhdl-file-name-case 'identity)
3597 :style radio :selected (eq 'identity vhdl-file-name-case)]
3598 ["Lower Case"
3599 (customize-set-variable 'vhdl-file-name-case 'downcase)
3600 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3601 ["Upper Case"
3602 (customize-set-variable 'vhdl-file-name-case 'upcase)
3603 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3604 ["Capitalize"
3605 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3606 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3607 "--"
3608 ["Customize Group..." (customize-group 'vhdl-naming) t])
3609 ("Template"
3610 ("Electric Keywords"
3611 ["VHDL Keywords"
3612 (customize-set-variable 'vhdl-electric-keywords
3613 (if (memq 'vhdl vhdl-electric-keywords)
3614 (delq 'vhdl vhdl-electric-keywords)
3615 (cons 'vhdl vhdl-electric-keywords)))
3616 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3617 ["User Model Keywords"
3618 (customize-set-variable 'vhdl-electric-keywords
3619 (if (memq 'user vhdl-electric-keywords)
3620 (delq 'user vhdl-electric-keywords)
3621 (cons 'user vhdl-electric-keywords)))
3622 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3623 ("Insert Optional Labels"
3624 ["None"
3625 (customize-set-variable 'vhdl-optional-labels 'none)
3626 :style radio :selected (eq 'none vhdl-optional-labels)]
3627 ["Processes Only"
3628 (customize-set-variable 'vhdl-optional-labels 'process)
3629 :style radio :selected (eq 'process vhdl-optional-labels)]
3630 ["All Constructs"
3631 (customize-set-variable 'vhdl-optional-labels 'all)
3632 :style radio :selected (eq 'all vhdl-optional-labels)])
3633 ("Insert Empty Lines"
3634 ["None"
3635 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3636 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3637 ["Design Units Only"
3638 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3639 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3640 ["All Constructs"
3641 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3642 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3643 ["Argument List Indent"
3644 (customize-set-variable 'vhdl-argument-list-indent
3645 (not vhdl-argument-list-indent))
3646 :style toggle :selected vhdl-argument-list-indent]
3647 ["Association List with Formals"
3648 (customize-set-variable 'vhdl-association-list-with-formals
3649 (not vhdl-association-list-with-formals))
3650 :style toggle :selected vhdl-association-list-with-formals]
3651 ["Conditions in Parenthesis"
3652 (customize-set-variable 'vhdl-conditions-in-parenthesis
3653 (not vhdl-conditions-in-parenthesis))
3654 :style toggle :selected vhdl-conditions-in-parenthesis]
3655 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3656 ["One String..." (customize-option 'vhdl-one-string) t]
3657 ("File Header"
3658 ["Header String..." (customize-option 'vhdl-file-header) t]
3659 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3660 ["Company Name..." (customize-option 'vhdl-company-name) t]
3661 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3662 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3663 ["Date Format..." (customize-option 'vhdl-date-format) t]
3664 ["Modify Date Prefix String..."
3665 (customize-option 'vhdl-modify-date-prefix-string) t]
3666 ["Modify Date on Saving"
3667 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3668 (not vhdl-modify-date-on-saving))
3669 (vhdl-activate-customizations))
3670 :style toggle :selected vhdl-modify-date-on-saving])
3671 ("Sequential Process"
3672 ("Kind of Reset"
3673 ["None"
3674 (customize-set-variable 'vhdl-reset-kind 'none)
3675 :style radio :selected (eq 'none vhdl-reset-kind)]
3676 ["Synchronous"
3677 (customize-set-variable 'vhdl-reset-kind 'sync)
3678 :style radio :selected (eq 'sync vhdl-reset-kind)]
3679 ["Asynchronous"
3680 (customize-set-variable 'vhdl-reset-kind 'async)
3681 :style radio :selected (eq 'async vhdl-reset-kind)])
3682 ["Reset is Active High"
3683 (customize-set-variable 'vhdl-reset-active-high
3684 (not vhdl-reset-active-high))
3685 :style toggle :selected vhdl-reset-active-high]
3686 ["Use Rising Clock Edge"
3687 (customize-set-variable 'vhdl-clock-rising-edge
3688 (not vhdl-clock-rising-edge))
3689 :style toggle :selected vhdl-clock-rising-edge]
3690 ("Clock Edge Condition"
3691 ["Standard"
3692 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3693 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3694 ["Function \"rising_edge\""
3695 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3696 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3697 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3698 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3699 "--"
3700 ["Customize Group..." (customize-group 'vhdl-template) t])
3701 ("Model"
3702 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3703 ("Port"
3704 ["Include Port Comments"
3705 (customize-set-variable 'vhdl-include-port-comments
3706 (not vhdl-include-port-comments))
3707 :style toggle :selected vhdl-include-port-comments]
3708 ["Include Direction Comments"
3709 (customize-set-variable 'vhdl-include-direction-comments
3710 (not vhdl-include-direction-comments))
3711 :style toggle :selected vhdl-include-direction-comments]
3712 ["Include Type Comments"
3713 (customize-set-variable 'vhdl-include-type-comments
3714 (not vhdl-include-type-comments))
3715 :style toggle :selected vhdl-include-type-comments]
3716 ("Include Group Comments"
3717 ["Never"
3718 (customize-set-variable 'vhdl-include-group-comments 'never)
3719 :style radio :selected (eq 'never vhdl-include-group-comments)]
3720 ["Declarations"
3721 (customize-set-variable 'vhdl-include-group-comments 'decl)
3722 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3723 ["Always"
3724 (customize-set-variable 'vhdl-include-group-comments 'always)
3725 :style radio :selected (eq 'always vhdl-include-group-comments)])
3726 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3727 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3728 ("Testbench"
3729 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3730 ["Architecture Name..."
3731 (customize-option 'vhdl-testbench-architecture-name) t]
3732 ["Configuration Name..."
3733 (customize-option 'vhdl-testbench-configuration-name) t]
3734 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3735 ["Include Header"
3736 (customize-set-variable 'vhdl-testbench-include-header
3737 (not vhdl-testbench-include-header))
3738 :style toggle :selected vhdl-testbench-include-header]
3739 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3740 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3741 ["Initialize Signals"
3742 (customize-set-variable 'vhdl-testbench-initialize-signals
3743 (not vhdl-testbench-initialize-signals))
3744 :style toggle :selected vhdl-testbench-initialize-signals]
3745 ["Include Library Clause"
3746 (customize-set-variable 'vhdl-testbench-include-library
3747 (not vhdl-testbench-include-library))
3748 :style toggle :selected vhdl-testbench-include-library]
3749 ["Include Configuration"
3750 (customize-set-variable 'vhdl-testbench-include-configuration
3751 (not vhdl-testbench-include-configuration))
3752 :style toggle :selected vhdl-testbench-include-configuration]
3753 ("Create Files"
3754 ["None"
3755 (customize-set-variable 'vhdl-testbench-create-files 'none)
3756 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3757 ["Single"
3758 (customize-set-variable 'vhdl-testbench-create-files 'single)
3759 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3760 ["Separate"
3761 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3762 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3763 ["Testbench Entity File Name..."
3764 (customize-option 'vhdl-testbench-entity-file-name) t]
3765 ["Testbench Architecture File Name..."
3766 (customize-option 'vhdl-testbench-architecture-file-name) t])
3767 "--"
3768 ["Customize Group..." (customize-group 'vhdl-port) t])
3769 ("Compose"
3770 ["Architecture Name..."
3771 (customize-option 'vhdl-compose-architecture-name) t]
3772 ["Configuration Name..."
3773 (customize-option 'vhdl-compose-configuration-name) t]
3774 ["Components Package Name..."
3775 (customize-option 'vhdl-components-package-name) t]
3776 ["Use Components Package"
3777 (customize-set-variable 'vhdl-use-components-package
3778 (not vhdl-use-components-package))
3779 :style toggle :selected vhdl-use-components-package]
3780 ["Include Header"
3781 (customize-set-variable 'vhdl-compose-include-header
3782 (not vhdl-compose-include-header))
3783 :style toggle :selected vhdl-compose-include-header]
3784 ("Create Entity/Architecture Files"
3785 ["None"
3786 (customize-set-variable 'vhdl-compose-create-files 'none)
3787 :style radio :selected (eq 'none vhdl-compose-create-files)]
3788 ["Single"
3789 (customize-set-variable 'vhdl-compose-create-files 'single)
3790 :style radio :selected (eq 'single vhdl-compose-create-files)]
3791 ["Separate"
3792 (customize-set-variable 'vhdl-compose-create-files 'separate)
3793 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3794 ["Create Configuration File"
3795 (customize-set-variable 'vhdl-compose-configuration-create-file
3796 (not vhdl-compose-configuration-create-file))
3797 :style toggle :selected vhdl-compose-configuration-create-file]
3798 ["Hierarchical Configuration"
3799 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3800 (not vhdl-compose-configuration-hierarchical))
3801 :style toggle :selected vhdl-compose-configuration-hierarchical]
3802 ["Use Subconfiguration"
3803 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3804 (not vhdl-compose-configuration-use-subconfiguration))
3805 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3806 "--"
3807 ["Customize Group..." (customize-group 'vhdl-compose) t])
3808 ("Comment"
3809 ["Self Insert Comments"
3810 (customize-set-variable 'vhdl-self-insert-comments
3811 (not vhdl-self-insert-comments))
3812 :style toggle :selected vhdl-self-insert-comments]
3813 ["Prompt for Comments"
3814 (customize-set-variable 'vhdl-prompt-for-comments
3815 (not vhdl-prompt-for-comments))
3816 :style toggle :selected vhdl-prompt-for-comments]
3817 ["Inline Comment Column..."
3818 (customize-option 'vhdl-inline-comment-column) t]
3819 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3820 "--"
3821 ["Customize Group..." (customize-group 'vhdl-comment) t])
3822 ("Align"
3823 ["Auto Align Templates"
3824 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3825 :style toggle :selected vhdl-auto-align]
3826 ["Align Line Groups"
3827 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3828 :style toggle :selected vhdl-align-groups]
3829 ["Group Separation String..."
3830 (customize-set-variable 'vhdl-align-group-separate) t]
3831 ["Align Lines with Same Indent"
3832 (customize-set-variable 'vhdl-align-same-indent
3833 (not vhdl-align-same-indent))
3834 :style toggle :selected vhdl-align-same-indent]
3835 "--"
3836 ["Customize Group..." (customize-group 'vhdl-align) t])
3837 ("Highlight"
3838 ["Highlighting On/Off..."
3839 (customize-option
3840 (if (fboundp 'global-font-lock-mode)
3841 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3842 ["Highlight Keywords"
3843 (progn (customize-set-variable 'vhdl-highlight-keywords
3844 (not vhdl-highlight-keywords))
3845 (vhdl-fontify-buffer))
3846 :style toggle :selected vhdl-highlight-keywords]
3847 ["Highlight Names"
3848 (progn (customize-set-variable 'vhdl-highlight-names
3849 (not vhdl-highlight-names))
3850 (vhdl-fontify-buffer))
3851 :style toggle :selected vhdl-highlight-names]
3852 ["Highlight Special Words"
3853 (progn (customize-set-variable 'vhdl-highlight-special-words
3854 (not vhdl-highlight-special-words))
3855 (vhdl-fontify-buffer))
3856 :style toggle :selected vhdl-highlight-special-words]
3857 ["Highlight Forbidden Words"
3858 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3859 (not vhdl-highlight-forbidden-words))
3860 (vhdl-fontify-buffer))
3861 :style toggle :selected vhdl-highlight-forbidden-words]
3862 ["Highlight Verilog Keywords"
3863 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3864 (not vhdl-highlight-verilog-keywords))
3865 (vhdl-fontify-buffer))
3866 :style toggle :selected vhdl-highlight-verilog-keywords]
3867 ["Highlight \"translate_off\""
3868 (progn (customize-set-variable 'vhdl-highlight-translate-off
3869 (not vhdl-highlight-translate-off))
3870 (vhdl-fontify-buffer))
3871 :style toggle :selected vhdl-highlight-translate-off]
3872 ["Case Sensitive Highlighting"
3873 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3874 (not vhdl-highlight-case-sensitive))
3875 (vhdl-fontify-buffer))
3876 :style toggle :selected vhdl-highlight-case-sensitive]
3877 ["Special Syntax Definition..."
3878 (customize-option 'vhdl-special-syntax-alist) t]
3879 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3880 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3881 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3882 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3883 "--"
3884 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3885 ("Speedbar"
3886 ["Auto Open at Startup"
3887 (customize-set-variable 'vhdl-speedbar-auto-open
3888 (not vhdl-speedbar-auto-open))
3889 :style toggle :selected vhdl-speedbar-auto-open]
3890 ("Default Displaying Mode"
3891 ["Files"
3892 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3893 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3894 ["Directory Hierarchy"
3895 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3896 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3897 ["Project Hierarchy"
3898 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3899 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3900 ["Indentation Offset..."
3901 (customize-option 'speedbar-indentation-width) t]
3902 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3903 ["Jump to Unit when Opening"
3904 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3905 (not vhdl-speedbar-jump-to-unit))
3906 :style toggle :selected vhdl-speedbar-jump-to-unit]
3907 ["Update Hierarchy on File Saving"
3908 (customize-set-variable 'vhdl-speedbar-update-on-saving
3909 (not vhdl-speedbar-update-on-saving))
3910 :style toggle :selected vhdl-speedbar-update-on-saving]
3911 ("Save in Cache File"
3912 ["Hierarchy Information"
3913 (customize-set-variable 'vhdl-speedbar-save-cache
3914 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3915 (delq 'hierarchy vhdl-speedbar-save-cache)
3916 (cons 'hierarchy vhdl-speedbar-save-cache)))
3917 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3918 ["Displaying Status"
3919 (customize-set-variable 'vhdl-speedbar-save-cache
3920 (if (memq 'display vhdl-speedbar-save-cache)
3921 (delq 'display vhdl-speedbar-save-cache)
3922 (cons 'display vhdl-speedbar-save-cache)))
3923 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3924 ["Cache File Name..."
3925 (customize-option 'vhdl-speedbar-cache-file-name) t]
3926 "--"
3927 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3928 ("Menu"
3929 ["Add Index Menu when Loading File"
3930 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3931 (vhdl-index-menu-init))
3932 :style toggle :selected vhdl-index-menu]
3933 ["Add Source File Menu when Loading File"
3934 (progn (customize-set-variable 'vhdl-source-file-menu
3935 (not vhdl-source-file-menu))
3936 (vhdl-add-source-files-menu))
3937 :style toggle :selected vhdl-source-file-menu]
3938 ["Add Hideshow Menu at Startup"
3939 (progn (customize-set-variable 'vhdl-hideshow-menu
3940 (not vhdl-hideshow-menu))
3941 (vhdl-activate-customizations))
3942 :style toggle :selected vhdl-hideshow-menu]
3943 ["Hide Everything Initially"
3944 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3945 :style toggle :selected vhdl-hide-all-init]
3946 "--"
3947 ["Customize Group..." (customize-group 'vhdl-menu) t])
3948 ("Print"
3949 ["In Two Column Format"
3950 (progn (customize-set-variable 'vhdl-print-two-column
3951 (not vhdl-print-two-column))
3952 (message "Activate new setting by saving options and restarting Emacs"))
3953 :style toggle :selected vhdl-print-two-column]
3954 ["Use Customized Faces"
3955 (progn (customize-set-variable 'vhdl-print-customize-faces
3956 (not vhdl-print-customize-faces))
3957 (message "Activate new setting by saving options and restarting Emacs"))
3958 :style toggle :selected vhdl-print-customize-faces]
3959 "--"
3960 ["Customize Group..." (customize-group 'vhdl-print) t])
3961 ("Miscellaneous"
3962 ["Use Intelligent Tab"
3963 (progn (customize-set-variable 'vhdl-intelligent-tab
3964 (not vhdl-intelligent-tab))
3965 (vhdl-activate-customizations))
3966 :style toggle :selected vhdl-intelligent-tab]
3967 ["Indent Syntax-Based"
3968 (customize-set-variable 'vhdl-indent-syntax-based
3969 (not vhdl-indent-syntax-based))
3970 :style toggle :selected vhdl-indent-syntax-based]
3971 ["Word Completion is Case Sensitive"
3972 (customize-set-variable 'vhdl-word-completion-case-sensitive
3973 (not vhdl-word-completion-case-sensitive))
3974 :style toggle :selected vhdl-word-completion-case-sensitive]
3975 ["Word Completion in Minibuffer"
3976 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3977 (not vhdl-word-completion-in-minibuffer))
3978 (message "Activate new setting by saving options and restarting Emacs"))
3979 :style toggle :selected vhdl-word-completion-in-minibuffer]
3980 ["Underscore is Part of Word"
3981 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3982 (not vhdl-underscore-is-part-of-word))
3983 (vhdl-activate-customizations))
3984 :style toggle :selected vhdl-underscore-is-part-of-word]
3985 "--"
3986 ["Customize Group..." (customize-group 'vhdl-misc) t])
3987 ["Related..." (customize-browse 'vhdl-related) t]
3988 "--"
3989 ["Save Options" customize-save-customized t]
3990 ["Activate Options" vhdl-activate-customizations t]
3991 ["Browse Options..." vhdl-customize t])))
3992
3993 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3994 "VHDL Mode menu.")
3995
3996 (defun vhdl-update-mode-menu ()
3997 "Update VHDL Mode menu."
3998 (interactive)
3999 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4000 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4001 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4002 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4003 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4004
4005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4006 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4007
4008 (defconst vhdl-imenu-generic-expression
4009 '(
4010 ("Subprogram"
4011 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4012 4)
4013 ("Instance"
4014 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4015 1)
4016 ("Component"
4017 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4018 2)
4019 ("Procedural"
4020 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4021 1)
4022 ("Process"
4023 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4024 1)
4025 ("Block"
4026 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4027 1)
4028 ("Package"
4029 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4030 3)
4031 ("Configuration"
4032 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4033 2)
4034 ("Architecture"
4035 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4036 2)
4037 ("Entity"
4038 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4039 2)
4040 )
4041 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4042
4043 (defun vhdl-index-menu-init ()
4044 "Initialize index menu."
4045 (set (make-local-variable 'imenu-case-fold-search) t)
4046 (set (make-local-variable 'imenu-generic-expression)
4047 vhdl-imenu-generic-expression)
4048 (when (and vhdl-index-menu (fboundp 'imenu))
4049 (if (or (not (boundp 'font-lock-maximum-size))
4050 (> font-lock-maximum-size (buffer-size)))
4051 (imenu-add-to-menubar "Index")
4052 (message "Scanning buffer for index...buffer too big"))))
4053
4054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4055 ;; Source file menu (using `easy-menu.el')
4056
4057 (defvar vhdl-sources-menu nil)
4058
4059 (defun vhdl-directory-files (directory &optional full match)
4060 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4061 message."
4062 (if (not (file-directory-p directory))
4063 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4064 (let ((dir (directory-files directory full match)))
4065 (setq dir (delete "." dir))
4066 (setq dir (delete ".." dir))
4067 dir)))
4068
4069 (defun vhdl-get-source-files (&optional full directory)
4070 "Get list of VHDL source files in DIRECTORY or current directory."
4071 (let ((mode-alist auto-mode-alist)
4072 filename-regexp)
4073 ;; create regular expressions for matching file names
4074 (setq filename-regexp "\\`[^.].*\\(")
4075 (while mode-alist
4076 (when (eq (cdar mode-alist) 'vhdl-mode)
4077 (setq filename-regexp
4078 (concat filename-regexp (caar mode-alist) "\\|")))
4079 (setq mode-alist (cdr mode-alist)))
4080 (setq filename-regexp
4081 (concat (substring filename-regexp 0
4082 (string-match "\\\\|$" filename-regexp)) "\\)"))
4083 ;; find files
4084 (vhdl-directory-files
4085 (or directory default-directory) full filename-regexp)))
4086
4087 (defun vhdl-add-source-files-menu ()
4088 "Scan directory for all VHDL source files and generate menu.
4089 The directory of the current source file is scanned."
4090 (interactive)
4091 (message "Scanning directory for source files ...")
4092 (let ((newmap (current-local-map))
4093 (file-list (vhdl-get-source-files))
4094 menu-list found)
4095 ;; Create list for menu
4096 (setq found nil)
4097 (while file-list
4098 (setq found t)
4099 (setq menu-list (cons (vector (car file-list)
4100 (list 'find-file (car file-list)) t)
4101 menu-list))
4102 (setq file-list (cdr file-list)))
4103 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4104 (when found (setq menu-list (cons "--" menu-list)))
4105 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4106 (setq menu-list (cons "Sources" menu-list))
4107 ;; Create menu
4108 (easy-menu-add menu-list)
4109 (easy-menu-define vhdl-sources-menu newmap
4110 "VHDL source files menu" menu-list))
4111 (message ""))
4112
4113
4114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4115 ;;; Mode definition
4116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4117 ;; performs all buffer local initializations
4118
4119 ;;;###autoload
4120 (define-derived-mode vhdl-mode prog-mode
4121 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4122 (vhdl-electric-mode "e")
4123 (vhdl-stutter-mode "s"))
4124 "Major mode for editing VHDL code.
4125
4126 Usage:
4127 ------
4128
4129 TEMPLATE INSERTION (electrification):
4130 After typing a VHDL keyword and entering `SPC', you are prompted for
4131 arguments while a template is generated for that VHDL construct. Typing
4132 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4133 template generation. Optional arguments are indicated by square
4134 brackets and removed if the queried string is left empty. Prompts for
4135 mandatory arguments remain in the code if the queried string is left
4136 empty. They can be queried again by `C-c C-t C-q'. Enabled
4137 electrification is indicated by `/e' in the modeline.
4138
4139 Typing `M-SPC' after a keyword inserts a space without calling the
4140 template generator. Automatic template generation (i.e.
4141 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4142 setting option `vhdl-electric-mode' (see OPTIONS).
4143
4144 Template generators can be invoked from the VHDL menu, by key
4145 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4146 the keyword (i.e. first word of menu entry not in parenthesis) and
4147 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4148 conf, comp, cons, func, inst, pack, sig, var.
4149
4150 Template styles can be customized in customization group
4151 `vhdl-template' \(see OPTIONS).
4152
4153
4154 HEADER INSERTION:
4155 A file header can be inserted by `C-c C-t C-h'. A file footer
4156 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4157 See customization group `vhdl-header'.
4158
4159
4160 STUTTERING:
4161 Double striking of some keys inserts cumbersome VHDL syntax elements.
4162 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4163 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4164 the modeline. The stuttering keys and their effects are:
4165
4166 ;; --> \" : \" [ --> ( -- --> comment
4167 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4168 .. --> \" => \" ] --> ) --- --> horizontal line
4169 ,, --> \" <= \" ]] --> ] ---- --> display comment
4170 == --> \" == \" '' --> \\\"
4171
4172
4173 WORD COMPLETION:
4174 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4175 word in the buffer that starts alike, inserts it and adjusts case.
4176 Re-typing `TAB' toggles through alternative word completions. This also
4177 works in the minibuffer (i.e. in template generator prompts).
4178
4179 Typing `TAB' after `(' looks for and inserts complete parenthesized
4180 expressions (e.g. for array index ranges). All keywords as well as
4181 standard types and subprograms of VHDL have predefined abbreviations
4182 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4183 beginning with \"std\").
4184
4185 Typing `TAB' after a non-word character indents the line if at the
4186 beginning of a line (i.e. no preceding non-blank characters), and
4187 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4188 stop.
4189
4190
4191 COMMENTS:
4192 `--' puts a single comment.
4193 `---' draws a horizontal line for separating code segments.
4194 `----' inserts a display comment, i.e. two horizontal lines
4195 with a comment in between.
4196 `--CR' comments out code on that line. Re-hitting CR comments
4197 out following lines.
4198 `C-c c' comments out a region if not commented out,
4199 uncomments a region if already commented out.
4200
4201 You are prompted for comments after object definitions (i.e. signals,
4202 variables, constants, ports) and after subprogram and process
4203 specifications if option `vhdl-prompt-for-comments' is non-nil.
4204 Comments are automatically inserted as additional labels (e.g. after
4205 begin statements) and as help comments if `vhdl-self-insert-comments' is
4206 non-nil.
4207
4208 Inline comments (i.e. comments after a piece of code on the same line)
4209 are indented at least to `vhdl-inline-comment-column'. Comments go at
4210 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4211 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4212 in a comment automatically opens a new comment line. `M-q' re-fills
4213 multi-line comments.
4214
4215
4216 INDENTATION:
4217 `TAB' indents a line if at the beginning of the line. The amount of
4218 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4219 always indents the current line (is bound to `TAB' if option
4220 `vhdl-intelligent-tab' is nil).
4221
4222 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4223 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4224 indented normally (nil) or relative to the opening parenthesis (non-nil)
4225 according to option `vhdl-argument-list-indent'.
4226
4227 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4228 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4229 and vice versa.
4230
4231 Syntax-based indentation can be very slow in large files. Option
4232 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4233
4234
4235 ALIGNMENT:
4236 The alignment functions align operators, keywords, and inline comments
4237 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4238 separated by blank lines, `C-c C-a C-i' a block of lines with same
4239 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4240 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4241 C-a C-d' all lines within the declarative part of a design unit. `C-c
4242 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4243 for a group of lines, and `C-c C-a M-c' for a region.
4244
4245 If option `vhdl-align-groups' is non-nil, groups of code lines
4246 separated by special lines (see option `vhdl-align-group-separate') are
4247 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4248 blocks of lines with same indent are aligned separately. Some templates
4249 are automatically aligned after generation if option `vhdl-auto-align'
4250 is non-nil.
4251
4252 Alignment tries to align inline comments at
4253 `vhdl-inline-comment-column' and tries inline comment not to exceed
4254 `vhdl-end-comment-column'.
4255
4256 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4257 symbols are surrounded by one space, and multiple spaces are eliminated.
4258
4259
4260 CODE FILLING:
4261 Code filling allows to condense code (e.g. sensitivity lists or port
4262 maps) by removing comments and newlines and re-wrapping so that all
4263 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4264 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4265 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4266 `C-c C-f M-f' an entire region.
4267
4268
4269 CODE BEAUTIFICATION:
4270 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4271 buffer respectively. This inludes indentation, alignment, and case
4272 fixing. Code beautification can also be run non-interactively using the
4273 command:
4274
4275 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4276
4277
4278 PORT TRANSLATION:
4279 Generic and port clauses from entity or component declarations can be
4280 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4281 as component instantiations and corresponding internal constants and
4282 signals, as a generic map with constants as actual generics, and as
4283 internal signal initializations (menu).
4284
4285 To include formals in component instantiations, see option
4286 `vhdl-association-list-with-formals'. To include comments in pasting,
4287 see options `vhdl-include-...-comments'.
4288
4289 A clause with several generic/port names on the same line can be
4290 flattened (`C-c C-p C-f') so that only one name per line exists. The
4291 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4292 outputs and vice versa, which can be useful in testbenches. (This
4293 reversion is done on the internal data structure and is only reflected
4294 in subsequent paste operations.)
4295
4296 Names for actual ports, instances, testbenches, and
4297 design-under-test instances can be derived from existing names according
4298 to options `vhdl-...-name'. See customization group `vhdl-port'.
4299
4300
4301 SUBPROGRAM TRANSLATION:
4302 Similar functionality exists for copying/pasting the interface of
4303 subprograms (function/procedure). A subprogram interface can be copied
4304 and then pasted as a subprogram declaration, body or call (uses
4305 association list with formals).
4306
4307
4308 TESTBENCH GENERATION:
4309 A copied port can also be pasted as a testbench. The generated
4310 testbench includes an entity, an architecture, and an optional
4311 configuration. The architecture contains the component declaration and
4312 instantiation of the DUT as well as internal constant and signal
4313 declarations. Additional user-defined templates can be inserted. The
4314 names used for entity/architecture/configuration/DUT as well as the file
4315 structure to be generated can be customized. See customization group
4316 `vhdl-testbench'.
4317
4318
4319 KEY BINDINGS:
4320 Key bindings (`C-c ...') exist for most commands (see in menu).
4321
4322
4323 VHDL MENU:
4324 All commands can be found in the VHDL menu including their key bindings.
4325
4326
4327 FILE BROWSER:
4328 The speedbar allows browsing of directories and file contents. It can
4329 be accessed from the VHDL menu and is automatically opened if option
4330 `vhdl-speedbar-auto-open' is non-nil.
4331
4332 In speedbar, open files and directories with `mouse-2' on the name and
4333 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4334
4335
4336 DESIGN HIERARCHY BROWSER:
4337 The speedbar can also be used for browsing the hierarchy of design units
4338 contained in the source files of the current directory or the specified
4339 projects (see option `vhdl-project-alist').
4340
4341 The speedbar can be switched between file, directory hierarchy and
4342 project hierarchy browsing mode in the speedbar menu or by typing `f',
4343 `h' or `H' in speedbar.
4344
4345 In speedbar, open design units with `mouse-2' on the name and browse
4346 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4347 from entities and components (in packages). Individual design units and
4348 complete designs can directly be compiled (\"Make\" menu entry).
4349
4350 The hierarchy is automatically updated upon saving a modified source
4351 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4352 hierarchy is only updated for projects that have been opened once in the
4353 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4354 options in group `vhdl-speedbar').
4355
4356 Simple design consistency checks are done during scanning, such as
4357 multiple declarations of the same unit or missing primary units that are
4358 required by secondary units.
4359
4360
4361 STRUCTURAL COMPOSITION:
4362 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4363 for a new component. Subcomponents (i.e. component declaration and
4364 instantiation) can be automatically placed from a previously read port
4365 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4366 all subcomponents can be automatically connected using internal signals
4367 and ports (`C-c C-c C-w') following these rules:
4368 - subcomponent actual ports with same name are considered to be
4369 connected by a signal (internal signal or port)
4370 - signals that are only inputs to subcomponents are considered as
4371 inputs to this component -> input port created
4372 - signals that are only outputs from subcomponents are considered as
4373 outputs from this component -> output port created
4374 - signals that are inputs to AND outputs from subcomponents are
4375 considered as internal connections -> internal signal created
4376
4377 Purpose: With appropriate naming conventions it is possible to
4378 create higher design levels with only a few mouse clicks or key
4379 strokes. A new design level can be created by simply generating a new
4380 component, placing the required subcomponents from the hierarchy
4381 browser, and wiring everything automatically.
4382
4383 Note: Automatic wiring only works reliably on templates of new
4384 components and component instantiations that were created by VHDL mode.
4385
4386 Component declarations can be placed in a components package (option
4387 `vhdl-use-components-package') which can be automatically generated for
4388 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4389 component instantiation is also supported (option
4390 `vhdl-use-direct-instantiation').
4391
4392 | Configuration declarations can automatically be generated either from
4393 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4394 | the speedbar menu (for the architecture under the cursor). The
4395 | configurations can optionally be hierarchical (i.e. include all
4396 | component levels of a hierarchical design, option
4397 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4398 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4399 | subcomponents in hierarchical configurations, the most-recently-analyzed
4400 | (mra) architecture is selected. If another architecture is desired, it
4401 | can be marked as most-recently-analyzed (speedbar menu) before
4402 | generating the configuration.
4403 |
4404 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4405 | declarations) are currently not considered when displaying
4406 | configurations in speedbar.
4407
4408 See the options group `vhdl-compose' for all relevant user options.
4409
4410
4411 SOURCE FILE COMPILATION:
4412 The syntax of the current buffer can be analyzed by calling a VHDL
4413 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4414 option `vhdl-compiler'. The available compilers are listed in option
4415 `vhdl-compiler-alist' including all required compilation command,
4416 command options, compilation directory, and error message syntax
4417 information. New compilers can be added.
4418
4419 All the source files of an entire design can be compiled by the `make'
4420 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4421
4422
4423 MAKEFILE GENERATION:
4424 Makefiles can be generated automatically by an internal generation
4425 routine (`C-c M-k'). The library unit dependency information is
4426 obtained from the hierarchy browser. Makefile generation can be
4427 customized for each compiler in option `vhdl-compiler-alist'.
4428
4429 Makefile generation can also be run non-interactively using the
4430 command:
4431
4432 emacs -batch -l ~/.emacs -l vhdl-mode
4433 [-compiler compilername] [-project projectname]
4434 -f vhdl-generate-makefile
4435
4436 The Makefile's default target \"all\" compiles the entire design, the
4437 target \"clean\" removes it and the target \"library\" creates the
4438 library directory if not existent. The Makefile also includes a target
4439 for each primary library unit which allows selective compilation of this
4440 unit, its secondary units and its subhierarchy (example: compilation of
4441 a design specified by a configuration). User specific parts can be
4442 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4443
4444 Limitations:
4445 - Only library units and dependencies within the current library are
4446 considered. Makefiles for designs that span multiple libraries are
4447 not (yet) supported.
4448 - Only one-level configurations are supported (also hierarchical),
4449 but configurations that go down several levels are not.
4450 - The \"others\" keyword in configurations is not supported.
4451
4452
4453 PROJECTS:
4454 Projects can be defined in option `vhdl-project-alist' and a current
4455 project be selected using option `vhdl-project' (permanently) or from
4456 the menu or speedbar (temporarily). For each project, title and
4457 description strings (for the file headers), source files/directories
4458 (for the hierarchy browser and Makefile generation), library name, and
4459 compiler-dependent options, exceptions and compilation directory can be
4460 specified. Compilation settings overwrite the settings of option
4461 `vhdl-compiler-alist'.
4462
4463 Project setups can be exported (i.e. written to a file) and imported.
4464 Imported setups are not automatically saved in `vhdl-project-alist' but
4465 can be saved afterwards in its customization buffer. When starting
4466 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4467 vhdl-mode\") in a directory with an existing project setup file, it is
4468 automatically loaded and its project activated if option
4469 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4470 files can be specified in option `vhdl-project-file-name'. Multiple
4471 project setups can be automatically loaded from global directories.
4472 This is an alternative to specifying project setups with option
4473 `vhdl-project-alist'.
4474
4475
4476 SPECIAL MENUES:
4477 As an alternative to the speedbar, an index menu can be added (set
4478 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4479 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4480 file) for browsing the file contents (is not populated if buffer is
4481 larger than `font-lock-maximum-size'). Also, a source file menu can be
4482 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4483 current directory for VHDL source files.
4484
4485
4486 VHDL STANDARDS:
4487 The VHDL standards to be used are specified in option `vhdl-standard'.
4488 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4489
4490
4491 KEYWORD CASE:
4492 Lower and upper case for keywords and standardized types, attributes,
4493 and enumeration values is supported. If the option
4494 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4495 lower case and are converted into upper case automatically (not for
4496 types, attributes, and enumeration values). The case of keywords,
4497 types, attributes,and enumeration values can be fixed for an entire
4498 region (menu) or buffer (`C-c C-x C-c') according to the options
4499 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4500
4501
4502 HIGHLIGHTING (fontification):
4503 Keywords and standardized types, attributes, enumeration values, and
4504 function names (controlled by option `vhdl-highlight-keywords'), as well
4505 as comments, strings, and template prompts are highlighted using
4506 different colors. Unit, subprogram, signal, variable, constant,
4507 parameter and generic/port names in declarations as well as labels are
4508 highlighted if option `vhdl-highlight-names' is non-nil.
4509
4510 Additional reserved words or words with a forbidden syntax (e.g. words
4511 that should be avoided) can be specified in option
4512 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4513 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4514 keywords are highlighted as forbidden words if option
4515 `vhdl-highlight-verilog-keywords' is non-nil.
4516
4517 Words with special syntax can be highlighted by specifying their
4518 syntax and color in option `vhdl-special-syntax-alist' and by setting
4519 option `vhdl-highlight-special-words' to non-nil. This allows to
4520 establish some naming conventions (e.g. to distinguish different kinds
4521 of signals or other objects by using name suffices) and to support them
4522 visually.
4523
4524 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4525 to support case-sensitive highlighting. However, keywords are then only
4526 highlighted if written in lower case.
4527
4528 Code between \"translate_off\" and \"translate_on\" pragmas is
4529 highlighted using a different background color if option
4530 `vhdl-highlight-translate-off' is non-nil.
4531
4532 For documentation and customization of the used colors see
4533 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4534 highlighting of matching parenthesis, see customization group
4535 `paren-showing'. Automatic buffer highlighting is turned on/off by
4536 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4537
4538
4539 USER MODELS:
4540 VHDL models (templates) can be specified by the user and made accessible
4541 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4542 electrification. See option `vhdl-model-alist'.
4543
4544
4545 HIDE/SHOW:
4546 The code of blocks, processes, subprograms, component declarations and
4547 instantiations, generic/port clauses, and configuration declarations can
4548 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4549 the code (see customization group `vhdl-menu'). XEmacs: limited
4550 functionality due to old `hideshow.el' package.
4551
4552
4553 CODE UPDATING:
4554 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4555 current process, `C-c C-u M-s' of all processes in the current buffer.
4556 Limitations:
4557 - Only declared local signals (ports, signals declared in
4558 architecture and blocks) are automatically inserted.
4559 - Global signals declared in packages are not automatically inserted.
4560 Insert them once manually (will be kept afterwards).
4561 - Out parameters of procedures are considered to be read.
4562 Use option `vhdl-entity-file-name' to specify the entity file name
4563 \(used to obtain the port names).
4564
4565
4566 CODE FIXING:
4567 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4568 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4569
4570
4571 PRINTING:
4572 Postscript printing with different faces (an optimized set of faces is
4573 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4574 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4575 postscript printing commands. Option `vhdl-print-two-column' defines
4576 appropriate default settings for nice landscape two-column printing.
4577 The paper format can be set by option `ps-paper-type'. Do not forget to
4578 switch `ps-print-color-p' to nil for printing on black-and-white
4579 printers.
4580
4581
4582 OPTIONS:
4583 User options allow customization of VHDL Mode. All options are
4584 accessible from the \"Options\" menu entry. Simple options (switches
4585 and choices) can directly be changed, while for complex options a
4586 customization buffer is opened. Changed options can be saved for future
4587 sessions using the \"Save Options\" menu entry.
4588
4589 Options and their detailed descriptions can also be accessed by using
4590 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4591 customize-group' for groups). Some customizations only take effect
4592 after some action (read the NOTE in the option documentation).
4593 Customization can also be done globally (i.e. site-wide, read the
4594 INSTALL file).
4595
4596 Not all options are described in this documentation, so go and see
4597 what other useful user options there are (`M-x vhdl-customize' or menu)!
4598
4599
4600 FILE EXTENSIONS:
4601 As default, files with extensions \".vhd\" and \".vhdl\" are
4602 automatically recognized as VHDL source files. To add an extension
4603 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4604
4605 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4606
4607
4608 HINTS:
4609 - To start Emacs with open VHDL hierarchy browser without having to load
4610 a VHDL file first, use the command:
4611
4612 emacs -l vhdl-mode -f speedbar-frame-mode
4613
4614 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4615
4616 - Some features only work on properly indented code.
4617
4618
4619 RELEASE NOTES:
4620 See also the release notes (menu) for added features in new releases.
4621
4622
4623 Maintenance:
4624 ------------
4625
4626 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4627 Add a description of the problem and include a reproducible test case.
4628
4629 Questions and enhancement requests can be sent to <reto@gnu.org>.
4630
4631 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4632 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4633 releases. You are kindly invited to participate in beta testing. Subscribe
4634 to above mailing lists by sending an email to <reto@gnu.org>.
4635
4636 VHDL Mode is officially distributed at
4637 URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
4638 where the latest version can be found.
4639
4640
4641 Known problems:
4642 ---------------
4643
4644 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4645 - XEmacs: Incorrect start-up when automatically opening speedbar.
4646 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4647
4648
4649 The VHDL Mode Authors
4650 Reto Zimmermann and Rod Whitby
4651
4652 Key bindings:
4653 -------------
4654
4655 \\{vhdl-mode-map}"
4656 :abbrev-table vhdl-mode-abbrev-table
4657
4658 ;; set local variables
4659 (set (make-local-variable 'paragraph-start)
4660 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4661 (set (make-local-variable 'paragraph-separate) paragraph-start)
4662 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4663 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4664 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4665 (set (make-local-variable 'comment-start) "--")
4666 (set (make-local-variable 'comment-end) "")
4667 (when vhdl-emacs-21
4668 (set (make-local-variable 'comment-padding) ""))
4669 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4670 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4671 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4672 (set (make-local-variable 'comment-multi-line) nil)
4673 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4674 (set (make-local-variable 'hippie-expand-verbose) nil)
4675
4676 ;; setup the comment indent variable in a Emacs version portable way
4677 ;; ignore any byte compiler warnings you might get here
4678 (when (boundp 'comment-indent-function)
4679 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4680
4681 ;; initialize font locking
4682 (set (make-local-variable 'font-lock-defaults)
4683 (list
4684 '(nil vhdl-font-lock-keywords) nil
4685 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4686 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4687 (set (make-local-variable 'syntax-propertize-function)
4688 (syntax-propertize-rules
4689 ;; Mark single quotes as having string quote syntax in
4690 ;; 'c' instances.
4691 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4692 (set (make-local-variable 'font-lock-syntactic-keywords)
4693 vhdl-font-lock-syntactic-keywords))
4694 (unless vhdl-emacs-21
4695 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4696 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4697 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4698 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4699 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4700 ; (turn-on-font-lock)
4701
4702 ;; variables for source file compilation
4703 (when vhdl-compile-use-local-error-regexp
4704 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4705 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4706
4707 ;; add index menu
4708 (vhdl-index-menu-init)
4709 ;; add source file menu
4710 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4711 ;; add VHDL menu
4712 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4713 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4714 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4715 ;; initialize hideshow and add menu
4716 (vhdl-hideshow-init)
4717 (run-hooks 'menu-bar-update-hook)
4718
4719 ;; miscellaneous
4720 (vhdl-ps-print-init)
4721 (vhdl-write-file-hooks-init)
4722 (message "VHDL Mode %s.%s" vhdl-version
4723 (if noninteractive "" " See menu for documentation and release notes.")))
4724
4725 (defun vhdl-activate-customizations ()
4726 "Activate all customizations on local variables."
4727 (interactive)
4728 (vhdl-mode-map-init)
4729 (use-local-map vhdl-mode-map)
4730 (set-syntax-table vhdl-mode-syntax-table)
4731 (setq comment-column vhdl-inline-comment-column)
4732 (setq end-comment-column vhdl-end-comment-column)
4733 (vhdl-write-file-hooks-init)
4734 (vhdl-update-mode-menu)
4735 (vhdl-hideshow-init)
4736 (run-hooks 'menu-bar-update-hook))
4737
4738 (defun vhdl-write-file-hooks-init ()
4739 "Add/remove hooks when buffer is saved."
4740 (if vhdl-modify-date-on-saving
4741 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4742 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4743 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4744 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4745
4746 (defun vhdl-process-command-line-option (option)
4747 "Process command line options for VHDL Mode."
4748 (cond
4749 ;; set compiler
4750 ((equal option "-compiler")
4751 (vhdl-set-compiler (car command-line-args-left))
4752 (setq command-line-args-left (cdr command-line-args-left)))
4753 ;; set project
4754 ((equal option "-project")
4755 (vhdl-set-project (car command-line-args-left))
4756 (setq command-line-args-left (cdr command-line-args-left)))))
4757
4758 ;; make Emacs process VHDL Mode options
4759 (setq command-switch-alist
4760 (append command-switch-alist
4761 '(("-compiler" . vhdl-process-command-line-option)
4762 ("-project" . vhdl-process-command-line-option))))
4763
4764
4765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4766 ;;; Keywords and standardized words
4767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4768
4769 (defconst vhdl-93-keywords
4770 '(
4771 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4772 "assert" "attribute"
4773 "begin" "block" "body" "buffer" "bus"
4774 "case" "component" "configuration" "constant"
4775 "disconnect" "downto"
4776 "else" "elsif" "end" "entity" "exit"
4777 "file" "for" "function"
4778 "generate" "generic" "group" "guarded"
4779 "if" "impure" "in" "inertial" "inout" "is"
4780 "label" "library" "linkage" "literal" "loop"
4781 "map" "mod"
4782 "nand" "new" "next" "nor" "not" "null"
4783 "of" "on" "open" "or" "others" "out"
4784 "package" "port" "postponed" "procedure" "process" "pure"
4785 "range" "record" "register" "reject" "rem" "report" "return"
4786 "rol" "ror"
4787 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4788 "then" "to" "transport" "type"
4789 "unaffected" "units" "until" "use"
4790 "variable"
4791 "wait" "when" "while" "with"
4792 "xnor" "xor"
4793 )
4794 "List of VHDL'93 keywords.")
4795
4796 (defconst vhdl-ams-keywords
4797 '(
4798 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4799 "reference" "spectrum" "subnature" "terminal" "through"
4800 "tolerance"
4801 )
4802 "List of VHDL-AMS keywords.")
4803
4804 (defconst vhdl-verilog-keywords
4805 '(
4806 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4807 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4808 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4809 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4810 "endprimitive" "endspecify" "endtable" "endtask" "event"
4811 "for" "force" "forever" "fork" "function"
4812 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4813 "macromodule" "makefile" "medium" "module"
4814 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4815 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4816 "pullup"
4817 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4818 "rtranif0" "rtranif1"
4819 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4820 "strong1" "supply" "supply0" "supply1"
4821 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4822 "triand" "trior" "trireg"
4823 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4824 )
4825 "List of Verilog keywords as candidate for additional reserved words.")
4826
4827 (defconst vhdl-93-types
4828 '(
4829 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4830 "real" "time" "natural" "positive" "string" "line" "text" "side"
4831 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4832 "std_logic" "std_logic_vector"
4833 "std_ulogic" "std_ulogic_vector"
4834 )
4835 "List of VHDL'93 standardized types.")
4836
4837 (defconst vhdl-ams-types
4838 '(
4839 "domain_type" "real_vector"
4840 ;; from `nature_pkg' package
4841 "voltage" "current" "electrical" "position" "velocity" "force"
4842 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4843 "pressure" "flowrate" "fluid"
4844 )
4845 "List of VHDL-AMS standardized types.")
4846
4847 (defconst vhdl-math-types
4848 '(
4849 "complex" "complex_polar"
4850 )
4851 "List of Math Packages standardized types.")
4852
4853 (defconst vhdl-93-attributes
4854 '(
4855 "base" "left" "right" "high" "low" "pos" "val" "succ"
4856 "pred" "leftof" "rightof" "range" "reverse_range"
4857 "length" "delayed" "stable" "quiet" "transaction"
4858 "event" "active" "last_event" "last_active" "last_value"
4859 "driving" "driving_value" "ascending" "value" "image"
4860 "simple_name" "instance_name" "path_name"
4861 "foreign"
4862 )
4863 "List of VHDL'93 standardized attributes.")
4864
4865 (defconst vhdl-ams-attributes
4866 '(
4867 "across" "through"
4868 "reference" "contribution" "tolerance"
4869 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4870 "ramp" "slew"
4871 )
4872 "List of VHDL-AMS standardized attributes.")
4873
4874 (defconst vhdl-93-enum-values
4875 '(
4876 "true" "false"
4877 "note" "warning" "error" "failure"
4878 "read_mode" "write_mode" "append_mode"
4879 "open_ok" "status_error" "name_error" "mode_error"
4880 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4881 "right" "left"
4882 )
4883 "List of VHDL'93 standardized enumeration values.")
4884
4885 (defconst vhdl-ams-enum-values
4886 '(
4887 "quiescent_domain" "time_domain" "frequency_domain"
4888 ;; from `nature_pkg' package
4889 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4890 )
4891 "List of VHDL-AMS standardized enumeration values.")
4892
4893 (defconst vhdl-math-constants
4894 '(
4895 "math_e" "math_1_over_e"
4896 "math_pi" "math_two_pi" "math_1_over_pi"
4897 "math_half_pi" "math_q_pi" "math_3_half_pi"
4898 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4899 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4900 "math_deg_to_rad" "math_rad_to_deg"
4901 "cbase_1" "cbase_j" "czero"
4902 )
4903 "List of Math Packages standardized constants.")
4904
4905 (defconst vhdl-93-functions
4906 '(
4907 "now" "resolved" "rising_edge" "falling_edge"
4908 "read" "readline" "write" "writeline" "endfile"
4909 "resize" "is_X" "std_match"
4910 "shift_left" "shift_right" "rotate_left" "rotate_right"
4911 "to_unsigned" "to_signed" "to_integer"
4912 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4913 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4914 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4915 "shl" "shr" "ext" "sxt"
4916 "deallocate"
4917 )
4918 "List of VHDL'93 standardized functions.")
4919
4920 (defconst vhdl-ams-functions
4921 '(
4922 "frequency"
4923 )
4924 "List of VHDL-AMS standardized functions.")
4925
4926 (defconst vhdl-math-functions
4927 '(
4928 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4929 "sqrt" "cbrt" "exp" "log"
4930 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4931 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4932 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4933 )
4934 "List of Math Packages standardized functions.")
4935
4936 (defconst vhdl-93-packages
4937 '(
4938 "std_logic_1164" "numeric_std" "numeric_bit"
4939 "standard" "textio"
4940 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4941 "std_logic_misc" "std_logic_textio"
4942 "ieee" "std" "work"
4943 )
4944 "List of VHDL'93 standardized packages and libraries.")
4945
4946 (defconst vhdl-ams-packages
4947 '(
4948 ;; from `nature_pkg' package
4949 "nature_pkg"
4950 )
4951 "List of VHDL-AMS standardized packages and libraries.")
4952
4953 (defconst vhdl-math-packages
4954 '(
4955 "math_real" "math_complex"
4956 )
4957 "List of Math Packages standardized packages and libraries.")
4958
4959 (defvar vhdl-keywords nil
4960 "List of VHDL keywords.")
4961
4962 (defvar vhdl-types nil
4963 "List of VHDL standardized types.")
4964
4965 (defvar vhdl-attributes nil
4966 "List of VHDL standardized attributes.")
4967
4968 (defvar vhdl-enum-values nil
4969 "List of VHDL standardized enumeration values.")
4970
4971 (defvar vhdl-constants nil
4972 "List of VHDL standardized constants.")
4973
4974 (defvar vhdl-functions nil
4975 "List of VHDL standardized functions.")
4976
4977 (defvar vhdl-packages nil
4978 "List of VHDL standardized packages and libraries.")
4979
4980 (defvar vhdl-reserved-words nil
4981 "List of additional reserved words.")
4982
4983 (defvar vhdl-keywords-regexp nil
4984 "Regexp for VHDL keywords.")
4985
4986 (defvar vhdl-types-regexp nil
4987 "Regexp for VHDL standardized types.")
4988
4989 (defvar vhdl-attributes-regexp nil
4990 "Regexp for VHDL standardized attributes.")
4991
4992 (defvar vhdl-enum-values-regexp nil
4993 "Regexp for VHDL standardized enumeration values.")
4994
4995 (defvar vhdl-functions-regexp nil
4996 "Regexp for VHDL standardized functions.")
4997
4998 (defvar vhdl-packages-regexp nil
4999 "Regexp for VHDL standardized packages and libraries.")
5000
5001 (defvar vhdl-reserved-words-regexp nil
5002 "Regexp for additional reserved words.")
5003
5004 (defvar vhdl-directive-keywords-regexp nil
5005 "Regexp for compiler directive keywords.")
5006
5007 (defun vhdl-words-init ()
5008 "Initialize reserved words."
5009 (setq vhdl-keywords
5010 (append vhdl-93-keywords
5011 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5012 (setq vhdl-types
5013 (append vhdl-93-types
5014 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5015 (when (vhdl-standard-p 'math) vhdl-math-types)))
5016 (setq vhdl-attributes
5017 (append vhdl-93-attributes
5018 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5019 (setq vhdl-enum-values
5020 (append vhdl-93-enum-values
5021 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5022 (setq vhdl-constants
5023 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5024 (setq vhdl-functions
5025 (append vhdl-93-functions
5026 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5027 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5028 (setq vhdl-packages
5029 (append vhdl-93-packages
5030 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5031 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5032 (setq vhdl-reserved-words
5033 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5034 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5035 '("")))
5036 (setq vhdl-keywords-regexp
5037 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5038 (setq vhdl-types-regexp
5039 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5040 (setq vhdl-attributes-regexp
5041 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5042 (setq vhdl-enum-values-regexp
5043 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5044 (setq vhdl-functions-regexp
5045 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5046 (setq vhdl-packages-regexp
5047 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5048 (setq vhdl-reserved-words-regexp
5049 (concat "\\<\\("
5050 (unless (equal vhdl-forbidden-syntax "")
5051 (concat vhdl-forbidden-syntax "\\|"))
5052 (regexp-opt vhdl-reserved-words)
5053 "\\)\\>"))
5054 (setq vhdl-directive-keywords-regexp
5055 (concat "\\<\\(" (mapconcat 'regexp-quote
5056 vhdl-directive-keywords "\\|") "\\)\\>"))
5057 (vhdl-abbrev-list-init))
5058
5059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5060 ;; Words to expand
5061
5062 (defvar vhdl-abbrev-list nil
5063 "Predefined abbreviations for VHDL.")
5064
5065 (defun vhdl-abbrev-list-init ()
5066 (setq vhdl-abbrev-list
5067 (append
5068 (list vhdl-upper-case-keywords) vhdl-keywords
5069 (list vhdl-upper-case-types) vhdl-types
5070 (list vhdl-upper-case-attributes) vhdl-attributes
5071 (list vhdl-upper-case-enum-values) vhdl-enum-values
5072 (list vhdl-upper-case-constants) vhdl-constants
5073 (list nil) vhdl-functions
5074 (list nil) vhdl-packages)))
5075
5076 ;; initialize reserved words for VHDL Mode
5077 (vhdl-words-init)
5078
5079
5080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5081 ;;; Indentation
5082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5083
5084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5085 ;; Syntax analysis
5086
5087 ;; constant regular expressions for looking at various constructs
5088
5089 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5090 "Regexp describing a VHDL symbol.
5091 We cannot use just `word' syntax class since `_' cannot be in word
5092 class. Putting underscore in word class breaks forward word movement
5093 behavior that users are familiar with.")
5094
5095 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5096 "Regexp describing a case statement header key.")
5097
5098 (defconst vhdl-label-key
5099 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5100 "Regexp describing a VHDL label.")
5101
5102 ;; Macro definitions:
5103
5104 (defmacro vhdl-point (position)
5105 "Return the value of point at certain commonly referenced POSITIONs.
5106 POSITION can be one of the following symbols:
5107
5108 bol -- beginning of line
5109 eol -- end of line
5110 bod -- beginning of defun
5111 boi -- back to indentation
5112 eoi -- last whitespace on line
5113 ionl -- indentation of next line
5114 iopl -- indentation of previous line
5115 bonl -- beginning of next line
5116 bopl -- beginning of previous line
5117
5118 This function does not modify point or mark."
5119 (or (and (eq 'quote (car-safe position))
5120 (null (cddr position)))
5121 (error "ERROR: Bad buffer position requested: %s" position))
5122 (setq position (nth 1 position))
5123 `(let ((here (point)))
5124 ,@(cond
5125 ((eq position 'bol) '((beginning-of-line)))
5126 ((eq position 'eol) '((end-of-line)))
5127 ((eq position 'bod) '((save-match-data
5128 (vhdl-beginning-of-defun))))
5129 ((eq position 'boi) '((back-to-indentation)))
5130 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5131 ((eq position 'bonl) '((forward-line 1)))
5132 ((eq position 'bopl) '((forward-line -1)))
5133 ((eq position 'iopl)
5134 '((forward-line -1)
5135 (back-to-indentation)))
5136 ((eq position 'ionl)
5137 '((forward-line 1)
5138 (back-to-indentation)))
5139 (t (error "ERROR: Unknown buffer position requested: %s" position))
5140 )
5141 (prog1
5142 (point)
5143 (goto-char here))
5144 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5145 ;; doesn't hurt for v19
5146 ,@nil
5147 ))
5148
5149 (defmacro vhdl-safe (&rest body)
5150 "Safely execute BODY, return nil if an error occurred."
5151 `(condition-case nil
5152 (progn ,@body)
5153 (error nil)))
5154
5155 (defmacro vhdl-add-syntax (symbol &optional relpos)
5156 "A simple macro to append the syntax in SYMBOL to the syntax list.
5157 Try to increase performance by using this macro."
5158 `(setq vhdl-syntactic-context
5159 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5160
5161 (defmacro vhdl-has-syntax (symbol)
5162 "A simple macro to return check the syntax list.
5163 Try to increase performance by using this macro."
5164 `(assoc ,symbol vhdl-syntactic-context))
5165
5166 ;; Syntactic element offset manipulation:
5167
5168 (defun vhdl-read-offset (langelem)
5169 "Read new offset value for LANGELEM from minibuffer.
5170 Return a valid value only."
5171 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5172 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5173 (prompt "Offset: ")
5174 offset input interned)
5175 (while (not offset)
5176 (setq input (read-string prompt oldoff)
5177 offset (cond ((string-equal "+" input) '+)
5178 ((string-equal "-" input) '-)
5179 ((string-equal "++" input) '++)
5180 ((string-equal "--" input) '--)
5181 ((string-match "^-?[0-9]+$" input)
5182 (string-to-number input))
5183 ((fboundp (setq interned (intern input)))
5184 interned)
5185 ((boundp interned) interned)
5186 ;; error, but don't signal one, keep trying
5187 ;; to read an input value
5188 (t (ding)
5189 (setq prompt errmsg)
5190 nil))))
5191 offset))
5192
5193 (defun vhdl-set-offset (symbol offset &optional add-p)
5194 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5195 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5196 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5197 `vhdl-offsets-alist' if it doesn't already appear there."
5198 (interactive
5199 (let* ((langelem
5200 (intern (completing-read
5201 (concat "Syntactic symbol to change"
5202 (if current-prefix-arg " or add" "")
5203 ": ")
5204 (mapcar
5205 (function
5206 (lambda (langelem)
5207 (cons (format "%s" (car langelem)) nil)))
5208 vhdl-offsets-alist)
5209 nil (not current-prefix-arg)
5210 ;; initial contents tries to be the last element
5211 ;; on the syntactic analysis list for the current
5212 ;; line
5213 (let* ((syntax (vhdl-get-syntactic-context))
5214 (len (length syntax))
5215 (ic (format "%s" (car (nth (1- len) syntax)))))
5216 ic)
5217 )))
5218 (offset (vhdl-read-offset langelem)))
5219 (list langelem offset current-prefix-arg)))
5220 ;; sanity check offset
5221 (or (eq offset '+)
5222 (eq offset '-)
5223 (eq offset '++)
5224 (eq offset '--)
5225 (integerp offset)
5226 (fboundp offset)
5227 (boundp offset)
5228 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5229 offset))
5230 (let ((entry (assq symbol vhdl-offsets-alist)))
5231 (if entry
5232 (setcdr entry offset)
5233 (if add-p
5234 (setq vhdl-offsets-alist
5235 (cons (cons symbol offset) vhdl-offsets-alist))
5236 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5237 (vhdl-keep-region-active))
5238
5239 (defun vhdl-set-style (style &optional local)
5240 "Set `vhdl-mode' variables to use one of several different indentation styles.
5241 STYLE is a string representing the desired style and optional LOCAL is
5242 a flag which, if non-nil, means to make the style variables being
5243 changed buffer local, instead of the default, which is to set the
5244 global variables. Interactively, the flag comes from the prefix
5245 argument. The styles are chosen from the `vhdl-style-alist' variable."
5246 (interactive (list (completing-read "Use which VHDL indentation style? "
5247 vhdl-style-alist nil t)
5248 current-prefix-arg))
5249 (let ((vars (cdr (assoc style vhdl-style-alist))))
5250 (or vars
5251 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5252 ;; set all the variables
5253 (mapc
5254 (function
5255 (lambda (varentry)
5256 (let ((var (car varentry))
5257 (val (cdr varentry)))
5258 ;; special case for vhdl-offsets-alist
5259 (if (not (eq var 'vhdl-offsets-alist))
5260 (set (if local (make-local-variable var) var) val)
5261 ;; reset vhdl-offsets-alist to the default value first
5262 (set (if local (make-local-variable var) var)
5263 (copy-alist vhdl-offsets-alist-default))
5264 ;; now set the langelems that are different
5265 (mapcar
5266 (function
5267 (lambda (langentry)
5268 (let ((langelem (car langentry))
5269 (offset (cdr langentry)))
5270 (vhdl-set-offset langelem offset)
5271 )))
5272 val))
5273 )))
5274 vars))
5275 (vhdl-keep-region-active))
5276
5277 (defun vhdl-get-offset (langelem)
5278 "Get offset from LANGELEM which is a cons cell of the form:
5279 \(SYMBOL . RELPOS). The symbol is matched against
5280 vhdl-offsets-alist and the offset found there is either returned,
5281 or added to the indentation at RELPOS. If RELPOS is nil, then
5282 the offset is simply returned."
5283 (let* ((symbol (car langelem))
5284 (relpos (cdr langelem))
5285 (match (assq symbol vhdl-offsets-alist))
5286 (offset (cdr-safe match)))
5287 ;; offset can be a number, a function, a variable, or one of the
5288 ;; symbols + or -
5289 (cond
5290 ((not match)
5291 (if vhdl-strict-syntax-p
5292 (error "ERROR: Don't know how to indent a %s" symbol)
5293 (setq offset 0
5294 relpos 0)))
5295 ((eq offset '+) (setq offset vhdl-basic-offset))
5296 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5297 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5298 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5299 ((and (not (numberp offset))
5300 (fboundp offset))
5301 (setq offset (funcall offset langelem)))
5302 ((not (numberp offset))
5303 (setq offset (eval offset)))
5304 )
5305 (+ (if (and relpos
5306 (< relpos (vhdl-point 'bol)))
5307 (save-excursion
5308 (goto-char relpos)
5309 (current-column))
5310 0)
5311 offset)))
5312
5313 ;; Syntactic support functions:
5314
5315 (defun vhdl-in-comment-p ()
5316 "Check if point is in a comment."
5317 (eq (vhdl-in-literal) 'comment))
5318
5319 (defun vhdl-in-string-p ()
5320 "Check if point is in a string."
5321 (eq (vhdl-in-literal) 'string))
5322
5323 (defun vhdl-in-literal ()
5324 "Determine if point is in a VHDL literal."
5325 (save-excursion
5326 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5327 (cond
5328 ((nth 3 state) 'string)
5329 ((nth 4 state) 'comment)
5330 ((vhdl-beginning-of-macro) 'pound)
5331 (t nil)))))
5332
5333 (defun vhdl-forward-comment (&optional direction)
5334 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5335 negative, skip forward otherwise."
5336 (interactive "p")
5337 (if (and direction (< direction 0))
5338 ;; skip backwards
5339 (progn
5340 (skip-chars-backward " \t\n")
5341 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5342 (goto-char (match-beginning 3))
5343 (skip-chars-backward " \t\n")))
5344 ;; skip forwards
5345 (skip-chars-forward " \t\n")
5346 (while (looking-at "--.*")
5347 (goto-char (match-end 0))
5348 (skip-chars-forward " \t\n"))))
5349
5350 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5351 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5352 (defalias 'vhdl-forward-comment 'forward-comment))
5353
5354 ;; This is the best we can do in Win-Emacs.
5355 (defun vhdl-win-il (&optional lim)
5356 "Determine if point is in a VHDL literal."
5357 (save-excursion
5358 (let* ((here (point))
5359 (state nil)
5360 (match nil)
5361 (lim (or lim (vhdl-point 'bod))))
5362 (goto-char lim )
5363 (while (< (point) here)
5364 (setq match
5365 (and (re-search-forward "--\\|[\"']"
5366 here 'move)
5367 (buffer-substring (match-beginning 0) (match-end 0))))
5368 (setq state
5369 (cond
5370 ;; no match
5371 ((null match) nil)
5372 ;; looking at the opening of a VHDL style comment
5373 ((string= "--" match)
5374 (if (<= here (progn (end-of-line) (point))) 'comment))
5375 ;; looking at the opening of a double quote string
5376 ((string= "\"" match)
5377 (if (not (save-restriction
5378 ;; this seems to be necessary since the
5379 ;; re-search-forward will not work without it
5380 (narrow-to-region (point) here)
5381 (re-search-forward
5382 ;; this regexp matches a double quote
5383 ;; which is preceded by an even number
5384 ;; of backslashes, including zero
5385 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5386 'string))
5387 ;; looking at the opening of a single quote string
5388 ((string= "'" match)
5389 (if (not (save-restriction
5390 ;; see comments from above
5391 (narrow-to-region (point) here)
5392 (re-search-forward
5393 ;; this matches a single quote which is
5394 ;; preceded by zero or two backslashes.
5395 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5396 here 'move)))
5397 'string))
5398 (t nil)))
5399 ) ; end-while
5400 state)))
5401
5402 (and (string-match "Win-Emacs" emacs-version)
5403 (fset 'vhdl-in-literal 'vhdl-win-il))
5404
5405 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5406 ;; defined as lexical whitespace or comments. Search no farther back
5407 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5408 ;; used for backward skipping, (point-max) is used for forward
5409 ;; skipping.
5410
5411 (defun vhdl-forward-syntactic-ws (&optional lim)
5412 "Forward skip of syntactic whitespace."
5413 (let* ((here (point-max))
5414 (hugenum (point-max)))
5415 (while (/= here (point))
5416 (setq here (point))
5417 (vhdl-forward-comment hugenum)
5418 ;; skip preprocessor directives
5419 (when (and (eq (char-after) ?#)
5420 (= (vhdl-point 'boi) (point)))
5421 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5422 (= (forward-line 1) 0)))
5423 (end-of-line)))
5424 (if lim (goto-char (min (point) lim)))))
5425
5426
5427 ;; This is the best we can do in Win-Emacs.
5428 (defun vhdl-win-fsws (&optional lim)
5429 "Forward skip syntactic whitespace for Win-Emacs."
5430 (let ((lim (or lim (point-max)))
5431 stop)
5432 (while (not stop)
5433 (skip-chars-forward " \t\n\r\f" lim)
5434 (cond
5435 ;; vhdl comment
5436 ((looking-at "--") (end-of-line))
5437 ;; none of the above
5438 (t (setq stop t))))))
5439
5440 (and (string-match "Win-Emacs" emacs-version)
5441 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5442
5443 (defun vhdl-beginning-of-macro (&optional lim)
5444 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5445 (let ((here (point)))
5446 (beginning-of-line)
5447 (while (eq (char-before (1- (point))) ?\\)
5448 (forward-line -1))
5449 (back-to-indentation)
5450 (if (and (<= (point) here)
5451 (eq (char-after) ?#))
5452 t
5453 (goto-char here)
5454 nil)))
5455
5456 (defun vhdl-backward-syntactic-ws (&optional lim)
5457 "Backward skip over syntactic whitespace."
5458 (let* ((here (point-min))
5459 (hugenum (- (point-max))))
5460 (while (/= here (point))
5461 (setq here (point))
5462 (vhdl-forward-comment hugenum)
5463 (vhdl-beginning-of-macro))
5464 (if lim (goto-char (max (point) lim)))))
5465
5466 ;; This is the best we can do in Win-Emacs.
5467 (defun vhdl-win-bsws (&optional lim)
5468 "Backward skip syntactic whitespace for Win-Emacs."
5469 (let ((lim (or lim (vhdl-point 'bod)))
5470 stop)
5471 (while (not stop)
5472 (skip-chars-backward " \t\n\r\f" lim)
5473 (cond
5474 ;; vhdl comment
5475 ((eq (vhdl-in-literal) 'comment)
5476 (skip-chars-backward "^-" lim)
5477 (skip-chars-backward "-" lim)
5478 (while (not (or (and (= (following-char) ?-)
5479 (= (char-after (1+ (point))) ?-))
5480 (<= (point) lim)))
5481 (skip-chars-backward "^-" lim)
5482 (skip-chars-backward "-" lim)))
5483 ;; none of the above
5484 (t (setq stop t))))))
5485
5486 (and (string-match "Win-Emacs" emacs-version)
5487 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5488
5489 ;; Functions to help finding the correct indentation column:
5490
5491 (defun vhdl-first-word (point)
5492 "If the keyword at POINT is at boi, then return (current-column) at
5493 that point, else nil."
5494 (save-excursion
5495 (and (goto-char point)
5496 (eq (point) (vhdl-point 'boi))
5497 (current-column))))
5498
5499 (defun vhdl-last-word (point)
5500 "If the keyword at POINT is at eoi, then return (current-column) at
5501 that point, else nil."
5502 (save-excursion
5503 (and (goto-char point)
5504 (save-excursion (or (eq (progn (forward-sexp) (point))
5505 (vhdl-point 'eoi))
5506 (looking-at "\\s-*\\(--\\)?")))
5507 (current-column))))
5508
5509 ;; Core syntactic evaluation functions:
5510
5511 (defconst vhdl-libunit-re
5512 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5513
5514 (defun vhdl-libunit-p ()
5515 (and
5516 (save-excursion
5517 (forward-sexp)
5518 (skip-chars-forward " \t\n")
5519 (not (looking-at "is\\b[^_]")))
5520 (save-excursion
5521 (backward-sexp)
5522 (and (not (looking-at "use\\b[^_]"))
5523 (progn
5524 (forward-sexp)
5525 (vhdl-forward-syntactic-ws)
5526 (/= (following-char) ?:))))
5527 ))
5528
5529 (defconst vhdl-defun-re
5530 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5531
5532 (defun vhdl-defun-p ()
5533 (save-excursion
5534 (if (looking-at "block\\|process\\|procedural")
5535 ;; "block", "process", "procedural":
5536 (save-excursion
5537 (backward-sexp)
5538 (not (looking-at "end\\s-+\\w")))
5539 ;; "architecture", "configuration", "entity",
5540 ;; "package", "procedure", "function":
5541 t)))
5542
5543 (defun vhdl-corresponding-defun ()
5544 "If the word at the current position corresponds to a \"defun\"
5545 keyword, then return a string that can be used to find the
5546 corresponding \"begin\" keyword, else return nil."
5547 (save-excursion
5548 (and (looking-at vhdl-defun-re)
5549 (vhdl-defun-p)
5550 (if (looking-at "block\\|process\\|procedural")
5551 ;; "block", "process". "procedural:
5552 (buffer-substring (match-beginning 0) (match-end 0))
5553 ;; "architecture", "configuration", "entity", "package",
5554 ;; "procedure", "function":
5555 "is"))))
5556
5557 (defconst vhdl-begin-fwd-re
5558 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5559 "A regular expression for searching forward that matches all known
5560 \"begin\" keywords.")
5561
5562 (defconst vhdl-begin-bwd-re
5563 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5564 "A regular expression for searching backward that matches all known
5565 \"begin\" keywords.")
5566
5567 (defun vhdl-begin-p (&optional lim)
5568 "Return t if we are looking at a real \"begin\" keyword.
5569 Assumes that the caller will make sure that we are looking at
5570 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5571 the middle of an identifier that just happens to contain a \"begin\"
5572 keyword."
5573 (cond
5574 ;; "[architecture|case|configuration|entity|package|
5575 ;; procedure|function] ... is":
5576 ((and (looking-at "i")
5577 (save-excursion
5578 ;; Skip backward over first sexp (needed to skip over a
5579 ;; procedure interface list, and is harmless in other
5580 ;; situations). Note that we need "return" in the
5581 ;; following search list so that we don't run into
5582 ;; semicolons in the function interface list.
5583 (backward-sexp)
5584 (let (foundp)
5585 (while (and (not foundp)
5586 (re-search-backward
5587 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5588 lim 'move))
5589 (if (or (= (preceding-char) ?_)
5590 (vhdl-in-literal))
5591 (backward-char)
5592 (setq foundp t))))
5593 (and (/= (following-char) ?\;)
5594 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5595 t)
5596 ;; "begin", "then":
5597 ((looking-at "be\\|t")
5598 t)
5599 ;; "else":
5600 ((and (looking-at "e")
5601 ;; make sure that the "else" isn't inside a
5602 ;; conditional signal assignment.
5603 (save-excursion
5604 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5605 (or (eq (following-char) ?\;)
5606 (eq (point) lim))))
5607 t)
5608 ;; "block", "generate", "loop", "process", "procedural",
5609 ;; "units", "record":
5610 ((and (looking-at "bl\\|[glpur]")
5611 (save-excursion
5612 (backward-sexp)
5613 (not (looking-at "end\\s-+\\w"))))
5614 t)
5615 ;; "component":
5616 ((and (looking-at "c")
5617 (save-excursion
5618 (backward-sexp)
5619 (not (looking-at "end\\s-+\\w")))
5620 ;; look out for the dreaded entity class in an attribute
5621 (save-excursion
5622 (vhdl-backward-syntactic-ws lim)
5623 (/= (preceding-char) ?:)))
5624 t)
5625 ;; "for" (inside configuration declaration):
5626 ((and (looking-at "f")
5627 (save-excursion
5628 (backward-sexp)
5629 (not (looking-at "end\\s-+\\w")))
5630 (vhdl-has-syntax 'configuration))
5631 t)
5632 ))
5633
5634 (defun vhdl-corresponding-mid (&optional lim)
5635 (cond
5636 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5637 "begin")
5638 ((looking-at "then")
5639 "<else>")
5640 (t
5641 "end")))
5642
5643 (defun vhdl-corresponding-end (&optional lim)
5644 "If the word at the current position corresponds to a \"begin\"
5645 keyword, then return a vector containing enough information to find
5646 the corresponding \"end\" keyword, else return nil. The keyword to
5647 search forward for is aref 0. The column in which the keyword must
5648 appear is aref 1 or nil if any column is suitable.
5649 Assumes that the caller will make sure that we are not in the middle
5650 of an identifier that just happens to contain a \"begin\" keyword."
5651 (save-excursion
5652 (and (looking-at vhdl-begin-fwd-re)
5653 (/= (preceding-char) ?_)
5654 (not (vhdl-in-literal))
5655 (vhdl-begin-p lim)
5656 (cond
5657 ;; "is", "generate", "loop":
5658 ((looking-at "[igl]")
5659 (vector "end"
5660 (and (vhdl-last-word (point))
5661 (or (vhdl-first-word (point))
5662 (save-excursion
5663 (vhdl-beginning-of-statement-1 lim)
5664 (vhdl-backward-skip-label lim)
5665 (vhdl-first-word (point)))))))
5666 ;; "begin", "else", "for":
5667 ((looking-at "be\\|[ef]")
5668 (vector "end"
5669 (and (vhdl-last-word (point))
5670 (or (vhdl-first-word (point))
5671 (save-excursion
5672 (vhdl-beginning-of-statement-1 lim)
5673 (vhdl-backward-skip-label lim)
5674 (vhdl-first-word (point)))))))
5675 ;; "component", "units", "record":
5676 ((looking-at "[cur]")
5677 ;; The first end found will close the block
5678 (vector "end" nil))
5679 ;; "block", "process", "procedural":
5680 ((looking-at "bl\\|p")
5681 (vector "end"
5682 (or (vhdl-first-word (point))
5683 (save-excursion
5684 (vhdl-beginning-of-statement-1 lim)
5685 (vhdl-backward-skip-label lim)
5686 (vhdl-first-word (point))))))
5687 ;; "then":
5688 ((looking-at "t")
5689 (vector "elsif\\|else\\|end\\s-+if"
5690 (and (vhdl-last-word (point))
5691 (or (vhdl-first-word (point))
5692 (save-excursion
5693 (vhdl-beginning-of-statement-1 lim)
5694 (vhdl-backward-skip-label lim)
5695 (vhdl-first-word (point)))))))
5696 ))))
5697
5698 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5699
5700 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5701
5702 (defun vhdl-end-p (&optional lim)
5703 "Return t if we are looking at a real \"end\" keyword.
5704 Assumes that the caller will make sure that we are looking at
5705 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5706 the middle of an identifier that just happens to contain an \"end\"
5707 keyword."
5708 (or (not (looking-at "else"))
5709 ;; make sure that the "else" isn't inside a conditional signal
5710 ;; assignment.
5711 (save-excursion
5712 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5713 (or (eq (following-char) ?\;)
5714 (eq (point) lim)
5715 (vhdl-in-literal)))))
5716
5717 (defun vhdl-corresponding-begin (&optional lim)
5718 "If the word at the current position corresponds to an \"end\"
5719 keyword, then return a vector containing enough information to find
5720 the corresponding \"begin\" keyword, else return nil. The keyword to
5721 search backward for is aref 0. The column in which the keyword must
5722 appear is aref 1 or nil if any column is suitable. The supplementary
5723 keyword to search forward for is aref 2 or nil if this is not
5724 required. If aref 3 is t, then the \"begin\" keyword may be found in
5725 the middle of a statement.
5726 Assumes that the caller will make sure that we are not in the middle
5727 of an identifier that just happens to contain an \"end\" keyword."
5728 (save-excursion
5729 (let (pos)
5730 (if (and (looking-at vhdl-end-fwd-re)
5731 (not (vhdl-in-literal))
5732 (vhdl-end-p lim))
5733 (if (looking-at "el")
5734 ;; "else", "elsif":
5735 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5736 ;; "end ...":
5737 (setq pos (point))
5738 (forward-sexp)
5739 (skip-chars-forward " \t\n")
5740 (cond
5741 ;; "end if":
5742 ((looking-at "if\\b[^_]")
5743 (vector "else\\|elsif\\|if"
5744 (vhdl-first-word pos)
5745 "else\\|then" nil))
5746 ;; "end component":
5747 ((looking-at "component\\b[^_]")
5748 (vector (buffer-substring (match-beginning 1)
5749 (match-end 1))
5750 (vhdl-first-word pos)
5751 nil nil))
5752 ;; "end units", "end record":
5753 ((looking-at "\\(units\\|record\\)\\b[^_]")
5754 (vector (buffer-substring (match-beginning 1)
5755 (match-end 1))
5756 (vhdl-first-word pos)
5757 nil t))
5758 ;; "end block", "end process", "end procedural":
5759 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5760 (vector "begin" (vhdl-first-word pos) nil nil))
5761 ;; "end case":
5762 ((looking-at "case\\b[^_]")
5763 (vector "case" (vhdl-first-word pos) "is" nil))
5764 ;; "end generate":
5765 ((looking-at "generate\\b[^_]")
5766 (vector "generate\\|for\\|if"
5767 (vhdl-first-word pos)
5768 "generate" nil))
5769 ;; "end loop":
5770 ((looking-at "loop\\b[^_]")
5771 (vector "loop\\|while\\|for"
5772 (vhdl-first-word pos)
5773 "loop" nil))
5774 ;; "end for" (inside configuration declaration):
5775 ((looking-at "for\\b[^_]")
5776 (vector "for" (vhdl-first-word pos) nil nil))
5777 ;; "end [id]":
5778 (t
5779 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5780 (vhdl-first-word pos)
5781 ;; return an alist of (statement . keyword) mappings
5782 '(
5783 ;; "begin ... end [id]":
5784 ("begin" . nil)
5785 ;; "architecture ... is ... begin ... end [id]":
5786 ("architecture" . "is")
5787 ;; "configuration ... is ... end [id]":
5788 ("configuration" . "is")
5789 ;; "entity ... is ... end [id]":
5790 ("entity" . "is")
5791 ;; "package ... is ... end [id]":
5792 ("package" . "is")
5793 ;; "procedure ... is ... begin ... end [id]":
5794 ("procedure" . "is")
5795 ;; "function ... is ... begin ... end [id]":
5796 ("function" . "is")
5797 )
5798 nil))
5799 ))) ; "end ..."
5800 )))
5801
5802 (defconst vhdl-leader-re
5803 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5804
5805 (defun vhdl-end-of-leader ()
5806 (save-excursion
5807 (cond ((looking-at "block\\|process\\|procedural")
5808 (if (save-excursion
5809 (forward-sexp)
5810 (skip-chars-forward " \t\n")
5811 (= (following-char) ?\())
5812 (forward-sexp 2)
5813 (forward-sexp))
5814 (when (looking-at "[ \t\n]*is")
5815 (goto-char (match-end 0)))
5816 (point))
5817 ((looking-at "component")
5818 (forward-sexp 2)
5819 (when (looking-at "[ \t\n]*is")
5820 (goto-char (match-end 0)))
5821 (point))
5822 ((looking-at "for")
5823 (forward-sexp 2)
5824 (skip-chars-forward " \t\n")
5825 (while (looking-at "[,:(]")
5826 (forward-sexp)
5827 (skip-chars-forward " \t\n"))
5828 (point))
5829 (t nil)
5830 )))
5831
5832 (defconst vhdl-trailer-re
5833 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5834
5835 (defconst vhdl-statement-fwd-re
5836 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5837 "A regular expression for searching forward that matches all known
5838 \"statement\" keywords.")
5839
5840 (defconst vhdl-statement-bwd-re
5841 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5842 "A regular expression for searching backward that matches all known
5843 \"statement\" keywords.")
5844
5845 (defun vhdl-statement-p (&optional lim)
5846 "Return t if we are looking at a real \"statement\" keyword.
5847 Assumes that the caller will make sure that we are looking at
5848 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5849 in the middle of an identifier that just happens to contain a
5850 \"statement\" keyword."
5851 (cond
5852 ;; "for" ... "generate":
5853 ((and (looking-at "f")
5854 ;; Make sure it's the start of a parameter specification.
5855 (save-excursion
5856 (forward-sexp 2)
5857 (skip-chars-forward " \t\n")
5858 (looking-at "in\\b[^_]"))
5859 ;; Make sure it's not an "end for".
5860 (save-excursion
5861 (backward-sexp)
5862 (not (looking-at "end\\s-+\\w"))))
5863 t)
5864 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5865 ((and (looking-at "i")
5866 ;; Make sure it's not an "end if".
5867 (save-excursion
5868 (backward-sexp)
5869 (not (looking-at "end\\s-+\\w"))))
5870 t)
5871 ;; "while" ... "loop":
5872 ((looking-at "w")
5873 t)
5874 ))
5875
5876 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5877 "Regexp describing a case statement alternative key.")
5878
5879 (defun vhdl-case-alternative-p (&optional lim)
5880 "Return t if we are looking at a real case alternative.
5881 Assumes that the caller will make sure that we are looking at
5882 vhdl-case-alternative-re, and are not inside a literal, and that
5883 we are not in the middle of an identifier that just happens to
5884 contain a \"when\" keyword."
5885 (save-excursion
5886 (let (foundp)
5887 (while (and (not foundp)
5888 (re-search-backward ";\\|<=" lim 'move))
5889 (if (or (= (preceding-char) ?_)
5890 (vhdl-in-literal))
5891 (backward-char)
5892 (setq foundp t)))
5893 (or (eq (following-char) ?\;)
5894 (eq (point) lim)))
5895 ))
5896
5897 ;; Core syntactic movement functions:
5898
5899 (defconst vhdl-b-t-b-re
5900 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5901
5902 (defun vhdl-backward-to-block (&optional lim)
5903 "Move backward to the previous \"begin\" or \"end\" keyword."
5904 (let (foundp)
5905 (while (and (not foundp)
5906 (re-search-backward vhdl-b-t-b-re lim 'move))
5907 (if (or (= (preceding-char) ?_)
5908 (vhdl-in-literal))
5909 (backward-char)
5910 (cond
5911 ;; "begin" keyword:
5912 ((and (looking-at vhdl-begin-fwd-re)
5913 (/= (preceding-char) ?_)
5914 (vhdl-begin-p lim))
5915 (setq foundp 'begin))
5916 ;; "end" keyword:
5917 ((and (looking-at vhdl-end-fwd-re)
5918 (/= (preceding-char) ?_)
5919 (vhdl-end-p lim))
5920 (setq foundp 'end))
5921 ))
5922 )
5923 foundp
5924 ))
5925
5926 (defun vhdl-forward-sexp (&optional count lim)
5927 "Move forward across one balanced expression (sexp).
5928 With COUNT, do it that many times."
5929 (interactive "p")
5930 (let ((count (or count 1))
5931 (case-fold-search t)
5932 end-vec target)
5933 (save-excursion
5934 (while (> count 0)
5935 ;; skip whitespace
5936 (skip-chars-forward " \t\n")
5937 ;; Check for an unbalanced "end" keyword
5938 (if (and (looking-at vhdl-end-fwd-re)
5939 (/= (preceding-char) ?_)
5940 (not (vhdl-in-literal))
5941 (vhdl-end-p lim)
5942 (not (looking-at "else")))
5943 (error
5944 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5945 ;; If the current keyword is a "begin" keyword, then find the
5946 ;; corresponding "end" keyword.
5947 (if (setq end-vec (vhdl-corresponding-end lim))
5948 (let (
5949 ;; end-re is the statement keyword to search for
5950 (end-re
5951 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5952 ;; column is either the statement keyword target column
5953 ;; or nil
5954 (column (aref end-vec 1))
5955 (eol (vhdl-point 'eol))
5956 foundp literal placeholder)
5957 ;; Look for the statement keyword.
5958 (while (and (not foundp)
5959 (re-search-forward end-re nil t)
5960 (setq placeholder (match-end 1))
5961 (goto-char (match-beginning 0)))
5962 ;; If we are in a literal, or not in the right target
5963 ;; column and not on the same line as the begin, then
5964 ;; try again.
5965 (if (or (and column
5966 (/= (current-indentation) column)
5967 (> (point) eol))
5968 (= (preceding-char) ?_)
5969 (setq literal (vhdl-in-literal)))
5970 (if (eq literal 'comment)
5971 (end-of-line)
5972 (forward-char))
5973 ;; An "else" keyword corresponds to both the opening brace
5974 ;; of the following sexp and the closing brace of the
5975 ;; previous sexp.
5976 (if (not (looking-at "else"))
5977 (goto-char placeholder))
5978 (setq foundp t))
5979 )
5980 (if (not foundp)
5981 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5982 )
5983 ;; If the current keyword is not a "begin" keyword, then just
5984 ;; perform the normal forward-sexp.
5985 (forward-sexp)
5986 )
5987 (setq count (1- count))
5988 )
5989 (setq target (point)))
5990 (goto-char target)
5991 nil))
5992
5993 (defun vhdl-backward-sexp (&optional count lim)
5994 "Move backward across one balanced expression (sexp).
5995 With COUNT, do it that many times. LIM bounds any required backward
5996 searches."
5997 (interactive "p")
5998 (let ((count (or count 1))
5999 (case-fold-search t)
6000 begin-vec target)
6001 (save-excursion
6002 (while (> count 0)
6003 ;; Perform the normal backward-sexp, unless we are looking at
6004 ;; "else" - an "else" keyword corresponds to both the opening brace
6005 ;; of the following sexp and the closing brace of the previous sexp.
6006 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6007 (/= (preceding-char) ?_)
6008 (not (vhdl-in-literal)))
6009 nil
6010 (backward-sexp)
6011 (if (and (looking-at vhdl-begin-fwd-re)
6012 (/= (preceding-char) ?_)
6013 (not (vhdl-in-literal))
6014 (vhdl-begin-p lim))
6015 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6016 ;; If the current keyword is an "end" keyword, then find the
6017 ;; corresponding "begin" keyword.
6018 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6019 (/= (preceding-char) ?_))
6020 (let (
6021 ;; begin-re is the statement keyword to search for
6022 (begin-re
6023 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6024 ;; column is either the statement keyword target column
6025 ;; or nil
6026 (column (aref begin-vec 1))
6027 ;; internal-p controls where the statement keyword can
6028 ;; be found.
6029 (internal-p (aref begin-vec 3))
6030 (last-backward (point)) last-forward
6031 foundp literal keyword)
6032 ;; Look for the statement keyword.
6033 (while (and (not foundp)
6034 (re-search-backward begin-re lim t)
6035 (setq keyword
6036 (buffer-substring (match-beginning 1)
6037 (match-end 1))))
6038 ;; If we are in a literal or in the wrong column,
6039 ;; then try again.
6040 (if (or (and column
6041 (and (/= (current-indentation) column)
6042 ;; possibly accept current-column as
6043 ;; well as current-indentation.
6044 (or (not internal-p)
6045 (/= (current-column) column))))
6046 (= (preceding-char) ?_)
6047 (vhdl-in-literal))
6048 (backward-char)
6049 ;; If there is a supplementary keyword, then
6050 ;; search forward for it.
6051 (if (and (setq begin-re (aref begin-vec 2))
6052 (or (not (listp begin-re))
6053 ;; If begin-re is an alist, then find the
6054 ;; element corresponding to the actual
6055 ;; keyword that we found.
6056 (progn
6057 (setq begin-re
6058 (assoc keyword begin-re))
6059 (and begin-re
6060 (setq begin-re (cdr begin-re))))))
6061 (and
6062 (setq begin-re
6063 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6064 (save-excursion
6065 (setq last-forward (point))
6066 ;; Look for the supplementary keyword
6067 ;; (bounded by the backward search start
6068 ;; point).
6069 (while (and (not foundp)
6070 (re-search-forward begin-re
6071 last-backward t)
6072 (goto-char (match-beginning 1)))
6073 ;; If we are in a literal, then try again.
6074 (if (or (= (preceding-char) ?_)
6075 (setq literal
6076 (vhdl-in-literal)))
6077 (if (eq literal 'comment)
6078 (goto-char
6079 (min (vhdl-point 'eol) last-backward))
6080 (forward-char))
6081 ;; We have found the supplementary keyword.
6082 ;; Save the position of the keyword in foundp.
6083 (setq foundp (point)))
6084 )
6085 foundp)
6086 ;; If the supplementary keyword was found, then
6087 ;; move point to the supplementary keyword.
6088 (goto-char foundp))
6089 ;; If there was no supplementary keyword, then
6090 ;; point is already at the statement keyword.
6091 (setq foundp t)))
6092 ) ; end of the search for the statement keyword
6093 (if (not foundp)
6094 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6095 ))
6096 (setq count (1- count))
6097 )
6098 (setq target (point)))
6099 (goto-char target)
6100 nil))
6101
6102 (defun vhdl-backward-up-list (&optional count limit)
6103 "Move backward out of one level of blocks.
6104 With argument, do this that many times."
6105 (interactive "p")
6106 (let ((count (or count 1))
6107 target)
6108 (save-excursion
6109 (while (> count 0)
6110 (if (looking-at vhdl-defun-re)
6111 (error "ERROR: Unbalanced blocks"))
6112 (vhdl-backward-to-block limit)
6113 (setq count (1- count)))
6114 (setq target (point)))
6115 (goto-char target)))
6116
6117 (defun vhdl-end-of-defun (&optional count)
6118 "Move forward to the end of a VHDL defun."
6119 (interactive)
6120 (let ((case-fold-search t))
6121 (vhdl-beginning-of-defun)
6122 (if (not (looking-at "block\\|process\\|procedural"))
6123 (re-search-forward "\\bis\\b"))
6124 (vhdl-forward-sexp)))
6125
6126 (defun vhdl-mark-defun ()
6127 "Put mark at end of this \"defun\", point at beginning."
6128 (interactive)
6129 (let ((case-fold-search t))
6130 (push-mark)
6131 (vhdl-beginning-of-defun)
6132 (push-mark)
6133 (if (not (looking-at "block\\|process\\|procedural"))
6134 (re-search-forward "\\bis\\b"))
6135 (vhdl-forward-sexp)
6136 (exchange-point-and-mark)))
6137
6138 (defun vhdl-beginning-of-libunit ()
6139 "Move backward to the beginning of a VHDL library unit.
6140 Returns the location of the corresponding begin keyword, unless search
6141 stops due to beginning or end of buffer.
6142 Note that if point is between the \"libunit\" keyword and the
6143 corresponding \"begin\" keyword, then that libunit will not be
6144 recognized, and the search will continue backwards. If point is
6145 at the \"begin\" keyword, then the defun will be recognized. The
6146 returned point is at the first character of the \"libunit\" keyword."
6147 (let ((last-forward (point))
6148 (last-backward
6149 ;; Just in case we are actually sitting on the "begin"
6150 ;; keyword, allow for the keyword and an extra character,
6151 ;; as this will be used when looking forward for the
6152 ;; "begin" keyword.
6153 (save-excursion (forward-word 1) (1+ (point))))
6154 foundp literal placeholder)
6155 ;; Find the "libunit" keyword.
6156 (while (and (not foundp)
6157 (re-search-backward vhdl-libunit-re nil 'move))
6158 ;; If we are in a literal, or not at a real libunit, then try again.
6159 (if (or (= (preceding-char) ?_)
6160 (vhdl-in-literal)
6161 (not (vhdl-libunit-p)))
6162 (backward-char)
6163 ;; Find the corresponding "begin" keyword.
6164 (setq last-forward (point))
6165 (while (and (not foundp)
6166 (re-search-forward "\\bis\\b[^_]" last-backward t)
6167 (setq placeholder (match-beginning 0)))
6168 (if (or (= (preceding-char) ?_)
6169 (setq literal (vhdl-in-literal)))
6170 ;; It wasn't a real keyword, so keep searching.
6171 (if (eq literal 'comment)
6172 (goto-char
6173 (min (vhdl-point 'eol) last-backward))
6174 (forward-char))
6175 ;; We have found the begin keyword, loop will exit.
6176 (setq foundp placeholder)))
6177 ;; Go back to the libunit keyword
6178 (goto-char last-forward)))
6179 foundp))
6180
6181 (defun vhdl-beginning-of-defun (&optional count)
6182 "Move backward to the beginning of a VHDL defun.
6183 With argument, do it that many times.
6184 Returns the location of the corresponding begin keyword, unless search
6185 stops due to beginning or end of buffer."
6186 ;; Note that if point is between the "defun" keyword and the
6187 ;; corresponding "begin" keyword, then that defun will not be
6188 ;; recognized, and the search will continue backwards. If point is
6189 ;; at the "begin" keyword, then the defun will be recognized. The
6190 ;; returned point is at the first character of the "defun" keyword.
6191 (interactive "p")
6192 (let ((count (or count 1))
6193 (case-fold-search t)
6194 (last-forward (point))
6195 foundp)
6196 (while (> count 0)
6197 (setq foundp nil)
6198 (goto-char last-forward)
6199 (let ((last-backward
6200 ;; Just in case we are actually sitting on the "begin"
6201 ;; keyword, allow for the keyword and an extra character,
6202 ;; as this will be used when looking forward for the
6203 ;; "begin" keyword.
6204 (save-excursion (forward-word 1) (1+ (point))))
6205 begin-string literal)
6206 (while (and (not foundp)
6207 (re-search-backward vhdl-defun-re nil 'move))
6208 ;; If we are in a literal, then try again.
6209 (if (or (= (preceding-char) ?_)
6210 (vhdl-in-literal))
6211 (backward-char)
6212 (if (setq begin-string (vhdl-corresponding-defun))
6213 ;; This is a real defun keyword.
6214 ;; Find the corresponding "begin" keyword.
6215 ;; Look for the begin keyword.
6216 (progn
6217 ;; Save the search start point.
6218 (setq last-forward (point))
6219 (while (and (not foundp)
6220 (search-forward begin-string last-backward t))
6221 (if (or (= (preceding-char) ?_)
6222 (save-match-data
6223 (setq literal (vhdl-in-literal))))
6224 ;; It wasn't a real keyword, so keep searching.
6225 (if (eq literal 'comment)
6226 (goto-char
6227 (min (vhdl-point 'eol) last-backward))
6228 (forward-char))
6229 ;; We have found the begin keyword, loop will exit.
6230 (setq foundp (match-beginning 0)))
6231 )
6232 ;; Go back to the defun keyword
6233 (goto-char last-forward)) ; end search for begin keyword
6234 ))
6235 ) ; end of the search for the defun keyword
6236 )
6237 (setq count (1- count))
6238 )
6239 (vhdl-keep-region-active)
6240 foundp))
6241
6242 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6243 "Go to the beginning of the innermost VHDL statement.
6244 With prefix arg, go back N - 1 statements. If already at the
6245 beginning of a statement then go to the beginning of the preceding
6246 one. If within a string or comment, or next to a comment (only
6247 whitespace between), move by sentences instead of statements.
6248
6249 When called from a program, this function takes 3 optional args: the
6250 prefix arg, a buffer position limit which is the farthest back to
6251 search, and an argument indicating an interactive call."
6252 (interactive "p\np")
6253 (let ((count (or count 1))
6254 (case-fold-search t)
6255 (lim (or lim (point-min)))
6256 (here (point))
6257 state)
6258 (save-excursion
6259 (goto-char lim)
6260 (setq state (parse-partial-sexp (point) here nil nil)))
6261 (if (and interactive
6262 (or (nth 3 state)
6263 (nth 4 state)
6264 (looking-at (concat "[ \t]*" comment-start-skip))))
6265 (forward-sentence (- count))
6266 (while (> count 0)
6267 (vhdl-beginning-of-statement-1 lim)
6268 (setq count (1- count))))
6269 ;; its possible we've been left up-buf of lim
6270 (goto-char (max (point) lim))
6271 )
6272 (vhdl-keep-region-active))
6273
6274 (defconst vhdl-e-o-s-re
6275 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6276
6277 (defun vhdl-end-of-statement ()
6278 "Very simple implementation."
6279 (interactive)
6280 (re-search-forward vhdl-e-o-s-re))
6281
6282 (defconst vhdl-b-o-s-re
6283 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6284 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6285
6286 (defun vhdl-beginning-of-statement-1 (&optional lim)
6287 "Move to the start of the current statement, or the previous
6288 statement if already at the beginning of one."
6289 (let ((lim (or lim (point-min)))
6290 (here (point))
6291 (pos (point))
6292 donep)
6293 ;; go backwards one balanced expression, but be careful of
6294 ;; unbalanced paren being reached
6295 (if (not (vhdl-safe (progn (backward-sexp) t)))
6296 (progn
6297 (backward-up-list 1)
6298 (forward-char)
6299 (vhdl-forward-syntactic-ws here)
6300 (setq donep t)))
6301 (while (and (not donep)
6302 (not (bobp))
6303 ;; look backwards for a statement boundary
6304 (re-search-backward vhdl-b-o-s-re lim 'move))
6305 (if (or (= (preceding-char) ?_)
6306 (vhdl-in-literal))
6307 (backward-char)
6308 (cond
6309 ;; If we are looking at an open paren, then stop after it
6310 ((eq (following-char) ?\()
6311 (forward-char)
6312 (vhdl-forward-syntactic-ws here)
6313 (setq donep t))
6314 ;; If we are looking at a close paren, then skip it
6315 ((eq (following-char) ?\))
6316 (forward-char)
6317 (setq pos (point))
6318 (backward-sexp)
6319 (if (< (point) lim)
6320 (progn (goto-char pos)
6321 (vhdl-forward-syntactic-ws here)
6322 (setq donep t))))
6323 ;; If we are looking at a semicolon, then stop
6324 ((eq (following-char) ?\;)
6325 (progn
6326 (forward-char)
6327 (vhdl-forward-syntactic-ws here)
6328 (setq donep t)))
6329 ;; If we are looking at a "begin", then stop
6330 ((and (looking-at vhdl-begin-fwd-re)
6331 (/= (preceding-char) ?_)
6332 (vhdl-begin-p nil))
6333 ;; If it's a leader "begin", then find the
6334 ;; right place
6335 (if (looking-at vhdl-leader-re)
6336 (save-excursion
6337 ;; set a default stop point at the begin
6338 (setq pos (point))
6339 ;; is the start point inside the leader area ?
6340 (goto-char (vhdl-end-of-leader))
6341 (vhdl-forward-syntactic-ws here)
6342 (if (< (point) here)
6343 ;; start point was not inside leader area
6344 ;; set stop point at word after leader
6345 (setq pos (point))))
6346 (forward-word 1)
6347 (vhdl-forward-syntactic-ws here)
6348 (setq pos (point)))
6349 (goto-char pos)
6350 (setq donep t))
6351 ;; If we are looking at a "statement", then stop
6352 ((and (looking-at vhdl-statement-fwd-re)
6353 (/= (preceding-char) ?_)
6354 (vhdl-statement-p nil))
6355 (setq donep t))
6356 ;; If we are looking at a case alternative key, then stop
6357 ((and (looking-at vhdl-case-alternative-re)
6358 (vhdl-case-alternative-p lim))
6359 (save-excursion
6360 ;; set a default stop point at the when
6361 (setq pos (point))
6362 ;; is the start point inside the case alternative key ?
6363 (looking-at vhdl-case-alternative-re)
6364 (goto-char (match-end 0))
6365 (vhdl-forward-syntactic-ws here)
6366 (if (< (point) here)
6367 ;; start point was not inside the case alternative key
6368 ;; set stop point at word after case alternative keyleader
6369 (setq pos (point))))
6370 (goto-char pos)
6371 (setq donep t))
6372 ;; Bogus find, continue
6373 (t
6374 (backward-char)))))
6375 ))
6376
6377 ;; Defuns for calculating the current syntactic state:
6378
6379 (defun vhdl-get-library-unit (bod placeholder)
6380 "If there is an enclosing library unit at BOD, with its \"begin\"
6381 keyword at PLACEHOLDER, then return the library unit type."
6382 (let ((here (vhdl-point 'bol)))
6383 (if (save-excursion
6384 (goto-char placeholder)
6385 (vhdl-safe (vhdl-forward-sexp 1 bod))
6386 (<= here (point)))
6387 (save-excursion
6388 (goto-char bod)
6389 (cond
6390 ((looking-at "e") 'entity)
6391 ((looking-at "a") 'architecture)
6392 ((looking-at "c") 'configuration)
6393 ((looking-at "p")
6394 (save-excursion
6395 (goto-char bod)
6396 (forward-sexp)
6397 (vhdl-forward-syntactic-ws here)
6398 (if (looking-at "body\\b[^_]")
6399 'package-body 'package))))))
6400 ))
6401
6402 (defun vhdl-get-block-state (&optional lim)
6403 "Finds and records all the closest opens.
6404 LIM is the furthest back we need to search (it should be the
6405 previous libunit keyword)."
6406 (let ((here (point))
6407 (lim (or lim (point-min)))
6408 keyword sexp-start sexp-mid sexp-end
6409 preceding-sexp containing-sexp
6410 containing-begin containing-mid containing-paren)
6411 (save-excursion
6412 ;; Find the containing-paren, and use that as the limit
6413 (if (setq containing-paren
6414 (save-restriction
6415 (narrow-to-region lim (point))
6416 (vhdl-safe (scan-lists (point) -1 1))))
6417 (setq lim containing-paren))
6418 ;; Look backwards for "begin" and "end" keywords.
6419 (while (and (> (point) lim)
6420 (not containing-sexp))
6421 (setq keyword (vhdl-backward-to-block lim))
6422 (cond
6423 ((eq keyword 'begin)
6424 ;; Found a "begin" keyword
6425 (setq sexp-start (point))
6426 (setq sexp-mid (vhdl-corresponding-mid lim))
6427 (setq sexp-end (vhdl-safe
6428 (save-excursion
6429 (vhdl-forward-sexp 1 lim) (point))))
6430 (if (and sexp-end (<= sexp-end here))
6431 ;; we want to record this sexp, but we only want to
6432 ;; record the last-most of any of them before here
6433 (or preceding-sexp
6434 (setq preceding-sexp sexp-start))
6435 ;; we're contained in this sexp so put sexp-start on
6436 ;; front of list
6437 (setq containing-sexp sexp-start)
6438 (setq containing-mid sexp-mid)
6439 (setq containing-begin t)))
6440 ((eq keyword 'end)
6441 ;; Found an "end" keyword
6442 (forward-sexp)
6443 (setq sexp-end (point))
6444 (setq sexp-mid nil)
6445 (setq sexp-start
6446 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6447 (progn (backward-sexp) (point))))
6448 ;; we want to record this sexp, but we only want to
6449 ;; record the last-most of any of them before here
6450 (or preceding-sexp
6451 (setq preceding-sexp sexp-start)))
6452 )))
6453 ;; Check if the containing-paren should be the containing-sexp
6454 (if (and containing-paren
6455 (or (null containing-sexp)
6456 (< containing-sexp containing-paren)))
6457 (setq containing-sexp containing-paren
6458 preceding-sexp nil
6459 containing-begin nil
6460 containing-mid nil))
6461 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6462 ))
6463
6464
6465 (defconst vhdl-s-c-a-re
6466 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6467
6468 (defun vhdl-skip-case-alternative (&optional lim)
6469 "Skip forward over case/when bodies, with optional maximal
6470 limit. If no next case alternative is found, nil is returned and
6471 point is not moved."
6472 (let ((lim (or lim (point-max)))
6473 (here (point))
6474 donep foundp)
6475 (while (and (< (point) lim)
6476 (not donep))
6477 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6478 (save-match-data
6479 (not (vhdl-in-literal)))
6480 (/= (match-beginning 0) here))
6481 (progn
6482 (goto-char (match-beginning 0))
6483 (cond
6484 ((and (looking-at "case")
6485 (re-search-forward "\\bis[^_]" lim t))
6486 (backward-sexp)
6487 (vhdl-forward-sexp))
6488 (t
6489 (setq donep t
6490 foundp t))))))
6491 (if (not foundp)
6492 (goto-char here))
6493 foundp))
6494
6495 (defun vhdl-backward-skip-label (&optional lim)
6496 "Skip backward over a label, with optional maximal
6497 limit. If label is not found, nil is returned and point
6498 is not moved."
6499 (let ((lim (or lim (point-min)))
6500 placeholder)
6501 (if (save-excursion
6502 (vhdl-backward-syntactic-ws lim)
6503 (and (eq (preceding-char) ?:)
6504 (progn
6505 (backward-sexp)
6506 (setq placeholder (point))
6507 (looking-at vhdl-label-key))))
6508 (goto-char placeholder))
6509 ))
6510
6511 (defun vhdl-forward-skip-label (&optional lim)
6512 "Skip forward over a label, with optional maximal
6513 limit. If label is not found, nil is returned and point
6514 is not moved."
6515 (let ((lim (or lim (point-max))))
6516 (if (looking-at vhdl-label-key)
6517 (progn
6518 (goto-char (match-end 0))
6519 (vhdl-forward-syntactic-ws lim)))
6520 ))
6521
6522 (defun vhdl-get-syntactic-context ()
6523 "Guess the syntactic description of the current line of VHDL code."
6524 (save-excursion
6525 (save-restriction
6526 (beginning-of-line)
6527 (let* ((indent-point (point))
6528 (case-fold-search t)
6529 vec literal containing-sexp preceding-sexp
6530 containing-begin containing-mid containing-leader
6531 char-before-ip char-after-ip begin-after-ip end-after-ip
6532 placeholder lim library-unit
6533 )
6534
6535 ;; Reset the syntactic context
6536 (setq vhdl-syntactic-context nil)
6537
6538 (save-excursion
6539 ;; Move to the start of the previous library unit, and
6540 ;; record the position of the "begin" keyword.
6541 (setq placeholder (vhdl-beginning-of-libunit))
6542 ;; The position of the "libunit" keyword gives us a gross
6543 ;; limit point.
6544 (setq lim (point))
6545 )
6546
6547 ;; If there is a previous library unit, and we are enclosed by
6548 ;; it, then set the syntax accordingly.
6549 (and placeholder
6550 (setq library-unit (vhdl-get-library-unit lim placeholder))
6551 (vhdl-add-syntax library-unit lim))
6552
6553 ;; Find the surrounding state.
6554 (if (setq vec (vhdl-get-block-state lim))
6555 (progn
6556 (setq containing-sexp (aref vec 0))
6557 (setq preceding-sexp (aref vec 1))
6558 (setq containing-begin (aref vec 2))
6559 (setq containing-mid (aref vec 3))
6560 ))
6561
6562 ;; set the limit on the farthest back we need to search
6563 (setq lim (if containing-sexp
6564 (save-excursion
6565 (goto-char containing-sexp)
6566 ;; set containing-leader if required
6567 (if (looking-at vhdl-leader-re)
6568 (setq containing-leader (vhdl-end-of-leader)))
6569 (vhdl-point 'bol))
6570 (point-min)))
6571
6572 ;; cache char before and after indent point, and move point to
6573 ;; the most likely position to perform the majority of tests
6574 (goto-char indent-point)
6575 (skip-chars-forward " \t")
6576 (setq literal (vhdl-in-literal))
6577 (setq char-after-ip (following-char))
6578 (setq begin-after-ip (and
6579 (not literal)
6580 (looking-at vhdl-begin-fwd-re)
6581 (vhdl-begin-p)))
6582 (setq end-after-ip (and
6583 (not literal)
6584 (looking-at vhdl-end-fwd-re)
6585 (vhdl-end-p)))
6586 (vhdl-backward-syntactic-ws lim)
6587 (setq char-before-ip (preceding-char))
6588 (goto-char indent-point)
6589 (skip-chars-forward " \t")
6590
6591 ;; now figure out syntactic qualities of the current line
6592 (cond
6593 ;; CASE 1: in a string or comment.
6594 ((memq literal '(string comment))
6595 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6596 ;; CASE 2: Line is at top level.
6597 ((null containing-sexp)
6598 ;; Find the point to which indentation will be relative
6599 (save-excursion
6600 (if (null preceding-sexp)
6601 ;; CASE 2X.1
6602 ;; no preceding-sexp -> use the preceding statement
6603 (vhdl-beginning-of-statement-1 lim)
6604 ;; CASE 2X.2
6605 ;; if there is a preceding-sexp then indent relative to it
6606 (goto-char preceding-sexp)
6607 ;; if not at boi, then the block-opening keyword is
6608 ;; probably following a label, so we need a different
6609 ;; relpos
6610 (if (/= (point) (vhdl-point 'boi))
6611 ;; CASE 2X.3
6612 (vhdl-beginning-of-statement-1 lim)))
6613 ;; v-b-o-s could have left us at point-min
6614 (and (bobp)
6615 ;; CASE 2X.4
6616 (vhdl-forward-syntactic-ws indent-point))
6617 (setq placeholder (point)))
6618 (cond
6619 ;; CASE 2A : we are looking at a block-open
6620 (begin-after-ip
6621 (vhdl-add-syntax 'block-open placeholder))
6622 ;; CASE 2B: we are looking at a block-close
6623 (end-after-ip
6624 (vhdl-add-syntax 'block-close placeholder))
6625 ;; CASE 2C: we are looking at a top-level statement
6626 ((progn
6627 (vhdl-backward-syntactic-ws lim)
6628 (or (bobp)
6629 (= (preceding-char) ?\;)))
6630 (vhdl-add-syntax 'statement placeholder))
6631 ;; CASE 2D: we are looking at a top-level statement-cont
6632 (t
6633 (vhdl-beginning-of-statement-1 lim)
6634 ;; v-b-o-s could have left us at point-min
6635 (and (bobp)
6636 ;; CASE 2D.1
6637 (vhdl-forward-syntactic-ws indent-point))
6638 (vhdl-add-syntax 'statement-cont (point)))
6639 )) ; end CASE 2
6640 ;; CASE 3: line is inside parentheses. Most likely we are
6641 ;; either in a subprogram argument (interface) list, or a
6642 ;; continued expression containing parentheses.
6643 ((null containing-begin)
6644 (vhdl-backward-syntactic-ws containing-sexp)
6645 (cond
6646 ;; CASE 3A: we are looking at the arglist closing paren
6647 ((eq char-after-ip ?\))
6648 (goto-char containing-sexp)
6649 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6650 ;; CASE 3B: we are looking at the first argument in an empty
6651 ;; argument list.
6652 ((eq char-before-ip ?\()
6653 (goto-char containing-sexp)
6654 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6655 ;; CASE 3C: we are looking at an arglist continuation line,
6656 ;; but the preceding argument is on the same line as the
6657 ;; opening paren. This case includes multi-line
6658 ;; expression paren groupings.
6659 ((and (save-excursion
6660 (goto-char (1+ containing-sexp))
6661 (skip-chars-forward " \t")
6662 (not (eolp))
6663 (not (looking-at "--")))
6664 (save-excursion
6665 (vhdl-beginning-of-statement-1 containing-sexp)
6666 (skip-chars-backward " \t(")
6667 (<= (point) containing-sexp)))
6668 (goto-char containing-sexp)
6669 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6670 ;; CASE 3D: we are looking at just a normal arglist
6671 ;; continuation line
6672 (t (vhdl-beginning-of-statement-1 containing-sexp)
6673 (vhdl-forward-syntactic-ws indent-point)
6674 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6675 ))
6676 ;; CASE 4: A block mid open
6677 ((and begin-after-ip
6678 (looking-at containing-mid))
6679 (goto-char containing-sexp)
6680 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6681 (if (looking-at vhdl-trailer-re)
6682 ;; CASE 4.1
6683 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6684 (vhdl-backward-skip-label (vhdl-point 'boi))
6685 (vhdl-add-syntax 'block-open (point)))
6686 ;; CASE 5: block close brace
6687 (end-after-ip
6688 (goto-char containing-sexp)
6689 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6690 (if (looking-at vhdl-trailer-re)
6691 ;; CASE 5.1
6692 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6693 (vhdl-backward-skip-label (vhdl-point 'boi))
6694 (vhdl-add-syntax 'block-close (point)))
6695 ;; CASE 6: A continued statement
6696 ((and (/= char-before-ip ?\;)
6697 ;; check it's not a trailer begin keyword, or a begin
6698 ;; keyword immediately following a label.
6699 (not (and begin-after-ip
6700 (or (looking-at vhdl-trailer-re)
6701 (save-excursion
6702 (vhdl-backward-skip-label containing-sexp)))))
6703 ;; check it's not a statement keyword
6704 (not (and (looking-at vhdl-statement-fwd-re)
6705 (vhdl-statement-p)))
6706 ;; see if the b-o-s is before the indent point
6707 (> indent-point
6708 (save-excursion
6709 (vhdl-beginning-of-statement-1 containing-sexp)
6710 ;; If we ended up after a leader, then this will
6711 ;; move us forward to the start of the first
6712 ;; statement. Note that a containing sexp here is
6713 ;; always a keyword, not a paren, so this will
6714 ;; have no effect if we hit the containing-sexp.
6715 (vhdl-forward-syntactic-ws indent-point)
6716 (setq placeholder (point))))
6717 ;; check it's not a block-intro
6718 (/= placeholder containing-sexp)
6719 ;; check it's not a case block-intro
6720 (save-excursion
6721 (goto-char placeholder)
6722 (or (not (looking-at vhdl-case-alternative-re))
6723 (> (match-end 0) indent-point))))
6724 ;; Make placeholder skip a label, but only if it puts us
6725 ;; before the indent point at the start of a line.
6726 (let ((new placeholder))
6727 (if (and (> indent-point
6728 (save-excursion
6729 (goto-char placeholder)
6730 (vhdl-forward-skip-label indent-point)
6731 (setq new (point))))
6732 (save-excursion
6733 (goto-char new)
6734 (eq new (progn (back-to-indentation) (point)))))
6735 (setq placeholder new)))
6736 (vhdl-add-syntax 'statement-cont placeholder)
6737 (if begin-after-ip
6738 (vhdl-add-syntax 'block-open)))
6739 ;; Statement. But what kind?
6740 ;; CASE 7: A case alternative key
6741 ((and (looking-at vhdl-case-alternative-re)
6742 (vhdl-case-alternative-p containing-sexp))
6743 ;; for a case alternative key, we set relpos to the first
6744 ;; non-whitespace char on the line containing the "case"
6745 ;; keyword.
6746 (goto-char containing-sexp)
6747 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6748 (if (looking-at vhdl-trailer-re)
6749 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6750 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6751 ;; CASE 8: statement catchall
6752 (t
6753 ;; we know its a statement, but we need to find out if it is
6754 ;; the first statement in a block
6755 (if containing-leader
6756 (goto-char containing-leader)
6757 (goto-char containing-sexp)
6758 ;; Note that a containing sexp here is always a keyword,
6759 ;; not a paren, so skip over the keyword.
6760 (forward-sexp))
6761 ;; move to the start of the first statement
6762 (vhdl-forward-syntactic-ws indent-point)
6763 (setq placeholder (point))
6764 ;; we want to ignore case alternatives keys when skipping forward
6765 (let (incase-p)
6766 (while (looking-at vhdl-case-alternative-re)
6767 (setq incase-p (point))
6768 ;; we also want to skip over the body of the
6769 ;; case/when statement if that doesn't put us at
6770 ;; after the indent-point
6771 (while (vhdl-skip-case-alternative indent-point))
6772 ;; set up the match end
6773 (looking-at vhdl-case-alternative-re)
6774 (goto-char (match-end 0))
6775 ;; move to the start of the first case alternative statement
6776 (vhdl-forward-syntactic-ws indent-point)
6777 (setq placeholder (point)))
6778 (cond
6779 ;; CASE 8A: we saw a case/when statement so we must be
6780 ;; in a switch statement. find out if we are at the
6781 ;; statement just after a case alternative key
6782 ((and incase-p
6783 (= (point) indent-point))
6784 ;; relpos is the "when" keyword
6785 (vhdl-add-syntax 'statement-case-intro incase-p))
6786 ;; CASE 8B: any old statement
6787 ((< (point) indent-point)
6788 ;; relpos is the first statement of the block
6789 (vhdl-add-syntax 'statement placeholder)
6790 (if begin-after-ip
6791 (vhdl-add-syntax 'block-open)))
6792 ;; CASE 8C: first statement in a block
6793 (t
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-backward-skip-label (vhdl-point 'boi))
6799 (vhdl-add-syntax 'statement-block-intro (point))
6800 (if begin-after-ip
6801 (vhdl-add-syntax 'block-open)))
6802 )))
6803 )
6804
6805 ;; now we need to look at any modifiers
6806 (goto-char indent-point)
6807 (skip-chars-forward " \t")
6808 (if (looking-at "--")
6809 (vhdl-add-syntax 'comment))
6810 (if (eq literal 'pound)
6811 (vhdl-add-syntax 'cpp-macro))
6812 ;; return the syntax
6813 vhdl-syntactic-context))))
6814
6815 ;; Standard indentation line-ups:
6816
6817 (defun vhdl-lineup-arglist (langelem)
6818 "Lineup the current arglist line with the arglist appearing just
6819 after the containing paren which starts the arglist."
6820 (save-excursion
6821 (let* ((containing-sexp
6822 (save-excursion
6823 ;; arglist-cont-nonempty gives relpos ==
6824 ;; to boi of containing-sexp paren. This
6825 ;; is good when offset is +, but bad
6826 ;; when it is vhdl-lineup-arglist, so we
6827 ;; have to special case a kludge here.
6828 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6829 (progn
6830 (beginning-of-line)
6831 (backward-up-list 1)
6832 (skip-chars-forward " \t" (vhdl-point 'eol)))
6833 (goto-char (cdr langelem)))
6834 (point)))
6835 (cs-curcol (save-excursion
6836 (goto-char (cdr langelem))
6837 (current-column))))
6838 (if (save-excursion
6839 (beginning-of-line)
6840 (looking-at "[ \t]*)"))
6841 (progn (goto-char (match-end 0))
6842 (backward-sexp)
6843 (forward-char)
6844 (vhdl-forward-syntactic-ws)
6845 (- (current-column) cs-curcol))
6846 (goto-char containing-sexp)
6847 (or (eolp)
6848 (let ((eol (vhdl-point 'eol))
6849 (here (progn
6850 (forward-char)
6851 (skip-chars-forward " \t")
6852 (point))))
6853 (vhdl-forward-syntactic-ws)
6854 (if (< (point) eol)
6855 (goto-char here))))
6856 (- (current-column) cs-curcol)
6857 ))))
6858
6859 (defun vhdl-lineup-arglist-intro (langelem)
6860 "Lineup an arglist-intro line to just after the open paren."
6861 (save-excursion
6862 (let ((cs-curcol (save-excursion
6863 (goto-char (cdr langelem))
6864 (current-column)))
6865 (ce-curcol (save-excursion
6866 (beginning-of-line)
6867 (backward-up-list 1)
6868 (skip-chars-forward " \t" (vhdl-point 'eol))
6869 (current-column))))
6870 (- ce-curcol cs-curcol -1))))
6871
6872 (defun vhdl-lineup-comment (langelem)
6873 "Support old behavior for comment indentation. We look at
6874 vhdl-comment-only-line-offset to decide how to indent comment
6875 only-lines."
6876 (save-excursion
6877 (back-to-indentation)
6878 ;; at or to the right of comment-column
6879 (if (>= (current-column) comment-column)
6880 (vhdl-comment-indent)
6881 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6882 (if (not (bolp))
6883 (or (car-safe vhdl-comment-only-line-offset)
6884 vhdl-comment-only-line-offset)
6885 (or (cdr-safe vhdl-comment-only-line-offset)
6886 (car-safe vhdl-comment-only-line-offset)
6887 -1000 ;jam it against the left side
6888 )))))
6889
6890 (defun vhdl-lineup-statement-cont (langelem)
6891 "Line up statement-cont after the assignment operator."
6892 (save-excursion
6893 (let* ((relpos (cdr langelem))
6894 (assignp (save-excursion
6895 (goto-char (vhdl-point 'boi))
6896 (and (re-search-forward "\\(<\\|:\\)="
6897 (vhdl-point 'eol) t)
6898 (- (point) (vhdl-point 'boi)))))
6899 (curcol (progn
6900 (goto-char relpos)
6901 (current-column)))
6902 foundp)
6903 (while (and (not foundp)
6904 (< (point) (vhdl-point 'eol)))
6905 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6906 (if (vhdl-in-literal)
6907 (forward-char)
6908 (if (= (preceding-char) ?\()
6909 ;; skip over any parenthesized expressions
6910 (goto-char (min (vhdl-point 'eol)
6911 (scan-lists (point) 1 1)))
6912 ;; found an assignment operator (not at eol)
6913 (setq foundp (not (looking-at "\\s-*$"))))))
6914 (if (not foundp)
6915 ;; there's no assignment operator on the line
6916 vhdl-basic-offset
6917 ;; calculate indentation column after assign and ws, unless
6918 ;; our line contains an assignment operator
6919 (if (not assignp)
6920 (progn
6921 (forward-char)
6922 (skip-chars-forward " \t")
6923 (setq assignp 0)))
6924 (- (current-column) assignp curcol))
6925 )))
6926
6927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6928 ;; Progress reporting
6929
6930 (defvar vhdl-progress-info nil
6931 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6932
6933 (defun vhdl-update-progress-info (string pos)
6934 "Update progress information."
6935 (when (and vhdl-progress-info (not noninteractive)
6936 (< vhdl-progress-interval
6937 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6938 (let ((delta (- (aref vhdl-progress-info 1)
6939 (aref vhdl-progress-info 0))))
6940 (if (= 0 delta)
6941 (message (concat string "... (100%s)") "%")
6942 (message (concat string "... (%2d%s)")
6943 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6944 delta) "%")))
6945 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6946
6947 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6948 ;; Indentation commands
6949
6950 (defun vhdl-electric-tab (&optional prefix-arg)
6951 "If preceeding character is part of a word or a paren then hippie-expand,
6952 else if right of non whitespace on line then insert tab,
6953 else if last command was a tab or return then dedent one step or if a comment
6954 toggle between normal indent and inline comment indent,
6955 else indent `correctly'."
6956 (interactive "*P")
6957 (vhdl-prepare-search-2
6958 (cond
6959 ;; indent region if region is active
6960 ((and (not (featurep 'xemacs)) (use-region-p))
6961 (vhdl-indent-region (region-beginning) (region-end) nil))
6962 ;; expand word
6963 ((= (char-syntax (preceding-char)) ?w)
6964 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6965 (case-replace nil)
6966 (hippie-expand-only-buffers
6967 (or (and (boundp 'hippie-expand-only-buffers)
6968 hippie-expand-only-buffers)
6969 '(vhdl-mode))))
6970 (vhdl-expand-abbrev prefix-arg)))
6971 ;; expand parenthesis
6972 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6973 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6974 (case-replace nil))
6975 (vhdl-expand-paren prefix-arg)))
6976 ;; insert tab
6977 ((> (current-column) (current-indentation))
6978 (insert-tab))
6979 ;; toggle comment indent
6980 ((and (looking-at "--")
6981 (or (eq last-command 'vhdl-electric-tab)
6982 (eq last-command 'vhdl-electric-return)))
6983 (cond ((= (current-indentation) 0) ; no indent
6984 (indent-to 1)
6985 (indent-according-to-mode))
6986 ((< (current-indentation) comment-column) ; normal indent
6987 (indent-to comment-column)
6988 (indent-according-to-mode))
6989 (t ; inline comment indent
6990 (delete-region (line-beginning-position) (point)))))
6991 ;; dedent
6992 ((and (>= (current-indentation) vhdl-basic-offset)
6993 (or (eq last-command 'vhdl-electric-tab)
6994 (eq last-command 'vhdl-electric-return)))
6995 (backward-delete-char-untabify vhdl-basic-offset nil))
6996 ;; indent line
6997 (t (indent-according-to-mode)))
6998 (setq this-command 'vhdl-electric-tab)))
6999
7000 (defun vhdl-electric-return ()
7001 "newline-and-indent or indent-new-comment-line if in comment and preceding
7002 character is a space."
7003 (interactive)
7004 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7005 (indent-new-comment-line)
7006 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7007 (vhdl-fix-case-word -1))
7008 (newline-and-indent)))
7009
7010 (defun vhdl-indent-line ()
7011 "Indent the current line as VHDL code. Returns the amount of
7012 indentation change."
7013 (interactive)
7014 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7015 (pos (- (point-max) (point)))
7016 (indent
7017 (if syntax
7018 ;; indent syntax-based
7019 (if (and (eq (caar syntax) 'comment)
7020 (>= (vhdl-get-offset (car syntax)) comment-column))
7021 ;; special case: comments at or right of comment-column
7022 (vhdl-get-offset (car syntax))
7023 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7024 ;; indent like previous nonblank line
7025 (save-excursion (beginning-of-line)
7026 (re-search-backward "^[^\n]" nil t)
7027 (current-indentation))))
7028 (shift-amt (- indent (current-indentation))))
7029 (and vhdl-echo-syntactic-information-p
7030 (message "syntax: %s, indent= %d" syntax indent))
7031 (unless (zerop shift-amt)
7032 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7033 (beginning-of-line)
7034 (indent-to indent))
7035 (if (< (point) (vhdl-point 'boi))
7036 (back-to-indentation)
7037 ;; If initial point was within line's indentation, position after
7038 ;; the indentation. Else stay at same point in text.
7039 (when (> (- (point-max) pos) (point))
7040 (goto-char (- (point-max) pos))))
7041 (run-hooks 'vhdl-special-indent-hook)
7042 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7043 shift-amt))
7044
7045 (defun vhdl-indent-region (beg end column)
7046 "Indent region as VHDL code.
7047 Adds progress reporting to `indent-region'."
7048 (interactive "r\nP")
7049 (when vhdl-progress-interval
7050 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7051 (count-lines (point-min) end) 0)))
7052 (indent-region beg end column)
7053 (when vhdl-progress-interval (message "Indenting...done"))
7054 (setq vhdl-progress-info nil))
7055
7056 (defun vhdl-indent-buffer ()
7057 "Indent whole buffer as VHDL code.
7058 Calls `indent-region' for whole buffer and adds progress reporting."
7059 (interactive)
7060 (vhdl-indent-region (point-min) (point-max) nil))
7061
7062 (defun vhdl-indent-group ()
7063 "Indent group of lines between empty lines."
7064 (interactive)
7065 (let ((beg (save-excursion
7066 (if (re-search-backward vhdl-align-group-separate nil t)
7067 (point-marker)
7068 (point-min-marker))))
7069 (end (save-excursion
7070 (if (re-search-forward vhdl-align-group-separate nil t)
7071 (point-marker)
7072 (point-max-marker)))))
7073 (vhdl-indent-region beg end nil)))
7074
7075 (defun vhdl-indent-sexp (&optional endpos)
7076 "Indent each line of the list starting just after point.
7077 If optional arg ENDPOS is given, indent each line, stopping when
7078 ENDPOS is encountered."
7079 (interactive)
7080 (save-excursion
7081 (let ((beg (point))
7082 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7083 (indent-region beg end nil))))
7084
7085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7086 ;; Miscellaneous commands
7087
7088 (defun vhdl-show-syntactic-information ()
7089 "Show syntactic information for current line."
7090 (interactive)
7091 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7092 (vhdl-keep-region-active))
7093
7094 ;; Verification and regression functions:
7095
7096 (defun vhdl-regress-line (&optional arg)
7097 "Check syntactic information for current line."
7098 (interactive "P")
7099 (let ((expected (save-excursion
7100 (end-of-line)
7101 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7102 (forward-char 4)
7103 (read (current-buffer)))))
7104 (actual (vhdl-get-syntactic-context))
7105 (expurgated))
7106 ;; remove the library unit symbols
7107 (mapc
7108 (function
7109 (lambda (elt)
7110 (if (memq (car elt) '(entity configuration package
7111 package-body architecture))
7112 nil
7113 (setq expurgated (append expurgated (list elt))))))
7114 actual)
7115 (if (and (not arg) expected (listp expected))
7116 (if (not (equal expected expurgated))
7117 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7118 (save-excursion
7119 (beginning-of-line)
7120 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7121 (end-of-line)
7122 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7123 (delete-region (point) (line-end-position)))
7124 (insert " -- ")
7125 (insert (format "%s" expurgated))))))
7126 (vhdl-keep-region-active))
7127
7128
7129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7130 ;;; Alignment, whitespace fixup, beautifying
7131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7132
7133 (defconst vhdl-align-alist
7134 '(
7135 ;; after some keywords
7136 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7137 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7138 ;; before ':'
7139 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7140 ;; after direction specifications
7141 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7142 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7143 ;; before "==", ":=", "=>", and "<="
7144 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7145 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7146 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7147 ;; before some keywords
7148 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7149 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7150 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7151 ;; before "=>" since "when/else ... =>" can occur
7152 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7153 )
7154 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7155 It is searched in order. If REGEXP is found anywhere in the first
7156 line of a region to be aligned, ALIGN-PATTERN will be used for that
7157 region. ALIGN-PATTERN must include the whitespace to be expanded or
7158 contracted. It may also provide regexps for the text surrounding the
7159 whitespace. SUBEXP specifies which sub-expression of
7160 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7161
7162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7163 ;; Align code
7164
7165 (defvar vhdl-align-try-all-clauses t
7166 "If REGEXP is not found on the first line of the region that clause
7167 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7168
7169 (defun vhdl-do-group (function &optional spacing)
7170 "Apply FUNCTION on group of lines between empty lines."
7171 (let
7172 ;; search for group beginning
7173 ((beg (save-excursion
7174 (if (re-search-backward vhdl-align-group-separate nil t)
7175 (progn (beginning-of-line 2) (back-to-indentation) (point))
7176 (point-min))))
7177 ;; search for group end
7178 (end (save-excursion
7179 (if (re-search-forward vhdl-align-group-separate nil t)
7180 (progn (beginning-of-line) (point))
7181 (point-max)))))
7182 ;; run FUNCTION
7183 (funcall function beg end spacing)))
7184
7185 (defun vhdl-do-list (function &optional spacing)
7186 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7187 parentheses."
7188 (let (beg end)
7189 (save-excursion
7190 ;; search for beginning of balanced group of parentheses
7191 (setq beg (vhdl-re-search-backward "[()]" nil t))
7192 (while (looking-at ")")
7193 (forward-char) (backward-sexp)
7194 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7195 ;; search for end of balanced group of parentheses
7196 (when beg
7197 (forward-list)
7198 (setq end (point))
7199 (goto-char (1+ beg))
7200 (skip-chars-forward " \t\n")
7201 (setq beg (point))))
7202 ;; run FUNCTION
7203 (if beg
7204 (funcall function beg end spacing)
7205 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7206
7207 (defun vhdl-do-same-indent (function &optional spacing)
7208 "Apply FUNCTION to block of lines with same indent."
7209 (let ((indent (current-indentation))
7210 beg end)
7211 ;; search for first line with same indent
7212 (save-excursion
7213 (while (and (not (bobp))
7214 (or (looking-at "^\\s-*\\(--.*\\)?$")
7215 (= (current-indentation) indent)))
7216 (unless (looking-at "^\\s-*$")
7217 (back-to-indentation) (setq beg (point)))
7218 (beginning-of-line -0)))
7219 ;; search for last line with same indent
7220 (save-excursion
7221 (while (and (not (eobp))
7222 (or (looking-at "^\\s-*\\(--.*\\)?$")
7223 (= (current-indentation) indent)))
7224 (if (looking-at "^\\s-*$")
7225 (beginning-of-line 2)
7226 (beginning-of-line 2)
7227 (setq end (point)))))
7228 ;; run FUNCTION
7229 (funcall function beg end spacing)))
7230
7231 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7232 "Attempt to align a range of lines based on the content of the
7233 lines. The definition of `alignment-list' determines the matching
7234 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7235 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7236 indentation is done before aligning."
7237 (interactive "r\np")
7238 (setq alignment-list (or alignment-list vhdl-align-alist))
7239 (setq spacing (or spacing 1))
7240 (save-excursion
7241 (let (bol indent)
7242 (goto-char end)
7243 (setq end (point-marker))
7244 (goto-char begin)
7245 (setq bol (setq begin (progn (beginning-of-line) (point))))
7246 ; (untabify bol end)
7247 (when indent
7248 (indent-region bol end nil))))
7249 (let ((copy (copy-alist alignment-list)))
7250 (vhdl-prepare-search-2
7251 (while copy
7252 (save-excursion
7253 (goto-char begin)
7254 (let (element
7255 (eol (point-at-eol)))
7256 (setq element (nth 0 copy))
7257 (when (and (or (and (listp (car element))
7258 (memq major-mode (car element)))
7259 (eq major-mode (car element)))
7260 (or vhdl-align-try-all-clauses
7261 (re-search-forward (car (cdr element)) eol t)))
7262 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7263 (car (cdr (cdr (cdr element)))) spacing))
7264 (setq copy (cdr copy))))))))
7265
7266 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7267 "Align a range of lines from BEGIN to END. The regular expression
7268 MATCH must match exactly one field: the whitespace to be
7269 contracted/expanded. The alignment column will equal the
7270 rightmost column of the widest whitespace block. SPACING is
7271 the amount of extra spaces to add to the calculated maximum required.
7272 SPACING defaults to 1 so that at least one space is inserted after
7273 the token in MATCH."
7274 (setq spacing (or spacing 1))
7275 (setq substr (or substr 1))
7276 (save-excursion
7277 (let (distance (max 0) (lines 0) bol eol width)
7278 ;; Determine the greatest whitespace distance to the alignment
7279 ;; character
7280 (goto-char begin)
7281 (setq eol (point-at-eol)
7282 bol (setq begin (progn (beginning-of-line) (point))))
7283 (while (< bol end)
7284 (save-excursion
7285 (when (and (re-search-forward match eol t)
7286 (not (vhdl-in-literal)))
7287 (setq distance (- (match-beginning substr) bol))
7288 (when (> distance max)
7289 (setq max distance))))
7290 (forward-line)
7291 (setq bol (point)
7292 eol (point-at-eol))
7293 (setq lines (1+ lines)))
7294 ;; Now insert enough maxs to push each assignment operator to
7295 ;; the same column. We need to use 'lines' as a counter, since
7296 ;; the location of the mark may change
7297 (goto-char (setq bol begin))
7298 (setq eol (point-at-eol))
7299 (while (> lines 0)
7300 (when (and (re-search-forward match eol t)
7301 (not (vhdl-in-literal)))
7302 (setq width (- (match-end substr) (match-beginning substr)))
7303 (setq distance (- (match-beginning substr) bol))
7304 (goto-char (match-beginning substr))
7305 (delete-char width)
7306 (insert-char ? (+ (- max distance) spacing)))
7307 (beginning-of-line)
7308 (forward-line)
7309 (setq bol (point)
7310 eol (point-at-eol))
7311 (setq lines (1- lines))))))
7312
7313 (defun vhdl-align-region-groups (beg end &optional spacing
7314 no-message no-comments)
7315 "Align region, treat groups of lines separately."
7316 (interactive "r\nP")
7317 (save-excursion
7318 (let (orig pos)
7319 (goto-char beg)
7320 (beginning-of-line)
7321 (setq orig (point-marker))
7322 (setq beg (point))
7323 (goto-char end)
7324 (setq end (point-marker))
7325 (untabify beg end)
7326 (unless no-message
7327 (when vhdl-progress-interval
7328 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7329 (count-lines (point-min) end) 0))))
7330 (vhdl-fixup-whitespace-region beg end t)
7331 (goto-char beg)
7332 (if (not vhdl-align-groups)
7333 ;; align entire region
7334 (progn (vhdl-align-region-1 beg end spacing)
7335 (unless no-comments
7336 (vhdl-align-inline-comment-region-1 beg end)))
7337 ;; align groups
7338 (while (and (< beg end)
7339 (re-search-forward vhdl-align-group-separate end t))
7340 (setq pos (point-marker))
7341 (vhdl-align-region-1 beg pos spacing)
7342 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7343 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7344 (setq beg (1+ pos))
7345 (goto-char beg))
7346 ;; align last group
7347 (when (< beg end)
7348 (vhdl-align-region-1 beg end spacing)
7349 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7350 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7351 (when vhdl-indent-tabs-mode
7352 (tabify orig end))
7353 (unless no-message
7354 (when vhdl-progress-interval (message "Aligning...done"))
7355 (setq vhdl-progress-info nil)))))
7356
7357 (defun vhdl-align-region (beg end &optional spacing)
7358 "Align region, treat blocks with same indent and argument lists separately."
7359 (interactive "r\nP")
7360 (if (not vhdl-align-same-indent)
7361 ;; align entire region
7362 (vhdl-align-region-groups beg end spacing)
7363 ;; align blocks with same indent and argument lists
7364 (save-excursion
7365 (let ((cur-beg beg)
7366 indent cur-end)
7367 (when vhdl-progress-interval
7368 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7369 (count-lines (point-min) end) 0)))
7370 (goto-char end)
7371 (setq end (point-marker))
7372 (goto-char cur-beg)
7373 (while (< (point) end)
7374 ;; is argument list opening?
7375 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7376 (point) (vhdl-point 'eol)))))
7377 ;; determine region for argument list
7378 (progn (goto-char cur-beg)
7379 (forward-sexp)
7380 (setq cur-end (point))
7381 (beginning-of-line 2))
7382 ;; determine region with same indent
7383 (setq indent (current-indentation))
7384 (setq cur-beg (point))
7385 (setq cur-end (vhdl-point 'bonl))
7386 (beginning-of-line 2)
7387 (while (and (< (point) end)
7388 (or (looking-at "^\\s-*\\(--.*\\)?$")
7389 (= (current-indentation) indent))
7390 (<= (save-excursion
7391 (nth 0 (parse-partial-sexp
7392 (point) (vhdl-point 'eol)))) 0))
7393 (unless (looking-at "^\\s-*$")
7394 (setq cur-end (vhdl-point 'bonl)))
7395 (beginning-of-line 2)))
7396 ;; align region
7397 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7398 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7399 (when vhdl-progress-interval (message "Aligning...done"))
7400 (setq vhdl-progress-info nil)))))
7401
7402 (defun vhdl-align-group (&optional spacing)
7403 "Align group of lines between empty lines."
7404 (interactive)
7405 (vhdl-do-group 'vhdl-align-region spacing))
7406
7407 (defun vhdl-align-list (&optional spacing)
7408 "Align the lines of a list surrounded by a balanced group of parentheses."
7409 (interactive)
7410 (vhdl-do-list 'vhdl-align-region-groups spacing))
7411
7412 (defun vhdl-align-same-indent (&optional spacing)
7413 "Align block of lines with same indent."
7414 (interactive)
7415 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7416
7417 (defun vhdl-align-declarations (&optional spacing)
7418 "Align the lines within the declarative part of a design unit."
7419 (interactive)
7420 (let (beg end)
7421 (vhdl-prepare-search-2
7422 (save-excursion
7423 ;; search for declarative part
7424 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7425 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7426 (setq beg (point))
7427 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7428 (setq end (point)))))
7429 (if beg
7430 (vhdl-align-region-groups beg end spacing)
7431 (error "ERROR: Not within the declarative part of a design unit"))))
7432
7433 (defun vhdl-align-buffer ()
7434 "Align buffer."
7435 (interactive)
7436 (vhdl-align-region (point-min) (point-max)))
7437
7438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7439 ;; Align inline comments
7440
7441 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7442 "Align inline comments in region."
7443 (save-excursion
7444 (let ((start-max comment-column)
7445 (length-max 0)
7446 comment-list start-list tmp-list start length
7447 cur-start prev-start no-code)
7448 (setq spacing (or spacing 2))
7449 (vhdl-prepare-search-2
7450 (goto-char beg)
7451 ;; search for comment start positions and lengths
7452 (while (< (point) end)
7453 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7454 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7455 (not (save-excursion (goto-char (match-beginning 2))
7456 (vhdl-in-literal))))
7457 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7458 (setq length (- (match-end 2) (match-beginning 2)))
7459 (setq start-max (max start start-max))
7460 (setq length-max (max length length-max))
7461 (setq comment-list (cons (cons start length) comment-list)))
7462 (beginning-of-line 2))
7463 (setq comment-list
7464 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7465 ;; reduce start positions
7466 (setq start-list (list (caar comment-list)))
7467 (setq comment-list (cdr comment-list))
7468 (while comment-list
7469 (unless (or (= (caar comment-list) (car start-list))
7470 (<= (+ (car start-list) (cdar comment-list))
7471 end-comment-column))
7472 (setq start-list (cons (caar comment-list) start-list)))
7473 (setq comment-list (cdr comment-list)))
7474 ;; align lines as nicely as possible
7475 (goto-char beg)
7476 (while (< (point) end)
7477 (setq cur-start nil)
7478 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7479 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7480 (not (save-excursion
7481 (goto-char (match-beginning 3))
7482 (vhdl-in-literal))))
7483 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7484 (>= (- (match-end 2) (match-beginning 2))
7485 comment-column))))
7486 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7487 (setq length (- (match-end 3) (match-beginning 3)))
7488 (setq no-code (= (match-beginning 1) (match-end 1)))
7489 ;; insert minimum whitespace
7490 (goto-char (match-end 2))
7491 (delete-region (match-beginning 2) (match-end 2))
7492 (insert-char ?\ spacing)
7493 (setq tmp-list start-list)
7494 ;; insert additional whitespace to align
7495 (setq cur-start
7496 (cond
7497 ;; align comment-only line to inline comment of previous line
7498 ((and no-code prev-start
7499 (<= length (- end-comment-column prev-start)))
7500 prev-start)
7501 ;; align all comments at `start-max' if this is possible
7502 ((<= (+ start-max length-max) end-comment-column)
7503 start-max)
7504 ;; align at `comment-column' if possible
7505 ((and (<= start comment-column)
7506 (<= length (- end-comment-column comment-column)))
7507 comment-column)
7508 ;; align at left-most possible start position otherwise
7509 (t
7510 (while (and tmp-list (< (car tmp-list) start))
7511 (setq tmp-list (cdr tmp-list)))
7512 (car tmp-list))))
7513 (indent-to cur-start))
7514 (setq prev-start cur-start)
7515 (beginning-of-line 2))))))
7516
7517 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7518 "Align inline comments within a region. Groups of code lines separated by
7519 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7520 (interactive "r\nP")
7521 (save-excursion
7522 (let (orig pos)
7523 (goto-char beg)
7524 (beginning-of-line)
7525 (setq orig (point-marker))
7526 (setq beg (point))
7527 (goto-char end)
7528 (setq end (point-marker))
7529 (untabify beg end)
7530 (unless no-message (message "Aligning inline comments..."))
7531 (goto-char beg)
7532 (if (not vhdl-align-groups)
7533 ;; align entire region
7534 (vhdl-align-inline-comment-region-1 beg end spacing)
7535 ;; align groups
7536 (while (and (< beg end)
7537 (re-search-forward vhdl-align-group-separate end t))
7538 (setq pos (point-marker))
7539 (vhdl-align-inline-comment-region-1 beg pos spacing)
7540 (setq beg (1+ pos))
7541 (goto-char beg))
7542 ;; align last group
7543 (when (< beg end)
7544 (vhdl-align-inline-comment-region-1 beg end spacing)))
7545 (when vhdl-indent-tabs-mode
7546 (tabify orig end))
7547 (unless no-message (message "Aligning inline comments...done")))))
7548
7549 (defun vhdl-align-inline-comment-group (&optional spacing)
7550 "Align inline comments within a group of lines between empty lines."
7551 (interactive)
7552 (save-excursion
7553 (let ((start (point))
7554 beg end)
7555 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7556 (point-marker) (point-max)))
7557 (goto-char start)
7558 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7559 (point) (point-min)))
7560 (untabify beg end)
7561 (message "Aligning inline comments...")
7562 (vhdl-align-inline-comment-region-1 beg end)
7563 (when vhdl-indent-tabs-mode
7564 (tabify beg end))
7565 (message "Aligning inline comments...done"))))
7566
7567 (defun vhdl-align-inline-comment-buffer ()
7568 "Align inline comments within buffer. Groups of code lines separated by
7569 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7570 (interactive)
7571 (vhdl-align-inline-comment-region (point-min) (point-max)))
7572
7573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7574 ;; Fixup whitespace
7575
7576 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7577 "Fixup whitespace in region. Surround operator symbols by one space,
7578 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7579 end of line, do nothing in comments and strings."
7580 (interactive "r")
7581 (unless no-message (message "Fixing up whitespace..."))
7582 (save-excursion
7583 (goto-char end)
7584 (setq end (point-marker))
7585 ;; have no space before and one space after `,' and ';'
7586 (goto-char beg)
7587 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7588 (if (match-string 1)
7589 (goto-char (match-end 1))
7590 (replace-match "\\3 " nil nil nil 3)))
7591 ;; have no space after `('
7592 (goto-char beg)
7593 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7594 (if (match-string 1)
7595 (goto-char (match-end 1))
7596 (replace-match "\\2")))
7597 ;; have no space before `)'
7598 (goto-char beg)
7599 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7600 (if (match-string 1)
7601 (goto-char (match-end 1))
7602 (replace-match "\\2")))
7603 ;; surround operator symbols by one space
7604 (goto-char beg)
7605 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7606 (if (match-string 1)
7607 (goto-char (match-end 1))
7608 (replace-match "\\3 \\4 \\5")
7609 (goto-char (match-end 2))))
7610 ;; eliminate multiple spaces and spaces at end of line
7611 (goto-char beg)
7612 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7613 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7614 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7615 (progn (replace-match "" nil nil) t))
7616 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7617 (progn (replace-match ";" nil nil) t))
7618 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7619 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7620 (progn (replace-match " " nil nil) t))
7621 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7622 (progn (replace-match " " nil nil) t))
7623 ; (re-search-forward "[^ \t-]+" end t))))
7624 (re-search-forward "[^ \t\"-]+" end t))))
7625 (unless no-message (message "Fixing up whitespace...done")))
7626
7627 (defun vhdl-fixup-whitespace-buffer ()
7628 "Fixup whitespace in buffer. Surround operator symbols by one space,
7629 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7630 end of line, do nothing in comments."
7631 (interactive)
7632 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7633
7634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7635 ;; Beautify
7636
7637 (defun vhdl-beautify-region (beg end)
7638 "Beautify region by applying indentation, whitespace fixup, alignment, and
7639 case fixing to a region. Calls functions `vhdl-indent-buffer',
7640 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7641 `vhdl-fix-case-buffer'."
7642 (interactive "r")
7643 (setq end (save-excursion (goto-char end) (point-marker)))
7644 (vhdl-indent-region beg end nil)
7645 (let ((vhdl-align-groups t))
7646 (vhdl-align-region beg end))
7647 (vhdl-fix-case-region beg end))
7648
7649 (defun vhdl-beautify-buffer ()
7650 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7651 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7652 buffer."
7653 (interactive)
7654 (vhdl-beautify-region (point-min) (point-max))
7655 (when noninteractive (save-buffer)))
7656
7657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7658 ;; Code filling
7659
7660 (defun vhdl-fill-region (beg end &optional arg)
7661 "Fill lines for a region of code."
7662 (interactive "r\np")
7663 (save-excursion
7664 (goto-char beg)
7665 (let ((margin (if arg (current-indentation) (current-column))))
7666 (goto-char end)
7667 (setq end (point-marker))
7668 ;; remove inline comments, newlines and whitespace
7669 (vhdl-comment-kill-region beg end)
7670 (vhdl-comment-kill-inline-region beg end)
7671 (subst-char-in-region beg (1- end) ?\n ?\ )
7672 (vhdl-fixup-whitespace-region beg end)
7673 ;; wrap and end-comment-column
7674 (goto-char beg)
7675 (while (re-search-forward "\\s-" end t)
7676 (when(> (current-column) vhdl-end-comment-column)
7677 (backward-char)
7678 (when (re-search-backward "\\s-" beg t)
7679 (replace-match "\n")
7680 (indent-to margin)))))))
7681
7682 (defun vhdl-fill-group ()
7683 "Fill group of lines between empty lines."
7684 (interactive)
7685 (vhdl-do-group 'vhdl-fill-region))
7686
7687 (defun vhdl-fill-list ()
7688 "Fill the lines of a list surrounded by a balanced group of parentheses."
7689 (interactive)
7690 (vhdl-do-list 'vhdl-fill-region))
7691
7692 (defun vhdl-fill-same-indent ()
7693 "Fill the lines of block of lines with same indent."
7694 (interactive)
7695 (vhdl-do-same-indent 'vhdl-fill-region))
7696
7697
7698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7699 ;;; Code updating/fixing
7700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7701
7702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7703 ;; Sensitivity list update
7704
7705 ;; Strategy:
7706 ;; - no sensitivity list is generated for processes with wait statements
7707 ;; - otherwise, do the following:
7708 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7709 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7710 ;; manually entered global signals)
7711 ;; 3. signals from 1. and 2. form the list of visible signals
7712 ;; 4. search for if/elsif conditions containing an event (sequential code)
7713 ;; 5. scan for strings that are within syntactical regions where signals are
7714 ;; read but not within sequential code, and that correspond to visible
7715 ;; signals
7716 ;; 6. replace sensitivity list by list of signals from 5.
7717
7718 (defun vhdl-update-sensitivity-list-process ()
7719 "Update sensitivity list of current process."
7720 (interactive)
7721 (save-excursion
7722 (vhdl-prepare-search-2
7723 (end-of-line)
7724 ;; look whether in process
7725 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7726 (equal (upcase (match-string 2)) "PROCESS")
7727 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7728 (error "ERROR: Not within a process")
7729 (message "Updating sensitivity list...")
7730 (vhdl-update-sensitivity-list)
7731 (message "Updating sensitivity list...done")))))
7732
7733 (defun vhdl-update-sensitivity-list-buffer ()
7734 "Update sensitivity list of all processes in current buffer."
7735 (interactive)
7736 (save-excursion
7737 (vhdl-prepare-search-2
7738 (goto-char (point-min))
7739 (message "Updating sensitivity lists...")
7740 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7741 (goto-char (match-beginning 0))
7742 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7743 (message "Updating sensitivity lists...done"))))
7744
7745 (defun vhdl-update-sensitivity-list ()
7746 "Update sensitivity list."
7747 (let ((proc-beg (point))
7748 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7749 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7750 seq-region-list)
7751 (cond
7752 ;; search for wait statement (no sensitivity list allowed)
7753 ((progn (goto-char proc-mid)
7754 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7755 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7756 ;; combinational process (update sensitivity list)
7757 (t
7758 (let
7759 ;; scan for visible signals
7760 ((visible-list (vhdl-get-visible-signals))
7761 ;; define syntactic regions where signals are read
7762 (scan-regions-list
7763 '(;; right-hand side of signal/variable assignment
7764 ;; (special case: "<=" is relational operator in a condition)
7765 ((re-search-forward "[<:]=" proc-end t)
7766 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7767 ;; if condition
7768 ((re-search-forward "^\\s-*if\\>" proc-end t)
7769 (re-search-forward "\\<then\\>" proc-end t))
7770 ;; elsif condition
7771 ((re-search-forward "\\<elsif\\>" proc-end t)
7772 (re-search-forward "\\<then\\>" proc-end t))
7773 ;; while loop condition
7774 ((re-search-forward "^\\s-*while\\>" proc-end t)
7775 (re-search-forward "\\<loop\\>" proc-end t))
7776 ;; exit/next condition
7777 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7778 (re-search-forward ";" proc-end t))
7779 ;; assert condition
7780 ((re-search-forward "\\<assert\\>" proc-end t)
7781 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7782 ;; case expression
7783 ((re-search-forward "^\\s-*case\\>" proc-end t)
7784 (re-search-forward "\\<is\\>" proc-end t))
7785 ;; parameter list of procedure call
7786 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7787 (1- (point)))
7788 (progn (backward-char) (forward-sexp)
7789 (while (looking-at "(") (forward-sexp)) (point)))))
7790 name read-list sens-list signal-list
7791 sens-beg sens-end beg end margin)
7792 ;; scan for signals in old sensitivity list
7793 (goto-char proc-beg)
7794 (re-search-forward "\\<process\\>" proc-mid t)
7795 (if (not (looking-at "[ \t\n]*("))
7796 (setq sens-beg (point))
7797 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7798 (goto-char (match-end 1))
7799 (forward-sexp)
7800 (setq sens-end (1- (point)))
7801 (goto-char sens-beg)
7802 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7803 (setq sens-list
7804 (cons (downcase (match-string 0)) sens-list))
7805 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7806 (setq signal-list (append visible-list sens-list))
7807 ;; search for sequential parts
7808 (goto-char proc-mid)
7809 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7810 (setq end (re-search-forward "\\<then\\>" proc-end t))
7811 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7812 (goto-char end)
7813 (backward-word 1)
7814 (vhdl-forward-sexp)
7815 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7816 (beginning-of-line)))
7817 ;; scan for signals read in process
7818 (while scan-regions-list
7819 (goto-char proc-mid)
7820 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7821 (setq end (eval (nth 1 (car scan-regions-list)))))
7822 (goto-char beg)
7823 (unless (or (vhdl-in-literal)
7824 (and seq-region-list
7825 (let ((tmp-list seq-region-list))
7826 (while (and tmp-list
7827 (< (point) (caar tmp-list)))
7828 (setq tmp-list (cdr tmp-list)))
7829 (and tmp-list (< (point) (cdar tmp-list))))))
7830 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7831 (setq name (match-string 1))
7832 (when (and (not (match-string 4)) ; not when formal parameter
7833 (not (and (match-string 3) ; not event attribute
7834 (not (member (downcase (match-string 3))
7835 '("event" "last_event" "transaction")))))
7836 (member (downcase name) signal-list))
7837 (unless (member-ignore-case name read-list)
7838 (setq read-list (cons name read-list))))
7839 (goto-char (match-end 1)))))
7840 (setq scan-regions-list (cdr scan-regions-list)))
7841 ;; update sensitivity list
7842 (goto-char sens-beg)
7843 (if sens-end
7844 (delete-region sens-beg sens-end)
7845 (when read-list
7846 (insert " ()") (backward-char)))
7847 (setq read-list (sort read-list 'string<))
7848 (when read-list
7849 (setq margin (current-column))
7850 (insert (car read-list))
7851 (setq read-list (cdr read-list))
7852 (while read-list
7853 (insert ",")
7854 (if (<= (+ (current-column) (length (car read-list)) 2)
7855 end-comment-column)
7856 (insert " ")
7857 (insert "\n") (indent-to margin))
7858 (insert (car read-list))
7859 (setq read-list (cdr read-list)))))))))
7860
7861 (defun vhdl-get-visible-signals ()
7862 "Get all signals visible in the current block."
7863 (let (beg end signal-list entity-name file-name)
7864 (vhdl-prepare-search-2
7865 ;; get entity name
7866 (save-excursion
7867 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7868 (not (equal "END" (upcase (match-string 1))))
7869 (setq entity-name (match-string 2)))
7870 (error "ERROR: Not within an architecture")))
7871 ;; search for signals declared in entity port clause
7872 (save-excursion
7873 (goto-char (point-min))
7874 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7875 (setq file-name
7876 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7877 "." (file-name-extension (buffer-file-name)))))
7878 (vhdl-visit-file
7879 file-name t
7880 (vhdl-prepare-search-2
7881 (goto-char (point-min))
7882 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7883 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7884 (when (setq beg (re-search-forward
7885 "^\\s-*port[ \t\n]*("
7886 (save-excursion
7887 (re-search-forward "^end\\>" nil t)) t))
7888 (setq end (save-excursion
7889 (backward-char) (forward-sexp) (point)))
7890 (vhdl-forward-syntactic-ws)
7891 (while (< (point) end)
7892 (when (looking-at "signal[ \t\n]+")
7893 (goto-char (match-end 0)))
7894 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7895 (setq signal-list
7896 (cons (downcase (match-string 1)) signal-list))
7897 (goto-char (match-end 0))
7898 (vhdl-forward-syntactic-ws))
7899 (re-search-forward ";" end 1)
7900 (vhdl-forward-syntactic-ws)))))))
7901 ;; search for signals declared in architecture declarative part
7902 (save-excursion
7903 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7904 (not (equal "END" (upcase (match-string 1))))
7905 (setq end (re-search-forward "^begin\\>" nil t))))
7906 (error "ERROR: No architecture declarative part found")
7907 ;; scan for all declared signal and alias names
7908 (goto-char beg)
7909 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7910 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7911 (if (match-string 2)
7912 ;; scan signal name
7913 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7914 (setq signal-list
7915 (cons (downcase (match-string 1)) signal-list))
7916 (goto-char (match-end 0)))
7917 ;; scan alias name, check is alias of (declared) signal
7918 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7919 (member (downcase (match-string 2)) signal-list))
7920 (setq signal-list
7921 (cons (downcase (match-string 1)) signal-list))
7922 (goto-char (match-end 0))))
7923 (setq beg (point))))))
7924 ;; search for signals declared in surrounding block declarative parts
7925 (save-excursion
7926 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7927 (match-string 2))
7928 (goto-char (match-end 2))
7929 (vhdl-backward-sexp)
7930 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7931 beg)
7932 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7933 ;; scan for all declared signal names
7934 (goto-char beg)
7935 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7936 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7937 (if (match-string 2)
7938 ;; scan signal name
7939 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7940 (setq signal-list
7941 (cons (downcase (match-string 1)) signal-list))
7942 (goto-char (match-end 0)))
7943 ;; scan alias name, check is alias of (declared) signal
7944 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7945 (member (downcase (match-string 2)) signal-list))
7946 (setq signal-list
7947 (cons (downcase (match-string 1)) signal-list))
7948 (goto-char (match-end 0))))))
7949 (goto-char beg)))
7950 signal-list)))
7951
7952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7953 ;; Generic/port clause fixing
7954
7955 (defun vhdl-fix-clause ()
7956 "Fix closing parenthesis within generic/port clause."
7957 (interactive)
7958 (save-excursion
7959 (vhdl-prepare-search-2
7960 (let ((pos (point))
7961 beg end)
7962 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7963 (error "ERROR: Not within a generic/port clause")
7964 ;; search for end of clause
7965 (goto-char (match-end 0))
7966 (setq beg (1- (point)))
7967 (vhdl-forward-syntactic-ws)
7968 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7969 (goto-char (1- (match-end 0)))
7970 (setq end (point-marker))
7971 (forward-char)
7972 (vhdl-forward-syntactic-ws))
7973 (goto-char end)
7974 (when (> pos (point-at-eol))
7975 (error "ERROR: Not within a generic/port clause"))
7976 ;; delete closing parenthesis on separate line (not supported style)
7977 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7978 (vhdl-line-kill)
7979 (vhdl-backward-syntactic-ws)
7980 (setq end (point-marker))
7981 (insert ";"))
7982 ;; delete superfluous parentheses
7983 (while (progn (goto-char beg)
7984 (condition-case () (forward-sexp)
7985 (error (goto-char (point-max))))
7986 (< (point) end))
7987 (delete-char -1))
7988 ;; add closing parenthesis
7989 (when (> (point) end)
7990 (goto-char end)
7991 (insert ")")))))))
7992
7993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7994 ;; Miscellaneous
7995
7996 (defun vhdl-remove-trailing-spaces ()
7997 "Remove trailing spaces in the whole buffer."
7998 (interactive)
7999 (save-match-data
8000 (save-excursion
8001 (goto-char (point-min))
8002 (while (re-search-forward "[ \t]+$" (point-max) t)
8003 (unless (vhdl-in-literal)
8004 (replace-match "" nil nil))))))
8005
8006
8007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8008 ;;; Electrification
8009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8010
8011 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8012 "Syntax of prompt inserted by template generators.")
8013
8014 (defvar vhdl-template-invoked-by-hook nil
8015 "Indicates whether a template has been invoked by a hook or by key or menu.
8016 Used for undoing after template abortion.")
8017
8018 ;; correct different behavior of function `unread-command-events' in XEmacs
8019 (defun vhdl-character-to-event (arg))
8020 (defalias 'vhdl-character-to-event
8021 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8022
8023 (defun vhdl-work-library ()
8024 "Return the working library name of the current project or \"work\" if no
8025 project is defined."
8026 (vhdl-resolve-env-variable
8027 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8028
8029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8030 ;; Enabling/disabling
8031
8032 (define-minor-mode vhdl-electric-mode
8033 "Toggle VHDL electric mode.
8034 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8035 :global t)
8036
8037 (define-minor-mode vhdl-stutter-mode
8038 "Toggle VHDL stuttering mode.
8039 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8040 :global t)
8041
8042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8043 ;; Stuttering
8044
8045 (defun vhdl-electric-dash (count)
8046 "-- starts a comment, --- draws a horizontal line,
8047 ---- starts a display comment."
8048 (interactive "p")
8049 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8050 (cond
8051 ((and abbrev-start-location (= abbrev-start-location (point)))
8052 (setq abbrev-start-location nil)
8053 (goto-char last-abbrev-location)
8054 (beginning-of-line nil)
8055 (vhdl-comment-display))
8056 ((/= (preceding-char) ?-) ; standard dash (minus)
8057 (self-insert-command count))
8058 (t (self-insert-command count)
8059 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8060 (let ((next-input (read-char)))
8061 (if (= next-input ?-) ; triple dash
8062 (progn
8063 (vhdl-comment-display-line)
8064 (message
8065 "Enter '-' for display comment, else continue coding")
8066 (let ((next-input (read-char)))
8067 (if (= next-input ?-) ; four dashes
8068 (vhdl-comment-display t)
8069 (setq unread-command-events ; pushback the char
8070 (list (vhdl-character-to-event next-input))))))
8071 (setq unread-command-events ; pushback the char
8072 (list (vhdl-character-to-event next-input)))
8073 (vhdl-comment-insert)))))
8074 (self-insert-command count)))
8075
8076 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8077 (interactive "p")
8078 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8079 (if (= (preceding-char) ?\()
8080 (progn (delete-char -1) (insert-char ?\[ 1))
8081 (insert-char ?\( 1))
8082 (self-insert-command count)))
8083
8084 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8085 (interactive "p")
8086 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8087 (progn
8088 (if (= (preceding-char) ?\))
8089 (progn (delete-char -1) (insert-char ?\] 1))
8090 (insert-char ?\) 1))
8091 (blink-matching-open))
8092 (self-insert-command count)))
8093
8094 (defun vhdl-electric-quote (count) "'' --> \""
8095 (interactive "p")
8096 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8097 (if (= (preceding-char) last-input-event)
8098 (progn (delete-char -1) (insert-char ?\" 1))
8099 (insert-char ?\' 1))
8100 (self-insert-command count)))
8101
8102 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8103 (interactive "p")
8104 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8105 (cond ((= (preceding-char) last-input-event)
8106 (progn (delete-char -1)
8107 (unless (eq (preceding-char) ? ) (insert " "))
8108 (insert ": ")
8109 (setq this-command 'vhdl-electric-colon)))
8110 ((and
8111 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8112 (progn (delete-char -1) (insert "= ")))
8113 (t (insert-char ?\; 1)))
8114 (self-insert-command count)))
8115
8116 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8117 (interactive "p")
8118 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8119 (cond ((= (preceding-char) last-input-event)
8120 (progn (delete-char -1)
8121 (unless (eq (preceding-char) ? ) (insert " "))
8122 (insert "<= ")))
8123 (t (insert-char ?\, 1)))
8124 (self-insert-command count)))
8125
8126 (defun vhdl-electric-period (count) "'..' --> ' => '"
8127 (interactive "p")
8128 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8129 (cond ((= (preceding-char) last-input-event)
8130 (progn (delete-char -1)
8131 (unless (eq (preceding-char) ? ) (insert " "))
8132 (insert "=> ")))
8133 (t (insert-char ?\. 1)))
8134 (self-insert-command count)))
8135
8136 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8137 (interactive "p")
8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8139 (cond ((= (preceding-char) last-input-event)
8140 (progn (delete-char -1)
8141 (unless (eq (preceding-char) ? ) (insert " "))
8142 (insert "== ")))
8143 (t (insert-char ?\= 1)))
8144 (self-insert-command count)))
8145
8146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8147 ;; VHDL templates
8148
8149 (defun vhdl-template-paired-parens ()
8150 "Insert a pair of round parentheses, placing point between them."
8151 (interactive)
8152 (insert "()")
8153 (backward-char))
8154
8155 (defun vhdl-template-alias ()
8156 "Insert alias declaration."
8157 (interactive)
8158 (let ((start (point)))
8159 (vhdl-insert-keyword "ALIAS ")
8160 (when (vhdl-template-field "name" nil t start (point))
8161 (insert " : ")
8162 (unless (vhdl-template-field
8163 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8164 nil t)
8165 (delete-char -3))
8166 (vhdl-insert-keyword " IS ")
8167 (vhdl-template-field "name" ";")
8168 (vhdl-comment-insert-inline))))
8169
8170 (defun vhdl-template-architecture ()
8171 "Insert architecture."
8172 (interactive)
8173 (let ((margin (current-indentation))
8174 (start (point))
8175 arch-name)
8176 (vhdl-insert-keyword "ARCHITECTURE ")
8177 (when (setq arch-name
8178 (vhdl-template-field "name" nil t start (point)))
8179 (vhdl-insert-keyword " OF ")
8180 (if (save-excursion
8181 (vhdl-prepare-search-1
8182 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8183 (insert (match-string 1))
8184 (vhdl-template-field "entity name"))
8185 (vhdl-insert-keyword " IS\n")
8186 (vhdl-template-begin-end
8187 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8188 (memq vhdl-insert-empty-lines '(unit all))))))
8189
8190 (defun vhdl-template-array (kind &optional secondary)
8191 "Insert array type definition."
8192 (interactive)
8193 (let ((start (point)))
8194 (vhdl-insert-keyword "ARRAY (")
8195 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8196 secondary)
8197 (vhdl-insert-keyword ") OF ")
8198 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8199 (vhdl-insert-keyword ";"))))
8200
8201 (defun vhdl-template-assert ()
8202 "Insert an assertion statement."
8203 (interactive)
8204 (let ((start (point)))
8205 (vhdl-insert-keyword "ASSERT ")
8206 (when vhdl-conditions-in-parenthesis (insert "("))
8207 (when (vhdl-template-field "condition (negated)" nil t start (point))
8208 (when vhdl-conditions-in-parenthesis (insert ")"))
8209 (setq start (point))
8210 (vhdl-insert-keyword " REPORT ")
8211 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8212 (delete-region start (point)))
8213 (setq start (point))
8214 (vhdl-insert-keyword " SEVERITY ")
8215 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8216 (delete-region start (point)))
8217 (insert ";"))))
8218
8219 (defun vhdl-template-attribute ()
8220 "Insert an attribute declaration or specification."
8221 (interactive)
8222 (if (eq (vhdl-decision-query
8223 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8224 (vhdl-template-attribute-spec)
8225 (vhdl-template-attribute-decl)))
8226
8227 (defun vhdl-template-attribute-decl ()
8228 "Insert an attribute declaration."
8229 (interactive)
8230 (let ((start (point)))
8231 (vhdl-insert-keyword "ATTRIBUTE ")
8232 (when (vhdl-template-field "name" " : " t start (point))
8233 (vhdl-template-field "type" ";")
8234 (vhdl-comment-insert-inline))))
8235
8236 (defun vhdl-template-attribute-spec ()
8237 "Insert an attribute specification."
8238 (interactive)
8239 (let ((start (point)))
8240 (vhdl-insert-keyword "ATTRIBUTE ")
8241 (when (vhdl-template-field "name" nil t start (point))
8242 (vhdl-insert-keyword " OF ")
8243 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8244 (vhdl-template-field "entity class")
8245 (vhdl-insert-keyword " IS ")
8246 (vhdl-template-field "expression" ";"))))
8247
8248 (defun vhdl-template-block ()
8249 "Insert a block."
8250 (interactive)
8251 (let ((margin (current-indentation))
8252 (start (point))
8253 label)
8254 (vhdl-insert-keyword ": BLOCK ")
8255 (goto-char start)
8256 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8257 (forward-word 1)
8258 (forward-char 1)
8259 (insert "(")
8260 (if (vhdl-template-field "[guard expression]" nil t)
8261 (insert ")")
8262 (delete-char -2))
8263 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8264 (insert "\n")
8265 (vhdl-template-begin-end "BLOCK" label margin)
8266 (vhdl-comment-block))))
8267
8268 (defun vhdl-template-block-configuration ()
8269 "Insert a block configuration statement."
8270 (interactive)
8271 (let ((margin (current-indentation))
8272 (start (point)))
8273 (vhdl-insert-keyword "FOR ")
8274 (when (vhdl-template-field "block name" nil t start (point))
8275 (vhdl-insert-keyword "\n\n")
8276 (indent-to margin)
8277 (vhdl-insert-keyword "END FOR;")
8278 (end-of-line 0)
8279 (indent-to (+ margin vhdl-basic-offset)))))
8280
8281 (defun vhdl-template-break ()
8282 "Insert a break statement."
8283 (interactive)
8284 (let (position)
8285 (vhdl-insert-keyword "BREAK")
8286 (setq position (point))
8287 (insert " ")
8288 (while (or
8289 (progn (vhdl-insert-keyword "FOR ")
8290 (if (vhdl-template-field "[quantity name]" " USE " t)
8291 (progn (vhdl-template-field "quantity name" " => ") t)
8292 (delete-region (point)
8293 (progn (forward-word -1) (point)))
8294 nil))
8295 (vhdl-template-field "[quantity name]" " => " t))
8296 (vhdl-template-field "expression")
8297 (setq position (point))
8298 (insert ", "))
8299 (delete-region position (point))
8300 (unless (vhdl-sequential-statement-p)
8301 (vhdl-insert-keyword " ON ")
8302 (if (vhdl-template-field "[sensitivity list]" nil t)
8303 (setq position (point))
8304 (delete-region position (point))))
8305 (vhdl-insert-keyword " WHEN ")
8306 (when vhdl-conditions-in-parenthesis (insert "("))
8307 (if (vhdl-template-field "[condition]" nil t)
8308 (when vhdl-conditions-in-parenthesis (insert ")"))
8309 (delete-region position (point)))
8310 (insert ";")))
8311
8312 (defun vhdl-template-case (&optional kind)
8313 "Insert a case statement."
8314 (interactive)
8315 (let ((margin (current-indentation))
8316 (start (point))
8317 label)
8318 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8319 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8320 (vhdl-insert-keyword "CASE ")
8321 (vhdl-insert-keyword ": CASE ")
8322 (goto-char start)
8323 (setq label (vhdl-template-field "[label]" nil t))
8324 (unless label (delete-char 2))
8325 (forward-word 1)
8326 (forward-char 1))
8327 (when (vhdl-template-field "expression" nil t start (point))
8328 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8329 (indent-to margin)
8330 (vhdl-insert-keyword "END CASE")
8331 (when label (insert " " label))
8332 (insert ";")
8333 (forward-line -1)
8334 (indent-to (+ margin vhdl-basic-offset))
8335 (vhdl-insert-keyword "WHEN ")
8336 (let ((position (point)))
8337 (insert " => ;\n")
8338 (indent-to (+ margin vhdl-basic-offset))
8339 (vhdl-insert-keyword "WHEN OTHERS => null;")
8340 (goto-char position)))))
8341
8342 (defun vhdl-template-case-is ()
8343 "Insert a sequential case statement."
8344 (interactive)
8345 (vhdl-template-case 'is))
8346
8347 (defun vhdl-template-case-use ()
8348 "Insert a simultaneous case statement."
8349 (interactive)
8350 (vhdl-template-case 'use))
8351
8352 (defun vhdl-template-component ()
8353 "Insert a component declaration."
8354 (interactive)
8355 (vhdl-template-component-decl))
8356
8357 (defun vhdl-template-component-conf ()
8358 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8359 since these are almost equivalent)."
8360 (interactive)
8361 (let ((margin (current-indentation))
8362 (result (vhdl-template-configuration-spec t)))
8363 (when result
8364 (insert "\n")
8365 (indent-to margin)
8366 (vhdl-insert-keyword "END FOR;")
8367 (when (eq result 'no-use)
8368 (end-of-line -0)))))
8369
8370 (defun vhdl-template-component-decl ()
8371 "Insert a component declaration."
8372 (interactive)
8373 (let ((margin (current-indentation))
8374 (start (point))
8375 name end-column)
8376 (vhdl-insert-keyword "COMPONENT ")
8377 (when (setq name (vhdl-template-field "name" nil t start (point)))
8378 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8379 (insert "\n\n")
8380 (indent-to margin)
8381 (vhdl-insert-keyword "END COMPONENT")
8382 (unless (vhdl-standard-p '87) (insert " " name))
8383 (insert ";")
8384 (setq end-column (current-column))
8385 (end-of-line -0)
8386 (indent-to (+ margin vhdl-basic-offset))
8387 (vhdl-template-generic-list t t)
8388 (insert "\n")
8389 (indent-to (+ margin vhdl-basic-offset))
8390 (vhdl-template-port-list t)
8391 (beginning-of-line 2)
8392 (forward-char end-column))))
8393
8394 (defun vhdl-template-component-inst ()
8395 "Insert a component instantiation statement."
8396 (interactive)
8397 (let ((margin (current-indentation))
8398 (start (point))
8399 unit position)
8400 (when (vhdl-template-field "instance label" nil t start (point))
8401 (insert ": ")
8402 (if (not (vhdl-use-direct-instantiation))
8403 (vhdl-template-field "component name")
8404 ;; direct instantiation
8405 (setq unit (vhdl-template-field
8406 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8407 (setq unit (upcase (or unit "")))
8408 (cond ((equal unit "ENTITY")
8409 (vhdl-template-field "library name" "." nil nil nil nil
8410 (vhdl-work-library))
8411 (vhdl-template-field "entity name" "(")
8412 (if (vhdl-template-field "[architecture name]" nil t)
8413 (insert ")")
8414 (delete-char -1)))
8415 ((equal unit "CONFIGURATION")
8416 (vhdl-template-field "library name" "." nil nil nil nil
8417 (vhdl-work-library))
8418 (vhdl-template-field "configuration name"))
8419 (t (vhdl-template-field "component name"))))
8420 (insert "\n")
8421 (indent-to (+ margin vhdl-basic-offset))
8422 (setq position (point))
8423 (vhdl-insert-keyword "GENERIC ")
8424 (when (vhdl-template-map position t t)
8425 (insert "\n")
8426 (indent-to (+ margin vhdl-basic-offset)))
8427 (setq position (point))
8428 (vhdl-insert-keyword "PORT ")
8429 (unless (vhdl-template-map position t t)
8430 (delete-region (line-beginning-position) (point))
8431 (delete-char -1))
8432 (insert ";"))))
8433
8434 (defun vhdl-template-conditional-signal-asst ()
8435 "Insert a conditional signal assignment."
8436 (interactive)
8437 (when (vhdl-template-field "target signal")
8438 (insert " <= ")
8439 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8440 ; (insert " "))
8441 (let ((margin (current-column))
8442 (start (point))
8443 position)
8444 (vhdl-template-field "waveform")
8445 (setq position (point))
8446 (vhdl-insert-keyword " WHEN ")
8447 (when vhdl-conditions-in-parenthesis (insert "("))
8448 (while (and (vhdl-template-field "[condition]" nil t)
8449 (progn
8450 (when vhdl-conditions-in-parenthesis (insert ")"))
8451 (setq position (point))
8452 (vhdl-insert-keyword " ELSE")
8453 (insert "\n")
8454 (indent-to margin)
8455 (vhdl-template-field "[waveform]" nil t)))
8456 (setq position (point))
8457 (vhdl-insert-keyword " WHEN ")
8458 (when vhdl-conditions-in-parenthesis (insert "(")))
8459 (delete-region position (point))
8460 (insert ";")
8461 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8462
8463 (defun vhdl-template-configuration ()
8464 "Insert a configuration specification if within an architecture,
8465 a block or component configuration if within a configuration declaration,
8466 a configuration declaration if not within a design unit."
8467 (interactive)
8468 (vhdl-prepare-search-1
8469 (cond
8470 ((and (save-excursion ; architecture body
8471 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8472 (equal "ARCHITECTURE" (upcase (match-string 1))))
8473 (vhdl-template-configuration-spec))
8474 ((and (save-excursion ; configuration declaration
8475 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8476 (equal "CONFIGURATION" (upcase (match-string 1))))
8477 (if (eq (vhdl-decision-query
8478 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8479 (vhdl-template-component-conf)
8480 (vhdl-template-block-configuration)))
8481 (t (vhdl-template-configuration-decl))))) ; otherwise
8482
8483 (defun vhdl-template-configuration-spec (&optional optional-use)
8484 "Insert a configuration specification."
8485 (interactive)
8486 (let ((margin (current-indentation))
8487 (start (point))
8488 aspect position)
8489 (vhdl-insert-keyword "FOR ")
8490 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8491 t start (point))
8492 (vhdl-template-field "component name" "\n")
8493 (indent-to (+ margin vhdl-basic-offset))
8494 (setq start (point))
8495 (vhdl-insert-keyword "USE ")
8496 (if (and optional-use
8497 (not (setq aspect (vhdl-template-field
8498 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8499 (progn (delete-region start (point)) 'no-use)
8500 (unless optional-use
8501 (setq aspect (vhdl-template-field
8502 "ENTITY | CONFIGURATION | OPEN" " ")))
8503 (setq aspect (upcase (or aspect "")))
8504 (cond ((equal aspect "ENTITY")
8505 (vhdl-template-field "library name" "." nil nil nil nil
8506 (vhdl-work-library))
8507 (vhdl-template-field "entity name" "(")
8508 (if (vhdl-template-field "[architecture name]" nil t)
8509 (insert ")")
8510 (delete-char -1))
8511 (insert "\n")
8512 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8513 (setq position (point))
8514 (vhdl-insert-keyword "GENERIC ")
8515 (when (vhdl-template-map position t t)
8516 (insert "\n")
8517 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8518 (setq position (point))
8519 (vhdl-insert-keyword "PORT ")
8520 (unless (vhdl-template-map position t t)
8521 (delete-region (line-beginning-position) (point))
8522 (delete-char -1))
8523 (insert ";")
8524 t)
8525 ((equal aspect "CONFIGURATION")
8526 (vhdl-template-field "library name" "." nil nil nil nil
8527 (vhdl-work-library))
8528 (vhdl-template-field "configuration name" ";"))
8529 (t (delete-char -1) (insert ";") t))))))
8530
8531
8532 (defun vhdl-template-configuration-decl ()
8533 "Insert a configuration declaration."
8534 (interactive)
8535 (let ((margin (current-indentation))
8536 (start (point))
8537 entity-exists string name position)
8538 (vhdl-insert-keyword "CONFIGURATION ")
8539 (when (setq name (vhdl-template-field "name" nil t start (point)))
8540 (vhdl-insert-keyword " OF ")
8541 (save-excursion
8542 (vhdl-prepare-search-1
8543 (setq entity-exists (vhdl-re-search-backward
8544 "\\<entity \\(\\w*\\) is\\>" nil t))
8545 (setq string (match-string 1))))
8546 (if (and entity-exists (not (equal string "")))
8547 (insert string)
8548 (vhdl-template-field "entity name"))
8549 (vhdl-insert-keyword " IS\n")
8550 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8551 (indent-to (+ margin vhdl-basic-offset))
8552 (setq position (point))
8553 (insert "\n")
8554 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8555 (indent-to margin)
8556 (vhdl-insert-keyword "END ")
8557 (unless (vhdl-standard-p '87)
8558 (vhdl-insert-keyword "CONFIGURATION "))
8559 (insert name ";")
8560 (goto-char position))))
8561
8562 (defun vhdl-template-constant ()
8563 "Insert a constant declaration."
8564 (interactive)
8565 (let ((start (point))
8566 (in-arglist (vhdl-in-argument-list-p)))
8567 (vhdl-insert-keyword "CONSTANT ")
8568 (when (vhdl-template-field "name" nil t start (point))
8569 (insert " : ")
8570 (when in-arglist (vhdl-insert-keyword "IN "))
8571 (vhdl-template-field "type")
8572 (if in-arglist
8573 (progn (insert ";")
8574 (vhdl-comment-insert-inline))
8575 (let ((position (point)))
8576 (insert " := ")
8577 (unless (vhdl-template-field "[initialization]" nil t)
8578 (delete-region position (point)))
8579 (insert ";")
8580 (vhdl-comment-insert-inline))))))
8581
8582 (defun vhdl-template-default ()
8583 "Insert nothing."
8584 (interactive)
8585 (insert " ")
8586 (unexpand-abbrev)
8587 (backward-word 1)
8588 (vhdl-case-word 1)
8589 (forward-char 1))
8590
8591 (defun vhdl-template-default-indent ()
8592 "Insert nothing and indent."
8593 (interactive)
8594 (insert " ")
8595 (unexpand-abbrev)
8596 (backward-word 1)
8597 (vhdl-case-word 1)
8598 (forward-char 1)
8599 (indent-according-to-mode))
8600
8601 (defun vhdl-template-disconnect ()
8602 "Insert a disconnect statement."
8603 (interactive)
8604 (let ((start (point)))
8605 (vhdl-insert-keyword "DISCONNECT ")
8606 (when (vhdl-template-field "signal names | OTHERS | ALL"
8607 " : " t start (point))
8608 (vhdl-template-field "type")
8609 (vhdl-insert-keyword " AFTER ")
8610 (vhdl-template-field "time expression" ";"))))
8611
8612 (defun vhdl-template-else ()
8613 "Insert an else statement."
8614 (interactive)
8615 (let (margin)
8616 (vhdl-prepare-search-1
8617 (vhdl-insert-keyword "ELSE")
8618 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8619 (equal "WHEN" (upcase (match-string 1))))
8620 (insert " ")
8621 (indent-according-to-mode)
8622 (setq margin (current-indentation))
8623 (insert "\n")
8624 (indent-to (+ margin vhdl-basic-offset))))))
8625
8626 (defun vhdl-template-elsif ()
8627 "Insert an elsif statement."
8628 (interactive)
8629 (let ((start (point))
8630 margin)
8631 (vhdl-insert-keyword "ELSIF ")
8632 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8633 (when vhdl-conditions-in-parenthesis (insert "("))
8634 (when (vhdl-template-field "condition" nil t start (point))
8635 (when vhdl-conditions-in-parenthesis (insert ")"))
8636 (indent-according-to-mode)
8637 (setq margin (current-indentation))
8638 (vhdl-insert-keyword
8639 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8640 (indent-to (+ margin vhdl-basic-offset))))))
8641
8642 (defun vhdl-template-entity ()
8643 "Insert an entity."
8644 (interactive)
8645 (let ((margin (current-indentation))
8646 (start (point))
8647 name end-column)
8648 (vhdl-insert-keyword "ENTITY ")
8649 (when (setq name (vhdl-template-field "name" nil t start (point)))
8650 (vhdl-insert-keyword " IS\n\n")
8651 (indent-to margin)
8652 (vhdl-insert-keyword "END ")
8653 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8654 (insert name ";")
8655 (setq end-column (current-column))
8656 (end-of-line -0)
8657 (indent-to (+ margin vhdl-basic-offset))
8658 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8659 (indent-to (+ margin vhdl-basic-offset))
8660 (when (vhdl-template-generic-list t)
8661 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8662 (insert "\n")
8663 (indent-to (+ margin vhdl-basic-offset))
8664 (when (vhdl-template-port-list t)
8665 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8666 (beginning-of-line 2)
8667 (forward-char end-column))))
8668
8669 (defun vhdl-template-exit ()
8670 "Insert an exit statement."
8671 (interactive)
8672 (let ((start (point)))
8673 (vhdl-insert-keyword "EXIT ")
8674 (if (vhdl-template-field "[loop label]" nil t start (point))
8675 (let ((position (point)))
8676 (vhdl-insert-keyword " WHEN ")
8677 (when vhdl-conditions-in-parenthesis (insert "("))
8678 (if (vhdl-template-field "[condition]" nil t)
8679 (when vhdl-conditions-in-parenthesis (insert ")"))
8680 (delete-region position (point))))
8681 (delete-char -1))
8682 (insert ";")))
8683
8684 (defun vhdl-template-file ()
8685 "Insert a file declaration."
8686 (interactive)
8687 (let ((start (point)))
8688 (vhdl-insert-keyword "FILE ")
8689 (when (vhdl-template-field "name" nil t start (point))
8690 (insert " : ")
8691 (vhdl-template-field "type")
8692 (unless (vhdl-standard-p '87)
8693 (vhdl-insert-keyword " OPEN ")
8694 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8695 nil t)
8696 (delete-char -6)))
8697 (vhdl-insert-keyword " IS ")
8698 (when (vhdl-standard-p '87)
8699 (vhdl-template-field "[IN | OUT]" " " t))
8700 (vhdl-template-field "filename-string" nil nil nil nil t)
8701 (insert ";")
8702 (vhdl-comment-insert-inline))))
8703
8704 (defun vhdl-template-for ()
8705 "Insert a block or component configuration if within a configuration
8706 declaration, a configuration specification if within an architecture
8707 declarative part (and not within a subprogram), a for-loop if within a
8708 sequential statement part (subprogram or process), and a for-generate
8709 otherwise."
8710 (interactive)
8711 (vhdl-prepare-search-1
8712 (cond
8713 ((vhdl-sequential-statement-p) ; sequential statement
8714 (vhdl-template-for-loop))
8715 ((and (save-excursion ; configuration declaration
8716 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8717 (equal "CONFIGURATION" (upcase (match-string 1))))
8718 (if (eq (vhdl-decision-query
8719 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8720 (vhdl-template-component-conf)
8721 (vhdl-template-block-configuration)))
8722 ((and (save-excursion
8723 (re-search-backward ; architecture declarative part
8724 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8725 (equal "ARCHITECTURE" (upcase (match-string 1))))
8726 (vhdl-template-configuration-spec))
8727 (t (vhdl-template-for-generate))))) ; concurrent statement
8728
8729 (defun vhdl-template-for-generate ()
8730 "Insert a for-generate."
8731 (interactive)
8732 (let ((margin (current-indentation))
8733 (start (point))
8734 label position)
8735 (vhdl-insert-keyword ": FOR ")
8736 (setq position (point-marker))
8737 (goto-char start)
8738 (when (setq label (vhdl-template-field "label" nil t start position))
8739 (goto-char position)
8740 (vhdl-template-field "loop variable")
8741 (vhdl-insert-keyword " IN ")
8742 (vhdl-template-field "range")
8743 (vhdl-template-generate-body margin label))))
8744
8745 (defun vhdl-template-for-loop ()
8746 "Insert a for loop."
8747 (interactive)
8748 (let ((margin (current-indentation))
8749 (start (point))
8750 label index)
8751 (if (not (eq vhdl-optional-labels 'all))
8752 (vhdl-insert-keyword "FOR ")
8753 (vhdl-insert-keyword ": FOR ")
8754 (goto-char start)
8755 (setq label (vhdl-template-field "[label]" nil t))
8756 (unless label (delete-char 2))
8757 (forward-word 1)
8758 (forward-char 1))
8759 (when (setq index (vhdl-template-field "loop variable"
8760 nil t start (point)))
8761 (vhdl-insert-keyword " IN ")
8762 (vhdl-template-field "range")
8763 (vhdl-insert-keyword " LOOP\n\n")
8764 (indent-to margin)
8765 (vhdl-insert-keyword "END LOOP")
8766 (if label
8767 (insert " " label ";")
8768 (insert ";")
8769 (when vhdl-self-insert-comments (insert " -- " index)))
8770 (forward-line -1)
8771 (indent-to (+ margin vhdl-basic-offset)))))
8772
8773 (defun vhdl-template-function (&optional kind)
8774 "Insert a function declaration or body."
8775 (interactive)
8776 (let ((margin (current-indentation))
8777 (start (point))
8778 name)
8779 (vhdl-insert-keyword "FUNCTION ")
8780 (when (setq name (vhdl-template-field "name" nil t start (point)))
8781 (vhdl-template-argument-list t)
8782 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8783 (end-of-line)
8784 (insert "\n")
8785 (indent-to (+ margin vhdl-basic-offset))
8786 (vhdl-insert-keyword "RETURN ")
8787 (vhdl-template-field "type")
8788 (if (if kind (eq kind 'body)
8789 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8790 (progn (vhdl-insert-keyword " IS\n")
8791 (vhdl-template-begin-end
8792 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8793 (vhdl-comment-block))
8794 (insert ";")))))
8795
8796 (defun vhdl-template-function-decl ()
8797 "Insert a function declaration."
8798 (interactive)
8799 (vhdl-template-function 'decl))
8800
8801 (defun vhdl-template-function-body ()
8802 "Insert a function declaration."
8803 (interactive)
8804 (vhdl-template-function 'body))
8805
8806 (defun vhdl-template-generate ()
8807 "Insert a generation scheme."
8808 (interactive)
8809 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8810 (vhdl-template-if-generate)
8811 (vhdl-template-for-generate)))
8812
8813 (defun vhdl-template-generic ()
8814 "Insert generic declaration, or generic map in instantiation statements."
8815 (interactive)
8816 (let ((start (point)))
8817 (vhdl-prepare-search-1
8818 (cond
8819 ((and (save-excursion ; entity declaration
8820 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8821 (equal "ENTITY" (upcase (match-string 1))))
8822 (vhdl-template-generic-list nil))
8823 ((or (save-excursion
8824 (or (beginning-of-line)
8825 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8826 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8827 (vhdl-insert-keyword "GENERIC ")
8828 (vhdl-template-map start))
8829 (t (vhdl-template-generic-list nil t))))))
8830
8831 (defun vhdl-template-group ()
8832 "Insert group or group template declaration."
8833 (interactive)
8834 (let ((start (point)))
8835 (if (eq (vhdl-decision-query
8836 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8837 (vhdl-template-group-template)
8838 (vhdl-template-group-decl))))
8839
8840 (defun vhdl-template-group-decl ()
8841 "Insert group declaration."
8842 (interactive)
8843 (let ((start (point)))
8844 (vhdl-insert-keyword "GROUP ")
8845 (when (vhdl-template-field "name" " : " t start (point))
8846 (vhdl-template-field "template name" " (")
8847 (vhdl-template-field "constituent list" ");")
8848 (vhdl-comment-insert-inline))))
8849
8850 (defun vhdl-template-group-template ()
8851 "Insert group template declaration."
8852 (interactive)
8853 (let ((start (point)))
8854 (vhdl-insert-keyword "GROUP ")
8855 (when (vhdl-template-field "template name" nil t start (point))
8856 (vhdl-insert-keyword " IS (")
8857 (vhdl-template-field "entity class list" ");")
8858 (vhdl-comment-insert-inline))))
8859
8860 (defun vhdl-template-if ()
8861 "Insert a sequential if statement or an if-generate statement."
8862 (interactive)
8863 (if (vhdl-sequential-statement-p)
8864 (vhdl-template-if-then)
8865 (if (and (vhdl-standard-p 'ams)
8866 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8867 (vhdl-template-if-use)
8868 (vhdl-template-if-generate))))
8869
8870 (defun vhdl-template-if-generate ()
8871 "Insert an if-generate."
8872 (interactive)
8873 (let ((margin (current-indentation))
8874 (start (point))
8875 label position)
8876 (vhdl-insert-keyword ": IF ")
8877 (setq position (point-marker))
8878 (goto-char start)
8879 (when (setq label (vhdl-template-field "label" nil t start position))
8880 (goto-char position)
8881 (when vhdl-conditions-in-parenthesis (insert "("))
8882 (vhdl-template-field "condition")
8883 (when vhdl-conditions-in-parenthesis (insert ")"))
8884 (vhdl-template-generate-body margin label))))
8885
8886 (defun vhdl-template-if-then-use (kind)
8887 "Insert a sequential if statement."
8888 (interactive)
8889 (let ((margin (current-indentation))
8890 (start (point))
8891 label)
8892 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8893 (vhdl-insert-keyword "IF ")
8894 (vhdl-insert-keyword ": IF ")
8895 (goto-char start)
8896 (setq label (vhdl-template-field "[label]" nil t))
8897 (unless label (delete-char 2))
8898 (forward-word 1)
8899 (forward-char 1))
8900 (when vhdl-conditions-in-parenthesis (insert "("))
8901 (when (vhdl-template-field "condition" nil t start (point))
8902 (when vhdl-conditions-in-parenthesis (insert ")"))
8903 (vhdl-insert-keyword
8904 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8905 (indent-to margin)
8906 (vhdl-insert-keyword "END IF")
8907 (when label (insert " " label))
8908 (insert ";")
8909 (forward-line -1)
8910 (indent-to (+ margin vhdl-basic-offset)))))
8911
8912 (defun vhdl-template-if-then ()
8913 "Insert a sequential if statement."
8914 (interactive)
8915 (vhdl-template-if-then-use 'then))
8916
8917 (defun vhdl-template-if-use ()
8918 "Insert a simultaneous if statement."
8919 (interactive)
8920 (vhdl-template-if-then-use 'use))
8921
8922 (defun vhdl-template-instance ()
8923 "Insert a component instantiation statement."
8924 (interactive)
8925 (vhdl-template-component-inst))
8926
8927 (defun vhdl-template-library ()
8928 "Insert a library specification."
8929 (interactive)
8930 (let ((margin (current-indentation))
8931 (start (point))
8932 name end-pos)
8933 (vhdl-insert-keyword "LIBRARY ")
8934 (when (setq name (vhdl-template-field "names" nil t start (point)))
8935 (insert ";")
8936 (unless (string-match "," name)
8937 (setq end-pos (point))
8938 (insert "\n")
8939 (indent-to margin)
8940 (vhdl-insert-keyword "USE ")
8941 (insert name)
8942 (vhdl-insert-keyword "..ALL;")
8943 (backward-char 5)
8944 (if (vhdl-template-field "package name")
8945 (forward-char 5)
8946 (delete-region end-pos (+ (point) 5)))))))
8947
8948 (defun vhdl-template-limit ()
8949 "Insert a limit."
8950 (interactive)
8951 (let ((start (point)))
8952 (vhdl-insert-keyword "LIMIT ")
8953 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8954 t start (point))
8955 (vhdl-template-field "type")
8956 (vhdl-insert-keyword " WITH ")
8957 (vhdl-template-field "real expression" ";"))))
8958
8959 (defun vhdl-template-loop ()
8960 "Insert a loop."
8961 (interactive)
8962 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8963 (cond ((eq char ?w)
8964 (vhdl-template-while-loop))
8965 ((eq char ?f)
8966 (vhdl-template-for-loop))
8967 (t (vhdl-template-bare-loop)))))
8968
8969 (defun vhdl-template-bare-loop ()
8970 "Insert a loop."
8971 (interactive)
8972 (let ((margin (current-indentation))
8973 (start (point))
8974 label)
8975 (if (not (eq vhdl-optional-labels 'all))
8976 (vhdl-insert-keyword "LOOP ")
8977 (vhdl-insert-keyword ": LOOP ")
8978 (goto-char start)
8979 (setq label (vhdl-template-field "[label]" nil t))
8980 (unless label (delete-char 2))
8981 (forward-word 1)
8982 (delete-char 1))
8983 (insert "\n\n")
8984 (indent-to margin)
8985 (vhdl-insert-keyword "END LOOP")
8986 (insert (if label (concat " " label ";") ";"))
8987 (forward-line -1)
8988 (indent-to (+ margin vhdl-basic-offset))))
8989
8990 (defun vhdl-template-map (&optional start optional secondary)
8991 "Insert a map specification with association list."
8992 (interactive)
8993 (let ((start (or start (point)))
8994 margin end-pos)
8995 (vhdl-insert-keyword "MAP (")
8996 (if (not vhdl-association-list-with-formals)
8997 (if (vhdl-template-field
8998 (concat (and optional "[") "association list" (and optional "]"))
8999 ")" (or (not secondary) optional)
9000 (and (not secondary) start) (point))
9001 t
9002 (if (and optional secondary) (delete-region start (point)))
9003 nil)
9004 (if vhdl-argument-list-indent
9005 (setq margin (current-column))
9006 (setq margin (+ (current-indentation) vhdl-basic-offset))
9007 (insert "\n")
9008 (indent-to margin))
9009 (if (vhdl-template-field
9010 (concat (and optional "[") "formal" (and optional "]"))
9011 " => " (or (not secondary) optional)
9012 (and (not secondary) start) (point))
9013 (progn
9014 (vhdl-template-field "actual" ",")
9015 (setq end-pos (point))
9016 (insert "\n")
9017 (indent-to margin)
9018 (while (vhdl-template-field "[formal]" " => " t)
9019 (vhdl-template-field "actual" ",")
9020 (setq end-pos (point))
9021 (insert "\n")
9022 (indent-to margin))
9023 (delete-region end-pos (point))
9024 (delete-char -1)
9025 (insert ")")
9026 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9027 t)
9028 (when (and optional secondary) (delete-region start (point)))
9029 nil))))
9030
9031 (defun vhdl-template-modify (&optional noerror)
9032 "Actualize modification date."
9033 (interactive)
9034 (vhdl-prepare-search-2
9035 (save-excursion
9036 (goto-char (point-min))
9037 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9038 (progn (delete-region (point) (progn (end-of-line) (point)))
9039 (vhdl-template-insert-date))
9040 (unless noerror
9041 (error "ERROR: Modification date prefix string \"%s\" not found"
9042 vhdl-modify-date-prefix-string))))))
9043
9044
9045 (defun vhdl-template-modify-noerror ()
9046 "Call `vhdl-template-modify' with NOERROR non-nil."
9047 (vhdl-template-modify t))
9048
9049 (defun vhdl-template-nature ()
9050 "Insert a nature declaration."
9051 (interactive)
9052 (let ((start (point))
9053 name mid-pos end-pos)
9054 (vhdl-insert-keyword "NATURE ")
9055 (when (setq name (vhdl-template-field "name" nil t start (point)))
9056 (vhdl-insert-keyword " IS ")
9057 (let ((definition
9058 (upcase
9059 (or (vhdl-template-field
9060 "across type | ARRAY | RECORD")
9061 ""))))
9062 (cond ((equal definition "")
9063 (insert ";"))
9064 ((equal definition "ARRAY")
9065 (delete-region (point) (progn (forward-word -1) (point)))
9066 (vhdl-template-array 'nature t))
9067 ((equal definition "RECORD")
9068 (setq mid-pos (point-marker))
9069 (delete-region (point) (progn (forward-word -1) (point)))
9070 (vhdl-template-record 'nature name t))
9071 (t
9072 (vhdl-insert-keyword " ACROSS ")
9073 (vhdl-template-field "through type")
9074 (vhdl-insert-keyword " THROUGH ")
9075 (vhdl-template-field "reference name")
9076 (vhdl-insert-keyword " REFERENCE;")))
9077 (when mid-pos
9078 (setq end-pos (point-marker))
9079 (goto-char mid-pos)
9080 (end-of-line))
9081 (vhdl-comment-insert-inline)
9082 (when end-pos (goto-char end-pos))))))
9083
9084 (defun vhdl-template-next ()
9085 "Insert a next statement."
9086 (interactive)
9087 (let ((start (point)))
9088 (vhdl-insert-keyword "NEXT ")
9089 (if (vhdl-template-field "[loop label]" nil t start (point))
9090 (let ((position (point)))
9091 (vhdl-insert-keyword " WHEN ")
9092 (when vhdl-conditions-in-parenthesis (insert "("))
9093 (if (vhdl-template-field "[condition]" nil t)
9094 (when vhdl-conditions-in-parenthesis (insert ")"))
9095 (delete-region position (point))))
9096 (delete-char -1))
9097 (insert ";")))
9098
9099 (defun vhdl-template-others ()
9100 "Insert an others aggregate."
9101 (interactive)
9102 (let ((start (point)))
9103 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9104 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9105 (vhdl-insert-keyword "OTHERS => '")
9106 (when (vhdl-template-field "value" nil t start (point))
9107 (insert "')")))
9108 (vhdl-insert-keyword "OTHERS "))))
9109
9110 (defun vhdl-template-package (&optional kind)
9111 "Insert a package specification or body."
9112 (interactive)
9113 (let ((margin (current-indentation))
9114 (start (point))
9115 name body position)
9116 (vhdl-insert-keyword "PACKAGE ")
9117 (setq body (if kind (eq kind 'body)
9118 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9119 (when body
9120 (vhdl-insert-keyword "BODY ")
9121 (when (save-excursion
9122 (vhdl-prepare-search-1
9123 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9124 (insert (setq name (match-string 1)))))
9125 (when (or name
9126 (setq name (vhdl-template-field "name" nil t start (point))))
9127 (vhdl-insert-keyword " IS\n")
9128 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9129 (indent-to (+ margin vhdl-basic-offset))
9130 (setq position (point))
9131 (insert "\n")
9132 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9133 (indent-to margin)
9134 (vhdl-insert-keyword "END ")
9135 (unless (vhdl-standard-p '87)
9136 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9137 (insert (or name "") ";")
9138 (goto-char position))))
9139
9140 (defun vhdl-template-package-decl ()
9141 "Insert a package specification."
9142 (interactive)
9143 (vhdl-template-package 'decl))
9144
9145 (defun vhdl-template-package-body ()
9146 "Insert a package body."
9147 (interactive)
9148 (vhdl-template-package 'body))
9149
9150 (defun vhdl-template-port ()
9151 "Insert a port declaration, or port map in instantiation statements."
9152 (interactive)
9153 (let ((start (point)))
9154 (vhdl-prepare-search-1
9155 (cond
9156 ((and (save-excursion ; entity declaration
9157 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9158 (equal "ENTITY" (upcase (match-string 1))))
9159 (vhdl-template-port-list nil))
9160 ((or (save-excursion
9161 (or (beginning-of-line)
9162 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9163 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9164 (vhdl-insert-keyword "PORT ")
9165 (vhdl-template-map start))
9166 (t (vhdl-template-port-list nil))))))
9167
9168 (defun vhdl-template-procedural ()
9169 "Insert a procedural."
9170 (interactive)
9171 (let ((margin (current-indentation))
9172 (start (point))
9173 (case-fold-search t)
9174 label)
9175 (vhdl-insert-keyword "PROCEDURAL ")
9176 (when (memq vhdl-optional-labels '(process all))
9177 (goto-char start)
9178 (insert ": ")
9179 (goto-char start)
9180 (setq label (vhdl-template-field "[label]" nil t))
9181 (unless label (delete-char 2))
9182 (forward-word 1)
9183 (forward-char 1))
9184 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9185 (insert "\n")
9186 (vhdl-template-begin-end "PROCEDURAL" label margin)
9187 (vhdl-comment-block)))
9188
9189 (defun vhdl-template-procedure (&optional kind)
9190 "Insert a procedure declaration or body."
9191 (interactive)
9192 (let ((margin (current-indentation))
9193 (start (point))
9194 name)
9195 (vhdl-insert-keyword "PROCEDURE ")
9196 (when (setq name (vhdl-template-field "name" nil t start (point)))
9197 (vhdl-template-argument-list)
9198 (if (if kind (eq kind 'body)
9199 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9200 (progn (vhdl-insert-keyword " IS")
9201 (when vhdl-auto-align
9202 (vhdl-align-region-groups start (point) 1))
9203 (end-of-line) (insert "\n")
9204 (vhdl-template-begin-end
9205 (unless (vhdl-standard-p '87) "PROCEDURE")
9206 name margin)
9207 (vhdl-comment-block))
9208 (insert ";")
9209 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9210 (end-of-line)))))
9211
9212 (defun vhdl-template-procedure-decl ()
9213 "Insert a procedure declaration."
9214 (interactive)
9215 (vhdl-template-procedure 'decl))
9216
9217 (defun vhdl-template-procedure-body ()
9218 "Insert a procedure body."
9219 (interactive)
9220 (vhdl-template-procedure 'body))
9221
9222 (defun vhdl-template-process (&optional kind)
9223 "Insert a process."
9224 (interactive)
9225 (let ((margin (current-indentation))
9226 (start (point))
9227 label seq input-signals clock reset final-pos)
9228 (setq seq (if kind (eq kind 'seq)
9229 (eq (vhdl-decision-query
9230 "process" "(c)ombinational or (s)equential?" t) ?s)))
9231 (vhdl-insert-keyword "PROCESS ")
9232 (when (memq vhdl-optional-labels '(process all))
9233 (goto-char start)
9234 (insert ": ")
9235 (goto-char start)
9236 (setq label (vhdl-template-field "[label]" nil t))
9237 (unless label (delete-char 2))
9238 (forward-word 1)
9239 (forward-char 1))
9240 (insert "(")
9241 (if (not seq)
9242 (unless (setq input-signals
9243 (vhdl-template-field "[sensitivity list]" ")" t))
9244 (setq input-signals "")
9245 (delete-char -2))
9246 (setq clock (or (and (not (equal "" vhdl-clock-name))
9247 (progn (insert vhdl-clock-name) vhdl-clock-name))
9248 (vhdl-template-field "clock name") "<clock>"))
9249 (when (eq vhdl-reset-kind 'async)
9250 (insert ", ")
9251 (setq reset (or (and (not (equal "" vhdl-reset-name))
9252 (progn (insert vhdl-reset-name) vhdl-reset-name))
9253 (vhdl-template-field "reset name") "<reset>")))
9254 (insert ")"))
9255 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9256 (insert "\n")
9257 (vhdl-template-begin-end "PROCESS" label margin)
9258 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9259 (when vhdl-prompt-for-comments
9260 (setq final-pos (point-marker))
9261 (vhdl-prepare-search-2
9262 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9263 (vhdl-re-search-backward "\\<process\\>" nil t))
9264 (end-of-line -0)
9265 (if (bobp)
9266 (progn (insert "\n") (forward-line -1))
9267 (insert "\n"))
9268 (indent-to margin)
9269 (insert "-- purpose: ")
9270 (if (not (vhdl-template-field "[description]" nil t))
9271 (vhdl-line-kill-entire)
9272 (insert "\n")
9273 (indent-to margin)
9274 (insert "-- type : ")
9275 (insert (if seq "sequential" "combinational") "\n")
9276 (indent-to margin)
9277 (insert "-- inputs : ")
9278 (if (not seq)
9279 (insert input-signals)
9280 (insert clock ", ")
9281 (when reset (insert reset ", "))
9282 (unless (vhdl-template-field "[signal names]" nil t)
9283 (delete-char -2)))
9284 (insert "\n")
9285 (indent-to margin)
9286 (insert "-- outputs: ")
9287 (vhdl-template-field "[signal names]" nil t))))
9288 (goto-char final-pos))))
9289
9290 (defun vhdl-template-process-comb ()
9291 "Insert a combinational process."
9292 (interactive)
9293 (vhdl-template-process 'comb))
9294
9295 (defun vhdl-template-process-seq ()
9296 "Insert a sequential process."
9297 (interactive)
9298 (vhdl-template-process 'seq))
9299
9300 (defun vhdl-template-quantity ()
9301 "Insert a quantity declaration."
9302 (interactive)
9303 (if (vhdl-in-argument-list-p)
9304 (let ((start (point)))
9305 (vhdl-insert-keyword "QUANTITY ")
9306 (when (vhdl-template-field "names" nil t start (point))
9307 (insert " : ")
9308 (vhdl-template-field "[IN | OUT]" " " t)
9309 (vhdl-template-field "type")
9310 (insert ";")
9311 (vhdl-comment-insert-inline)))
9312 (let ((char (vhdl-decision-query
9313 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9314 (cond ((eq char ?f) (vhdl-template-quantity-free))
9315 ((eq char ?b) (vhdl-template-quantity-branch))
9316 ((eq char ?s) (vhdl-template-quantity-source))
9317 (t (vhdl-template-undo (point) (point)))))))
9318
9319 (defun vhdl-template-quantity-free ()
9320 "Insert a free quantity declaration."
9321 (interactive)
9322 (vhdl-insert-keyword "QUANTITY ")
9323 (vhdl-template-field "names")
9324 (insert " : ")
9325 (vhdl-template-field "type")
9326 (let ((position (point)))
9327 (insert " := ")
9328 (unless (vhdl-template-field "[initialization]" nil t)
9329 (delete-region position (point)))
9330 (insert ";")
9331 (vhdl-comment-insert-inline)))
9332
9333 (defun vhdl-template-quantity-branch ()
9334 "Insert a branch quantity declaration."
9335 (interactive)
9336 (let (position)
9337 (vhdl-insert-keyword "QUANTITY ")
9338 (when (vhdl-template-field "[across names]" " " t)
9339 (vhdl-insert-keyword "ACROSS "))
9340 (when (vhdl-template-field "[through names]" " " t)
9341 (vhdl-insert-keyword "THROUGH "))
9342 (vhdl-template-field "plus terminal name")
9343 (setq position (point))
9344 (vhdl-insert-keyword " TO ")
9345 (unless (vhdl-template-field "[minus terminal name]" nil t)
9346 (delete-region position (point)))
9347 (insert ";")
9348 (vhdl-comment-insert-inline)))
9349
9350 (defun vhdl-template-quantity-source ()
9351 "Insert a source quantity declaration."
9352 (interactive)
9353 (vhdl-insert-keyword "QUANTITY ")
9354 (vhdl-template-field "names")
9355 (insert " : ")
9356 (vhdl-template-field "type" " ")
9357 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9358 (progn (vhdl-insert-keyword "NOISE ")
9359 (vhdl-template-field "power expression"))
9360 (vhdl-insert-keyword "SPECTRUM ")
9361 (vhdl-template-field "magnitude expression" ", ")
9362 (vhdl-template-field "phase expression"))
9363 (insert ";")
9364 (vhdl-comment-insert-inline))
9365
9366 (defun vhdl-template-record (kind &optional name secondary)
9367 "Insert a record type declaration."
9368 (interactive)
9369 (let ((margin (current-column))
9370 (start (point))
9371 (first t))
9372 (vhdl-insert-keyword "RECORD\n")
9373 (indent-to (+ margin vhdl-basic-offset))
9374 (when (or (vhdl-template-field "element names"
9375 nil (not secondary) start (point))
9376 secondary)
9377 (while (or first (vhdl-template-field "[element names]" nil t))
9378 (insert " : ")
9379 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9380 (vhdl-comment-insert-inline)
9381 (insert "\n")
9382 (indent-to (+ margin vhdl-basic-offset))
9383 (setq first nil))
9384 (delete-region (line-beginning-position) (point))
9385 (indent-to margin)
9386 (vhdl-insert-keyword "END RECORD")
9387 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9388 (insert ";")
9389 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9390
9391 (defun vhdl-template-report ()
9392 "Insert a report statement."
9393 (interactive)
9394 (let ((start (point)))
9395 (vhdl-insert-keyword "REPORT ")
9396 (if (equal "\"\"" (vhdl-template-field
9397 "string expression" nil t start (point) t))
9398 (delete-char -2)
9399 (setq start (point))
9400 (vhdl-insert-keyword " SEVERITY ")
9401 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9402 (delete-region start (point)))
9403 (insert ";"))))
9404
9405 (defun vhdl-template-return ()
9406 "Insert a return statement."
9407 (interactive)
9408 (let ((start (point)))
9409 (vhdl-insert-keyword "RETURN ")
9410 (unless (vhdl-template-field "[expression]" nil t start (point))
9411 (delete-char -1))
9412 (insert ";")))
9413
9414 (defun vhdl-template-selected-signal-asst ()
9415 "Insert a selected signal assignment."
9416 (interactive)
9417 (let ((margin (current-indentation))
9418 (start (point))
9419 (choices t))
9420 (let ((position (point)))
9421 (vhdl-insert-keyword " SELECT ")
9422 (goto-char position))
9423 (vhdl-insert-keyword "WITH ")
9424 (when (vhdl-template-field "selector expression"
9425 nil t start (+ (point) 7))
9426 (forward-word 1)
9427 (delete-char 1)
9428 (insert "\n")
9429 (indent-to (+ margin vhdl-basic-offset))
9430 (vhdl-template-field "target signal" " <= ")
9431 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9432 (insert "\n")
9433 (indent-to (+ margin vhdl-basic-offset))
9434 (vhdl-template-field "waveform")
9435 (vhdl-insert-keyword " WHEN ")
9436 (vhdl-template-field "choices" ",")
9437 (insert "\n")
9438 (indent-to (+ margin vhdl-basic-offset))
9439 (while (and choices (vhdl-template-field "[waveform]" nil t))
9440 (vhdl-insert-keyword " WHEN ")
9441 (if (setq choices (vhdl-template-field "[choices]" "," t))
9442 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9443 (vhdl-insert-keyword "OTHERS")))
9444 (when choices
9445 (fixup-whitespace)
9446 (delete-char -2))
9447 (insert ";")
9448 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9449
9450 (defun vhdl-template-signal ()
9451 "Insert a signal declaration."
9452 (interactive)
9453 (let ((start (point))
9454 (in-arglist (vhdl-in-argument-list-p)))
9455 (vhdl-insert-keyword "SIGNAL ")
9456 (when (vhdl-template-field "names" nil t start (point))
9457 (insert " : ")
9458 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9459 (vhdl-template-field "type")
9460 (if in-arglist
9461 (progn (insert ";")
9462 (vhdl-comment-insert-inline))
9463 (let ((position (point)))
9464 (insert " := ")
9465 (unless (vhdl-template-field "[initialization]" nil t)
9466 (delete-region position (point)))
9467 (insert ";")
9468 (vhdl-comment-insert-inline))))))
9469
9470 (defun vhdl-template-subnature ()
9471 "Insert a subnature declaration."
9472 (interactive)
9473 (let ((start (point))
9474 position)
9475 (vhdl-insert-keyword "SUBNATURE ")
9476 (when (vhdl-template-field "name" nil t start (point))
9477 (vhdl-insert-keyword " IS ")
9478 (vhdl-template-field "nature" " (")
9479 (if (vhdl-template-field "[index range]" nil t)
9480 (insert ")")
9481 (delete-char -2))
9482 (setq position (point))
9483 (vhdl-insert-keyword " TOLERANCE ")
9484 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9485 nil t nil nil t))
9486 (delete-region position (point))
9487 (vhdl-insert-keyword " ACROSS ")
9488 (vhdl-template-field "string expression" nil nil nil nil t)
9489 (vhdl-insert-keyword " THROUGH"))
9490 (insert ";")
9491 (vhdl-comment-insert-inline))))
9492
9493 (defun vhdl-template-subprogram-body ()
9494 "Insert a subprogram body."
9495 (interactive)
9496 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9497 (vhdl-template-function-body)
9498 (vhdl-template-procedure-body)))
9499
9500 (defun vhdl-template-subprogram-decl ()
9501 "Insert a subprogram declaration."
9502 (interactive)
9503 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9504 (vhdl-template-function-decl)
9505 (vhdl-template-procedure-decl)))
9506
9507 (defun vhdl-template-subtype ()
9508 "Insert a subtype declaration."
9509 (interactive)
9510 (let ((start (point)))
9511 (vhdl-insert-keyword "SUBTYPE ")
9512 (when (vhdl-template-field "name" nil t start (point))
9513 (vhdl-insert-keyword " IS ")
9514 (vhdl-template-field "type" " ")
9515 (unless
9516 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9517 (delete-char -1))
9518 (insert ";")
9519 (vhdl-comment-insert-inline))))
9520
9521 (defun vhdl-template-terminal ()
9522 "Insert a terminal declaration."
9523 (interactive)
9524 (let ((start (point)))
9525 (vhdl-insert-keyword "TERMINAL ")
9526 (when (vhdl-template-field "names" nil t start (point))
9527 (insert " : ")
9528 (vhdl-template-field "nature")
9529 (insert ";")
9530 (vhdl-comment-insert-inline))))
9531
9532 (defun vhdl-template-type ()
9533 "Insert a type declaration."
9534 (interactive)
9535 (let ((start (point))
9536 name mid-pos end-pos)
9537 (vhdl-insert-keyword "TYPE ")
9538 (when (setq name (vhdl-template-field "name" nil t start (point)))
9539 (vhdl-insert-keyword " IS ")
9540 (let ((definition
9541 (upcase
9542 (or (vhdl-template-field
9543 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9544 ""))))
9545 (cond ((equal definition "")
9546 (delete-char -4)
9547 (insert ";"))
9548 ((equal definition "ARRAY")
9549 (delete-region (point) (progn (forward-word -1) (point)))
9550 (vhdl-template-array 'type t))
9551 ((equal definition "RECORD")
9552 (setq mid-pos (point-marker))
9553 (delete-region (point) (progn (forward-word -1) (point)))
9554 (vhdl-template-record 'type name t))
9555 ((equal definition "ACCESS")
9556 (insert " ")
9557 (vhdl-template-field "type" ";"))
9558 ((equal definition "FILE")
9559 (vhdl-insert-keyword " OF ")
9560 (vhdl-template-field "type" ";"))
9561 (t (insert ";")))
9562 (when mid-pos
9563 (setq end-pos (point-marker))
9564 (goto-char mid-pos)
9565 (end-of-line))
9566 (vhdl-comment-insert-inline)
9567 (when end-pos (goto-char end-pos))))))
9568
9569 (defun vhdl-template-use ()
9570 "Insert a use clause."
9571 (interactive)
9572 (let ((start (point)))
9573 (vhdl-prepare-search-1
9574 (vhdl-insert-keyword "USE ")
9575 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9576 (vhdl-insert-keyword "..ALL;")
9577 (backward-char 6)
9578 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9579 (forward-char 1)
9580 (vhdl-template-field "package name")
9581 (forward-char 5))))))
9582
9583 (defun vhdl-template-variable ()
9584 "Insert a variable declaration."
9585 (interactive)
9586 (let ((start (point))
9587 (in-arglist (vhdl-in-argument-list-p)))
9588 (vhdl-prepare-search-2
9589 (if (or (save-excursion
9590 (and (vhdl-re-search-backward
9591 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9592 nil t)
9593 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9594 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9595 (vhdl-insert-keyword "VARIABLE ")
9596 (vhdl-insert-keyword "SHARED VARIABLE ")))
9597 (when (vhdl-template-field "names" nil t start (point))
9598 (insert " : ")
9599 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9600 (vhdl-template-field "type")
9601 (if in-arglist
9602 (progn (insert ";")
9603 (vhdl-comment-insert-inline))
9604 (let ((position (point)))
9605 (insert " := ")
9606 (unless (vhdl-template-field "[initialization]" nil t)
9607 (delete-region position (point)))
9608 (insert ";")
9609 (vhdl-comment-insert-inline))))))
9610
9611 (defun vhdl-template-wait ()
9612 "Insert a wait statement."
9613 (interactive)
9614 (vhdl-insert-keyword "WAIT ")
9615 (unless (vhdl-template-field
9616 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9617 nil t)
9618 (delete-char -1))
9619 (insert ";"))
9620
9621 (defun vhdl-template-when ()
9622 "Indent correctly if within a case statement."
9623 (interactive)
9624 (let ((position (point))
9625 margin)
9626 (vhdl-prepare-search-2
9627 (if (and (= (current-column) (current-indentation))
9628 (vhdl-re-search-forward "\\<end\\>" nil t)
9629 (looking-at "\\s-*\\<case\\>"))
9630 (progn
9631 (setq margin (current-indentation))
9632 (goto-char position)
9633 (delete-horizontal-space)
9634 (indent-to (+ margin vhdl-basic-offset)))
9635 (goto-char position)))
9636 (vhdl-insert-keyword "WHEN ")))
9637
9638 (defun vhdl-template-while-loop ()
9639 "Insert a while loop."
9640 (interactive)
9641 (let* ((margin (current-indentation))
9642 (start (point))
9643 label)
9644 (if (not (eq vhdl-optional-labels 'all))
9645 (vhdl-insert-keyword "WHILE ")
9646 (vhdl-insert-keyword ": WHILE ")
9647 (goto-char start)
9648 (setq label (vhdl-template-field "[label]" nil t))
9649 (unless label (delete-char 2))
9650 (forward-word 1)
9651 (forward-char 1))
9652 (when vhdl-conditions-in-parenthesis (insert "("))
9653 (when (vhdl-template-field "condition" nil t start (point))
9654 (when vhdl-conditions-in-parenthesis (insert ")"))
9655 (vhdl-insert-keyword " LOOP\n\n")
9656 (indent-to margin)
9657 (vhdl-insert-keyword "END LOOP")
9658 (insert (if label (concat " " label ";") ";"))
9659 (forward-line -1)
9660 (indent-to (+ margin vhdl-basic-offset)))))
9661
9662 (defun vhdl-template-with ()
9663 "Insert a with statement (i.e. selected signal assignment)."
9664 (interactive)
9665 (vhdl-prepare-search-1
9666 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9667 (equal ";" (match-string 1)))
9668 (vhdl-template-selected-signal-asst)
9669 (vhdl-insert-keyword "WITH "))))
9670
9671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9672 ;; Special templates
9673
9674 (defun vhdl-template-clocked-wait ()
9675 "Insert a wait statement for rising/falling clock edge."
9676 (interactive)
9677 (let ((start (point))
9678 clock)
9679 (vhdl-insert-keyword "WAIT UNTIL ")
9680 (when (setq clock
9681 (or (and (not (equal "" vhdl-clock-name))
9682 (progn (insert vhdl-clock-name) vhdl-clock-name))
9683 (vhdl-template-field "clock name" nil t start (point))))
9684 (insert "'event")
9685 (vhdl-insert-keyword " AND ")
9686 (insert clock)
9687 (insert
9688 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9689 (vhdl-comment-insert-inline
9690 (concat (if vhdl-clock-rising-edge "rising" "falling")
9691 " clock edge")))))
9692
9693 (defun vhdl-template-seq-process (clock reset)
9694 "Insert a template for the body of a sequential process."
9695 (let ((margin (current-indentation))
9696 position)
9697 (vhdl-insert-keyword "IF ")
9698 (when (eq vhdl-reset-kind 'async)
9699 (insert reset " = "
9700 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9701 (vhdl-insert-keyword " THEN")
9702 (vhdl-comment-insert-inline
9703 (concat "asynchronous reset (active "
9704 (if vhdl-reset-active-high "high" "low") ")"))
9705 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9706 (setq position (point))
9707 (insert "\n") (indent-to margin)
9708 (vhdl-insert-keyword "ELSIF "))
9709 (if (eq vhdl-clock-edge-condition 'function)
9710 (insert (if vhdl-clock-rising-edge "rising" "falling")
9711 "_edge(" clock ")")
9712 (insert clock "'event")
9713 (vhdl-insert-keyword " AND ")
9714 (insert clock " = "
9715 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9716 (vhdl-insert-keyword " THEN")
9717 (vhdl-comment-insert-inline
9718 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9719 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9720 (when (eq vhdl-reset-kind 'sync)
9721 (vhdl-insert-keyword "IF ")
9722 (setq reset (or (and (not (equal "" vhdl-reset-name))
9723 (progn (insert vhdl-reset-name) vhdl-reset-name))
9724 (vhdl-template-field "reset name") "<reset>"))
9725 (insert " = "
9726 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9727 (vhdl-insert-keyword " THEN")
9728 (vhdl-comment-insert-inline
9729 (concat "synchronous reset (active "
9730 (if vhdl-reset-active-high "high" "low") ")"))
9731 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9732 (setq position (point))
9733 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9734 (vhdl-insert-keyword "ELSE")
9735 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9736 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9737 (vhdl-insert-keyword "END IF;"))
9738 (when (eq vhdl-reset-kind 'none)
9739 (setq position (point)))
9740 (insert "\n") (indent-to margin)
9741 (vhdl-insert-keyword "END IF;")
9742 (goto-char position)
9743 reset))
9744
9745 (defun vhdl-template-standard-package (library package)
9746 "Insert specification of a standard package. Include a library
9747 specification, if not already there."
9748 (let ((margin (current-indentation)))
9749 (unless (equal library "std")
9750 (unless (or (save-excursion
9751 (vhdl-prepare-search-1
9752 (and (not (bobp))
9753 (re-search-backward
9754 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9755 library "\\|end\\)\\>") nil t)
9756 (match-string 2))))
9757 (equal (downcase library) "work"))
9758 (vhdl-insert-keyword "LIBRARY ")
9759 (insert library ";")
9760 (when package
9761 (insert "\n")
9762 (indent-to margin)))
9763 (when package
9764 (vhdl-insert-keyword "USE ")
9765 (insert library "." package)
9766 (vhdl-insert-keyword ".ALL;")))))
9767
9768 (defun vhdl-template-package-math-complex ()
9769 "Insert specification of `math_complex' package."
9770 (interactive)
9771 (vhdl-template-standard-package "ieee" "math_complex"))
9772
9773 (defun vhdl-template-package-math-real ()
9774 "Insert specification of `math_real' package."
9775 (interactive)
9776 (vhdl-template-standard-package "ieee" "math_real"))
9777
9778 (defun vhdl-template-package-numeric-bit ()
9779 "Insert specification of `numeric_bit' package."
9780 (interactive)
9781 (vhdl-template-standard-package "ieee" "numeric_bit"))
9782
9783 (defun vhdl-template-package-numeric-std ()
9784 "Insert specification of `numeric_std' package."
9785 (interactive)
9786 (vhdl-template-standard-package "ieee" "numeric_std"))
9787
9788 (defun vhdl-template-package-std-logic-1164 ()
9789 "Insert specification of `std_logic_1164' package."
9790 (interactive)
9791 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9792
9793 (defun vhdl-template-package-std-logic-arith ()
9794 "Insert specification of `std_logic_arith' package."
9795 (interactive)
9796 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9797
9798 (defun vhdl-template-package-std-logic-misc ()
9799 "Insert specification of `std_logic_misc' package."
9800 (interactive)
9801 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9802
9803 (defun vhdl-template-package-std-logic-signed ()
9804 "Insert specification of `std_logic_signed' package."
9805 (interactive)
9806 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9807
9808 (defun vhdl-template-package-std-logic-textio ()
9809 "Insert specification of `std_logic_textio' package."
9810 (interactive)
9811 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9812
9813 (defun vhdl-template-package-std-logic-unsigned ()
9814 "Insert specification of `std_logic_unsigned' package."
9815 (interactive)
9816 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9817
9818 (defun vhdl-template-package-textio ()
9819 "Insert specification of `textio' package."
9820 (interactive)
9821 (vhdl-template-standard-package "std" "textio"))
9822
9823 (defun vhdl-template-directive (directive)
9824 "Insert directive."
9825 (unless (= (current-indentation) (current-column))
9826 (delete-horizontal-space)
9827 (insert " "))
9828 (insert "-- pragma " directive))
9829
9830 (defun vhdl-template-directive-translate-on ()
9831 "Insert directive 'translate_on'."
9832 (interactive)
9833 (vhdl-template-directive "translate_on"))
9834
9835 (defun vhdl-template-directive-translate-off ()
9836 "Insert directive 'translate_off'."
9837 (interactive)
9838 (vhdl-template-directive "translate_off"))
9839
9840 (defun vhdl-template-directive-synthesis-on ()
9841 "Insert directive 'synthesis_on'."
9842 (interactive)
9843 (vhdl-template-directive "synthesis_on"))
9844
9845 (defun vhdl-template-directive-synthesis-off ()
9846 "Insert directive 'synthesis_off'."
9847 (interactive)
9848 (vhdl-template-directive "synthesis_off"))
9849
9850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9851 ;; Header and footer templates
9852
9853 (defun vhdl-template-header (&optional file-title)
9854 "Insert a VHDL file header."
9855 (interactive)
9856 (unless (equal vhdl-file-header "")
9857 (let (pos)
9858 (save-excursion
9859 (goto-char (point-min))
9860 (vhdl-insert-string-or-file vhdl-file-header)
9861 (setq pos (point-marker)))
9862 (vhdl-template-replace-header-keywords
9863 (point-min-marker) pos file-title))))
9864
9865 (defun vhdl-template-footer ()
9866 "Insert a VHDL file footer."
9867 (interactive)
9868 (unless (equal vhdl-file-footer "")
9869 (let (pos)
9870 (save-excursion
9871 (goto-char (point-max))
9872 (setq pos (point-marker))
9873 (vhdl-insert-string-or-file vhdl-file-footer)
9874 (unless (= (preceding-char) ?\n)
9875 (insert "\n")))
9876 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9877
9878 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9879 is-model)
9880 "Replace keywords in header and footer."
9881 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9882 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9883 pos)
9884 (vhdl-prepare-search-2
9885 (save-excursion
9886 (goto-char beg)
9887 (while (search-forward "<projectdesc>" end t)
9888 (replace-match project-desc t t))
9889 (goto-char beg)
9890 (while (search-forward "<filename>" end t)
9891 (replace-match (buffer-name) t t))
9892 (goto-char beg)
9893 (while (search-forward "<copyright>" end t)
9894 (replace-match vhdl-copyright-string t t))
9895 (goto-char beg)
9896 (while (search-forward "<author>" end t)
9897 (replace-match "" t t)
9898 (insert (user-full-name))
9899 (when user-mail-address (insert " <" user-mail-address ">")))
9900 (goto-char beg)
9901 (while (search-forward "<login>" end t)
9902 (replace-match (user-login-name) t t))
9903 (goto-char beg)
9904 (while (search-forward "<project>" end t)
9905 (replace-match project-title t t))
9906 (goto-char beg)
9907 (while (search-forward "<company>" end t)
9908 (replace-match vhdl-company-name t t))
9909 (goto-char beg)
9910 (while (search-forward "<platform>" end t)
9911 (replace-match vhdl-platform-spec t t))
9912 (goto-char beg)
9913 (while (search-forward "<standard>" end t)
9914 (replace-match
9915 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9916 ((vhdl-standard-p '93) "'93"))
9917 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9918 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9919 (goto-char beg)
9920 ;; Replace <RCS> with $, so that RCS for the source is
9921 ;; not over-enthusiastic with replacements
9922 (while (search-forward "<RCS>" end t)
9923 (replace-match "$" nil t))
9924 (goto-char beg)
9925 (while (search-forward "<date>" end t)
9926 (replace-match "" t t)
9927 (vhdl-template-insert-date))
9928 (goto-char beg)
9929 (while (search-forward "<year>" end t)
9930 (replace-match (format-time-string "%Y" nil) t t))
9931 (goto-char beg)
9932 (when file-title
9933 (while (search-forward "<title string>" end t)
9934 (replace-match file-title t t))
9935 (goto-char beg))
9936 (let (string)
9937 (while
9938 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9939 (setq string (read-string (concat (match-string 1) ": ")))
9940 (replace-match string t t)))
9941 (goto-char beg)
9942 (when (and (not is-model) (search-forward "<cursor>" end t))
9943 (replace-match "" t t)
9944 (setq pos (point))))
9945 (when pos (goto-char pos))
9946 (unless is-model
9947 (when (or (not project-title) (equal project-title ""))
9948 (message "You can specify a project title in user option `vhdl-project-alist'"))
9949 (when (or (not project-desc) (equal project-desc ""))
9950 (message "You can specify a project description in user option `vhdl-project-alist'"))
9951 (when (equal vhdl-platform-spec "")
9952 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9953 (when (equal vhdl-company-name "")
9954 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9955
9956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9957 ;; Comment templates and functions
9958
9959 (defun vhdl-comment-indent ()
9960 "Indent comments."
9961 (let* ((position (point))
9962 (col
9963 (progn
9964 (forward-line -1)
9965 (if (re-search-forward "--" position t)
9966 (- (current-column) 2) ; existing comment at bol stays there
9967 (goto-char position)
9968 (skip-chars-backward " \t")
9969 (max comment-column ; else indent to comment column
9970 (1+ (current-column))))))) ; except leave at least one space
9971 (goto-char position)
9972 col))
9973
9974 (defun vhdl-comment-insert ()
9975 "Start a comment at the end of the line.
9976 If on line with code, indent at least `comment-column'.
9977 If starting after end-comment-column, start a new line."
9978 (interactive)
9979 (when (> (current-column) end-comment-column) (newline-and-indent))
9980 (if (or (looking-at "\\s-*$") ; end of line
9981 (and (not unread-command-events) ; called with key binding or menu
9982 (not (end-of-line))))
9983 (let (margin)
9984 (while (= (preceding-char) ?-) (delete-char -1))
9985 (setq margin (current-column))
9986 (delete-horizontal-space)
9987 (if (bolp)
9988 (progn (indent-to margin) (insert "--"))
9989 (insert " ")
9990 (indent-to comment-column)
9991 (insert "--"))
9992 (if (not unread-command-events) (insert " ")))
9993 ;; else code following current point implies commenting out code
9994 (let (next-input code)
9995 (while (= (preceding-char) ?-) (delete-char -2))
9996 (while (= (setq next-input (read-char)) 13) ; CR
9997 (insert "--") ; or have a space after it?
9998 (forward-char -2)
9999 (forward-line 1)
10000 (message "Enter CR if commenting out a line of code.")
10001 (setq code t))
10002 (unless code
10003 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10004 (setq unread-command-events
10005 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10006
10007 (defun vhdl-comment-display (&optional line-exists)
10008 "Add 2 comment lines at the current indent, making a display comment."
10009 (interactive)
10010 (let ((margin (current-indentation)))
10011 (unless line-exists (vhdl-comment-display-line))
10012 (insert "\n") (indent-to margin)
10013 (insert "\n") (indent-to margin)
10014 (vhdl-comment-display-line)
10015 (end-of-line -0)
10016 (insert "-- ")))
10017
10018 (defun vhdl-comment-display-line ()
10019 "Displays one line of dashes."
10020 (interactive)
10021 (while (= (preceding-char) ?-) (delete-char -2))
10022 (let* ((col (current-column))
10023 (len (- end-comment-column col)))
10024 (insert-char ?- len)))
10025
10026 (defun vhdl-comment-append-inline ()
10027 "Append empty inline comment to current line."
10028 (interactive)
10029 (end-of-line)
10030 (delete-horizontal-space)
10031 (insert " ")
10032 (indent-to comment-column)
10033 (insert "-- "))
10034
10035 (defun vhdl-comment-insert-inline (&optional string always-insert)
10036 "Insert inline comment."
10037 (when (or (and string (or vhdl-self-insert-comments always-insert))
10038 (and (not string) vhdl-prompt-for-comments))
10039 (let ((position (point)))
10040 (insert " ")
10041 (indent-to comment-column)
10042 (insert "-- ")
10043 (if (not (or (and string (progn (insert string) t))
10044 (vhdl-template-field "[comment]" nil t)))
10045 (delete-region position (point))
10046 (while (= (preceding-char) ?\ ) (delete-char -1))
10047 ;; (when (> (current-column) end-comment-column)
10048 ;; (setq position (point-marker))
10049 ;; (re-search-backward "-- ")
10050 ;; (insert "\n")
10051 ;; (indent-to comment-column)
10052 ;; (goto-char position))
10053 ))))
10054
10055 (defun vhdl-comment-block ()
10056 "Insert comment for code block."
10057 (when vhdl-prompt-for-comments
10058 (let ((final-pos (point-marker)))
10059 (vhdl-prepare-search-2
10060 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10061 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10062 (let (margin)
10063 (back-to-indentation)
10064 (setq margin (current-column))
10065 (end-of-line -0)
10066 (if (bobp)
10067 (progn (insert "\n") (forward-line -1))
10068 (insert "\n"))
10069 (indent-to margin)
10070 (insert "-- purpose: ")
10071 (unless (vhdl-template-field "[description]" nil t)
10072 (vhdl-line-kill-entire)))))
10073 (goto-char final-pos))))
10074
10075 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10076 "Comment out region if not commented out, uncomment otherwise."
10077 (interactive "r\nP")
10078 (save-excursion
10079 (goto-char (1- end))
10080 (end-of-line)
10081 (setq end (point-marker))
10082 (goto-char beg)
10083 (beginning-of-line)
10084 (setq beg (point))
10085 (if (looking-at comment-start)
10086 (comment-region beg end '(4))
10087 (comment-region beg end))))
10088
10089 (defun vhdl-comment-uncomment-line (&optional arg)
10090 "Comment out line if not commented out, uncomment otherwise."
10091 (interactive "p")
10092 (save-excursion
10093 (beginning-of-line)
10094 (let ((position (point)))
10095 (forward-line (or arg 1))
10096 (vhdl-comment-uncomment-region position (point)))))
10097
10098 (defun vhdl-comment-kill-region (beg end)
10099 "Kill comments in region."
10100 (interactive "r")
10101 (save-excursion
10102 (goto-char end)
10103 (setq end (point-marker))
10104 (goto-char beg)
10105 (beginning-of-line)
10106 (while (< (point) end)
10107 (if (looking-at "^\\(\\s-*--.*\n\\)")
10108 (progn (delete-region (match-beginning 1) (match-end 1)))
10109 (beginning-of-line 2)))))
10110
10111 (defun vhdl-comment-kill-inline-region (beg end)
10112 "Kill inline comments in region."
10113 (interactive "r")
10114 (save-excursion
10115 (goto-char end)
10116 (setq end (point-marker))
10117 (goto-char beg)
10118 (beginning-of-line)
10119 (while (< (point) end)
10120 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10121 (delete-region (match-beginning 1) (match-end 1)))
10122 (beginning-of-line 2))))
10123
10124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10125 ;; Subtemplates
10126
10127 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10128 "Insert a begin ... end pair with optional name after the end.
10129 Point is left between them."
10130 (let (position)
10131 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10132 (indent-to margin)
10133 (vhdl-insert-keyword "BEGIN")
10134 (when (and (or construct name) vhdl-self-insert-comments)
10135 (insert " --")
10136 (when construct (insert " ") (vhdl-insert-keyword construct))
10137 (when name (insert " " name)))
10138 (insert "\n")
10139 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10140 (indent-to (+ margin vhdl-basic-offset))
10141 (setq position (point))
10142 (insert "\n")
10143 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10144 (indent-to margin)
10145 (vhdl-insert-keyword "END")
10146 (when construct (insert " ") (vhdl-insert-keyword construct))
10147 (insert (if name (concat " " name) "") ";")
10148 (goto-char position)))
10149
10150 (defun vhdl-template-argument-list (&optional is-function)
10151 "Read from user a procedure or function argument list."
10152 (insert " (")
10153 (let ((margin (current-column))
10154 (start (point))
10155 (end-pos (point))
10156 not-empty interface semicolon-pos)
10157 (unless vhdl-argument-list-indent
10158 (setq margin (+ (current-indentation) vhdl-basic-offset))
10159 (insert "\n")
10160 (indent-to margin))
10161 (setq interface (vhdl-template-field
10162 (concat "[CONSTANT | SIGNAL"
10163 (unless is-function " | VARIABLE") "]") " " t))
10164 (while (vhdl-template-field "[names]" nil t)
10165 (setq not-empty t)
10166 (insert " : ")
10167 (unless is-function
10168 (if (and interface (equal (upcase interface) "CONSTANT"))
10169 (vhdl-insert-keyword "IN ")
10170 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10171 (vhdl-template-field "type")
10172 (setq semicolon-pos (point))
10173 (insert ";")
10174 (vhdl-comment-insert-inline)
10175 (setq end-pos (point))
10176 (insert "\n")
10177 (indent-to margin)
10178 (setq interface (vhdl-template-field
10179 (concat "[CONSTANT | SIGNAL"
10180 (unless is-function " | VARIABLE") "]") " " t)))
10181 (delete-region end-pos (point))
10182 (when semicolon-pos (goto-char semicolon-pos))
10183 (if not-empty
10184 (progn (delete-char 1) (insert ")"))
10185 (delete-char -2))))
10186
10187 (defun vhdl-template-generic-list (optional &optional no-value)
10188 "Read from user a generic spec argument list."
10189 (let (margin
10190 (start (point)))
10191 (vhdl-insert-keyword "GENERIC (")
10192 (setq margin (current-column))
10193 (unless vhdl-argument-list-indent
10194 (let ((position (point)))
10195 (back-to-indentation)
10196 (setq margin (+ (current-column) vhdl-basic-offset))
10197 (goto-char position)
10198 (insert "\n")
10199 (indent-to margin)))
10200 (let ((vhdl-generics (vhdl-template-field
10201 (concat (and optional "[") "name"
10202 (and no-value "s") (and optional "]"))
10203 nil optional)))
10204 (if (not vhdl-generics)
10205 (if optional
10206 (progn (vhdl-line-kill-entire) (end-of-line -0)
10207 (unless vhdl-argument-list-indent
10208 (vhdl-line-kill-entire) (end-of-line -0)))
10209 (vhdl-template-undo start (point))
10210 nil )
10211 (insert " : ")
10212 (let (semicolon-pos end-pos)
10213 (while vhdl-generics
10214 (vhdl-template-field "type")
10215 (if no-value
10216 (progn (setq semicolon-pos (point))
10217 (insert ";"))
10218 (insert " := ")
10219 (unless (vhdl-template-field "[value]" nil t)
10220 (delete-char -4))
10221 (setq semicolon-pos (point))
10222 (insert ";"))
10223 (vhdl-comment-insert-inline)
10224 (setq end-pos (point))
10225 (insert "\n")
10226 (indent-to margin)
10227 (setq vhdl-generics (vhdl-template-field
10228 (concat "[name" (and no-value "s") "]")
10229 " : " t)))
10230 (delete-region end-pos (point))
10231 (goto-char semicolon-pos)
10232 (insert ")")
10233 (end-of-line)
10234 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10235 t)))))
10236
10237 (defun vhdl-template-port-list (optional)
10238 "Read from user a port spec argument list."
10239 (let ((start (point))
10240 margin vhdl-ports object)
10241 (vhdl-insert-keyword "PORT (")
10242 (setq margin (current-column))
10243 (unless vhdl-argument-list-indent
10244 (let ((position (point)))
10245 (back-to-indentation)
10246 (setq margin (+ (current-column) vhdl-basic-offset))
10247 (goto-char position)
10248 (insert "\n")
10249 (indent-to margin)))
10250 (when (vhdl-standard-p 'ams)
10251 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10252 " " t)))
10253 (setq vhdl-ports (vhdl-template-field
10254 (concat (and optional "[") "names" (and optional "]"))
10255 nil optional))
10256 (if (not vhdl-ports)
10257 (if optional
10258 (progn (vhdl-line-kill-entire) (end-of-line -0)
10259 (unless vhdl-argument-list-indent
10260 (vhdl-line-kill-entire) (end-of-line -0)))
10261 (vhdl-template-undo start (point))
10262 nil)
10263 (insert " : ")
10264 (let (semicolon-pos end-pos)
10265 (while vhdl-ports
10266 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10267 (vhdl-template-field "IN | OUT | INOUT" " "))
10268 ((equal "QUANTITY" (upcase object))
10269 (vhdl-template-field "[IN | OUT]" " " t)))
10270 (vhdl-template-field
10271 (if (and object (equal "TERMINAL" (upcase object)))
10272 "nature" "type"))
10273 (setq semicolon-pos (point))
10274 (insert ";")
10275 (vhdl-comment-insert-inline)
10276 (setq end-pos (point))
10277 (insert "\n")
10278 (indent-to margin)
10279 (when (vhdl-standard-p 'ams)
10280 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10281 " " t)))
10282 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10283 (delete-region end-pos (point))
10284 (goto-char semicolon-pos)
10285 (insert ")")
10286 (end-of-line)
10287 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10288 t))))
10289
10290 (defun vhdl-template-generate-body (margin label)
10291 "Insert body for generate template."
10292 (vhdl-insert-keyword " GENERATE")
10293 ; (if (not (vhdl-standard-p '87))
10294 ; (vhdl-template-begin-end "GENERATE" label margin)
10295 (insert "\n\n")
10296 (indent-to margin)
10297 (vhdl-insert-keyword "END GENERATE ")
10298 (insert label ";")
10299 (end-of-line 0)
10300 (indent-to (+ margin vhdl-basic-offset)))
10301
10302 (defun vhdl-template-insert-date ()
10303 "Insert date in appropriate format."
10304 (interactive)
10305 (insert
10306 (cond
10307 ;; 'american, 'european, 'scientific kept for backward compatibility
10308 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10309 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10310 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10311 (t (format-time-string vhdl-date-format nil)))))
10312
10313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10314 ;; Help functions
10315
10316 (defun vhdl-electric-space (count)
10317 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10318 if in comment and past end-comment-column."
10319 (interactive "p")
10320 (cond ((vhdl-in-comment-p)
10321 (self-insert-command count)
10322 (cond ((>= (current-column) (+ 2 end-comment-column))
10323 (backward-char 1)
10324 (skip-chars-backward "^ \t\n")
10325 (indent-new-comment-line)
10326 (skip-chars-forward "^ \t\n")
10327 (forward-char 1))
10328 ((>= (current-column) end-comment-column)
10329 (indent-new-comment-line))
10330 (t nil)))
10331 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10332 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10333 (vhdl-prepare-search-1
10334 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10335 (self-insert-command count))
10336 (t (self-insert-command count))))
10337
10338 (defun vhdl-template-field (prompt &optional follow-string optional
10339 begin end is-string default)
10340 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10341 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10342 an empty string is inserted, return nil and call `vhdl-template-undo' for
10343 the region between BEGIN and END. IS-STRING indicates whether a string
10344 with double-quotes is to be inserted. DEFAULT specifies a default string."
10345 (let ((position (point))
10346 string)
10347 (insert "<" prompt ">")
10348 (setq string
10349 (condition-case ()
10350 (read-from-minibuffer (concat prompt ": ")
10351 (or (and is-string '("\"\"" . 2)) default)
10352 vhdl-minibuffer-local-map)
10353 (quit (if (and optional begin end)
10354 (progn (beep) "")
10355 (keyboard-quit)))))
10356 (when (or (not (equal string "")) optional)
10357 (delete-region position (point)))
10358 (when (and (equal string "") optional begin end)
10359 (vhdl-template-undo begin end)
10360 (message "Template aborted"))
10361 (unless (equal string "")
10362 (insert string)
10363 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10364 vhdl-keywords-regexp)
10365 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10366 vhdl-types-regexp)
10367 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10368 (concat "'" vhdl-attributes-regexp))
10369 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10370 vhdl-enum-values-regexp))
10371 (when (or (not (equal string "")) (not optional))
10372 (insert (or follow-string "")))
10373 (if (equal string "") nil string)))
10374
10375 (defun vhdl-decision-query (string prompt &optional optional)
10376 "Query a decision from the user."
10377 (let ((start (point)))
10378 (when string (vhdl-insert-keyword (concat string " ")))
10379 (message "%s" (or prompt ""))
10380 (let ((char (read-char)))
10381 (delete-region start (point))
10382 (if (and optional (eq char ?\r))
10383 (progn (insert " ")
10384 (unexpand-abbrev)
10385 (throw 'abort "ERROR: Template aborted"))
10386 char))))
10387
10388 (defun vhdl-insert-keyword (keyword)
10389 "Insert KEYWORD and adjust case."
10390 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10391
10392 (defun vhdl-case-keyword (keyword)
10393 "Adjust case of KEYWORD."
10394 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10395
10396 (defun vhdl-case-word (num)
10397 "Adjust case of following NUM words."
10398 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10399
10400 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10401 "If preceeding character is part of a word or a paren then hippie-expand,
10402 else insert tab (used for word completion in VHDL minibuffer)."
10403 (interactive "P")
10404 (cond
10405 ;; expand word
10406 ((= (char-syntax (preceding-char)) ?w)
10407 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10408 (case-replace nil)
10409 (hippie-expand-only-buffers
10410 (or (and (boundp 'hippie-expand-only-buffers)
10411 hippie-expand-only-buffers)
10412 '(vhdl-mode))))
10413 (vhdl-expand-abbrev prefix-arg)))
10414 ;; expand parenthesis
10415 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10416 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10417 (case-replace nil))
10418 (vhdl-expand-paren prefix-arg)))
10419 ;; insert tab
10420 (t (insert-tab))))
10421
10422 (defun vhdl-template-search-prompt ()
10423 "Search for left out template prompts and query again."
10424 (interactive)
10425 (vhdl-prepare-search-2
10426 (when (or (re-search-forward
10427 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10428 (re-search-backward
10429 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10430 (let ((string (match-string 1)))
10431 (replace-match "")
10432 (vhdl-template-field string)))))
10433
10434 (defun vhdl-template-undo (begin end)
10435 "Undo aborted template by deleting region and unexpanding the keyword."
10436 (cond (vhdl-template-invoked-by-hook
10437 (goto-char end)
10438 (insert " ")
10439 (delete-region begin end)
10440 (unexpand-abbrev))
10441 (t (delete-region begin end))))
10442
10443 (defun vhdl-insert-string-or-file (string)
10444 "Insert STRING or file contents if STRING is an existing file name."
10445 (unless (equal string "")
10446 (let ((file-name
10447 (progn (string-match "^\\([^\n]+\\)" string)
10448 (vhdl-resolve-env-variable (match-string 1 string)))))
10449 (if (file-exists-p file-name)
10450 (forward-char (cadr (insert-file-contents file-name)))
10451 (insert string)))))
10452
10453 (defun vhdl-beginning-of-block ()
10454 "Move cursor to the beginning of the enclosing block."
10455 (let (pos)
10456 (save-excursion
10457 (beginning-of-line)
10458 ;; search backward for block beginning or end
10459 (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))
10460 ;; not consider subprogram declarations
10461 (or (and (match-string 5)
10462 (save-match-data
10463 (save-excursion
10464 (goto-char (match-end 5))
10465 (forward-word 1)
10466 (vhdl-forward-syntactic-ws)
10467 (when (looking-at "(")
10468 (forward-sexp))
10469 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10470 (match-string 1)))
10471 ;; not consider configuration specifications
10472 (and (match-string 6)
10473 (save-match-data
10474 (save-excursion
10475 (vhdl-end-of-block)
10476 (beginning-of-line)
10477 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10478 (match-string 2))
10479 ;; skip subblock if block end found
10480 (vhdl-beginning-of-block)))
10481 (when pos (goto-char pos))))
10482
10483 (defun vhdl-end-of-block ()
10484 "Move cursor to the end of the enclosing block."
10485 (let (pos)
10486 (save-excursion
10487 (end-of-line)
10488 ;; search forward for block beginning or end
10489 (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))
10490 ;; not consider subprogram declarations
10491 (or (and (match-string 5)
10492 (save-match-data
10493 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10494 (match-string 1)))
10495 ;; not consider configuration specifications
10496 (and (match-string 6)
10497 (save-match-data
10498 (save-excursion
10499 (vhdl-end-of-block)
10500 (beginning-of-line)
10501 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10502 (not (match-string 2)))
10503 ;; skip subblock if block beginning found
10504 (vhdl-end-of-block)))
10505 (when pos (goto-char pos))))
10506
10507 (defun vhdl-sequential-statement-p ()
10508 "Check if point is within sequential statement part."
10509 (let ((start (point)))
10510 (save-excursion
10511 (vhdl-prepare-search-2
10512 ;; is sequential statement if ...
10513 (and (re-search-backward "^\\s-*begin\\>" nil t)
10514 ;; ... point is between "begin" and "end" of ...
10515 (progn (vhdl-end-of-block)
10516 (< start (point)))
10517 ;; ... a sequential block
10518 (progn (vhdl-beginning-of-block)
10519 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10520
10521 (defun vhdl-in-argument-list-p ()
10522 "Check if within an argument list."
10523 (save-excursion
10524 (vhdl-prepare-search-2
10525 (or (string-match "arglist"
10526 (format "%s" (caar (vhdl-get-syntactic-context))))
10527 (progn (beginning-of-line)
10528 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10529
10530 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10531 ;; Abbrev hooks
10532
10533 (defun vhdl-hooked-abbrev (func)
10534 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10535 but not if inside a comment or quote."
10536 (if (or (vhdl-in-literal)
10537 (save-excursion
10538 (forward-word -1)
10539 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10540 (progn
10541 (insert " ")
10542 (unexpand-abbrev)
10543 (delete-char -1))
10544 (if (not vhdl-electric-mode)
10545 (progn
10546 (insert " ")
10547 (unexpand-abbrev)
10548 (backward-word 1)
10549 (vhdl-case-word 1)
10550 (delete-char 1))
10551 (let ((invoke-char last-command-event)
10552 (abbrev-mode -1)
10553 (vhdl-template-invoked-by-hook t))
10554 (let ((caught (catch 'abort
10555 (funcall func))))
10556 (when (stringp caught) (message "%s" caught)))
10557 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10558 ;; delete CR which is still in event queue
10559 (if (fboundp 'enqueue-eval-event)
10560 (enqueue-eval-event 'delete-char -1)
10561 (setq unread-command-events ; push back a delete char
10562 (list (vhdl-character-to-event ?\177))))))))
10563
10564 (defun vhdl-template-alias-hook ()
10565 (vhdl-hooked-abbrev 'vhdl-template-alias))
10566 (defun vhdl-template-architecture-hook ()
10567 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10568 (defun vhdl-template-assert-hook ()
10569 (vhdl-hooked-abbrev 'vhdl-template-assert))
10570 (defun vhdl-template-attribute-hook ()
10571 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10572 (defun vhdl-template-block-hook ()
10573 (vhdl-hooked-abbrev 'vhdl-template-block))
10574 (defun vhdl-template-break-hook ()
10575 (vhdl-hooked-abbrev 'vhdl-template-break))
10576 (defun vhdl-template-case-hook ()
10577 (vhdl-hooked-abbrev 'vhdl-template-case))
10578 (defun vhdl-template-component-hook ()
10579 (vhdl-hooked-abbrev 'vhdl-template-component))
10580 (defun vhdl-template-instance-hook ()
10581 (vhdl-hooked-abbrev 'vhdl-template-instance))
10582 (defun vhdl-template-conditional-signal-asst-hook ()
10583 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10584 (defun vhdl-template-configuration-hook ()
10585 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10586 (defun vhdl-template-constant-hook ()
10587 (vhdl-hooked-abbrev 'vhdl-template-constant))
10588 (defun vhdl-template-disconnect-hook ()
10589 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10590 (defun vhdl-template-display-comment-hook ()
10591 (vhdl-hooked-abbrev 'vhdl-comment-display))
10592 (defun vhdl-template-else-hook ()
10593 (vhdl-hooked-abbrev 'vhdl-template-else))
10594 (defun vhdl-template-elsif-hook ()
10595 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10596 (defun vhdl-template-entity-hook ()
10597 (vhdl-hooked-abbrev 'vhdl-template-entity))
10598 (defun vhdl-template-exit-hook ()
10599 (vhdl-hooked-abbrev 'vhdl-template-exit))
10600 (defun vhdl-template-file-hook ()
10601 (vhdl-hooked-abbrev 'vhdl-template-file))
10602 (defun vhdl-template-for-hook ()
10603 (vhdl-hooked-abbrev 'vhdl-template-for))
10604 (defun vhdl-template-function-hook ()
10605 (vhdl-hooked-abbrev 'vhdl-template-function))
10606 (defun vhdl-template-generic-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-generic))
10608 (defun vhdl-template-group-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-group))
10610 (defun vhdl-template-library-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-library))
10612 (defun vhdl-template-limit-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-limit))
10614 (defun vhdl-template-if-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-if))
10616 (defun vhdl-template-bare-loop-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10618 (defun vhdl-template-map-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-map))
10620 (defun vhdl-template-nature-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-nature))
10622 (defun vhdl-template-next-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-next))
10624 (defun vhdl-template-others-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-others))
10626 (defun vhdl-template-package-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-package))
10628 (defun vhdl-template-port-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-port))
10630 (defun vhdl-template-procedural-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10632 (defun vhdl-template-procedure-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10634 (defun vhdl-template-process-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-process))
10636 (defun vhdl-template-quantity-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10638 (defun vhdl-template-report-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-report))
10640 (defun vhdl-template-return-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-return))
10642 (defun vhdl-template-selected-signal-asst-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10644 (defun vhdl-template-signal-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-signal))
10646 (defun vhdl-template-subnature-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10648 (defun vhdl-template-subtype-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10650 (defun vhdl-template-terminal-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10652 (defun vhdl-template-type-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-type))
10654 (defun vhdl-template-use-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-use))
10656 (defun vhdl-template-variable-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-variable))
10658 (defun vhdl-template-wait-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-wait))
10660 (defun vhdl-template-when-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-when))
10662 (defun vhdl-template-while-loop-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10664 (defun vhdl-template-with-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-with))
10666 (defun vhdl-template-and-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-and))
10668 (defun vhdl-template-or-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-or))
10670 (defun vhdl-template-nand-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-nand))
10672 (defun vhdl-template-nor-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-nor))
10674 (defun vhdl-template-xor-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-xor))
10676 (defun vhdl-template-xnor-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10678 (defun vhdl-template-not-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-not))
10680
10681 (defun vhdl-template-default-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-default))
10683 (defun vhdl-template-default-indent-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10685
10686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10687 ;; Template insertion from completion list
10688
10689 (defun vhdl-template-insert-construct (name)
10690 "Insert the built-in construct template with NAME."
10691 (interactive
10692 (list (let ((completion-ignore-case t))
10693 (completing-read "Construct name: "
10694 vhdl-template-construct-alist nil t))))
10695 (vhdl-template-insert-fun
10696 (cadr (assoc name vhdl-template-construct-alist))))
10697
10698 (defun vhdl-template-insert-package (name)
10699 "Insert the built-in package template with NAME."
10700 (interactive
10701 (list (let ((completion-ignore-case t))
10702 (completing-read "Package name: "
10703 vhdl-template-package-alist nil t))))
10704 (vhdl-template-insert-fun
10705 (cadr (assoc name vhdl-template-package-alist))))
10706
10707 (defun vhdl-template-insert-directive (name)
10708 "Insert the built-in directive template with NAME."
10709 (interactive
10710 (list (let ((completion-ignore-case t))
10711 (completing-read "Directive name: "
10712 vhdl-template-directive-alist nil t))))
10713 (vhdl-template-insert-fun
10714 (cadr (assoc name vhdl-template-directive-alist))))
10715
10716 (defun vhdl-template-insert-fun (fun)
10717 "Call FUN to insert a built-in template."
10718 (let ((caught (catch 'abort (when fun (funcall fun)))))
10719 (when (stringp caught) (message "%s" caught))))
10720
10721
10722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10723 ;;; Models
10724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10725
10726 (defun vhdl-model-insert (model-name)
10727 "Insert the user model with name MODEL-NAME."
10728 (interactive
10729 (let ((completion-ignore-case t))
10730 (list (completing-read "Model name: " vhdl-model-alist))))
10731 (indent-according-to-mode)
10732 (let ((start (point-marker))
10733 (margin (current-indentation))
10734 model position prompt string end)
10735 (vhdl-prepare-search-2
10736 (when (setq model (assoc model-name vhdl-model-alist))
10737 ;; insert model
10738 (beginning-of-line)
10739 (delete-horizontal-space)
10740 (goto-char start)
10741 (vhdl-insert-string-or-file (nth 1 model))
10742 (setq end (point-marker))
10743 ;; indent code
10744 (goto-char start)
10745 (beginning-of-line)
10746 (while (< (point) end)
10747 (unless (looking-at "^$")
10748 (insert-char ? margin))
10749 (beginning-of-line 2))
10750 (goto-char start)
10751 ;; insert clock
10752 (unless (equal "" vhdl-clock-name)
10753 (while (re-search-forward "<clock>" end t)
10754 (replace-match vhdl-clock-name)))
10755 (goto-char start)
10756 ;; insert reset
10757 (unless (equal "" vhdl-reset-name)
10758 (while (re-search-forward "<reset>" end t)
10759 (replace-match vhdl-reset-name)))
10760 ;; replace header prompts
10761 (vhdl-template-replace-header-keywords start end nil t)
10762 (goto-char start)
10763 ;; query other prompts
10764 (while (re-search-forward
10765 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10766 (unless (equal "cursor" (match-string 1))
10767 (setq position (match-beginning 1))
10768 (setq prompt (match-string 1))
10769 (replace-match "")
10770 (setq string (vhdl-template-field prompt nil t))
10771 ;; replace occurrences of same prompt
10772 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10773 (replace-match (or string "")))
10774 (goto-char position)))
10775 (goto-char start)
10776 ;; goto final position
10777 (if (re-search-forward "<cursor>" end t)
10778 (replace-match "")
10779 (goto-char end))))))
10780
10781 (defun vhdl-model-defun ()
10782 "Define help and hook functions for user models."
10783 (let ((model-alist vhdl-model-alist)
10784 model-name model-keyword)
10785 (while model-alist
10786 ;; define functions for user models that can be invoked from menu and key
10787 ;; bindings and which themselves call `vhdl-model-insert' with the model
10788 ;; name as argument
10789 (setq model-name (nth 0 (car model-alist)))
10790 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10791 ,(concat "Insert model for \"" model-name "\".")
10792 (interactive)
10793 (vhdl-model-insert ,model-name)))
10794 ;; define hooks for user models that are invoked from keyword abbrevs
10795 (setq model-keyword (nth 3 (car model-alist)))
10796 (unless (equal model-keyword "")
10797 (eval `(defun
10798 ,(vhdl-function-name
10799 "vhdl-model" model-name "hook") ()
10800 (vhdl-hooked-abbrev
10801 ',(vhdl-function-name "vhdl-model" model-name)))))
10802 (setq model-alist (cdr model-alist)))))
10803
10804 (vhdl-model-defun)
10805
10806
10807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10808 ;;; Port translation
10809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10810
10811 (defvar vhdl-port-list nil
10812 "Variable to hold last port map parsed.")
10813 ;; structure: (parenthesised expression means list of such entries)
10814 ;; (ent-name
10815 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10816 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10817 ;; (lib-name pack-key))
10818
10819 (defun vhdl-parse-string (string &optional optional)
10820 "Check that the text following point matches the regexp in STRING."
10821 (if (looking-at string)
10822 (goto-char (match-end 0))
10823 (unless optional
10824 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10825 (vhdl-current-line) string)))
10826 nil))
10827
10828 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10829 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10830 (vhdl-prepare-search-1
10831 (if (string-match (car regexp-cons) string)
10832 (if adjust-case
10833 (funcall vhdl-file-name-case
10834 (replace-match (cdr regexp-cons) t nil string))
10835 (replace-match (cdr regexp-cons) t nil string))
10836 string)))
10837
10838 (defun vhdl-parse-group-comment ()
10839 "Parse comment and empty lines between groups of lines."
10840 (let ((start (point))
10841 string)
10842 (vhdl-forward-comment (point-max))
10843 (setq string (buffer-substring-no-properties start (point)))
10844 (vhdl-forward-syntactic-ws)
10845 ;; strip off leading blanks and first newline
10846 (while (string-match "^\\(\\s-+\\)" string)
10847 (setq string (concat (substring string 0 (match-beginning 1))
10848 (substring string (match-end 1)))))
10849 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10850 (substring string 1)
10851 string)))
10852
10853 (defun vhdl-paste-group-comment (string indent)
10854 "Paste comment and empty lines from STRING between groups of lines
10855 with INDENT."
10856 (let ((pos (point-marker)))
10857 (when (> indent 0)
10858 (while (string-match "^\\(--\\)" string)
10859 (setq string (concat (substring string 0 (match-beginning 1))
10860 (make-string indent ? )
10861 (substring string (match-beginning 1))))))
10862 (beginning-of-line)
10863 (insert string)
10864 (goto-char pos)))
10865
10866 (defvar vhdl-port-flattened nil
10867 "Indicates whether a port has been flattened.")
10868
10869 (defun vhdl-port-flatten (&optional as-alist)
10870 "Flatten port list so that only one generic/port exists per line.
10871 This operation is performed on an internally stored port and is only
10872 reflected in a subsequent paste operation."
10873 (interactive)
10874 (if (not vhdl-port-list)
10875 (error "ERROR: No port has been read")
10876 (message "Flattening port for next paste...")
10877 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10878 (old-vhdl-port-list (cdr vhdl-port-list))
10879 old-port-list new-port-list old-port new-port names)
10880 ;; traverse port list and flatten entries
10881 (while (cdr old-vhdl-port-list)
10882 (setq old-port-list (car old-vhdl-port-list))
10883 (setq new-port-list nil)
10884 (while old-port-list
10885 (setq old-port (car old-port-list))
10886 (setq names (car old-port))
10887 (while names
10888 (setq new-port (cons (if as-alist (car names) (list (car names)))
10889 (cdr old-port)))
10890 (setq new-port-list (append new-port-list (list new-port)))
10891 (setq names (cdr names)))
10892 (setq old-port-list (cdr old-port-list)))
10893 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10894 (setq new-vhdl-port-list (append new-vhdl-port-list
10895 (list new-port-list))))
10896 (setq vhdl-port-list
10897 (append new-vhdl-port-list (list old-vhdl-port-list))
10898 vhdl-port-flattened t)
10899 (message "Flattening port for next paste...done"))))
10900
10901 (defvar vhdl-port-reversed-direction nil
10902 "Indicates whether port directions are reversed.")
10903
10904 (defun vhdl-port-reverse-direction ()
10905 "Reverse direction for all ports (useful in testbenches).
10906 This operation is performed on an internally stored port and is only
10907 reflected in a subsequent paste operation."
10908 (interactive)
10909 (if (not vhdl-port-list)
10910 (error "ERROR: No port has been read")
10911 (message "Reversing port directions for next paste...")
10912 (let ((port-list (nth 2 vhdl-port-list))
10913 port-dir-car port-dir)
10914 ;; traverse port list and reverse directions
10915 (while port-list
10916 (setq port-dir-car (cddr (car port-list))
10917 port-dir (car port-dir-car))
10918 (setcar port-dir-car
10919 (cond ((equal port-dir "in") "out")
10920 ((equal port-dir "out") "in")
10921 (t port-dir)))
10922 (setq port-list (cdr port-list)))
10923 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10924 (message "Reversing port directions for next paste...done"))))
10925
10926 (defun vhdl-port-copy ()
10927 "Get generic and port information from an entity or component declaration."
10928 (interactive)
10929 (save-excursion
10930 (let (parse-error end-of-list
10931 decl-type name generic-list port-list context-clause
10932 object names direct type init comment group-comment)
10933 (vhdl-prepare-search-2
10934 (setq
10935 parse-error
10936 (catch 'parse
10937 ;; check if within entity or component declaration
10938 (end-of-line)
10939 (when (or (not (re-search-backward
10940 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10941 (equal "END" (upcase (match-string 1))))
10942 (throw 'parse "ERROR: Not within an entity or component declaration"))
10943 (setq decl-type (downcase (match-string-no-properties 1)))
10944 (forward-word 1)
10945 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10946 (setq name (match-string-no-properties 1))
10947 (message "Reading port of %s \"%s\"..." decl-type name)
10948 (vhdl-forward-syntactic-ws)
10949 ;; parse generic clause
10950 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10951 ;; parse group comment and spacing
10952 (setq group-comment (vhdl-parse-group-comment))
10953 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10954 (while (not end-of-list)
10955 ;; parse names (accept extended identifiers)
10956 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10957 (setq names (list (match-string-no-properties 1)))
10958 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10959 (setq names
10960 (append names (list (match-string-no-properties 1)))))
10961 ;; parse type
10962 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10963 (setq type (match-string-no-properties 1))
10964 (setq comment nil)
10965 (while (looking-at "(")
10966 (setq type
10967 (concat type
10968 (buffer-substring-no-properties
10969 (point) (progn (forward-sexp) (point)))
10970 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10971 (match-string-no-properties 1)))))
10972 ;; special case: closing parenthesis is on separate line
10973 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10974 (setq comment (substring type (match-beginning 2)))
10975 (setq type (substring type 0 (match-beginning 1))))
10976 ;; strip of trailing group-comment
10977 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10978 (setq type (substring type 0 (match-end 1)))
10979 ;; parse initialization expression
10980 (setq init nil)
10981 (when (vhdl-parse-string ":=[ \t\n]*" t)
10982 (vhdl-parse-string "\\([^();\n]*\\)")
10983 (setq init (match-string-no-properties 1))
10984 (while (looking-at "(")
10985 (setq init
10986 (concat init
10987 (buffer-substring-no-properties
10988 (point) (progn (forward-sexp) (point)))
10989 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10990 (match-string-no-properties 1))))))
10991 ;; special case: closing parenthesis is on separate line
10992 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10993 (setq comment (substring init (match-beginning 2)))
10994 (setq init (substring init 0 (match-beginning 1)))
10995 (vhdl-forward-syntactic-ws))
10996 (skip-chars-forward " \t")
10997 ;; parse inline comment, special case: as above, no initial.
10998 (unless comment
10999 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11000 (match-string-no-properties 1))))
11001 (vhdl-forward-syntactic-ws)
11002 (setq end-of-list (vhdl-parse-string ")" t))
11003 (vhdl-parse-string "\\s-*;\\s-*")
11004 ;; parse inline comment
11005 (unless comment
11006 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11007 (match-string-no-properties 1))))
11008 ;; save everything in list
11009 (setq generic-list (append generic-list
11010 (list (list names type init
11011 comment group-comment))))
11012 ;; parse group comment and spacing
11013 (setq group-comment (vhdl-parse-group-comment))))
11014 ;; parse port clause
11015 (when (vhdl-parse-string "port[ \t\n]*(" t)
11016 ;; parse group comment and spacing
11017 (setq group-comment (vhdl-parse-group-comment))
11018 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11019 (while (not end-of-list)
11020 ;; parse object
11021 (setq object
11022 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11023 (match-string-no-properties 1)))
11024 ;; parse names (accept extended identifiers)
11025 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11026 (setq names (list (match-string-no-properties 1)))
11027 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11028 (setq names (append names (list (match-string-no-properties 1)))))
11029 ;; parse direction
11030 (vhdl-parse-string ":[ \t\n]*")
11031 (setq direct
11032 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11033 (match-string-no-properties 1)))
11034 ;; parse type
11035 (vhdl-parse-string "\\([^();\n]+\\)")
11036 (setq type (match-string-no-properties 1))
11037 (setq comment nil)
11038 (while (looking-at "(")
11039 (setq type (concat type
11040 (buffer-substring-no-properties
11041 (point) (progn (forward-sexp) (point)))
11042 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11043 (match-string-no-properties 1)))))
11044 ;; special case: closing parenthesis is on separate line
11045 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11046 (setq comment (substring type (match-beginning 2)))
11047 (setq type (substring type 0 (match-beginning 1))))
11048 ;; strip of trailing group-comment
11049 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11050 (setq type (substring type 0 (match-end 1)))
11051 (vhdl-forward-syntactic-ws)
11052 (setq end-of-list (vhdl-parse-string ")" t))
11053 (vhdl-parse-string "\\s-*;\\s-*")
11054 ;; parse inline comment
11055 (unless comment
11056 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11057 (match-string-no-properties 1))))
11058 ;; save everything in list
11059 (setq port-list (append port-list
11060 (list (list names object direct type
11061 comment group-comment))))
11062 ;; parse group comment and spacing
11063 (setq group-comment (vhdl-parse-group-comment))))
11064 ; (vhdl-parse-string "end\\>")
11065 ;; parse context clause
11066 (setq context-clause (vhdl-scan-context-clause))
11067 ; ;; add surrounding package to context clause
11068 ; (when (and (equal decl-type "component")
11069 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11070 ; (setq context-clause
11071 ; (append context-clause
11072 ; (list (cons (vhdl-work-library)
11073 ; (match-string-no-properties 1))))))
11074 (message "Reading port of %s \"%s\"...done" decl-type name)
11075 nil)))
11076 ;; finish parsing
11077 (if parse-error
11078 (error parse-error)
11079 (setq vhdl-port-list (list name generic-list port-list context-clause)
11080 vhdl-port-reversed-direction nil
11081 vhdl-port-flattened nil)))))
11082
11083 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11084 "Paste a context clause."
11085 (let ((margin (current-indentation))
11086 (clause-list (nth 3 vhdl-port-list))
11087 clause)
11088 (while clause-list
11089 (setq clause (car clause-list))
11090 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11091 (downcase exclude-pack-name)))
11092 (save-excursion
11093 (re-search-backward
11094 (concat "^\\s-*use\\s-+" (car clause)
11095 "\." (cdr clause) "\\>") nil t)))
11096 (vhdl-template-standard-package (car clause) (cdr clause))
11097 (insert "\n"))
11098 (setq clause-list (cdr clause-list)))))
11099
11100 (defun vhdl-port-paste-generic (&optional no-init)
11101 "Paste a generic clause."
11102 (let ((margin (current-indentation))
11103 (generic-list (nth 1 vhdl-port-list))
11104 list-margin start names generic)
11105 ;; paste generic clause
11106 (when generic-list
11107 (setq start (point))
11108 (vhdl-insert-keyword "GENERIC (")
11109 (unless vhdl-argument-list-indent
11110 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11111 (setq list-margin (current-column))
11112 (while generic-list
11113 (setq generic (car generic-list))
11114 ;; paste group comment and spacing
11115 (when (memq vhdl-include-group-comments '(decl always))
11116 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11117 ;; paste names
11118 (setq names (nth 0 generic))
11119 (while names
11120 (insert (car names))
11121 (setq names (cdr names))
11122 (when names (insert ", ")))
11123 ;; paste type
11124 (insert " : " (nth 1 generic))
11125 ;; paste initialization
11126 (when (and (not no-init) (nth 2 generic))
11127 (insert " := " (nth 2 generic)))
11128 (unless (cdr generic-list) (insert ")"))
11129 (insert ";")
11130 ;; paste comment
11131 (when (and vhdl-include-port-comments (nth 3 generic))
11132 (vhdl-comment-insert-inline (nth 3 generic) t))
11133 (setq generic-list (cdr generic-list))
11134 (when generic-list (insert "\n") (indent-to list-margin)))
11135 ;; align generic clause
11136 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11137
11138 (defun vhdl-port-paste-port ()
11139 "Paste a port clause."
11140 (let ((margin (current-indentation))
11141 (port-list (nth 2 vhdl-port-list))
11142 list-margin start names port)
11143 ;; paste port clause
11144 (when port-list
11145 (setq start (point))
11146 (vhdl-insert-keyword "PORT (")
11147 (unless vhdl-argument-list-indent
11148 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11149 (setq list-margin (current-column))
11150 (while port-list
11151 (setq port (car port-list))
11152 ;; paste group comment and spacing
11153 (when (memq vhdl-include-group-comments '(decl always))
11154 (vhdl-paste-group-comment (nth 5 port) list-margin))
11155 ;; paste object
11156 (when (nth 1 port) (insert (nth 1 port) " "))
11157 ;; paste names
11158 (setq names (nth 0 port))
11159 (while names
11160 (insert (car names))
11161 (setq names (cdr names))
11162 (when names (insert ", ")))
11163 ;; paste direction
11164 (insert " : ")
11165 (when (nth 2 port) (insert (nth 2 port) " "))
11166 ;; paste type
11167 (insert (nth 3 port))
11168 (unless (cdr port-list) (insert ")"))
11169 (insert ";")
11170 ;; paste comment
11171 (when (and vhdl-include-port-comments (nth 4 port))
11172 (vhdl-comment-insert-inline (nth 4 port) t))
11173 (setq port-list (cdr port-list))
11174 (when port-list (insert "\n") (indent-to list-margin)))
11175 ;; align port clause
11176 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11177
11178 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11179 "Paste as an entity or component declaration."
11180 (unless no-indent (indent-according-to-mode))
11181 (let ((margin (current-indentation))
11182 (name (nth 0 vhdl-port-list)))
11183 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11184 (insert name)
11185 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11186 (vhdl-insert-keyword " IS"))
11187 ;; paste generic and port clause
11188 (when (nth 1 vhdl-port-list)
11189 (insert "\n")
11190 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11191 (insert "\n"))
11192 (indent-to (+ margin vhdl-basic-offset))
11193 (vhdl-port-paste-generic (eq kind 'component)))
11194 (when (nth 2 vhdl-port-list)
11195 (insert "\n")
11196 (when (and (memq vhdl-insert-empty-lines '(unit all))
11197 (eq kind 'entity))
11198 (insert "\n"))
11199 (indent-to (+ margin vhdl-basic-offset)))
11200 (vhdl-port-paste-port)
11201 (insert "\n")
11202 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11203 (insert "\n"))
11204 (indent-to margin)
11205 (vhdl-insert-keyword "END")
11206 (if (eq kind 'entity)
11207 (progn
11208 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11209 (insert " " name))
11210 (vhdl-insert-keyword " COMPONENT")
11211 (unless (vhdl-standard-p '87) (insert " " name)))
11212 (insert ";")))
11213
11214 (defun vhdl-port-paste-entity (&optional no-indent)
11215 "Paste as an entity declaration."
11216 (interactive)
11217 (if (not vhdl-port-list)
11218 (error "ERROR: No port read")
11219 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11220 (vhdl-port-paste-declaration 'entity no-indent)
11221 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11222
11223 (defun vhdl-port-paste-component (&optional no-indent)
11224 "Paste as a component declaration."
11225 (interactive)
11226 (if (not vhdl-port-list)
11227 (error "ERROR: No port read")
11228 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11229 (vhdl-port-paste-declaration 'component no-indent)
11230 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11231
11232 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11233 "Paste as a generic map."
11234 (interactive)
11235 (unless secondary (indent-according-to-mode))
11236 (let ((margin (current-indentation))
11237 list-margin start generic
11238 (generic-list (nth 1 vhdl-port-list)))
11239 (when generic-list
11240 (setq start (point))
11241 (vhdl-insert-keyword "GENERIC MAP (")
11242 (if (not vhdl-association-list-with-formals)
11243 ;; paste list of actual generics
11244 (while generic-list
11245 (insert (if no-constants
11246 (car (nth 0 (car generic-list)))
11247 (or (nth 2 (car generic-list)) " ")))
11248 (setq generic-list (cdr generic-list))
11249 (insert (if generic-list ", " ")"))
11250 (when (and (not generic-list) secondary
11251 (null (nth 2 vhdl-port-list)))
11252 (insert ";")))
11253 (unless vhdl-argument-list-indent
11254 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11255 (setq list-margin (current-column))
11256 (while generic-list
11257 (setq generic (car generic-list))
11258 ;; paste group comment and spacing
11259 (when (eq vhdl-include-group-comments 'always)
11260 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11261 ;; paste formal and actual generic
11262 (insert (car (nth 0 generic)) " => "
11263 (if no-constants
11264 (car (nth 0 generic))
11265 (or (nth 2 generic) "")))
11266 (setq generic-list (cdr generic-list))
11267 (insert (if generic-list "," ")"))
11268 (when (and (not generic-list) secondary
11269 (null (nth 2 vhdl-port-list)))
11270 (insert ";"))
11271 ;; paste comment
11272 (when (or vhdl-include-type-comments
11273 (and vhdl-include-port-comments (nth 3 generic)))
11274 (vhdl-comment-insert-inline
11275 (concat
11276 (when vhdl-include-type-comments
11277 (concat "[" (nth 1 generic) "] "))
11278 (when vhdl-include-port-comments (nth 3 generic))) t))
11279 (when generic-list (insert "\n") (indent-to list-margin)))
11280 ;; align generic map
11281 (when vhdl-auto-align
11282 (vhdl-align-region-groups start (point) 1 t))))))
11283
11284 (defun vhdl-port-paste-port-map ()
11285 "Paste as a port map."
11286 (let ((margin (current-indentation))
11287 list-margin start port
11288 (port-list (nth 2 vhdl-port-list)))
11289 (when port-list
11290 (setq start (point))
11291 (vhdl-insert-keyword "PORT MAP (")
11292 (if (not vhdl-association-list-with-formals)
11293 ;; paste list of actual ports
11294 (while port-list
11295 (insert (vhdl-replace-string vhdl-actual-port-name
11296 (car (nth 0 (car port-list)))))
11297 (setq port-list (cdr port-list))
11298 (insert (if port-list ", " ")")))
11299 (unless vhdl-argument-list-indent
11300 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11301 (setq list-margin (current-column))
11302 (while port-list
11303 (setq port (car port-list))
11304 ;; paste group comment and spacing
11305 (when (eq vhdl-include-group-comments 'always)
11306 (vhdl-paste-group-comment (nth 5 port) list-margin))
11307 ;; paste formal and actual port
11308 (insert (car (nth 0 port)) " => ")
11309 (insert (vhdl-replace-string vhdl-actual-port-name
11310 (car (nth 0 port))))
11311 (setq port-list (cdr port-list))
11312 (insert (if port-list "," ");"))
11313 ;; paste comment
11314 (when (or vhdl-include-direction-comments
11315 vhdl-include-type-comments
11316 (and vhdl-include-port-comments (nth 4 port)))
11317 (vhdl-comment-insert-inline
11318 (concat
11319 (cond ((and vhdl-include-direction-comments
11320 vhdl-include-type-comments)
11321 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11322 (nth 3 port) "] "))
11323 ((and vhdl-include-direction-comments (nth 2 port))
11324 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11325 (vhdl-include-direction-comments " ")
11326 (vhdl-include-type-comments
11327 (concat "[" (nth 3 port) "] ")))
11328 (when vhdl-include-port-comments (nth 4 port))) t))
11329 (when port-list (insert "\n") (indent-to list-margin)))
11330 ;; align port clause
11331 (when vhdl-auto-align
11332 (vhdl-align-region-groups start (point) 1))))))
11333
11334 (defun vhdl-port-paste-instance (&optional name no-indent title)
11335 "Paste as an instantiation."
11336 (interactive)
11337 (if (not vhdl-port-list)
11338 (error "ERROR: No port read")
11339 (let ((orig-vhdl-port-list vhdl-port-list))
11340 ;; flatten local copy of port list (must be flat for port mapping)
11341 (vhdl-port-flatten)
11342 (unless no-indent (indent-according-to-mode))
11343 (let ((margin (current-indentation)))
11344 ;; paste instantiation
11345 (cond (name
11346 (insert name))
11347 ((equal (cdr vhdl-instance-name) "")
11348 (setq name (vhdl-template-field "instance name")))
11349 ((string-match "\%d" (cdr vhdl-instance-name))
11350 (let ((n 1))
11351 (while (save-excursion
11352 (setq name (format (vhdl-replace-string
11353 vhdl-instance-name
11354 (nth 0 vhdl-port-list)) n))
11355 (goto-char (point-min))
11356 (vhdl-re-search-forward name nil t))
11357 (setq n (1+ n)))
11358 (insert name)))
11359 (t (insert (vhdl-replace-string vhdl-instance-name
11360 (nth 0 vhdl-port-list)))))
11361 (message "Pasting port as instantiation \"%s\"..." name)
11362 (insert ": ")
11363 (when title
11364 (save-excursion
11365 (beginning-of-line)
11366 (indent-to vhdl-basic-offset)
11367 (insert "-- instance \"" name "\"\n")))
11368 (if (not (vhdl-use-direct-instantiation))
11369 (insert (nth 0 vhdl-port-list))
11370 (vhdl-insert-keyword "ENTITY ")
11371 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11372 (when (nth 1 vhdl-port-list)
11373 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11374 (vhdl-port-paste-generic-map t t))
11375 (when (nth 2 vhdl-port-list)
11376 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11377 (vhdl-port-paste-port-map))
11378 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11379 (insert ";"))
11380 (message "Pasting port as instantiation \"%s\"...done" name))
11381 (setq vhdl-port-list orig-vhdl-port-list))))
11382
11383 (defun vhdl-port-paste-constants (&optional no-indent)
11384 "Paste generics as constants."
11385 (interactive)
11386 (if (not vhdl-port-list)
11387 (error "ERROR: No port read")
11388 (let ((orig-vhdl-port-list vhdl-port-list))
11389 (message "Pasting port as constants...")
11390 ;; flatten local copy of port list (must be flat for constant initial.)
11391 (vhdl-port-flatten)
11392 (unless no-indent (indent-according-to-mode))
11393 (let ((margin (current-indentation))
11394 start generic name
11395 (generic-list (nth 1 vhdl-port-list)))
11396 (when generic-list
11397 (setq start (point))
11398 (while generic-list
11399 (setq generic (car generic-list))
11400 ;; paste group comment and spacing
11401 (when (memq vhdl-include-group-comments '(decl always))
11402 (vhdl-paste-group-comment (nth 4 generic) margin))
11403 (vhdl-insert-keyword "CONSTANT ")
11404 ;; paste generic constants
11405 (setq name (nth 0 generic))
11406 (when name
11407 (insert (car name))
11408 ;; paste type
11409 (insert " : " (nth 1 generic))
11410 ;; paste initialization
11411 (when (nth 2 generic)
11412 (insert " := " (nth 2 generic)))
11413 (insert ";")
11414 ;; paste comment
11415 (when (and vhdl-include-port-comments (nth 3 generic))
11416 (vhdl-comment-insert-inline (nth 3 generic) t))
11417 (setq generic-list (cdr generic-list))
11418 (when generic-list (insert "\n") (indent-to margin))))
11419 ;; align signal list
11420 (when vhdl-auto-align
11421 (vhdl-align-region-groups start (point) 1))))
11422 (message "Pasting port as constants...done")
11423 (setq vhdl-port-list orig-vhdl-port-list))))
11424
11425 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11426 "Paste ports as internal signals."
11427 (interactive)
11428 (if (not vhdl-port-list)
11429 (error "ERROR: No port read")
11430 (message "Pasting port as signals...")
11431 (unless no-indent (indent-according-to-mode))
11432 (let ((margin (current-indentation))
11433 start port names
11434 (port-list (nth 2 vhdl-port-list)))
11435 (when port-list
11436 (setq start (point))
11437 (while port-list
11438 (setq port (car port-list))
11439 ;; paste group comment and spacing
11440 (when (memq vhdl-include-group-comments '(decl always))
11441 (vhdl-paste-group-comment (nth 5 port) margin))
11442 ;; paste object
11443 (if (nth 1 port)
11444 (insert (nth 1 port) " ")
11445 (vhdl-insert-keyword "SIGNAL "))
11446 ;; paste actual port signals
11447 (setq names (nth 0 port))
11448 (while names
11449 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11450 (setq names (cdr names))
11451 (when names (insert ", ")))
11452 ;; paste type
11453 (insert " : " (nth 3 port))
11454 ;; paste initialization (inputs only)
11455 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11456 (insert " := " (if (string-match "(.+)" (nth 3 port))
11457 "(others => '0')" "'0'")))
11458 (insert ";")
11459 ;; paste comment
11460 (when (or vhdl-include-direction-comments
11461 (and vhdl-include-port-comments (nth 4 port)))
11462 (vhdl-comment-insert-inline
11463 (concat
11464 (cond ((and vhdl-include-direction-comments (nth 2 port))
11465 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11466 (vhdl-include-direction-comments " "))
11467 (when vhdl-include-port-comments (nth 4 port))) t))
11468 (setq port-list (cdr port-list))
11469 (when port-list (insert "\n") (indent-to margin)))
11470 ;; align signal list
11471 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11472 (message "Pasting port as signals...done")))
11473
11474 (defun vhdl-port-paste-initializations (&optional no-indent)
11475 "Paste ports as signal initializations."
11476 (interactive)
11477 (if (not vhdl-port-list)
11478 (error "ERROR: No port read")
11479 (let ((orig-vhdl-port-list vhdl-port-list))
11480 (message "Pasting port as initializations...")
11481 ;; flatten local copy of port list (must be flat for signal initial.)
11482 (vhdl-port-flatten)
11483 (unless no-indent (indent-according-to-mode))
11484 (let ((margin (current-indentation))
11485 start port name
11486 (port-list (nth 2 vhdl-port-list)))
11487 (when port-list
11488 (setq start (point))
11489 (while port-list
11490 (setq port (car port-list))
11491 ;; paste actual port signal (inputs only)
11492 (when (equal "IN" (upcase (nth 2 port)))
11493 (setq name (car (nth 0 port)))
11494 (insert (vhdl-replace-string vhdl-actual-port-name name))
11495 ;; paste initialization
11496 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11497 "(others => '0')" "'0'") ";"))
11498 (setq port-list (cdr port-list))
11499 (when (and port-list
11500 (equal "IN" (upcase (nth 2 (car port-list)))))
11501 (insert "\n") (indent-to margin)))
11502 ;; align signal list
11503 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11504 (message "Pasting port as initializations...done")
11505 (setq vhdl-port-list orig-vhdl-port-list))))
11506
11507 (defun vhdl-port-paste-testbench ()
11508 "Paste as a bare-bones testbench."
11509 (interactive)
11510 (if (not vhdl-port-list)
11511 (error "ERROR: No port read")
11512 (let ((case-fold-search t)
11513 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11514 (nth 0 vhdl-port-list)))
11515 (source-buffer (current-buffer))
11516 arch-name config-name ent-file-name arch-file-name
11517 ent-buffer arch-buffer position)
11518 ;; open entity file
11519 (unless (eq vhdl-testbench-create-files 'none)
11520 (setq ent-file-name
11521 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11522 ent-name t)
11523 "." (file-name-extension (buffer-file-name))))
11524 (if (file-exists-p ent-file-name)
11525 (if (y-or-n-p
11526 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11527 (progn (find-file ent-file-name)
11528 (erase-buffer)
11529 (set-buffer-modified-p nil))
11530 (if (eq vhdl-testbench-create-files 'separate)
11531 (setq ent-file-name nil)
11532 (error "ERROR: Pasting port as testbench...aborted")))
11533 (find-file ent-file-name)))
11534 (unless (and (eq vhdl-testbench-create-files 'separate)
11535 (null ent-file-name))
11536 ;; paste entity header
11537 (if vhdl-testbench-include-header
11538 (progn (vhdl-template-header
11539 (concat "Testbench for design \""
11540 (nth 0 vhdl-port-list) "\""))
11541 (goto-char (point-max)))
11542 (vhdl-comment-display-line) (insert "\n\n"))
11543 ;; paste std_logic_1164 package
11544 (when vhdl-testbench-include-library
11545 (vhdl-template-package-std-logic-1164)
11546 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11547 ;; paste entity declaration
11548 (vhdl-insert-keyword "ENTITY ")
11549 (insert ent-name)
11550 (vhdl-insert-keyword " IS")
11551 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11552 (insert "\n")
11553 (vhdl-insert-keyword "END ")
11554 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11555 (insert ent-name ";")
11556 (insert "\n\n")
11557 (vhdl-comment-display-line) (insert "\n"))
11558 ;; get architecture name
11559 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11560 (read-from-minibuffer "architecture name: "
11561 nil vhdl-minibuffer-local-map)
11562 (vhdl-replace-string vhdl-testbench-architecture-name
11563 (nth 0 vhdl-port-list))))
11564 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11565 ;; open architecture file
11566 (if (not (eq vhdl-testbench-create-files 'separate))
11567 (insert "\n")
11568 (setq ent-buffer (current-buffer))
11569 (setq arch-file-name
11570 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11571 (concat ent-name " " arch-name) t)
11572 "." (file-name-extension (buffer-file-name))))
11573 (when (and (file-exists-p arch-file-name)
11574 (not (y-or-n-p (concat "File \"" arch-file-name
11575 "\" exists; overwrite? "))))
11576 (error "ERROR: Pasting port as testbench...aborted"))
11577 (find-file arch-file-name)
11578 (erase-buffer)
11579 (set-buffer-modified-p nil)
11580 ;; paste architecture header
11581 (if vhdl-testbench-include-header
11582 (progn (vhdl-template-header
11583 (concat "Testbench architecture for design \""
11584 (nth 0 vhdl-port-list) "\""))
11585 (goto-char (point-max)))
11586 (vhdl-comment-display-line) (insert "\n\n")))
11587 ;; paste architecture body
11588 (vhdl-insert-keyword "ARCHITECTURE ")
11589 (insert arch-name)
11590 (vhdl-insert-keyword " OF ")
11591 (insert ent-name)
11592 (vhdl-insert-keyword " IS")
11593 (insert "\n\n") (indent-to vhdl-basic-offset)
11594 ;; paste component declaration
11595 (unless (vhdl-use-direct-instantiation)
11596 (vhdl-port-paste-component t)
11597 (insert "\n\n") (indent-to vhdl-basic-offset))
11598 ;; paste constants
11599 (when (nth 1 vhdl-port-list)
11600 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11601 (vhdl-port-paste-constants t)
11602 (insert "\n\n") (indent-to vhdl-basic-offset))
11603 ;; paste internal signals
11604 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11605 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11606 (insert "\n")
11607 ;; paste custom declarations
11608 (unless (equal "" vhdl-testbench-declarations)
11609 (insert "\n")
11610 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11611 (setq position (point))
11612 (insert "\n\n")
11613 (vhdl-comment-display-line) (insert "\n")
11614 (when vhdl-testbench-include-configuration
11615 (setq config-name (vhdl-replace-string
11616 vhdl-testbench-configuration-name
11617 (concat ent-name " " arch-name)))
11618 (insert "\n")
11619 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11620 (vhdl-insert-keyword " OF ") (insert ent-name)
11621 (vhdl-insert-keyword " IS\n")
11622 (indent-to vhdl-basic-offset)
11623 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11624 (indent-to vhdl-basic-offset)
11625 (vhdl-insert-keyword "END FOR;\n")
11626 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11627 (vhdl-comment-display-line) (insert "\n"))
11628 (goto-char position)
11629 (vhdl-template-begin-end
11630 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11631 ;; paste instantiation
11632 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11633 (vhdl-port-paste-instance
11634 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11635 (insert "\n")
11636 ;; paste custom statements
11637 (unless (equal "" vhdl-testbench-statements)
11638 (insert "\n")
11639 (vhdl-insert-string-or-file vhdl-testbench-statements))
11640 (insert "\n")
11641 (indent-to vhdl-basic-offset)
11642 (unless (eq vhdl-testbench-create-files 'none)
11643 (setq arch-buffer (current-buffer))
11644 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11645 (set-buffer arch-buffer) (save-buffer))
11646 (message "%s"
11647 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11648 ent-name arch-name)
11649 (and ent-file-name
11650 (format "\n File created: \"%s\"" ent-file-name))
11651 (and arch-file-name
11652 (format "\n File created: \"%s\"" arch-file-name)))))))
11653
11654
11655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11656 ;;; Subprogram interface translation
11657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11658
11659 (defvar vhdl-subprog-list nil
11660 "Variable to hold last subprogram interface parsed.")
11661 ;; structure: (parenthesised expression means list of such entries)
11662 ;; (subprog-name kind
11663 ;; ((names) object direct type init comment group-comment)
11664 ;; return-type return-comment group-comment)
11665
11666 (defvar vhdl-subprog-flattened nil
11667 "Indicates whether an subprogram interface has been flattened.")
11668
11669 (defun vhdl-subprog-flatten ()
11670 "Flatten interface list so that only one parameter exists per line."
11671 (interactive)
11672 (if (not vhdl-subprog-list)
11673 (error "ERROR: No subprogram interface has been read")
11674 (message "Flattening subprogram interface...")
11675 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11676 new-subprog-list old-subprog new-subprog names)
11677 ;; traverse parameter list and flatten entries
11678 (while old-subprog-list
11679 (setq old-subprog (car old-subprog-list))
11680 (setq names (car old-subprog))
11681 (while names
11682 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11683 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11684 (setq names (cdr names)))
11685 (setq old-subprog-list (cdr old-subprog-list)))
11686 (setq vhdl-subprog-list
11687 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11688 new-subprog-list (nth 3 vhdl-subprog-list)
11689 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11690 vhdl-subprog-flattened t)
11691 (message "Flattening subprogram interface...done"))))
11692
11693 (defun vhdl-subprog-copy ()
11694 "Get interface information from a subprogram specification."
11695 (interactive)
11696 (save-excursion
11697 (let (parse-error pos end-of-list
11698 name kind param-list object names direct type init
11699 comment group-comment
11700 return-type return-comment return-group-comment)
11701 (vhdl-prepare-search-2
11702 (setq
11703 parse-error
11704 (catch 'parse
11705 ;; check if within function declaration
11706 (setq pos (point))
11707 (end-of-line)
11708 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11709 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11710 (goto-char (match-end 0))
11711 (save-excursion (backward-char)
11712 (forward-sexp)
11713 (<= pos (point))))
11714 (throw 'parse "ERROR: Not within a subprogram specification"))
11715 (setq name (match-string-no-properties 5))
11716 (setq kind (if (match-string 2) 'procedure 'function))
11717 (setq end-of-list (not (match-string 7)))
11718 (message "Reading interface of subprogram \"%s\"..." name)
11719 ;; parse parameter list
11720 (setq group-comment (vhdl-parse-group-comment))
11721 (setq end-of-list (or end-of-list
11722 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11723 (while (not end-of-list)
11724 ;; parse object
11725 (setq object
11726 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11727 (match-string-no-properties 1)))
11728 ;; parse names (accept extended identifiers)
11729 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11730 (setq names (list (match-string-no-properties 1)))
11731 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11732 (setq names (append names (list (match-string-no-properties 1)))))
11733 ;; parse direction
11734 (vhdl-parse-string ":[ \t\n]*")
11735 (setq direct
11736 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11737 (match-string-no-properties 1)))
11738 ;; parse type
11739 (vhdl-parse-string "\\([^():;\n]+\\)")
11740 (setq type (match-string-no-properties 1))
11741 (setq comment nil)
11742 (while (looking-at "(")
11743 (setq type
11744 (concat type
11745 (buffer-substring-no-properties
11746 (point) (progn (forward-sexp) (point)))
11747 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11748 (match-string-no-properties 1)))))
11749 ;; special case: closing parenthesis is on separate line
11750 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11751 (setq comment (substring type (match-beginning 2)))
11752 (setq type (substring type 0 (match-beginning 1))))
11753 ;; strip off trailing group-comment
11754 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11755 (setq type (substring type 0 (match-end 1)))
11756 ;; parse initialization expression
11757 (setq init nil)
11758 (when (vhdl-parse-string ":=[ \t\n]*" t)
11759 (vhdl-parse-string "\\([^();\n]*\\)")
11760 (setq init (match-string-no-properties 1))
11761 (while (looking-at "(")
11762 (setq init
11763 (concat init
11764 (buffer-substring-no-properties
11765 (point) (progn (forward-sexp) (point)))
11766 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11767 (match-string-no-properties 1))))))
11768 ;; special case: closing parenthesis is on separate line
11769 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11770 (setq comment (substring init (match-beginning 2)))
11771 (setq init (substring init 0 (match-beginning 1)))
11772 (vhdl-forward-syntactic-ws))
11773 (skip-chars-forward " \t")
11774 ;; parse inline comment, special case: as above, no initial.
11775 (unless comment
11776 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11777 (match-string-no-properties 1))))
11778 (vhdl-forward-syntactic-ws)
11779 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11780 ;; parse inline comment
11781 (unless comment
11782 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11783 (match-string-no-properties 1))))
11784 (setq return-group-comment (vhdl-parse-group-comment))
11785 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11786 ;; parse return type
11787 (when (match-string 3)
11788 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11789 (setq return-type (match-string-no-properties 1))
11790 (when (and return-type
11791 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11792 (setq return-comment (substring return-type (match-beginning 2)))
11793 (setq return-type (substring return-type 0 (match-beginning 1))))
11794 ;; strip of trailing group-comment
11795 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11796 (setq return-type (substring return-type 0 (match-end 1)))
11797 ;; parse return comment
11798 (unless return-comment
11799 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11800 (match-string-no-properties 1)))))
11801 ;; parse inline comment
11802 (unless comment
11803 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11804 (match-string-no-properties 1))))
11805 ;; save everything in list
11806 (setq param-list (append param-list
11807 (list (list names object direct type init
11808 comment group-comment))))
11809 ;; parse group comment and spacing
11810 (setq group-comment (vhdl-parse-group-comment)))
11811 (message "Reading interface of subprogram \"%s\"...done" name)
11812 nil)))
11813 ;; finish parsing
11814 (if parse-error
11815 (error parse-error)
11816 (setq vhdl-subprog-list
11817 (list name kind param-list return-type return-comment
11818 return-group-comment)
11819 vhdl-subprog-flattened nil)))))
11820
11821 (defun vhdl-subprog-paste-specification (kind)
11822 "Paste as a subprogram specification."
11823 (indent-according-to-mode)
11824 (let ((margin (current-column))
11825 (param-list (nth 2 vhdl-subprog-list))
11826 list-margin start names param)
11827 ;; paste keyword and name
11828 (vhdl-insert-keyword
11829 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11830 (insert (nth 0 vhdl-subprog-list))
11831 (if (not param-list)
11832 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11833 (setq start (point))
11834 ;; paste parameter list
11835 (insert " (")
11836 (unless vhdl-argument-list-indent
11837 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11838 (setq list-margin (current-column))
11839 (while param-list
11840 (setq param (car param-list))
11841 ;; paste group comment and spacing
11842 (when (memq vhdl-include-group-comments (list kind 'always))
11843 (vhdl-paste-group-comment (nth 6 param) list-margin))
11844 ;; paste object
11845 (when (nth 1 param) (insert (nth 1 param) " "))
11846 ;; paste names
11847 (setq names (nth 0 param))
11848 (while names
11849 (insert (car names))
11850 (setq names (cdr names))
11851 (when names (insert ", ")))
11852 ;; paste direction
11853 (insert " : ")
11854 (when (nth 2 param) (insert (nth 2 param) " "))
11855 ;; paste type
11856 (insert (nth 3 param))
11857 ;; paste initialization
11858 (when (nth 4 param) (insert " := " (nth 4 param)))
11859 ;; terminate line
11860 (if (cdr param-list)
11861 (insert ";")
11862 (insert ")")
11863 (when (null (nth 3 vhdl-subprog-list))
11864 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11865 ;; paste comment
11866 (when (and vhdl-include-port-comments (nth 5 param))
11867 (vhdl-comment-insert-inline (nth 5 param) t))
11868 (setq param-list (cdr param-list))
11869 (when param-list (insert "\n") (indent-to list-margin)))
11870 (when (nth 3 vhdl-subprog-list)
11871 (insert "\n") (indent-to list-margin)
11872 ;; paste group comment and spacing
11873 (when (memq vhdl-include-group-comments (list kind 'always))
11874 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11875 ;; paste return type
11876 (insert "return " (nth 3 vhdl-subprog-list))
11877 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11878 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11879 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11880 ;; align parameter list
11881 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11882 ;; paste body
11883 (when (eq kind 'body)
11884 (insert "\n")
11885 (vhdl-template-begin-end
11886 (unless (vhdl-standard-p '87)
11887 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11888 (nth 0 vhdl-subprog-list) margin))))
11889
11890 (defun vhdl-subprog-paste-declaration ()
11891 "Paste as a subprogram declaration."
11892 (interactive)
11893 (if (not vhdl-subprog-list)
11894 (error "ERROR: No subprogram interface read")
11895 (message "Pasting interface as subprogram declaration \"%s\"..."
11896 (car vhdl-subprog-list))
11897 ;; paste specification
11898 (vhdl-subprog-paste-specification 'decl)
11899 (message "Pasting interface as subprogram declaration \"%s\"...done"
11900 (car vhdl-subprog-list))))
11901
11902 (defun vhdl-subprog-paste-body ()
11903 "Paste as a subprogram body."
11904 (interactive)
11905 (if (not vhdl-subprog-list)
11906 (error "ERROR: No subprogram interface read")
11907 (message "Pasting interface as subprogram body \"%s\"..."
11908 (car vhdl-subprog-list))
11909 ;; paste specification and body
11910 (vhdl-subprog-paste-specification 'body)
11911 (message "Pasting interface as subprogram body \"%s\"...done"
11912 (car vhdl-subprog-list))))
11913
11914 (defun vhdl-subprog-paste-call ()
11915 "Paste as a subprogram call."
11916 (interactive)
11917 (if (not vhdl-subprog-list)
11918 (error "ERROR: No subprogram interface read")
11919 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11920 param-list margin list-margin param start)
11921 ;; flatten local copy of interface list (must be flat for parameter mapping)
11922 (vhdl-subprog-flatten)
11923 (setq param-list (nth 2 vhdl-subprog-list))
11924 (indent-according-to-mode)
11925 (setq margin (current-indentation))
11926 (message "Pasting interface as subprogram call \"%s\"..."
11927 (car vhdl-subprog-list))
11928 ;; paste name
11929 (insert (nth 0 vhdl-subprog-list))
11930 (if (not param-list)
11931 (insert ";")
11932 (setq start (point))
11933 ;; paste parameter list
11934 (insert " (")
11935 (unless vhdl-argument-list-indent
11936 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11937 (setq list-margin (current-column))
11938 (while param-list
11939 (setq param (car param-list))
11940 ;; paste group comment and spacing
11941 (when (eq vhdl-include-group-comments 'always)
11942 (vhdl-paste-group-comment (nth 6 param) list-margin))
11943 ;; paste formal port
11944 (insert (car (nth 0 param)) " => ")
11945 (setq param-list (cdr param-list))
11946 (insert (if param-list "," ");"))
11947 ;; paste comment
11948 (when (and vhdl-include-port-comments (nth 5 param))
11949 (vhdl-comment-insert-inline (nth 5 param)))
11950 (when param-list (insert "\n") (indent-to list-margin)))
11951 ;; align parameter list
11952 (when vhdl-auto-align
11953 (vhdl-align-region-groups start (point) 1)))
11954 (message "Pasting interface as subprogram call \"%s\"...done"
11955 (car vhdl-subprog-list))
11956 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11957
11958
11959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11960 ;;; Miscellaneous
11961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11962
11963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11964 ;; Hippie expand customization
11965
11966 (defvar vhdl-expand-upper-case nil)
11967
11968 (defun vhdl-try-expand-abbrev (old)
11969 "Try expanding abbreviations from `vhdl-abbrev-list'."
11970 (unless old
11971 (he-init-string (he-dabbrev-beg) (point))
11972 (setq he-expand-list
11973 (let ((abbrev-list vhdl-abbrev-list)
11974 (sel-abbrev-list '()))
11975 (while abbrev-list
11976 (when (or (not (stringp (car abbrev-list)))
11977 (string-match
11978 (concat "^" he-search-string) (car abbrev-list)))
11979 (setq sel-abbrev-list
11980 (cons (car abbrev-list) sel-abbrev-list)))
11981 (setq abbrev-list (cdr abbrev-list)))
11982 (nreverse sel-abbrev-list))))
11983 (while (and he-expand-list
11984 (or (not (stringp (car he-expand-list)))
11985 (he-string-member (car he-expand-list) he-tried-table t)))
11986 ; (equal (car he-expand-list) he-search-string)))
11987 (unless (stringp (car he-expand-list))
11988 (setq vhdl-expand-upper-case (car he-expand-list)))
11989 (setq he-expand-list (cdr he-expand-list)))
11990 (if (null he-expand-list)
11991 (progn (when old (he-reset-string))
11992 nil)
11993 (he-substitute-string
11994 (if vhdl-expand-upper-case
11995 (upcase (car he-expand-list))
11996 (car he-expand-list))
11997 t)
11998 (setq he-expand-list (cdr he-expand-list))
11999 t))
12000
12001 (defun vhdl-he-list-beg ()
12002 "Also looks at the word before `(' in order to better match parenthesized
12003 expressions (e.g. for index ranges of types and signals)."
12004 (save-excursion
12005 (condition-case ()
12006 (progn (backward-up-list 1)
12007 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12008 (error ()))
12009 (point)))
12010
12011 ;; override `he-list-beg' from `hippie-exp'
12012 (unless (and (boundp 'viper-mode) viper-mode)
12013 (defalias 'he-list-beg 'vhdl-he-list-beg))
12014
12015 ;; function for expanding abbrevs and dabbrevs
12016 (defun vhdl-expand-abbrev (arg))
12017 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12018 '(try-expand-dabbrev
12019 try-expand-dabbrev-all-buffers
12020 vhdl-try-expand-abbrev)))
12021
12022 ;; function for expanding parenthesis
12023 (defun vhdl-expand-paren (arg))
12024 (fset 'vhdl-expand-paren (make-hippie-expand-function
12025 '(try-expand-list
12026 try-expand-list-all-buffers)))
12027
12028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12029 ;; Case fixing
12030
12031 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12032 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12033 depending on parameter UPPER-CASE."
12034 (let ((case-replace nil)
12035 (last-update 0))
12036 (vhdl-prepare-search-2
12037 (save-excursion
12038 (goto-char end)
12039 (setq end (point-marker))
12040 (goto-char beg)
12041 (while (re-search-forward word-regexp end t)
12042 (or (vhdl-in-literal)
12043 (if upper-case
12044 (upcase-word -1)
12045 (downcase-word -1)))
12046 (when (and count vhdl-progress-interval (not noninteractive)
12047 (< vhdl-progress-interval
12048 (- (nth 1 (current-time)) last-update)))
12049 (message "Fixing case... (%2d%s)"
12050 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12051 "%")
12052 (setq last-update (nth 1 (current-time)))))
12053 (goto-char end)))))
12054
12055 (defun vhdl-fix-case-region (beg end &optional arg)
12056 "Convert all VHDL words in region to lower or upper case, depending on
12057 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12058 (interactive "r\nP")
12059 (vhdl-fix-case-region-1
12060 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12061 (vhdl-fix-case-region-1
12062 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12063 (vhdl-fix-case-region-1
12064 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12065 (vhdl-fix-case-region-1
12066 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12067 (when vhdl-progress-interval (message "Fixing case...done")))
12068
12069 (defun vhdl-fix-case-buffer ()
12070 "Convert all VHDL words in buffer to lower or upper case, depending on
12071 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12072 (interactive)
12073 (vhdl-fix-case-region (point-min) (point-max)))
12074
12075 (defun vhdl-fix-case-word (&optional arg)
12076 "Convert word after cursor to upper case if necessary."
12077 (interactive "p")
12078 (save-excursion
12079 (when arg (backward-word 1))
12080 (vhdl-prepare-search-1
12081 (when (and vhdl-upper-case-keywords
12082 (looking-at vhdl-keywords-regexp))
12083 (upcase-word 1))
12084 (when (and vhdl-upper-case-types
12085 (looking-at vhdl-types-regexp))
12086 (upcase-word 1))
12087 (when (and vhdl-upper-case-attributes
12088 (looking-at vhdl-attributes-regexp))
12089 (upcase-word 1))
12090 (when (and vhdl-upper-case-enum-values
12091 (looking-at vhdl-enum-values-regexp))
12092 (upcase-word 1)))))
12093
12094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12095 ;; Line handling functions
12096
12097 (defun vhdl-current-line ()
12098 "Return the line number of the line containing point."
12099 (save-restriction
12100 (widen)
12101 (1+ (count-lines (point-min) (point-at-bol)))))
12102
12103 (defun vhdl-line-kill-entire (&optional arg)
12104 "Delete entire line."
12105 (interactive "p")
12106 (beginning-of-line)
12107 (kill-line (or arg 1)))
12108
12109 (defun vhdl-line-kill (&optional arg)
12110 "Kill current line."
12111 (interactive "p")
12112 (vhdl-line-kill-entire arg))
12113
12114 (defun vhdl-line-copy (&optional arg)
12115 "Copy current line."
12116 (interactive "p")
12117 (save-excursion
12118 (let ((position (point-at-bol)))
12119 (forward-line (or arg 1))
12120 (copy-region-as-kill position (point)))))
12121
12122 (defun vhdl-line-yank ()
12123 "Yank entire line."
12124 (interactive)
12125 (beginning-of-line)
12126 (yank))
12127
12128 (defun vhdl-line-expand (&optional prefix-arg)
12129 "Hippie-expand current line."
12130 (interactive "P")
12131 (let ((case-fold-search t) (case-replace nil)
12132 (hippie-expand-try-functions-list
12133 '(try-expand-line try-expand-line-all-buffers)))
12134 (hippie-expand prefix-arg)))
12135
12136 (defun vhdl-line-transpose-next (&optional arg)
12137 "Interchange this line with next line."
12138 (interactive "p")
12139 (forward-line 1)
12140 (transpose-lines (or arg 1))
12141 (forward-line -1))
12142
12143 (defun vhdl-line-transpose-previous (&optional arg)
12144 "Interchange this line with previous line."
12145 (interactive "p")
12146 (forward-line 1)
12147 (transpose-lines (- 0 (or arg 0)))
12148 (forward-line -1))
12149
12150 (defun vhdl-line-open ()
12151 "Open a new line and indent."
12152 (interactive)
12153 (end-of-line -0)
12154 (newline-and-indent))
12155
12156 (defun vhdl-delete-indentation ()
12157 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12158 it works within comments too."
12159 (interactive)
12160 (let ((fill-prefix "-- "))
12161 (delete-indentation)))
12162
12163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12164 ;; Move functions
12165
12166 (defun vhdl-forward-same-indent ()
12167 "Move forward to next line with same indent."
12168 (interactive)
12169 (let ((pos (point))
12170 (indent (current-indentation)))
12171 (beginning-of-line 2)
12172 (while (and (not (eobp))
12173 (or (looking-at "^\\s-*\\(--.*\\)?$")
12174 (> (current-indentation) indent)))
12175 (beginning-of-line 2))
12176 (if (= (current-indentation) indent)
12177 (back-to-indentation)
12178 (message "No following line with same indent found in this block")
12179 (goto-char pos)
12180 nil)))
12181
12182 (defun vhdl-backward-same-indent ()
12183 "Move backward to previous line with same indent."
12184 (interactive)
12185 (let ((pos (point))
12186 (indent (current-indentation)))
12187 (beginning-of-line -0)
12188 (while (and (not (bobp))
12189 (or (looking-at "^\\s-*\\(--.*\\)?$")
12190 (> (current-indentation) indent)))
12191 (beginning-of-line -0))
12192 (if (= (current-indentation) indent)
12193 (back-to-indentation)
12194 (message "No preceding line with same indent found in this block")
12195 (goto-char pos)
12196 nil)))
12197
12198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12199 ;; Statistics
12200
12201 (defun vhdl-statistics-buffer ()
12202 "Get some file statistics."
12203 (interactive)
12204 (let ((no-stats 0)
12205 (no-code-lines 0)
12206 (no-lines (count-lines (point-min) (point-max))))
12207 (save-excursion
12208 ;; count statements
12209 (goto-char (point-min))
12210 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12211 (if (match-string 1)
12212 (goto-char (match-end 1))
12213 (setq no-stats (1+ no-stats))))
12214 ;; count code lines
12215 (goto-char (point-min))
12216 (while (not (eobp))
12217 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12218 (setq no-code-lines (1+ no-code-lines)))
12219 (beginning-of-line 2)))
12220 ;; print results
12221 (message "\n\
12222 File statistics: \"%s\"\n\
12223 ---------------------\n\
12224 # statements : %5d\n\
12225 # code lines : %5d\n\
12226 # total lines : %5d\n\ "
12227 (buffer-file-name) no-stats no-code-lines no-lines)
12228 (unless vhdl-emacs-21 (vhdl-show-messages))))
12229
12230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12231 ;; Help functions
12232
12233 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12234 "Like `re-search-forward', but does not match within literals."
12235 (let (pos)
12236 (save-excursion
12237 (while (and (setq pos (re-search-forward regexp bound noerror count))
12238 (vhdl-in-literal))))
12239 (when pos (goto-char pos))
12240 pos))
12241
12242 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12243 "Like `re-search-backward', but does not match within literals."
12244 (let (pos)
12245 (save-excursion
12246 (while (and (setq pos (re-search-backward regexp bound noerror count))
12247 (vhdl-in-literal))))
12248 (when pos (goto-char pos))
12249 pos))
12250
12251
12252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12253 ;;; Project
12254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12255
12256 (defun vhdl-set-project (name)
12257 "Set current project to NAME."
12258 (interactive
12259 (list (let ((completion-ignore-case t))
12260 (completing-read "Project name: " vhdl-project-alist nil t))))
12261 (cond ((equal name "")
12262 (setq vhdl-project nil)
12263 (message "Current VHDL project: None"))
12264 ((assoc name vhdl-project-alist)
12265 (setq vhdl-project name)
12266 (message "Current VHDL project: \"%s\"" name))
12267 (t
12268 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12269 (vhdl-speedbar-update-current-project))
12270
12271 (defun vhdl-set-default-project ()
12272 "Set current project as default on startup."
12273 (interactive)
12274 (customize-set-variable 'vhdl-project vhdl-project)
12275 (customize-save-customized))
12276
12277 (defun vhdl-toggle-project (name token indent)
12278 "Set current project to NAME or unset if NAME is current project."
12279 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12280
12281 (defun vhdl-export-project (file-name)
12282 "Write project setup for current project."
12283 (interactive
12284 (let ((name (vhdl-resolve-env-variable
12285 (vhdl-replace-string
12286 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12287 (concat (subst-char-in-string
12288 ? ?_ (or (vhdl-project-p)
12289 (error "ERROR: No current project")))
12290 " " (user-login-name))))))
12291 (list (read-file-name
12292 "Write project file: "
12293 (when (file-name-absolute-p name) "") nil nil name))))
12294 (setq file-name (abbreviate-file-name file-name))
12295 (let ((orig-buffer (current-buffer)))
12296 (unless (file-exists-p (file-name-directory file-name))
12297 (make-directory (file-name-directory file-name) t))
12298 (if (not (file-writable-p file-name))
12299 (error "ERROR: File not writable: \"%s\"" file-name)
12300 (set-buffer (find-file-noselect file-name t t))
12301 (erase-buffer)
12302 (insert ";; -*- Emacs-Lisp -*-\n\n"
12303 ";;; " (file-name-nondirectory file-name)
12304 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12305 ";; Project : " vhdl-project "\n"
12306 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12307 (user-login-name) "\n\n\n"
12308 ";; project name\n"
12309 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12310 ";; project setup\n"
12311 "(aput 'vhdl-project-alist vhdl-project\n'")
12312 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12313 (insert ")\n")
12314 (save-buffer)
12315 (kill-buffer (current-buffer))
12316 (set-buffer orig-buffer))))
12317
12318 (defun vhdl-import-project (file-name &optional auto not-make-current)
12319 "Read project setup and set current project."
12320 (interactive
12321 (let ((name (vhdl-resolve-env-variable
12322 (vhdl-replace-string
12323 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12324 (concat "" " " (user-login-name))))))
12325 (list (read-file-name
12326 "Read project file: " (when (file-name-absolute-p name) "") nil t
12327 (file-name-directory name)))))
12328 (when (file-exists-p file-name)
12329 (condition-case ()
12330 (let ((current-project vhdl-project))
12331 (load-file file-name)
12332 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12333 (adelete 'vhdl-project-alist vhdl-project)
12334 (error ""))
12335 (when not-make-current
12336 (setq vhdl-project current-project))
12337 (vhdl-update-mode-menu)
12338 (vhdl-speedbar-refresh)
12339 (unless not-make-current
12340 (message "Current VHDL project: \"%s\"%s"
12341 vhdl-project (if auto " (auto-loaded)" ""))))
12342 (error (vhdl-warning
12343 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12344
12345 (defun vhdl-duplicate-project ()
12346 "Duplicate setup of current project."
12347 (interactive)
12348 (let ((new-name (read-from-minibuffer "New project name: "))
12349 (project-entry (aget vhdl-project-alist vhdl-project t)))
12350 (setq vhdl-project-alist
12351 (append vhdl-project-alist
12352 (list (cons new-name project-entry))))
12353 (vhdl-update-mode-menu)))
12354
12355 (defun vhdl-auto-load-project ()
12356 "Automatically load project setup at startup."
12357 (let ((file-name-list vhdl-project-file-name)
12358 file-list list-length)
12359 (while file-name-list
12360 (setq file-list
12361 (append file-list
12362 (file-expand-wildcards
12363 (vhdl-resolve-env-variable
12364 (vhdl-replace-string
12365 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12366 (concat "\*" " " (user-login-name)))))))
12367 (setq list-length (or list-length (length file-list)))
12368 (setq file-name-list (cdr file-name-list)))
12369 (while file-list
12370 (vhdl-import-project (expand-file-name (car file-list)) t
12371 (not (> list-length 0)))
12372 (setq list-length (1- list-length))
12373 (setq file-list (cdr file-list)))))
12374
12375 ;; automatically load project setup when idle after startup
12376 (when (memq 'startup vhdl-project-auto-load)
12377 (if noninteractive
12378 (vhdl-auto-load-project)
12379 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12380
12381
12382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12383 ;;; Hideshow
12384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12385 ;; (using `hideshow.el')
12386
12387 (defconst vhdl-hs-start-regexp
12388 (concat
12389 "\\(^\\)\\s-*\\("
12390 ;; generic/port clause
12391 "\\(generic\\|port\\)[ \t\n]*(\\|"
12392 ;; component
12393 "component\\>\\|"
12394 ;; component instantiation
12395 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12396 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12397 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12398 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12399 ;; subprogram
12400 "\\(function\\|procedure\\)\\>\\|"
12401 ;; process, block
12402 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12403 ;; configuration declaration
12404 "configuration\\>"
12405 "\\)")
12406 "Regexp to match start of construct to hide.")
12407
12408 (defun vhdl-hs-forward-sexp-func (count)
12409 "Find end of construct to hide (for hideshow). Only searches forward."
12410 (let ((pos (point)))
12411 (vhdl-prepare-search-2
12412 (beginning-of-line)
12413 (cond
12414 ;; generic/port clause
12415 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12416 (goto-char (match-end 0))
12417 (backward-char)
12418 (forward-sexp))
12419 ;; component declaration
12420 ((looking-at "^\\s-*component\\>")
12421 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12422 ;; component instantiation
12423 ((looking-at
12424 (concat
12425 "^\\s-*\\w+\\s-*:[ \t\n]*"
12426 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12427 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12428 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12429 (goto-char (match-end 0))
12430 (backward-char)
12431 (forward-sexp)
12432 (setq pos (point))
12433 (vhdl-forward-syntactic-ws)
12434 (when (looking-at "port\\s-+map[ \t\n]*(")
12435 (goto-char (match-end 0))
12436 (backward-char)
12437 (forward-sexp)
12438 (setq pos (point)))
12439 (goto-char pos))
12440 ;; subprogram declaration/body
12441 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12442 (goto-char (match-end 0))
12443 (vhdl-forward-syntactic-ws)
12444 (when (looking-at "(")
12445 (forward-sexp))
12446 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12447 (vhdl-in-literal)))
12448 ;; subprogram body
12449 (when (match-string 2)
12450 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12451 (backward-word 1)
12452 (vhdl-forward-sexp)))
12453 ;; block (recursive)
12454 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12455 (goto-char (match-end 0))
12456 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12457 (match-beginning 2))
12458 (vhdl-hs-forward-sexp-func count)))
12459 ;; process
12460 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12461 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12462 ;; configuration declaration
12463 ((looking-at "^\\s-*configuration\\>")
12464 (forward-word 4)
12465 (vhdl-forward-sexp))
12466 (t (goto-char pos))))))
12467
12468 (defun vhdl-hideshow-init ()
12469 "Initialize `hideshow'."
12470 (when vhdl-hideshow-menu
12471 (vhdl-hs-minor-mode 1)))
12472
12473 (defun vhdl-hs-minor-mode (&optional arg)
12474 "Toggle hideshow minor mode and update menu bar."
12475 (interactive "P")
12476 (require 'hideshow)
12477 ;; check for hideshow version 5.x
12478 (if (not (boundp 'hs-block-start-mdata-select))
12479 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12480 ;; initialize hideshow
12481 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12482 (setq hs-special-modes-alist
12483 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12484 'vhdl-hs-forward-sexp-func nil)
12485 hs-special-modes-alist)))
12486 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
12487 (if vhdl-hide-all-init
12488 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
12489 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
12490 (hs-minor-mode arg)
12491 (force-mode-line-update))) ; hack to update menu bar
12492
12493
12494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12495 ;;; Font locking
12496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12497 ;; (using `font-lock.el')
12498
12499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12500 ;; Help functions
12501
12502 (defun vhdl-within-translate-off ()
12503 "Return point if within translate-off region, else nil."
12504 (and (save-excursion
12505 (re-search-backward
12506 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12507 (equal "off" (match-string 1))
12508 (point)))
12509
12510 (defun vhdl-start-translate-off (limit)
12511 "Return point before translate-off pragma if before LIMIT, else nil."
12512 (when (re-search-forward
12513 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12514 (match-beginning 0)))
12515
12516 (defun vhdl-end-translate-off (limit)
12517 "Return point after translate-on pragma if before LIMIT, else nil."
12518 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12519
12520 (defun vhdl-match-translate-off (limit)
12521 "Match a translate-off block, setting match-data and returning t, else nil."
12522 (when (< (point) limit)
12523 (let ((start (or (vhdl-within-translate-off)
12524 (vhdl-start-translate-off limit)))
12525 (case-fold-search t))
12526 (when start
12527 (let ((end (or (vhdl-end-translate-off limit) limit)))
12528 (set-match-data (list start end))
12529 (goto-char end))))))
12530
12531 (defun vhdl-font-lock-match-item (limit)
12532 "Match, and move over, any declaration item after point. Adapted from
12533 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12534 (condition-case nil
12535 (save-restriction
12536 (narrow-to-region (point-min) limit)
12537 ;; match item
12538 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12539 (save-match-data
12540 (goto-char (match-end 1))
12541 ;; move to next item
12542 (if (looking-at "\\(\\s-*,\\)")
12543 (goto-char (match-end 1))
12544 (end-of-line) t))))
12545 (error t)))
12546
12547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12548 ;; Syntax definitions
12549
12550 (defconst vhdl-font-lock-syntactic-keywords
12551 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12552 "Mark single quotes as having string quote syntax in 'c' instances.")
12553
12554 (defvar vhdl-font-lock-keywords nil
12555 "Regular expressions to highlight in VHDL Mode.")
12556
12557 (defvar vhdl-font-lock-keywords-0
12558 ;; set in `vhdl-font-lock-init' because dependent on user options
12559 "For consideration as a value of `vhdl-font-lock-keywords'.
12560 This does highlighting of template prompts and directives (pragmas).")
12561
12562 (defvar vhdl-font-lock-keywords-1 nil
12563 ;; set in `vhdl-font-lock-init' because dependent on user options
12564 "For consideration as a value of `vhdl-font-lock-keywords'.
12565 This does highlighting of keywords and standard identifiers.")
12566
12567 (defconst vhdl-font-lock-keywords-2
12568 (list
12569 ;; highlight names of units, subprograms, and components when declared
12570 (list
12571 (concat
12572 "^\\s-*\\("
12573 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12574 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12575 "\\)\\s-+\\(\\w+\\)")
12576 5 'font-lock-function-name-face)
12577
12578 ;; highlight entity names of architectures and configurations
12579 (list
12580 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12581 2 'font-lock-function-name-face)
12582
12583 ;; highlight labels of common constructs
12584 (list
12585 (concat
12586 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12587 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12588 "postponed\\|process\\|"
12589 (when (vhdl-standard-p 'ams) "procedural\\|")
12590 "with\\|while"
12591 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12592 1 'font-lock-function-name-face)
12593
12594 ;; highlight label and component name of component instantiations
12595 (list
12596 (concat
12597 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12598 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12599 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12600
12601 ;; highlight label and instantiated unit of component instantiations
12602 (list
12603 (concat
12604 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12605 "\\(component\\|configuration\\|entity\\)\\s-+"
12606 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12607 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12608 '(5 font-lock-function-name-face nil t)
12609 '(7 font-lock-function-name-face nil t))
12610
12611 ;; highlight names and labels at end of constructs
12612 (list
12613 (concat
12614 "^\\s-*end\\s-+\\(\\("
12615 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12616 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12617 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12618 (when (vhdl-standard-p 'ams) "procedural\\|")
12619 "units"
12620 "\\)\\s-+\\)?\\(\\w*\\)")
12621 5 'font-lock-function-name-face)
12622
12623 ;; highlight labels in exit and next statements
12624 (list
12625 (concat
12626 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12627 3 'font-lock-function-name-face)
12628
12629 ;; highlight entity name in attribute specifications
12630 (list
12631 (concat
12632 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12633 1 'font-lock-function-name-face)
12634
12635 ;; highlight labels in block and component specifications
12636 (list
12637 (concat
12638 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12639 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12640 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12641
12642 ;; highlight names in library clauses
12643 (list "^\\s-*library\\>"
12644 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12645
12646 ;; highlight names in use clauses
12647 (list
12648 (concat
12649 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12650 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12651 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12652 '(7 font-lock-function-name-face nil t))
12653
12654 ;; highlight attribute name in attribute declarations/specifications
12655 (list
12656 (concat
12657 "^\\s-*attribute\\s-+\\(\\w+\\)")
12658 1 'vhdl-font-lock-attribute-face)
12659
12660 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12661 (list
12662 (concat
12663 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12664 3 'font-lock-type-face)
12665
12666 ;; highlight signal/variable/constant declaration names
12667 (list "\\(:[^=]\\)"
12668 '(vhdl-font-lock-match-item
12669 (progn (goto-char (match-beginning 1))
12670 (skip-syntax-backward " ")
12671 (skip-syntax-backward "w_")
12672 (skip-syntax-backward " ")
12673 (while (= (preceding-char) ?,)
12674 (backward-char 1)
12675 (skip-syntax-backward " ")
12676 (skip-syntax-backward "w_")
12677 (skip-syntax-backward " ")))
12678 ; (skip-chars-backward "^-(\n\";")
12679 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12680
12681 ;; highlight formal parameters in component instantiations and subprogram
12682 ;; calls
12683 (list "\\(=>\\)"
12684 '(vhdl-font-lock-match-item
12685 (progn (goto-char (match-beginning 1))
12686 (skip-syntax-backward " ")
12687 (while (= (preceding-char) ?\)) (backward-sexp))
12688 (skip-syntax-backward "w_")
12689 (skip-syntax-backward " ")
12690 (when (memq (preceding-char) '(?n ?N ?|))
12691 (goto-char (point-max))))
12692 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12693
12694 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12695 ;; variables
12696 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12697 '(vhdl-font-lock-match-item
12698 (progn (goto-char (match-end 1)) (match-beginning 2))
12699 nil (1 font-lock-variable-name-face)))
12700 )
12701 "For consideration as a value of `vhdl-font-lock-keywords'.
12702 This does context sensitive highlighting of names and labels.")
12703
12704 (defvar vhdl-font-lock-keywords-3 nil
12705 ;; set in `vhdl-font-lock-init' because dependent on user options
12706 "For consideration as a value of `vhdl-font-lock-keywords'.
12707 This does highlighting of words with special syntax.")
12708
12709 (defvar vhdl-font-lock-keywords-4 nil
12710 ;; set in `vhdl-font-lock-init' because dependent on user options
12711 "For consideration as a value of `vhdl-font-lock-keywords'.
12712 This does highlighting of additional reserved words.")
12713
12714 (defconst vhdl-font-lock-keywords-5
12715 ;; background highlight translate-off regions
12716 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12717 "For consideration as a value of `vhdl-font-lock-keywords'.
12718 This does background highlighting of translate-off regions.")
12719
12720 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12721 ;; Font and color definitions
12722
12723 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12724 "Face name to use for prompts.")
12725
12726 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12727 "Face name to use for standardized attributes.")
12728
12729 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12730 "Face name to use for standardized enumeration values.")
12731
12732 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12733 "Face name to use for standardized functions and packages.")
12734
12735 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12736 "Face name to use for directives.")
12737
12738 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12739 "Face name to use for additional reserved words.")
12740
12741 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12742 "Face name to use for translate-off regions.")
12743
12744 ;; face names to use for words with special syntax.
12745 (let ((syntax-alist vhdl-special-syntax-alist)
12746 name)
12747 (while syntax-alist
12748 (setq name (vhdl-function-name
12749 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12750 (eval `(defvar ,name ',name
12751 ,(concat "Face name to use for "
12752 (nth 0 (car syntax-alist)) ".")))
12753 (setq syntax-alist (cdr syntax-alist))))
12754
12755 (defgroup vhdl-highlight-faces nil
12756 "Faces for highlighting."
12757 :group 'vhdl-highlight)
12758
12759 ;; add faces used from `font-lock'
12760 (custom-add-to-group
12761 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12762 (custom-add-to-group
12763 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12764 (custom-add-to-group
12765 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12766 (custom-add-to-group
12767 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12768 (custom-add-to-group
12769 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12770 (custom-add-to-group
12771 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12772
12773 (defface vhdl-font-lock-prompt-face
12774 '((((min-colors 88) (class color) (background light))
12775 (:foreground "Red1" :bold t))
12776 (((class color) (background light)) (:foreground "Red" :bold t))
12777 (((class color) (background dark)) (:foreground "Pink" :bold t))
12778 (t (:inverse-video t)))
12779 "Font lock mode face used to highlight prompts."
12780 :group 'vhdl-highlight-faces)
12781
12782 (defface vhdl-font-lock-attribute-face
12783 '((((class color) (background light)) (:foreground "Orchid"))
12784 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12785 (t (:italic t :bold t)))
12786 "Font lock mode face used to highlight standardized attributes."
12787 :group 'vhdl-highlight-faces)
12788
12789 (defface vhdl-font-lock-enumvalue-face
12790 '((((class color) (background light)) (:foreground "SaddleBrown"))
12791 (((class color) (background dark)) (:foreground "BurlyWood"))
12792 (t (:italic t :bold t)))
12793 "Font lock mode face used to highlight standardized enumeration values."
12794 :group 'vhdl-highlight-faces)
12795
12796 (defface vhdl-font-lock-function-face
12797 '((((class color) (background light)) (:foreground "Cyan4"))
12798 (((class color) (background dark)) (:foreground "Orchid1"))
12799 (t (:italic t :bold t)))
12800 "Font lock mode face used to highlight standardized functions and packages."
12801 :group 'vhdl-highlight-faces)
12802
12803 (defface vhdl-font-lock-directive-face
12804 '((((class color) (background light)) (:foreground "CadetBlue"))
12805 (((class color) (background dark)) (:foreground "Aquamarine"))
12806 (t (:italic t :bold t)))
12807 "Font lock mode face used to highlight directives."
12808 :group 'vhdl-highlight-faces)
12809
12810 (defface vhdl-font-lock-reserved-words-face
12811 '((((class color) (background light)) (:foreground "Orange" :bold t))
12812 (((min-colors 88) (class color) (background dark))
12813 (:foreground "Yellow1" :bold t))
12814 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12815 (t ()))
12816 "Font lock mode face used to highlight additional reserved words."
12817 :group 'vhdl-highlight-faces)
12818
12819 (defface vhdl-font-lock-translate-off-face
12820 '((((class color) (background light)) (:background "LightGray"))
12821 (((class color) (background dark)) (:background "DimGray"))
12822 (t ()))
12823 "Font lock mode face used to background highlight translate-off regions."
12824 :group 'vhdl-highlight-faces)
12825
12826 ;; font lock mode faces used to highlight words with special syntax.
12827 (let ((syntax-alist vhdl-special-syntax-alist))
12828 (while syntax-alist
12829 (eval `(defface ,(vhdl-function-name
12830 "vhdl-font-lock" (caar syntax-alist) "face")
12831 '((((class color) (background light))
12832 (:foreground ,(nth 2 (car syntax-alist))))
12833 (((class color) (background dark))
12834 (:foreground ,(nth 3 (car syntax-alist))))
12835 (t ()))
12836 ,(concat "Font lock mode face used to highlight "
12837 (nth 0 (car syntax-alist)) ".")
12838 :group 'vhdl-highlight-faces))
12839 (setq syntax-alist (cdr syntax-alist))))
12840
12841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12842 ;; Font lock initialization
12843
12844 (defun vhdl-font-lock-init ()
12845 "Initialize fontification."
12846 ;; highlight template prompts and directives
12847 (setq vhdl-font-lock-keywords-0
12848 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12849 vhdl-template-prompt-syntax ">\\)")
12850 2 'vhdl-font-lock-prompt-face t)
12851 (list (concat "--\\s-*"
12852 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12853 2 'vhdl-font-lock-directive-face t)
12854 ;; highlight c-preprocessor directives
12855 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12856 '(1 font-lock-builtin-face)
12857 '(3 font-lock-variable-name-face nil t))))
12858 ;; highlight keywords and standardized types, attributes, enumeration
12859 ;; values, and subprograms
12860 (setq vhdl-font-lock-keywords-1
12861 (list
12862 (list (concat "'" vhdl-attributes-regexp)
12863 1 'vhdl-font-lock-attribute-face)
12864 (list vhdl-types-regexp 1 'font-lock-type-face)
12865 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12866 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12867 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12868 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12869 ;; highlight words with special syntax.
12870 (setq vhdl-font-lock-keywords-3
12871 (let ((syntax-alist vhdl-special-syntax-alist)
12872 keywords)
12873 (while syntax-alist
12874 (setq keywords
12875 (cons
12876 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12877 (vhdl-function-name
12878 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12879 keywords))
12880 (setq syntax-alist (cdr syntax-alist)))
12881 keywords))
12882 ;; highlight additional reserved words
12883 (setq vhdl-font-lock-keywords-4
12884 (list (list vhdl-reserved-words-regexp 1
12885 'vhdl-font-lock-reserved-words-face)))
12886 ;; highlight everything together
12887 (setq vhdl-font-lock-keywords
12888 (append
12889 vhdl-font-lock-keywords-0
12890 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12891 (when (or vhdl-highlight-forbidden-words
12892 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12893 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12894 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12895 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12896
12897 ;; initialize fontification for VHDL Mode
12898 (vhdl-font-lock-init)
12899
12900 (defun vhdl-fontify-buffer ()
12901 "Re-initialize fontification and fontify buffer."
12902 (interactive)
12903 (setq font-lock-defaults
12904 `(vhdl-font-lock-keywords
12905 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12906 beginning-of-line))
12907 (when (fboundp 'font-lock-unset-defaults)
12908 (font-lock-unset-defaults)) ; not implemented in XEmacs
12909 (font-lock-set-defaults)
12910 (font-lock-mode nil)
12911 (font-lock-mode t))
12912
12913 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12914 ;; Initialization for postscript printing
12915
12916 (defun vhdl-ps-print-settings ()
12917 "Initialize custom face and page settings for postscript printing."
12918 ;; define custom face settings
12919 (unless (or (not vhdl-print-customize-faces)
12920 ps-print-color-p)
12921 (set (make-local-variable 'ps-bold-faces)
12922 '(font-lock-keyword-face
12923 font-lock-type-face
12924 vhdl-font-lock-attribute-face
12925 vhdl-font-lock-enumvalue-face
12926 vhdl-font-lock-directive-face))
12927 (set (make-local-variable 'ps-italic-faces)
12928 '(font-lock-comment-face
12929 font-lock-function-name-face
12930 font-lock-type-face
12931 vhdl-font-lock-attribute-face
12932 vhdl-font-lock-enumvalue-face
12933 vhdl-font-lock-directive-face))
12934 (set (make-local-variable 'ps-underlined-faces)
12935 '(font-lock-string-face))
12936 (setq ps-always-build-face-reference t))
12937 ;; define page settings, so that a line containing 79 characters (default)
12938 ;; fits into one column
12939 (when vhdl-print-two-column
12940 (set (make-local-variable 'ps-landscape-mode) t)
12941 (set (make-local-variable 'ps-number-of-columns) 2)
12942 (set (make-local-variable 'ps-font-size) 7.0)
12943 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12944 (set (make-local-variable 'ps-header-font-size) 9.0)
12945 (set (make-local-variable 'ps-header-offset) 12.0)
12946 (when (eq ps-paper-type 'letter)
12947 (set (make-local-variable 'ps-inter-column) 40.0)
12948 (set (make-local-variable 'ps-left-margin) 40.0)
12949 (set (make-local-variable 'ps-right-margin) 40.0))))
12950
12951 (defun vhdl-ps-print-init ()
12952 "Initialize postscript printing."
12953 (if (featurep 'xemacs)
12954 (when (boundp 'ps-print-color-p)
12955 (vhdl-ps-print-settings))
12956 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
12957 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
12958
12959
12960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12961 ;;; Hierarchy browser (using `speedbar.el')
12962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12963 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12964 ;; directory by using the speedbar.
12965
12966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12967 ;; Variables
12968
12969 (defvar vhdl-entity-alist nil
12970 "Cache with entities and corresponding architectures for each
12971 project/directory.")
12972 ;; structure: (parenthesised expression means list of such entries)
12973 ;; (cache-key
12974 ;; (ent-key ent-name ent-file ent-line
12975 ;; (arch-key arch-name arch-file arch-line
12976 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12977 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12978 ;; (lib-name pack-key))
12979 ;; mra-key (lib-name pack-key))
12980
12981 (defvar vhdl-config-alist nil
12982 "Cache with configurations for each project/directory.")
12983 ;; structure: (parenthesised expression means list of such entries)
12984 ;; (cache-key
12985 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12986 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12987 ;; inst-conf-key inst-lib-key)
12988 ;; (lib-name pack-key)))
12989
12990 (defvar vhdl-package-alist nil
12991 "Cache with packages for each project/directory.")
12992 ;; structure: (parenthesised expression means list of such entries)
12993 ;; (cache-key
12994 ;; (pack-key pack-name pack-file pack-line
12995 ;; (comp-key comp-name comp-file comp-line)
12996 ;; (func-key func-name func-file func-line)
12997 ;; (lib-name pack-key)
12998 ;; pack-body-file pack-body-line
12999 ;; (func-key func-name func-body-file func-body-line)
13000 ;; (lib-name pack-key)))
13001
13002 (defvar vhdl-ent-inst-alist nil
13003 "Cache with instantiated entities for each project/directory.")
13004 ;; structure: (parenthesised expression means list of such entries)
13005 ;; (cache-key (inst-ent-key))
13006
13007 (defvar vhdl-file-alist nil
13008 "Cache with design units in each file for each project/directory.")
13009 ;; structure: (parenthesised expression means list of such entries)
13010 ;; (cache-key
13011 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13012 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13013
13014 (defvar vhdl-directory-alist nil
13015 "Cache with source directories for each project.")
13016 ;; structure: (parenthesised expression means list of such entries)
13017 ;; (cache-key (directory))
13018
13019 (defvar vhdl-speedbar-shown-unit-alist nil
13020 "Alist of design units simultaneously open in the current speedbar for each
13021 directory and project.")
13022
13023 (defvar vhdl-speedbar-shown-project-list nil
13024 "List of projects simultaneously open in the current speedbar.")
13025
13026 (defvar vhdl-updated-project-list nil
13027 "List of projects and directories with updated files.")
13028
13029 (defvar vhdl-modified-file-list nil
13030 "List of modified files to be rescanned for hierarchy updating.")
13031
13032 (defvar vhdl-speedbar-hierarchy-depth 0
13033 "Depth of instantiation hierarchy to display.")
13034
13035 (defvar vhdl-speedbar-show-projects nil
13036 "Non-nil means project hierarchy is displayed in speedbar, directory
13037 hierarchy otherwise.")
13038
13039 (defun vhdl-get-end-of-unit ()
13040 "Return position of end of current unit."
13041 (let ((pos (point)))
13042 (save-excursion
13043 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13044 (save-excursion
13045 (goto-char (match-beginning 0))
13046 (vhdl-backward-syntactic-ws)
13047 (and (/= (preceding-char) ?\;) (not (bobp))))))
13048 (re-search-backward "^[ \t]*end\\>" pos 1)
13049 (point))))
13050
13051 (defun vhdl-match-string-downcase (num &optional string)
13052 "Like `match-string-no-properties' with down-casing."
13053 (let ((match (match-string-no-properties num string)))
13054 (and match (downcase match))))
13055
13056
13057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13058 ;; Scan functions
13059
13060 (defun vhdl-scan-context-clause ()
13061 "Scan the context clause that preceeds a design unit."
13062 (let (lib-alist)
13063 (save-excursion
13064 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13065 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13066 (equal "USE" (upcase (match-string 1))))
13067 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13068 (setq lib-alist (cons (cons (match-string-no-properties 1)
13069 (vhdl-match-string-downcase 2))
13070 lib-alist))))))
13071 lib-alist))
13072
13073 (defun vhdl-scan-directory-contents (name &optional project update num-string
13074 non-final)
13075 "Scan contents of VHDL files in directory or file pattern NAME."
13076 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13077 ; (unless (file-directory-p (match-string 1 name))
13078 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13079 (let* ((dir-name (match-string 1 name))
13080 (file-pattern (match-string 2 name))
13081 (is-directory (= 0 (length file-pattern)))
13082 (file-list
13083 (if update
13084 (list name)
13085 (if is-directory
13086 (vhdl-get-source-files t dir-name)
13087 (vhdl-directory-files
13088 dir-name t (wildcard-to-regexp file-pattern)))))
13089 (key (or project dir-name))
13090 (file-exclude-regexp
13091 (or (nth 3 (aget vhdl-project-alist project)) ""))
13092 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13093 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13094 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13095 ent-alist conf-alist pack-alist ent-inst-list file-alist
13096 tmp-list tmp-entry no-files files-exist big-files)
13097 (when (or project update)
13098 (setq ent-alist (aget vhdl-entity-alist key t)
13099 conf-alist (aget vhdl-config-alist key t)
13100 pack-alist (aget vhdl-package-alist key t)
13101 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13102 file-alist (aget vhdl-file-alist key t)))
13103 (when (and (not is-directory) (null file-list))
13104 (message "No such file: \"%s\"" name))
13105 (setq files-exist file-list)
13106 (when file-list
13107 (setq no-files (length file-list))
13108 (message "Scanning %s %s\"%s\"..."
13109 (if is-directory "directory" "files") (or num-string "") name)
13110 ;; exclude files
13111 (unless (equal file-exclude-regexp "")
13112 (let ((case-fold-search nil)
13113 file-tmp-list)
13114 (while file-list
13115 (unless (string-match file-exclude-regexp (car file-list))
13116 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13117 (setq file-list (cdr file-list)))
13118 (setq file-list (nreverse file-tmp-list))))
13119 ;; do for all files
13120 (while file-list
13121 (unless noninteractive
13122 (message "Scanning %s %s\"%s\"... (%2d%s)"
13123 (if is-directory "directory" "files")
13124 (or num-string "") name
13125 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13126 (let ((file-name (abbreviate-file-name (car file-list)))
13127 ent-list arch-list arch-ent-list conf-list
13128 pack-list pack-body-list inst-list inst-ent-list)
13129 ;; scan file
13130 (vhdl-visit-file
13131 file-name nil
13132 (vhdl-prepare-search-2
13133 (save-excursion
13134 ;; scan for design units
13135 (if (and limit-design-file-size
13136 (< limit-design-file-size (buffer-size)))
13137 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13138 (setq big-files t))
13139 ;; scan for entities
13140 (goto-char (point-min))
13141 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13142 (let* ((ent-name (match-string-no-properties 1))
13143 (ent-key (downcase ent-name))
13144 (ent-entry (aget ent-alist ent-key t))
13145 (lib-alist (vhdl-scan-context-clause)))
13146 (if (nth 1 ent-entry)
13147 (vhdl-warning-when-idle
13148 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13149 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13150 file-name (vhdl-current-line))
13151 (setq ent-list (cons ent-key ent-list))
13152 (aput 'ent-alist ent-key
13153 (list ent-name file-name (vhdl-current-line)
13154 (nth 3 ent-entry) (nth 4 ent-entry)
13155 lib-alist)))))
13156 ;; scan for architectures
13157 (goto-char (point-min))
13158 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13159 (let* ((arch-name (match-string-no-properties 1))
13160 (arch-key (downcase arch-name))
13161 (ent-name (match-string-no-properties 2))
13162 (ent-key (downcase ent-name))
13163 (ent-entry (aget ent-alist ent-key t))
13164 (arch-alist (nth 3 ent-entry))
13165 (arch-entry (aget arch-alist arch-key t))
13166 (lib-arch-alist (vhdl-scan-context-clause)))
13167 (if arch-entry
13168 (vhdl-warning-when-idle
13169 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13170 arch-name ent-name (nth 1 arch-entry)
13171 (nth 2 arch-entry) file-name (vhdl-current-line))
13172 (setq arch-list (cons arch-key arch-list)
13173 arch-ent-list (cons ent-key arch-ent-list))
13174 (aput 'arch-alist arch-key
13175 (list arch-name file-name (vhdl-current-line) nil
13176 lib-arch-alist))
13177 (aput 'ent-alist ent-key
13178 (list (or (nth 0 ent-entry) ent-name)
13179 (nth 1 ent-entry) (nth 2 ent-entry)
13180 (vhdl-sort-alist arch-alist)
13181 arch-key (nth 5 ent-entry))))))
13182 ;; scan for configurations
13183 (goto-char (point-min))
13184 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13185 (let* ((conf-name (match-string-no-properties 1))
13186 (conf-key (downcase conf-name))
13187 (conf-entry (aget conf-alist conf-key t))
13188 (ent-name (match-string-no-properties 2))
13189 (ent-key (downcase ent-name))
13190 (lib-alist (vhdl-scan-context-clause))
13191 (conf-line (vhdl-current-line))
13192 (end-of-unit (vhdl-get-end-of-unit))
13193 arch-key comp-conf-list inst-key-list
13194 inst-comp-key inst-ent-key inst-arch-key
13195 inst-conf-key inst-lib-key)
13196 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13197 (setq arch-key (vhdl-match-string-downcase 1)))
13198 (if conf-entry
13199 (vhdl-warning-when-idle
13200 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13201 conf-name ent-name (nth 1 conf-entry)
13202 (nth 2 conf-entry) file-name conf-line)
13203 (setq conf-list (cons conf-key conf-list))
13204 ;; scan for subconfigurations and subentities
13205 (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)
13206 (setq inst-comp-key (vhdl-match-string-downcase 3)
13207 inst-key-list (split-string
13208 (vhdl-match-string-downcase 1)
13209 "[ \t\n]*,[ \t\n]*"))
13210 (vhdl-forward-syntactic-ws)
13211 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13212 (setq
13213 inst-lib-key (vhdl-match-string-downcase 3)
13214 inst-ent-key (and (match-string 2)
13215 (vhdl-match-string-downcase 4))
13216 inst-arch-key (and (match-string 2)
13217 (vhdl-match-string-downcase 6))
13218 inst-conf-key (and (not (match-string 2))
13219 (vhdl-match-string-downcase 4)))
13220 (while inst-key-list
13221 (setq comp-conf-list
13222 (cons (list (car inst-key-list)
13223 inst-comp-key inst-ent-key
13224 inst-arch-key inst-conf-key
13225 inst-lib-key)
13226 comp-conf-list))
13227 (setq inst-key-list (cdr inst-key-list)))))
13228 (aput 'conf-alist conf-key
13229 (list conf-name file-name conf-line ent-key
13230 arch-key comp-conf-list lib-alist)))))
13231 ;; scan for packages
13232 (goto-char (point-min))
13233 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13234 (let* ((pack-name (match-string-no-properties 2))
13235 (pack-key (downcase pack-name))
13236 (is-body (match-string-no-properties 1))
13237 (pack-entry (aget pack-alist pack-key t))
13238 (pack-line (vhdl-current-line))
13239 (end-of-unit (vhdl-get-end-of-unit))
13240 comp-name func-name comp-alist func-alist lib-alist)
13241 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13242 (vhdl-warning-when-idle
13243 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13244 (if is-body " body" "") pack-name
13245 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13246 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13247 file-name (vhdl-current-line))
13248 ;; scan for context clauses
13249 (setq lib-alist (vhdl-scan-context-clause))
13250 ;; scan for component and subprogram declarations/bodies
13251 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13252 (if (equal (upcase (match-string 1)) "COMPONENT")
13253 (setq comp-name (match-string-no-properties 2)
13254 comp-alist
13255 (cons (list (downcase comp-name) comp-name
13256 file-name (vhdl-current-line))
13257 comp-alist))
13258 (setq func-name (match-string-no-properties 2)
13259 func-alist
13260 (cons (list (downcase func-name) func-name
13261 file-name (vhdl-current-line))
13262 func-alist))))
13263 (setq func-alist (nreverse func-alist))
13264 (setq comp-alist (nreverse comp-alist))
13265 (if is-body
13266 (setq pack-body-list (cons pack-key pack-body-list))
13267 (setq pack-list (cons pack-key pack-list)))
13268 (aput
13269 'pack-alist pack-key
13270 (if is-body
13271 (list (or (nth 0 pack-entry) pack-name)
13272 (nth 1 pack-entry) (nth 2 pack-entry)
13273 (nth 3 pack-entry) (nth 4 pack-entry)
13274 (nth 5 pack-entry)
13275 file-name pack-line func-alist lib-alist)
13276 (list pack-name file-name pack-line
13277 comp-alist func-alist lib-alist
13278 (nth 6 pack-entry) (nth 7 pack-entry)
13279 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13280 ;; scan for hierarchy
13281 (if (and limit-hier-file-size
13282 (< limit-hier-file-size (buffer-size)))
13283 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13284 (setq big-files t))
13285 ;; scan for architectures
13286 (goto-char (point-min))
13287 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13288 (let* ((ent-name (match-string-no-properties 2))
13289 (ent-key (downcase ent-name))
13290 (arch-name (match-string-no-properties 1))
13291 (arch-key (downcase arch-name))
13292 (ent-entry (aget ent-alist ent-key t))
13293 (arch-alist (nth 3 ent-entry))
13294 (arch-entry (aget arch-alist arch-key t))
13295 (beg-of-unit (point))
13296 (end-of-unit (vhdl-get-end-of-unit))
13297 (inst-no 0)
13298 inst-alist inst-path)
13299 ;; scan for contained instantiations
13300 (while (and (re-search-forward
13301 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13302 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13303 "component[ \t\n]+\\(\\w+\\)\\|"
13304 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13305 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13306 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13307 (or (not limit-hier-inst-no)
13308 (<= (setq inst-no (1+ inst-no))
13309 limit-hier-inst-no)))
13310 (cond
13311 ;; block/generate beginning found
13312 ((match-string 14)
13313 (setq inst-path
13314 (cons (match-string-no-properties 1) inst-path)))
13315 ;; block/generate end found
13316 ((match-string 16)
13317 (setq inst-path (cdr inst-path)))
13318 ;; instantiation found
13319 (t
13320 (let* ((inst-name (match-string-no-properties 1))
13321 (inst-key (downcase inst-name))
13322 (inst-comp-name
13323 (or (match-string-no-properties 3)
13324 (match-string-no-properties 6)))
13325 (inst-ent-key
13326 (or (and (match-string 8)
13327 (vhdl-match-string-downcase 11))
13328 (and inst-comp-name
13329 (downcase inst-comp-name))))
13330 (inst-arch-key (vhdl-match-string-downcase 13))
13331 (inst-conf-key
13332 (and (not (match-string 8))
13333 (vhdl-match-string-downcase 11)))
13334 (inst-lib-key (vhdl-match-string-downcase 10)))
13335 (goto-char (match-end 1))
13336 (setq inst-list (cons inst-key inst-list)
13337 inst-ent-list
13338 (cons inst-ent-key inst-ent-list))
13339 (setq inst-alist
13340 (append
13341 inst-alist
13342 (list (list inst-key inst-name file-name
13343 (vhdl-current-line) inst-comp-name
13344 inst-ent-key inst-arch-key
13345 inst-conf-key inst-lib-key
13346 (reverse inst-path)))))))))
13347 ;; scan for contained configuration specifications
13348 (goto-char beg-of-unit)
13349 (while (re-search-forward
13350 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13351 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13352 (let* ((inst-comp-name (match-string-no-properties 3))
13353 (inst-ent-key
13354 (and (match-string 6)
13355 (vhdl-match-string-downcase 9)))
13356 (inst-arch-key (vhdl-match-string-downcase 11))
13357 (inst-conf-key
13358 (and (not (match-string 6))
13359 (vhdl-match-string-downcase 9)))
13360 (inst-lib-key (vhdl-match-string-downcase 8))
13361 (inst-key-list
13362 (split-string (vhdl-match-string-downcase 1)
13363 "[ \t\n]*,[ \t\n]*"))
13364 (tmp-inst-alist inst-alist)
13365 inst-entry)
13366 (while tmp-inst-alist
13367 (when (and (or (equal "all" (car inst-key-list))
13368 (member (nth 0 (car tmp-inst-alist))
13369 inst-key-list))
13370 (equal
13371 (downcase
13372 (or (nth 4 (car tmp-inst-alist)) ""))
13373 (downcase inst-comp-name)))
13374 (setq inst-entry (car tmp-inst-alist))
13375 (setq inst-ent-list
13376 (cons (or inst-ent-key (nth 5 inst-entry))
13377 (vhdl-delete
13378 (nth 5 inst-entry) inst-ent-list)))
13379 (setq inst-entry
13380 (list (nth 0 inst-entry) (nth 1 inst-entry)
13381 (nth 2 inst-entry) (nth 3 inst-entry)
13382 (nth 4 inst-entry)
13383 (or inst-ent-key (nth 5 inst-entry))
13384 (or inst-arch-key (nth 6 inst-entry))
13385 inst-conf-key inst-lib-key))
13386 (setcar tmp-inst-alist inst-entry))
13387 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13388 ;; save in cache
13389 (aput 'arch-alist arch-key
13390 (list (nth 0 arch-entry) (nth 1 arch-entry)
13391 (nth 2 arch-entry) inst-alist
13392 (nth 4 arch-entry)))
13393 (aput 'ent-alist ent-key
13394 (list (nth 0 ent-entry) (nth 1 ent-entry)
13395 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13396 (nth 4 ent-entry) (nth 5 ent-entry)))
13397 (when (and limit-hier-inst-no
13398 (> inst-no limit-hier-inst-no))
13399 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13400 (setq big-files t))
13401 (goto-char end-of-unit))))
13402 ;; remember design units for this file
13403 (aput 'file-alist file-name
13404 (list ent-list arch-list arch-ent-list conf-list
13405 pack-list pack-body-list inst-list inst-ent-list))
13406 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13407 (setq file-list (cdr file-list))))
13408 (when (or (and (not project) files-exist)
13409 (and project (not non-final)))
13410 ;; consistency checks:
13411 ;; check whether each architecture has a corresponding entity
13412 (setq tmp-list ent-alist)
13413 (while tmp-list
13414 (when (null (nth 2 (car tmp-list)))
13415 (setq tmp-entry (car (nth 4 (car tmp-list))))
13416 (vhdl-warning-when-idle
13417 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13418 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13419 (nth 3 tmp-entry)))
13420 (setq tmp-list (cdr tmp-list)))
13421 ;; check whether configuration has a corresponding entity/architecture
13422 (setq tmp-list conf-alist)
13423 (while tmp-list
13424 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13425 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13426 (setq tmp-entry (car tmp-list))
13427 (vhdl-warning-when-idle
13428 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13429 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13430 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13431 (setq tmp-entry (car tmp-list))
13432 (vhdl-warning-when-idle
13433 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13434 (nth 1 tmp-entry) (nth 4 tmp-entry)
13435 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13436 (setq tmp-list (cdr tmp-list)))
13437 ;; check whether each package body has a package declaration
13438 (setq tmp-list pack-alist)
13439 (while tmp-list
13440 (when (null (nth 2 (car tmp-list)))
13441 (setq tmp-entry (car tmp-list))
13442 (vhdl-warning-when-idle
13443 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13444 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13445 (setq tmp-list (cdr tmp-list)))
13446 ;; sort lists
13447 (setq ent-alist (vhdl-sort-alist ent-alist))
13448 (setq conf-alist (vhdl-sort-alist conf-alist))
13449 (setq pack-alist (vhdl-sort-alist pack-alist))
13450 ;; remember updated directory/project
13451 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13452 ;; clear directory alists
13453 (unless project
13454 (adelete 'vhdl-entity-alist key)
13455 (adelete 'vhdl-config-alist key)
13456 (adelete 'vhdl-package-alist key)
13457 (adelete 'vhdl-ent-inst-alist key)
13458 (adelete 'vhdl-file-alist key))
13459 ;; put directory contents into cache
13460 (aput 'vhdl-entity-alist key ent-alist)
13461 (aput 'vhdl-config-alist key conf-alist)
13462 (aput 'vhdl-package-alist key pack-alist)
13463 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13464 (aput 'vhdl-file-alist key file-alist)
13465 ;; final messages
13466 (message "Scanning %s %s\"%s\"...done"
13467 (if is-directory "directory" "files") (or num-string "") name)
13468 (unless project (message "Scanning directory...done"))
13469 (when big-files
13470 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13471 ;; save cache when scanned non-interactively
13472 (when (or (not project) (not non-final))
13473 (when (and noninteractive vhdl-speedbar-save-cache)
13474 (vhdl-save-cache key)))
13475 t))
13476
13477 (defun vhdl-scan-project-contents (project)
13478 "Scan the contents of all VHDL files found in the directories and files
13479 of PROJECT."
13480 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13481 (default-dir (vhdl-resolve-env-variable
13482 (nth 1 (aget vhdl-project-alist project))))
13483 (file-exclude-regexp
13484 (or (nth 3 (aget vhdl-project-alist project)) ""))
13485 dir-list-tmp dir dir-name num-dir act-dir recursive)
13486 ;; clear project alists
13487 (adelete 'vhdl-entity-alist project)
13488 (adelete 'vhdl-config-alist project)
13489 (adelete 'vhdl-package-alist project)
13490 (adelete 'vhdl-ent-inst-alist project)
13491 (adelete 'vhdl-file-alist project)
13492 ;; expand directory names by default-directory
13493 (message "Collecting source files...")
13494 (while dir-list
13495 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13496 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13497 (setq recursive (match-string 1 dir)
13498 dir-name (match-string 3 dir))
13499 (setq dir-list-tmp
13500 (cons (concat recursive
13501 (if (file-name-absolute-p dir-name) "" default-dir)
13502 dir-name)
13503 dir-list-tmp))
13504 (setq dir-list (cdr dir-list)))
13505 ;; resolve path wildcards
13506 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13507 ;; expand directories
13508 (while dir-list-tmp
13509 (setq dir (car dir-list-tmp))
13510 ;; get subdirectories
13511 (if (string-match "-r \\(.*[/\\]\\)" dir)
13512 (setq dir-list (append dir-list (vhdl-get-subdirs
13513 (match-string 1 dir))))
13514 (setq dir-list (append dir-list (list dir))))
13515 (setq dir-list-tmp (cdr dir-list-tmp)))
13516 ;; exclude files
13517 (unless (equal file-exclude-regexp "")
13518 (let ((case-fold-search nil))
13519 (while dir-list
13520 (unless (string-match file-exclude-regexp (car dir-list))
13521 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13522 (setq dir-list (cdr dir-list)))
13523 (setq dir-list (nreverse dir-list-tmp))))
13524 (message "Collecting source files...done")
13525 ;; scan for design units for each directory in DIR-LIST
13526 (setq dir-list-tmp nil
13527 num-dir (length dir-list)
13528 act-dir 1)
13529 (while dir-list
13530 (setq dir-name (abbreviate-file-name
13531 (expand-file-name (car dir-list))))
13532 (vhdl-scan-directory-contents dir-name project nil
13533 (format "(%s/%s) " act-dir num-dir)
13534 (cdr dir-list))
13535 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13536 (setq dir-list (cdr dir-list)
13537 act-dir (1+ act-dir)))
13538 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13539 (message "Scanning project \"%s\"...done" project)))
13540
13541 (defun vhdl-update-file-contents (file-name)
13542 "Update hierarchy information by contents of current buffer."
13543 (setq file-name (abbreviate-file-name file-name))
13544 (let* ((dir-name (file-name-directory file-name))
13545 (directory-alist vhdl-directory-alist)
13546 updated)
13547 (while directory-alist
13548 (when (member dir-name (nth 1 (car directory-alist)))
13549 (let* ((vhdl-project (nth 0 (car directory-alist)))
13550 (project (vhdl-project-p))
13551 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13552 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13553 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13554 (ent-inst-list (car (aget vhdl-ent-inst-alist
13555 (or project dir-name) t)))
13556 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13557 (file-entry (aget file-alist file-name t))
13558 (ent-list (nth 0 file-entry))
13559 (arch-list (nth 1 file-entry))
13560 (arch-ent-list (nth 2 file-entry))
13561 (conf-list (nth 3 file-entry))
13562 (pack-list (nth 4 file-entry))
13563 (pack-body-list (nth 5 file-entry))
13564 (inst-ent-list (nth 7 file-entry))
13565 (cache-key (or project dir-name))
13566 arch-alist key ent-key entry)
13567 ;; delete design units previously contained in this file:
13568 ;; entities
13569 (while ent-list
13570 (setq key (car ent-list)
13571 entry (aget ent-alist key t))
13572 (when (equal file-name (nth 1 entry))
13573 (if (nth 3 entry)
13574 (aput 'ent-alist key
13575 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13576 (adelete 'ent-alist key)))
13577 (setq ent-list (cdr ent-list)))
13578 ;; architectures
13579 (while arch-list
13580 (setq key (car arch-list)
13581 ent-key (car arch-ent-list)
13582 entry (aget ent-alist ent-key t)
13583 arch-alist (nth 3 entry))
13584 (when (equal file-name (nth 1 (aget arch-alist key t)))
13585 (adelete 'arch-alist key)
13586 (if (or (nth 1 entry) arch-alist)
13587 (aput 'ent-alist ent-key
13588 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13589 arch-alist (nth 4 entry) (nth 5 entry)))
13590 (adelete 'ent-alist ent-key)))
13591 (setq arch-list (cdr arch-list)
13592 arch-ent-list (cdr arch-ent-list)))
13593 ;; configurations
13594 (while conf-list
13595 (setq key (car conf-list))
13596 (when (equal file-name (nth 1 (aget conf-alist key t)))
13597 (adelete 'conf-alist key))
13598 (setq conf-list (cdr conf-list)))
13599 ;; package declarations
13600 (while pack-list
13601 (setq key (car pack-list)
13602 entry (aget pack-alist key t))
13603 (when (equal file-name (nth 1 entry))
13604 (if (nth 6 entry)
13605 (aput 'pack-alist key
13606 (list (nth 0 entry) nil nil nil nil nil
13607 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13608 (nth 9 entry)))
13609 (adelete 'pack-alist key)))
13610 (setq pack-list (cdr pack-list)))
13611 ;; package bodies
13612 (while pack-body-list
13613 (setq key (car pack-body-list)
13614 entry (aget pack-alist key t))
13615 (when (equal file-name (nth 6 entry))
13616 (if (nth 1 entry)
13617 (aput 'pack-alist key
13618 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13619 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13620 nil nil nil nil))
13621 (adelete 'pack-alist key)))
13622 (setq pack-body-list (cdr pack-body-list)))
13623 ;; instantiated entities
13624 (while inst-ent-list
13625 (setq ent-inst-list
13626 (vhdl-delete (car inst-ent-list) ent-inst-list))
13627 (setq inst-ent-list (cdr inst-ent-list)))
13628 ;; update caches
13629 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13630 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13631 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13632 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13633 ;; scan file
13634 (vhdl-scan-directory-contents file-name project t)
13635 (when (or (and vhdl-speedbar-show-projects project)
13636 (and (not vhdl-speedbar-show-projects) (not project)))
13637 (vhdl-speedbar-refresh project))
13638 (setq updated t)))
13639 (setq directory-alist (cdr directory-alist)))
13640 updated))
13641
13642 (defun vhdl-update-hierarchy ()
13643 "Update directory and hierarchy information in speedbar."
13644 (let ((file-list (reverse vhdl-modified-file-list))
13645 updated)
13646 (when (and vhdl-speedbar-update-on-saving file-list)
13647 (while file-list
13648 (setq updated
13649 (or (vhdl-update-file-contents (car file-list))
13650 updated))
13651 (setq file-list (cdr file-list)))
13652 (setq vhdl-modified-file-list nil)
13653 (vhdl-speedbar-update-current-unit)
13654 (when updated (message "Updating hierarchy...done")))))
13655
13656 ;; structure (parenthesised expression means list of such entries)
13657 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13658 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13659 ;; comp-lib-name level)
13660 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13661 conf-inst-alist level indent
13662 &optional include-top ent-hier)
13663 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13664 entity ENT-KEY."
13665 (let* ((ent-entry (aget ent-alist ent-key t))
13666 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13667 (cdar (last (nth 3 ent-entry)))))
13668 (inst-alist (nth 3 arch-entry))
13669 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13670 hier-list subcomp-list tmp-list inst-key inst-comp-name
13671 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13672 (when (= level 0) (message "Extract design hierarchy..."))
13673 (when include-top
13674 (setq level (1+ level)))
13675 (when (member ent-key ent-hier)
13676 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13677 ;; check configured architecture (already checked during scanning)
13678 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13679 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13680 ;; process all instances
13681 (while inst-alist
13682 (setq inst-entry (car inst-alist)
13683 inst-key (nth 0 inst-entry)
13684 inst-comp-name (nth 4 inst-entry)
13685 inst-conf-key (nth 7 inst-entry))
13686 ;; search entry in configuration's instantiations list
13687 (setq tmp-list conf-inst-alist)
13688 (while (and tmp-list
13689 (not (and (member (nth 0 (car tmp-list))
13690 (list "all" inst-key))
13691 (equal (nth 1 (car tmp-list))
13692 (downcase (or inst-comp-name ""))))))
13693 (setq tmp-list (cdr tmp-list)))
13694 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13695 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13696 (when (and inst-conf-key (not inst-conf-entry))
13697 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13698 ;; determine entity
13699 (setq inst-ent-key
13700 (or (nth 2 (car tmp-list)) ; from configuration
13701 (nth 3 inst-conf-entry) ; from subconfiguration
13702 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13703 ; from configuration spec.
13704 (nth 5 inst-entry))) ; from direct instantiation
13705 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13706 ;; determine architecture
13707 (setq inst-arch-key
13708 (or (nth 3 (car tmp-list)) ; from configuration
13709 (nth 4 inst-conf-entry) ; from subconfiguration
13710 (nth 6 inst-entry) ; from direct instantiation
13711 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13712 ; from configuration spec.
13713 (nth 4 inst-ent-entry) ; MRA
13714 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13715 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13716 ;; set library
13717 (setq inst-lib-key
13718 (or (nth 5 (car tmp-list)) ; from configuration
13719 (nth 8 inst-entry))) ; from direct instantiation
13720 ;; gather information for this instance
13721 (setq comp-entry
13722 (list (nth 1 inst-entry)
13723 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13724 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13725 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13726 (or (nth 0 inst-arch-entry) inst-arch-key)
13727 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13728 (or (nth 0 inst-conf-entry) inst-conf-key)
13729 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13730 inst-lib-key level))
13731 ;; get subcomponent hierarchy
13732 (setq subcomp-list (vhdl-get-hierarchy
13733 ent-alist conf-alist
13734 inst-ent-key inst-arch-key inst-conf-key
13735 (nth 5 inst-conf-entry)
13736 (1+ level) indent nil (cons ent-key ent-hier)))
13737 ;; add to list
13738 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13739 (setq inst-alist (cdr inst-alist)))
13740 (when include-top
13741 (setq hier-list
13742 (cons (list nil nil (nth 0 ent-entry)
13743 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13744 (nth 0 arch-entry)
13745 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13746 nil nil
13747 nil (1- level))
13748 hier-list)))
13749 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13750 hier-list))
13751
13752 (defun vhdl-get-instantiations (ent-key indent)
13753 "Get all instantiations of entity ENT-KEY."
13754 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13755 arch-alist inst-alist ent-inst-list
13756 ent-entry arch-entry inst-entry)
13757 (while ent-alist
13758 (setq ent-entry (car ent-alist))
13759 (setq arch-alist (nth 4 ent-entry))
13760 (while arch-alist
13761 (setq arch-entry (car arch-alist))
13762 (setq inst-alist (nth 4 arch-entry))
13763 (while inst-alist
13764 (setq inst-entry (car inst-alist))
13765 (when (equal ent-key (nth 5 inst-entry))
13766 (setq ent-inst-list
13767 (cons (list (nth 1 inst-entry)
13768 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13769 (nth 1 ent-entry)
13770 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13771 (nth 1 arch-entry)
13772 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13773 ent-inst-list)))
13774 (setq inst-alist (cdr inst-alist)))
13775 (setq arch-alist (cdr arch-alist)))
13776 (setq ent-alist (cdr ent-alist)))
13777 (nreverse ent-inst-list)))
13778
13779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13780 ;; Caching in file
13781
13782 (defun vhdl-save-caches ()
13783 "Save all updated hierarchy caches to file."
13784 (interactive)
13785 (condition-case nil
13786 (when vhdl-speedbar-save-cache
13787 ;; update hierarchy
13788 (vhdl-update-hierarchy)
13789 (let ((project-list vhdl-updated-project-list))
13790 (message "Saving hierarchy caches...")
13791 ;; write updated project caches
13792 (while project-list
13793 (vhdl-save-cache (car project-list))
13794 (setq project-list (cdr project-list)))
13795 (message "Saving hierarchy caches...done")))
13796 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13797 (sit-for 2)))))
13798
13799 (defun vhdl-save-cache (key)
13800 "Save current hierarchy cache to file."
13801 (let* ((orig-buffer (current-buffer))
13802 (vhdl-project key)
13803 (project (vhdl-project-p))
13804 (default-directory key)
13805 (directory (abbreviate-file-name (vhdl-default-directory)))
13806 (file-name (vhdl-resolve-env-variable
13807 (vhdl-replace-string
13808 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13809 (concat
13810 (subst-char-in-string ? ?_ (or project "dir"))
13811 " " (user-login-name)))))
13812 (file-dir-name (expand-file-name file-name directory))
13813 (cache-key (or project directory))
13814 (key (if project "project" "directory")))
13815 (unless (file-exists-p (file-name-directory file-dir-name))
13816 (make-directory (file-name-directory file-dir-name) t))
13817 (if (not (file-writable-p file-dir-name))
13818 (progn (vhdl-warning (format "File not writable: \"%s\""
13819 (abbreviate-file-name file-dir-name)))
13820 (sit-for 2))
13821 (message "Saving cache: \"%s\"" file-dir-name)
13822 (set-buffer (find-file-noselect file-dir-name t t))
13823 (erase-buffer)
13824 (insert ";; -*- Emacs-Lisp -*-\n\n"
13825 ";;; " (file-name-nondirectory file-name)
13826 " - design hierarchy cache file for Emacs VHDL Mode "
13827 vhdl-version "\n")
13828 (insert "\n;; " (if project "Project " "Directory") " : ")
13829 (if project (insert project) (prin1 directory (current-buffer)))
13830 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13831 (user-login-name) "\n\n"
13832 "\n;; version number\n"
13833 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13834 "\n;; " (if project "project" "directory") " name"
13835 "\n(setq " key " ")
13836 (prin1 (or project directory) (current-buffer))
13837 (insert ")\n")
13838 (when (member 'hierarchy vhdl-speedbar-save-cache)
13839 (insert "\n;; entity and architecture cache\n"
13840 "(aput 'vhdl-entity-alist " key " '")
13841 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13842 (insert ")\n\n;; configuration cache\n"
13843 "(aput 'vhdl-config-alist " key " '")
13844 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13845 (insert ")\n\n;; package cache\n"
13846 "(aput 'vhdl-package-alist " key " '")
13847 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13848 (insert ")\n\n;; instantiated entities cache\n"
13849 "(aput 'vhdl-ent-inst-alist " key " '")
13850 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13851 (insert ")\n\n;; design units per file cache\n"
13852 "(aput 'vhdl-file-alist " key " '")
13853 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13854 (when project
13855 (insert ")\n\n;; source directories in project cache\n"
13856 "(aput 'vhdl-directory-alist " key " '")
13857 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13858 (insert ")\n"))
13859 (when (member 'display vhdl-speedbar-save-cache)
13860 (insert "\n;; shown design units cache\n"
13861 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13862 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13863 (current-buffer))
13864 (insert ")\n"))
13865 (setq vhdl-updated-project-list
13866 (delete cache-key vhdl-updated-project-list))
13867 (save-buffer)
13868 (kill-buffer (current-buffer))
13869 (set-buffer orig-buffer))))
13870
13871 (defun vhdl-load-cache (key)
13872 "Load hierarchy cache information from file."
13873 (let* ((vhdl-project key)
13874 (default-directory key)
13875 (directory (vhdl-default-directory))
13876 (file-name (vhdl-resolve-env-variable
13877 (vhdl-replace-string
13878 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13879 (concat
13880 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13881 " " (user-login-name)))))
13882 (file-dir-name (expand-file-name file-name directory))
13883 vhdl-cache-version)
13884 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13885 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13886 (when (file-exists-p file-dir-name)
13887 (condition-case ()
13888 (progn (load-file file-dir-name)
13889 (string< (mapconcat
13890 (lambda (a) (format "%3d" (string-to-number a)))
13891 (split-string "3.33" "\\.") "")
13892 (mapconcat
13893 (lambda (a) (format "%3d" (string-to-number a)))
13894 (split-string vhdl-cache-version "\\.") "")))
13895 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13896 nil))))))
13897
13898 (defun vhdl-require-hierarchy-info ()
13899 "Make sure that hierarchy information is available. Load cache or scan files
13900 if required."
13901 (if (vhdl-project-p)
13902 (unless (or (assoc vhdl-project vhdl-file-alist)
13903 (vhdl-load-cache vhdl-project))
13904 (vhdl-scan-project-contents vhdl-project))
13905 (let ((directory (abbreviate-file-name default-directory)))
13906 (unless (or (assoc directory vhdl-file-alist)
13907 (vhdl-load-cache directory))
13908 (vhdl-scan-directory-contents directory)))))
13909
13910 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13911 ;; Add hierarchy browser functionality to speedbar
13912
13913 (defvar vhdl-speedbar-key-map nil
13914 "Keymap used when in the VHDL hierarchy browser mode.")
13915
13916 (defvar vhdl-speedbar-menu-items nil
13917 "Additional menu-items to add to speedbar frame.")
13918
13919 (defun vhdl-speedbar-initialize ()
13920 "Initialize speedbar."
13921 ;; general settings
13922 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13923 ;; VHDL file extensions (extracted from `auto-mode-alist')
13924 (let ((mode-alist auto-mode-alist))
13925 (while mode-alist
13926 (when (eq (cdar mode-alist) 'vhdl-mode)
13927 (speedbar-add-supported-extension (caar mode-alist)))
13928 (setq mode-alist (cdr mode-alist))))
13929 ;; hierarchy browser settings
13930 (when (boundp 'speedbar-mode-functions-list)
13931 ;; special functions
13932 (speedbar-add-mode-functions-list
13933 '("vhdl directory"
13934 (speedbar-item-info . vhdl-speedbar-item-info)
13935 (speedbar-line-directory . speedbar-files-line-path)))
13936 (speedbar-add-mode-functions-list
13937 '("vhdl project"
13938 (speedbar-item-info . vhdl-speedbar-item-info)
13939 (speedbar-line-directory . vhdl-speedbar-line-project)))
13940 ;; keymap
13941 (unless vhdl-speedbar-key-map
13942 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13943 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13944 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13945 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13946 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13947 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13948 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13949 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13950 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13951 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13952 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13953 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13954 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13955 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13956 (let ((key 0))
13957 (while (<= key 9)
13958 (define-key vhdl-speedbar-key-map (int-to-string key)
13959 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13960 (setq key (1+ key)))))
13961 (define-key speedbar-key-map "h"
13962 (lambda () (interactive)
13963 (speedbar-change-initial-expansion-list "vhdl directory")))
13964 (define-key speedbar-key-map "H"
13965 (lambda () (interactive)
13966 (speedbar-change-initial-expansion-list "vhdl project")))
13967 ;; menu
13968 (unless vhdl-speedbar-menu-items
13969 (setq
13970 vhdl-speedbar-menu-items
13971 `(["Edit" speedbar-edit-line t]
13972 ["Expand" speedbar-expand-line
13973 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13974 ["Contract" vhdl-speedbar-contract-level t]
13975 ["Expand All" vhdl-speedbar-expand-all t]
13976 ["Contract All" vhdl-speedbar-contract-all t]
13977 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13978 (while (<= key 9)
13979 (setq menu-list
13980 (cons `[,(if (= key 0) "All" (int-to-string key))
13981 (vhdl-speedbar-set-depth ,key)
13982 :style radio
13983 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13984 :keys ,(int-to-string key)]
13985 menu-list))
13986 (setq key (1+ key)))
13987 (nreverse menu-list))
13988 "--"
13989 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13990 (or (vhdl-speedbar-check-unit 'entity)
13991 (vhdl-speedbar-check-unit 'subprogram))]
13992 ["Place Component" vhdl-speedbar-place-component
13993 (vhdl-speedbar-check-unit 'entity)]
13994 ["Generate Configuration" vhdl-speedbar-configuration
13995 (vhdl-speedbar-check-unit 'architecture)]
13996 ["Select as MRA" vhdl-speedbar-select-mra
13997 (vhdl-speedbar-check-unit 'architecture)]
13998 ["Make" vhdl-speedbar-make-design
13999 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14000 ["Generate Makefile" vhdl-speedbar-generate-makefile
14001 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14002 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14003 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14004 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14005 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14006 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14007 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14008 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14009 ;; hook-ups
14010 (speedbar-add-expansion-list
14011 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14012 vhdl-speedbar-display-directory))
14013 (speedbar-add-expansion-list
14014 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14015 vhdl-speedbar-display-projects))
14016 (setq speedbar-stealthy-function-list
14017 (append
14018 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14019 ("vhdl project" vhdl-speedbar-update-current-project
14020 vhdl-speedbar-update-current-unit)
14021 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14022 ; (speedbar-extension-list-to-regex
14023 ; speedbar-ignored-path-expressions))))
14024 )
14025 speedbar-stealthy-function-list))
14026 (when (eq vhdl-speedbar-display-mode 'directory)
14027 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14028 (when (eq vhdl-speedbar-display-mode 'project)
14029 (setq speedbar-initial-expansion-list-name "vhdl project"))
14030 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14031
14032 (defun vhdl-speedbar (&optional arg)
14033 "Open/close speedbar."
14034 (interactive)
14035 (if (not (fboundp 'speedbar))
14036 (error "WARNING: Speedbar is not available or not installed")
14037 (condition-case ()
14038 (speedbar-frame-mode arg)
14039 (error (error "WARNING: An error occurred while opening speedbar")))))
14040
14041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14042 ;; Display functions
14043
14044 (defvar vhdl-speedbar-last-selected-project nil
14045 "Name of last selected project.")
14046
14047 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14048 (defmacro speedbar-with-writable (&rest forms)
14049 "Allow the buffer to be writable and evaluate FORMS."
14050 (list 'let '((inhibit-read-only t))
14051 (cons 'progn forms)))
14052 (put 'speedbar-with-writable 'lisp-indent-function 0)
14053
14054 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14055 "Display directory and hierarchy information in speedbar."
14056 (setq vhdl-speedbar-show-projects nil)
14057 (setq speedbar-ignored-directory-regexp
14058 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14059 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14060 (setq speedbar-last-selected-file nil)
14061 (speedbar-with-writable
14062 (condition-case nil
14063 (progn
14064 ;; insert directory path
14065 (speedbar-directory-buttons directory depth)
14066 ;; insert subdirectories
14067 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14068 ;; scan and insert hierarchy of current directory
14069 (vhdl-speedbar-insert-dir-hierarchy directory depth
14070 speedbar-power-click)
14071 ;; expand subdirectories
14072 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14073 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14074
14075 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14076 "Display projects and hierarchy information in speedbar."
14077 (setq vhdl-speedbar-show-projects t)
14078 (setq speedbar-ignored-directory-regexp ".")
14079 (setq speedbar-last-selected-file nil)
14080 (setq vhdl-speedbar-last-selected-project nil)
14081 (speedbar-with-writable
14082 (condition-case nil
14083 ;; insert projects
14084 (vhdl-speedbar-insert-projects)
14085 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14086 (setq speedbar-full-text-cache nil)) ; prevent caching
14087
14088 (defun vhdl-speedbar-insert-projects ()
14089 "Insert all projects in speedbar."
14090 (vhdl-speedbar-make-title-line "Projects:")
14091 (let ((project-alist (if vhdl-project-sort
14092 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14093 vhdl-project-alist))
14094 (vhdl-speedbar-update-current-unit nil))
14095 ;; insert projects
14096 (while project-alist
14097 (speedbar-make-tag-line
14098 'angle ?+ 'vhdl-speedbar-expand-project
14099 (caar project-alist) (caar project-alist)
14100 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14101 (setq project-alist (cdr project-alist)))
14102 (setq project-alist vhdl-project-alist)
14103 ;; expand projects
14104 (while project-alist
14105 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14106 (goto-char (point-min))
14107 (when (re-search-forward
14108 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14109 (goto-char (match-end 1))
14110 (speedbar-do-function-pointer)))
14111 (setq project-alist (cdr project-alist))))
14112 ; (vhdl-speedbar-update-current-project)
14113 ; (vhdl-speedbar-update-current-unit nil t)
14114 )
14115
14116 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14117 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14118 otherwise use cached data."
14119 (when (or rescan (and (not (assoc project vhdl-file-alist))
14120 (not (vhdl-load-cache project))))
14121 (vhdl-scan-project-contents project))
14122 ;; insert design hierarchy
14123 (vhdl-speedbar-insert-hierarchy
14124 (aget vhdl-entity-alist project t)
14125 (aget vhdl-config-alist project t)
14126 (aget vhdl-package-alist project t)
14127 (car (aget vhdl-ent-inst-alist project t)) indent)
14128 (insert (int-to-string indent) ":\n")
14129 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14130 (put-text-property (1- (point)) (point) 'invisible nil)
14131 ;; expand design units
14132 (vhdl-speedbar-expand-units project))
14133
14134 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14135 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14136 otherwise use cached data."
14137 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14138 (not (vhdl-load-cache directory))))
14139 (vhdl-scan-directory-contents directory))
14140 ;; insert design hierarchy
14141 (vhdl-speedbar-insert-hierarchy
14142 (aget vhdl-entity-alist directory t)
14143 (aget vhdl-config-alist directory t)
14144 (aget vhdl-package-alist directory t)
14145 (car (aget vhdl-ent-inst-alist directory t)) depth)
14146 ;; expand design units
14147 (vhdl-speedbar-expand-units directory)
14148 (aput 'vhdl-directory-alist directory (list (list directory))))
14149
14150 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14151 ent-inst-list depth)
14152 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14153 (if (not (or ent-alist conf-alist pack-alist))
14154 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14155 (let (ent-entry conf-entry pack-entry)
14156 ;; insert entities
14157 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14158 (while ent-alist
14159 (setq ent-entry (car ent-alist))
14160 (speedbar-make-tag-line
14161 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14162 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14163 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14164 'vhdl-speedbar-entity-face depth)
14165 (unless (nth 2 ent-entry)
14166 (end-of-line 0) (insert "!") (forward-char 1))
14167 (unless (member (nth 0 ent-entry) ent-inst-list)
14168 (end-of-line 0) (insert " (top)") (forward-char 1))
14169 (setq ent-alist (cdr ent-alist)))
14170 ;; insert configurations
14171 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14172 (while conf-alist
14173 (setq conf-entry (car conf-alist))
14174 (speedbar-make-tag-line
14175 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14176 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14177 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14178 'vhdl-speedbar-configuration-face depth)
14179 (setq conf-alist (cdr conf-alist)))
14180 ;; insert packages
14181 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14182 (while pack-alist
14183 (setq pack-entry (car pack-alist))
14184 (vhdl-speedbar-make-pack-line
14185 (nth 0 pack-entry) (nth 1 pack-entry)
14186 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14187 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14188 depth)
14189 (setq pack-alist (cdr pack-alist))))))
14190
14191 (defun vhdl-speedbar-rescan-hierarchy ()
14192 "Rescan hierarchy for the directory or project under the cursor."
14193 (interactive)
14194 (let (key path)
14195 (cond
14196 ;; current project
14197 (vhdl-speedbar-show-projects
14198 (setq key (vhdl-speedbar-line-project))
14199 (vhdl-scan-project-contents key))
14200 ;; top-level directory
14201 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14202 (re-search-forward "[0-9]+:" nil t)
14203 (vhdl-scan-directory-contents
14204 (abbreviate-file-name (speedbar-line-directory))))
14205 ;; current directory
14206 (t (setq path (speedbar-line-directory))
14207 (string-match "^\\(.+[/\\]\\)" path)
14208 (vhdl-scan-directory-contents
14209 (abbreviate-file-name (match-string 1 path)))))
14210 (vhdl-speedbar-refresh key)))
14211
14212 (defun vhdl-speedbar-expand-dirs (directory)
14213 "Expand subdirectories in DIRECTORY according to
14214 `speedbar-shown-directories'."
14215 ;; (nicked from `speedbar-default-directory-list')
14216 (let ((sf (cdr (reverse speedbar-shown-directories)))
14217 (vhdl-speedbar-update-current-unit nil))
14218 (setq speedbar-shown-directories
14219 (list (expand-file-name default-directory)))
14220 (while sf
14221 (when (speedbar-goto-this-file (car sf))
14222 (beginning-of-line)
14223 (when (looking-at "[0-9]+:\\s-*<")
14224 (goto-char (match-end 0))
14225 (speedbar-do-function-pointer)))
14226 (setq sf (cdr sf))))
14227 (vhdl-speedbar-update-current-unit nil t))
14228
14229 (defun vhdl-speedbar-expand-units (key)
14230 "Expand design units in directory/project KEY according to
14231 `vhdl-speedbar-shown-unit-alist'."
14232 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14233 (vhdl-speedbar-update-current-unit nil)
14234 vhdl-updated-project-list)
14235 (adelete 'vhdl-speedbar-shown-unit-alist key)
14236 (vhdl-prepare-search-1
14237 (while unit-alist ; expand units
14238 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14239 (beginning-of-line)
14240 (let ((arch-alist (nth 1 (car unit-alist)))
14241 position)
14242 (when (looking-at "^[0-9]+:\\s-*\\[")
14243 (goto-char (match-end 0))
14244 (setq position (point))
14245 (speedbar-do-function-pointer)
14246 (select-frame speedbar-frame)
14247 (while arch-alist ; expand architectures
14248 (goto-char position)
14249 (when (re-search-forward
14250 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14251 (car arch-alist) "\\>\\)") nil t)
14252 (beginning-of-line)
14253 (when (looking-at "^[0-9]+:\\s-*{")
14254 (goto-char (match-end 0))
14255 (speedbar-do-function-pointer)
14256 (select-frame speedbar-frame)))
14257 (setq arch-alist (cdr arch-alist))))
14258 (setq unit-alist (cdr unit-alist))))))
14259 (vhdl-speedbar-update-current-unit nil t))
14260
14261 (defun vhdl-speedbar-contract-level ()
14262 "Contract current level in current directory/project."
14263 (interactive)
14264 (when (or (save-excursion
14265 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14266 (and (save-excursion
14267 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14268 (re-search-backward
14269 (format "^[0-%d]:\\s-*[[{<]-"
14270 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14271 (goto-char (match-end 0))
14272 (speedbar-do-function-pointer)
14273 (speedbar-center-buffer-smartly)))
14274
14275 (defun vhdl-speedbar-contract-all ()
14276 "Contract all expanded design units in current directory/project."
14277 (interactive)
14278 (if (and vhdl-speedbar-show-projects
14279 (save-excursion (beginning-of-line) (looking-at "^0:")))
14280 (progn (setq vhdl-speedbar-shown-project-list nil)
14281 (vhdl-speedbar-refresh))
14282 (let ((key (vhdl-speedbar-line-key)))
14283 (adelete 'vhdl-speedbar-shown-unit-alist key)
14284 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14285 (when (memq 'display vhdl-speedbar-save-cache)
14286 (add-to-list 'vhdl-updated-project-list key)))))
14287
14288 (defun vhdl-speedbar-expand-all ()
14289 "Expand all design units in current directory/project."
14290 (interactive)
14291 (let* ((key (vhdl-speedbar-line-key))
14292 (ent-alist (aget vhdl-entity-alist key t))
14293 (conf-alist (aget vhdl-config-alist key t))
14294 (pack-alist (aget vhdl-package-alist key t))
14295 arch-alist unit-alist subunit-alist)
14296 (add-to-list 'vhdl-speedbar-shown-project-list key)
14297 (while ent-alist
14298 (setq arch-alist (nth 4 (car ent-alist)))
14299 (setq subunit-alist nil)
14300 (while arch-alist
14301 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14302 (setq arch-alist (cdr arch-alist)))
14303 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14304 (setq ent-alist (cdr ent-alist)))
14305 (while conf-alist
14306 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14307 (setq conf-alist (cdr conf-alist)))
14308 (while pack-alist
14309 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14310 (setq pack-alist (cdr pack-alist)))
14311 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14312 (vhdl-speedbar-refresh)
14313 (when (memq 'display vhdl-speedbar-save-cache)
14314 (add-to-list 'vhdl-updated-project-list key))))
14315
14316 (defun vhdl-speedbar-expand-project (text token indent)
14317 "Expand/contract the project under the cursor."
14318 (cond
14319 ((string-match "+" text) ; expand project
14320 (speedbar-change-expand-button-char ?-)
14321 (unless (member token vhdl-speedbar-shown-project-list)
14322 (setq vhdl-speedbar-shown-project-list
14323 (cons token vhdl-speedbar-shown-project-list)))
14324 (speedbar-with-writable
14325 (save-excursion
14326 (end-of-line) (forward-char 1)
14327 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14328 speedbar-power-click))))
14329 ((string-match "-" text) ; contract project
14330 (speedbar-change-expand-button-char ?+)
14331 (setq vhdl-speedbar-shown-project-list
14332 (delete token vhdl-speedbar-shown-project-list))
14333 (speedbar-delete-subblock indent))
14334 (t (error "Nothing to display")))
14335 (when (equal (selected-frame) speedbar-frame)
14336 (speedbar-center-buffer-smartly)))
14337
14338 (defun vhdl-speedbar-expand-entity (text token indent)
14339 "Expand/contract the entity under the cursor."
14340 (cond
14341 ((string-match "+" text) ; expand entity
14342 (let* ((key (vhdl-speedbar-line-key indent))
14343 (ent-alist (aget vhdl-entity-alist key t))
14344 (ent-entry (aget ent-alist token t))
14345 (arch-alist (nth 3 ent-entry))
14346 (inst-alist (vhdl-get-instantiations token indent))
14347 (subpack-alist (nth 5 ent-entry))
14348 (multiple-arch (> (length arch-alist) 1))
14349 arch-entry inst-entry)
14350 (if (not (or arch-alist inst-alist subpack-alist))
14351 (speedbar-change-expand-button-char ??)
14352 (speedbar-change-expand-button-char ?-)
14353 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14354 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14355 (aput 'unit-alist token nil)
14356 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14357 (speedbar-with-writable
14358 (save-excursion
14359 (end-of-line) (forward-char 1)
14360 ;; insert architectures
14361 (when arch-alist
14362 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14363 (while arch-alist
14364 (setq arch-entry (car arch-alist))
14365 (speedbar-make-tag-line
14366 'curly ?+ 'vhdl-speedbar-expand-architecture
14367 (cons token (nth 0 arch-entry))
14368 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14369 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14370 'vhdl-speedbar-architecture-face (1+ indent))
14371 (when (and multiple-arch
14372 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14373 (end-of-line 0) (insert " (mra)") (forward-char 1))
14374 (setq arch-alist (cdr arch-alist)))
14375 ;; insert instantiations
14376 (when inst-alist
14377 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14378 (while inst-alist
14379 (setq inst-entry (car inst-alist))
14380 (vhdl-speedbar-make-inst-line
14381 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14382 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14383 nil nil nil (1+ indent) 0 " in ")
14384 (setq inst-alist (cdr inst-alist)))
14385 ;; insert required packages
14386 (vhdl-speedbar-insert-subpackages
14387 subpack-alist (1+ indent) indent)))
14388 (when (memq 'display vhdl-speedbar-save-cache)
14389 (add-to-list 'vhdl-updated-project-list key))
14390 (vhdl-speedbar-update-current-unit t t))))
14391 ((string-match "-" text) ; contract entity
14392 (speedbar-change-expand-button-char ?+)
14393 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14394 (let* ((key (vhdl-speedbar-line-key indent))
14395 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14396 (adelete 'unit-alist token)
14397 (if unit-alist
14398 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14399 (adelete 'vhdl-speedbar-shown-unit-alist key))
14400 (speedbar-delete-subblock indent)
14401 (when (memq 'display vhdl-speedbar-save-cache)
14402 (add-to-list 'vhdl-updated-project-list key))))
14403 (t (error "Nothing to display")))
14404 (when (equal (selected-frame) speedbar-frame)
14405 (speedbar-center-buffer-smartly)))
14406
14407 (defun vhdl-speedbar-expand-architecture (text token indent)
14408 "Expand/contract the architecture under the cursor."
14409 (cond
14410 ((string-match "+" text) ; expand architecture
14411 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14412 (ent-alist (aget vhdl-entity-alist key t))
14413 (conf-alist (aget vhdl-config-alist key t))
14414 (hier-alist (vhdl-get-hierarchy
14415 ent-alist conf-alist (car token) (cdr token) nil nil
14416 0 (1- indent)))
14417 (ent-entry (aget ent-alist (car token) t))
14418 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14419 (subpack-alist (nth 4 arch-entry))
14420 entry)
14421 (if (not (or hier-alist subpack-alist))
14422 (speedbar-change-expand-button-char ??)
14423 (speedbar-change-expand-button-char ?-)
14424 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14425 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14426 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14427 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14428 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14429 (speedbar-with-writable
14430 (save-excursion
14431 (end-of-line) (forward-char 1)
14432 ;; insert instance hierarchy
14433 (when hier-alist
14434 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14435 (1+ indent)))
14436 (while hier-alist
14437 (setq entry (car hier-alist))
14438 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14439 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14440 (vhdl-speedbar-make-inst-line
14441 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14442 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14443 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14444 (setq hier-alist (cdr hier-alist)))
14445 ;; insert required packages
14446 (vhdl-speedbar-insert-subpackages
14447 subpack-alist (1+ indent) (1- indent))))
14448 (when (memq 'display vhdl-speedbar-save-cache)
14449 (add-to-list 'vhdl-updated-project-list key))
14450 (vhdl-speedbar-update-current-unit t t))))
14451 ((string-match "-" text) ; contract architecture
14452 (speedbar-change-expand-button-char ?+)
14453 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14454 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14455 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14456 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14457 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14458 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14459 (speedbar-delete-subblock indent)
14460 (when (memq 'display vhdl-speedbar-save-cache)
14461 (add-to-list 'vhdl-updated-project-list key))))
14462 (t (error "Nothing to display")))
14463 (when (equal (selected-frame) speedbar-frame)
14464 (speedbar-center-buffer-smartly)))
14465
14466 (defun vhdl-speedbar-expand-config (text token indent)
14467 "Expand/contract the configuration under the cursor."
14468 (cond
14469 ((string-match "+" text) ; expand configuration
14470 (let* ((key (vhdl-speedbar-line-key indent))
14471 (conf-alist (aget vhdl-config-alist key t))
14472 (conf-entry (aget conf-alist token))
14473 (ent-alist (aget vhdl-entity-alist key t))
14474 (hier-alist (vhdl-get-hierarchy
14475 ent-alist conf-alist (nth 3 conf-entry)
14476 (nth 4 conf-entry) token (nth 5 conf-entry)
14477 0 indent t))
14478 (subpack-alist (nth 6 conf-entry))
14479 entry)
14480 (if (not (or hier-alist subpack-alist))
14481 (speedbar-change-expand-button-char ??)
14482 (speedbar-change-expand-button-char ?-)
14483 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14484 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14485 (aput 'unit-alist token nil)
14486 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14487 (speedbar-with-writable
14488 (save-excursion
14489 (end-of-line) (forward-char 1)
14490 ;; insert instance hierarchy
14491 (when hier-alist
14492 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14493 (while hier-alist
14494 (setq entry (car hier-alist))
14495 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14496 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14497 (vhdl-speedbar-make-inst-line
14498 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14499 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14500 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14501 (setq hier-alist (cdr hier-alist)))
14502 ;; insert required packages
14503 (vhdl-speedbar-insert-subpackages
14504 subpack-alist (1+ indent) indent)))
14505 (when (memq 'display vhdl-speedbar-save-cache)
14506 (add-to-list 'vhdl-updated-project-list key))
14507 (vhdl-speedbar-update-current-unit t t))))
14508 ((string-match "-" text) ; contract configuration
14509 (speedbar-change-expand-button-char ?+)
14510 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14511 (let* ((key (vhdl-speedbar-line-key indent))
14512 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14513 (adelete 'unit-alist token)
14514 (if unit-alist
14515 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14516 (adelete 'vhdl-speedbar-shown-unit-alist key))
14517 (speedbar-delete-subblock indent)
14518 (when (memq 'display vhdl-speedbar-save-cache)
14519 (add-to-list 'vhdl-updated-project-list key))))
14520 (t (error "Nothing to display")))
14521 (when (equal (selected-frame) speedbar-frame)
14522 (speedbar-center-buffer-smartly)))
14523
14524 (defun vhdl-speedbar-expand-package (text token indent)
14525 "Expand/contract the package under the cursor."
14526 (cond
14527 ((string-match "+" text) ; expand package
14528 (let* ((key (vhdl-speedbar-line-key indent))
14529 (pack-alist (aget vhdl-package-alist key t))
14530 (pack-entry (aget pack-alist token t))
14531 (comp-alist (nth 3 pack-entry))
14532 (func-alist (nth 4 pack-entry))
14533 (func-body-alist (nth 8 pack-entry))
14534 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14535 comp-entry func-entry func-body-entry)
14536 (if (not (or comp-alist func-alist subpack-alist))
14537 (speedbar-change-expand-button-char ??)
14538 (speedbar-change-expand-button-char ?-)
14539 ;; add package to `vhdl-speedbar-shown-unit-alist'
14540 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14541 (aput 'unit-alist token nil)
14542 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14543 (speedbar-with-writable
14544 (save-excursion
14545 (end-of-line) (forward-char 1)
14546 ;; insert components
14547 (when comp-alist
14548 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14549 (while comp-alist
14550 (setq comp-entry (car comp-alist))
14551 (speedbar-make-tag-line
14552 nil nil nil
14553 (cons token (nth 0 comp-entry))
14554 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14555 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14556 'vhdl-speedbar-entity-face (1+ indent))
14557 (setq comp-alist (cdr comp-alist)))
14558 ;; insert subprograms
14559 (when func-alist
14560 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14561 (while func-alist
14562 (setq func-entry (car func-alist)
14563 func-body-entry (aget func-body-alist (car func-entry) t))
14564 (when (nth 2 func-entry)
14565 (vhdl-speedbar-make-subprogram-line
14566 (nth 1 func-entry)
14567 (cons (nth 2 func-entry) (nth 3 func-entry))
14568 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14569 (1+ indent)))
14570 (setq func-alist (cdr func-alist)))
14571 ;; insert required packages
14572 (vhdl-speedbar-insert-subpackages
14573 subpack-alist (1+ indent) indent)))
14574 (when (memq 'display vhdl-speedbar-save-cache)
14575 (add-to-list 'vhdl-updated-project-list key))
14576 (vhdl-speedbar-update-current-unit t t))))
14577 ((string-match "-" text) ; contract package
14578 (speedbar-change-expand-button-char ?+)
14579 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14580 (let* ((key (vhdl-speedbar-line-key indent))
14581 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14582 (adelete 'unit-alist token)
14583 (if unit-alist
14584 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14585 (adelete 'vhdl-speedbar-shown-unit-alist key))
14586 (speedbar-delete-subblock indent)
14587 (when (memq 'display vhdl-speedbar-save-cache)
14588 (add-to-list 'vhdl-updated-project-list key))))
14589 (t (error "Nothing to display")))
14590 (when (equal (selected-frame) speedbar-frame)
14591 (speedbar-center-buffer-smartly)))
14592
14593 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14594 "Insert required packages."
14595 (let* ((pack-alist (aget vhdl-package-alist
14596 (vhdl-speedbar-line-key dir-indent) t))
14597 pack-key lib-name pack-entry)
14598 (when subpack-alist
14599 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14600 (while subpack-alist
14601 (setq pack-key (cdar subpack-alist)
14602 lib-name (caar subpack-alist))
14603 (setq pack-entry (aget pack-alist pack-key t))
14604 (vhdl-speedbar-make-subpack-line
14605 (or (nth 0 pack-entry) pack-key) lib-name
14606 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14607 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14608 (setq subpack-alist (cdr subpack-alist)))))
14609
14610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14611 ;; Display help functions
14612
14613 (defvar vhdl-speedbar-update-current-unit t
14614 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14615
14616 (defun vhdl-speedbar-update-current-project ()
14617 "Highlight project that is currently active."
14618 (when (and vhdl-speedbar-show-projects
14619 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14620 (and (boundp 'speedbar-frame)
14621 (frame-live-p speedbar-frame)))
14622 (let ((last-frame (selected-frame))
14623 (project-alist vhdl-project-alist)
14624 pos)
14625 (select-frame speedbar-frame)
14626 (speedbar-with-writable
14627 (save-excursion
14628 (while project-alist
14629 (goto-char (point-min))
14630 (when (re-search-forward
14631 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14632 (put-text-property (match-beginning 1) (match-end 1) 'face
14633 (if (equal (caar project-alist) vhdl-project)
14634 'speedbar-selected-face
14635 'speedbar-directory-face))
14636 (when (equal (caar project-alist) vhdl-project)
14637 (setq pos (1- (match-beginning 1)))))
14638 (setq project-alist (cdr project-alist))))
14639 (when pos (goto-char pos)))
14640 (select-frame last-frame)
14641 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14642 t)
14643
14644 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14645 "Highlight all design units that are contained in the current file.
14646 NO-POSITION non-nil means do not re-position cursor."
14647 (let ((last-frame (selected-frame))
14648 (project-list vhdl-speedbar-shown-project-list)
14649 file-alist pos file-name)
14650 ;; get current file name
14651 (if (fboundp 'speedbar-select-attached-frame)
14652 (speedbar-select-attached-frame)
14653 (select-frame speedbar-attached-frame))
14654 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14655 (when (and vhdl-speedbar-update-current-unit
14656 (or always (not (equal file-name speedbar-last-selected-file))))
14657 (if vhdl-speedbar-show-projects
14658 (while project-list
14659 (setq file-alist (append file-alist (aget vhdl-file-alist
14660 (car project-list) t)))
14661 (setq project-list (cdr project-list)))
14662 (setq file-alist (aget vhdl-file-alist
14663 (abbreviate-file-name default-directory) t)))
14664 (select-frame speedbar-frame)
14665 (set-buffer speedbar-buffer)
14666 (speedbar-with-writable
14667 (vhdl-prepare-search-1
14668 (save-excursion
14669 ;; unhighlight last units
14670 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14671 (vhdl-speedbar-update-units
14672 "\\[.\\] " (nth 0 file-entry)
14673 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14674 (vhdl-speedbar-update-units
14675 "{.} " (nth 1 file-entry)
14676 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14677 (vhdl-speedbar-update-units
14678 "\\[.\\] " (nth 3 file-entry)
14679 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14680 (vhdl-speedbar-update-units
14681 "[]>] " (nth 4 file-entry)
14682 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14683 (vhdl-speedbar-update-units
14684 "\\[.\\].+(" '("body")
14685 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14686 (vhdl-speedbar-update-units
14687 "> " (nth 6 file-entry)
14688 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14689 ;; highlight current units
14690 (let* ((file-entry (aget file-alist file-name t)))
14691 (setq
14692 pos (vhdl-speedbar-update-units
14693 "\\[.\\] " (nth 0 file-entry)
14694 file-name 'vhdl-speedbar-entity-selected-face pos)
14695 pos (vhdl-speedbar-update-units
14696 "{.} " (nth 1 file-entry)
14697 file-name 'vhdl-speedbar-architecture-selected-face pos)
14698 pos (vhdl-speedbar-update-units
14699 "\\[.\\] " (nth 3 file-entry)
14700 file-name 'vhdl-speedbar-configuration-selected-face pos)
14701 pos (vhdl-speedbar-update-units
14702 "[]>] " (nth 4 file-entry)
14703 file-name 'vhdl-speedbar-package-selected-face pos)
14704 pos (vhdl-speedbar-update-units
14705 "\\[.\\].+(" '("body")
14706 file-name 'vhdl-speedbar-package-selected-face pos)
14707 pos (vhdl-speedbar-update-units
14708 "> " (nth 6 file-entry)
14709 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14710 ;; move speedbar so the first highlighted unit is visible
14711 (when (and pos (not no-position))
14712 (goto-char pos)
14713 (speedbar-center-buffer-smartly)
14714 (speedbar-position-cursor-on-line))
14715 (setq speedbar-last-selected-file file-name))
14716 (select-frame last-frame)
14717 t))
14718
14719 (defun vhdl-speedbar-update-units (text unit-list file-name face
14720 &optional pos)
14721 "Help function to highlight design units."
14722 (while unit-list
14723 (goto-char (point-min))
14724 (while (re-search-forward
14725 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14726 (when (equal file-name (car (get-text-property
14727 (match-beginning 1) 'speedbar-token)))
14728 (setq pos (or pos (point-marker)))
14729 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14730 (setq unit-list (cdr unit-list)))
14731 pos)
14732
14733 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14734 ent-name ent-file-marker
14735 arch-name arch-file-marker
14736 conf-name conf-file-marker
14737 lib-name depth offset delimiter)
14738 "Insert instantiation entry."
14739 (let ((start (point))
14740 visible-start)
14741 (insert (int-to-string depth) ":")
14742 (put-text-property start (point) 'invisible t)
14743 (setq visible-start (point))
14744 (insert-char ? (* depth speedbar-indentation-width))
14745 (while (> offset 0)
14746 (insert "|")
14747 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14748 (setq offset (1- offset)))
14749 (put-text-property visible-start (point) 'invisible nil)
14750 (setq start (point))
14751 (insert ">")
14752 (speedbar-make-button start (point) nil nil nil)
14753 (setq visible-start (point))
14754 (insert " ")
14755 (setq start (point))
14756 (if (not inst-name)
14757 (insert "(top)")
14758 (insert inst-name)
14759 (speedbar-make-button
14760 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14761 'vhdl-speedbar-find-file inst-file-marker))
14762 (insert delimiter)
14763 (when ent-name
14764 (setq start (point))
14765 (insert ent-name)
14766 (speedbar-make-button
14767 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14768 'vhdl-speedbar-find-file ent-file-marker)
14769 (when arch-name
14770 (insert " (")
14771 (setq start (point))
14772 (insert arch-name)
14773 (speedbar-make-button
14774 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14775 'vhdl-speedbar-find-file arch-file-marker)
14776 (insert ")"))
14777 (when conf-name
14778 (insert " (")
14779 (setq start (point))
14780 (insert conf-name)
14781 (speedbar-make-button
14782 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14783 'vhdl-speedbar-find-file conf-file-marker)
14784 (insert ")")))
14785 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14786 (setq start (point))
14787 (insert " (" lib-name ")")
14788 (put-text-property (+ 2 start) (1- (point)) 'face
14789 'vhdl-speedbar-library-face))
14790 (insert-char ?\n 1)
14791 (put-text-property visible-start (point) 'invisible nil)))
14792
14793 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14794 body-file-marker depth)
14795 "Insert package entry."
14796 (let ((start (point))
14797 visible-start)
14798 (insert (int-to-string depth) ":")
14799 (put-text-property start (point) 'invisible t)
14800 (setq visible-start (point))
14801 (insert-char ? (* depth speedbar-indentation-width))
14802 (put-text-property visible-start (point) 'invisible nil)
14803 (setq start (point))
14804 (insert "[+]")
14805 (speedbar-make-button
14806 start (point) 'speedbar-button-face 'speedbar-highlight-face
14807 'vhdl-speedbar-expand-package pack-key)
14808 (setq visible-start (point))
14809 (insert-char ? 1 nil)
14810 (setq start (point))
14811 (insert pack-name)
14812 (speedbar-make-button
14813 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14814 'vhdl-speedbar-find-file pack-file-marker)
14815 (unless (car pack-file-marker)
14816 (insert "!"))
14817 (when (car body-file-marker)
14818 (insert " (")
14819 (setq start (point))
14820 (insert "body")
14821 (speedbar-make-button
14822 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14823 'vhdl-speedbar-find-file body-file-marker)
14824 (insert ")"))
14825 (insert-char ?\n 1)
14826 (put-text-property visible-start (point) 'invisible nil)))
14827
14828 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14829 pack-body-file-marker depth)
14830 "Insert used package entry."
14831 (let ((start (point))
14832 visible-start)
14833 (insert (int-to-string depth) ":")
14834 (put-text-property start (point) 'invisible t)
14835 (setq visible-start (point))
14836 (insert-char ? (* depth speedbar-indentation-width))
14837 (put-text-property visible-start (point) 'invisible nil)
14838 (setq start (point))
14839 (insert ">")
14840 (speedbar-make-button start (point) nil nil nil)
14841 (setq visible-start (point))
14842 (insert " ")
14843 (setq start (point))
14844 (insert pack-name)
14845 (speedbar-make-button
14846 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14847 'vhdl-speedbar-find-file pack-file-marker)
14848 (when (car pack-body-file-marker)
14849 (insert " (")
14850 (setq start (point))
14851 (insert "body")
14852 (speedbar-make-button
14853 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14854 'vhdl-speedbar-find-file pack-body-file-marker)
14855 (insert ")"))
14856 (setq start (point))
14857 (insert " (" lib-name ")")
14858 (put-text-property (+ 2 start) (1- (point)) 'face
14859 'vhdl-speedbar-library-face)
14860 (insert-char ?\n 1)
14861 (put-text-property visible-start (point) 'invisible nil)))
14862
14863 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14864 func-body-file-marker
14865 depth)
14866 "Insert subprogram entry."
14867 (let ((start (point))
14868 visible-start)
14869 (insert (int-to-string depth) ":")
14870 (put-text-property start (point) 'invisible t)
14871 (setq visible-start (point))
14872 (insert-char ? (* depth speedbar-indentation-width))
14873 (put-text-property visible-start (point) 'invisible nil)
14874 (setq start (point))
14875 (insert ">")
14876 (speedbar-make-button start (point) nil nil nil)
14877 (setq visible-start (point))
14878 (insert " ")
14879 (setq start (point))
14880 (insert func-name)
14881 (speedbar-make-button
14882 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14883 'vhdl-speedbar-find-file func-file-marker)
14884 (when (car func-body-file-marker)
14885 (insert " (")
14886 (setq start (point))
14887 (insert "body")
14888 (speedbar-make-button
14889 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14890 'vhdl-speedbar-find-file func-body-file-marker)
14891 (insert ")"))
14892 (insert-char ?\n 1)
14893 (put-text-property visible-start (point) 'invisible nil)))
14894
14895 (defun vhdl-speedbar-make-title-line (text &optional depth)
14896 "Insert design unit title entry."
14897 (let ((start (point))
14898 visible-start)
14899 (when depth
14900 (insert (int-to-string depth) ":")
14901 (put-text-property start (point) 'invisible t))
14902 (setq visible-start (point))
14903 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14904 (setq start (point))
14905 (insert text)
14906 (speedbar-make-button start (point) nil nil nil nil)
14907 (insert-char ?\n 1)
14908 (put-text-property visible-start (point) 'invisible nil)))
14909
14910 (defun vhdl-speedbar-insert-dirs (files level)
14911 "Insert subdirectories."
14912 (let ((dirs (car files)))
14913 (while dirs
14914 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14915 (car dirs) 'speedbar-dir-follow nil
14916 'speedbar-directory-face level)
14917 (setq dirs (cdr dirs)))))
14918
14919 (defun vhdl-speedbar-dired (text token indent)
14920 "Speedbar click handler for directory expand button in hierarchy mode."
14921 (cond ((string-match "+" text) ; we have to expand this dir
14922 (setq speedbar-shown-directories
14923 (cons (expand-file-name
14924 (concat (speedbar-line-directory indent) token "/"))
14925 speedbar-shown-directories))
14926 (speedbar-change-expand-button-char ?-)
14927 (speedbar-reset-scanners)
14928 (speedbar-with-writable
14929 (save-excursion
14930 (end-of-line) (forward-char 1)
14931 (vhdl-speedbar-insert-dirs
14932 (speedbar-file-lists
14933 (concat (speedbar-line-directory indent) token "/"))
14934 (1+ indent))
14935 (speedbar-reset-scanners)
14936 (vhdl-speedbar-insert-dir-hierarchy
14937 (abbreviate-file-name
14938 (concat (speedbar-line-directory indent) token "/"))
14939 (1+ indent) speedbar-power-click)))
14940 (vhdl-speedbar-update-current-unit t t))
14941 ((string-match "-" text) ; we have to contract this node
14942 (speedbar-reset-scanners)
14943 (let ((oldl speedbar-shown-directories)
14944 (newl nil)
14945 (td (expand-file-name
14946 (concat (speedbar-line-directory indent) token))))
14947 (while oldl
14948 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14949 (setq newl (cons (car oldl) newl)))
14950 (setq oldl (cdr oldl)))
14951 (setq speedbar-shown-directories (nreverse newl)))
14952 (speedbar-change-expand-button-char ?+)
14953 (speedbar-delete-subblock indent))
14954 (t (error "Nothing to display")))
14955 (when (equal (selected-frame) speedbar-frame)
14956 (speedbar-center-buffer-smartly)))
14957
14958 (defun vhdl-speedbar-item-info ()
14959 "Derive and display information about this line item."
14960 (save-excursion
14961 (beginning-of-line)
14962 ;; skip invisible number info
14963 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14964 (cond
14965 ;; project/directory entry
14966 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14967 (if vhdl-speedbar-show-projects
14968 (message "Project \"%s\"" (match-string-no-properties 1))
14969 (speedbar-files-item-info)))
14970 ;; design unit entry
14971 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14972 (goto-char (match-end 1))
14973 (let ((face (get-text-property (point) 'face)))
14974 (message
14975 "%s \"%s\" in \"%s\""
14976 ;; design unit kind
14977 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14978 (eq face 'vhdl-speedbar-entity-selected-face))
14979 (if (equal (match-string 2) ">") "Component" "Entity"))
14980 ((or (eq face 'vhdl-speedbar-architecture-face)
14981 (eq face 'vhdl-speedbar-architecture-selected-face))
14982 "Architecture")
14983 ((or (eq face 'vhdl-speedbar-configuration-face)
14984 (eq face 'vhdl-speedbar-configuration-selected-face))
14985 "Configuration")
14986 ((or (eq face 'vhdl-speedbar-package-face)
14987 (eq face 'vhdl-speedbar-package-selected-face))
14988 "Package")
14989 ((or (eq face 'vhdl-speedbar-instantiation-face)
14990 (eq face 'vhdl-speedbar-instantiation-selected-face))
14991 "Instantiation")
14992 ((eq face 'vhdl-speedbar-subprogram-face)
14993 "Subprogram")
14994 (t ""))
14995 ;; design unit name
14996 (buffer-substring-no-properties
14997 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14998 (match-end 1))
14999 ;; file name
15000 (file-relative-name
15001 (or (car (get-text-property (point) 'speedbar-token))
15002 "?")
15003 (vhdl-default-directory)))))
15004 (t (message "")))))
15005
15006 (defun vhdl-speedbar-line-text ()
15007 "Calls `speedbar-line-text' and removes text properties."
15008 (let ((string (speedbar-line-text)))
15009 (set-text-properties 0 (length string) nil string)
15010 string))
15011
15012 (defun vhdl-speedbar-higher-text ()
15013 "Get speedbar-line-text of higher level."
15014 (let (depth string)
15015 (save-excursion
15016 (beginning-of-line)
15017 (looking-at "^\\([0-9]+\\):")
15018 (setq depth (string-to-number (match-string 1)))
15019 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15020 (setq string (match-string 1))
15021 (set-text-properties 0 (length string) nil string)
15022 string))))
15023
15024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15025 ;; Help functions
15026
15027 (defun vhdl-speedbar-line-key (&optional indent)
15028 "Get currently displayed directory of project name."
15029 (if vhdl-speedbar-show-projects
15030 (vhdl-speedbar-line-project)
15031 (abbreviate-file-name
15032 (file-name-as-directory (speedbar-line-directory indent)))))
15033
15034 (defun vhdl-speedbar-line-project (&optional indent)
15035 "Get currently displayed project name."
15036 (and vhdl-speedbar-show-projects
15037 (save-excursion
15038 (end-of-line)
15039 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15040 (match-string-no-properties 1))))
15041
15042 (defun vhdl-add-modified-file ()
15043 "Add file to `vhdl-modified-file-list'."
15044 (when vhdl-file-alist
15045 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15046 nil)
15047
15048 (defun vhdl-resolve-paths (path-list)
15049 "Resolve path wildcards in PATH-LIST."
15050 (let (path-list-1 path-list-2 path-beg path-end dir)
15051 ;; eliminate non-existent directories
15052 (while path-list
15053 (setq dir (car path-list))
15054 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15055 (if (file-directory-p (match-string 2 dir))
15056 (setq path-list-1 (cons dir path-list-1))
15057 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15058 (setq path-list (cdr path-list)))
15059 ;; resolve path wildcards
15060 (while path-list-1
15061 (setq dir (car path-list-1))
15062 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15063 (progn
15064 (setq path-beg (match-string 1 dir)
15065 path-end (match-string 5 dir))
15066 (setq path-list-1
15067 (append
15068 (mapcar
15069 (function
15070 (lambda (var) (concat path-beg var path-end)))
15071 (let ((all-list (vhdl-directory-files
15072 (match-string 2 dir) t
15073 (concat "\\<" (wildcard-to-regexp
15074 (match-string 4 dir)))))
15075 dir-list)
15076 (while all-list
15077 (when (file-directory-p (car all-list))
15078 (setq dir-list (cons (car all-list) dir-list)))
15079 (setq all-list (cdr all-list)))
15080 dir-list))
15081 (cdr path-list-1))))
15082 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15083 (when (file-directory-p (match-string 2 dir))
15084 (setq path-list-2 (cons dir path-list-2)))
15085 (setq path-list-1 (cdr path-list-1))))
15086 (nreverse path-list-2)))
15087
15088 (defun vhdl-speedbar-goto-this-unit (directory unit)
15089 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15090 (let ((dest (point)))
15091 (if (and (if vhdl-speedbar-show-projects
15092 (progn (goto-char (point-min)) t)
15093 (speedbar-goto-this-file directory))
15094 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15095 (progn (speedbar-position-cursor-on-line)
15096 t)
15097 (goto-char dest)
15098 nil)))
15099
15100 (defun vhdl-speedbar-find-file (text token indent)
15101 "When user clicks on TEXT, load file with name and position in TOKEN.
15102 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15103 is already shown in a buffer."
15104 (if (not (car token))
15105 (error "ERROR: File cannot be found")
15106 (let ((buffer (get-file-buffer (car token))))
15107 (speedbar-find-file-in-frame (car token))
15108 (when (or vhdl-speedbar-jump-to-unit buffer)
15109 (goto-char (point-min))
15110 (forward-line (1- (cdr token)))
15111 (recenter))
15112 (vhdl-speedbar-update-current-unit t t)
15113 (speedbar-set-timer dframe-update-speed)
15114 (speedbar-maybee-jump-to-attached-frame))))
15115
15116 (defun vhdl-speedbar-port-copy ()
15117 "Copy the port of the entity/component or subprogram under the cursor."
15118 (interactive)
15119 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15120 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15121 (error "ERROR: No entity/component or subprogram under cursor")
15122 (beginning-of-line)
15123 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15124 (condition-case info
15125 (let ((token (get-text-property
15126 (match-beginning 3) 'speedbar-token)))
15127 (vhdl-visit-file (car token) t
15128 (progn (goto-char (point-min))
15129 (forward-line (1- (cdr token)))
15130 (end-of-line)
15131 (if is-entity
15132 (vhdl-port-copy)
15133 (vhdl-subprog-copy)))))
15134 (error (error "ERROR: %s not scanned successfully\n (%s)"
15135 (if is-entity "Port" "Interface") (cadr info))))
15136 (error "ERROR: No entity/component or subprogram on current line")))))
15137
15138 (defun vhdl-speedbar-place-component ()
15139 "Place the entity/component under the cursor as component."
15140 (interactive)
15141 (if (not (vhdl-speedbar-check-unit 'entity))
15142 (error "ERROR: No entity/component under cursor")
15143 (vhdl-speedbar-port-copy)
15144 (if (fboundp 'speedbar-select-attached-frame)
15145 (speedbar-select-attached-frame)
15146 (select-frame speedbar-attached-frame))
15147 (vhdl-compose-place-component)
15148 (select-frame speedbar-frame)))
15149
15150 (defun vhdl-speedbar-configuration ()
15151 "Generate configuration for the architecture under the cursor."
15152 (interactive)
15153 (if (not (vhdl-speedbar-check-unit 'architecture))
15154 (error "ERROR: No architecture under cursor")
15155 (let ((arch-name (vhdl-speedbar-line-text))
15156 (ent-name (vhdl-speedbar-higher-text)))
15157 (if (fboundp 'speedbar-select-attached-frame)
15158 (speedbar-select-attached-frame)
15159 (select-frame speedbar-attached-frame))
15160 (vhdl-compose-configuration ent-name arch-name))))
15161
15162 (defun vhdl-speedbar-select-mra ()
15163 "Select the architecture under the cursor as MRA."
15164 (interactive)
15165 (if (not (vhdl-speedbar-check-unit 'architecture))
15166 (error "ERROR: No architecture under cursor")
15167 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15168 (ent-key (downcase (vhdl-speedbar-higher-text)))
15169 (ent-alist (aget vhdl-entity-alist
15170 (or (vhdl-project-p) default-directory) t))
15171 (ent-entry (aget ent-alist ent-key t)))
15172 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15173 (speedbar-refresh))))
15174
15175 (defun vhdl-speedbar-make-design ()
15176 "Make (compile) design unit or directory/project under the cursor."
15177 (interactive)
15178 (if (not (save-excursion (beginning-of-line)
15179 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15180 (error "ERROR: No primary design unit or directory/project under cursor")
15181 (let ((is-unit (match-string 2))
15182 (unit-name (vhdl-speedbar-line-text))
15183 (vhdl-project (vhdl-speedbar-line-project))
15184 (directory (file-name-as-directory
15185 (or (speedbar-line-file) (speedbar-line-directory)))))
15186 (if (fboundp 'speedbar-select-attached-frame)
15187 (speedbar-select-attached-frame)
15188 (select-frame speedbar-attached-frame))
15189 (let ((default-directory directory))
15190 (vhdl-make (and is-unit unit-name))))))
15191
15192 (defun vhdl-speedbar-generate-makefile ()
15193 "Generate Makefile for directory/project under the cursor."
15194 (interactive)
15195 (let ((vhdl-project (vhdl-speedbar-line-project))
15196 (default-directory (file-name-as-directory
15197 (or (speedbar-line-file) (speedbar-line-directory)))))
15198 (vhdl-generate-makefile)))
15199
15200 (defun vhdl-speedbar-check-unit (design-unit)
15201 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15202 expansion function)."
15203 (save-excursion
15204 (speedbar-position-cursor-on-line)
15205 (cond ((eq design-unit 'entity)
15206 (memq (get-text-property (match-end 0) 'face)
15207 '(vhdl-speedbar-entity-face
15208 vhdl-speedbar-entity-selected-face)))
15209 ((eq design-unit 'architecture)
15210 (memq (get-text-property (match-end 0) 'face)
15211 '(vhdl-speedbar-architecture-face
15212 vhdl-speedbar-architecture-selected-face)))
15213 ((eq design-unit 'subprogram)
15214 (eq (get-text-property (match-end 0) 'face)
15215 'vhdl-speedbar-subprogram-face))
15216 (t nil))))
15217
15218 (defun vhdl-speedbar-set-depth (depth)
15219 "Set hierarchy display depth to DEPTH and refresh speedbar."
15220 (setq vhdl-speedbar-hierarchy-depth depth)
15221 (speedbar-refresh))
15222
15223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15224 ;; Fontification
15225
15226 (defface vhdl-speedbar-entity-face
15227 '((((class color) (background light)) (:foreground "ForestGreen"))
15228 (((class color) (background dark)) (:foreground "PaleGreen")))
15229 "Face used for displaying entity names."
15230 :group 'speedbar-faces)
15231
15232 (defface vhdl-speedbar-architecture-face
15233 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15234 (((class color) (background light)) (:foreground "Blue"))
15235
15236 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15237 "Face used for displaying architecture names."
15238 :group 'speedbar-faces)
15239
15240 (defface vhdl-speedbar-configuration-face
15241 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15242 (((class color) (background dark)) (:foreground "Salmon")))
15243 "Face used for displaying configuration names."
15244 :group 'speedbar-faces)
15245
15246 (defface vhdl-speedbar-package-face
15247 '((((class color) (background light)) (:foreground "Grey50"))
15248 (((class color) (background dark)) (:foreground "Grey80")))
15249 "Face used for displaying package names."
15250 :group 'speedbar-faces)
15251
15252 (defface vhdl-speedbar-library-face
15253 '((((class color) (background light)) (:foreground "Purple"))
15254 (((class color) (background dark)) (:foreground "Orchid1")))
15255 "Face used for displaying library names."
15256 :group 'speedbar-faces)
15257
15258 (defface vhdl-speedbar-instantiation-face
15259 '((((class color) (background light)) (:foreground "Brown"))
15260 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15261 (((class color) (background dark)) (:foreground "Yellow")))
15262 "Face used for displaying instantiation names."
15263 :group 'speedbar-faces)
15264
15265 (defface vhdl-speedbar-subprogram-face
15266 '((((class color) (background light)) (:foreground "Orchid4"))
15267 (((class color) (background dark)) (:foreground "BurlyWood2")))
15268 "Face used for displaying subprogram names."
15269 :group 'speedbar-faces)
15270
15271 (defface vhdl-speedbar-entity-selected-face
15272 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15273 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15274 "Face used for displaying entity names."
15275 :group 'speedbar-faces)
15276
15277 (defface vhdl-speedbar-architecture-selected-face
15278 '((((min-colors 88) (class color) (background light)) (:foreground
15279 "Blue1" :underline t))
15280 (((class color) (background light)) (:foreground "Blue" :underline t))
15281 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15282 "Face used for displaying architecture names."
15283 :group 'speedbar-faces)
15284
15285 (defface vhdl-speedbar-configuration-selected-face
15286 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15287 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15288 "Face used for displaying configuration names."
15289 :group 'speedbar-faces)
15290
15291 (defface vhdl-speedbar-package-selected-face
15292 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15293 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15294 "Face used for displaying package names."
15295 :group 'speedbar-faces)
15296
15297 (defface vhdl-speedbar-instantiation-selected-face
15298 '((((class color) (background light)) (:foreground "Brown" :underline t))
15299 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15300 "Face used for displaying instantiation names."
15301 :group 'speedbar-faces)
15302
15303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15304 ;; Initialization
15305
15306 ;; add speedbar
15307 (when (fboundp 'speedbar)
15308 (condition-case ()
15309 (when (and vhdl-speedbar-auto-open
15310 (not (and (boundp 'speedbar-frame)
15311 (frame-live-p speedbar-frame))))
15312 (speedbar-frame-mode 1)
15313 (if (fboundp 'speedbar-select-attached-frame)
15314 (speedbar-select-attached-frame)
15315 (select-frame speedbar-attached-frame)))
15316 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15317
15318 ;; initialize speedbar
15319 (if (not (boundp 'speedbar-frame))
15320 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15321 (vhdl-speedbar-initialize)
15322 (when speedbar-frame (vhdl-speedbar-refresh)))
15323
15324
15325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15326 ;;; Structural composition
15327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15328
15329 (defun vhdl-get-components-package-name ()
15330 "Return the name of the components package."
15331 (let ((project (vhdl-project-p)))
15332 (if project
15333 (vhdl-replace-string (car vhdl-components-package-name)
15334 (subst-char-in-string ? ?_ project))
15335 (cdr vhdl-components-package-name))))
15336
15337 (defun vhdl-compose-new-component ()
15338 "Create entity and architecture for new component."
15339 (interactive)
15340 (let* ((case-fold-search t)
15341 (ent-name (read-from-minibuffer "entity name: "
15342 nil vhdl-minibuffer-local-map))
15343 (arch-name
15344 (if (equal (cdr vhdl-compose-architecture-name) "")
15345 (read-from-minibuffer "architecture name: "
15346 nil vhdl-minibuffer-local-map)
15347 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15348 ent-file-name arch-file-name ent-buffer arch-buffer project)
15349 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15350 ;; open entity file
15351 (unless (eq vhdl-compose-create-files 'none)
15352 (setq ent-file-name
15353 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15354 "." (file-name-extension (buffer-file-name))))
15355 (when (and (file-exists-p ent-file-name)
15356 (not (y-or-n-p (concat "File \"" ent-file-name
15357 "\" exists; overwrite? "))))
15358 (error "ERROR: Creating component...aborted"))
15359 (find-file ent-file-name)
15360 (erase-buffer)
15361 (set-buffer-modified-p nil))
15362 ;; insert header
15363 (if vhdl-compose-include-header
15364 (progn (vhdl-template-header)
15365 (goto-char (point-max)))
15366 (vhdl-comment-display-line) (insert "\n\n"))
15367 ;; insert library clause
15368 (vhdl-template-package-std-logic-1164)
15369 (when vhdl-use-components-package
15370 (insert "\n")
15371 (vhdl-template-standard-package (vhdl-work-library)
15372 (vhdl-get-components-package-name)))
15373 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15374 ;; insert entity declaration
15375 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15376 (vhdl-insert-keyword " IS\n")
15377 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15378 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15379 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15380 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15381 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15382 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15383 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15384 (vhdl-insert-keyword "END ")
15385 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15386 (insert ent-name ";\n\n")
15387 (vhdl-comment-display-line) (insert "\n")
15388 ;; open architecture file
15389 (if (not (eq vhdl-compose-create-files 'separate))
15390 (insert "\n")
15391 (setq ent-buffer (current-buffer))
15392 (setq arch-file-name
15393 (concat (vhdl-replace-string vhdl-architecture-file-name
15394 (concat ent-name " " arch-name) t)
15395 "." (file-name-extension (buffer-file-name))))
15396 (when (and (file-exists-p arch-file-name)
15397 (not (y-or-n-p (concat "File \"" arch-file-name
15398 "\" exists; overwrite? "))))
15399 (error "ERROR: Creating component...aborted"))
15400 (find-file arch-file-name)
15401 (erase-buffer)
15402 (set-buffer-modified-p nil)
15403 ;; insert header
15404 (if vhdl-compose-include-header
15405 (progn (vhdl-template-header)
15406 (goto-char (point-max)))
15407 (vhdl-comment-display-line) (insert "\n\n")))
15408 ;; insert architecture body
15409 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15410 (vhdl-insert-keyword " OF ") (insert ent-name)
15411 (vhdl-insert-keyword " IS\n\n")
15412 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15413 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15414 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15415 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15416 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15417 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15418 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15419 (vhdl-insert-keyword "BEGIN")
15420 (when vhdl-self-insert-comments
15421 (insert " -- ")
15422 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15423 (insert arch-name))
15424 (insert "\n\n")
15425 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15426 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15427 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15428 (vhdl-insert-keyword "END ")
15429 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15430 (insert arch-name ";\n\n")
15431 ;; insert footer and save
15432 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15433 (vhdl-template-footer)
15434 (vhdl-comment-display-line) (insert "\n"))
15435 (goto-char (point-min))
15436 (setq arch-buffer (current-buffer))
15437 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15438 (set-buffer arch-buffer) (save-buffer)
15439 (message "%s"
15440 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15441 (and ent-file-name
15442 (format "\n File created: \"%s\"" ent-file-name))
15443 (and arch-file-name
15444 (format "\n File created: \"%s\"" arch-file-name))))))
15445
15446 (defun vhdl-compose-place-component ()
15447 "Place new component by pasting current port as component declaration and
15448 component instantiation."
15449 (interactive)
15450 (if (not vhdl-port-list)
15451 (error "ERROR: No port has been read")
15452 (save-excursion
15453 (vhdl-prepare-search-2
15454 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15455 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15456 (error "ERROR: No architecture found"))
15457 (let* ((ent-name (match-string 1))
15458 (ent-file-name
15459 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15460 "." (file-name-extension (buffer-file-name))))
15461 (orig-buffer (current-buffer)))
15462 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15463 ;; place component declaration
15464 (unless (or vhdl-use-components-package
15465 (vhdl-use-direct-instantiation)
15466 (save-excursion
15467 (re-search-forward
15468 (concat "^\\s-*component\\s-+"
15469 (car vhdl-port-list) "\\>") nil t)))
15470 (re-search-forward "^begin\\>" nil)
15471 (beginning-of-line)
15472 (skip-chars-backward " \t\n")
15473 (insert "\n\n") (indent-to vhdl-basic-offset)
15474 (vhdl-port-paste-component t))
15475 ;; place component instantiation
15476 (re-search-forward "^end\\>" nil)
15477 (beginning-of-line)
15478 (skip-chars-backward " \t\n")
15479 (insert "\n\n") (indent-to vhdl-basic-offset)
15480 (vhdl-port-paste-instance nil t t)
15481 ;; place use clause for used packages
15482 (when (nth 3 vhdl-port-list)
15483 ;; open entity file
15484 (when (file-exists-p ent-file-name)
15485 (find-file ent-file-name))
15486 (goto-char (point-min))
15487 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15488 (error "ERROR: Entity not found: \"%s\"" ent-name))
15489 (goto-char (match-beginning 0))
15490 (if (and (save-excursion
15491 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15492 (match-string 1))
15493 (progn (goto-char (match-end 0))
15494 (beginning-of-line 2))
15495 (insert "\n")
15496 (backward-char))
15497 (vhdl-port-paste-context-clause)
15498 (switch-to-buffer orig-buffer))
15499 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15500
15501 (defun vhdl-compose-wire-components ()
15502 "Connect components."
15503 (interactive)
15504 (save-excursion
15505 (vhdl-prepare-search-2
15506 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15507 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15508 (error "ERROR: No architecture found"))
15509 (let* ((ent-name (match-string 1))
15510 (ent-file-name
15511 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15512 "." (file-name-extension (buffer-file-name))))
15513 (arch-decl-pos (point-marker))
15514 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15515 (arch-end-pos (re-search-forward "^end\\>" nil))
15516 (pack-name (vhdl-get-components-package-name))
15517 (pack-file-name
15518 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15519 "." (file-name-extension (buffer-file-name))))
15520 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15521 port-alist generic-alist inst-alist
15522 signal-name signal-entry signal-alist local-list written-list
15523 single-in-list multi-in-list single-out-list multi-out-list
15524 constant-name constant-entry constant-alist single-list multi-list
15525 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15526 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15527 signal-beg-pos signal-pos
15528 constant-temp-pos port-temp-pos signal-temp-pos)
15529 (message "Wiring components...")
15530 ;; process all instances
15531 (goto-char arch-stat-pos)
15532 (while (re-search-forward
15533 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15534 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15535 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15536 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15537 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15538 (setq inst-name (match-string-no-properties 1)
15539 comp-name (match-string-no-properties 4)
15540 comp-ent-name (match-string-no-properties 12)
15541 has-generic (or (match-string 7) (match-string 17)))
15542 ;; get port ...
15543 (if comp-name
15544 ;; ... from component declaration
15545 (vhdl-visit-file
15546 (when vhdl-use-components-package pack-file-name) t
15547 (save-excursion
15548 (goto-char (point-min))
15549 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15550 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15551 (vhdl-port-copy)))
15552 ;; ... from entity declaration (direct instantiation)
15553 (setq comp-ent-file-name
15554 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15555 "." (file-name-extension (buffer-file-name))))
15556 (vhdl-visit-file
15557 comp-ent-file-name t
15558 (save-excursion
15559 (goto-char (point-min))
15560 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15561 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15562 (vhdl-port-copy))))
15563 (vhdl-port-flatten t)
15564 (setq generic-alist (nth 1 vhdl-port-list)
15565 port-alist (nth 2 vhdl-port-list)
15566 vhdl-port-list nil)
15567 (setq constant-alist nil
15568 signal-alist nil)
15569 (when has-generic
15570 ;; process all constants in generic map
15571 (vhdl-forward-syntactic-ws)
15572 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15573 (setq constant-name (match-string-no-properties 3))
15574 (setq constant-entry
15575 (cons constant-name
15576 (if (match-string 1)
15577 (or (aget generic-alist (match-string 2) t)
15578 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15579 (cdar generic-alist))))
15580 (setq constant-alist (cons constant-entry constant-alist))
15581 (setq constant-name (downcase constant-name))
15582 (if (or (member constant-name single-list)
15583 (member constant-name multi-list))
15584 (progn (setq single-list (delete constant-name single-list))
15585 (add-to-list 'multi-list constant-name))
15586 (add-to-list 'single-list constant-name))
15587 (unless (match-string 1)
15588 (setq generic-alist (cdr generic-alist)))
15589 (vhdl-forward-syntactic-ws))
15590 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15591 ;; process all signals in port map
15592 (vhdl-forward-syntactic-ws)
15593 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15594 (setq signal-name (match-string-no-properties 3))
15595 (setq signal-entry (cons signal-name
15596 (if (match-string 1)
15597 (or (aget port-alist (match-string 2) t)
15598 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15599 (cdar port-alist))))
15600 (setq signal-alist (cons signal-entry signal-alist))
15601 (setq signal-name (downcase signal-name))
15602 (if (equal (upcase (nth 2 signal-entry)) "IN")
15603 ;; input signal
15604 (cond
15605 ((member signal-name local-list)
15606 nil)
15607 ((or (member signal-name single-out-list)
15608 (member signal-name multi-out-list))
15609 (setq single-out-list (delete signal-name single-out-list))
15610 (setq multi-out-list (delete signal-name multi-out-list))
15611 (add-to-list 'local-list signal-name))
15612 ((member signal-name single-in-list)
15613 (setq single-in-list (delete signal-name single-in-list))
15614 (add-to-list 'multi-in-list signal-name))
15615 ((not (member signal-name multi-in-list))
15616 (add-to-list 'single-in-list signal-name)))
15617 ;; output signal
15618 (cond
15619 ((member signal-name local-list)
15620 nil)
15621 ((or (member signal-name single-in-list)
15622 (member signal-name multi-in-list))
15623 (setq single-in-list (delete signal-name single-in-list))
15624 (setq multi-in-list (delete signal-name multi-in-list))
15625 (add-to-list 'local-list signal-name))
15626 ((member signal-name single-out-list)
15627 (setq single-out-list (delete signal-name single-out-list))
15628 (add-to-list 'multi-out-list signal-name))
15629 ((not (member signal-name multi-out-list))
15630 (add-to-list 'single-out-list signal-name))))
15631 (unless (match-string 1)
15632 (setq port-alist (cdr port-alist)))
15633 (vhdl-forward-syntactic-ws))
15634 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15635 (nreverse signal-alist)) inst-alist)))
15636 ;; prepare signal insertion
15637 (vhdl-goto-marker arch-decl-pos)
15638 (forward-line 1)
15639 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15640 (setq signal-pos (point-marker))
15641 (while (progn (vhdl-forward-syntactic-ws)
15642 (looking-at "signal\\>"))
15643 (beginning-of-line 2)
15644 (delete-region signal-pos (point)))
15645 (setq signal-beg-pos signal-pos)
15646 ;; open entity file
15647 (when (file-exists-p ent-file-name)
15648 (find-file ent-file-name))
15649 (goto-char (point-min))
15650 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15651 (error "ERROR: Entity not found: \"%s\"" ent-name))
15652 ;; prepare generic clause insertion
15653 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15654 (match-string 1))
15655 (goto-char (match-beginning 0))
15656 (indent-to vhdl-basic-offset)
15657 (insert "generic ();\n\n")
15658 (backward-char 4))
15659 (backward-char)
15660 (setq generic-pos (point-marker))
15661 (forward-sexp) (end-of-line)
15662 (delete-region generic-pos (point)) (delete-char 1)
15663 (insert "(\n")
15664 (when multi-list
15665 (insert "\n")
15666 (indent-to (* 2 vhdl-basic-offset))
15667 (insert "-- global generics\n"))
15668 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15669 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15670 ;; prepare port clause insertion
15671 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15672 (match-string 1))
15673 (goto-char (match-beginning 0))
15674 (indent-to vhdl-basic-offset)
15675 (insert "port ();\n\n")
15676 (backward-char 4))
15677 (backward-char)
15678 (setq port-in-pos (point-marker))
15679 (forward-sexp) (end-of-line)
15680 (delete-region port-in-pos (point)) (delete-char 1)
15681 (insert "(\n")
15682 (when (or multi-in-list multi-out-list)
15683 (insert "\n")
15684 (indent-to (* 2 vhdl-basic-offset))
15685 (insert "-- global ports\n"))
15686 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15687 port-out-pos (point-marker) port-inst-pos (point-marker)
15688 port-end-pos (point-marker))
15689 ;; insert generics, ports and signals
15690 (setq inst-alist (nreverse inst-alist))
15691 (while inst-alist
15692 (setq inst-name (nth 0 (car inst-alist))
15693 constant-alist (nth 1 (car inst-alist))
15694 signal-alist (nth 2 (car inst-alist))
15695 constant-temp-pos generic-inst-pos
15696 port-temp-pos port-inst-pos
15697 signal-temp-pos signal-pos)
15698 ;; generics
15699 (while constant-alist
15700 (setq constant-name (downcase (caar constant-alist))
15701 constant-entry (car constant-alist))
15702 (cond ((member constant-name written-list)
15703 nil)
15704 ((member constant-name multi-list)
15705 (vhdl-goto-marker generic-pos)
15706 (setq generic-end-pos
15707 (vhdl-max-marker
15708 generic-end-pos
15709 (vhdl-compose-insert-generic constant-entry)))
15710 (setq generic-pos (point-marker))
15711 (add-to-list 'written-list constant-name))
15712 (t
15713 (vhdl-goto-marker
15714 (vhdl-max-marker generic-inst-pos generic-pos))
15715 (setq generic-end-pos
15716 (vhdl-compose-insert-generic constant-entry))
15717 (setq generic-inst-pos (point-marker))
15718 (add-to-list 'written-list constant-name)))
15719 (setq constant-alist (cdr constant-alist)))
15720 (when (/= constant-temp-pos generic-inst-pos)
15721 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15722 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15723 (insert "-- generics for \"" inst-name "\"\n")
15724 (vhdl-goto-marker generic-inst-pos))
15725 ;; ports and signals
15726 (while signal-alist
15727 (setq signal-name (downcase (caar signal-alist))
15728 signal-entry (car signal-alist))
15729 (cond ((member signal-name written-list)
15730 nil)
15731 ((member signal-name multi-in-list)
15732 (vhdl-goto-marker port-in-pos)
15733 (setq port-end-pos
15734 (vhdl-max-marker
15735 port-end-pos (vhdl-compose-insert-port signal-entry)))
15736 (setq port-in-pos (point-marker))
15737 (add-to-list 'written-list signal-name))
15738 ((member signal-name multi-out-list)
15739 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15740 (setq port-end-pos
15741 (vhdl-max-marker
15742 port-end-pos (vhdl-compose-insert-port signal-entry)))
15743 (setq port-out-pos (point-marker))
15744 (add-to-list 'written-list signal-name))
15745 ((or (member signal-name single-in-list)
15746 (member signal-name single-out-list))
15747 (vhdl-goto-marker
15748 (vhdl-max-marker
15749 port-inst-pos
15750 (vhdl-max-marker port-out-pos port-in-pos)))
15751 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15752 (setq port-inst-pos (point-marker))
15753 (add-to-list 'written-list signal-name))
15754 ((equal (upcase (nth 2 signal-entry)) "OUT")
15755 (vhdl-goto-marker signal-pos)
15756 (vhdl-compose-insert-signal signal-entry)
15757 (setq signal-pos (point-marker))
15758 (add-to-list 'written-list signal-name)))
15759 (setq signal-alist (cdr signal-alist)))
15760 (when (/= port-temp-pos port-inst-pos)
15761 (vhdl-goto-marker
15762 (vhdl-max-marker port-temp-pos
15763 (vhdl-max-marker port-in-pos port-out-pos)))
15764 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15765 (insert "-- ports to \"" inst-name "\"\n")
15766 (vhdl-goto-marker port-inst-pos))
15767 (when (/= signal-temp-pos signal-pos)
15768 (vhdl-goto-marker signal-temp-pos)
15769 (insert "\n") (indent-to vhdl-basic-offset)
15770 (insert "-- outputs of \"" inst-name "\"\n")
15771 (vhdl-goto-marker signal-pos))
15772 (setq inst-alist (cdr inst-alist)))
15773 ;; finalize generic/port clause
15774 (vhdl-goto-marker generic-end-pos) (backward-char)
15775 (when (= generic-beg-pos generic-end-pos)
15776 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15777 (insert ";") (backward-char))
15778 (insert ")")
15779 (vhdl-goto-marker port-end-pos) (backward-char)
15780 (when (= port-beg-pos port-end-pos)
15781 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15782 (insert ";") (backward-char))
15783 (insert ")")
15784 ;; align everything
15785 (when vhdl-auto-align
15786 (vhdl-goto-marker generic-beg-pos)
15787 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15788 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15789 (vhdl-goto-marker signal-beg-pos)
15790 (vhdl-align-region-groups signal-beg-pos signal-pos))
15791 (switch-to-buffer (marker-buffer signal-beg-pos))
15792 (message "Wiring components...done")))))
15793
15794 (defun vhdl-compose-insert-generic (entry)
15795 "Insert ENTRY as generic declaration."
15796 (let (pos)
15797 (indent-to (* 2 vhdl-basic-offset))
15798 (insert (nth 0 entry) " : " (nth 1 entry))
15799 (when (nth 2 entry)
15800 (insert " := " (nth 2 entry)))
15801 (insert ";")
15802 (setq pos (point-marker))
15803 (when (and vhdl-include-port-comments (nth 3 entry))
15804 (vhdl-comment-insert-inline (nth 3 entry) t))
15805 (insert "\n")
15806 pos))
15807
15808 (defun vhdl-compose-insert-port (entry)
15809 "Insert ENTRY as port declaration."
15810 (let (pos)
15811 (indent-to (* 2 vhdl-basic-offset))
15812 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15813 (setq pos (point-marker))
15814 (when (and vhdl-include-port-comments (nth 4 entry))
15815 (vhdl-comment-insert-inline (nth 4 entry) t))
15816 (insert "\n")
15817 pos))
15818
15819 (defun vhdl-compose-insert-signal (entry)
15820 "Insert ENTRY as signal declaration."
15821 (indent-to vhdl-basic-offset)
15822 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15823 (when (and vhdl-include-port-comments (nth 4 entry))
15824 (vhdl-comment-insert-inline (nth 4 entry) t))
15825 (insert "\n"))
15826
15827 (defun vhdl-compose-components-package ()
15828 "Generate a package containing component declarations for all entities in the
15829 current project/directory."
15830 (interactive)
15831 (vhdl-require-hierarchy-info)
15832 (let* ((project (vhdl-project-p))
15833 (pack-name (vhdl-get-components-package-name))
15834 (pack-file-name
15835 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15836 "." (file-name-extension (buffer-file-name))))
15837 (ent-alist (aget vhdl-entity-alist
15838 (or project default-directory) t))
15839 (lazy-lock-minimum-size 0)
15840 clause-pos component-pos)
15841 (message "Generating components package \"%s\"..." pack-name)
15842 ;; open package file
15843 (when (and (file-exists-p pack-file-name)
15844 (not (y-or-n-p (concat "File \"" pack-file-name
15845 "\" exists; overwrite? "))))
15846 (error "ERROR: Generating components package...aborted"))
15847 (find-file pack-file-name)
15848 (erase-buffer)
15849 ;; insert header
15850 (if vhdl-compose-include-header
15851 (progn (vhdl-template-header
15852 (concat "Components package (generated by Emacs VHDL Mode "
15853 vhdl-version ")"))
15854 (goto-char (point-max)))
15855 (vhdl-comment-display-line) (insert "\n\n"))
15856 ;; insert std_logic_1164 package
15857 (vhdl-template-package-std-logic-1164)
15858 (insert "\n") (setq clause-pos (point-marker))
15859 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15860 ;; insert package declaration
15861 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15862 (vhdl-insert-keyword " IS\n\n")
15863 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15864 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15865 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15866 (indent-to vhdl-basic-offset)
15867 (setq component-pos (point-marker))
15868 (insert "\n\n") (vhdl-insert-keyword "END ")
15869 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15870 (insert pack-name ";\n\n")
15871 ;; insert footer
15872 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15873 (vhdl-template-footer)
15874 (vhdl-comment-display-line) (insert "\n"))
15875 ;; insert component declarations
15876 (while ent-alist
15877 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15878 (progn (goto-char (point-min))
15879 (forward-line (1- (nth 3 (car ent-alist))))
15880 (end-of-line)
15881 (vhdl-port-copy)))
15882 (goto-char component-pos)
15883 (vhdl-port-paste-component t)
15884 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15885 (setq component-pos (point-marker))
15886 (goto-char clause-pos)
15887 (vhdl-port-paste-context-clause pack-name)
15888 (setq clause-pos (point-marker))
15889 (setq ent-alist (cdr ent-alist)))
15890 (goto-char (point-min))
15891 (save-buffer)
15892 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15893 pack-name pack-file-name)))
15894
15895 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15896 &optional insert-conf)
15897 "Generate block configuration for architecture."
15898 (let ((margin (current-indentation))
15899 (beg (point-at-bol))
15900 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15901 ;; insert block configuration (for architecture)
15902 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15903 (setq margin (+ margin vhdl-basic-offset))
15904 ;; process all instances
15905 (while inst-alist
15906 (setq inst-entry (car inst-alist))
15907 ;; is component?
15908 (when (nth 4 inst-entry)
15909 (setq insert-conf t)
15910 (setq inst-path (nth 9 inst-entry))
15911 ;; skip common path with previous instance
15912 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15913 (setq inst-path (cdr inst-path)
15914 inst-prev-path (cdr inst-prev-path)))
15915 ;; insert block configuration end (for previous block/generate)
15916 (while inst-prev-path
15917 (setq margin (- margin vhdl-basic-offset))
15918 (indent-to margin)
15919 (vhdl-insert-keyword "END FOR;\n")
15920 (setq inst-prev-path (cdr inst-prev-path)))
15921 ;; insert block configuration beginning (for current block/generate)
15922 (indent-to margin)
15923 (while inst-path
15924 (setq margin (+ margin vhdl-basic-offset))
15925 (vhdl-insert-keyword "FOR ")
15926 (insert (car inst-path) "\n")
15927 (indent-to margin)
15928 (setq inst-path (cdr inst-path)))
15929 ;; insert component configuration beginning
15930 (vhdl-insert-keyword "FOR ")
15931 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15932 ;; find subconfiguration
15933 (setq conf-key (nth 7 inst-entry))
15934 (setq tmp-alist conf-alist)
15935 ;; use first configuration found for instance's entity
15936 (while (and tmp-alist (null conf-key))
15937 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15938 (setq conf-key (nth 0 (car tmp-alist))))
15939 (setq tmp-alist (cdr tmp-alist)))
15940 (setq conf-entry (aget conf-alist conf-key t))
15941 ;; insert binding indication ...
15942 ;; ... with subconfiguration (if exists)
15943 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15944 (progn
15945 (indent-to (+ margin vhdl-basic-offset))
15946 (vhdl-insert-keyword "USE CONFIGURATION ")
15947 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15948 (insert ";\n"))
15949 ;; ... with entity (if exists)
15950 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15951 (when ent-entry
15952 (indent-to (+ margin vhdl-basic-offset))
15953 (vhdl-insert-keyword "USE ENTITY ")
15954 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15955 ;; insert architecture name (if architecture exists)
15956 (when (nth 3 ent-entry)
15957 (setq arch-name
15958 ;; choose architecture name a) from configuration,
15959 ;; b) from mra, or c) from first architecture
15960 (or (nth 0 (aget (nth 3 ent-entry)
15961 (or (nth 6 inst-entry)
15962 (nth 4 ent-entry)) t))
15963 (nth 1 (car (nth 3 ent-entry)))))
15964 (insert "(" arch-name ")"))
15965 (insert ";\n")
15966 ;; insert block configuration (for architecture of subcomponent)
15967 (when (and vhdl-compose-configuration-hierarchical
15968 (nth 3 ent-entry))
15969 (indent-to (+ margin vhdl-basic-offset))
15970 (vhdl-compose-configuration-architecture
15971 (nth 0 ent-entry) arch-name
15972 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15973 ;; insert component configuration end
15974 (indent-to margin)
15975 (vhdl-insert-keyword "END FOR;\n")
15976 (setq inst-prev-path (nth 9 inst-entry)))
15977 (setq inst-alist (cdr inst-alist)))
15978 ;; insert block configuration end (for block/generate)
15979 (while inst-prev-path
15980 (setq margin (- margin vhdl-basic-offset))
15981 (indent-to margin)
15982 (vhdl-insert-keyword "END FOR;\n")
15983 (setq inst-prev-path (cdr inst-prev-path)))
15984 (indent-to (- margin vhdl-basic-offset))
15985 ;; insert block configuration end or remove beginning (for architecture)
15986 (if insert-conf
15987 (vhdl-insert-keyword "END FOR;\n")
15988 (delete-region beg (point)))))
15989
15990 (defun vhdl-compose-configuration (&optional ent-name arch-name)
15991 "Generate configuration declaration."
15992 (interactive)
15993 (vhdl-require-hierarchy-info)
15994 (let ((ent-alist (aget vhdl-entity-alist
15995 (or (vhdl-project-p) default-directory) t))
15996 (conf-alist (aget vhdl-config-alist
15997 (or (vhdl-project-p) default-directory) t))
15998 (from-speedbar ent-name)
15999 inst-alist conf-name conf-file-name pos)
16000 (vhdl-prepare-search-2
16001 ;; get entity and architecture name
16002 (unless ent-name
16003 (save-excursion
16004 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16005 (not (equal "END" (upcase (match-string 1))))
16006 (setq ent-name (match-string-no-properties 3))
16007 (setq arch-name (match-string-no-properties 2)))
16008 (error "ERROR: Not within an architecture"))))
16009 (setq conf-name (vhdl-replace-string
16010 vhdl-compose-configuration-name
16011 (concat ent-name " " arch-name)))
16012 (setq inst-alist
16013 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16014 (downcase arch-name) t))))
16015 (message "Generating configuration \"%s\"..." conf-name)
16016 (if vhdl-compose-configuration-create-file
16017 ;; open configuration file
16018 (progn
16019 (setq conf-file-name
16020 (concat (vhdl-replace-string vhdl-configuration-file-name
16021 conf-name t)
16022 "." (file-name-extension (buffer-file-name))))
16023 (when (and (file-exists-p conf-file-name)
16024 (not (y-or-n-p (concat "File \"" conf-file-name
16025 "\" exists; overwrite? "))))
16026 (error "ERROR: Creating configuration...aborted"))
16027 (find-file conf-file-name)
16028 (erase-buffer)
16029 (set-buffer-modified-p nil)
16030 ;; insert header
16031 (if vhdl-compose-include-header
16032 (progn (vhdl-template-header
16033 (concat "Configuration declaration for design \""
16034 ent-name "(" arch-name ")\""))
16035 (goto-char (point-max)))
16036 (vhdl-comment-display-line) (insert "\n\n")))
16037 ;; goto end of architecture
16038 (unless from-speedbar
16039 (re-search-forward "^end\\>" nil)
16040 (end-of-line) (insert "\n\n")
16041 (vhdl-comment-display-line) (insert "\n\n")))
16042 ;; insert library clause
16043 (setq pos (point))
16044 (vhdl-template-standard-package (vhdl-work-library) nil)
16045 (when (/= pos (point))
16046 (insert "\n\n"))
16047 ;; insert configuration
16048 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16049 (vhdl-insert-keyword " OF ") (insert ent-name)
16050 (vhdl-insert-keyword " IS\n")
16051 (indent-to vhdl-basic-offset)
16052 ;; insert block configuration (for architecture)
16053 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16054 (vhdl-insert-keyword "END ") (insert conf-name ";")
16055 (when conf-file-name
16056 ;; insert footer and save
16057 (insert "\n\n")
16058 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16059 (vhdl-template-footer)
16060 (vhdl-comment-display-line) (insert "\n"))
16061 (save-buffer))
16062 (message "%s"
16063 (concat (format "Generating configuration \"%s\"...done" conf-name)
16064 (and conf-file-name
16065 (format "\n File created: \"%s\"" conf-file-name))))))
16066
16067
16068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16069 ;;; Compilation / Makefile generation
16070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16071 ;; (using `compile.el')
16072
16073 (defun vhdl-makefile-name ()
16074 "Return the Makefile name of the current project or the current compiler if
16075 no project is defined."
16076 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16077 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16078 (vhdl-replace-string
16079 (cons "\\(.*\\)\n\\(.*\\)"
16080 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16081 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16082
16083 (defun vhdl-compile-directory ()
16084 "Return the directory where compilation/make should be run."
16085 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16086 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16087 (directory (vhdl-resolve-env-variable
16088 (if project
16089 (vhdl-replace-string
16090 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16091 (nth 6 compiler)))))
16092 (file-name-as-directory
16093 (if (file-name-absolute-p directory)
16094 directory
16095 (expand-file-name directory (vhdl-default-directory))))))
16096
16097 (defun vhdl-uniquify (in-list)
16098 "Remove duplicate elements from IN-LIST."
16099 (let (out-list)
16100 (while in-list
16101 (add-to-list 'out-list (car in-list))
16102 (setq in-list (cdr in-list)))
16103 out-list))
16104
16105 (defun vhdl-set-compiler (name)
16106 "Set current compiler to NAME."
16107 (interactive
16108 (list (let ((completion-ignore-case t))
16109 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16110 (if (assoc name vhdl-compiler-alist)
16111 (progn (setq vhdl-compiler name)
16112 (message "Current compiler: \"%s\"" vhdl-compiler))
16113 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16114
16115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16116 ;; Compilation
16117
16118 (defun vhdl-compile-init ()
16119 "Initialize for compilation."
16120 (when (or (null compilation-error-regexp-alist)
16121 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16122 compilation-error-regexp-alist)))
16123 ;; `compilation-error-regexp-alist'
16124 (let ((commands-alist vhdl-compiler-alist)
16125 regexp-alist sublist)
16126 (while commands-alist
16127 (setq sublist (nth 11 (car commands-alist)))
16128 (unless (or (equal "" (car sublist))
16129 (assoc (car sublist) regexp-alist))
16130 (setq regexp-alist (cons (list (nth 0 sublist)
16131 (if (= 0 (nth 1 sublist))
16132 (if (featurep 'xemacs) 9 nil)
16133 (nth 1 sublist))
16134 (nth 2 sublist) (nth 3 sublist))
16135 regexp-alist)))
16136 (setq commands-alist (cdr commands-alist)))
16137 (setq compilation-error-regexp-alist
16138 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16139 ;; `compilation-file-regexp-alist'
16140 (let ((commands-alist vhdl-compiler-alist)
16141 regexp-alist sublist)
16142 ;; matches vhdl-mode file name output
16143 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16144 (while commands-alist
16145 (setq sublist (nth 12 (car commands-alist)))
16146 (unless (or (equal "" (car sublist))
16147 (assoc (car sublist) regexp-alist))
16148 (setq regexp-alist (cons sublist regexp-alist)))
16149 (setq commands-alist (cdr commands-alist)))
16150 (setq compilation-file-regexp-alist
16151 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16152
16153 (defvar vhdl-compile-file-name nil
16154 "Name of file to be compiled.")
16155
16156 (defun vhdl-compile-print-file-name ()
16157 "Function called within `compile' to print out file name for compilers that
16158 do not print any file names."
16159 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16160
16161 (defun vhdl-get-compile-options (project compiler file-name
16162 &optional file-options-only)
16163 "Get compiler options. Returning nil means do not compile this file."
16164 (let* ((compiler-options (nth 1 compiler))
16165 (project-entry (aget (nth 4 project) vhdl-compiler))
16166 (project-options (nth 0 project-entry))
16167 (exception-list (and file-name (nth 2 project-entry)))
16168 (work-library (vhdl-work-library))
16169 (case-fold-search nil)
16170 file-options)
16171 (while (and exception-list
16172 (not (string-match (caar exception-list) file-name)))
16173 (setq exception-list (cdr exception-list)))
16174 (if (and exception-list (not (cdar exception-list)))
16175 nil
16176 (if (and file-options-only (not exception-list))
16177 'default
16178 (setq file-options (cdar exception-list))
16179 ;; insert library name in compiler-specific options
16180 (setq compiler-options
16181 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16182 work-library))
16183 ;; insert compiler-specific options in project-specific options
16184 (when project-options
16185 (setq project-options
16186 (vhdl-replace-string
16187 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16188 (concat work-library "\n" compiler-options))))
16189 ;; insert project-specific options in file-specific options
16190 (when file-options
16191 (setq file-options
16192 (vhdl-replace-string
16193 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16194 (concat work-library "\n" compiler-options "\n"
16195 project-options))))
16196 ;; return options
16197 (or file-options project-options compiler-options)))))
16198
16199 (defun vhdl-get-make-options (project compiler)
16200 "Get make options."
16201 (let* ((compiler-options (nth 3 compiler))
16202 (project-entry (aget (nth 4 project) vhdl-compiler))
16203 (project-options (nth 1 project-entry))
16204 (makefile-name (vhdl-makefile-name)))
16205 ;; insert Makefile name in compiler-specific options
16206 (setq compiler-options
16207 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16208 makefile-name))
16209 ;; insert compiler-specific options in project-specific options
16210 (when project-options
16211 (setq project-options
16212 (vhdl-replace-string
16213 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16214 (concat makefile-name "\n" compiler-options))))
16215 ;; return options
16216 (or project-options compiler-options)))
16217
16218 (defun vhdl-compile ()
16219 "Compile current buffer using the VHDL compiler specified in
16220 `vhdl-compiler'."
16221 (interactive)
16222 (vhdl-compile-init)
16223 (let* ((project (aget vhdl-project-alist vhdl-project))
16224 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16225 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16226 (command (nth 0 compiler))
16227 (file-name (buffer-file-name))
16228 (options (vhdl-get-compile-options project compiler file-name))
16229 (default-directory (vhdl-compile-directory))
16230 compilation-process-setup-function)
16231 (unless (file-directory-p default-directory)
16232 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16233 ;; put file name into quotes if it contains spaces
16234 (when (string-match " " file-name)
16235 (setq file-name (concat "\"" file-name "\"")))
16236 ;; print out file name if compiler does not
16237 (setq vhdl-compile-file-name (buffer-file-name))
16238 (when (and (= 0 (nth 1 (nth 10 compiler)))
16239 (= 0 (nth 1 (nth 11 compiler))))
16240 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16241 ;; run compilation
16242 (if options
16243 (when command
16244 (compile (concat command " " options " " file-name)))
16245 (vhdl-warning "Your project settings tell me not to compile this file"))))
16246
16247 (defvar vhdl-make-target "all"
16248 "Default target for `vhdl-make' command.")
16249
16250 (defun vhdl-make (&optional target)
16251 "Call make command for compilation of all updated source files (requires
16252 `Makefile'). Optional argument TARGET allows to compile the design
16253 specified by a target."
16254 (interactive)
16255 (setq vhdl-make-target
16256 (or target (read-from-minibuffer "Target: " vhdl-make-target
16257 vhdl-minibuffer-local-map)))
16258 (vhdl-compile-init)
16259 (let* ((project (aget vhdl-project-alist vhdl-project))
16260 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16261 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16262 (command (nth 2 compiler))
16263 (options (vhdl-get-make-options project compiler))
16264 (default-directory (vhdl-compile-directory)))
16265 (unless (file-directory-p default-directory)
16266 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16267 ;; run make
16268 (compile (concat (if (equal command "") "make" command)
16269 " " options " " vhdl-make-target))))
16270
16271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16272 ;; Makefile generation
16273
16274 (defun vhdl-generate-makefile ()
16275 "Generate `Makefile'."
16276 (interactive)
16277 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16278 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16279 (command (nth 4 compiler)))
16280 ;; generate makefile
16281 (if command
16282 (let ((default-directory (vhdl-compile-directory)))
16283 (compile (vhdl-replace-string
16284 (cons "\\(.*\\) \\(.*\\)" command)
16285 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16286 (vhdl-generate-makefile-1))))
16287
16288 (defun vhdl-get-packages (lib-alist work-library)
16289 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16290 (let (pack-list)
16291 (while lib-alist
16292 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16293 (setq pack-list (cons (cdar lib-alist) pack-list)))
16294 (setq lib-alist (cdr lib-alist)))
16295 pack-list))
16296
16297 (defun vhdl-generate-makefile-1 ()
16298 "Generate Makefile for current project or directory."
16299 ;; scan hierarchy if required
16300 (if (vhdl-project-p)
16301 (unless (or (assoc vhdl-project vhdl-file-alist)
16302 (vhdl-load-cache vhdl-project))
16303 (vhdl-scan-project-contents vhdl-project))
16304 (let ((directory (abbreviate-file-name default-directory)))
16305 (unless (or (assoc directory vhdl-file-alist)
16306 (vhdl-load-cache directory))
16307 (vhdl-scan-directory-contents directory))))
16308 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16309 (project (vhdl-project-p))
16310 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16311 (conf-alist (aget vhdl-config-alist (or project directory) t))
16312 (pack-alist (aget vhdl-package-alist (or project directory) t))
16313 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16314 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16315 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16316 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16317 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16318 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16319 (adjust-case (nth 5 regexp-list))
16320 (work-library (downcase (vhdl-work-library)))
16321 (compile-directory (expand-file-name (vhdl-compile-directory)
16322 default-directory))
16323 (makefile-name (vhdl-makefile-name))
16324 rule-alist arch-alist inst-alist
16325 target-list depend-list unit-list prim-list second-list subcomp-list
16326 lib-alist lib-body-alist pack-list all-pack-list
16327 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16328 conf-key conf-file-name pack-key pack-file-name
16329 ent-entry arch-entry conf-entry pack-entry inst-entry
16330 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16331 tmp-key tmp-list rule)
16332 ;; check prerequisites
16333 (unless (file-exists-p compile-directory)
16334 (make-directory compile-directory t))
16335 (unless regexp-list
16336 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16337 vhdl-compiler))
16338 (message "Generating makefile \"%s\"..." makefile-name)
16339 ;; rules for all entities
16340 (setq tmp-list ent-alist)
16341 (while ent-alist
16342 (setq ent-entry (car ent-alist)
16343 ent-key (nth 0 ent-entry))
16344 (when (nth 2 ent-entry)
16345 (setq ent-file-name (file-relative-name
16346 (nth 2 ent-entry) compile-directory)
16347 arch-alist (nth 4 ent-entry)
16348 lib-alist (nth 6 ent-entry)
16349 rule (aget rule-alist ent-file-name)
16350 target-list (nth 0 rule)
16351 depend-list (nth 1 rule)
16352 second-list nil
16353 subcomp-list nil)
16354 (setq tmp-key (vhdl-replace-string
16355 ent-regexp (funcall adjust-case ent-key)))
16356 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16357 ;; rule target for this entity
16358 (setq target-list (cons ent-key target-list))
16359 ;; rule dependencies for all used packages
16360 (setq pack-list (vhdl-get-packages lib-alist work-library))
16361 (setq depend-list (append depend-list pack-list))
16362 (setq all-pack-list pack-list)
16363 ;; add rule
16364 (aput 'rule-alist ent-file-name (list target-list depend-list))
16365 ;; rules for all corresponding architectures
16366 (while arch-alist
16367 (setq arch-entry (car arch-alist)
16368 arch-key (nth 0 arch-entry)
16369 ent-arch-key (concat ent-key "-" arch-key)
16370 arch-file-name (file-relative-name (nth 2 arch-entry)
16371 compile-directory)
16372 inst-alist (nth 4 arch-entry)
16373 lib-alist (nth 5 arch-entry)
16374 rule (aget rule-alist arch-file-name)
16375 target-list (nth 0 rule)
16376 depend-list (nth 1 rule))
16377 (setq tmp-key (vhdl-replace-string
16378 arch-regexp
16379 (funcall adjust-case (concat arch-key " " ent-key))))
16380 (setq unit-list
16381 (cons (cons ent-arch-key tmp-key) unit-list))
16382 (setq second-list (cons ent-arch-key second-list))
16383 ;; rule target for this architecture
16384 (setq target-list (cons ent-arch-key target-list))
16385 ;; rule dependency for corresponding entity
16386 (setq depend-list (cons ent-key depend-list))
16387 ;; rule dependencies for contained component instantiations
16388 (while inst-alist
16389 (setq inst-entry (car inst-alist))
16390 (when (or (null (nth 8 inst-entry))
16391 (equal (downcase (nth 8 inst-entry)) work-library))
16392 (setq inst-ent-key (or (nth 7 inst-entry)
16393 (nth 5 inst-entry)))
16394 (setq depend-list (cons inst-ent-key depend-list)
16395 subcomp-list (cons inst-ent-key subcomp-list)))
16396 (setq inst-alist (cdr inst-alist)))
16397 ;; rule dependencies for all used packages
16398 (setq pack-list (vhdl-get-packages lib-alist work-library))
16399 (setq depend-list (append depend-list pack-list))
16400 (setq all-pack-list (append all-pack-list pack-list))
16401 ;; add rule
16402 (aput 'rule-alist arch-file-name (list target-list depend-list))
16403 (setq arch-alist (cdr arch-alist)))
16404 (setq prim-list (cons (list ent-key second-list
16405 (append subcomp-list all-pack-list))
16406 prim-list)))
16407 (setq ent-alist (cdr ent-alist)))
16408 (setq ent-alist tmp-list)
16409 ;; rules for all configurations
16410 (setq tmp-list conf-alist)
16411 (while conf-alist
16412 (setq conf-entry (car conf-alist)
16413 conf-key (nth 0 conf-entry)
16414 conf-file-name (file-relative-name
16415 (nth 2 conf-entry) compile-directory)
16416 ent-key (nth 4 conf-entry)
16417 arch-key (nth 5 conf-entry)
16418 inst-alist (nth 6 conf-entry)
16419 lib-alist (nth 7 conf-entry)
16420 rule (aget rule-alist conf-file-name)
16421 target-list (nth 0 rule)
16422 depend-list (nth 1 rule)
16423 subcomp-list (list ent-key))
16424 (setq tmp-key (vhdl-replace-string
16425 conf-regexp (funcall adjust-case conf-key)))
16426 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16427 ;; rule target for this configuration
16428 (setq target-list (cons conf-key target-list))
16429 ;; rule dependency for corresponding entity and architecture
16430 (setq depend-list
16431 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16432 ;; rule dependencies for used packages
16433 (setq pack-list (vhdl-get-packages lib-alist work-library))
16434 (setq depend-list (append depend-list pack-list))
16435 ;; rule dependencies for contained component configurations
16436 (while inst-alist
16437 (setq inst-entry (car inst-alist))
16438 (setq inst-ent-key (nth 2 inst-entry)
16439 ; comp-arch-key (nth 2 inst-entry))
16440 inst-conf-key (nth 4 inst-entry))
16441 (when (equal (downcase (nth 5 inst-entry)) work-library)
16442 (when inst-ent-key
16443 (setq depend-list (cons inst-ent-key depend-list)
16444 subcomp-list (cons inst-ent-key subcomp-list)))
16445 ; (when comp-arch-key
16446 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16447 ; depend-list)))
16448 (when inst-conf-key
16449 (setq depend-list (cons inst-conf-key depend-list)
16450 subcomp-list (cons inst-conf-key subcomp-list))))
16451 (setq inst-alist (cdr inst-alist)))
16452 ;; add rule
16453 (aput 'rule-alist conf-file-name (list target-list depend-list))
16454 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16455 prim-list))
16456 (setq conf-alist (cdr conf-alist)))
16457 (setq conf-alist tmp-list)
16458 ;; rules for all packages
16459 (setq tmp-list pack-alist)
16460 (while pack-alist
16461 (setq pack-entry (car pack-alist)
16462 pack-key (nth 0 pack-entry)
16463 pack-body-key nil)
16464 (when (nth 2 pack-entry)
16465 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16466 compile-directory)
16467 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16468 rule (aget rule-alist pack-file-name)
16469 target-list (nth 0 rule) depend-list (nth 1 rule))
16470 (setq tmp-key (vhdl-replace-string
16471 pack-regexp (funcall adjust-case pack-key)))
16472 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16473 ;; rule target for this package
16474 (setq target-list (cons pack-key target-list))
16475 ;; rule dependencies for all used packages
16476 (setq pack-list (vhdl-get-packages lib-alist work-library))
16477 (setq depend-list (append depend-list pack-list))
16478 (setq all-pack-list pack-list)
16479 ;; add rule
16480 (aput 'rule-alist pack-file-name (list target-list depend-list))
16481 ;; rules for this package's body
16482 (when (nth 7 pack-entry)
16483 (setq pack-body-key (concat pack-key "-body")
16484 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16485 compile-directory)
16486 rule (aget rule-alist pack-body-file-name)
16487 target-list (nth 0 rule)
16488 depend-list (nth 1 rule))
16489 (setq tmp-key (vhdl-replace-string
16490 pack-body-regexp (funcall adjust-case pack-key)))
16491 (setq unit-list
16492 (cons (cons pack-body-key tmp-key) unit-list))
16493 ;; rule target for this package's body
16494 (setq target-list (cons pack-body-key target-list))
16495 ;; rule dependency for corresponding package declaration
16496 (setq depend-list (cons pack-key depend-list))
16497 ;; rule dependencies for all used packages
16498 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16499 (setq depend-list (append depend-list pack-list))
16500 (setq all-pack-list (append all-pack-list pack-list))
16501 ;; add rule
16502 (aput 'rule-alist pack-body-file-name
16503 (list target-list depend-list)))
16504 (setq prim-list
16505 (cons (list pack-key (when pack-body-key (list pack-body-key))
16506 all-pack-list)
16507 prim-list)))
16508 (setq pack-alist (cdr pack-alist)))
16509 (setq pack-alist tmp-list)
16510 ;; generate Makefile
16511 (let* ((project (aget vhdl-project-alist project))
16512 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16513 (compiler-id (nth 9 compiler))
16514 (library-directory
16515 (vhdl-resolve-env-variable
16516 (vhdl-replace-string
16517 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16518 compiler-id)))
16519 (makefile-path-name (expand-file-name
16520 makefile-name compile-directory))
16521 (orig-buffer (current-buffer))
16522 cell second-list subcomp-list options unit-key unit-name)
16523 ;; sort lists
16524 (setq unit-list (vhdl-sort-alist unit-list))
16525 (setq prim-list (vhdl-sort-alist prim-list))
16526 (setq tmp-list rule-alist)
16527 (while tmp-list ; pre-sort rule targets
16528 (setq cell (cdar tmp-list))
16529 (setcar cell (sort (car cell) 'string<))
16530 (setq tmp-list (cdr tmp-list)))
16531 (setq rule-alist ; sort by first rule target
16532 (sort rule-alist
16533 (function (lambda (a b)
16534 (string< (car (cadr a)) (car (cadr b)))))))
16535 ;; open and clear Makefile
16536 (set-buffer (find-file-noselect makefile-path-name t t))
16537 (erase-buffer)
16538 (insert "# -*- Makefile -*-\n"
16539 "### " (file-name-nondirectory makefile-name)
16540 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16541 "\n")
16542 (if project
16543 (insert "\n# Project : " (nth 0 project))
16544 (insert "\n# Directory : \"" directory "\""))
16545 (insert "\n# Platform : " vhdl-compiler
16546 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16547 (user-login-name) "\n")
16548 ;; insert compile and option variable settings
16549 (insert "\n\n# Define compilation command and options\n"
16550 "\nCOMPILE = " (nth 0 compiler)
16551 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16552 "\n")
16553 ;; insert library paths
16554 (setq library-directory
16555 (directory-file-name
16556 (if (file-name-absolute-p library-directory)
16557 library-directory
16558 (file-relative-name
16559 (expand-file-name library-directory directory)
16560 compile-directory))))
16561 (insert "\n\n# Define library paths\n"
16562 "\nLIBRARY-" work-library " = " library-directory "\n")
16563 ;; insert variable definitions for all library unit files
16564 (insert "\n\n# Define library unit files\n")
16565 (setq tmp-list unit-list)
16566 (while unit-list
16567 (insert "\nUNIT-" work-library "-" (caar unit-list)
16568 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16569 (setq unit-list (cdr unit-list)))
16570 ;; insert variable definition for list of all library unit files
16571 (insert "\n\n\n# Define list of all library unit files\n"
16572 "\nALL_UNITS =")
16573 (setq unit-list tmp-list)
16574 (while unit-list
16575 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16576 (setq unit-list (cdr unit-list)))
16577 (insert "\n")
16578 (setq unit-list tmp-list)
16579 ;; insert `make all' rule
16580 (insert "\n\n\n# Rule for compiling entire design\n"
16581 "\nall :"
16582 " \\\n\t\tlibrary"
16583 " \\\n\t\t$(ALL_UNITS)\n")
16584 ;; insert `make clean' rule
16585 (insert "\n\n# Rule for cleaning entire design\n"
16586 "\nclean : "
16587 "\n\t-rm -f $(ALL_UNITS)\n")
16588 ;; insert `make library' rule
16589 (insert "\n\n# Rule for creating library directory\n"
16590 "\nlibrary :"
16591 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16592 "\n$(LIBRARY-" work-library ") :"
16593 "\n\t"
16594 (vhdl-replace-string
16595 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16596 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16597 "\n")
16598 ;; insert rule for each library unit
16599 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16600 (while prim-list
16601 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16602 (setq subcomp-list
16603 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16604 (setq unit-key (caar prim-list)
16605 unit-name (or (nth 0 (aget ent-alist unit-key t))
16606 (nth 0 (aget conf-alist unit-key t))
16607 (nth 0 (aget pack-alist unit-key t))))
16608 (insert "\n" unit-key)
16609 (unless (equal unit-key unit-name)
16610 (insert " \\\n" unit-name))
16611 (insert " :"
16612 " \\\n\t\tlibrary"
16613 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16614 (while second-list
16615 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16616 (setq second-list (cdr second-list)))
16617 (while subcomp-list
16618 (when (and (assoc (car subcomp-list) unit-list)
16619 (not (equal unit-key (car subcomp-list))))
16620 (insert " \\\n\t\t" (car subcomp-list)))
16621 (setq subcomp-list (cdr subcomp-list)))
16622 (insert "\n")
16623 (setq prim-list (cdr prim-list)))
16624 ;; insert rule for each library unit file
16625 (insert "\n\n# Rules for compiling single library unit files\n")
16626 (while rule-alist
16627 (setq rule (car rule-alist))
16628 ;; get compiler options for this file
16629 (setq options
16630 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16631 ;; insert rule if file is supposed to be compiled
16632 (setq target-list (nth 1 rule)
16633 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16634 ;; insert targets
16635 (setq tmp-list target-list)
16636 (while target-list
16637 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16638 (if (cdr target-list) " \\" " :"))
16639 (setq target-list (cdr target-list)))
16640 (setq target-list tmp-list)
16641 ;; insert file name as first dependency
16642 (insert " \\\n\t\t" (nth 0 rule))
16643 ;; insert dependencies (except if also target or unit does not exist)
16644 (while depend-list
16645 (when (and (not (member (car depend-list) target-list))
16646 (assoc (car depend-list) unit-list))
16647 (insert " \\\n\t\t"
16648 "$(UNIT-" work-library "-" (car depend-list) ")"))
16649 (setq depend-list (cdr depend-list)))
16650 ;; insert compile command
16651 (if options
16652 (insert "\n\t$(COMPILE) "
16653 (if (eq options 'default) "$(OPTIONS)" options) " "
16654 (nth 0 rule) "\n")
16655 (setq tmp-list target-list)
16656 (while target-list
16657 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16658 (if (cdr target-list) " \\" "\n"))
16659 (setq target-list (cdr target-list)))
16660 (setq target-list tmp-list))
16661 (setq rule-alist (cdr rule-alist)))
16662 (insert "\n\n### " makefile-name " ends here\n")
16663 ;; run Makefile generation hook
16664 (run-hooks 'vhdl-makefile-generation-hook)
16665 (message "Generating makefile \"%s\"...done" makefile-name)
16666 ;; save and close file
16667 (if (file-writable-p makefile-path-name)
16668 (progn (save-buffer)
16669 (kill-buffer (current-buffer))
16670 (set-buffer orig-buffer)
16671 (add-to-history 'file-name-history makefile-path-name))
16672 (vhdl-warning-when-idle
16673 (format "File not writable: \"%s\""
16674 (abbreviate-file-name makefile-path-name)))
16675 (switch-to-buffer (current-buffer))))))
16676
16677
16678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16679 ;;; Bug reports
16680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16681 ;; (using `reporter.el')
16682
16683 (defconst vhdl-mode-help-address
16684 "Reto Zimmermann <reto@gnu.org>"
16685 "Address for VHDL Mode bug reports.")
16686
16687 (defun vhdl-submit-bug-report ()
16688 "Submit via mail a bug report on VHDL Mode."
16689 (interactive)
16690 ;; load in reporter
16691 (and
16692 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16693 (let ((reporter-prompt-for-summary-p t))
16694 (reporter-submit-bug-report
16695 vhdl-mode-help-address
16696 (concat "VHDL Mode " vhdl-version)
16697 (list
16698 ;; report all important user options
16699 'vhdl-offsets-alist
16700 'vhdl-comment-only-line-offset
16701 'tab-width
16702 'vhdl-electric-mode
16703 'vhdl-stutter-mode
16704 'vhdl-indent-tabs-mode
16705 'vhdl-project-alist
16706 'vhdl-project
16707 'vhdl-project-file-name
16708 'vhdl-project-auto-load
16709 'vhdl-project-sort
16710 'vhdl-compiler-alist
16711 'vhdl-compiler
16712 'vhdl-compile-use-local-error-regexp
16713 'vhdl-makefile-generation-hook
16714 'vhdl-default-library
16715 'vhdl-standard
16716 'vhdl-basic-offset
16717 'vhdl-upper-case-keywords
16718 'vhdl-upper-case-types
16719 'vhdl-upper-case-attributes
16720 'vhdl-upper-case-enum-values
16721 'vhdl-upper-case-constants
16722 'vhdl-use-direct-instantiation
16723 'vhdl-compose-configuration-name
16724 'vhdl-entity-file-name
16725 'vhdl-architecture-file-name
16726 'vhdl-configuration-file-name
16727 'vhdl-package-file-name
16728 'vhdl-file-name-case
16729 'vhdl-electric-keywords
16730 'vhdl-optional-labels
16731 'vhdl-insert-empty-lines
16732 'vhdl-argument-list-indent
16733 'vhdl-association-list-with-formals
16734 'vhdl-conditions-in-parenthesis
16735 'vhdl-zero-string
16736 'vhdl-one-string
16737 'vhdl-file-header
16738 'vhdl-file-footer
16739 'vhdl-company-name
16740 'vhdl-copyright-string
16741 'vhdl-platform-spec
16742 'vhdl-date-format
16743 'vhdl-modify-date-prefix-string
16744 'vhdl-modify-date-on-saving
16745 'vhdl-reset-kind
16746 'vhdl-reset-active-high
16747 'vhdl-clock-rising-edge
16748 'vhdl-clock-edge-condition
16749 'vhdl-clock-name
16750 'vhdl-reset-name
16751 'vhdl-model-alist
16752 'vhdl-include-port-comments
16753 'vhdl-include-direction-comments
16754 'vhdl-include-type-comments
16755 'vhdl-include-group-comments
16756 'vhdl-actual-port-name
16757 'vhdl-instance-name
16758 'vhdl-testbench-entity-name
16759 'vhdl-testbench-architecture-name
16760 'vhdl-testbench-configuration-name
16761 'vhdl-testbench-dut-name
16762 'vhdl-testbench-include-header
16763 'vhdl-testbench-declarations
16764 'vhdl-testbench-statements
16765 'vhdl-testbench-initialize-signals
16766 'vhdl-testbench-include-library
16767 'vhdl-testbench-include-configuration
16768 'vhdl-testbench-create-files
16769 'vhdl-testbench-entity-file-name
16770 'vhdl-testbench-architecture-file-name
16771 'vhdl-compose-create-files
16772 'vhdl-compose-configuration-create-file
16773 'vhdl-compose-configuration-hierarchical
16774 'vhdl-compose-configuration-use-subconfiguration
16775 'vhdl-compose-include-header
16776 'vhdl-compose-architecture-name
16777 'vhdl-components-package-name
16778 'vhdl-use-components-package
16779 'vhdl-self-insert-comments
16780 'vhdl-prompt-for-comments
16781 'vhdl-inline-comment-column
16782 'vhdl-end-comment-column
16783 'vhdl-auto-align
16784 'vhdl-align-groups
16785 'vhdl-align-group-separate
16786 'vhdl-align-same-indent
16787 'vhdl-highlight-keywords
16788 'vhdl-highlight-names
16789 'vhdl-highlight-special-words
16790 'vhdl-highlight-forbidden-words
16791 'vhdl-highlight-verilog-keywords
16792 'vhdl-highlight-translate-off
16793 'vhdl-highlight-case-sensitive
16794 'vhdl-special-syntax-alist
16795 'vhdl-forbidden-words
16796 'vhdl-forbidden-syntax
16797 'vhdl-directive-keywords
16798 'vhdl-speedbar-auto-open
16799 'vhdl-speedbar-display-mode
16800 'vhdl-speedbar-scan-limit
16801 'vhdl-speedbar-jump-to-unit
16802 'vhdl-speedbar-update-on-saving
16803 'vhdl-speedbar-save-cache
16804 'vhdl-speedbar-cache-file-name
16805 'vhdl-index-menu
16806 'vhdl-source-file-menu
16807 'vhdl-hideshow-menu
16808 'vhdl-hide-all-init
16809 'vhdl-print-two-column
16810 'vhdl-print-customize-faces
16811 'vhdl-intelligent-tab
16812 'vhdl-indent-syntax-based
16813 'vhdl-word-completion-case-sensitive
16814 'vhdl-word-completion-in-minibuffer
16815 'vhdl-underscore-is-part-of-word
16816 'vhdl-mode-hook)
16817 (function
16818 (lambda ()
16819 (insert
16820 (if vhdl-special-indent-hook
16821 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16822 "vhdl-special-indent-hook is set to '"
16823 (format "%s" vhdl-special-indent-hook)
16824 ".\nPerhaps this is your problem?\n"
16825 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16826 "\n"))))
16827 nil
16828 "Hi Reto,"))))
16829
16830
16831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16832 ;;; Documentation
16833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16834
16835 (defconst vhdl-doc-release-notes nil
16836 "\
16837 Release Notes for VHDL Mode 3.33
16838 ================================
16839
16840 - New Features
16841 - User Options
16842
16843
16844 New Features
16845 ------------
16846
16847 CONFIGURATION DECLARATION GENERATION:
16848 - Automatic generation of a configuration declaration for a design.
16849 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16850
16851
16852 User Options
16853 ------------
16854
16855 `vhdl-configuration-file-name': (new)
16856 Specify how the configuration file name is obtained.
16857 `vhdl-compose-configuration-name': (new)
16858 Specify how the configuration name is optained.
16859 `vhdl-compose-configuration-create-file': (new)
16860 Specify whether a new file should be created for a configuration.
16861 `vhdl-compose-configuration-hierarchical': (new)
16862 Specify whether hierarchical configurations should be created.
16863 `vhdl-compose-configuration-use-subconfiguration': (new)
16864 Specify whether subconfigurations should be used inside configurations.
16865 ")
16866
16867
16868 (defconst vhdl-doc-keywords nil
16869 "\
16870 Reserved words in VHDL
16871 ----------------------
16872
16873 VHDL'93 (IEEE Std 1076-1993):
16874 `vhdl-93-keywords' : keywords
16875 `vhdl-93-types' : standardized types
16876 `vhdl-93-attributes' : standardized attributes
16877 `vhdl-93-enum-values' : standardized enumeration values
16878 `vhdl-93-functions' : standardized functions
16879 `vhdl-93-packages' : standardized packages and libraries
16880
16881 VHDL-AMS (IEEE Std 1076.1):
16882 `vhdl-ams-keywords' : keywords
16883 `vhdl-ams-types' : standardized types
16884 `vhdl-ams-attributes' : standardized attributes
16885 `vhdl-ams-enum-values' : standardized enumeration values
16886 `vhdl-ams-functions' : standardized functions
16887
16888 Math Packages (IEEE Std 1076.2):
16889 `vhdl-math-types' : standardized types
16890 `vhdl-math-constants' : standardized constants
16891 `vhdl-math-functions' : standardized functions
16892 `vhdl-math-packages' : standardized packages
16893
16894 Forbidden words:
16895 `vhdl-verilog-keywords' : Verilog reserved words
16896
16897 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16898
16899
16900 (defconst vhdl-doc-coding-style nil
16901 "\
16902 For VHDL coding style and naming convention guidelines, see the following
16903 references:
16904
16905 \[1] Ben Cohen.
16906 \"VHDL Coding Styles and Methodologies\".
16907 Kluwer Academic Publishers, 1999.
16908 http://members.aol.com/vhdlcohen/vhdl/
16909
16910 \[2] Michael Keating and Pierre Bricaud.
16911 \"Reuse Methodology Manual, Second Edition\".
16912 Kluwer Academic Publishers, 1999.
16913 http://www.openmore.com/openmore/rmm2.html
16914
16915 \[3] European Space Agency.
16916 \"VHDL Modelling Guidelines\".
16917 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16918
16919 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16920 to visually support naming conventions.")
16921
16922
16923 (defun vhdl-version ()
16924 "Echo the current version of VHDL Mode in the minibuffer."
16925 (interactive)
16926 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16927 (vhdl-keep-region-active))
16928
16929 (defun vhdl-doc-variable (variable)
16930 "Display VARIABLE's documentation in *Help* buffer."
16931 (interactive)
16932 (unless (featurep 'xemacs)
16933 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16934 (with-output-to-temp-buffer
16935 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16936 (princ (documentation-property variable 'variable-documentation))
16937 (with-current-buffer standard-output
16938 (help-mode))
16939 (help-print-return-message)))
16940
16941 (defun vhdl-doc-mode ()
16942 "Display VHDL Mode documentation in *Help* buffer."
16943 (interactive)
16944 (unless (featurep 'xemacs)
16945 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16946 (with-output-to-temp-buffer
16947 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16948 (princ mode-name)
16949 (princ " mode:\n")
16950 (princ (documentation 'vhdl-mode))
16951 (with-current-buffer standard-output
16952 (help-mode))
16953 (help-print-return-message)))
16954
16955
16956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16957
16958 (provide 'vhdl-mode)
16959
16960 ;;; vhdl-mode.el ends here