]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vhdl-mode.el
86b917767a960e4ef330b1495b0bd8bee46fd972
[gnu-emacs] / 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-electric-mode t
203 "*Non-nil enables electrification (automatic template generation).
204 If nil, template generators can still be invoked through key bindings and
205 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
206 toggled by `\\[vhdl-electric-mode]'."
207 :type 'boolean
208 :group 'vhdl-mode)
209
210 (defcustom vhdl-stutter-mode t
211 "*Non-nil enables stuttering.
212 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
213 by `\\[vhdl-stutter-mode]'."
214 :type 'boolean
215 :group 'vhdl-mode)
216
217 (defcustom vhdl-indent-tabs-mode nil
218 "*Non-nil means indentation can insert tabs.
219 Overrides local variable `indent-tabs-mode'."
220 :type 'boolean
221 :group 'vhdl-mode)
222
223
224 (defgroup vhdl-compile nil
225 "Customizations for compilation."
226 :group 'vhdl)
227
228 (defcustom vhdl-compiler-alist
229 '(
230 ;; Cadence Leapfrog: cv -file test.vhd
231 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
232 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
233 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
234 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
235 ("\\1/entity" "\\2/\\1" "\\1/configuration"
236 "\\1/package" "\\1/body" downcase))
237 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
238 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
239 ;; (PLL_400X_TOP) is not declared [10.3].
240 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
241 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
242 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
243 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
244 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
245 ;; Ikos Voyager: analyze test.vhd
246 ;; analyze test.vhd
247 ;; E L4/C5: this library unit is inaccessible
248 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
249 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
250 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
251 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
252 nil)
253 ;; ModelSim, Model Technology: vcom test.vhd
254 ;; ERROR: test.vhd(14): Unknown identifier: positiv
255 ;; WARNING[2]: test.vhd(85): Possible infinite loop
256 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
257 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
258 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
259 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase))
262 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
263 ;; test.vhd:34: error message
264 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
265 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
268 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
269 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
270 ;; ERROR: test.vhd(24): near "dnd": expecting: END
271 ;; WARNING[4]: test.vhd(30): A space is required between ...
272 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
273 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
274 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
275 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
276 "\\1/_primary.dat" "\\1/body.dat" downcase))
277 ;; Savant: scram -publish-cc test.vhd
278 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
279 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
280 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
281 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
282 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
283 "\\1_config.vhdl" "\\1_package.vhdl"
284 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
285 ;; Simili: vhdlp -work test.vhd
286 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
287 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
289 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
290 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
291 "\\1/prim.var" "\\1/_body.var" downcase))
292 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
293 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
294 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
296 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
297 nil)
298 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
299 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
300 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
301 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
302 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
303 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
304 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
305 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
306 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
307 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
308 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
309 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
310 ;; Synplify:
311 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
312 ("Synplify" "n/a" "n/a" "make" "-f \\1"
313 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
314 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
315 nil)
316 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
317 ;; Compiling "test.vhd" line 1...
318 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
319 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
320 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
321 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
322 ("^ *Compiling \"\\(.+\\)\" " 1)
323 nil)
324 ;; VeriBest: vc vhdl test.vhd
325 ;; (no file name printed out!)
326 ;; 32: Z <= A and BitA ;
327 ;; ^^^^
328 ;; [Error] Name BITA is unknown
329 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
330 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
331 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
332 nil)
333 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
334 ;; Compiling "test.vhd" line 1...
335 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
336 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
337 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
338 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
339 ("^ *Compiling \"\\(.+\\)\" " 1)
340 nil)
341 )
342 "*List of available VHDL compilers and their properties.
343 Each list entry specifies the following items for a compiler:
344 Compiler:
345 Compiler name : name used in option `vhdl-compiler' to choose compiler
346 Compile command : command used for source file compilation
347 Compile options : compile options (\"\\1\" inserts library name)
348 Make command : command used for compilation using a Makefile
349 Make options : make options (\"\\1\" inserts Makefile name)
350 Generate Makefile: use built-in function or command to generate a Makefile
351 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
352 Library command : command to create library directory \(\"\\1\" inserts
353 library directory, \"\\2\" inserts library name)
354 Compile directory: where compilation is run and the Makefile is placed
355 Library directory: directory of default library
356 Makefile name : name of Makefile (default is \"Makefile\")
357 ID string : compiler identification string (see `vhdl-project-alist')
358 Error message:
359 Regexp : regular expression to match error messages (*)
360 File subexp index: index of subexpression that matches the file name
361 Line subexp index: index of subexpression that matches the line number
362 Column subexp idx: index of subexpression that matches the column number
363 File message:
364 Regexp : regular expression to match a file name message
365 File subexp index: index of subexpression that matches the file name
366 Unit-to-file name mapping: mapping of library unit names to names of files
367 generated by the compiler (used for Makefile generation)
368 To string : string a name is mapped to (\"\\1\" inserts the unit name,
369 \"\\2\" inserts the entity name for architectures)
370 Case adjustment : adjust case of inserted unit names
371
372 \(*) The regular expression must match the error message starting from the
373 beginning of the line (but not necessarily to the end of the line).
374
375 Compile options allows insertion of the library name (see `vhdl-project-alist')
376 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
377
378 For Makefile generation, the built-in function can be used (requires
379 specification of the unit-to-file name mapping). Alternatively, an
380 external command can be specified. Work directory allows specification of
381 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
382 used for Makefile generation). To use another library name than \"work\",
383 customize `vhdl-project-alist'. The library command is inserted in Makefiles
384 to automatically create the library directory if not existent.
385
386 Compile options, compile directory, library directory, and Makefile name are
387 overwritten by the project settings if a project is defined (see
388 `vhdl-project-alist'). Directory paths are relative to the source file
389 directory.
390
391 Some compilers do not include the file name in the error message, but print
392 out a file name message in advance. In this case, set \"File Subexp Index\"
393 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
394 If no file name at all is printed out, set both \"File Message\" entries to 0
395 \(a default file name message will be printed out instead, does not work in
396 XEmacs).
397
398 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
399 assigning its name to option `vhdl-compiler'.
400
401 Please send any missing or erroneous compiler properties to the maintainer for
402 updating.
403
404 NOTE: Activate new error and file message regexps and reflect the new setting
405 in the choice list of option `vhdl-compiler' by restarting Emacs."
406 :type '(repeat
407 (list :tag "Compiler" :indent 2
408 (string :tag "Compiler name ")
409 (string :tag "Compile command ")
410 (string :tag "Compile options " "-work \\1")
411 (string :tag "Make command " "make")
412 (string :tag "Make options " "-f \\1")
413 (choice :tag "Generate Makefile "
414 (const :tag "Built-in function" nil)
415 (string :tag "Command" "vmake \\2 > \\1"))
416 (string :tag "Library command " "mkdir \\1")
417 (directory :tag "Compile directory "
418 :validate vhdl-widget-directory-validate "./")
419 (directory :tag "Library directory "
420 :validate vhdl-widget-directory-validate "work/")
421 (file :tag "Makefile name " "Makefile")
422 (string :tag "ID string ")
423 (list :tag "Error message" :indent 4
424 (regexp :tag "Regexp ")
425 (integer :tag "File subexp index")
426 (integer :tag "Line subexp index")
427 (integer :tag "Column subexp idx"))
428 (list :tag "File message" :indent 4
429 (regexp :tag "Regexp ")
430 (integer :tag "File subexp index"))
431 (choice :tag "Unit-to-file name mapping"
432 :format "%t: %[Value Menu%] %v\n"
433 (const :tag "Not defined" nil)
434 (list :tag "To string" :indent 4
435 (string :tag "Entity " "\\1.vhd")
436 (string :tag "Architecture " "\\2_\\1.vhd")
437 (string :tag "Configuration " "\\1.vhd")
438 (string :tag "Package " "\\1.vhd")
439 (string :tag "Package Body " "\\1_body.vhd")
440 (choice :tag "Case adjustment "
441 (const :tag "None" identity)
442 (const :tag "Upcase" upcase)
443 (const :tag "Downcase" downcase))))))
444 :set (lambda (variable value)
445 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
446 :group 'vhdl-compile)
447
448 (defcustom vhdl-compiler "ModelSim"
449 "*Specifies the VHDL compiler to be used for syntax analysis.
450 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
451 :type (let ((alist vhdl-compiler-alist) list)
452 (while alist
453 (setq list (cons (list 'const (caar alist)) list))
454 (setq alist (cdr alist)))
455 (append '(choice) (nreverse list)))
456 :group 'vhdl-compile)
457
458 (defcustom vhdl-compile-use-local-error-regexp t
459 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
460 In this case, only error message regexps for VHDL compilers are active if
461 compilation is started from a VHDL buffer. Otherwise, the error message
462 regexps are appended to the predefined global regexps, and all regexps are
463 active all the time. Note that by doing that, the predefined global regexps
464 might result in erroneous parsing of error messages for some VHDL compilers.
465
466 NOTE: Activate the new setting by restarting Emacs."
467 :type 'boolean
468 :group 'vhdl-compile)
469
470 (defcustom vhdl-makefile-generation-hook nil
471 "*Functions to run at the end of Makefile generation.
472 Allows to insert user specific parts into a Makefile.
473
474 Example:
475 \(lambda nil
476 \(re-search-backward \"^# Rule for compiling entire design\")
477 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
478 :type 'hook
479 :group 'vhdl-compile)
480
481 (defcustom vhdl-default-library "work"
482 "*Name of default library.
483 Is overwritten by project settings if a project is active."
484 :type 'string
485 :group 'vhdl-compile)
486
487
488 (defgroup vhdl-project nil
489 "Customizations for projects."
490 :group 'vhdl)
491
492 (defcustom vhdl-project-alist
493 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
494 "~/example1/" ("src/system/" "src/components/") ""
495 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
496 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
497 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
498 ("Example 2" "Individual source files, multiple compilers in different directories"
499 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
500 nil "\\1/" "work" "\\1/work/" "Makefile" "")
501 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
502 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
503 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
504 -------------------------------------------------------------------------------
505 -- This is a multi-line project description
506 -- that can be used as a project dependent part of the file header.
507 "))
508 "*List of projects and their properties.
509 Name : name used in option `vhdl-project' to choose project
510 Title : title of project (single-line string)
511 Default directory: default project directory (absolute path)
512 Sources : a) source files : path + \"/\" + file name
513 b) directory : path + \"/\"
514 c) directory tree: \"-r \" + path + \"/\"
515 Exclude regexp : matches file/directory names to be excluded as sources
516 Compile options : project-specific options for each compiler
517 Compiler name : name of compiler for which these options are valid
518 Compile options: project-specific compiler options
519 (\"\\1\" inserts library name, \"\\2\" default options)
520 Make options: project-specific make options
521 (\"\\1\" inserts Makefile name, \"\\2\" default options)
522 Exceptions : file-specific exceptions
523 File name regexp: matches file names for which exceptions are valid
524 - Options : file-specific compiler options string
525 (\"\\1\" inserts library name, \"\\2\" default options,
526 \"\\3\" project-specific options)
527 - Do not compile: do not compile this file (in Makefile)
528 Compile directory: where compilation is run and the Makefile is placed
529 \(\"\\1\" inserts compiler ID string)
530 Library name : name of library (default is \"work\")
531 Library directory: path to library (\"\\1\" inserts compiler ID string)
532 Makefile name : name of Makefile
533 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
534 Description : description of project (multi-line string)
535
536 Project title and description are used to insert into the file header (see
537 option `vhdl-file-header').
538
539 The default directory must have an absolute path (use `M-TAB' for completion).
540 All other paths can be absolute or relative to the default directory. All
541 paths must end with '/'.
542
543 The design units found in the sources (files and directories) are shown in the
544 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
545 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
546 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
547 specified, the default directory is taken as source directory. Otherwise,
548 the default directory is only taken as source directory if there is a sources
549 entry with the empty string or \"./\". Exclude regexp allows to filter out
550 specific file and directory names from the list of sources (e.g. CVS
551 directories).
552
553 Files are compiled in the compile directory. Makefiles are also placed into
554 the compile directory. Library directory specifies which directory the
555 compiler compiles into (used to generate the Makefile).
556
557 Since different compile/library directories and Makefiles may exist for
558 different compilers within one project, these paths and names allow the
559 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
560 Compile options, compile directory, library directory, and Makefile name
561 overwrite the settings of the current compiler.
562
563 File-specific compiler options (highest priority) overwrite project-specific
564 options which overwrite default options (lowest priority). Lower priority
565 options can be inserted in higher priority options. This allows to reuse
566 default options (e.g. \"-file\") in project- or file-specific options (e.g.
567 \"-93 -file\").
568
569 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
570 by restarting Emacs."
571 :type `(repeat
572 (list :tag "Project" :indent 2
573 (string :tag "Name ")
574 (string :tag "Title ")
575 (directory :tag "Default directory"
576 :validate vhdl-widget-directory-validate
577 ,(abbreviate-file-name default-directory))
578 (repeat :tag "Sources " :indent 4
579 (directory :format " %v" "./"))
580 (regexp :tag "Exclude regexp ")
581 (repeat
582 :tag "Compile options " :indent 4
583 (list :tag "Compiler" :indent 6
584 ,(let ((alist vhdl-compiler-alist) list)
585 (while alist
586 (setq list (cons (list 'const (caar alist)) list))
587 (setq alist (cdr alist)))
588 (append '(choice :tag "Compiler name")
589 (nreverse list)))
590 (string :tag "Compile options" "\\2")
591 (string :tag "Make options " "\\2")
592 (repeat
593 :tag "Exceptions " :indent 8
594 (cons :format "%v"
595 (regexp :tag "File name regexp ")
596 (choice :format "%[Value Menu%] %v"
597 (string :tag "Options" "\\3")
598 (const :tag "Do not compile" nil))))))
599 (directory :tag "Compile directory"
600 :validate vhdl-widget-directory-validate "./")
601 (string :tag "Library name " "work")
602 (directory :tag "Library directory"
603 :validate vhdl-widget-directory-validate "work/")
604 (file :tag "Makefile name " "Makefile")
605 (string :tag "Description: (type `C-j' for newline)"
606 :format "%t\n%v\n")))
607 :set (lambda (variable value)
608 (vhdl-custom-set variable value
609 'vhdl-update-mode-menu
610 'vhdl-speedbar-refresh))
611 :group 'vhdl-project)
612
613 (defcustom vhdl-project nil
614 "*Specifies the default for the current project.
615 Select a project name from the ones defined in option `vhdl-project-alist'.
616 Is used to determine the project title and description to be inserted in file
617 headers and the source files/directories to be scanned in the hierarchy
618 browser. The current project can also be changed temporarily in the menu."
619 :type (let ((alist vhdl-project-alist) list)
620 (while alist
621 (setq list (cons (list 'const (caar alist)) list))
622 (setq alist (cdr alist)))
623 (append '(choice (const :tag "None" nil) (const :tag "--"))
624 (nreverse list)))
625 :group 'vhdl-project)
626
627 (defcustom vhdl-project-file-name '("\\1.prj")
628 "*List of file names/paths for importing/exporting project setups.
629 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
630 replaced by the user name (allows to have user-specific project setups).
631 The first entry is used as file name to import/export individual project
632 setups. All entries are used to automatically import project setups at
633 startup (see option `vhdl-project-auto-load'). Projects loaded from the
634 first entry are automatically made current. Hint: specify local project
635 setups in first entry, global setups in following entries; loading a local
636 project setup will make it current, while loading the global setups
637 is done without changing the current project.
638 Names can also have an absolute path (i.e. project setups can be stored
639 in global directories)."
640 :type '(repeat (string :tag "File name" "\\1.prj"))
641 :group 'vhdl-project)
642
643 (defcustom vhdl-project-auto-load '(startup)
644 "*Automatically load project setups from files.
645 All project setup files that match the file names specified in option
646 `vhdl-project-file-name' are automatically loaded. The project of the
647 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
648 entry is activated.
649 A project setup file can be obtained by exporting a project (see menu).
650 At startup: project setup file is loaded at Emacs startup"
651 :type '(set (const :tag "At startup" startup))
652 :group 'vhdl-project)
653
654 (defcustom vhdl-project-sort t
655 "*Non-nil means projects are displayed in alphabetical order."
656 :type 'boolean
657 :group 'vhdl-project)
658
659
660 (defgroup vhdl-style nil
661 "Customizations for coding styles."
662 :group 'vhdl
663 :group 'vhdl-template
664 :group 'vhdl-port
665 :group 'vhdl-compose)
666
667 (defcustom vhdl-standard '(87 nil)
668 "*VHDL standards used.
669 Basic standard:
670 VHDL'87 : IEEE Std 1076-1987
671 VHDL'93 : IEEE Std 1076-1993
672 Additional standards:
673 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
674 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
675
676 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
677 \"Activate Options\"."
678 :type '(list (choice :tag "Basic standard"
679 (const :tag "VHDL'87" 87)
680 (const :tag "VHDL'93" 93))
681 (set :tag "Additional standards" :indent 2
682 (const :tag "VHDL-AMS" ams)
683 (const :tag "Math packages" math)))
684 :set (lambda (variable value)
685 (vhdl-custom-set variable value
686 'vhdl-template-map-init
687 'vhdl-mode-abbrev-table-init
688 'vhdl-template-construct-alist-init
689 'vhdl-template-package-alist-init
690 'vhdl-update-mode-menu
691 'vhdl-words-init 'vhdl-font-lock-init))
692 :group 'vhdl-style)
693
694 (defcustom vhdl-basic-offset 2
695 "*Amount of basic offset used for indentation.
696 This value is used by + and - symbols in `vhdl-offsets-alist'."
697 :type 'integer
698 :group 'vhdl-style)
699
700 (defcustom vhdl-upper-case-keywords nil
701 "*Non-nil means convert keywords to upper case.
702 This is done when typed or expanded or by the fix case functions."
703 :type 'boolean
704 :set (lambda (variable value)
705 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
706 :group 'vhdl-style)
707
708 (defcustom vhdl-upper-case-types nil
709 "*Non-nil means convert standardized types to upper case.
710 This is done when expanded or by the fix case functions."
711 :type 'boolean
712 :set (lambda (variable value)
713 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
714 :group 'vhdl-style)
715
716 (defcustom vhdl-upper-case-attributes nil
717 "*Non-nil means convert standardized attributes to upper case.
718 This is done when expanded or by the fix case functions."
719 :type 'boolean
720 :set (lambda (variable value)
721 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
722 :group 'vhdl-style)
723
724 (defcustom vhdl-upper-case-enum-values nil
725 "*Non-nil means convert standardized enumeration values to upper case.
726 This is done when expanded or by the fix case functions."
727 :type 'boolean
728 :set (lambda (variable value)
729 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
730 :group 'vhdl-style)
731
732 (defcustom vhdl-upper-case-constants t
733 "*Non-nil means convert standardized constants to upper case.
734 This is done when expanded."
735 :type 'boolean
736 :set (lambda (variable value)
737 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
738 :group 'vhdl-style)
739
740 (defcustom vhdl-use-direct-instantiation 'standard
741 "*Non-nil means use VHDL'93 direct component instantiation.
742 Never : never
743 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
744 Always : always"
745 :type '(choice (const :tag "Never" never)
746 (const :tag "Standard" standard)
747 (const :tag "Always" always))
748 :group 'vhdl-style)
749
750
751 (defgroup vhdl-naming nil
752 "Customizations for naming conventions."
753 :group 'vhdl)
754
755 (defcustom vhdl-entity-file-name '(".*" . "\\&")
756 (concat
757 "*Specifies how the entity file name is obtained.
758 The entity file name can be obtained by modifying the entity name (e.g.
759 attaching or stripping off a substring). The file extension is automatically
760 taken from the file name of the current buffer."
761 vhdl-name-doc-string)
762 :type '(cons (regexp :tag "From regexp")
763 (string :tag "To string "))
764 :group 'vhdl-naming
765 :group 'vhdl-compose)
766
767 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
768 (concat
769 "*Specifies how the architecture file name is obtained.
770 The architecture file name can be obtained by modifying the entity
771 and/or architecture name (e.g. attaching or stripping off a substring). The
772 file extension is automatically taken from the file name of the current
773 buffer. The string that is matched against the regexp is the concatenation
774 of the entity and the architecture name separated by a space. This gives
775 access to both names (see default setting as example)."
776 vhdl-name-doc-string)
777 :type '(cons (regexp :tag "From regexp")
778 (string :tag "To string "))
779 :group 'vhdl-naming
780 :group 'vhdl-compose)
781
782 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
783 (concat
784 "*Specifies how the configuration file name is obtained.
785 The configuration file name can be obtained by modifying the configuration
786 name (e.g. attaching or stripping off a substring). The file extension is
787 automatically taken from the file name of the current buffer."
788 vhdl-name-doc-string)
789 :type '(cons (regexp :tag "From regexp")
790 (string :tag "To string "))
791 :group 'vhdl-naming
792 :group 'vhdl-compose)
793
794 (defcustom vhdl-package-file-name '(".*" . "\\&")
795 (concat
796 "*Specifies how the package file name is obtained.
797 The package file name can be obtained by modifying the package name (e.g.
798 attaching or stripping off a substring). The file extension is automatically
799 taken from the file name of the current buffer. Package files can be created
800 in a different directory by prepending a relative or absolute path to the
801 file name."
802 vhdl-name-doc-string)
803 :type '(cons (regexp :tag "From regexp")
804 (string :tag "To string "))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
807
808 (defcustom vhdl-file-name-case 'identity
809 "*Specifies how to change case for obtaining file names.
810 When deriving a file name from a VHDL unit name, case can be changed as
811 follows:
812 As Is: case is not changed (taken as is)
813 Lower Case: whole name is changed to lower case
814 Upper Case: whole name is changed to upper case
815 Capitalize: first letter of each word in name is capitalized"
816 :type '(choice (const :tag "As Is" identity)
817 (const :tag "Lower Case" downcase)
818 (const :tag "Upper Case" upcase)
819 (const :tag "Capitalize" capitalize))
820 :group 'vhdl-naming
821 :group 'vhdl-compose)
822
823
824 (defgroup vhdl-template nil
825 "Customizations for electrification."
826 :group 'vhdl)
827
828 (defcustom vhdl-electric-keywords '(vhdl user)
829 "*Type of keywords for which electrification is enabled.
830 VHDL keywords: invoke built-in templates
831 User keywords: invoke user models (see option `vhdl-model-alist')"
832 :type '(set (const :tag "VHDL keywords" vhdl)
833 (const :tag "User model keywords" user))
834 :set (lambda (variable value)
835 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
836 :group 'vhdl-template)
837
838 (defcustom vhdl-optional-labels 'process
839 "*Constructs for which labels are to be queried.
840 Template generators prompt for optional labels for:
841 None : no constructs
842 Processes only: processes only (also procedurals in VHDL-AMS)
843 All constructs: all constructs with optional labels and keyword END"
844 :type '(choice (const :tag "None" none)
845 (const :tag "Processes only" process)
846 (const :tag "All constructs" all))
847 :group 'vhdl-template)
848
849 (defcustom vhdl-insert-empty-lines 'unit
850 "*Specifies whether to insert empty lines in some templates.
851 This improves readability of code. Empty lines are inserted in:
852 None : no constructs
853 Design units only: entities, architectures, configurations, packages only
854 All constructs : also all constructs with BEGIN...END parts
855
856 Replaces option `vhdl-additional-empty-lines'."
857 :type '(choice (const :tag "None" none)
858 (const :tag "Design units only" unit)
859 (const :tag "All constructs" all))
860 :group 'vhdl-template
861 :group 'vhdl-port
862 :group 'vhdl-compose)
863
864 (defcustom vhdl-argument-list-indent nil
865 "*Non-nil means indent argument lists relative to opening parenthesis.
866 That is, argument, association, and port lists start on the same line as the
867 opening parenthesis and subsequent lines are indented accordingly.
868 Otherwise, lists start on a new line and are indented as normal code."
869 :type 'boolean
870 :group 'vhdl-template
871 :group 'vhdl-port
872 :group 'vhdl-compose)
873
874 (defcustom vhdl-association-list-with-formals t
875 "*Non-nil means write association lists with formal parameters.
876 Templates prompt for formal and actual parameters (ports/generics).
877 When pasting component instantiations, formals are included.
878 If nil, only a list of actual parameters is entered."
879 :type 'boolean
880 :group 'vhdl-template
881 :group 'vhdl-port
882 :group 'vhdl-compose)
883
884 (defcustom vhdl-conditions-in-parenthesis nil
885 "*Non-nil means place parenthesis around condition expressions."
886 :type 'boolean
887 :group 'vhdl-template)
888
889 (defcustom vhdl-zero-string "'0'"
890 "*String to use for a logic zero."
891 :type 'string
892 :group 'vhdl-template)
893
894 (defcustom vhdl-one-string "'1'"
895 "*String to use for a logic one."
896 :type 'string
897 :group 'vhdl-template)
898
899
900 (defgroup vhdl-header nil
901 "Customizations for file header."
902 :group 'vhdl-template
903 :group 'vhdl-compose)
904
905 (defcustom vhdl-file-header "\
906 -------------------------------------------------------------------------------
907 -- Title : <title string>
908 -- Project : <project>
909 -------------------------------------------------------------------------------
910 -- File : <filename>
911 -- Author : <author>
912 -- Company : <company>
913 -- Created : <date>
914 -- Last update: <date>
915 -- Platform : <platform>
916 -- Standard : <standard>
917 <projectdesc>-------------------------------------------------------------------------------
918 -- Description: <cursor>
919 <copyright>-------------------------------------------------------------------------------
920 -- Revisions :
921 -- Date Version Author Description
922 -- <date> 1.0 <login>\tCreated
923 -------------------------------------------------------------------------------
924
925 "
926 "*String or file to insert as file header.
927 If the string specifies an existing file name, the contents of the file is
928 inserted, otherwise the string itself is inserted as file header.
929 Type `C-j' for newlines.
930 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
931 if the header needs to be version controlled.
932
933 The following keywords for template generation are supported:
934 <filename> : replaced by the name of the buffer
935 <author> : replaced by the user name and email address
936 \(`user-full-name', `mail-host-address', `user-mail-address')
937 <login> : replaced by user login name (`user-login-name')
938 <company> : replaced by contents of option `vhdl-company-name'
939 <date> : replaced by the current date
940 <year> : replaced by the current year
941 <project> : replaced by title of current project (`vhdl-project')
942 <projectdesc> : replaced by description of current project (`vhdl-project')
943 <copyright> : replaced by copyright string (`vhdl-copyright-string')
944 <platform> : replaced by contents of option `vhdl-platform-spec'
945 <standard> : replaced by the VHDL language standard(s) used
946 <... string> : replaced by a queried string (\"...\" is the prompt word)
947 <title string>: replaced by file title in automatically generated files
948 <cursor> : final cursor position
949
950 The (multi-line) project description <projectdesc> can be used as a project
951 dependent part of the file header and can also contain the above keywords."
952 :type 'string
953 :group 'vhdl-header)
954
955 (defcustom vhdl-file-footer ""
956 "*String or file to insert as file footer.
957 If the string specifies an existing file name, the contents of the file is
958 inserted, otherwise the string itself is inserted as file footer (i.e. at
959 the end of the file).
960 Type `C-j' for newlines.
961 The same keywords as in option `vhdl-file-header' can be used."
962 :type 'string
963 :group 'vhdl-header)
964
965 (defcustom vhdl-company-name ""
966 "*Name of company to insert in file header.
967 See option `vhdl-file-header'."
968 :type 'string
969 :group 'vhdl-header)
970
971 (defcustom vhdl-copyright-string "\
972 -------------------------------------------------------------------------------
973 -- Copyright (c) <year> <company>
974 "
975 "*Copyright string to insert in file header.
976 Can be multi-line string (type `C-j' for newline) and contain other file
977 header keywords (see option `vhdl-file-header')."
978 :type 'string
979 :group 'vhdl-header)
980
981 (defcustom vhdl-platform-spec ""
982 "*Specification of VHDL platform to insert in file header.
983 The platform specification should contain names and versions of the
984 simulation and synthesis tools used.
985 See option `vhdl-file-header'."
986 :type 'string
987 :group 'vhdl-header)
988
989 (defcustom vhdl-date-format "%Y-%m-%d"
990 "*Specifies the date format to use in the header.
991 This string is passed as argument to the command `format-time-string'.
992 For more information on format strings, see the documentation for the
993 `format-time-string' command (C-h f `format-time-string')."
994 :type 'string
995 :group 'vhdl-header)
996
997 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
998 "*Prefix string of modification date in VHDL file header.
999 If actualization of the modification date is called (menu,
1000 `\\[vhdl-template-modify]'), this string is searched and the rest
1001 of the line replaced by the current date."
1002 :type 'string
1003 :group 'vhdl-header)
1004
1005 (defcustom vhdl-modify-date-on-saving t
1006 "*Non-nil means update the modification date when the buffer is saved.
1007 Calls function `\\[vhdl-template-modify]').
1008
1009 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1010 \"Activate Options\"."
1011 :type 'boolean
1012 :group 'vhdl-header)
1013
1014
1015 (defgroup vhdl-sequential-process nil
1016 "Customizations for sequential processes."
1017 :group 'vhdl-template)
1018
1019 (defcustom vhdl-reset-kind 'async
1020 "*Specifies which kind of reset to use in sequential processes."
1021 :type '(choice (const :tag "None" none)
1022 (const :tag "Synchronous" sync)
1023 (const :tag "Asynchronous" async))
1024 :group 'vhdl-sequential-process)
1025
1026 (defcustom vhdl-reset-active-high nil
1027 "*Non-nil means reset in sequential processes is active high.
1028 Otherwise, reset is active low."
1029 :type 'boolean
1030 :group 'vhdl-sequential-process)
1031
1032 (defcustom vhdl-clock-rising-edge t
1033 "*Non-nil means rising edge of clock triggers sequential processes.
1034 Otherwise, falling edge triggers."
1035 :type 'boolean
1036 :group 'vhdl-sequential-process)
1037
1038 (defcustom vhdl-clock-edge-condition 'standard
1039 "*Syntax of the clock edge condition.
1040 Standard: \"clk'event and clk = '1'\"
1041 Function: \"rising_edge(clk)\""
1042 :type '(choice (const :tag "Standard" standard)
1043 (const :tag "Function" function))
1044 :group 'vhdl-sequential-process)
1045
1046 (defcustom vhdl-clock-name ""
1047 "*Name of clock signal to use in templates."
1048 :type 'string
1049 :group 'vhdl-sequential-process)
1050
1051 (defcustom vhdl-reset-name ""
1052 "*Name of reset signal to use in templates."
1053 :type 'string
1054 :group 'vhdl-sequential-process)
1055
1056
1057 (defgroup vhdl-model nil
1058 "Customizations for user models."
1059 :group 'vhdl)
1060
1061 (defcustom vhdl-model-alist
1062 '(("Example Model"
1063 "<label> : process (<clock>, <reset>)
1064 begin -- process <label>
1065 if <reset> = '0' then -- asynchronous reset (active low)
1066 <cursor>
1067 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1068 if <enable> = '1' then -- synchronous load
1069
1070 end if;
1071 end if;
1072 end process <label>;"
1073 "e" ""))
1074 "*List of user models.
1075 VHDL models (templates) can be specified by the user in this list. They can be
1076 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1077 electrification (i.e. overriding existing or creating new keywords, see
1078 option `vhdl-electric-keywords').
1079 Name : name of model (string of words and spaces)
1080 String : string or name of file to be inserted as model (newline: `C-j')
1081 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1082 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1083 Keyword : keyword to invoke model
1084
1085 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1086 A prompt that appears several times is queried once and replaced throughout
1087 the model. Special prompts are:
1088 <clock> : name specified in `vhdl-clock-name' (if not empty)
1089 <reset> : name specified in `vhdl-reset-name' (if not empty)
1090 <cursor>: final cursor position
1091 File header prompts (see variable `vhdl-file-header') are automatically
1092 replaced, so that user models can also be used to insert different types of
1093 headers.
1094
1095 If the string specifies an existing file name, the contents of the file is
1096 inserted, otherwise the string itself is inserted.
1097 The code within the models should be correctly indented.
1098 Type `C-j' for newlines.
1099
1100 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1101 \"Activate Options\"."
1102 :type '(repeat (list :tag "Model" :indent 2
1103 (string :tag "Name ")
1104 (string :tag "String : (type `C-j' for newline)"
1105 :format "%t\n%v")
1106 (sexp :tag "Key binding" x)
1107 (string :tag "Keyword " :format "%t: %v\n")))
1108 :set (lambda (variable value)
1109 (vhdl-custom-set variable value
1110 'vhdl-model-map-init
1111 'vhdl-model-defun
1112 'vhdl-mode-abbrev-table-init
1113 'vhdl-update-mode-menu))
1114 :group 'vhdl-model)
1115
1116
1117 (defgroup vhdl-compose nil
1118 "Customizations for structural composition."
1119 :group 'vhdl)
1120
1121 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1122 (concat
1123 "*Specifies how the component architecture name is obtained.
1124 The component architecture name can be obtained by modifying the entity name
1125 \(e.g. attaching or stripping off a substring).
1126 If TO STRING is empty, the architecture name is queried."
1127 vhdl-name-doc-string)
1128 :type '(cons (regexp :tag "From regexp")
1129 (string :tag "To string "))
1130 :group 'vhdl-compose)
1131
1132 (defcustom vhdl-compose-configuration-name
1133 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1134 (concat
1135 "*Specifies how the configuration name is obtained.
1136 The configuration name can be obtained by modifying the entity and/or
1137 architecture name (e.g. attaching or stripping off a substring). The string
1138 that is matched against the regexp is the concatenation of the entity and the
1139 architecture name separated by a space. This gives access to both names (see
1140 default setting as example)."
1141 vhdl-name-doc-string)
1142 :type '(cons (regexp :tag "From regexp")
1143 (string :tag "To string "))
1144 :group 'vhdl-compose)
1145
1146 (defcustom vhdl-components-package-name
1147 '((".*" . "\\&_components") . "components")
1148 (concat
1149 "*Specifies how the name for the components package is obtained.
1150 The components package is a package containing all component declarations for
1151 the current design. Its name can be obtained by modifying the project name
1152 \(e.g. attaching or stripping off a substring). If no project is defined, the
1153 DIRECTORY entry is chosen."
1154 vhdl-name-doc-string)
1155 :type '(cons (cons :tag "Project" :indent 2
1156 (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 (string :tag "Directory:\n String "))
1159 :group 'vhdl-compose)
1160
1161 (defcustom vhdl-use-components-package nil
1162 "*Non-nil means use a separate components package for component declarations.
1163 Otherwise, component declarations are inserted and searched for in the
1164 architecture declarative parts."
1165 :type 'boolean
1166 :group 'vhdl-compose)
1167
1168 (defcustom vhdl-compose-include-header t
1169 "*Non-nil means include a header in automatically generated files."
1170 :type 'boolean
1171 :group 'vhdl-compose)
1172
1173 (defcustom vhdl-compose-create-files 'single
1174 "*Specifies whether new files should be created for the new component.
1175 The component's entity and architecture are inserted:
1176 None : in current buffer
1177 Single file : in new single file
1178 Separate files: in two separate files
1179 The file names are obtained from variables `vhdl-entity-file-name' and
1180 `vhdl-architecture-file-name'."
1181 :type '(choice (const :tag "None" none)
1182 (const :tag "Single file" single)
1183 (const :tag "Separate files" separate))
1184 :group 'vhdl-compose)
1185
1186 (defcustom vhdl-compose-configuration-create-file nil
1187 "*Specifies whether a new file should be created for the configuration.
1188 If non-nil, a new file is created for the configuration.
1189 The file name is obtained from variable `vhdl-configuration-file-name'."
1190 :type 'boolean
1191 :group 'vhdl-compose)
1192
1193 (defcustom vhdl-compose-configuration-hierarchical t
1194 "*Specifies whether hierarchical configurations should be created.
1195 If non-nil, automatically created configurations are hierarchical and include
1196 the whole hierarchy of subcomponents. Otherwise the configuration only
1197 includes one level of subcomponents."
1198 :type 'boolean
1199 :group 'vhdl-compose)
1200
1201 (defcustom vhdl-compose-configuration-use-subconfiguration t
1202 "*Specifies whether subconfigurations should be used inside configurations.
1203 If non-nil, automatically created configurations use configurations in binding
1204 indications for subcomponents, if such configurations exist. Otherwise,
1205 entities are used in binding indications for subcomponents."
1206 :type 'boolean
1207 :group 'vhdl-compose)
1208
1209
1210 (defgroup vhdl-port nil
1211 "Customizations for port translation functions."
1212 :group 'vhdl
1213 :group 'vhdl-compose)
1214
1215 (defcustom vhdl-include-port-comments nil
1216 "*Non-nil means include port comments when a port is pasted."
1217 :type 'boolean
1218 :group 'vhdl-port)
1219
1220 (defcustom vhdl-include-direction-comments nil
1221 "*Non-nil means include port direction in instantiations as comments."
1222 :type 'boolean
1223 :group 'vhdl-port)
1224
1225 (defcustom vhdl-include-type-comments nil
1226 "*Non-nil means include generic/port type in instantiations as comments."
1227 :type 'boolean
1228 :group 'vhdl-port)
1229
1230 (defcustom vhdl-include-group-comments 'never
1231 "*Specifies whether to include group comments and spacings.
1232 The comments and empty lines between groups of ports are pasted:
1233 Never : never
1234 Declarations: in entity/component/constant/signal declarations only
1235 Always : also in generic/port maps"
1236 :type '(choice (const :tag "Never" never)
1237 (const :tag "Declarations" decl)
1238 (const :tag "Always" always))
1239 :group 'vhdl-port)
1240
1241 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1242 (concat
1243 "*Specifies how actual port names are obtained from formal port names.
1244 In a component instantiation, an actual port name can be obtained by
1245 modifying the formal port name (e.g. attaching or stripping off a substring)."
1246 vhdl-name-doc-string)
1247 :type '(cons (regexp :tag "From regexp")
1248 (string :tag "To string "))
1249 :group 'vhdl-port)
1250
1251 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1252 (concat
1253 "*Specifies how an instance name is obtained.
1254 The instance name can be obtained by modifying the name of the component to be
1255 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1256 by a unique number (starting with 1).
1257 If TO STRING is empty, the instance name is queried."
1258 vhdl-name-doc-string)
1259 :type '(cons (regexp :tag "From regexp")
1260 (string :tag "To string "))
1261 :group 'vhdl-port)
1262
1263
1264 (defgroup vhdl-testbench nil
1265 "Customizations for testbench generation."
1266 :group 'vhdl-port)
1267
1268 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1269 (concat
1270 "*Specifies how the testbench entity name is obtained.
1271 The entity name of a testbench can be obtained by modifying the name of
1272 the component to be tested (e.g. attaching or stripping off a substring)."
1273 vhdl-name-doc-string)
1274 :type '(cons (regexp :tag "From regexp")
1275 (string :tag "To string "))
1276 :group 'vhdl-testbench)
1277
1278 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1279 (concat
1280 "*Specifies how the testbench architecture name is obtained.
1281 The testbench architecture name can be obtained by modifying the name of
1282 the component to be tested (e.g. attaching or stripping off a substring).
1283 If TO STRING is empty, the architecture name is queried."
1284 vhdl-name-doc-string)
1285 :type '(cons (regexp :tag "From regexp")
1286 (string :tag "To string "))
1287 :group 'vhdl-testbench)
1288
1289 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1290 (concat
1291 "*Specifies how the testbench configuration name is obtained.
1292 The configuration name of a testbench can be obtained by modifying the entity
1293 and/or architecture name (e.g. attaching or stripping off a substring). The
1294 string that is matched against the regexp is the concatenation of the entity
1295 and the architecture name separated by a space. This gives access to both
1296 names (see default setting as example)."
1297 vhdl-name-doc-string)
1298 :type '(cons (regexp :tag "From regexp")
1299 (string :tag "To string "))
1300 :group 'vhdl-testbench)
1301
1302 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1303 (concat
1304 "*Specifies how a DUT instance name is obtained.
1305 The design-under-test instance name (i.e. the component instantiated in the
1306 testbench) can be obtained by modifying the component name (e.g. attaching
1307 or stripping off a substring)."
1308 vhdl-name-doc-string)
1309 :type '(cons (regexp :tag "From regexp")
1310 (string :tag "To string "))
1311 :group 'vhdl-testbench)
1312
1313 (defcustom vhdl-testbench-include-header t
1314 "*Non-nil means include a header in automatically generated files."
1315 :type 'boolean
1316 :group 'vhdl-testbench)
1317
1318 (defcustom vhdl-testbench-declarations "\
1319 -- clock
1320 signal Clk : std_logic := '1';
1321 "
1322 "*String or file to be inserted in the testbench declarative part.
1323 If the string specifies an existing file name, the contents of the file is
1324 inserted, otherwise the string itself is inserted in the testbench
1325 architecture before the BEGIN keyword.
1326 Type `C-j' for newlines."
1327 :type 'string
1328 :group 'vhdl-testbench)
1329
1330 (defcustom vhdl-testbench-statements "\
1331 -- clock generation
1332 Clk <= not Clk after 10 ns;
1333
1334 -- waveform generation
1335 WaveGen_Proc: process
1336 begin
1337 -- insert signal assignments here
1338
1339 wait until Clk = '1';
1340 end process WaveGen_Proc;
1341 "
1342 "*String or file to be inserted in the testbench statement part.
1343 If the string specifies an existing file name, the contents of the file is
1344 inserted, otherwise the string itself is inserted in the testbench
1345 architecture before the END keyword.
1346 Type `C-j' for newlines."
1347 :type 'string
1348 :group 'vhdl-testbench)
1349
1350 (defcustom vhdl-testbench-initialize-signals nil
1351 "*Non-nil means initialize signals with `0' when declared in testbench."
1352 :type 'boolean
1353 :group 'vhdl-testbench)
1354
1355 (defcustom vhdl-testbench-include-library t
1356 "*Non-nil means a library/use clause for std_logic_1164 is included."
1357 :type 'boolean
1358 :group 'vhdl-testbench)
1359
1360 (defcustom vhdl-testbench-include-configuration t
1361 "*Non-nil means a testbench configuration is attached at the end."
1362 :type 'boolean
1363 :group 'vhdl-testbench)
1364
1365 (defcustom vhdl-testbench-create-files 'single
1366 "*Specifies whether new files should be created for the testbench.
1367 testbench entity and architecture are inserted:
1368 None : in current buffer
1369 Single file : in new single file
1370 Separate files: in two separate files
1371 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1372 and `vhdl-testbench-architecture-file-name'."
1373 :type '(choice (const :tag "None" none)
1374 (const :tag "Single file" single)
1375 (const :tag "Separate files" separate))
1376 :group 'vhdl-testbench)
1377
1378 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1379 (concat
1380 "*Specifies how the testbench entity file name is obtained.
1381 The entity file name can be obtained by modifying the testbench entity name
1382 \(e.g. attaching or stripping off a substring). The file extension is
1383 automatically taken from the file name of the current buffer. Testbench
1384 files can be created in a different directory by prepending a relative or
1385 absolute path to the file name."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1390
1391 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1392 (concat
1393 "*Specifies how the testbench architecture file name is obtained.
1394 The architecture file name can be obtained by modifying the testbench entity
1395 and/or architecture name (e.g. attaching or stripping off a substring). The
1396 string that is matched against the regexp is the concatenation of the entity
1397 and the architecture name separated by a space. This gives access to both
1398 names (see default setting as example). Testbench files can be created in
1399 a different directory by prepending a relative or absolute path to the file
1400 name."
1401 vhdl-name-doc-string)
1402 :type '(cons (regexp :tag "From regexp")
1403 (string :tag "To string "))
1404 :group 'vhdl-testbench)
1405
1406
1407 (defgroup vhdl-comment nil
1408 "Customizations for comments."
1409 :group 'vhdl)
1410
1411 (defcustom vhdl-self-insert-comments t
1412 "*Non-nil means various templates automatically insert help comments."
1413 :type 'boolean
1414 :group 'vhdl-comment)
1415
1416 (defcustom vhdl-prompt-for-comments t
1417 "*Non-nil means various templates prompt for user definable comments."
1418 :type 'boolean
1419 :group 'vhdl-comment)
1420
1421 (defcustom vhdl-inline-comment-column 40
1422 "*Column to indent and align inline comments to.
1423 Overrides local option `comment-column'.
1424
1425 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1426 \"Activate Options\"."
1427 :type 'integer
1428 :group 'vhdl-comment)
1429
1430 (defcustom vhdl-end-comment-column 79
1431 "*End of comment column.
1432 Comments that exceed this column number are wrapped.
1433
1434 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1435 \"Activate Options\"."
1436 :type 'integer
1437 :group 'vhdl-comment)
1438
1439 (defvar end-comment-column)
1440
1441
1442 (defgroup vhdl-align nil
1443 "Customizations for alignment."
1444 :group 'vhdl)
1445
1446 (defcustom vhdl-auto-align t
1447 "*Non-nil means align some templates automatically after generation."
1448 :type 'boolean
1449 :group 'vhdl-align)
1450
1451 (defcustom vhdl-align-groups t
1452 "*Non-nil means align groups of code lines separately.
1453 A group of code lines is a region of consecutive lines between two lines that
1454 match the regexp in option `vhdl-align-group-separate'."
1455 :type 'boolean
1456 :group 'vhdl-align)
1457
1458 (defcustom vhdl-align-group-separate "^\\s-*$"
1459 "*Regexp for matching a line that separates groups of lines for alignment.
1460 Examples:
1461 \"^\\s-*$\": matches an empty line
1462 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1463 :type 'regexp
1464 :group 'vhdl-align)
1465
1466 (defcustom vhdl-align-same-indent t
1467 "*Non-nil means align blocks with same indent separately.
1468 When a region or the entire buffer is aligned, the code is divided into
1469 blocks of same indent which are aligned separately (except for argument/port
1470 lists). This gives nicer alignment in most cases.
1471 Option `vhdl-align-groups' still applies within these blocks."
1472 :type 'boolean
1473 :group 'vhdl-align)
1474
1475
1476 (defgroup vhdl-highlight nil
1477 "Customizations for highlighting."
1478 :group 'vhdl)
1479
1480 (defcustom vhdl-highlight-keywords t
1481 "*Non-nil means highlight VHDL keywords and other standardized words.
1482 The following faces are used:
1483 `font-lock-keyword-face' : keywords
1484 `font-lock-type-face' : standardized types
1485 `vhdl-font-lock-attribute-face': standardized attributes
1486 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1487 `vhdl-font-lock-function-face' : standardized function and package names
1488
1489 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1490 entry \"Fontify Buffer\")."
1491 :type 'boolean
1492 :set (lambda (variable value)
1493 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1494 :group 'vhdl-highlight)
1495
1496 (defcustom vhdl-highlight-names t
1497 "*Non-nil means highlight declaration names and construct labels.
1498 The following faces are used:
1499 `font-lock-function-name-face' : names in declarations of units,
1500 subprograms, components, as well as labels of VHDL constructs
1501 `font-lock-type-face' : names in type/nature declarations
1502 `vhdl-font-lock-attribute-face': names in attribute declarations
1503 `font-lock-variable-name-face' : names in declarations of signals,
1504 variables, constants, subprogram parameters, generics, and ports
1505
1506 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1507 entry \"Fontify Buffer\")."
1508 :type 'boolean
1509 :set (lambda (variable value)
1510 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1511 :group 'vhdl-highlight)
1512
1513 (defcustom vhdl-highlight-special-words nil
1514 "*Non-nil means highlight words with special syntax.
1515 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1516 are highlighted accordingly.
1517 Can be used for visual support of naming conventions.
1518
1519 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1520 entry \"Fontify Buffer\")."
1521 :type 'boolean
1522 :set (lambda (variable value)
1523 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1524 :group 'vhdl-highlight)
1525
1526 (defcustom vhdl-highlight-forbidden-words nil
1527 "*Non-nil means highlight forbidden words.
1528 The reserved words specified in option `vhdl-forbidden-words' or having the
1529 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1530 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1531 use them.
1532
1533 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1534 entry \"Fontify Buffer\")."
1535 :type 'boolean
1536 :set (lambda (variable value)
1537 (vhdl-custom-set variable value
1538 'vhdl-words-init 'vhdl-font-lock-init))
1539 :group 'vhdl-highlight)
1540
1541 (defcustom vhdl-highlight-verilog-keywords nil
1542 "*Non-nil means highlight Verilog keywords as reserved words.
1543 Verilog keywords are highlighted in a warning color (face
1544 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
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
1551 'vhdl-words-init 'vhdl-font-lock-init))
1552 :group 'vhdl-highlight)
1553
1554 (defcustom vhdl-highlight-translate-off nil
1555 "*Non-nil means background-highlight code excluded from translation.
1556 That is, all code between \"-- pragma translate_off\" and
1557 \"-- pragma translate_on\" is highlighted using a different background color
1558 \(face `vhdl-font-lock-translate-off-face').
1559 Note: this might slow down on-the-fly fontification (and thus editing).
1560
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1563 :type 'boolean
1564 :set (lambda (variable value)
1565 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1566 :group 'vhdl-highlight)
1567
1568 (defcustom vhdl-highlight-case-sensitive nil
1569 "*Non-nil means consider case for highlighting.
1570 Possible trade-off:
1571 non-nil also upper-case VHDL words are highlighted, but case of words with
1572 special syntax is not considered
1573 nil only lower-case VHDL words are highlighted, but case of words with
1574 special syntax is considered
1575 Overrides local option `font-lock-keywords-case-fold-search'.
1576
1577 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1578 entry \"Fontify Buffer\")."
1579 :type 'boolean
1580 :group 'vhdl-highlight)
1581
1582 (defcustom vhdl-special-syntax-alist
1583 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1584 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1585 ("variable" "\\w+_v" "Grey50" "Grey80"))
1586 "*List of special syntax to be highlighted.
1587 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1588 syntax (as regular expression) are highlighted in the corresponding color.
1589
1590 Name : string of words and spaces
1591 Regexp : regular expression describing word syntax
1592 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1593 Color (light): foreground color for light background
1594 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1595 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1596 Color (dark) : foreground color for dark background
1597 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1598 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1599
1600 Can be used for visual support of naming conventions, such as highlighting
1601 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1602 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1603 common substrings or name suffices.
1604 For each entry, a new face is generated with the specified colors and name
1605 \"vhdl-font-lock-\" + name + \"-face\".
1606
1607 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1608 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1609 :type '(repeat (list :tag "Face" :indent 2
1610 (string :tag "Name ")
1611 (regexp :tag "Regexp " "\\w+_")
1612 (string :tag "Color (light)")
1613 (string :tag "Color (dark) ")))
1614 :set (lambda (variable value)
1615 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1616 :group 'vhdl-highlight)
1617
1618 (defcustom vhdl-forbidden-words '()
1619 "*List of forbidden words to be highlighted.
1620 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1621 words are highlighted in a warning color to indicate not to use them.
1622
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type '(repeat (string :format "%v"))
1626 :set (lambda (variable value)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
1630
1631 (defcustom vhdl-forbidden-syntax ""
1632 "*Syntax of forbidden words to be highlighted.
1633 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1634 syntax are highlighted in a warning color to indicate not to use them.
1635 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1636 highlights identifiers with 10 or more characters).
1637
1638 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\")."
1640 :type 'regexp
1641 :set (lambda (variable value)
1642 (vhdl-custom-set variable value
1643 'vhdl-words-init 'vhdl-font-lock-init))
1644 :group 'vhdl-highlight)
1645
1646 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1647 "*List of compiler directive keywords recognized for highlighting.
1648
1649 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1650 entry \"Fontify Buffer\")."
1651 :type '(repeat (string :format "%v"))
1652 :set (lambda (variable value)
1653 (vhdl-custom-set variable value
1654 'vhdl-words-init 'vhdl-font-lock-init))
1655 :group 'vhdl-highlight)
1656
1657
1658 (defgroup vhdl-speedbar nil
1659 "Customizations for speedbar."
1660 :group 'vhdl)
1661
1662 (defcustom vhdl-speedbar-auto-open nil
1663 "*Non-nil means automatically open speedbar at startup.
1664 Alternatively, the speedbar can be opened from the VHDL menu."
1665 :type 'boolean
1666 :group 'vhdl-speedbar)
1667
1668 (defcustom vhdl-speedbar-display-mode 'files
1669 "*Specifies the default displaying mode when opening speedbar.
1670 Alternatively, the displaying mode can be selected from the speedbar menu or
1671 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1672 :type '(choice (const :tag "Files" files)
1673 (const :tag "Directory hierarchy" directory)
1674 (const :tag "Project hierarchy" project))
1675 :group 'vhdl-speedbar)
1676
1677 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1678 "*Limits scanning of large files and netlists.
1679 Design units: maximum file size to scan for design units
1680 Hierarchy (instances of subcomponents):
1681 File size: maximum file size to scan for instances (in bytes)
1682 Instances per arch: maximum number of instances to scan per architecture
1683
1684 \"None\" always means that there is no limit.
1685 In case of files not or incompletely scanned, a warning message and the file
1686 names are printed out.
1687 Background: scanning for instances is considerably slower than scanning for
1688 design units, especially when there are many instances. These limits should
1689 prevent the scanning of large netlists."
1690 :type '(list (choice :tag "Design units"
1691 :format "%t : %[Value Menu%] %v"
1692 (const :tag "None" nil)
1693 (integer :tag "File size"))
1694 (list :tag "Hierarchy" :indent 2
1695 (choice :tag "File size"
1696 :format "%t : %[Value Menu%] %v"
1697 (const :tag "None" nil)
1698 (integer :tag "Size "))
1699 (choice :tag "Instances per arch"
1700 (const :tag "None" nil)
1701 (integer :tag "Number "))))
1702 :group 'vhdl-speedbar)
1703
1704 (defcustom vhdl-speedbar-jump-to-unit t
1705 "*Non-nil means jump to the design unit code when opened in a buffer.
1706 The buffer cursor position is left unchanged otherwise."
1707 :type 'boolean
1708 :group 'vhdl-speedbar)
1709
1710 (defcustom vhdl-speedbar-update-on-saving t
1711 "*Automatically update design hierarchy when buffer is saved."
1712 :type 'boolean
1713 :group 'vhdl-speedbar)
1714
1715 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1716 "*Automatically save modified hierarchy caches when exiting Emacs.
1717 Hierarchy: design hierarchy information
1718 Display: displaying information (which design units to expand)"
1719 :type '(set (const :tag "Hierarchy" hierarchy)
1720 (const :tag "Display" display))
1721 :group 'vhdl-speedbar)
1722
1723 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1724 "*Name of file for saving hierarchy cache.
1725 \"\\1\" is replaced by the project name if a project is specified,
1726 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1727 different users to have cache files in the same directory). Can also have
1728 an absolute path (i.e. all caches can be stored in one global directory)."
1729 :type 'string
1730 :group 'vhdl-speedbar)
1731
1732
1733 (defgroup vhdl-menu nil
1734 "Customizations for menues."
1735 :group 'vhdl)
1736
1737 (defcustom vhdl-index-menu nil
1738 "*Non-nil means add an index menu for a source file when loading.
1739 Alternatively, the speedbar can be used. Note that the index menu scans a file
1740 when it is opened, while speedbar only scans the file upon request."
1741 :type 'boolean
1742 :group 'vhdl-menu)
1743
1744 (defcustom vhdl-source-file-menu nil
1745 "*Non-nil means add a menu of all source files in current directory.
1746 Alternatively, the speedbar can be used."
1747 :type 'boolean
1748 :group 'vhdl-menu)
1749
1750 (defcustom vhdl-hideshow-menu nil
1751 "*Non-nil means add hideshow menu and functionality at startup.
1752 Hideshow can also be enabled from the VHDL Mode menu.
1753 Hideshow allows hiding code of various VHDL constructs.
1754
1755 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1756 \"Activate Options\"."
1757 :type 'boolean
1758 :group 'vhdl-menu)
1759
1760 (defcustom vhdl-hide-all-init nil
1761 "*Non-nil means hide all design units initially after a file is loaded."
1762 :type 'boolean
1763 :group 'vhdl-menu)
1764
1765
1766 (defgroup vhdl-print nil
1767 "Customizations for printing."
1768 :group 'vhdl)
1769
1770 (defcustom vhdl-print-two-column t
1771 "*Non-nil means print code in two columns and landscape format.
1772 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1773 prints VHDL files in a nice two-column landscape style.
1774
1775 NOTE: Activate the new setting by restarting Emacs.
1776 Overrides `ps-print' settings locally."
1777 :type 'boolean
1778 :group 'vhdl-print)
1779
1780 (defcustom vhdl-print-customize-faces t
1781 "*Non-nil means use an optimized set of faces for postscript printing.
1782
1783 NOTE: Activate the new setting by restarting Emacs.
1784 Overrides `ps-print' settings locally."
1785 :type 'boolean
1786 :group 'vhdl-print)
1787
1788
1789 (defgroup vhdl-misc nil
1790 "Miscellaneous customizations."
1791 :group 'vhdl)
1792
1793 (defcustom vhdl-intelligent-tab t
1794 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1795 That is, if preceding character is part of a word then complete word,
1796 else if not at beginning of line then insert tab,
1797 else if last command was a `TAB' or `RET' then dedent one step,
1798 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1799 If nil, TAB always indents current line (i.e. `TAB' is bound to
1800 `indent-according-to-mode').
1801
1802 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1803 \"Activate Options\"."
1804 :type 'boolean
1805 :group 'vhdl-misc)
1806
1807 (defcustom vhdl-indent-syntax-based t
1808 "*Non-nil means indent lines of code based on their syntactic context.
1809 Otherwise, a line is indented like the previous nonblank line. This can be
1810 useful in large files where syntax-based indentation gets very slow."
1811 :type 'boolean
1812 :group 'vhdl-misc)
1813
1814 (defcustom vhdl-word-completion-case-sensitive nil
1815 "*Non-nil means word completion using `TAB' is case sensitive.
1816 That is, `TAB' completes words that start with the same letters and case.
1817 Otherwise, case is ignored."
1818 :type 'boolean
1819 :group 'vhdl-misc)
1820
1821 (defcustom vhdl-word-completion-in-minibuffer t
1822 "*Non-nil enables word completion in minibuffer (for template prompts).
1823
1824 NOTE: Activate the new setting by restarting Emacs."
1825 :type 'boolean
1826 :group 'vhdl-misc)
1827
1828 (defcustom vhdl-underscore-is-part-of-word nil
1829 "*Non-nil means consider the underscore character `_' as part of word.
1830 An identifier containing underscores is then treated as a single word in
1831 select and move operations. All parts of an identifier separated by underscore
1832 are treated as single words otherwise.
1833
1834 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1835 \"Activate Options\"."
1836 :type 'boolean
1837 :set (lambda (variable value)
1838 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1839 :group 'vhdl-misc)
1840
1841
1842 (defgroup vhdl-related nil
1843 "Related general customizations."
1844 :group 'vhdl)
1845
1846 ;; add related general customizations
1847 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1848 (if (featurep 'xemacs)
1849 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1850 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1851 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1852 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1853 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1854 (unless (featurep 'xemacs)
1855 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1856 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1857 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1858 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1859
1860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1861 ;; Internal variables
1862
1863 (defvar vhdl-menu-max-size 20
1864 "*Specifies the maximum size of a menu before splitting it into submenues.")
1865
1866 (defvar vhdl-progress-interval 1
1867 "*Interval used to update progress status during long operations.
1868 If a number, percentage complete gets updated after each interval of
1869 that many seconds. To inhibit all messages, set this option to nil.")
1870
1871 (defvar vhdl-inhibit-startup-warnings-p nil
1872 "*If non-nil, inhibits start up compatibility warnings.")
1873
1874 (defvar vhdl-strict-syntax-p nil
1875 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1876 If the syntactic symbol for a particular line does not match a symbol
1877 in the offsets alist, an error is generated, otherwise no error is
1878 reported and the syntactic symbol is ignored.")
1879
1880 (defvar vhdl-echo-syntactic-information-p nil
1881 "*If non-nil, syntactic info is echoed when the line is indented.")
1882
1883 (defconst vhdl-offsets-alist-default
1884 '((string . -1000)
1885 (cpp-macro . -1000)
1886 (block-open . 0)
1887 (block-close . 0)
1888 (statement . 0)
1889 (statement-cont . vhdl-lineup-statement-cont)
1890 (statement-block-intro . +)
1891 (statement-case-intro . +)
1892 (case-alternative . +)
1893 (comment . vhdl-lineup-comment)
1894 (arglist-intro . +)
1895 (arglist-cont . 0)
1896 (arglist-cont-nonempty . vhdl-lineup-arglist)
1897 (arglist-close . vhdl-lineup-arglist)
1898 (entity . 0)
1899 (configuration . 0)
1900 (package . 0)
1901 (architecture . 0)
1902 (package-body . 0)
1903 )
1904 "Default settings for offsets of syntactic elements.
1905 Do not change this constant! See the variable `vhdl-offsets-alist' for
1906 more information.")
1907
1908 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1909 "*Association list of syntactic element symbols and indentation offsets.
1910 As described below, each cons cell in this list has the form:
1911
1912 (SYNTACTIC-SYMBOL . OFFSET)
1913
1914 When a line is indented, `vhdl-mode' first determines the syntactic
1915 context of the line by generating a list of symbols called syntactic
1916 elements. This list can contain more than one syntactic element and
1917 the global variable `vhdl-syntactic-context' contains the context list
1918 for the line being indented. Each element in this list is actually a
1919 cons cell of the syntactic symbol and a buffer position. This buffer
1920 position is call the relative indent point for the line. Some
1921 syntactic symbols may not have a relative indent point associated with
1922 them.
1923
1924 After the syntactic context list for a line is generated, `vhdl-mode'
1925 calculates the absolute indentation for the line by looking at each
1926 syntactic element in the list. First, it compares the syntactic
1927 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1928 finds a match, it adds the OFFSET to the column of the relative indent
1929 point. The sum of this calculation for each element in the syntactic
1930 list is the absolute offset for line being indented.
1931
1932 If the syntactic element does not match any in the `vhdl-offsets-alist',
1933 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1934 the element is ignored.
1935
1936 Actually, OFFSET can be an integer, a function, a variable, or one of
1937 the following symbols: `+', `-', `++', or `--'. These latter
1938 designate positive or negative multiples of `vhdl-basic-offset',
1939 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1940 called with a single argument containing the cons of the syntactic
1941 element symbol and the relative indent point. The function should
1942 return an integer offset.
1943
1944 Here is the current list of valid syntactic element symbols:
1945
1946 string -- inside multi-line string
1947 block-open -- statement block open
1948 block-close -- statement block close
1949 statement -- a VHDL statement
1950 statement-cont -- a continuation of a VHDL statement
1951 statement-block-intro -- the first line in a new statement block
1952 statement-case-intro -- the first line in a case alternative block
1953 case-alternative -- a case statement alternative clause
1954 comment -- a line containing only a comment
1955 arglist-intro -- the first line in an argument list
1956 arglist-cont -- subsequent argument list lines when no
1957 arguments follow on the same line as the
1958 the arglist opening paren
1959 arglist-cont-nonempty -- subsequent argument list lines when at
1960 least one argument follows on the same
1961 line as the arglist opening paren
1962 arglist-close -- the solo close paren of an argument list
1963 entity -- inside an entity declaration
1964 configuration -- inside a configuration declaration
1965 package -- inside a package declaration
1966 architecture -- inside an architecture body
1967 package-body -- inside a package body")
1968
1969 (defvar vhdl-comment-only-line-offset 0
1970 "*Extra offset for line which contains only the start of a comment.
1971 Can contain an integer or a cons cell of the form:
1972
1973 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1974
1975 Where NON-ANCHORED-OFFSET is the amount of offset given to
1976 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1977 the amount of offset to give column-zero anchored comment-only lines.
1978 Just an integer as value is equivalent to (<val> . 0)")
1979
1980 (defvar vhdl-special-indent-hook nil
1981 "*Hook for user defined special indentation adjustments.
1982 This hook gets called after a line is indented by the mode.")
1983
1984 (defvar vhdl-style-alist
1985 '(("IEEE"
1986 (vhdl-basic-offset . 4)
1987 (vhdl-offsets-alist . ())))
1988 "Styles of Indentation.
1989 Elements of this alist are of the form:
1990
1991 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1992
1993 where STYLE-STRING is a short descriptive string used to select a
1994 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1995 value for that variable when using the selected style.
1996
1997 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1998 case, the VALUE is a list containing elements of the form:
1999
2000 (SYNTACTIC-SYMBOL . VALUE)
2001
2002 as described in `vhdl-offsets-alist'. These are passed directly to
2003 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2004 your style, only those that are different from the default.")
2005
2006 ;; dynamically append the default value of most variables
2007 (or (assoc "Default" vhdl-style-alist)
2008 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2009 vhdl-strict-syntax-p
2010 vhdl-echo-syntactic-information-p
2011 vhdl-basic-offset
2012 vhdl-offsets-alist
2013 vhdl-comment-only-line-offset))
2014 (default (cons "Default"
2015 (mapcar
2016 (function
2017 (lambda (var)
2018 (cons var (symbol-value var))))
2019 varlist))))
2020 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2021
2022 (defvar vhdl-mode-hook nil
2023 "*Hook called by `vhdl-mode'.")
2024
2025
2026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2027 ;;; Required packages
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029
2030 ;; mandatory
2031 (require 'assoc)
2032 (require 'compile) ; XEmacs
2033 (require 'easymenu)
2034 (require 'hippie-exp)
2035
2036 ;; optional (minimize warning messages during compile)
2037 (eval-when-compile
2038 (require 'font-lock)
2039 (require 'ps-print)
2040 (require 'speedbar))
2041
2042
2043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2044 ;;; Compatibility
2045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2046
2047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2048 ;; XEmacs compatibility
2049
2050 ;; active regions
2051 (defun vhdl-keep-region-active ()
2052 "Do whatever is necessary to keep the region active in XEmacs.
2053 Ignore byte-compiler warnings you might see."
2054 (and (featurep 'xemacs)
2055 (setq zmacs-region-stays t)))
2056
2057 ;; `wildcard-to-regexp' is included only in XEmacs 21
2058 (unless (fboundp 'wildcard-to-regexp)
2059 (defun wildcard-to-regexp (wildcard)
2060 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2061 (let* ((i (string-match "[*?]" wildcard))
2062 (result (substring wildcard 0 i))
2063 (len (length wildcard)))
2064 (when i
2065 (while (< i len)
2066 (let ((ch (aref wildcard i)))
2067 (setq result (concat result
2068 (cond ((eq ch ?*) "[^\000]*")
2069 ((eq ch ??) "[^\000]")
2070 (t (char-to-string ch)))))
2071 (setq i (1+ i)))))
2072 (concat "\\`" result "\\'"))))
2073
2074 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2075 ;; `regexp-opt' accelerates fontification by 10-20%
2076 (unless (fboundp 'regexp-opt)
2077 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2078 (defun regexp-opt (strings &optional paren)
2079 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2080 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2081
2082 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2083 (unless (fboundp 'match-string-no-properties)
2084 (defalias 'match-string-no-properties 'match-string))
2085
2086 ;; `subst-char-in-string' undefined (XEmacs)
2087 (unless (fboundp 'subst-char-in-string)
2088 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2089 (let ((i (length string))
2090 (newstr (if inplace string (copy-sequence string))))
2091 (while (> i 0)
2092 (setq i (1- i))
2093 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2094 newstr)))
2095
2096 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2097 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2098 (not noninteractive))
2099 (load "itimer")
2100 (when (string< itimer-version "1.09")
2101 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2102 (beep) (sit-for 5)))
2103
2104 ;; `file-expand-wildcards' undefined (XEmacs)
2105 (unless (fboundp 'file-expand-wildcards)
2106 (defun file-expand-wildcards (pattern &optional full)
2107 "Taken from Emacs' `files.el'."
2108 (let* ((nondir (file-name-nondirectory pattern))
2109 (dirpart (file-name-directory pattern))
2110 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2111 (mapcar 'file-name-as-directory
2112 (file-expand-wildcards (directory-file-name dirpart)))
2113 (list dirpart)))
2114 contents)
2115 (while dirs
2116 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2117 (file-directory-p (directory-file-name (car dirs))))
2118 (let ((this-dir-contents
2119 (delq nil
2120 (mapcar #'(lambda (name)
2121 (unless (string-match "\\`\\.\\.?\\'"
2122 (file-name-nondirectory name))
2123 name))
2124 (directory-files (or (car dirs) ".") full
2125 (wildcard-to-regexp nondir))))))
2126 (setq contents
2127 (nconc
2128 (if (and (car dirs) (not full))
2129 (mapcar (function (lambda (name) (concat (car dirs) name)))
2130 this-dir-contents)
2131 this-dir-contents)
2132 contents))))
2133 (setq dirs (cdr dirs)))
2134 contents)))
2135
2136 ;; `member-ignore-case' undefined (XEmacs)
2137 (unless (fboundp 'member-ignore-case)
2138 (defalias 'member-ignore-case 'member))
2139
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141 ;; Compatibility with older VHDL Mode versions
2142
2143 (defvar vhdl-warnings nil
2144 "Warnings to tell the user during start up.")
2145
2146 (defun vhdl-run-when-idle (secs repeat function)
2147 "Wait until idle, then run FUNCTION."
2148 (if (fboundp 'start-itimer)
2149 (start-itimer "vhdl-mode" function secs repeat t)
2150 ; (run-with-idle-timer secs repeat function)))
2151 ;; explicitely activate timer (necessary when Emacs is already idle)
2152 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2153
2154 (defun vhdl-warning-when-idle (&rest args)
2155 "Wait until idle, then print out warning STRING and beep."
2156 (if noninteractive
2157 (vhdl-warning (apply 'format args) t)
2158 (unless vhdl-warnings
2159 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2160 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2161
2162 (defun vhdl-warning (string &optional nobeep)
2163 "Print out warning STRING and beep."
2164 (message "WARNING: %s" string)
2165 (unless (or nobeep noninteractive) (beep)))
2166
2167 (defun vhdl-print-warnings ()
2168 "Print out messages in variable `vhdl-warnings'."
2169 (let ((no-warnings (length vhdl-warnings)))
2170 (setq vhdl-warnings (nreverse vhdl-warnings))
2171 (while vhdl-warnings
2172 (message "WARNING: %s" (car vhdl-warnings))
2173 (setq vhdl-warnings (cdr vhdl-warnings)))
2174 (beep)
2175 (when (> no-warnings 1)
2176 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2177
2178 ;; Backward compatibility checks and fixes
2179 ;; option `vhdl-compiler' changed format
2180 (unless (stringp vhdl-compiler)
2181 (setq vhdl-compiler "ModelSim")
2182 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2183
2184 ;; option `vhdl-standard' changed format
2185 (unless (listp vhdl-standard)
2186 (setq vhdl-standard '(87 nil))
2187 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2188
2189 ;; option `vhdl-model-alist' changed format
2190 (when (= (length (car vhdl-model-alist)) 3)
2191 (let ((old-alist vhdl-model-alist)
2192 new-alist)
2193 (while old-alist
2194 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2195 (setq old-alist (cdr old-alist)))
2196 (setq vhdl-model-alist (nreverse new-alist)))
2197 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2198
2199 ;; option `vhdl-project-alist' changed format
2200 (when (= (length (car vhdl-project-alist)) 3)
2201 (let ((old-alist vhdl-project-alist)
2202 new-alist)
2203 (while old-alist
2204 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2205 (setq old-alist (cdr old-alist)))
2206 (setq vhdl-project-alist (nreverse new-alist)))
2207 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2208
2209 ;; option `vhdl-project-alist' changed format (3.31.1)
2210 (when (= (length (car vhdl-project-alist)) 4)
2211 (let ((old-alist vhdl-project-alist)
2212 new-alist elem)
2213 (while old-alist
2214 (setq elem (car old-alist))
2215 (setq new-alist
2216 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2217 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2218 new-alist))
2219 (setq old-alist (cdr old-alist)))
2220 (setq vhdl-project-alist (nreverse new-alist)))
2221 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2222
2223 ;; option `vhdl-project-alist' changed format (3.31.12)
2224 (when (= (length (car vhdl-project-alist)) 10)
2225 (let ((tmp-alist vhdl-project-alist))
2226 (while tmp-alist
2227 (setcdr (nthcdr 3 (car tmp-alist))
2228 (cons "" (nthcdr 4 (car tmp-alist))))
2229 (setq tmp-alist (cdr tmp-alist))))
2230 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2231
2232 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2233 (when (= (length (car vhdl-compiler-alist)) 7)
2234 (let ((old-alist vhdl-compiler-alist)
2235 new-alist elem)
2236 (while old-alist
2237 (setq elem (car old-alist))
2238 (setq new-alist
2239 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2240 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2241 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2242 (nth 5 elem) (nth 6 elem) nil)
2243 new-alist))
2244 (setq old-alist (cdr old-alist)))
2245 (setq vhdl-compiler-alist (nreverse new-alist)))
2246 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2247
2248 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2249 (when (= (length (car vhdl-compiler-alist)) 12)
2250 (let ((tmp-alist vhdl-compiler-alist))
2251 (while tmp-alist
2252 (setcdr (nthcdr 4 (car tmp-alist))
2253 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2254 (setq tmp-alist (cdr tmp-alist))))
2255 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2256
2257 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2258 (when (= (length (car vhdl-compiler-alist)) 13)
2259 (let ((tmp-alist vhdl-compiler-alist))
2260 (while tmp-alist
2261 (setcdr (nthcdr 3 (car tmp-alist))
2262 (cons "" (nthcdr 4 (car tmp-alist))))
2263 (setq tmp-alist (cdr tmp-alist))))
2264 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2265
2266 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2267 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2268 (let ((tmp-alist vhdl-compiler-alist))
2269 (while tmp-alist
2270 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2271 '(0 . nil))
2272 (setq tmp-alist (cdr tmp-alist))))
2273 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2274
2275 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2276 (when (equal vhdl-project "")
2277 (setq vhdl-project nil)
2278 (customize-save-variable 'vhdl-project vhdl-project))
2279
2280 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2281 (when (stringp vhdl-project-file-name)
2282 (setq vhdl-project-file-name (list vhdl-project-file-name))
2283 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2284
2285 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2286 (if (not (boundp 'speedbar-indentation-width))
2287 (defvar speedbar-indentation-width 2)
2288 ;; set default to 2 if not already customized
2289 (unless (get 'speedbar-indentation-width 'saved-value)
2290 (setq speedbar-indentation-width 2)))
2291
2292
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;;; Help functions / inline substitutions / macros
2295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2296
2297 (defun vhdl-standard-p (standard)
2298 "Check if STANDARD is specified as used standard."
2299 (or (eq standard (car vhdl-standard))
2300 (memq standard (cadr vhdl-standard))))
2301
2302 (defun vhdl-project-p (&optional warning)
2303 "Return non-nil if a project is displayed, i.e. directories or files are
2304 specified."
2305 (if (assoc vhdl-project vhdl-project-alist)
2306 vhdl-project
2307 (when (and vhdl-project warning)
2308 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2309 nil))
2310
2311 (defun vhdl-resolve-env-variable (string)
2312 "Resolve environment variables in STRING."
2313 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2314 (setq string (concat (match-string 1 string)
2315 (getenv (match-string 2 string))
2316 (match-string 4 string))))
2317 string)
2318
2319 (defun vhdl-default-directory ()
2320 "Return the default directory of the current project or the directory of the
2321 current buffer if no project is defined."
2322 (if (vhdl-project-p)
2323 (expand-file-name (vhdl-resolve-env-variable
2324 (nth 1 (aget vhdl-project-alist vhdl-project))))
2325 default-directory))
2326
2327 (defmacro vhdl-prepare-search-1 (&rest body)
2328 "Enable case insensitive search and switch to syntax table that includes '_',
2329 then execute BODY, and finally restore the old environment. Used for
2330 consistent searching."
2331 `(let ((case-fold-search t)) ; case insensitive search
2332 ;; use extended syntax table
2333 (with-syntax-table vhdl-mode-ext-syntax-table
2334 ,@body)))
2335
2336 (defmacro vhdl-prepare-search-2 (&rest body)
2337 "Enable case insensitive search, switch to syntax table that includes '_',
2338 and remove `intangible' overlays, then execute BODY, and finally restore the
2339 old environment. Used for consistent searching."
2340 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2341 `(let ((case-fold-search t) ; case insensitive search
2342 (current-syntax-table (syntax-table))
2343 overlay-all-list overlay-intangible-list overlay)
2344 ;; use extended syntax table
2345 (set-syntax-table vhdl-mode-ext-syntax-table)
2346 ;; remove `intangible' overlays
2347 (when (fboundp 'overlay-lists)
2348 (setq overlay-all-list (overlay-lists))
2349 (setq overlay-all-list
2350 (append (car overlay-all-list) (cdr overlay-all-list)))
2351 (while overlay-all-list
2352 (setq overlay (car overlay-all-list))
2353 (when (memq 'intangible (overlay-properties overlay))
2354 (setq overlay-intangible-list
2355 (cons overlay overlay-intangible-list))
2356 (overlay-put overlay 'intangible nil))
2357 (setq overlay-all-list (cdr overlay-all-list))))
2358 ;; execute BODY safely
2359 (unwind-protect
2360 (progn ,@body)
2361 ;; restore syntax table
2362 (set-syntax-table current-syntax-table)
2363 ;; restore `intangible' overlays
2364 (when (fboundp 'overlay-lists)
2365 (while overlay-intangible-list
2366 (overlay-put (car overlay-intangible-list) 'intangible t)
2367 (setq overlay-intangible-list
2368 (cdr overlay-intangible-list)))))))
2369
2370 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2371 "Visit file FILE-NAME and execute BODY."
2372 `(if (null ,file-name)
2373 (progn ,@body)
2374 (unless (file-directory-p ,file-name)
2375 (let ((source-buffer (current-buffer))
2376 (visiting-buffer (find-buffer-visiting ,file-name))
2377 file-opened)
2378 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2379 (condition-case ()
2380 (progn (set-buffer (create-file-buffer ,file-name))
2381 (setq file-opened t)
2382 (vhdl-insert-file-contents ,file-name)
2383 (modify-syntax-entry ?\- ". 12" (syntax-table))
2384 (modify-syntax-entry ?\n ">" (syntax-table))
2385 (modify-syntax-entry ?\^M ">" (syntax-table))
2386 (modify-syntax-entry ?_ "w" (syntax-table))
2387 t)
2388 (error
2389 (if ,issue-error
2390 (progn
2391 (when file-opened (kill-buffer (current-buffer)))
2392 (set-buffer source-buffer)
2393 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2394 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2395 nil))))
2396 (condition-case info
2397 (progn ,@body)
2398 (error
2399 (if ,issue-error
2400 (progn
2401 (when file-opened (kill-buffer (current-buffer)))
2402 (set-buffer source-buffer)
2403 (error (cadr info)))
2404 (vhdl-warning (cadr info))))))
2405 (when file-opened (kill-buffer (current-buffer)))
2406 (set-buffer source-buffer)))))
2407
2408 (defun vhdl-insert-file-contents (filename)
2409 "Nicked from `insert-file-contents-literally', but allow coding system
2410 conversion."
2411 (let ((format-alist nil)
2412 (after-insert-file-functions nil)
2413 (jka-compr-compression-info-list nil))
2414 (insert-file-contents filename t)))
2415
2416 (defun vhdl-sort-alist (alist)
2417 "Sort ALIST."
2418 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2419
2420 (defun vhdl-get-subdirs (directory)
2421 "Recursively get subdirectories of DIRECTORY."
2422 (let ((dir-list (list (file-name-as-directory directory)))
2423 file-list)
2424 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2425 (while file-list
2426 (when (file-directory-p (car file-list))
2427 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2428 (setq file-list (cdr file-list)))
2429 dir-list))
2430
2431 (defun vhdl-aput (alist-symbol key &optional value)
2432 "As `aput', but delete key-value pair if VALUE is nil."
2433 (if value
2434 (aput alist-symbol key value)
2435 (adelete alist-symbol key)))
2436
2437 (defun vhdl-delete (elt list)
2438 "Delete by side effect the first occurrence of ELT as a member of LIST."
2439 (setq list (cons nil list))
2440 (let ((list1 list))
2441 (while (and (cdr list1) (not (equal elt (cadr list1))))
2442 (setq list1 (cdr list1)))
2443 (when list
2444 (setcdr list1 (cddr list1))))
2445 (cdr list))
2446
2447 (defun vhdl-speedbar-refresh (&optional key)
2448 "Refresh directory or project with name KEY."
2449 (when (and (boundp 'speedbar-frame)
2450 (frame-live-p speedbar-frame))
2451 (let ((pos (point))
2452 (last-frame (selected-frame)))
2453 (if (null key)
2454 (speedbar-refresh)
2455 (select-frame speedbar-frame)
2456 (when (save-excursion
2457 (goto-char (point-min))
2458 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2459 (goto-char (match-end 1))
2460 (speedbar-do-function-pointer)
2461 (backward-char 2)
2462 (speedbar-do-function-pointer)
2463 (message "Refreshing speedbar...done"))
2464 (select-frame last-frame)))))
2465
2466 (defun vhdl-show-messages ()
2467 "Get *Messages* buffer to show recent messages."
2468 (interactive)
2469 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2470
2471 (defun vhdl-use-direct-instantiation ()
2472 "Return whether direct instantiation is used."
2473 (or (eq vhdl-use-direct-instantiation 'always)
2474 (and (eq vhdl-use-direct-instantiation 'standard)
2475 (not (vhdl-standard-p '87)))))
2476
2477 (defun vhdl-max-marker (marker1 marker2)
2478 "Return larger marker."
2479 (if (> marker1 marker2) marker1 marker2))
2480
2481 (defun vhdl-goto-marker (marker)
2482 "Goto marker in appropriate buffer."
2483 (when (markerp marker)
2484 (set-buffer (marker-buffer marker)))
2485 (goto-char marker))
2486
2487 (defun vhdl-menu-split (list title)
2488 "Split menu LIST into several submenues, if number of
2489 elements > `vhdl-menu-max-size'."
2490 (if (> (length list) vhdl-menu-max-size)
2491 (let ((remain list)
2492 (result '())
2493 (sublist '())
2494 (menuno 1)
2495 (i 0))
2496 (while remain
2497 (setq sublist (cons (car remain) sublist))
2498 (setq remain (cdr remain))
2499 (setq i (+ i 1))
2500 (if (= i vhdl-menu-max-size)
2501 (progn
2502 (setq result (cons (cons (format "%s %s" title menuno)
2503 (nreverse sublist)) result))
2504 (setq i 0)
2505 (setq menuno (+ menuno 1))
2506 (setq sublist '()))))
2507 (and sublist
2508 (setq result (cons (cons (format "%s %s" title menuno)
2509 (nreverse sublist)) result)))
2510 (nreverse result))
2511 list))
2512
2513
2514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2515 ;;; Bindings
2516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2517
2518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2519 ;; Key bindings
2520
2521 (defvar vhdl-template-map nil
2522 "Keymap for VHDL templates.")
2523
2524 (defun vhdl-template-map-init ()
2525 "Initialize `vhdl-template-map'."
2526 (setq vhdl-template-map (make-sparse-keymap))
2527 ;; key bindings for VHDL templates
2528 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2529 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2530 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2531 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2532 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2533 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2534 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2535 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2536 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2537 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2538 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2539 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2540 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2541 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2542 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2543 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2544 (define-key vhdl-template-map "el" 'vhdl-template-else)
2545 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2546 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2547 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2548 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2549 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2550 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2551 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2552 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2553 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2554 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2555 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2556 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2557 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2558 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2559 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2560 (define-key vhdl-template-map "li" 'vhdl-template-library)
2561 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2562 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2563 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2564 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2565 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2566 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2567 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2568 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2569 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2570 (define-key vhdl-template-map "po" 'vhdl-template-port)
2571 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2572 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2573 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2574 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2575 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2576 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2577 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2578 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2579 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2580 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2581 (define-key vhdl-template-map "us" 'vhdl-template-use)
2582 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2583 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2584 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2585 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2586 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2587 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2588 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2589 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2590 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2591 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2592 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2593 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2594 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2595 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2596 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2597 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2598 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2599 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2600 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2601 (when (vhdl-standard-p 'ams)
2602 (define-key vhdl-template-map "br" 'vhdl-template-break)
2603 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2604 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2605 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2606 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2607 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2608 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2609 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2610 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2611 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2612 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2613 )
2614 (when (vhdl-standard-p 'math)
2615 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2616 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2617 ))
2618
2619 ;; initialize template map for VHDL Mode
2620 (vhdl-template-map-init)
2621
2622 (defun vhdl-function-name (prefix string &optional postfix)
2623 "Generate a Lisp function name.
2624 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2625 STRING are replaced by `-' and substrings are converted to lower case."
2626 (let ((name prefix))
2627 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2628 (setq name
2629 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2630 (setq string (substring string (match-beginning 2))))
2631 (when postfix (setq name (concat name "-" postfix)))
2632 (intern name)))
2633
2634 (defvar vhdl-model-map nil
2635 "Keymap for VHDL models.")
2636
2637 (defun vhdl-model-map-init ()
2638 "Initialize `vhdl-model-map'."
2639 (setq vhdl-model-map (make-sparse-keymap))
2640 ;; key bindings for VHDL models
2641 (let ((model-alist vhdl-model-alist) model)
2642 (while model-alist
2643 (setq model (car model-alist))
2644 (define-key vhdl-model-map (nth 2 model)
2645 (vhdl-function-name "vhdl-model" (nth 0 model)))
2646 (setq model-alist (cdr model-alist)))))
2647
2648 ;; initialize user model map for VHDL Mode
2649 (vhdl-model-map-init)
2650
2651 (defvar vhdl-mode-map nil
2652 "Keymap for VHDL Mode.")
2653
2654 (defun vhdl-mode-map-init ()
2655 "Initialize `vhdl-mode-map'."
2656 (setq vhdl-mode-map (make-sparse-keymap))
2657 ;; template key bindings
2658 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2659 ;; model key bindings
2660 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2661 ;; standard key bindings
2662 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2663 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2664 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2665 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2666 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2667 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2668 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2669 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2670 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2671 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2672 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2673 ;; backspace/delete key bindings
2674 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2675 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2676 (define-key vhdl-mode-map [delete] 'delete-char)
2677 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2678 ;; mode specific key bindings
2679 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2680 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2681 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2682 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2684 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2685 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2686 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2687 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2688 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2689 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2690 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2691 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2692 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2693 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2694 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2695 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2696 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2697 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2698 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2699 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2700 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2701 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2702 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2703 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2704 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2705 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2706 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2707 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2708 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2709 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2710 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2711 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2712 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2713 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2714 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2715 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2716 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2717 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2718 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2719 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2720 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2721 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2722 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2723 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2724 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2725 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2726 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2727 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2728 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2729 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2730 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2731 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2732 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2733 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2734 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2735 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2736 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2737 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2738 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2739 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2740 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2741 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2742 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2743 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2744 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2745 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2746 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2747 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2748 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2749 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2750 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2751 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2752 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2753 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2754 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2755 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2756 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2757 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2758 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2759 ;; insert commands bindings
2760 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2761 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2762 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2763 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2764 ;; electric key bindings
2765 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2766 (when vhdl-intelligent-tab
2767 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2768 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2769 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2770 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2771 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2772 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2773 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2774 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2775 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2776 (when (vhdl-standard-p 'ams)
2777 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2778
2779 ;; initialize mode map for VHDL Mode
2780 (vhdl-mode-map-init)
2781
2782 ;; define special minibuffer keymap for enabling word completion in minibuffer
2783 ;; (useful in template generator prompts)
2784 (defvar vhdl-minibuffer-local-map
2785 (let ((map (make-sparse-keymap)))
2786 (set-keymap-parent map minibuffer-local-map)
2787 (when vhdl-word-completion-in-minibuffer
2788 (define-key map "\t" 'vhdl-minibuffer-tab))
2789 map)
2790 "Keymap for minibuffer used in VHDL Mode.")
2791
2792 ;; set up electric character functions to work with
2793 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2794 (mapc
2795 (function
2796 (lambda (sym)
2797 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2798 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2799 '(vhdl-electric-space
2800 vhdl-electric-tab
2801 vhdl-electric-return
2802 vhdl-electric-dash
2803 vhdl-electric-open-bracket
2804 vhdl-electric-close-bracket
2805 vhdl-electric-quote
2806 vhdl-electric-semicolon
2807 vhdl-electric-comma
2808 vhdl-electric-period
2809 vhdl-electric-equal))
2810
2811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2812 ;; Syntax table
2813
2814 (defvar vhdl-mode-syntax-table nil
2815 "Syntax table used in `vhdl-mode' buffers.")
2816
2817 (defvar vhdl-mode-ext-syntax-table nil
2818 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2819
2820 (defun vhdl-mode-syntax-table-init ()
2821 "Initialize `vhdl-mode-syntax-table'."
2822 (setq vhdl-mode-syntax-table (make-syntax-table))
2823 ;; define punctuation
2824 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2825 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2826 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2827 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2828 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2829 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2830 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2831 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2832 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2833 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2835 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
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 ;; define string
2841 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2842 ;; define underscore
2843 (when vhdl-underscore-is-part-of-word
2844 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2845 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2846 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2847 ;; and \n and \^M end a comment
2848 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2850 ;; define parentheses to match
2851 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2857 ;; extended syntax table including '_' (for simpler search regexps)
2858 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2859 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2860
2861 ;; initialize syntax table for VHDL Mode
2862 (vhdl-mode-syntax-table-init)
2863
2864 (defvar vhdl-syntactic-context nil
2865 "Buffer local variable containing syntactic analysis list.")
2866 (make-variable-buffer-local 'vhdl-syntactic-context)
2867
2868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2869 ;; Abbrev ook bindings
2870
2871 (defvar vhdl-mode-abbrev-table nil
2872 "Abbrev table to use in `vhdl-mode' buffers.")
2873
2874 (defun vhdl-mode-abbrev-table-init ()
2875 "Initialize `vhdl-mode-abbrev-table'."
2876 (define-abbrev-table 'vhdl-mode-abbrev-table
2877 (append
2878 (when (memq 'vhdl vhdl-electric-keywords)
2879 ;; VHDL'93 keywords
2880 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2881 '(
2882 ("--" . vhdl-template-display-comment-hook)
2883 ("abs" . vhdl-template-default-hook)
2884 ("access" . vhdl-template-default-hook)
2885 ("after" . vhdl-template-default-hook)
2886 ("alias" . vhdl-template-alias-hook)
2887 ("all" . vhdl-template-default-hook)
2888 ("and" . vhdl-template-default-hook)
2889 ("arch" . vhdl-template-architecture-hook)
2890 ("architecture" . vhdl-template-architecture-hook)
2891 ("array" . vhdl-template-default-hook)
2892 ("assert" . vhdl-template-assert-hook)
2893 ("attr" . vhdl-template-attribute-hook)
2894 ("attribute" . vhdl-template-attribute-hook)
2895 ("begin" . vhdl-template-default-indent-hook)
2896 ("block" . vhdl-template-block-hook)
2897 ("body" . vhdl-template-default-hook)
2898 ("buffer" . vhdl-template-default-hook)
2899 ("bus" . vhdl-template-default-hook)
2900 ("case" . vhdl-template-case-hook)
2901 ("comp" . vhdl-template-component-hook)
2902 ("component" . vhdl-template-component-hook)
2903 ("cond" . vhdl-template-conditional-signal-asst-hook)
2904 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2905 ("conf" . vhdl-template-configuration-hook)
2906 ("configuration" . vhdl-template-configuration-hook)
2907 ("cons" . vhdl-template-constant-hook)
2908 ("constant" . vhdl-template-constant-hook)
2909 ("disconnect" . vhdl-template-disconnect-hook)
2910 ("downto" . vhdl-template-default-hook)
2911 ("else" . vhdl-template-else-hook)
2912 ("elseif" . vhdl-template-elsif-hook)
2913 ("elsif" . vhdl-template-elsif-hook)
2914 ("end" . vhdl-template-default-indent-hook)
2915 ("entity" . vhdl-template-entity-hook)
2916 ("exit" . vhdl-template-exit-hook)
2917 ("file" . vhdl-template-file-hook)
2918 ("for" . vhdl-template-for-hook)
2919 ("func" . vhdl-template-function-hook)
2920 ("function" . vhdl-template-function-hook)
2921 ("generic" . vhdl-template-generic-hook)
2922 ("group" . vhdl-template-group-hook)
2923 ("guarded" . vhdl-template-default-hook)
2924 ("if" . vhdl-template-if-hook)
2925 ("impure" . vhdl-template-default-hook)
2926 ("in" . vhdl-template-default-hook)
2927 ("inertial" . vhdl-template-default-hook)
2928 ("inout" . vhdl-template-default-hook)
2929 ("inst" . vhdl-template-instance-hook)
2930 ("instance" . vhdl-template-instance-hook)
2931 ("is" . vhdl-template-default-hook)
2932 ("label" . vhdl-template-default-hook)
2933 ("library" . vhdl-template-library-hook)
2934 ("linkage" . vhdl-template-default-hook)
2935 ("literal" . vhdl-template-default-hook)
2936 ("loop" . vhdl-template-bare-loop-hook)
2937 ("map" . vhdl-template-map-hook)
2938 ("mod" . vhdl-template-default-hook)
2939 ("nand" . vhdl-template-default-hook)
2940 ("new" . vhdl-template-default-hook)
2941 ("next" . vhdl-template-next-hook)
2942 ("nor" . vhdl-template-default-hook)
2943 ("not" . vhdl-template-default-hook)
2944 ("null" . vhdl-template-default-hook)
2945 ("of" . vhdl-template-default-hook)
2946 ("on" . vhdl-template-default-hook)
2947 ("open" . vhdl-template-default-hook)
2948 ("or" . vhdl-template-default-hook)
2949 ("others" . vhdl-template-others-hook)
2950 ("out" . vhdl-template-default-hook)
2951 ("pack" . vhdl-template-package-hook)
2952 ("package" . vhdl-template-package-hook)
2953 ("port" . vhdl-template-port-hook)
2954 ("postponed" . vhdl-template-default-hook)
2955 ("procedure" . vhdl-template-procedure-hook)
2956 ("process" . vhdl-template-process-hook)
2957 ("pure" . vhdl-template-default-hook)
2958 ("range" . vhdl-template-default-hook)
2959 ("record" . vhdl-template-default-hook)
2960 ("register" . vhdl-template-default-hook)
2961 ("reject" . vhdl-template-default-hook)
2962 ("rem" . vhdl-template-default-hook)
2963 ("report" . vhdl-template-report-hook)
2964 ("return" . vhdl-template-return-hook)
2965 ("rol" . vhdl-template-default-hook)
2966 ("ror" . vhdl-template-default-hook)
2967 ("select" . vhdl-template-selected-signal-asst-hook)
2968 ("severity" . vhdl-template-default-hook)
2969 ("shared" . vhdl-template-default-hook)
2970 ("sig" . vhdl-template-signal-hook)
2971 ("signal" . vhdl-template-signal-hook)
2972 ("sla" . vhdl-template-default-hook)
2973 ("sll" . vhdl-template-default-hook)
2974 ("sra" . vhdl-template-default-hook)
2975 ("srl" . vhdl-template-default-hook)
2976 ("subtype" . vhdl-template-subtype-hook)
2977 ("then" . vhdl-template-default-hook)
2978 ("to" . vhdl-template-default-hook)
2979 ("transport" . vhdl-template-default-hook)
2980 ("type" . vhdl-template-type-hook)
2981 ("unaffected" . vhdl-template-default-hook)
2982 ("units" . vhdl-template-default-hook)
2983 ("until" . vhdl-template-default-hook)
2984 ("use" . vhdl-template-use-hook)
2985 ("var" . vhdl-template-variable-hook)
2986 ("variable" . vhdl-template-variable-hook)
2987 ("wait" . vhdl-template-wait-hook)
2988 ("when" . vhdl-template-when-hook)
2989 ("while" . vhdl-template-while-loop-hook)
2990 ("with" . vhdl-template-with-hook)
2991 ("xnor" . vhdl-template-default-hook)
2992 ("xor" . vhdl-template-default-hook)
2993 )))
2994 ;; VHDL-AMS keywords
2995 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2996 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2997 '(
2998 ("across" . vhdl-template-default-hook)
2999 ("break" . vhdl-template-break-hook)
3000 ("limit" . vhdl-template-limit-hook)
3001 ("nature" . vhdl-template-nature-hook)
3002 ("noise" . vhdl-template-default-hook)
3003 ("procedural" . vhdl-template-procedural-hook)
3004 ("quantity" . vhdl-template-quantity-hook)
3005 ("reference" . vhdl-template-default-hook)
3006 ("spectrum" . vhdl-template-default-hook)
3007 ("subnature" . vhdl-template-subnature-hook)
3008 ("terminal" . vhdl-template-terminal-hook)
3009 ("through" . vhdl-template-default-hook)
3010 ("tolerance" . vhdl-template-default-hook)
3011 )))
3012 ;; user model keywords
3013 (when (memq 'user vhdl-electric-keywords)
3014 (let (abbrev-list keyword)
3015 (dolist (elem vhdl-model-alist)
3016 (setq keyword (nth 3 elem))
3017 (unless (equal keyword "")
3018 (push (list keyword ""
3019 (vhdl-function-name
3020 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3021 abbrev-list)))
3022 abbrev-list)))))
3023
3024 ;; initialize abbrev table for VHDL Mode
3025 (vhdl-mode-abbrev-table-init)
3026
3027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3028 ;; Template completion lists
3029
3030 (defvar vhdl-template-construct-alist nil
3031 "List of built-in construct templates.")
3032
3033 (defun vhdl-template-construct-alist-init ()
3034 "Initialize `vhdl-template-construct-alist'."
3035 (setq
3036 vhdl-template-construct-alist
3037 (append
3038 '(
3039 ("alias declaration" vhdl-template-alias)
3040 ("architecture body" vhdl-template-architecture)
3041 ("assertion" vhdl-template-assert)
3042 ("attribute declaration" vhdl-template-attribute-decl)
3043 ("attribute specification" vhdl-template-attribute-spec)
3044 ("block configuration" vhdl-template-block-configuration)
3045 ("block statement" vhdl-template-block)
3046 ("case statement" vhdl-template-case-is)
3047 ("component configuration" vhdl-template-component-conf)
3048 ("component declaration" vhdl-template-component-decl)
3049 ("component instantiation statement" vhdl-template-component-inst)
3050 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3051 ("configuration declaration" vhdl-template-configuration-decl)
3052 ("configuration specification" vhdl-template-configuration-spec)
3053 ("constant declaration" vhdl-template-constant)
3054 ("disconnection specification" vhdl-template-disconnect)
3055 ("entity declaration" vhdl-template-entity)
3056 ("exit statement" vhdl-template-exit)
3057 ("file declaration" vhdl-template-file)
3058 ("generate statement" vhdl-template-generate)
3059 ("generic clause" vhdl-template-generic)
3060 ("group declaration" vhdl-template-group-decl)
3061 ("group template declaration" vhdl-template-group-template)
3062 ("if statement" vhdl-template-if-then)
3063 ("library clause" vhdl-template-library)
3064 ("loop statement" vhdl-template-loop)
3065 ("next statement" vhdl-template-next)
3066 ("package declaration" vhdl-template-package-decl)
3067 ("package body" vhdl-template-package-body)
3068 ("port clause" vhdl-template-port)
3069 ("process statement" vhdl-template-process)
3070 ("report statement" vhdl-template-report)
3071 ("return statement" vhdl-template-return)
3072 ("selected signal assignment" vhdl-template-selected-signal-asst)
3073 ("signal declaration" vhdl-template-signal)
3074 ("subprogram declaration" vhdl-template-subprogram-decl)
3075 ("subprogram body" vhdl-template-subprogram-body)
3076 ("subtype declaration" vhdl-template-subtype)
3077 ("type declaration" vhdl-template-type)
3078 ("use clause" vhdl-template-use)
3079 ("variable declaration" vhdl-template-variable)
3080 ("wait statement" vhdl-template-wait)
3081 )
3082 (when (vhdl-standard-p 'ams)
3083 '(
3084 ("break statement" vhdl-template-break)
3085 ("nature declaration" vhdl-template-nature)
3086 ("quantity declaration" vhdl-template-quantity)
3087 ("simultaneous case statement" vhdl-template-case-use)
3088 ("simultaneous if statement" vhdl-template-if-use)
3089 ("simultaneous procedural statement" vhdl-template-procedural)
3090 ("step limit specification" vhdl-template-limit)
3091 ("subnature declaration" vhdl-template-subnature)
3092 ("terminal declaration" vhdl-template-terminal)
3093 )))))
3094
3095 ;; initialize for VHDL Mode
3096 (vhdl-template-construct-alist-init)
3097
3098 (defvar vhdl-template-package-alist nil
3099 "List of built-in package templates.")
3100
3101 (defun vhdl-template-package-alist-init ()
3102 "Initialize `vhdl-template-package-alist'."
3103 (setq
3104 vhdl-template-package-alist
3105 (append
3106 '(
3107 ("numeric_bit" vhdl-template-package-numeric-bit)
3108 ("numeric_std" vhdl-template-package-numeric-std)
3109 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3110 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3111 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3112 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3113 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3114 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3115 ("textio" vhdl-template-package-textio)
3116 )
3117 (when (vhdl-standard-p 'math)
3118 '(
3119 ("math_complex" vhdl-template-package-math-complex)
3120 ("math_real" vhdl-template-package-math-real)
3121 )))))
3122
3123 ;; initialize for VHDL Mode
3124 (vhdl-template-package-alist-init)
3125
3126 (defvar vhdl-template-directive-alist
3127 '(
3128 ("translate_on" vhdl-template-directive-translate-on)
3129 ("translate_off" vhdl-template-directive-translate-off)
3130 ("synthesis_on" vhdl-template-directive-synthesis-on)
3131 ("synthesis_off" vhdl-template-directive-synthesis-off)
3132 )
3133 "List of built-in directive templates.")
3134
3135
3136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3137 ;;; Menues
3138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3139
3140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3141 ;; VHDL menu (using `easy-menu.el')
3142
3143 (defun vhdl-customize ()
3144 "Call the customize function with `vhdl' as argument."
3145 (interactive)
3146 (customize-browse 'vhdl))
3147
3148 (defun vhdl-create-mode-menu ()
3149 "Create VHDL Mode menu."
3150 `("VHDL"
3151 ,(append
3152 '("Project"
3153 ["None" (vhdl-set-project "")
3154 :style radio :selected (null vhdl-project)]
3155 "--")
3156 ;; add menu entries for defined projects
3157 (let ((project-alist vhdl-project-alist) menu-list name)
3158 (while project-alist
3159 (setq name (caar project-alist))
3160 (setq menu-list
3161 (cons `[,name (vhdl-set-project ,name)
3162 :style radio :selected (equal ,name vhdl-project)]
3163 menu-list))
3164 (setq project-alist (cdr project-alist)))
3165 (setq menu-list
3166 (if vhdl-project-sort
3167 (sort menu-list
3168 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3169 (nreverse menu-list)))
3170 (vhdl-menu-split menu-list "Project"))
3171 '("--" "--"
3172 ["Select Project..." vhdl-set-project t]
3173 ["Set As Default Project" vhdl-set-default-project t]
3174 "--"
3175 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3176 ["Import Project..." vhdl-import-project
3177 :keys "C-c C-p C-m" :active t]
3178 ["Export Project" vhdl-export-project vhdl-project]
3179 "--"
3180 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3181 "--"
3182 ("Compile"
3183 ["Compile Buffer" vhdl-compile t]
3184 ["Stop Compilation" kill-compilation t]
3185 "--"
3186 ["Make" vhdl-make t]
3187 ["Generate Makefile" vhdl-generate-makefile t]
3188 "--"
3189 ["Next Error" next-error t]
3190 ["Previous Error" previous-error t]
3191 ["First Error" first-error t]
3192 "--"
3193 ,(append
3194 '("Compiler")
3195 ;; add menu entries for defined compilers
3196 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3197 (while comp-alist
3198 (setq name (caar comp-alist))
3199 (setq menu-list
3200 (cons `[,name (setq vhdl-compiler ,name)
3201 :style radio :selected (equal ,name vhdl-compiler)]
3202 menu-list))
3203 (setq comp-alist (cdr comp-alist)))
3204 (setq menu-list (nreverse menu-list))
3205 (vhdl-menu-split menu-list "Compiler"))
3206 '("--" "--"
3207 ["Select Compiler..." vhdl-set-compiler t]
3208 "--"
3209 ["Customize Compiler..."
3210 (customize-option 'vhdl-compiler-alist) t])))
3211 "--"
3212 ,(append
3213 '("Template"
3214 ("VHDL Construct 1"
3215 ["Alias" vhdl-template-alias t]
3216 ["Architecture" vhdl-template-architecture t]
3217 ["Assert" vhdl-template-assert t]
3218 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3219 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3220 ["Block" vhdl-template-block t]
3221 ["Case" vhdl-template-case-is t]
3222 ["Component (Decl)" vhdl-template-component-decl t]
3223 ["(Component) Instance" vhdl-template-component-inst t]
3224 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3225 ["Configuration (Block)" vhdl-template-block-configuration t]
3226 ["Configuration (Comp)" vhdl-template-component-conf t]
3227 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3228 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3229 ["Constant" vhdl-template-constant t]
3230 ["Disconnect" vhdl-template-disconnect t]
3231 ["Else" vhdl-template-else t]
3232 ["Elsif" vhdl-template-elsif t]
3233 ["Entity" vhdl-template-entity t]
3234 ["Exit" vhdl-template-exit t]
3235 ["File" vhdl-template-file t]
3236 ["For (Generate)" vhdl-template-for-generate t]
3237 ["For (Loop)" vhdl-template-for-loop t]
3238 ["Function (Body)" vhdl-template-function-body t]
3239 ["Function (Decl)" vhdl-template-function-decl t]
3240 ["Generic" vhdl-template-generic t]
3241 ["Group (Decl)" vhdl-template-group-decl t]
3242 ["Group (Template)" vhdl-template-group-template t])
3243 ("VHDL Construct 2"
3244 ["If (Generate)" vhdl-template-if-generate t]
3245 ["If (Then)" vhdl-template-if-then t]
3246 ["Library" vhdl-template-library t]
3247 ["Loop" vhdl-template-bare-loop t]
3248 ["Map" vhdl-template-map t]
3249 ["Next" vhdl-template-next t]
3250 ["Others (Aggregate)" vhdl-template-others t]
3251 ["Package (Decl)" vhdl-template-package-decl t]
3252 ["Package (Body)" vhdl-template-package-body t]
3253 ["Port" vhdl-template-port t]
3254 ["Procedure (Body)" vhdl-template-procedure-body t]
3255 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3256 ["Process (Comb)" vhdl-template-process-comb t]
3257 ["Process (Seq)" vhdl-template-process-seq t]
3258 ["Report" vhdl-template-report t]
3259 ["Return" vhdl-template-return t]
3260 ["Select" vhdl-template-selected-signal-asst t]
3261 ["Signal" vhdl-template-signal t]
3262 ["Subtype" vhdl-template-subtype t]
3263 ["Type" vhdl-template-type t]
3264 ["Use" vhdl-template-use t]
3265 ["Variable" vhdl-template-variable t]
3266 ["Wait" vhdl-template-wait t]
3267 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3268 ["When" vhdl-template-when t]
3269 ["While (Loop)" vhdl-template-while-loop t]
3270 ["With" vhdl-template-with t]))
3271 (when (vhdl-standard-p 'ams)
3272 '(("VHDL-AMS Construct"
3273 ["Break" vhdl-template-break t]
3274 ["Case (Use)" vhdl-template-case-use t]
3275 ["If (Use)" vhdl-template-if-use t]
3276 ["Limit" vhdl-template-limit t]
3277 ["Nature" vhdl-template-nature t]
3278 ["Procedural" vhdl-template-procedural t]
3279 ["Quantity (Free)" vhdl-template-quantity-free t]
3280 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3281 ["Quantity (Source)" vhdl-template-quantity-source t]
3282 ["Subnature" vhdl-template-subnature t]
3283 ["Terminal" vhdl-template-terminal t])))
3284 '(["Insert Construct..." vhdl-template-insert-construct
3285 :keys "C-c C-i C-t"]
3286 "--")
3287 (list
3288 (append
3289 '("Package")
3290 (when (vhdl-standard-p 'math)
3291 '(["math_complex" vhdl-template-package-math-complex t]
3292 ["math_real" vhdl-template-package-math-real t]))
3293 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3294 ["numeric_std" vhdl-template-package-numeric-std t]
3295 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3296 ["textio" vhdl-template-package-textio t]
3297 "--"
3298 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3299 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3300 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3301 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3302 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3303 "--"
3304 ["Insert Package..." vhdl-template-insert-package
3305 :keys "C-c C-i C-p"])))
3306 '(("Directive"
3307 ["translate_on" vhdl-template-directive-translate-on t]
3308 ["translate_off" vhdl-template-directive-translate-off t]
3309 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3310 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3311 "--"
3312 ["Insert Directive..." vhdl-template-insert-directive
3313 :keys "C-c C-i C-d"])
3314 "--"
3315 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3316 ["Insert Footer" vhdl-template-footer t]
3317 ["Insert Date" vhdl-template-insert-date t]
3318 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3319 "--"
3320 ["Query Next Prompt" vhdl-template-search-prompt t]))
3321 ,(append
3322 '("Model")
3323 ;; add menu entries for defined models
3324 (let ((model-alist vhdl-model-alist) menu-list model)
3325 (while model-alist
3326 (setq model (car model-alist))
3327 (setq menu-list
3328 (cons
3329 (vector
3330 (nth 0 model)
3331 (vhdl-function-name "vhdl-model" (nth 0 model))
3332 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3333 menu-list))
3334 (setq model-alist (cdr model-alist)))
3335 (setq menu-list (nreverse menu-list))
3336 (vhdl-menu-split menu-list "Model"))
3337 '("--" "--"
3338 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3339 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3340 ("Port"
3341 ["Copy" vhdl-port-copy t]
3342 "--"
3343 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3344 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3345 ["Paste As Instance" vhdl-port-paste-instance
3346 :keys "C-c C-p C-i" :active vhdl-port-list]
3347 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3348 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3349 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3350 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3351 "--"
3352 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3353 "--"
3354 ["Flatten" vhdl-port-flatten
3355 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3356 ["Reverse Direction" vhdl-port-reverse-direction
3357 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3358 ("Compose"
3359 ["New Component" vhdl-compose-new-component t]
3360 ["Copy Component" vhdl-port-copy t]
3361 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3362 ["Wire Components" vhdl-compose-wire-components t]
3363 "--"
3364 ["Generate Configuration" vhdl-compose-configuration t]
3365 ["Generate Components Package" vhdl-compose-components-package t])
3366 ("Subprogram"
3367 ["Copy" vhdl-subprog-copy t]
3368 "--"
3369 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3370 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3371 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3372 "--"
3373 ["Flatten" vhdl-subprog-flatten
3374 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3375 "--"
3376 ("Comment"
3377 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3378 "--"
3379 ["Insert Inline Comment" vhdl-comment-append-inline t]
3380 ["Insert Horizontal Line" vhdl-comment-display-line t]
3381 ["Insert Display Comment" vhdl-comment-display t]
3382 "--"
3383 ["Fill Comment" fill-paragraph t]
3384 ["Fill Comment Region" fill-region (mark)]
3385 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3386 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3387 ("Line"
3388 ["Kill" vhdl-line-kill t]
3389 ["Copy" vhdl-line-copy t]
3390 ["Yank" vhdl-line-yank t]
3391 ["Expand" vhdl-line-expand t]
3392 "--"
3393 ["Transpose Next" vhdl-line-transpose-next t]
3394 ["Transpose Prev" vhdl-line-transpose-previous t]
3395 ["Open" vhdl-line-open t]
3396 ["Join" vhdl-delete-indentation t]
3397 "--"
3398 ["Goto" goto-line t]
3399 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3400 ("Move"
3401 ["Forward Statement" vhdl-end-of-statement t]
3402 ["Backward Statement" vhdl-beginning-of-statement t]
3403 ["Forward Expression" vhdl-forward-sexp t]
3404 ["Backward Expression" vhdl-backward-sexp t]
3405 ["Forward Same Indent" vhdl-forward-same-indent t]
3406 ["Backward Same Indent" vhdl-backward-same-indent t]
3407 ["Forward Function" vhdl-end-of-defun t]
3408 ["Backward Function" vhdl-beginning-of-defun t]
3409 ["Mark Function" vhdl-mark-defun t])
3410 "--"
3411 ("Indent"
3412 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3413 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3414 ["Region" vhdl-indent-region (mark)]
3415 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3416 ("Align"
3417 ["Group" vhdl-align-group t]
3418 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3419 ["List" vhdl-align-list t]
3420 ["Declarations" vhdl-align-declarations t]
3421 ["Region" vhdl-align-region (mark)]
3422 ["Buffer" vhdl-align-buffer t]
3423 "--"
3424 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3425 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3426 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3427 ("Fill"
3428 ["List" vhdl-fill-list t]
3429 ["Group" vhdl-fill-group t]
3430 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3431 ["Region" vhdl-fill-region (mark)])
3432 ("Beautify"
3433 ["Region" vhdl-beautify-region (mark)]
3434 ["Buffer" vhdl-beautify-buffer t])
3435 ("Fix"
3436 ["Generic/Port Clause" vhdl-fix-clause t]
3437 "--"
3438 ["Case Region" vhdl-fix-case-region (mark)]
3439 ["Case Buffer" vhdl-fix-case-buffer t]
3440 "--"
3441 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3442 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3443 "--"
3444 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3445 ("Update"
3446 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3447 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3448 "--"
3449 ["Fontify Buffer" vhdl-fontify-buffer t]
3450 ["Statistics Buffer" vhdl-statistics-buffer t]
3451 ["Show Messages" vhdl-show-messages t]
3452 ["Syntactic Info" vhdl-show-syntactic-information t]
3453 "--"
3454 ["Speedbar" vhdl-speedbar t]
3455 ["Hide/Show" vhdl-hs-minor-mode t]
3456 "--"
3457 ("Documentation"
3458 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3459 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3460 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3461 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3462 ["Version" vhdl-version t]
3463 ["Bug Report..." vhdl-submit-bug-report t]
3464 "--"
3465 ("Options"
3466 ("Mode"
3467 ["Electric Mode"
3468 (progn (customize-set-variable 'vhdl-electric-mode
3469 (not vhdl-electric-mode))
3470 (vhdl-mode-line-update))
3471 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3472 ["Stutter Mode"
3473 (progn (customize-set-variable 'vhdl-stutter-mode
3474 (not vhdl-stutter-mode))
3475 (vhdl-mode-line-update))
3476 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3477 ["Indent Tabs Mode"
3478 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3479 (not vhdl-indent-tabs-mode))
3480 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3481 :style toggle :selected vhdl-indent-tabs-mode]
3482 "--"
3483 ["Customize Group..." (customize-group 'vhdl-mode) t])
3484 ("Project"
3485 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3486 ,(append
3487 '("Selected Project at Startup"
3488 ["None" (progn (customize-set-variable 'vhdl-project nil)
3489 (vhdl-set-project ""))
3490 :style radio :selected (null vhdl-project)]
3491 "--")
3492 ;; add menu entries for defined projects
3493 (let ((project-alist vhdl-project-alist) menu-list name)
3494 (while project-alist
3495 (setq name (caar project-alist))
3496 (setq menu-list
3497 (cons `[,name (progn (customize-set-variable
3498 'vhdl-project ,name)
3499 (vhdl-set-project ,name))
3500 :style radio :selected (equal ,name vhdl-project)]
3501 menu-list))
3502 (setq project-alist (cdr project-alist)))
3503 (setq menu-list (nreverse menu-list))
3504 (vhdl-menu-split menu-list "Project")))
3505 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3506 ("Auto Load Setup File"
3507 ["At Startup"
3508 (customize-set-variable 'vhdl-project-auto-load
3509 (if (memq 'startup vhdl-project-auto-load)
3510 (delq 'startup vhdl-project-auto-load)
3511 (cons 'startup vhdl-project-auto-load)))
3512 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3513 ["Sort Projects"
3514 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3515 :style toggle :selected vhdl-project-sort]
3516 "--"
3517 ["Customize Group..." (customize-group 'vhdl-project) t])
3518 ("Compiler"
3519 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3520 ,(append
3521 '("Selected Compiler at Startup")
3522 ;; add menu entries for defined compilers
3523 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3524 (while comp-alist
3525 (setq name (caar comp-alist))
3526 (setq menu-list
3527 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3528 :style radio :selected (equal ,name vhdl-compiler)]
3529 menu-list))
3530 (setq comp-alist (cdr comp-alist)))
3531 (setq menu-list (nreverse menu-list))
3532 (vhdl-menu-split menu-list "Compler")))
3533 ["Use Local Error Regexp"
3534 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3535 (not vhdl-compile-use-local-error-regexp))
3536 :style toggle :selected vhdl-compile-use-local-error-regexp]
3537 ["Makefile Generation Hook..."
3538 (customize-option 'vhdl-makefile-generation-hook) t]
3539 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3540 "--"
3541 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3542 ("Style"
3543 ("VHDL Standard"
3544 ["VHDL'87"
3545 (progn (customize-set-variable 'vhdl-standard
3546 (list '87 (cadr vhdl-standard)))
3547 (vhdl-activate-customizations))
3548 :style radio :selected (eq '87 (car vhdl-standard))]
3549 ["VHDL'93"
3550 (progn (customize-set-variable 'vhdl-standard
3551 (list '93 (cadr vhdl-standard)))
3552 (vhdl-activate-customizations))
3553 :style radio :selected (eq '93 (car vhdl-standard))]
3554 "--"
3555 ["VHDL-AMS"
3556 (progn (customize-set-variable
3557 'vhdl-standard (list (car vhdl-standard)
3558 (if (memq 'ams (cadr vhdl-standard))
3559 (delq 'ams (cadr vhdl-standard))
3560 (cons 'ams (cadr vhdl-standard)))))
3561 (vhdl-activate-customizations))
3562 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3563 ["Math Packages"
3564 (progn (customize-set-variable
3565 'vhdl-standard (list (car vhdl-standard)
3566 (if (memq 'math (cadr vhdl-standard))
3567 (delq 'math (cadr vhdl-standard))
3568 (cons 'math (cadr vhdl-standard)))))
3569 (vhdl-activate-customizations))
3570 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3571 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3572 ["Upper Case Keywords"
3573 (customize-set-variable 'vhdl-upper-case-keywords
3574 (not vhdl-upper-case-keywords))
3575 :style toggle :selected vhdl-upper-case-keywords]
3576 ["Upper Case Types"
3577 (customize-set-variable 'vhdl-upper-case-types
3578 (not vhdl-upper-case-types))
3579 :style toggle :selected vhdl-upper-case-types]
3580 ["Upper Case Attributes"
3581 (customize-set-variable 'vhdl-upper-case-attributes
3582 (not vhdl-upper-case-attributes))
3583 :style toggle :selected vhdl-upper-case-attributes]
3584 ["Upper Case Enumeration Values"
3585 (customize-set-variable 'vhdl-upper-case-enum-values
3586 (not vhdl-upper-case-enum-values))
3587 :style toggle :selected vhdl-upper-case-enum-values]
3588 ["Upper Case Constants"
3589 (customize-set-variable 'vhdl-upper-case-constants
3590 (not vhdl-upper-case-constants))
3591 :style toggle :selected vhdl-upper-case-constants]
3592 ("Use Direct Instantiation"
3593 ["Never"
3594 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3595 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3596 ["Standard"
3597 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3598 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3599 ["Always"
3600 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3601 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3602 "--"
3603 ["Customize Group..." (customize-group 'vhdl-style) t])
3604 ("Naming"
3605 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3606 ["Architecture File Name..."
3607 (customize-option 'vhdl-architecture-file-name) t]
3608 ["Configuration File Name..."
3609 (customize-option 'vhdl-configuration-file-name) t]
3610 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3611 ("File Name Case"
3612 ["As Is"
3613 (customize-set-variable 'vhdl-file-name-case 'identity)
3614 :style radio :selected (eq 'identity vhdl-file-name-case)]
3615 ["Lower Case"
3616 (customize-set-variable 'vhdl-file-name-case 'downcase)
3617 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3618 ["Upper Case"
3619 (customize-set-variable 'vhdl-file-name-case 'upcase)
3620 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3621 ["Capitalize"
3622 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3623 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3624 "--"
3625 ["Customize Group..." (customize-group 'vhdl-naming) t])
3626 ("Template"
3627 ("Electric Keywords"
3628 ["VHDL Keywords"
3629 (customize-set-variable 'vhdl-electric-keywords
3630 (if (memq 'vhdl vhdl-electric-keywords)
3631 (delq 'vhdl vhdl-electric-keywords)
3632 (cons 'vhdl vhdl-electric-keywords)))
3633 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3634 ["User Model Keywords"
3635 (customize-set-variable 'vhdl-electric-keywords
3636 (if (memq 'user vhdl-electric-keywords)
3637 (delq 'user vhdl-electric-keywords)
3638 (cons 'user vhdl-electric-keywords)))
3639 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3640 ("Insert Optional Labels"
3641 ["None"
3642 (customize-set-variable 'vhdl-optional-labels 'none)
3643 :style radio :selected (eq 'none vhdl-optional-labels)]
3644 ["Processes Only"
3645 (customize-set-variable 'vhdl-optional-labels 'process)
3646 :style radio :selected (eq 'process vhdl-optional-labels)]
3647 ["All Constructs"
3648 (customize-set-variable 'vhdl-optional-labels 'all)
3649 :style radio :selected (eq 'all vhdl-optional-labels)])
3650 ("Insert Empty Lines"
3651 ["None"
3652 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3653 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3654 ["Design Units Only"
3655 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3656 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3657 ["All Constructs"
3658 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3659 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3660 ["Argument List Indent"
3661 (customize-set-variable 'vhdl-argument-list-indent
3662 (not vhdl-argument-list-indent))
3663 :style toggle :selected vhdl-argument-list-indent]
3664 ["Association List with Formals"
3665 (customize-set-variable 'vhdl-association-list-with-formals
3666 (not vhdl-association-list-with-formals))
3667 :style toggle :selected vhdl-association-list-with-formals]
3668 ["Conditions in Parenthesis"
3669 (customize-set-variable 'vhdl-conditions-in-parenthesis
3670 (not vhdl-conditions-in-parenthesis))
3671 :style toggle :selected vhdl-conditions-in-parenthesis]
3672 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3673 ["One String..." (customize-option 'vhdl-one-string) t]
3674 ("File Header"
3675 ["Header String..." (customize-option 'vhdl-file-header) t]
3676 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3677 ["Company Name..." (customize-option 'vhdl-company-name) t]
3678 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3679 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3680 ["Date Format..." (customize-option 'vhdl-date-format) t]
3681 ["Modify Date Prefix String..."
3682 (customize-option 'vhdl-modify-date-prefix-string) t]
3683 ["Modify Date on Saving"
3684 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3685 (not vhdl-modify-date-on-saving))
3686 (vhdl-activate-customizations))
3687 :style toggle :selected vhdl-modify-date-on-saving])
3688 ("Sequential Process"
3689 ("Kind of Reset"
3690 ["None"
3691 (customize-set-variable 'vhdl-reset-kind 'none)
3692 :style radio :selected (eq 'none vhdl-reset-kind)]
3693 ["Synchronous"
3694 (customize-set-variable 'vhdl-reset-kind 'sync)
3695 :style radio :selected (eq 'sync vhdl-reset-kind)]
3696 ["Asynchronous"
3697 (customize-set-variable 'vhdl-reset-kind 'async)
3698 :style radio :selected (eq 'async vhdl-reset-kind)])
3699 ["Reset is Active High"
3700 (customize-set-variable 'vhdl-reset-active-high
3701 (not vhdl-reset-active-high))
3702 :style toggle :selected vhdl-reset-active-high]
3703 ["Use Rising Clock Edge"
3704 (customize-set-variable 'vhdl-clock-rising-edge
3705 (not vhdl-clock-rising-edge))
3706 :style toggle :selected vhdl-clock-rising-edge]
3707 ("Clock Edge Condition"
3708 ["Standard"
3709 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3710 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3711 ["Function \"rising_edge\""
3712 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3713 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3714 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3715 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3716 "--"
3717 ["Customize Group..." (customize-group 'vhdl-template) t])
3718 ("Model"
3719 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3720 ("Port"
3721 ["Include Port Comments"
3722 (customize-set-variable 'vhdl-include-port-comments
3723 (not vhdl-include-port-comments))
3724 :style toggle :selected vhdl-include-port-comments]
3725 ["Include Direction Comments"
3726 (customize-set-variable 'vhdl-include-direction-comments
3727 (not vhdl-include-direction-comments))
3728 :style toggle :selected vhdl-include-direction-comments]
3729 ["Include Type Comments"
3730 (customize-set-variable 'vhdl-include-type-comments
3731 (not vhdl-include-type-comments))
3732 :style toggle :selected vhdl-include-type-comments]
3733 ("Include Group Comments"
3734 ["Never"
3735 (customize-set-variable 'vhdl-include-group-comments 'never)
3736 :style radio :selected (eq 'never vhdl-include-group-comments)]
3737 ["Declarations"
3738 (customize-set-variable 'vhdl-include-group-comments 'decl)
3739 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3740 ["Always"
3741 (customize-set-variable 'vhdl-include-group-comments 'always)
3742 :style radio :selected (eq 'always vhdl-include-group-comments)])
3743 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3744 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3745 ("Testbench"
3746 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3747 ["Architecture Name..."
3748 (customize-option 'vhdl-testbench-architecture-name) t]
3749 ["Configuration Name..."
3750 (customize-option 'vhdl-testbench-configuration-name) t]
3751 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3752 ["Include Header"
3753 (customize-set-variable 'vhdl-testbench-include-header
3754 (not vhdl-testbench-include-header))
3755 :style toggle :selected vhdl-testbench-include-header]
3756 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3757 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3758 ["Initialize Signals"
3759 (customize-set-variable 'vhdl-testbench-initialize-signals
3760 (not vhdl-testbench-initialize-signals))
3761 :style toggle :selected vhdl-testbench-initialize-signals]
3762 ["Include Library Clause"
3763 (customize-set-variable 'vhdl-testbench-include-library
3764 (not vhdl-testbench-include-library))
3765 :style toggle :selected vhdl-testbench-include-library]
3766 ["Include Configuration"
3767 (customize-set-variable 'vhdl-testbench-include-configuration
3768 (not vhdl-testbench-include-configuration))
3769 :style toggle :selected vhdl-testbench-include-configuration]
3770 ("Create Files"
3771 ["None"
3772 (customize-set-variable 'vhdl-testbench-create-files 'none)
3773 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3774 ["Single"
3775 (customize-set-variable 'vhdl-testbench-create-files 'single)
3776 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3777 ["Separate"
3778 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3779 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3780 ["Testbench Entity File Name..."
3781 (customize-option 'vhdl-testbench-entity-file-name) t]
3782 ["Testbench Architecture File Name..."
3783 (customize-option 'vhdl-testbench-architecture-file-name) t])
3784 "--"
3785 ["Customize Group..." (customize-group 'vhdl-port) t])
3786 ("Compose"
3787 ["Architecture Name..."
3788 (customize-option 'vhdl-compose-architecture-name) t]
3789 ["Configuration Name..."
3790 (customize-option 'vhdl-compose-configuration-name) t]
3791 ["Components Package Name..."
3792 (customize-option 'vhdl-components-package-name) t]
3793 ["Use Components Package"
3794 (customize-set-variable 'vhdl-use-components-package
3795 (not vhdl-use-components-package))
3796 :style toggle :selected vhdl-use-components-package]
3797 ["Include Header"
3798 (customize-set-variable 'vhdl-compose-include-header
3799 (not vhdl-compose-include-header))
3800 :style toggle :selected vhdl-compose-include-header]
3801 ("Create Entity/Architecture Files"
3802 ["None"
3803 (customize-set-variable 'vhdl-compose-create-files 'none)
3804 :style radio :selected (eq 'none vhdl-compose-create-files)]
3805 ["Single"
3806 (customize-set-variable 'vhdl-compose-create-files 'single)
3807 :style radio :selected (eq 'single vhdl-compose-create-files)]
3808 ["Separate"
3809 (customize-set-variable 'vhdl-compose-create-files 'separate)
3810 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3811 ["Create Configuration File"
3812 (customize-set-variable 'vhdl-compose-configuration-create-file
3813 (not vhdl-compose-configuration-create-file))
3814 :style toggle :selected vhdl-compose-configuration-create-file]
3815 ["Hierarchical Configuration"
3816 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3817 (not vhdl-compose-configuration-hierarchical))
3818 :style toggle :selected vhdl-compose-configuration-hierarchical]
3819 ["Use Subconfiguration"
3820 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3821 (not vhdl-compose-configuration-use-subconfiguration))
3822 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3823 "--"
3824 ["Customize Group..." (customize-group 'vhdl-compose) t])
3825 ("Comment"
3826 ["Self Insert Comments"
3827 (customize-set-variable 'vhdl-self-insert-comments
3828 (not vhdl-self-insert-comments))
3829 :style toggle :selected vhdl-self-insert-comments]
3830 ["Prompt for Comments"
3831 (customize-set-variable 'vhdl-prompt-for-comments
3832 (not vhdl-prompt-for-comments))
3833 :style toggle :selected vhdl-prompt-for-comments]
3834 ["Inline Comment Column..."
3835 (customize-option 'vhdl-inline-comment-column) t]
3836 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3837 "--"
3838 ["Customize Group..." (customize-group 'vhdl-comment) t])
3839 ("Align"
3840 ["Auto Align Templates"
3841 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3842 :style toggle :selected vhdl-auto-align]
3843 ["Align Line Groups"
3844 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3845 :style toggle :selected vhdl-align-groups]
3846 ["Group Separation String..."
3847 (customize-set-variable 'vhdl-align-group-separate) t]
3848 ["Align Lines with Same Indent"
3849 (customize-set-variable 'vhdl-align-same-indent
3850 (not vhdl-align-same-indent))
3851 :style toggle :selected vhdl-align-same-indent]
3852 "--"
3853 ["Customize Group..." (customize-group 'vhdl-align) t])
3854 ("Highlight"
3855 ["Highlighting On/Off..."
3856 (customize-option
3857 (if (fboundp 'global-font-lock-mode)
3858 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3859 ["Highlight Keywords"
3860 (progn (customize-set-variable 'vhdl-highlight-keywords
3861 (not vhdl-highlight-keywords))
3862 (vhdl-fontify-buffer))
3863 :style toggle :selected vhdl-highlight-keywords]
3864 ["Highlight Names"
3865 (progn (customize-set-variable 'vhdl-highlight-names
3866 (not vhdl-highlight-names))
3867 (vhdl-fontify-buffer))
3868 :style toggle :selected vhdl-highlight-names]
3869 ["Highlight Special Words"
3870 (progn (customize-set-variable 'vhdl-highlight-special-words
3871 (not vhdl-highlight-special-words))
3872 (vhdl-fontify-buffer))
3873 :style toggle :selected vhdl-highlight-special-words]
3874 ["Highlight Forbidden Words"
3875 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3876 (not vhdl-highlight-forbidden-words))
3877 (vhdl-fontify-buffer))
3878 :style toggle :selected vhdl-highlight-forbidden-words]
3879 ["Highlight Verilog Keywords"
3880 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3881 (not vhdl-highlight-verilog-keywords))
3882 (vhdl-fontify-buffer))
3883 :style toggle :selected vhdl-highlight-verilog-keywords]
3884 ["Highlight \"translate_off\""
3885 (progn (customize-set-variable 'vhdl-highlight-translate-off
3886 (not vhdl-highlight-translate-off))
3887 (vhdl-fontify-buffer))
3888 :style toggle :selected vhdl-highlight-translate-off]
3889 ["Case Sensitive Highlighting"
3890 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3891 (not vhdl-highlight-case-sensitive))
3892 (vhdl-fontify-buffer))
3893 :style toggle :selected vhdl-highlight-case-sensitive]
3894 ["Special Syntax Definition..."
3895 (customize-option 'vhdl-special-syntax-alist) t]
3896 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3897 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3898 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3899 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3900 "--"
3901 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3902 ("Speedbar"
3903 ["Auto Open at Startup"
3904 (customize-set-variable 'vhdl-speedbar-auto-open
3905 (not vhdl-speedbar-auto-open))
3906 :style toggle :selected vhdl-speedbar-auto-open]
3907 ("Default Displaying Mode"
3908 ["Files"
3909 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3910 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3911 ["Directory Hierarchy"
3912 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3913 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3914 ["Project Hierarchy"
3915 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3916 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3917 ["Indentation Offset..."
3918 (customize-option 'speedbar-indentation-width) t]
3919 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3920 ["Jump to Unit when Opening"
3921 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3922 (not vhdl-speedbar-jump-to-unit))
3923 :style toggle :selected vhdl-speedbar-jump-to-unit]
3924 ["Update Hierarchy on File Saving"
3925 (customize-set-variable 'vhdl-speedbar-update-on-saving
3926 (not vhdl-speedbar-update-on-saving))
3927 :style toggle :selected vhdl-speedbar-update-on-saving]
3928 ("Save in Cache File"
3929 ["Hierarchy Information"
3930 (customize-set-variable 'vhdl-speedbar-save-cache
3931 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3932 (delq 'hierarchy vhdl-speedbar-save-cache)
3933 (cons 'hierarchy vhdl-speedbar-save-cache)))
3934 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3935 ["Displaying Status"
3936 (customize-set-variable 'vhdl-speedbar-save-cache
3937 (if (memq 'display vhdl-speedbar-save-cache)
3938 (delq 'display vhdl-speedbar-save-cache)
3939 (cons 'display vhdl-speedbar-save-cache)))
3940 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3941 ["Cache File Name..."
3942 (customize-option 'vhdl-speedbar-cache-file-name) t]
3943 "--"
3944 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3945 ("Menu"
3946 ["Add Index Menu when Loading File"
3947 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3948 (vhdl-index-menu-init))
3949 :style toggle :selected vhdl-index-menu]
3950 ["Add Source File Menu when Loading File"
3951 (progn (customize-set-variable 'vhdl-source-file-menu
3952 (not vhdl-source-file-menu))
3953 (vhdl-add-source-files-menu))
3954 :style toggle :selected vhdl-source-file-menu]
3955 ["Add Hideshow Menu at Startup"
3956 (progn (customize-set-variable 'vhdl-hideshow-menu
3957 (not vhdl-hideshow-menu))
3958 (vhdl-activate-customizations))
3959 :style toggle :selected vhdl-hideshow-menu]
3960 ["Hide Everything Initially"
3961 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3962 :style toggle :selected vhdl-hide-all-init]
3963 "--"
3964 ["Customize Group..." (customize-group 'vhdl-menu) t])
3965 ("Print"
3966 ["In Two Column Format"
3967 (progn (customize-set-variable 'vhdl-print-two-column
3968 (not vhdl-print-two-column))
3969 (message "Activate new setting by saving options and restarting Emacs"))
3970 :style toggle :selected vhdl-print-two-column]
3971 ["Use Customized Faces"
3972 (progn (customize-set-variable 'vhdl-print-customize-faces
3973 (not vhdl-print-customize-faces))
3974 (message "Activate new setting by saving options and restarting Emacs"))
3975 :style toggle :selected vhdl-print-customize-faces]
3976 "--"
3977 ["Customize Group..." (customize-group 'vhdl-print) t])
3978 ("Miscellaneous"
3979 ["Use Intelligent Tab"
3980 (progn (customize-set-variable 'vhdl-intelligent-tab
3981 (not vhdl-intelligent-tab))
3982 (vhdl-activate-customizations))
3983 :style toggle :selected vhdl-intelligent-tab]
3984 ["Indent Syntax-Based"
3985 (customize-set-variable 'vhdl-indent-syntax-based
3986 (not vhdl-indent-syntax-based))
3987 :style toggle :selected vhdl-indent-syntax-based]
3988 ["Word Completion is Case Sensitive"
3989 (customize-set-variable 'vhdl-word-completion-case-sensitive
3990 (not vhdl-word-completion-case-sensitive))
3991 :style toggle :selected vhdl-word-completion-case-sensitive]
3992 ["Word Completion in Minibuffer"
3993 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3994 (not vhdl-word-completion-in-minibuffer))
3995 (message "Activate new setting by saving options and restarting Emacs"))
3996 :style toggle :selected vhdl-word-completion-in-minibuffer]
3997 ["Underscore is Part of Word"
3998 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3999 (not vhdl-underscore-is-part-of-word))
4000 (vhdl-activate-customizations))
4001 :style toggle :selected vhdl-underscore-is-part-of-word]
4002 "--"
4003 ["Customize Group..." (customize-group 'vhdl-misc) t])
4004 ["Related..." (customize-browse 'vhdl-related) t]
4005 "--"
4006 ["Save Options" customize-save-customized t]
4007 ["Activate Options" vhdl-activate-customizations t]
4008 ["Browse Options..." vhdl-customize t])))
4009
4010 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4011 "VHDL Mode menu.")
4012
4013 (defun vhdl-update-mode-menu ()
4014 "Update VHDL Mode menu."
4015 (interactive)
4016 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4017 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4018 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4019 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4020 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4021
4022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4023 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4024
4025 (defconst vhdl-imenu-generic-expression
4026 '(
4027 ("Subprogram"
4028 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4029 4)
4030 ("Instance"
4031 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4032 1)
4033 ("Component"
4034 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4035 2)
4036 ("Procedural"
4037 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4038 1)
4039 ("Process"
4040 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4041 1)
4042 ("Block"
4043 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4044 1)
4045 ("Package"
4046 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4047 3)
4048 ("Configuration"
4049 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4050 2)
4051 ("Architecture"
4052 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4053 2)
4054 ("Entity"
4055 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4056 2)
4057 )
4058 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4059
4060 (defun vhdl-index-menu-init ()
4061 "Initialize index menu."
4062 (set (make-local-variable 'imenu-case-fold-search) t)
4063 (set (make-local-variable 'imenu-generic-expression)
4064 vhdl-imenu-generic-expression)
4065 (when (and vhdl-index-menu (fboundp 'imenu))
4066 (if (or (not (boundp 'font-lock-maximum-size))
4067 (> font-lock-maximum-size (buffer-size)))
4068 (imenu-add-to-menubar "Index")
4069 (message "Scanning buffer for index...buffer too big"))))
4070
4071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4072 ;; Source file menu (using `easy-menu.el')
4073
4074 (defvar vhdl-sources-menu nil)
4075
4076 (defun vhdl-directory-files (directory &optional full match)
4077 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4078 message."
4079 (if (not (file-directory-p directory))
4080 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4081 (let ((dir (directory-files directory full match)))
4082 (setq dir (delete "." dir))
4083 (setq dir (delete ".." dir))
4084 dir)))
4085
4086 (defun vhdl-get-source-files (&optional full directory)
4087 "Get list of VHDL source files in DIRECTORY or current directory."
4088 (let ((mode-alist auto-mode-alist)
4089 filename-regexp)
4090 ;; create regular expressions for matching file names
4091 (setq filename-regexp "\\`[^.].*\\(")
4092 (while mode-alist
4093 (when (eq (cdar mode-alist) 'vhdl-mode)
4094 (setq filename-regexp
4095 (concat filename-regexp (caar mode-alist) "\\|")))
4096 (setq mode-alist (cdr mode-alist)))
4097 (setq filename-regexp
4098 (concat (substring filename-regexp 0
4099 (string-match "\\\\|$" filename-regexp)) "\\)"))
4100 ;; find files
4101 (vhdl-directory-files
4102 (or directory default-directory) full filename-regexp)))
4103
4104 (defun vhdl-add-source-files-menu ()
4105 "Scan directory for all VHDL source files and generate menu.
4106 The directory of the current source file is scanned."
4107 (interactive)
4108 (message "Scanning directory for source files ...")
4109 (let ((newmap (current-local-map))
4110 (file-list (vhdl-get-source-files))
4111 menu-list found)
4112 ;; Create list for menu
4113 (setq found nil)
4114 (while file-list
4115 (setq found t)
4116 (setq menu-list (cons (vector (car file-list)
4117 (list 'find-file (car file-list)) t)
4118 menu-list))
4119 (setq file-list (cdr file-list)))
4120 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4121 (when found (setq menu-list (cons "--" menu-list)))
4122 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4123 (setq menu-list (cons "Sources" menu-list))
4124 ;; Create menu
4125 (easy-menu-add menu-list)
4126 (easy-menu-define vhdl-sources-menu newmap
4127 "VHDL source files menu" menu-list))
4128 (message ""))
4129
4130
4131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4132 ;;; Mode definition
4133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4134 ;; performs all buffer local initializations
4135
4136 ;;;###autoload
4137 (defun vhdl-mode ()
4138 "Major mode for editing VHDL code.
4139
4140 Usage:
4141 ------
4142
4143 TEMPLATE INSERTION (electrification):
4144 After typing a VHDL keyword and entering `SPC', you are prompted for
4145 arguments while a template is generated for that VHDL construct. Typing
4146 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4147 template generation. Optional arguments are indicated by square
4148 brackets and removed if the queried string is left empty. Prompts for
4149 mandatory arguments remain in the code if the queried string is left
4150 empty. They can be queried again by `C-c C-t C-q'. Enabled
4151 electrification is indicated by `/e' in the modeline.
4152
4153 Typing `M-SPC' after a keyword inserts a space without calling the
4154 template generator. Automatic template generation (i.e.
4155 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4156 setting option `vhdl-electric-mode' (see OPTIONS).
4157
4158 Template generators can be invoked from the VHDL menu, by key
4159 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4160 the keyword (i.e. first word of menu entry not in parenthesis) and
4161 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4162 conf, comp, cons, func, inst, pack, sig, var.
4163
4164 Template styles can be customized in customization group
4165 `vhdl-template' \(see OPTIONS).
4166
4167
4168 HEADER INSERTION:
4169 A file header can be inserted by `C-c C-t C-h'. A file footer
4170 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4171 See customization group `vhdl-header'.
4172
4173
4174 STUTTERING:
4175 Double striking of some keys inserts cumbersome VHDL syntax elements.
4176 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4177 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4178 the modeline. The stuttering keys and their effects are:
4179
4180 ;; --> \" : \" [ --> ( -- --> comment
4181 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4182 .. --> \" => \" ] --> ) --- --> horizontal line
4183 ,, --> \" <= \" ]] --> ] ---- --> display comment
4184 == --> \" == \" '' --> \\\"
4185
4186
4187 WORD COMPLETION:
4188 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4189 word in the buffer that starts alike, inserts it and adjusts case.
4190 Re-typing `TAB' toggles through alternative word completions. This also
4191 works in the minibuffer (i.e. in template generator prompts).
4192
4193 Typing `TAB' after `(' looks for and inserts complete parenthesized
4194 expressions (e.g. for array index ranges). All keywords as well as
4195 standard types and subprograms of VHDL have predefined abbreviations
4196 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4197 beginning with \"std\").
4198
4199 Typing `TAB' after a non-word character indents the line if at the
4200 beginning of a line (i.e. no preceding non-blank characters), and
4201 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4202 stop.
4203
4204
4205 COMMENTS:
4206 `--' puts a single comment.
4207 `---' draws a horizontal line for separating code segments.
4208 `----' inserts a display comment, i.e. two horizontal lines
4209 with a comment in between.
4210 `--CR' comments out code on that line. Re-hitting CR comments
4211 out following lines.
4212 `C-c c' comments out a region if not commented out,
4213 uncomments a region if already commented out.
4214
4215 You are prompted for comments after object definitions (i.e. signals,
4216 variables, constants, ports) and after subprogram and process
4217 specifications if option `vhdl-prompt-for-comments' is non-nil.
4218 Comments are automatically inserted as additional labels (e.g. after
4219 begin statements) and as help comments if `vhdl-self-insert-comments' is
4220 non-nil.
4221
4222 Inline comments (i.e. comments after a piece of code on the same line)
4223 are indented at least to `vhdl-inline-comment-column'. Comments go at
4224 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4225 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4226 in a comment automatically opens a new comment line. `M-q' re-fills
4227 multi-line comments.
4228
4229
4230 INDENTATION:
4231 `TAB' indents a line if at the beginning of the line. The amount of
4232 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4233 always indents the current line (is bound to `TAB' if option
4234 `vhdl-intelligent-tab' is nil).
4235
4236 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4237 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4238 indented normally (nil) or relative to the opening parenthesis (non-nil)
4239 according to option `vhdl-argument-list-indent'.
4240
4241 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4242 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4243 and vice versa.
4244
4245 Syntax-based indentation can be very slow in large files. Option
4246 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4247
4248
4249 ALIGNMENT:
4250 The alignment functions align operators, keywords, and inline comments
4251 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4252 separated by blank lines, `C-c C-a C-i' a block of lines with same
4253 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4254 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4255 C-a C-d' all lines within the declarative part of a design unit. `C-c
4256 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4257 for a group of lines, and `C-c C-a M-c' for a region.
4258
4259 If option `vhdl-align-groups' is non-nil, groups of code lines
4260 separated by special lines (see option `vhdl-align-group-separate') are
4261 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4262 blocks of lines with same indent are aligned separately. Some templates
4263 are automatically aligned after generation if option `vhdl-auto-align'
4264 is non-nil.
4265
4266 Alignment tries to align inline comments at
4267 `vhdl-inline-comment-column' and tries inline comment not to exceed
4268 `vhdl-end-comment-column'.
4269
4270 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4271 symbols are surrounded by one space, and multiple spaces are eliminated.
4272
4273
4274 CODE FILLING:
4275 Code filling allows to condense code (e.g. sensitivity lists or port
4276 maps) by removing comments and newlines and re-wrapping so that all
4277 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4278 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4279 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4280 `C-c C-f M-f' an entire region.
4281
4282
4283 CODE BEAUTIFICATION:
4284 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4285 buffer respectively. This inludes indentation, alignment, and case
4286 fixing. Code beautification can also be run non-interactively using the
4287 command:
4288
4289 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4290
4291
4292 PORT TRANSLATION:
4293 Generic and port clauses from entity or component declarations can be
4294 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4295 as component instantiations and corresponding internal constants and
4296 signals, as a generic map with constants as actual generics, and as
4297 internal signal initializations (menu).
4298
4299 To include formals in component instantiations, see option
4300 `vhdl-association-list-with-formals'. To include comments in pasting,
4301 see options `vhdl-include-...-comments'.
4302
4303 A clause with several generic/port names on the same line can be
4304 flattened (`C-c C-p C-f') so that only one name per line exists. The
4305 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4306 outputs and vice versa, which can be useful in testbenches. (This
4307 reversion is done on the internal data structure and is only reflected
4308 in subsequent paste operations.)
4309
4310 Names for actual ports, instances, testbenches, and
4311 design-under-test instances can be derived from existing names according
4312 to options `vhdl-...-name'. See customization group `vhdl-port'.
4313
4314
4315 SUBPROGRAM TRANSLATION:
4316 Similar functionality exists for copying/pasting the interface of
4317 subprograms (function/procedure). A subprogram interface can be copied
4318 and then pasted as a subprogram declaration, body or call (uses
4319 association list with formals).
4320
4321
4322 TESTBENCH GENERATION:
4323 A copied port can also be pasted as a testbench. The generated
4324 testbench includes an entity, an architecture, and an optional
4325 configuration. The architecture contains the component declaration and
4326 instantiation of the DUT as well as internal constant and signal
4327 declarations. Additional user-defined templates can be inserted. The
4328 names used for entity/architecture/configuration/DUT as well as the file
4329 structure to be generated can be customized. See customization group
4330 `vhdl-testbench'.
4331
4332
4333 KEY BINDINGS:
4334 Key bindings (`C-c ...') exist for most commands (see in menu).
4335
4336
4337 VHDL MENU:
4338 All commands can be found in the VHDL menu including their key bindings.
4339
4340
4341 FILE BROWSER:
4342 The speedbar allows browsing of directories and file contents. It can
4343 be accessed from the VHDL menu and is automatically opened if option
4344 `vhdl-speedbar-auto-open' is non-nil.
4345
4346 In speedbar, open files and directories with `mouse-2' on the name and
4347 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4348
4349
4350 DESIGN HIERARCHY BROWSER:
4351 The speedbar can also be used for browsing the hierarchy of design units
4352 contained in the source files of the current directory or the specified
4353 projects (see option `vhdl-project-alist').
4354
4355 The speedbar can be switched between file, directory hierarchy and
4356 project hierarchy browsing mode in the speedbar menu or by typing `f',
4357 `h' or `H' in speedbar.
4358
4359 In speedbar, open design units with `mouse-2' on the name and browse
4360 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4361 from entities and components (in packages). Individual design units and
4362 complete designs can directly be compiled (\"Make\" menu entry).
4363
4364 The hierarchy is automatically updated upon saving a modified source
4365 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4366 hierarchy is only updated for projects that have been opened once in the
4367 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4368 options in group `vhdl-speedbar').
4369
4370 Simple design consistency checks are done during scanning, such as
4371 multiple declarations of the same unit or missing primary units that are
4372 required by secondary units.
4373
4374
4375 STRUCTURAL COMPOSITION:
4376 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4377 for a new component. Subcomponents (i.e. component declaration and
4378 instantiation) can be automatically placed from a previously read port
4379 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4380 all subcomponents can be automatically connected using internal signals
4381 and ports (`C-c C-c C-w') following these rules:
4382 - subcomponent actual ports with same name are considered to be
4383 connected by a signal (internal signal or port)
4384 - signals that are only inputs to subcomponents are considered as
4385 inputs to this component -> input port created
4386 - signals that are only outputs from subcomponents are considered as
4387 outputs from this component -> output port created
4388 - signals that are inputs to AND outputs from subcomponents are
4389 considered as internal connections -> internal signal created
4390
4391 Purpose: With appropriate naming conventions it is possible to
4392 create higher design levels with only a few mouse clicks or key
4393 strokes. A new design level can be created by simply generating a new
4394 component, placing the required subcomponents from the hierarchy
4395 browser, and wiring everything automatically.
4396
4397 Note: Automatic wiring only works reliably on templates of new
4398 components and component instantiations that were created by VHDL mode.
4399
4400 Component declarations can be placed in a components package (option
4401 `vhdl-use-components-package') which can be automatically generated for
4402 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4403 component instantiation is also supported (option
4404 `vhdl-use-direct-instantiation').
4405
4406 | Configuration declarations can automatically be generated either from
4407 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4408 | the speedbar menu (for the architecture under the cursor). The
4409 | configurations can optionally be hierarchical (i.e. include all
4410 | component levels of a hierarchical design, option
4411 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4412 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4413 | subcomponents in hierarchical configurations, the most-recently-analyzed
4414 | (mra) architecture is selected. If another architecture is desired, it
4415 | can be marked as most-recently-analyzed (speedbar menu) before
4416 | generating the configuration.
4417 |
4418 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4419 | declarations) are currently not considered when displaying
4420 | configurations in speedbar.
4421
4422 See the options group `vhdl-compose' for all relevant user options.
4423
4424
4425 SOURCE FILE COMPILATION:
4426 The syntax of the current buffer can be analyzed by calling a VHDL
4427 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4428 option `vhdl-compiler'. The available compilers are listed in option
4429 `vhdl-compiler-alist' including all required compilation command,
4430 command options, compilation directory, and error message syntax
4431 information. New compilers can be added.
4432
4433 All the source files of an entire design can be compiled by the `make'
4434 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4435
4436
4437 MAKEFILE GENERATION:
4438 Makefiles can be generated automatically by an internal generation
4439 routine (`C-c M-k'). The library unit dependency information is
4440 obtained from the hierarchy browser. Makefile generation can be
4441 customized for each compiler in option `vhdl-compiler-alist'.
4442
4443 Makefile generation can also be run non-interactively using the
4444 command:
4445
4446 emacs -batch -l ~/.emacs -l vhdl-mode
4447 [-compiler compilername] [-project projectname]
4448 -f vhdl-generate-makefile
4449
4450 The Makefile's default target \"all\" compiles the entire design, the
4451 target \"clean\" removes it and the target \"library\" creates the
4452 library directory if not existent. The Makefile also includes a target
4453 for each primary library unit which allows selective compilation of this
4454 unit, its secondary units and its subhierarchy (example: compilation of
4455 a design specified by a configuration). User specific parts can be
4456 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4457
4458 Limitations:
4459 - Only library units and dependencies within the current library are
4460 considered. Makefiles for designs that span multiple libraries are
4461 not (yet) supported.
4462 - Only one-level configurations are supported (also hierarchical),
4463 but configurations that go down several levels are not.
4464 - The \"others\" keyword in configurations is not supported.
4465
4466
4467 PROJECTS:
4468 Projects can be defined in option `vhdl-project-alist' and a current
4469 project be selected using option `vhdl-project' (permanently) or from
4470 the menu or speedbar (temporarily). For each project, title and
4471 description strings (for the file headers), source files/directories
4472 (for the hierarchy browser and Makefile generation), library name, and
4473 compiler-dependent options, exceptions and compilation directory can be
4474 specified. Compilation settings overwrite the settings of option
4475 `vhdl-compiler-alist'.
4476
4477 Project setups can be exported (i.e. written to a file) and imported.
4478 Imported setups are not automatically saved in `vhdl-project-alist' but
4479 can be saved afterwards in its customization buffer. When starting
4480 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4481 vhdl-mode\") in a directory with an existing project setup file, it is
4482 automatically loaded and its project activated if option
4483 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4484 files can be specified in option `vhdl-project-file-name'. Multiple
4485 project setups can be automatically loaded from global directories.
4486 This is an alternative to specifying project setups with option
4487 `vhdl-project-alist'.
4488
4489
4490 SPECIAL MENUES:
4491 As an alternative to the speedbar, an index menu can be added (set
4492 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4493 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4494 file) for browsing the file contents (is not populated if buffer is
4495 larger than `font-lock-maximum-size'). Also, a source file menu can be
4496 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4497 current directory for VHDL source files.
4498
4499
4500 VHDL STANDARDS:
4501 The VHDL standards to be used are specified in option `vhdl-standard'.
4502 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4503
4504
4505 KEYWORD CASE:
4506 Lower and upper case for keywords and standardized types, attributes,
4507 and enumeration values is supported. If the option
4508 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4509 lower case and are converted into upper case automatically (not for
4510 types, attributes, and enumeration values). The case of keywords,
4511 types, attributes,and enumeration values can be fixed for an entire
4512 region (menu) or buffer (`C-c C-x C-c') according to the options
4513 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4514
4515
4516 HIGHLIGHTING (fontification):
4517 Keywords and standardized types, attributes, enumeration values, and
4518 function names (controlled by option `vhdl-highlight-keywords'), as well
4519 as comments, strings, and template prompts are highlighted using
4520 different colors. Unit, subprogram, signal, variable, constant,
4521 parameter and generic/port names in declarations as well as labels are
4522 highlighted if option `vhdl-highlight-names' is non-nil.
4523
4524 Additional reserved words or words with a forbidden syntax (e.g. words
4525 that should be avoided) can be specified in option
4526 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4527 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4528 keywords are highlighted as forbidden words if option
4529 `vhdl-highlight-verilog-keywords' is non-nil.
4530
4531 Words with special syntax can be highlighted by specifying their
4532 syntax and color in option `vhdl-special-syntax-alist' and by setting
4533 option `vhdl-highlight-special-words' to non-nil. This allows to
4534 establish some naming conventions (e.g. to distinguish different kinds
4535 of signals or other objects by using name suffices) and to support them
4536 visually.
4537
4538 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4539 to support case-sensitive highlighting. However, keywords are then only
4540 highlighted if written in lower case.
4541
4542 Code between \"translate_off\" and \"translate_on\" pragmas is
4543 highlighted using a different background color if option
4544 `vhdl-highlight-translate-off' is non-nil.
4545
4546 For documentation and customization of the used colors see
4547 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4548 highlighting of matching parenthesis, see customization group
4549 `paren-showing'. Automatic buffer highlighting is turned on/off by
4550 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4551
4552
4553 USER MODELS:
4554 VHDL models (templates) can be specified by the user and made accessible
4555 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4556 electrification. See option `vhdl-model-alist'.
4557
4558
4559 HIDE/SHOW:
4560 The code of blocks, processes, subprograms, component declarations and
4561 instantiations, generic/port clauses, and configuration declarations can
4562 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4563 the code (see customization group `vhdl-menu'). XEmacs: limited
4564 functionality due to old `hideshow.el' package.
4565
4566
4567 CODE UPDATING:
4568 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4569 current process, `C-c C-u M-s' of all processes in the current buffer.
4570 Limitations:
4571 - Only declared local signals (ports, signals declared in
4572 architecture and blocks) are automatically inserted.
4573 - Global signals declared in packages are not automatically inserted.
4574 Insert them once manually (will be kept afterwards).
4575 - Out parameters of procedures are considered to be read.
4576 Use option `vhdl-entity-file-name' to specify the entity file name
4577 \(used to obtain the port names).
4578
4579
4580 CODE FIXING:
4581 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4582 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4583
4584
4585 PRINTING:
4586 Postscript printing with different faces (an optimized set of faces is
4587 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4588 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4589 postscript printing commands. Option `vhdl-print-two-column' defines
4590 appropriate default settings for nice landscape two-column printing.
4591 The paper format can be set by option `ps-paper-type'. Do not forget to
4592 switch `ps-print-color-p' to nil for printing on black-and-white
4593 printers.
4594
4595
4596 OPTIONS:
4597 User options allow customization of VHDL Mode. All options are
4598 accessible from the \"Options\" menu entry. Simple options (switches
4599 and choices) can directly be changed, while for complex options a
4600 customization buffer is opened. Changed options can be saved for future
4601 sessions using the \"Save Options\" menu entry.
4602
4603 Options and their detailed descriptions can also be accessed by using
4604 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4605 customize-group' for groups). Some customizations only take effect
4606 after some action (read the NOTE in the option documentation).
4607 Customization can also be done globally (i.e. site-wide, read the
4608 INSTALL file).
4609
4610 Not all options are described in this documentation, so go and see
4611 what other useful user options there are (`M-x vhdl-customize' or menu)!
4612
4613
4614 FILE EXTENSIONS:
4615 As default, files with extensions \".vhd\" and \".vhdl\" are
4616 automatically recognized as VHDL source files. To add an extension
4617 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4618
4619 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4620
4621
4622 HINTS:
4623 - To start Emacs with open VHDL hierarchy browser without having to load
4624 a VHDL file first, use the command:
4625
4626 emacs -l vhdl-mode -f speedbar-frame-mode
4627
4628 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4629
4630 - Some features only work on properly indented code.
4631
4632
4633 RELEASE NOTES:
4634 See also the release notes (menu) for added features in new releases.
4635
4636
4637 Maintenance:
4638 ------------
4639
4640 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4641 Add a description of the problem and include a reproducible test case.
4642
4643 Questions and enhancement requests can be sent to <reto@gnu.org>.
4644
4645 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4646 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4647 releases. You are kindly invited to participate in beta testing. Subscribe
4648 to above mailing lists by sending an email to <reto@gnu.org>.
4649
4650 VHDL Mode is officially distributed at
4651 URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
4652 where the latest version can be found.
4653
4654
4655 Known problems:
4656 ---------------
4657
4658 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4659 - XEmacs: Incorrect start-up when automatically opening speedbar.
4660 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4661
4662
4663 The VHDL Mode Authors
4664 Reto Zimmermann and Rod Whitby
4665
4666 Key bindings:
4667 -------------
4668
4669 \\{vhdl-mode-map}"
4670 (interactive)
4671 (kill-all-local-variables)
4672 (setq major-mode 'vhdl-mode)
4673 (setq mode-name "VHDL")
4674
4675 ;; set maps and tables
4676 (use-local-map vhdl-mode-map)
4677 (set-syntax-table vhdl-mode-syntax-table)
4678 (setq local-abbrev-table vhdl-mode-abbrev-table)
4679
4680 ;; set local variables
4681 (set (make-local-variable 'paragraph-start)
4682 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4683 (set (make-local-variable 'paragraph-separate) paragraph-start)
4684 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4685 (set (make-local-variable 'require-final-newline)
4686 (if vhdl-emacs-22 mode-require-final-newline t))
4687 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4688 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4689 (set (make-local-variable 'comment-start) "--")
4690 (set (make-local-variable 'comment-end) "")
4691 (when vhdl-emacs-21
4692 (set (make-local-variable 'comment-padding) ""))
4693 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4694 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4695 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4696 (set (make-local-variable 'comment-multi-line) nil)
4697 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4698 (set (make-local-variable 'hippie-expand-verbose) nil)
4699
4700 ;; setup the comment indent variable in a Emacs version portable way
4701 ;; ignore any byte compiler warnings you might get here
4702 (when (boundp 'comment-indent-function)
4703 (make-local-variable 'comment-indent-function)
4704 (setq comment-indent-function 'vhdl-comment-indent))
4705
4706 ;; initialize font locking
4707 (set (make-local-variable 'font-lock-defaults)
4708 (list
4709 '(nil vhdl-font-lock-keywords) nil
4710 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4711 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4712 (unless vhdl-emacs-21
4713 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4714 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4715 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4716 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4717 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4718 ; (turn-on-font-lock)
4719
4720 ;; variables for source file compilation
4721 (when vhdl-compile-use-local-error-regexp
4722 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4723 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4724
4725 ;; add index menu
4726 (vhdl-index-menu-init)
4727 ;; add source file menu
4728 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4729 ;; add VHDL menu
4730 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4731 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4732 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4733 ;; initialize hideshow and add menu
4734 (vhdl-hideshow-init)
4735 (run-hooks 'menu-bar-update-hook)
4736
4737 ;; miscellaneous
4738 (vhdl-ps-print-init)
4739 (vhdl-write-file-hooks-init)
4740 (vhdl-mode-line-update)
4741 (message "VHDL Mode %s.%s" vhdl-version
4742 (if noninteractive "" " See menu for documentation and release notes."))
4743
4744 ;; run hooks
4745 (if vhdl-emacs-22
4746 (run-mode-hooks 'vhdl-mode-hook)
4747 (run-hooks 'vhdl-mode-hook)))
4748
4749 (defun vhdl-activate-customizations ()
4750 "Activate all customizations on local variables."
4751 (interactive)
4752 (vhdl-mode-map-init)
4753 (use-local-map vhdl-mode-map)
4754 (set-syntax-table vhdl-mode-syntax-table)
4755 (setq comment-column vhdl-inline-comment-column)
4756 (setq end-comment-column vhdl-end-comment-column)
4757 (vhdl-write-file-hooks-init)
4758 (vhdl-update-mode-menu)
4759 (vhdl-hideshow-init)
4760 (run-hooks 'menu-bar-update-hook)
4761 (vhdl-mode-line-update))
4762
4763 (defun vhdl-write-file-hooks-init ()
4764 "Add/remove hooks when buffer is saved."
4765 (if vhdl-modify-date-on-saving
4766 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4767 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4768 (make-local-variable 'after-save-hook)
4769 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4770
4771 (defun vhdl-process-command-line-option (option)
4772 "Process command line options for VHDL Mode."
4773 (cond
4774 ;; set compiler
4775 ((equal option "-compiler")
4776 (vhdl-set-compiler (car command-line-args-left))
4777 (setq command-line-args-left (cdr command-line-args-left)))
4778 ;; set project
4779 ((equal option "-project")
4780 (vhdl-set-project (car command-line-args-left))
4781 (setq command-line-args-left (cdr command-line-args-left)))))
4782
4783 ;; make Emacs process VHDL Mode options
4784 (setq command-switch-alist
4785 (append command-switch-alist
4786 '(("-compiler" . vhdl-process-command-line-option)
4787 ("-project" . vhdl-process-command-line-option))))
4788
4789
4790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4791 ;;; Keywords and standardized words
4792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4793
4794 (defconst vhdl-93-keywords
4795 '(
4796 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4797 "assert" "attribute"
4798 "begin" "block" "body" "buffer" "bus"
4799 "case" "component" "configuration" "constant"
4800 "disconnect" "downto"
4801 "else" "elsif" "end" "entity" "exit"
4802 "file" "for" "function"
4803 "generate" "generic" "group" "guarded"
4804 "if" "impure" "in" "inertial" "inout" "is"
4805 "label" "library" "linkage" "literal" "loop"
4806 "map" "mod"
4807 "nand" "new" "next" "nor" "not" "null"
4808 "of" "on" "open" "or" "others" "out"
4809 "package" "port" "postponed" "procedure" "process" "pure"
4810 "range" "record" "register" "reject" "rem" "report" "return"
4811 "rol" "ror"
4812 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4813 "then" "to" "transport" "type"
4814 "unaffected" "units" "until" "use"
4815 "variable"
4816 "wait" "when" "while" "with"
4817 "xnor" "xor"
4818 )
4819 "List of VHDL'93 keywords.")
4820
4821 (defconst vhdl-ams-keywords
4822 '(
4823 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4824 "reference" "spectrum" "subnature" "terminal" "through"
4825 "tolerance"
4826 )
4827 "List of VHDL-AMS keywords.")
4828
4829 (defconst vhdl-verilog-keywords
4830 '(
4831 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4832 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4833 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4834 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4835 "endprimitive" "endspecify" "endtable" "endtask" "event"
4836 "for" "force" "forever" "fork" "function"
4837 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4838 "macromodule" "makefile" "medium" "module"
4839 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4840 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4841 "pullup"
4842 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4843 "rtranif0" "rtranif1"
4844 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4845 "strong1" "supply" "supply0" "supply1"
4846 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4847 "triand" "trior" "trireg"
4848 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4849 )
4850 "List of Verilog keywords as candidate for additional reserved words.")
4851
4852 (defconst vhdl-93-types
4853 '(
4854 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4855 "real" "time" "natural" "positive" "string" "line" "text" "side"
4856 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4857 "std_logic" "std_logic_vector"
4858 "std_ulogic" "std_ulogic_vector"
4859 )
4860 "List of VHDL'93 standardized types.")
4861
4862 (defconst vhdl-ams-types
4863 '(
4864 "domain_type" "real_vector"
4865 ;; from `nature_pkg' package
4866 "voltage" "current" "electrical" "position" "velocity" "force"
4867 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4868 "pressure" "flowrate" "fluid"
4869 )
4870 "List of VHDL-AMS standardized types.")
4871
4872 (defconst vhdl-math-types
4873 '(
4874 "complex" "complex_polar"
4875 )
4876 "List of Math Packages standardized types.")
4877
4878 (defconst vhdl-93-attributes
4879 '(
4880 "base" "left" "right" "high" "low" "pos" "val" "succ"
4881 "pred" "leftof" "rightof" "range" "reverse_range"
4882 "length" "delayed" "stable" "quiet" "transaction"
4883 "event" "active" "last_event" "last_active" "last_value"
4884 "driving" "driving_value" "ascending" "value" "image"
4885 "simple_name" "instance_name" "path_name"
4886 "foreign"
4887 )
4888 "List of VHDL'93 standardized attributes.")
4889
4890 (defconst vhdl-ams-attributes
4891 '(
4892 "across" "through"
4893 "reference" "contribution" "tolerance"
4894 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4895 "ramp" "slew"
4896 )
4897 "List of VHDL-AMS standardized attributes.")
4898
4899 (defconst vhdl-93-enum-values
4900 '(
4901 "true" "false"
4902 "note" "warning" "error" "failure"
4903 "read_mode" "write_mode" "append_mode"
4904 "open_ok" "status_error" "name_error" "mode_error"
4905 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4906 "right" "left"
4907 )
4908 "List of VHDL'93 standardized enumeration values.")
4909
4910 (defconst vhdl-ams-enum-values
4911 '(
4912 "quiescent_domain" "time_domain" "frequency_domain"
4913 ;; from `nature_pkg' package
4914 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4915 )
4916 "List of VHDL-AMS standardized enumeration values.")
4917
4918 (defconst vhdl-math-constants
4919 '(
4920 "math_e" "math_1_over_e"
4921 "math_pi" "math_two_pi" "math_1_over_pi"
4922 "math_half_pi" "math_q_pi" "math_3_half_pi"
4923 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4924 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4925 "math_deg_to_rad" "math_rad_to_deg"
4926 "cbase_1" "cbase_j" "czero"
4927 )
4928 "List of Math Packages standardized constants.")
4929
4930 (defconst vhdl-93-functions
4931 '(
4932 "now" "resolved" "rising_edge" "falling_edge"
4933 "read" "readline" "write" "writeline" "endfile"
4934 "resize" "is_X" "std_match"
4935 "shift_left" "shift_right" "rotate_left" "rotate_right"
4936 "to_unsigned" "to_signed" "to_integer"
4937 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4938 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4939 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4940 "shl" "shr" "ext" "sxt"
4941 "deallocate"
4942 )
4943 "List of VHDL'93 standardized functions.")
4944
4945 (defconst vhdl-ams-functions
4946 '(
4947 "frequency"
4948 )
4949 "List of VHDL-AMS standardized functions.")
4950
4951 (defconst vhdl-math-functions
4952 '(
4953 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4954 "sqrt" "cbrt" "exp" "log"
4955 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4956 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4957 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4958 )
4959 "List of Math Packages standardized functions.")
4960
4961 (defconst vhdl-93-packages
4962 '(
4963 "std_logic_1164" "numeric_std" "numeric_bit"
4964 "standard" "textio"
4965 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4966 "std_logic_misc" "std_logic_textio"
4967 "ieee" "std" "work"
4968 )
4969 "List of VHDL'93 standardized packages and libraries.")
4970
4971 (defconst vhdl-ams-packages
4972 '(
4973 ;; from `nature_pkg' package
4974 "nature_pkg"
4975 )
4976 "List of VHDL-AMS standardized packages and libraries.")
4977
4978 (defconst vhdl-math-packages
4979 '(
4980 "math_real" "math_complex"
4981 )
4982 "List of Math Packages standardized packages and libraries.")
4983
4984 (defvar vhdl-keywords nil
4985 "List of VHDL keywords.")
4986
4987 (defvar vhdl-types nil
4988 "List of VHDL standardized types.")
4989
4990 (defvar vhdl-attributes nil
4991 "List of VHDL standardized attributes.")
4992
4993 (defvar vhdl-enum-values nil
4994 "List of VHDL standardized enumeration values.")
4995
4996 (defvar vhdl-constants nil
4997 "List of VHDL standardized constants.")
4998
4999 (defvar vhdl-functions nil
5000 "List of VHDL standardized functions.")
5001
5002 (defvar vhdl-packages nil
5003 "List of VHDL standardized packages and libraries.")
5004
5005 (defvar vhdl-reserved-words nil
5006 "List of additional reserved words.")
5007
5008 (defvar vhdl-keywords-regexp nil
5009 "Regexp for VHDL keywords.")
5010
5011 (defvar vhdl-types-regexp nil
5012 "Regexp for VHDL standardized types.")
5013
5014 (defvar vhdl-attributes-regexp nil
5015 "Regexp for VHDL standardized attributes.")
5016
5017 (defvar vhdl-enum-values-regexp nil
5018 "Regexp for VHDL standardized enumeration values.")
5019
5020 (defvar vhdl-functions-regexp nil
5021 "Regexp for VHDL standardized functions.")
5022
5023 (defvar vhdl-packages-regexp nil
5024 "Regexp for VHDL standardized packages and libraries.")
5025
5026 (defvar vhdl-reserved-words-regexp nil
5027 "Regexp for additional reserved words.")
5028
5029 (defvar vhdl-directive-keywords-regexp nil
5030 "Regexp for compiler directive keywords.")
5031
5032 (defun vhdl-words-init ()
5033 "Initialize reserved words."
5034 (setq vhdl-keywords
5035 (append vhdl-93-keywords
5036 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5037 (setq vhdl-types
5038 (append vhdl-93-types
5039 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5040 (when (vhdl-standard-p 'math) vhdl-math-types)))
5041 (setq vhdl-attributes
5042 (append vhdl-93-attributes
5043 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5044 (setq vhdl-enum-values
5045 (append vhdl-93-enum-values
5046 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5047 (setq vhdl-constants
5048 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5049 (setq vhdl-functions
5050 (append vhdl-93-functions
5051 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5052 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5053 (setq vhdl-packages
5054 (append vhdl-93-packages
5055 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5056 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5057 (setq vhdl-reserved-words
5058 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5059 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5060 '("")))
5061 (setq vhdl-keywords-regexp
5062 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5063 (setq vhdl-types-regexp
5064 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5065 (setq vhdl-attributes-regexp
5066 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5067 (setq vhdl-enum-values-regexp
5068 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5069 (setq vhdl-functions-regexp
5070 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5071 (setq vhdl-packages-regexp
5072 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5073 (setq vhdl-reserved-words-regexp
5074 (concat "\\<\\("
5075 (unless (equal vhdl-forbidden-syntax "")
5076 (concat vhdl-forbidden-syntax "\\|"))
5077 (regexp-opt vhdl-reserved-words)
5078 "\\)\\>"))
5079 (setq vhdl-directive-keywords-regexp
5080 (concat "\\<\\(" (mapconcat 'regexp-quote
5081 vhdl-directive-keywords "\\|") "\\)\\>"))
5082 (vhdl-abbrev-list-init))
5083
5084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5085 ;; Words to expand
5086
5087 (defvar vhdl-abbrev-list nil
5088 "Predefined abbreviations for VHDL.")
5089
5090 (defun vhdl-abbrev-list-init ()
5091 (setq vhdl-abbrev-list
5092 (append
5093 (list vhdl-upper-case-keywords) vhdl-keywords
5094 (list vhdl-upper-case-types) vhdl-types
5095 (list vhdl-upper-case-attributes) vhdl-attributes
5096 (list vhdl-upper-case-enum-values) vhdl-enum-values
5097 (list vhdl-upper-case-constants) vhdl-constants
5098 (list nil) vhdl-functions
5099 (list nil) vhdl-packages)))
5100
5101 ;; initialize reserved words for VHDL Mode
5102 (vhdl-words-init)
5103
5104
5105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5106 ;;; Indentation
5107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5108
5109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5110 ;; Syntax analysis
5111
5112 ;; constant regular expressions for looking at various constructs
5113
5114 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5115 "Regexp describing a VHDL symbol.
5116 We cannot use just `word' syntax class since `_' cannot be in word
5117 class. Putting underscore in word class breaks forward word movement
5118 behavior that users are familiar with.")
5119
5120 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5121 "Regexp describing a case statement header key.")
5122
5123 (defconst vhdl-label-key
5124 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5125 "Regexp describing a VHDL label.")
5126
5127 ;; Macro definitions:
5128
5129 (defmacro vhdl-point (position)
5130 "Return the value of point at certain commonly referenced POSITIONs.
5131 POSITION can be one of the following symbols:
5132
5133 bol -- beginning of line
5134 eol -- end of line
5135 bod -- beginning of defun
5136 boi -- back to indentation
5137 eoi -- last whitespace on line
5138 ionl -- indentation of next line
5139 iopl -- indentation of previous line
5140 bonl -- beginning of next line
5141 bopl -- beginning of previous line
5142
5143 This function does not modify point or mark."
5144 (or (and (eq 'quote (car-safe position))
5145 (null (cddr position)))
5146 (error "ERROR: Bad buffer position requested: %s" position))
5147 (setq position (nth 1 position))
5148 `(let ((here (point)))
5149 ,@(cond
5150 ((eq position 'bol) '((beginning-of-line)))
5151 ((eq position 'eol) '((end-of-line)))
5152 ((eq position 'bod) '((save-match-data
5153 (vhdl-beginning-of-defun))))
5154 ((eq position 'boi) '((back-to-indentation)))
5155 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5156 ((eq position 'bonl) '((forward-line 1)))
5157 ((eq position 'bopl) '((forward-line -1)))
5158 ((eq position 'iopl)
5159 '((forward-line -1)
5160 (back-to-indentation)))
5161 ((eq position 'ionl)
5162 '((forward-line 1)
5163 (back-to-indentation)))
5164 (t (error "ERROR: Unknown buffer position requested: %s" position))
5165 )
5166 (prog1
5167 (point)
5168 (goto-char here))
5169 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5170 ;; doesn't hurt for v19
5171 ,@nil
5172 ))
5173
5174 (defmacro vhdl-safe (&rest body)
5175 "Safely execute BODY, return nil if an error occurred."
5176 `(condition-case nil
5177 (progn ,@body)
5178 (error nil)))
5179
5180 (defmacro vhdl-add-syntax (symbol &optional relpos)
5181 "A simple macro to append the syntax in SYMBOL to the syntax list.
5182 Try to increase performance by using this macro."
5183 `(setq vhdl-syntactic-context
5184 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5185
5186 (defmacro vhdl-has-syntax (symbol)
5187 "A simple macro to return check the syntax list.
5188 Try to increase performance by using this macro."
5189 `(assoc ,symbol vhdl-syntactic-context))
5190
5191 ;; Syntactic element offset manipulation:
5192
5193 (defun vhdl-read-offset (langelem)
5194 "Read new offset value for LANGELEM from minibuffer.
5195 Return a valid value only."
5196 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5197 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5198 (prompt "Offset: ")
5199 offset input interned)
5200 (while (not offset)
5201 (setq input (read-string prompt oldoff)
5202 offset (cond ((string-equal "+" input) '+)
5203 ((string-equal "-" input) '-)
5204 ((string-equal "++" input) '++)
5205 ((string-equal "--" input) '--)
5206 ((string-match "^-?[0-9]+$" input)
5207 (string-to-number input))
5208 ((fboundp (setq interned (intern input)))
5209 interned)
5210 ((boundp interned) interned)
5211 ;; error, but don't signal one, keep trying
5212 ;; to read an input value
5213 (t (ding)
5214 (setq prompt errmsg)
5215 nil))))
5216 offset))
5217
5218 (defun vhdl-set-offset (symbol offset &optional add-p)
5219 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5220 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5221 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5222 `vhdl-offsets-alist' if it doesn't already appear there."
5223 (interactive
5224 (let* ((langelem
5225 (intern (completing-read
5226 (concat "Syntactic symbol to change"
5227 (if current-prefix-arg " or add" "")
5228 ": ")
5229 (mapcar
5230 (function
5231 (lambda (langelem)
5232 (cons (format "%s" (car langelem)) nil)))
5233 vhdl-offsets-alist)
5234 nil (not current-prefix-arg)
5235 ;; initial contents tries to be the last element
5236 ;; on the syntactic analysis list for the current
5237 ;; line
5238 (let* ((syntax (vhdl-get-syntactic-context))
5239 (len (length syntax))
5240 (ic (format "%s" (car (nth (1- len) syntax)))))
5241 ic)
5242 )))
5243 (offset (vhdl-read-offset langelem)))
5244 (list langelem offset current-prefix-arg)))
5245 ;; sanity check offset
5246 (or (eq offset '+)
5247 (eq offset '-)
5248 (eq offset '++)
5249 (eq offset '--)
5250 (integerp offset)
5251 (fboundp offset)
5252 (boundp offset)
5253 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5254 offset))
5255 (let ((entry (assq symbol vhdl-offsets-alist)))
5256 (if entry
5257 (setcdr entry offset)
5258 (if add-p
5259 (setq vhdl-offsets-alist
5260 (cons (cons symbol offset) vhdl-offsets-alist))
5261 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5262 (vhdl-keep-region-active))
5263
5264 (defun vhdl-set-style (style &optional local)
5265 "Set `vhdl-mode' variables to use one of several different indentation styles.
5266 STYLE is a string representing the desired style and optional LOCAL is
5267 a flag which, if non-nil, means to make the style variables being
5268 changed buffer local, instead of the default, which is to set the
5269 global variables. Interactively, the flag comes from the prefix
5270 argument. The styles are chosen from the `vhdl-style-alist' variable."
5271 (interactive (list (completing-read "Use which VHDL indentation style? "
5272 vhdl-style-alist nil t)
5273 current-prefix-arg))
5274 (let ((vars (cdr (assoc style vhdl-style-alist))))
5275 (or vars
5276 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5277 ;; set all the variables
5278 (mapc
5279 (function
5280 (lambda (varentry)
5281 (let ((var (car varentry))
5282 (val (cdr varentry)))
5283 (and local
5284 (make-local-variable var))
5285 ;; special case for vhdl-offsets-alist
5286 (if (not (eq var 'vhdl-offsets-alist))
5287 (set var val)
5288 ;; reset vhdl-offsets-alist to the default value first
5289 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5290 ;; now set the langelems that are different
5291 (mapcar
5292 (function
5293 (lambda (langentry)
5294 (let ((langelem (car langentry))
5295 (offset (cdr langentry)))
5296 (vhdl-set-offset langelem offset)
5297 )))
5298 val))
5299 )))
5300 vars))
5301 (vhdl-keep-region-active))
5302
5303 (defun vhdl-get-offset (langelem)
5304 "Get offset from LANGELEM which is a cons cell of the form:
5305 \(SYMBOL . RELPOS). The symbol is matched against
5306 vhdl-offsets-alist and the offset found there is either returned,
5307 or added to the indentation at RELPOS. If RELPOS is nil, then
5308 the offset is simply returned."
5309 (let* ((symbol (car langelem))
5310 (relpos (cdr langelem))
5311 (match (assq symbol vhdl-offsets-alist))
5312 (offset (cdr-safe match)))
5313 ;; offset can be a number, a function, a variable, or one of the
5314 ;; symbols + or -
5315 (cond
5316 ((not match)
5317 (if vhdl-strict-syntax-p
5318 (error "ERROR: Don't know how to indent a %s" symbol)
5319 (setq offset 0
5320 relpos 0)))
5321 ((eq offset '+) (setq offset vhdl-basic-offset))
5322 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5323 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5324 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5325 ((and (not (numberp offset))
5326 (fboundp offset))
5327 (setq offset (funcall offset langelem)))
5328 ((not (numberp offset))
5329 (setq offset (eval offset)))
5330 )
5331 (+ (if (and relpos
5332 (< relpos (vhdl-point 'bol)))
5333 (save-excursion
5334 (goto-char relpos)
5335 (current-column))
5336 0)
5337 offset)))
5338
5339 ;; Syntactic support functions:
5340
5341 (defun vhdl-in-comment-p ()
5342 "Check if point is in a comment."
5343 (eq (vhdl-in-literal) 'comment))
5344
5345 (defun vhdl-in-string-p ()
5346 "Check if point is in a string."
5347 (eq (vhdl-in-literal) 'string))
5348
5349 (defun vhdl-in-literal ()
5350 "Determine if point is in a VHDL literal."
5351 (save-excursion
5352 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5353 (cond
5354 ((nth 3 state) 'string)
5355 ((nth 4 state) 'comment)
5356 ((vhdl-beginning-of-macro) 'pound)
5357 (t nil)))))
5358
5359 (defun vhdl-forward-comment (&optional direction)
5360 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5361 negative, skip forward otherwise."
5362 (interactive "p")
5363 (if (and direction (< direction 0))
5364 ;; skip backwards
5365 (progn
5366 (skip-chars-backward " \t\n")
5367 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5368 (goto-char (match-beginning 3))
5369 (skip-chars-backward " \t\n")))
5370 ;; skip forwards
5371 (skip-chars-forward " \t\n")
5372 (while (looking-at "--.*")
5373 (goto-char (match-end 0))
5374 (skip-chars-forward " \t\n"))))
5375
5376 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5377 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5378 (defalias 'vhdl-forward-comment 'forward-comment))
5379
5380 ;; This is the best we can do in Win-Emacs.
5381 (defun vhdl-win-il (&optional lim)
5382 "Determine if point is in a VHDL literal."
5383 (save-excursion
5384 (let* ((here (point))
5385 (state nil)
5386 (match nil)
5387 (lim (or lim (vhdl-point 'bod))))
5388 (goto-char lim )
5389 (while (< (point) here)
5390 (setq match
5391 (and (re-search-forward "--\\|[\"']"
5392 here 'move)
5393 (buffer-substring (match-beginning 0) (match-end 0))))
5394 (setq state
5395 (cond
5396 ;; no match
5397 ((null match) nil)
5398 ;; looking at the opening of a VHDL style comment
5399 ((string= "--" match)
5400 (if (<= here (progn (end-of-line) (point))) 'comment))
5401 ;; looking at the opening of a double quote string
5402 ((string= "\"" match)
5403 (if (not (save-restriction
5404 ;; this seems to be necessary since the
5405 ;; re-search-forward will not work without it
5406 (narrow-to-region (point) here)
5407 (re-search-forward
5408 ;; this regexp matches a double quote
5409 ;; which is preceded by an even number
5410 ;; of backslashes, including zero
5411 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5412 'string))
5413 ;; looking at the opening of a single quote string
5414 ((string= "'" match)
5415 (if (not (save-restriction
5416 ;; see comments from above
5417 (narrow-to-region (point) here)
5418 (re-search-forward
5419 ;; this matches a single quote which is
5420 ;; preceded by zero or two backslashes.
5421 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5422 here 'move)))
5423 'string))
5424 (t nil)))
5425 ) ; end-while
5426 state)))
5427
5428 (and (string-match "Win-Emacs" emacs-version)
5429 (fset 'vhdl-in-literal 'vhdl-win-il))
5430
5431 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5432 ;; defined as lexical whitespace or comments. Search no farther back
5433 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5434 ;; used for backward skipping, (point-max) is used for forward
5435 ;; skipping.
5436
5437 (defun vhdl-forward-syntactic-ws (&optional lim)
5438 "Forward skip of syntactic whitespace."
5439 (let* ((here (point-max))
5440 (hugenum (point-max)))
5441 (while (/= here (point))
5442 (setq here (point))
5443 (vhdl-forward-comment hugenum)
5444 ;; skip preprocessor directives
5445 (when (and (eq (char-after) ?#)
5446 (= (vhdl-point 'boi) (point)))
5447 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5448 (= (forward-line 1) 0)))
5449 (end-of-line)))
5450 (if lim (goto-char (min (point) lim)))))
5451
5452
5453 ;; This is the best we can do in Win-Emacs.
5454 (defun vhdl-win-fsws (&optional lim)
5455 "Forward skip syntactic whitespace for Win-Emacs."
5456 (let ((lim (or lim (point-max)))
5457 stop)
5458 (while (not stop)
5459 (skip-chars-forward " \t\n\r\f" lim)
5460 (cond
5461 ;; vhdl comment
5462 ((looking-at "--") (end-of-line))
5463 ;; none of the above
5464 (t (setq stop t))))))
5465
5466 (and (string-match "Win-Emacs" emacs-version)
5467 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5468
5469 (defun vhdl-beginning-of-macro (&optional lim)
5470 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5471 (let ((here (point)))
5472 (beginning-of-line)
5473 (while (eq (char-before (1- (point))) ?\\)
5474 (forward-line -1))
5475 (back-to-indentation)
5476 (if (and (<= (point) here)
5477 (eq (char-after) ?#))
5478 t
5479 (goto-char here)
5480 nil)))
5481
5482 (defun vhdl-backward-syntactic-ws (&optional lim)
5483 "Backward skip over syntactic whitespace."
5484 (let* ((here (point-min))
5485 (hugenum (- (point-max))))
5486 (while (/= here (point))
5487 (setq here (point))
5488 (vhdl-forward-comment hugenum)
5489 (vhdl-beginning-of-macro))
5490 (if lim (goto-char (max (point) lim)))))
5491
5492 ;; This is the best we can do in Win-Emacs.
5493 (defun vhdl-win-bsws (&optional lim)
5494 "Backward skip syntactic whitespace for Win-Emacs."
5495 (let ((lim (or lim (vhdl-point 'bod)))
5496 stop)
5497 (while (not stop)
5498 (skip-chars-backward " \t\n\r\f" lim)
5499 (cond
5500 ;; vhdl comment
5501 ((eq (vhdl-in-literal) 'comment)
5502 (skip-chars-backward "^-" lim)
5503 (skip-chars-backward "-" lim)
5504 (while (not (or (and (= (following-char) ?-)
5505 (= (char-after (1+ (point))) ?-))
5506 (<= (point) lim)))
5507 (skip-chars-backward "^-" lim)
5508 (skip-chars-backward "-" lim)))
5509 ;; none of the above
5510 (t (setq stop t))))))
5511
5512 (and (string-match "Win-Emacs" emacs-version)
5513 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5514
5515 ;; Functions to help finding the correct indentation column:
5516
5517 (defun vhdl-first-word (point)
5518 "If the keyword at POINT is at boi, then return (current-column) at
5519 that point, else nil."
5520 (save-excursion
5521 (and (goto-char point)
5522 (eq (point) (vhdl-point 'boi))
5523 (current-column))))
5524
5525 (defun vhdl-last-word (point)
5526 "If the keyword at POINT is at eoi, then return (current-column) at
5527 that point, else nil."
5528 (save-excursion
5529 (and (goto-char point)
5530 (save-excursion (or (eq (progn (forward-sexp) (point))
5531 (vhdl-point 'eoi))
5532 (looking-at "\\s-*\\(--\\)?")))
5533 (current-column))))
5534
5535 ;; Core syntactic evaluation functions:
5536
5537 (defconst vhdl-libunit-re
5538 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5539
5540 (defun vhdl-libunit-p ()
5541 (and
5542 (save-excursion
5543 (forward-sexp)
5544 (skip-chars-forward " \t\n")
5545 (not (looking-at "is\\b[^_]")))
5546 (save-excursion
5547 (backward-sexp)
5548 (and (not (looking-at "use\\b[^_]"))
5549 (progn
5550 (forward-sexp)
5551 (vhdl-forward-syntactic-ws)
5552 (/= (following-char) ?:))))
5553 ))
5554
5555 (defconst vhdl-defun-re
5556 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5557
5558 (defun vhdl-defun-p ()
5559 (save-excursion
5560 (if (looking-at "block\\|process\\|procedural")
5561 ;; "block", "process", "procedural":
5562 (save-excursion
5563 (backward-sexp)
5564 (not (looking-at "end\\s-+\\w")))
5565 ;; "architecture", "configuration", "entity",
5566 ;; "package", "procedure", "function":
5567 t)))
5568
5569 (defun vhdl-corresponding-defun ()
5570 "If the word at the current position corresponds to a \"defun\"
5571 keyword, then return a string that can be used to find the
5572 corresponding \"begin\" keyword, else return nil."
5573 (save-excursion
5574 (and (looking-at vhdl-defun-re)
5575 (vhdl-defun-p)
5576 (if (looking-at "block\\|process\\|procedural")
5577 ;; "block", "process". "procedural:
5578 (buffer-substring (match-beginning 0) (match-end 0))
5579 ;; "architecture", "configuration", "entity", "package",
5580 ;; "procedure", "function":
5581 "is"))))
5582
5583 (defconst vhdl-begin-fwd-re
5584 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5585 "A regular expression for searching forward that matches all known
5586 \"begin\" keywords.")
5587
5588 (defconst vhdl-begin-bwd-re
5589 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5590 "A regular expression for searching backward that matches all known
5591 \"begin\" keywords.")
5592
5593 (defun vhdl-begin-p (&optional lim)
5594 "Return t if we are looking at a real \"begin\" keyword.
5595 Assumes that the caller will make sure that we are looking at
5596 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5597 the middle of an identifier that just happens to contain a \"begin\"
5598 keyword."
5599 (cond
5600 ;; "[architecture|case|configuration|entity|package|
5601 ;; procedure|function] ... is":
5602 ((and (looking-at "i")
5603 (save-excursion
5604 ;; Skip backward over first sexp (needed to skip over a
5605 ;; procedure interface list, and is harmless in other
5606 ;; situations). Note that we need "return" in the
5607 ;; following search list so that we don't run into
5608 ;; semicolons in the function interface list.
5609 (backward-sexp)
5610 (let (foundp)
5611 (while (and (not foundp)
5612 (re-search-backward
5613 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5614 lim 'move))
5615 (if (or (= (preceding-char) ?_)
5616 (vhdl-in-literal))
5617 (backward-char)
5618 (setq foundp t))))
5619 (and (/= (following-char) ?\;)
5620 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5621 t)
5622 ;; "begin", "then":
5623 ((looking-at "be\\|t")
5624 t)
5625 ;; "else":
5626 ((and (looking-at "e")
5627 ;; make sure that the "else" isn't inside a
5628 ;; conditional signal assignment.
5629 (save-excursion
5630 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5631 (or (eq (following-char) ?\;)
5632 (eq (point) lim))))
5633 t)
5634 ;; "block", "generate", "loop", "process", "procedural",
5635 ;; "units", "record":
5636 ((and (looking-at "bl\\|[glpur]")
5637 (save-excursion
5638 (backward-sexp)
5639 (not (looking-at "end\\s-+\\w"))))
5640 t)
5641 ;; "component":
5642 ((and (looking-at "c")
5643 (save-excursion
5644 (backward-sexp)
5645 (not (looking-at "end\\s-+\\w")))
5646 ;; look out for the dreaded entity class in an attribute
5647 (save-excursion
5648 (vhdl-backward-syntactic-ws lim)
5649 (/= (preceding-char) ?:)))
5650 t)
5651 ;; "for" (inside configuration declaration):
5652 ((and (looking-at "f")
5653 (save-excursion
5654 (backward-sexp)
5655 (not (looking-at "end\\s-+\\w")))
5656 (vhdl-has-syntax 'configuration))
5657 t)
5658 ))
5659
5660 (defun vhdl-corresponding-mid (&optional lim)
5661 (cond
5662 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5663 "begin")
5664 ((looking-at "then")
5665 "<else>")
5666 (t
5667 "end")))
5668
5669 (defun vhdl-corresponding-end (&optional lim)
5670 "If the word at the current position corresponds to a \"begin\"
5671 keyword, then return a vector containing enough information to find
5672 the corresponding \"end\" keyword, else return nil. The keyword to
5673 search forward for is aref 0. The column in which the keyword must
5674 appear is aref 1 or nil if any column is suitable.
5675 Assumes that the caller will make sure that we are not in the middle
5676 of an identifier that just happens to contain a \"begin\" keyword."
5677 (save-excursion
5678 (and (looking-at vhdl-begin-fwd-re)
5679 (/= (preceding-char) ?_)
5680 (not (vhdl-in-literal))
5681 (vhdl-begin-p lim)
5682 (cond
5683 ;; "is", "generate", "loop":
5684 ((looking-at "[igl]")
5685 (vector "end"
5686 (and (vhdl-last-word (point))
5687 (or (vhdl-first-word (point))
5688 (save-excursion
5689 (vhdl-beginning-of-statement-1 lim)
5690 (vhdl-backward-skip-label lim)
5691 (vhdl-first-word (point)))))))
5692 ;; "begin", "else", "for":
5693 ((looking-at "be\\|[ef]")
5694 (vector "end"
5695 (and (vhdl-last-word (point))
5696 (or (vhdl-first-word (point))
5697 (save-excursion
5698 (vhdl-beginning-of-statement-1 lim)
5699 (vhdl-backward-skip-label lim)
5700 (vhdl-first-word (point)))))))
5701 ;; "component", "units", "record":
5702 ((looking-at "[cur]")
5703 ;; The first end found will close the block
5704 (vector "end" nil))
5705 ;; "block", "process", "procedural":
5706 ((looking-at "bl\\|p")
5707 (vector "end"
5708 (or (vhdl-first-word (point))
5709 (save-excursion
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point))))))
5713 ;; "then":
5714 ((looking-at "t")
5715 (vector "elsif\\|else\\|end\\s-+if"
5716 (and (vhdl-last-word (point))
5717 (or (vhdl-first-word (point))
5718 (save-excursion
5719 (vhdl-beginning-of-statement-1 lim)
5720 (vhdl-backward-skip-label lim)
5721 (vhdl-first-word (point)))))))
5722 ))))
5723
5724 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5725
5726 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5727
5728 (defun vhdl-end-p (&optional lim)
5729 "Return t if we are looking at a real \"end\" keyword.
5730 Assumes that the caller will make sure that we are looking at
5731 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5732 the middle of an identifier that just happens to contain an \"end\"
5733 keyword."
5734 (or (not (looking-at "else"))
5735 ;; make sure that the "else" isn't inside a conditional signal
5736 ;; assignment.
5737 (save-excursion
5738 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5739 (or (eq (following-char) ?\;)
5740 (eq (point) lim)
5741 (vhdl-in-literal)))))
5742
5743 (defun vhdl-corresponding-begin (&optional lim)
5744 "If the word at the current position corresponds to an \"end\"
5745 keyword, then return a vector containing enough information to find
5746 the corresponding \"begin\" keyword, else return nil. The keyword to
5747 search backward for is aref 0. The column in which the keyword must
5748 appear is aref 1 or nil if any column is suitable. The supplementary
5749 keyword to search forward for is aref 2 or nil if this is not
5750 required. If aref 3 is t, then the \"begin\" keyword may be found in
5751 the middle of a statement.
5752 Assumes that the caller will make sure that we are not in the middle
5753 of an identifier that just happens to contain an \"end\" keyword."
5754 (save-excursion
5755 (let (pos)
5756 (if (and (looking-at vhdl-end-fwd-re)
5757 (not (vhdl-in-literal))
5758 (vhdl-end-p lim))
5759 (if (looking-at "el")
5760 ;; "else", "elsif":
5761 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5762 ;; "end ...":
5763 (setq pos (point))
5764 (forward-sexp)
5765 (skip-chars-forward " \t\n")
5766 (cond
5767 ;; "end if":
5768 ((looking-at "if\\b[^_]")
5769 (vector "else\\|elsif\\|if"
5770 (vhdl-first-word pos)
5771 "else\\|then" nil))
5772 ;; "end component":
5773 ((looking-at "component\\b[^_]")
5774 (vector (buffer-substring (match-beginning 1)
5775 (match-end 1))
5776 (vhdl-first-word pos)
5777 nil nil))
5778 ;; "end units", "end record":
5779 ((looking-at "\\(units\\|record\\)\\b[^_]")
5780 (vector (buffer-substring (match-beginning 1)
5781 (match-end 1))
5782 (vhdl-first-word pos)
5783 nil t))
5784 ;; "end block", "end process", "end procedural":
5785 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5786 (vector "begin" (vhdl-first-word pos) nil nil))
5787 ;; "end case":
5788 ((looking-at "case\\b[^_]")
5789 (vector "case" (vhdl-first-word pos) "is" nil))
5790 ;; "end generate":
5791 ((looking-at "generate\\b[^_]")
5792 (vector "generate\\|for\\|if"
5793 (vhdl-first-word pos)
5794 "generate" nil))
5795 ;; "end loop":
5796 ((looking-at "loop\\b[^_]")
5797 (vector "loop\\|while\\|for"
5798 (vhdl-first-word pos)
5799 "loop" nil))
5800 ;; "end for" (inside configuration declaration):
5801 ((looking-at "for\\b[^_]")
5802 (vector "for" (vhdl-first-word pos) nil nil))
5803 ;; "end [id]":
5804 (t
5805 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5806 (vhdl-first-word pos)
5807 ;; return an alist of (statement . keyword) mappings
5808 '(
5809 ;; "begin ... end [id]":
5810 ("begin" . nil)
5811 ;; "architecture ... is ... begin ... end [id]":
5812 ("architecture" . "is")
5813 ;; "configuration ... is ... end [id]":
5814 ("configuration" . "is")
5815 ;; "entity ... is ... end [id]":
5816 ("entity" . "is")
5817 ;; "package ... is ... end [id]":
5818 ("package" . "is")
5819 ;; "procedure ... is ... begin ... end [id]":
5820 ("procedure" . "is")
5821 ;; "function ... is ... begin ... end [id]":
5822 ("function" . "is")
5823 )
5824 nil))
5825 ))) ; "end ..."
5826 )))
5827
5828 (defconst vhdl-leader-re
5829 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5830
5831 (defun vhdl-end-of-leader ()
5832 (save-excursion
5833 (cond ((looking-at "block\\|process\\|procedural")
5834 (if (save-excursion
5835 (forward-sexp)
5836 (skip-chars-forward " \t\n")
5837 (= (following-char) ?\())
5838 (forward-sexp 2)
5839 (forward-sexp))
5840 (when (looking-at "[ \t\n]*is")
5841 (goto-char (match-end 0)))
5842 (point))
5843 ((looking-at "component")
5844 (forward-sexp 2)
5845 (when (looking-at "[ \t\n]*is")
5846 (goto-char (match-end 0)))
5847 (point))
5848 ((looking-at "for")
5849 (forward-sexp 2)
5850 (skip-chars-forward " \t\n")
5851 (while (looking-at "[,:(]")
5852 (forward-sexp)
5853 (skip-chars-forward " \t\n"))
5854 (point))
5855 (t nil)
5856 )))
5857
5858 (defconst vhdl-trailer-re
5859 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5860
5861 (defconst vhdl-statement-fwd-re
5862 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5863 "A regular expression for searching forward that matches all known
5864 \"statement\" keywords.")
5865
5866 (defconst vhdl-statement-bwd-re
5867 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5868 "A regular expression for searching backward that matches all known
5869 \"statement\" keywords.")
5870
5871 (defun vhdl-statement-p (&optional lim)
5872 "Return t if we are looking at a real \"statement\" keyword.
5873 Assumes that the caller will make sure that we are looking at
5874 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5875 in the middle of an identifier that just happens to contain a
5876 \"statement\" keyword."
5877 (cond
5878 ;; "for" ... "generate":
5879 ((and (looking-at "f")
5880 ;; Make sure it's the start of a parameter specification.
5881 (save-excursion
5882 (forward-sexp 2)
5883 (skip-chars-forward " \t\n")
5884 (looking-at "in\\b[^_]"))
5885 ;; Make sure it's not an "end for".
5886 (save-excursion
5887 (backward-sexp)
5888 (not (looking-at "end\\s-+\\w"))))
5889 t)
5890 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5891 ((and (looking-at "i")
5892 ;; Make sure it's not an "end if".
5893 (save-excursion
5894 (backward-sexp)
5895 (not (looking-at "end\\s-+\\w"))))
5896 t)
5897 ;; "while" ... "loop":
5898 ((looking-at "w")
5899 t)
5900 ))
5901
5902 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5903 "Regexp describing a case statement alternative key.")
5904
5905 (defun vhdl-case-alternative-p (&optional lim)
5906 "Return t if we are looking at a real case alternative.
5907 Assumes that the caller will make sure that we are looking at
5908 vhdl-case-alternative-re, and are not inside a literal, and that
5909 we are not in the middle of an identifier that just happens to
5910 contain a \"when\" keyword."
5911 (save-excursion
5912 (let (foundp)
5913 (while (and (not foundp)
5914 (re-search-backward ";\\|<=" lim 'move))
5915 (if (or (= (preceding-char) ?_)
5916 (vhdl-in-literal))
5917 (backward-char)
5918 (setq foundp t)))
5919 (or (eq (following-char) ?\;)
5920 (eq (point) lim)))
5921 ))
5922
5923 ;; Core syntactic movement functions:
5924
5925 (defconst vhdl-b-t-b-re
5926 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5927
5928 (defun vhdl-backward-to-block (&optional lim)
5929 "Move backward to the previous \"begin\" or \"end\" keyword."
5930 (let (foundp)
5931 (while (and (not foundp)
5932 (re-search-backward vhdl-b-t-b-re lim 'move))
5933 (if (or (= (preceding-char) ?_)
5934 (vhdl-in-literal))
5935 (backward-char)
5936 (cond
5937 ;; "begin" keyword:
5938 ((and (looking-at vhdl-begin-fwd-re)
5939 (/= (preceding-char) ?_)
5940 (vhdl-begin-p lim))
5941 (setq foundp 'begin))
5942 ;; "end" keyword:
5943 ((and (looking-at vhdl-end-fwd-re)
5944 (/= (preceding-char) ?_)
5945 (vhdl-end-p lim))
5946 (setq foundp 'end))
5947 ))
5948 )
5949 foundp
5950 ))
5951
5952 (defun vhdl-forward-sexp (&optional count lim)
5953 "Move forward across one balanced expression (sexp).
5954 With COUNT, do it that many times."
5955 (interactive "p")
5956 (let ((count (or count 1))
5957 (case-fold-search t)
5958 end-vec target)
5959 (save-excursion
5960 (while (> count 0)
5961 ;; skip whitespace
5962 (skip-chars-forward " \t\n")
5963 ;; Check for an unbalanced "end" keyword
5964 (if (and (looking-at vhdl-end-fwd-re)
5965 (/= (preceding-char) ?_)
5966 (not (vhdl-in-literal))
5967 (vhdl-end-p lim)
5968 (not (looking-at "else")))
5969 (error
5970 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5971 ;; If the current keyword is a "begin" keyword, then find the
5972 ;; corresponding "end" keyword.
5973 (if (setq end-vec (vhdl-corresponding-end lim))
5974 (let (
5975 ;; end-re is the statement keyword to search for
5976 (end-re
5977 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5978 ;; column is either the statement keyword target column
5979 ;; or nil
5980 (column (aref end-vec 1))
5981 (eol (vhdl-point 'eol))
5982 foundp literal placeholder)
5983 ;; Look for the statement keyword.
5984 (while (and (not foundp)
5985 (re-search-forward end-re nil t)
5986 (setq placeholder (match-end 1))
5987 (goto-char (match-beginning 0)))
5988 ;; If we are in a literal, or not in the right target
5989 ;; column and not on the same line as the begin, then
5990 ;; try again.
5991 (if (or (and column
5992 (/= (current-indentation) column)
5993 (> (point) eol))
5994 (= (preceding-char) ?_)
5995 (setq literal (vhdl-in-literal)))
5996 (if (eq literal 'comment)
5997 (end-of-line)
5998 (forward-char))
5999 ;; An "else" keyword corresponds to both the opening brace
6000 ;; of the following sexp and the closing brace of the
6001 ;; previous sexp.
6002 (if (not (looking-at "else"))
6003 (goto-char placeholder))
6004 (setq foundp t))
6005 )
6006 (if (not foundp)
6007 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6008 )
6009 ;; If the current keyword is not a "begin" keyword, then just
6010 ;; perform the normal forward-sexp.
6011 (forward-sexp)
6012 )
6013 (setq count (1- count))
6014 )
6015 (setq target (point)))
6016 (goto-char target)
6017 nil))
6018
6019 (defun vhdl-backward-sexp (&optional count lim)
6020 "Move backward across one balanced expression (sexp).
6021 With COUNT, do it that many times. LIM bounds any required backward
6022 searches."
6023 (interactive "p")
6024 (let ((count (or count 1))
6025 (case-fold-search t)
6026 begin-vec target)
6027 (save-excursion
6028 (while (> count 0)
6029 ;; Perform the normal backward-sexp, unless we are looking at
6030 ;; "else" - an "else" keyword corresponds to both the opening brace
6031 ;; of the following sexp and the closing brace of the previous sexp.
6032 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6033 (/= (preceding-char) ?_)
6034 (not (vhdl-in-literal)))
6035 nil
6036 (backward-sexp)
6037 (if (and (looking-at vhdl-begin-fwd-re)
6038 (/= (preceding-char) ?_)
6039 (not (vhdl-in-literal))
6040 (vhdl-begin-p lim))
6041 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6042 ;; If the current keyword is an "end" keyword, then find the
6043 ;; corresponding "begin" keyword.
6044 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6045 (/= (preceding-char) ?_))
6046 (let (
6047 ;; begin-re is the statement keyword to search for
6048 (begin-re
6049 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6050 ;; column is either the statement keyword target column
6051 ;; or nil
6052 (column (aref begin-vec 1))
6053 ;; internal-p controls where the statement keyword can
6054 ;; be found.
6055 (internal-p (aref begin-vec 3))
6056 (last-backward (point)) last-forward
6057 foundp literal keyword)
6058 ;; Look for the statement keyword.
6059 (while (and (not foundp)
6060 (re-search-backward begin-re lim t)
6061 (setq keyword
6062 (buffer-substring (match-beginning 1)
6063 (match-end 1))))
6064 ;; If we are in a literal or in the wrong column,
6065 ;; then try again.
6066 (if (or (and column
6067 (and (/= (current-indentation) column)
6068 ;; possibly accept current-column as
6069 ;; well as current-indentation.
6070 (or (not internal-p)
6071 (/= (current-column) column))))
6072 (= (preceding-char) ?_)
6073 (vhdl-in-literal))
6074 (backward-char)
6075 ;; If there is a supplementary keyword, then
6076 ;; search forward for it.
6077 (if (and (setq begin-re (aref begin-vec 2))
6078 (or (not (listp begin-re))
6079 ;; If begin-re is an alist, then find the
6080 ;; element corresponding to the actual
6081 ;; keyword that we found.
6082 (progn
6083 (setq begin-re
6084 (assoc keyword begin-re))
6085 (and begin-re
6086 (setq begin-re (cdr begin-re))))))
6087 (and
6088 (setq begin-re
6089 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6090 (save-excursion
6091 (setq last-forward (point))
6092 ;; Look for the supplementary keyword
6093 ;; (bounded by the backward search start
6094 ;; point).
6095 (while (and (not foundp)
6096 (re-search-forward begin-re
6097 last-backward t)
6098 (goto-char (match-beginning 1)))
6099 ;; If we are in a literal, then try again.
6100 (if (or (= (preceding-char) ?_)
6101 (setq literal
6102 (vhdl-in-literal)))
6103 (if (eq literal 'comment)
6104 (goto-char
6105 (min (vhdl-point 'eol) last-backward))
6106 (forward-char))
6107 ;; We have found the supplementary keyword.
6108 ;; Save the position of the keyword in foundp.
6109 (setq foundp (point)))
6110 )
6111 foundp)
6112 ;; If the supplementary keyword was found, then
6113 ;; move point to the supplementary keyword.
6114 (goto-char foundp))
6115 ;; If there was no supplementary keyword, then
6116 ;; point is already at the statement keyword.
6117 (setq foundp t)))
6118 ) ; end of the search for the statement keyword
6119 (if (not foundp)
6120 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6121 ))
6122 (setq count (1- count))
6123 )
6124 (setq target (point)))
6125 (goto-char target)
6126 nil))
6127
6128 (defun vhdl-backward-up-list (&optional count limit)
6129 "Move backward out of one level of blocks.
6130 With argument, do this that many times."
6131 (interactive "p")
6132 (let ((count (or count 1))
6133 target)
6134 (save-excursion
6135 (while (> count 0)
6136 (if (looking-at vhdl-defun-re)
6137 (error "ERROR: Unbalanced blocks"))
6138 (vhdl-backward-to-block limit)
6139 (setq count (1- count)))
6140 (setq target (point)))
6141 (goto-char target)))
6142
6143 (defun vhdl-end-of-defun (&optional count)
6144 "Move forward to the end of a VHDL defun."
6145 (interactive)
6146 (let ((case-fold-search t))
6147 (vhdl-beginning-of-defun)
6148 (if (not (looking-at "block\\|process\\|procedural"))
6149 (re-search-forward "\\bis\\b"))
6150 (vhdl-forward-sexp)))
6151
6152 (defun vhdl-mark-defun ()
6153 "Put mark at end of this \"defun\", point at beginning."
6154 (interactive)
6155 (let ((case-fold-search t))
6156 (push-mark)
6157 (vhdl-beginning-of-defun)
6158 (push-mark)
6159 (if (not (looking-at "block\\|process\\|procedural"))
6160 (re-search-forward "\\bis\\b"))
6161 (vhdl-forward-sexp)
6162 (exchange-point-and-mark)))
6163
6164 (defun vhdl-beginning-of-libunit ()
6165 "Move backward to the beginning of a VHDL library unit.
6166 Returns the location of the corresponding begin keyword, unless search
6167 stops due to beginning or end of buffer.
6168 Note that if point is between the \"libunit\" keyword and the
6169 corresponding \"begin\" keyword, then that libunit will not be
6170 recognized, and the search will continue backwards. If point is
6171 at the \"begin\" keyword, then the defun will be recognized. The
6172 returned point is at the first character of the \"libunit\" keyword."
6173 (let ((last-forward (point))
6174 (last-backward
6175 ;; Just in case we are actually sitting on the "begin"
6176 ;; keyword, allow for the keyword and an extra character,
6177 ;; as this will be used when looking forward for the
6178 ;; "begin" keyword.
6179 (save-excursion (forward-word 1) (1+ (point))))
6180 foundp literal placeholder)
6181 ;; Find the "libunit" keyword.
6182 (while (and (not foundp)
6183 (re-search-backward vhdl-libunit-re nil 'move))
6184 ;; If we are in a literal, or not at a real libunit, then try again.
6185 (if (or (= (preceding-char) ?_)
6186 (vhdl-in-literal)
6187 (not (vhdl-libunit-p)))
6188 (backward-char)
6189 ;; Find the corresponding "begin" keyword.
6190 (setq last-forward (point))
6191 (while (and (not foundp)
6192 (re-search-forward "\\bis\\b[^_]" last-backward t)
6193 (setq placeholder (match-beginning 0)))
6194 (if (or (= (preceding-char) ?_)
6195 (setq literal (vhdl-in-literal)))
6196 ;; It wasn't a real keyword, so keep searching.
6197 (if (eq literal 'comment)
6198 (goto-char
6199 (min (vhdl-point 'eol) last-backward))
6200 (forward-char))
6201 ;; We have found the begin keyword, loop will exit.
6202 (setq foundp placeholder)))
6203 ;; Go back to the libunit keyword
6204 (goto-char last-forward)))
6205 foundp))
6206
6207 (defun vhdl-beginning-of-defun (&optional count)
6208 "Move backward to the beginning of a VHDL defun.
6209 With argument, do it that many times.
6210 Returns the location of the corresponding begin keyword, unless search
6211 stops due to beginning or end of buffer."
6212 ;; Note that if point is between the "defun" keyword and the
6213 ;; corresponding "begin" keyword, then that defun will not be
6214 ;; recognized, and the search will continue backwards. If point is
6215 ;; at the "begin" keyword, then the defun will be recognized. The
6216 ;; returned point is at the first character of the "defun" keyword.
6217 (interactive "p")
6218 (let ((count (or count 1))
6219 (case-fold-search t)
6220 (last-forward (point))
6221 foundp)
6222 (while (> count 0)
6223 (setq foundp nil)
6224 (goto-char last-forward)
6225 (let ((last-backward
6226 ;; Just in case we are actually sitting on the "begin"
6227 ;; keyword, allow for the keyword and an extra character,
6228 ;; as this will be used when looking forward for the
6229 ;; "begin" keyword.
6230 (save-excursion (forward-word 1) (1+ (point))))
6231 begin-string literal)
6232 (while (and (not foundp)
6233 (re-search-backward vhdl-defun-re nil 'move))
6234 ;; If we are in a literal, then try again.
6235 (if (or (= (preceding-char) ?_)
6236 (vhdl-in-literal))
6237 (backward-char)
6238 (if (setq begin-string (vhdl-corresponding-defun))
6239 ;; This is a real defun keyword.
6240 ;; Find the corresponding "begin" keyword.
6241 ;; Look for the begin keyword.
6242 (progn
6243 ;; Save the search start point.
6244 (setq last-forward (point))
6245 (while (and (not foundp)
6246 (search-forward begin-string last-backward t))
6247 (if (or (= (preceding-char) ?_)
6248 (save-match-data
6249 (setq literal (vhdl-in-literal))))
6250 ;; It wasn't a real keyword, so keep searching.
6251 (if (eq literal 'comment)
6252 (goto-char
6253 (min (vhdl-point 'eol) last-backward))
6254 (forward-char))
6255 ;; We have found the begin keyword, loop will exit.
6256 (setq foundp (match-beginning 0)))
6257 )
6258 ;; Go back to the defun keyword
6259 (goto-char last-forward)) ; end search for begin keyword
6260 ))
6261 ) ; end of the search for the defun keyword
6262 )
6263 (setq count (1- count))
6264 )
6265 (vhdl-keep-region-active)
6266 foundp))
6267
6268 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6269 "Go to the beginning of the innermost VHDL statement.
6270 With prefix arg, go back N - 1 statements. If already at the
6271 beginning of a statement then go to the beginning of the preceding
6272 one. If within a string or comment, or next to a comment (only
6273 whitespace between), move by sentences instead of statements.
6274
6275 When called from a program, this function takes 3 optional args: the
6276 prefix arg, a buffer position limit which is the farthest back to
6277 search, and an argument indicating an interactive call."
6278 (interactive "p\np")
6279 (let ((count (or count 1))
6280 (case-fold-search t)
6281 (lim (or lim (point-min)))
6282 (here (point))
6283 state)
6284 (save-excursion
6285 (goto-char lim)
6286 (setq state (parse-partial-sexp (point) here nil nil)))
6287 (if (and interactive
6288 (or (nth 3 state)
6289 (nth 4 state)
6290 (looking-at (concat "[ \t]*" comment-start-skip))))
6291 (forward-sentence (- count))
6292 (while (> count 0)
6293 (vhdl-beginning-of-statement-1 lim)
6294 (setq count (1- count))))
6295 ;; its possible we've been left up-buf of lim
6296 (goto-char (max (point) lim))
6297 )
6298 (vhdl-keep-region-active))
6299
6300 (defconst vhdl-e-o-s-re
6301 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6302
6303 (defun vhdl-end-of-statement ()
6304 "Very simple implementation."
6305 (interactive)
6306 (re-search-forward vhdl-e-o-s-re))
6307
6308 (defconst vhdl-b-o-s-re
6309 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6310 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6311
6312 (defun vhdl-beginning-of-statement-1 (&optional lim)
6313 "Move to the start of the current statement, or the previous
6314 statement if already at the beginning of one."
6315 (let ((lim (or lim (point-min)))
6316 (here (point))
6317 (pos (point))
6318 donep)
6319 ;; go backwards one balanced expression, but be careful of
6320 ;; unbalanced paren being reached
6321 (if (not (vhdl-safe (progn (backward-sexp) t)))
6322 (progn
6323 (backward-up-list 1)
6324 (forward-char)
6325 (vhdl-forward-syntactic-ws here)
6326 (setq donep t)))
6327 (while (and (not donep)
6328 (not (bobp))
6329 ;; look backwards for a statement boundary
6330 (re-search-backward vhdl-b-o-s-re lim 'move))
6331 (if (or (= (preceding-char) ?_)
6332 (vhdl-in-literal))
6333 (backward-char)
6334 (cond
6335 ;; If we are looking at an open paren, then stop after it
6336 ((eq (following-char) ?\()
6337 (forward-char)
6338 (vhdl-forward-syntactic-ws here)
6339 (setq donep t))
6340 ;; If we are looking at a close paren, then skip it
6341 ((eq (following-char) ?\))
6342 (forward-char)
6343 (setq pos (point))
6344 (backward-sexp)
6345 (if (< (point) lim)
6346 (progn (goto-char pos)
6347 (vhdl-forward-syntactic-ws here)
6348 (setq donep t))))
6349 ;; If we are looking at a semicolon, then stop
6350 ((eq (following-char) ?\;)
6351 (progn
6352 (forward-char)
6353 (vhdl-forward-syntactic-ws here)
6354 (setq donep t)))
6355 ;; If we are looking at a "begin", then stop
6356 ((and (looking-at vhdl-begin-fwd-re)
6357 (/= (preceding-char) ?_)
6358 (vhdl-begin-p nil))
6359 ;; If it's a leader "begin", then find the
6360 ;; right place
6361 (if (looking-at vhdl-leader-re)
6362 (save-excursion
6363 ;; set a default stop point at the begin
6364 (setq pos (point))
6365 ;; is the start point inside the leader area ?
6366 (goto-char (vhdl-end-of-leader))
6367 (vhdl-forward-syntactic-ws here)
6368 (if (< (point) here)
6369 ;; start point was not inside leader area
6370 ;; set stop point at word after leader
6371 (setq pos (point))))
6372 (forward-word 1)
6373 (vhdl-forward-syntactic-ws here)
6374 (setq pos (point)))
6375 (goto-char pos)
6376 (setq donep t))
6377 ;; If we are looking at a "statement", then stop
6378 ((and (looking-at vhdl-statement-fwd-re)
6379 (/= (preceding-char) ?_)
6380 (vhdl-statement-p nil))
6381 (setq donep t))
6382 ;; If we are looking at a case alternative key, then stop
6383 ((and (looking-at vhdl-case-alternative-re)
6384 (vhdl-case-alternative-p lim))
6385 (save-excursion
6386 ;; set a default stop point at the when
6387 (setq pos (point))
6388 ;; is the start point inside the case alternative key ?
6389 (looking-at vhdl-case-alternative-re)
6390 (goto-char (match-end 0))
6391 (vhdl-forward-syntactic-ws here)
6392 (if (< (point) here)
6393 ;; start point was not inside the case alternative key
6394 ;; set stop point at word after case alternative keyleader
6395 (setq pos (point))))
6396 (goto-char pos)
6397 (setq donep t))
6398 ;; Bogus find, continue
6399 (t
6400 (backward-char)))))
6401 ))
6402
6403 ;; Defuns for calculating the current syntactic state:
6404
6405 (defun vhdl-get-library-unit (bod placeholder)
6406 "If there is an enclosing library unit at BOD, with its \"begin\"
6407 keyword at PLACEHOLDER, then return the library unit type."
6408 (let ((here (vhdl-point 'bol)))
6409 (if (save-excursion
6410 (goto-char placeholder)
6411 (vhdl-safe (vhdl-forward-sexp 1 bod))
6412 (<= here (point)))
6413 (save-excursion
6414 (goto-char bod)
6415 (cond
6416 ((looking-at "e") 'entity)
6417 ((looking-at "a") 'architecture)
6418 ((looking-at "c") 'configuration)
6419 ((looking-at "p")
6420 (save-excursion
6421 (goto-char bod)
6422 (forward-sexp)
6423 (vhdl-forward-syntactic-ws here)
6424 (if (looking-at "body\\b[^_]")
6425 'package-body 'package))))))
6426 ))
6427
6428 (defun vhdl-get-block-state (&optional lim)
6429 "Finds and records all the closest opens.
6430 LIM is the furthest back we need to search (it should be the
6431 previous libunit keyword)."
6432 (let ((here (point))
6433 (lim (or lim (point-min)))
6434 keyword sexp-start sexp-mid sexp-end
6435 preceding-sexp containing-sexp
6436 containing-begin containing-mid containing-paren)
6437 (save-excursion
6438 ;; Find the containing-paren, and use that as the limit
6439 (if (setq containing-paren
6440 (save-restriction
6441 (narrow-to-region lim (point))
6442 (vhdl-safe (scan-lists (point) -1 1))))
6443 (setq lim containing-paren))
6444 ;; Look backwards for "begin" and "end" keywords.
6445 (while (and (> (point) lim)
6446 (not containing-sexp))
6447 (setq keyword (vhdl-backward-to-block lim))
6448 (cond
6449 ((eq keyword 'begin)
6450 ;; Found a "begin" keyword
6451 (setq sexp-start (point))
6452 (setq sexp-mid (vhdl-corresponding-mid lim))
6453 (setq sexp-end (vhdl-safe
6454 (save-excursion
6455 (vhdl-forward-sexp 1 lim) (point))))
6456 (if (and sexp-end (<= sexp-end here))
6457 ;; we want to record this sexp, but we only want to
6458 ;; record the last-most of any of them before here
6459 (or preceding-sexp
6460 (setq preceding-sexp sexp-start))
6461 ;; we're contained in this sexp so put sexp-start on
6462 ;; front of list
6463 (setq containing-sexp sexp-start)
6464 (setq containing-mid sexp-mid)
6465 (setq containing-begin t)))
6466 ((eq keyword 'end)
6467 ;; Found an "end" keyword
6468 (forward-sexp)
6469 (setq sexp-end (point))
6470 (setq sexp-mid nil)
6471 (setq sexp-start
6472 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6473 (progn (backward-sexp) (point))))
6474 ;; we want to record this sexp, but we only want to
6475 ;; record the last-most of any of them before here
6476 (or preceding-sexp
6477 (setq preceding-sexp sexp-start)))
6478 )))
6479 ;; Check if the containing-paren should be the containing-sexp
6480 (if (and containing-paren
6481 (or (null containing-sexp)
6482 (< containing-sexp containing-paren)))
6483 (setq containing-sexp containing-paren
6484 preceding-sexp nil
6485 containing-begin nil
6486 containing-mid nil))
6487 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6488 ))
6489
6490
6491 (defconst vhdl-s-c-a-re
6492 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6493
6494 (defun vhdl-skip-case-alternative (&optional lim)
6495 "Skip forward over case/when bodies, with optional maximal
6496 limit. If no next case alternative is found, nil is returned and
6497 point is not moved."
6498 (let ((lim (or lim (point-max)))
6499 (here (point))
6500 donep foundp)
6501 (while (and (< (point) lim)
6502 (not donep))
6503 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6504 (save-match-data
6505 (not (vhdl-in-literal)))
6506 (/= (match-beginning 0) here))
6507 (progn
6508 (goto-char (match-beginning 0))
6509 (cond
6510 ((and (looking-at "case")
6511 (re-search-forward "\\bis[^_]" lim t))
6512 (backward-sexp)
6513 (vhdl-forward-sexp))
6514 (t
6515 (setq donep t
6516 foundp t))))))
6517 (if (not foundp)
6518 (goto-char here))
6519 foundp))
6520
6521 (defun vhdl-backward-skip-label (&optional lim)
6522 "Skip backward over a label, with optional maximal
6523 limit. If label is not found, nil is returned and point
6524 is not moved."
6525 (let ((lim (or lim (point-min)))
6526 placeholder)
6527 (if (save-excursion
6528 (vhdl-backward-syntactic-ws lim)
6529 (and (eq (preceding-char) ?:)
6530 (progn
6531 (backward-sexp)
6532 (setq placeholder (point))
6533 (looking-at vhdl-label-key))))
6534 (goto-char placeholder))
6535 ))
6536
6537 (defun vhdl-forward-skip-label (&optional lim)
6538 "Skip forward over a label, with optional maximal
6539 limit. If label is not found, nil is returned and point
6540 is not moved."
6541 (let ((lim (or lim (point-max))))
6542 (if (looking-at vhdl-label-key)
6543 (progn
6544 (goto-char (match-end 0))
6545 (vhdl-forward-syntactic-ws lim)))
6546 ))
6547
6548 (defun vhdl-get-syntactic-context ()
6549 "Guess the syntactic description of the current line of VHDL code."
6550 (save-excursion
6551 (save-restriction
6552 (beginning-of-line)
6553 (let* ((indent-point (point))
6554 (case-fold-search t)
6555 vec literal containing-sexp preceding-sexp
6556 containing-begin containing-mid containing-leader
6557 char-before-ip char-after-ip begin-after-ip end-after-ip
6558 placeholder lim library-unit
6559 )
6560
6561 ;; Reset the syntactic context
6562 (setq vhdl-syntactic-context nil)
6563
6564 (save-excursion
6565 ;; Move to the start of the previous library unit, and
6566 ;; record the position of the "begin" keyword.
6567 (setq placeholder (vhdl-beginning-of-libunit))
6568 ;; The position of the "libunit" keyword gives us a gross
6569 ;; limit point.
6570 (setq lim (point))
6571 )
6572
6573 ;; If there is a previous library unit, and we are enclosed by
6574 ;; it, then set the syntax accordingly.
6575 (and placeholder
6576 (setq library-unit (vhdl-get-library-unit lim placeholder))
6577 (vhdl-add-syntax library-unit lim))
6578
6579 ;; Find the surrounding state.
6580 (if (setq vec (vhdl-get-block-state lim))
6581 (progn
6582 (setq containing-sexp (aref vec 0))
6583 (setq preceding-sexp (aref vec 1))
6584 (setq containing-begin (aref vec 2))
6585 (setq containing-mid (aref vec 3))
6586 ))
6587
6588 ;; set the limit on the farthest back we need to search
6589 (setq lim (if containing-sexp
6590 (save-excursion
6591 (goto-char containing-sexp)
6592 ;; set containing-leader if required
6593 (if (looking-at vhdl-leader-re)
6594 (setq containing-leader (vhdl-end-of-leader)))
6595 (vhdl-point 'bol))
6596 (point-min)))
6597
6598 ;; cache char before and after indent point, and move point to
6599 ;; the most likely position to perform the majority of tests
6600 (goto-char indent-point)
6601 (skip-chars-forward " \t")
6602 (setq literal (vhdl-in-literal))
6603 (setq char-after-ip (following-char))
6604 (setq begin-after-ip (and
6605 (not literal)
6606 (looking-at vhdl-begin-fwd-re)
6607 (vhdl-begin-p)))
6608 (setq end-after-ip (and
6609 (not literal)
6610 (looking-at vhdl-end-fwd-re)
6611 (vhdl-end-p)))
6612 (vhdl-backward-syntactic-ws lim)
6613 (setq char-before-ip (preceding-char))
6614 (goto-char indent-point)
6615 (skip-chars-forward " \t")
6616
6617 ;; now figure out syntactic qualities of the current line
6618 (cond
6619 ;; CASE 1: in a string or comment.
6620 ((memq literal '(string comment))
6621 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6622 ;; CASE 2: Line is at top level.
6623 ((null containing-sexp)
6624 ;; Find the point to which indentation will be relative
6625 (save-excursion
6626 (if (null preceding-sexp)
6627 ;; CASE 2X.1
6628 ;; no preceding-sexp -> use the preceding statement
6629 (vhdl-beginning-of-statement-1 lim)
6630 ;; CASE 2X.2
6631 ;; if there is a preceding-sexp then indent relative to it
6632 (goto-char preceding-sexp)
6633 ;; if not at boi, then the block-opening keyword is
6634 ;; probably following a label, so we need a different
6635 ;; relpos
6636 (if (/= (point) (vhdl-point 'boi))
6637 ;; CASE 2X.3
6638 (vhdl-beginning-of-statement-1 lim)))
6639 ;; v-b-o-s could have left us at point-min
6640 (and (bobp)
6641 ;; CASE 2X.4
6642 (vhdl-forward-syntactic-ws indent-point))
6643 (setq placeholder (point)))
6644 (cond
6645 ;; CASE 2A : we are looking at a block-open
6646 (begin-after-ip
6647 (vhdl-add-syntax 'block-open placeholder))
6648 ;; CASE 2B: we are looking at a block-close
6649 (end-after-ip
6650 (vhdl-add-syntax 'block-close placeholder))
6651 ;; CASE 2C: we are looking at a top-level statement
6652 ((progn
6653 (vhdl-backward-syntactic-ws lim)
6654 (or (bobp)
6655 (= (preceding-char) ?\;)))
6656 (vhdl-add-syntax 'statement placeholder))
6657 ;; CASE 2D: we are looking at a top-level statement-cont
6658 (t
6659 (vhdl-beginning-of-statement-1 lim)
6660 ;; v-b-o-s could have left us at point-min
6661 (and (bobp)
6662 ;; CASE 2D.1
6663 (vhdl-forward-syntactic-ws indent-point))
6664 (vhdl-add-syntax 'statement-cont (point)))
6665 )) ; end CASE 2
6666 ;; CASE 3: line is inside parentheses. Most likely we are
6667 ;; either in a subprogram argument (interface) list, or a
6668 ;; continued expression containing parentheses.
6669 ((null containing-begin)
6670 (vhdl-backward-syntactic-ws containing-sexp)
6671 (cond
6672 ;; CASE 3A: we are looking at the arglist closing paren
6673 ((eq char-after-ip ?\))
6674 (goto-char containing-sexp)
6675 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6676 ;; CASE 3B: we are looking at the first argument in an empty
6677 ;; argument list.
6678 ((eq char-before-ip ?\()
6679 (goto-char containing-sexp)
6680 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6681 ;; CASE 3C: we are looking at an arglist continuation line,
6682 ;; but the preceding argument is on the same line as the
6683 ;; opening paren. This case includes multi-line
6684 ;; expression paren groupings.
6685 ((and (save-excursion
6686 (goto-char (1+ containing-sexp))
6687 (skip-chars-forward " \t")
6688 (not (eolp))
6689 (not (looking-at "--")))
6690 (save-excursion
6691 (vhdl-beginning-of-statement-1 containing-sexp)
6692 (skip-chars-backward " \t(")
6693 (<= (point) containing-sexp)))
6694 (goto-char containing-sexp)
6695 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6696 ;; CASE 3D: we are looking at just a normal arglist
6697 ;; continuation line
6698 (t (vhdl-beginning-of-statement-1 containing-sexp)
6699 (vhdl-forward-syntactic-ws indent-point)
6700 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6701 ))
6702 ;; CASE 4: A block mid open
6703 ((and begin-after-ip
6704 (looking-at containing-mid))
6705 (goto-char containing-sexp)
6706 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6707 (if (looking-at vhdl-trailer-re)
6708 ;; CASE 4.1
6709 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6710 (vhdl-backward-skip-label (vhdl-point 'boi))
6711 (vhdl-add-syntax 'block-open (point)))
6712 ;; CASE 5: block close brace
6713 (end-after-ip
6714 (goto-char containing-sexp)
6715 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6716 (if (looking-at vhdl-trailer-re)
6717 ;; CASE 5.1
6718 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6719 (vhdl-backward-skip-label (vhdl-point 'boi))
6720 (vhdl-add-syntax 'block-close (point)))
6721 ;; CASE 6: A continued statement
6722 ((and (/= char-before-ip ?\;)
6723 ;; check it's not a trailer begin keyword, or a begin
6724 ;; keyword immediately following a label.
6725 (not (and begin-after-ip
6726 (or (looking-at vhdl-trailer-re)
6727 (save-excursion
6728 (vhdl-backward-skip-label containing-sexp)))))
6729 ;; check it's not a statement keyword
6730 (not (and (looking-at vhdl-statement-fwd-re)
6731 (vhdl-statement-p)))
6732 ;; see if the b-o-s is before the indent point
6733 (> indent-point
6734 (save-excursion
6735 (vhdl-beginning-of-statement-1 containing-sexp)
6736 ;; If we ended up after a leader, then this will
6737 ;; move us forward to the start of the first
6738 ;; statement. Note that a containing sexp here is
6739 ;; always a keyword, not a paren, so this will
6740 ;; have no effect if we hit the containing-sexp.
6741 (vhdl-forward-syntactic-ws indent-point)
6742 (setq placeholder (point))))
6743 ;; check it's not a block-intro
6744 (/= placeholder containing-sexp)
6745 ;; check it's not a case block-intro
6746 (save-excursion
6747 (goto-char placeholder)
6748 (or (not (looking-at vhdl-case-alternative-re))
6749 (> (match-end 0) indent-point))))
6750 ;; Make placeholder skip a label, but only if it puts us
6751 ;; before the indent point at the start of a line.
6752 (let ((new placeholder))
6753 (if (and (> indent-point
6754 (save-excursion
6755 (goto-char placeholder)
6756 (vhdl-forward-skip-label indent-point)
6757 (setq new (point))))
6758 (save-excursion
6759 (goto-char new)
6760 (eq new (progn (back-to-indentation) (point)))))
6761 (setq placeholder new)))
6762 (vhdl-add-syntax 'statement-cont placeholder)
6763 (if begin-after-ip
6764 (vhdl-add-syntax 'block-open)))
6765 ;; Statement. But what kind?
6766 ;; CASE 7: A case alternative key
6767 ((and (looking-at vhdl-case-alternative-re)
6768 (vhdl-case-alternative-p containing-sexp))
6769 ;; for a case alternative key, we set relpos to the first
6770 ;; non-whitespace char on the line containing the "case"
6771 ;; keyword.
6772 (goto-char containing-sexp)
6773 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6774 (if (looking-at vhdl-trailer-re)
6775 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6776 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6777 ;; CASE 8: statement catchall
6778 (t
6779 ;; we know its a statement, but we need to find out if it is
6780 ;; the first statement in a block
6781 (if containing-leader
6782 (goto-char containing-leader)
6783 (goto-char containing-sexp)
6784 ;; Note that a containing sexp here is always a keyword,
6785 ;; not a paren, so skip over the keyword.
6786 (forward-sexp))
6787 ;; move to the start of the first statement
6788 (vhdl-forward-syntactic-ws indent-point)
6789 (setq placeholder (point))
6790 ;; we want to ignore case alternatives keys when skipping forward
6791 (let (incase-p)
6792 (while (looking-at vhdl-case-alternative-re)
6793 (setq incase-p (point))
6794 ;; we also want to skip over the body of the
6795 ;; case/when statement if that doesn't put us at
6796 ;; after the indent-point
6797 (while (vhdl-skip-case-alternative indent-point))
6798 ;; set up the match end
6799 (looking-at vhdl-case-alternative-re)
6800 (goto-char (match-end 0))
6801 ;; move to the start of the first case alternative statement
6802 (vhdl-forward-syntactic-ws indent-point)
6803 (setq placeholder (point)))
6804 (cond
6805 ;; CASE 8A: we saw a case/when statement so we must be
6806 ;; in a switch statement. find out if we are at the
6807 ;; statement just after a case alternative key
6808 ((and incase-p
6809 (= (point) indent-point))
6810 ;; relpos is the "when" keyword
6811 (vhdl-add-syntax 'statement-case-intro incase-p))
6812 ;; CASE 8B: any old statement
6813 ((< (point) indent-point)
6814 ;; relpos is the first statement of the block
6815 (vhdl-add-syntax 'statement placeholder)
6816 (if begin-after-ip
6817 (vhdl-add-syntax 'block-open)))
6818 ;; CASE 8C: first statement in a block
6819 (t
6820 (goto-char containing-sexp)
6821 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6822 (if (looking-at vhdl-trailer-re)
6823 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6824 (vhdl-backward-skip-label (vhdl-point 'boi))
6825 (vhdl-add-syntax 'statement-block-intro (point))
6826 (if begin-after-ip
6827 (vhdl-add-syntax 'block-open)))
6828 )))
6829 )
6830
6831 ;; now we need to look at any modifiers
6832 (goto-char indent-point)
6833 (skip-chars-forward " \t")
6834 (if (looking-at "--")
6835 (vhdl-add-syntax 'comment))
6836 (if (eq literal 'pound)
6837 (vhdl-add-syntax 'cpp-macro))
6838 ;; return the syntax
6839 vhdl-syntactic-context))))
6840
6841 ;; Standard indentation line-ups:
6842
6843 (defun vhdl-lineup-arglist (langelem)
6844 "Lineup the current arglist line with the arglist appearing just
6845 after the containing paren which starts the arglist."
6846 (save-excursion
6847 (let* ((containing-sexp
6848 (save-excursion
6849 ;; arglist-cont-nonempty gives relpos ==
6850 ;; to boi of containing-sexp paren. This
6851 ;; is good when offset is +, but bad
6852 ;; when it is vhdl-lineup-arglist, so we
6853 ;; have to special case a kludge here.
6854 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6855 (progn
6856 (beginning-of-line)
6857 (backward-up-list 1)
6858 (skip-chars-forward " \t" (vhdl-point 'eol)))
6859 (goto-char (cdr langelem)))
6860 (point)))
6861 (cs-curcol (save-excursion
6862 (goto-char (cdr langelem))
6863 (current-column))))
6864 (if (save-excursion
6865 (beginning-of-line)
6866 (looking-at "[ \t]*)"))
6867 (progn (goto-char (match-end 0))
6868 (backward-sexp)
6869 (forward-char)
6870 (vhdl-forward-syntactic-ws)
6871 (- (current-column) cs-curcol))
6872 (goto-char containing-sexp)
6873 (or (eolp)
6874 (let ((eol (vhdl-point 'eol))
6875 (here (progn
6876 (forward-char)
6877 (skip-chars-forward " \t")
6878 (point))))
6879 (vhdl-forward-syntactic-ws)
6880 (if (< (point) eol)
6881 (goto-char here))))
6882 (- (current-column) cs-curcol)
6883 ))))
6884
6885 (defun vhdl-lineup-arglist-intro (langelem)
6886 "Lineup an arglist-intro line to just after the open paren."
6887 (save-excursion
6888 (let ((cs-curcol (save-excursion
6889 (goto-char (cdr langelem))
6890 (current-column)))
6891 (ce-curcol (save-excursion
6892 (beginning-of-line)
6893 (backward-up-list 1)
6894 (skip-chars-forward " \t" (vhdl-point 'eol))
6895 (current-column))))
6896 (- ce-curcol cs-curcol -1))))
6897
6898 (defun vhdl-lineup-comment (langelem)
6899 "Support old behavior for comment indentation. We look at
6900 vhdl-comment-only-line-offset to decide how to indent comment
6901 only-lines."
6902 (save-excursion
6903 (back-to-indentation)
6904 ;; at or to the right of comment-column
6905 (if (>= (current-column) comment-column)
6906 (vhdl-comment-indent)
6907 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6908 (if (not (bolp))
6909 (or (car-safe vhdl-comment-only-line-offset)
6910 vhdl-comment-only-line-offset)
6911 (or (cdr-safe vhdl-comment-only-line-offset)
6912 (car-safe vhdl-comment-only-line-offset)
6913 -1000 ;jam it against the left side
6914 )))))
6915
6916 (defun vhdl-lineup-statement-cont (langelem)
6917 "Line up statement-cont after the assignment operator."
6918 (save-excursion
6919 (let* ((relpos (cdr langelem))
6920 (assignp (save-excursion
6921 (goto-char (vhdl-point 'boi))
6922 (and (re-search-forward "\\(<\\|:\\)="
6923 (vhdl-point 'eol) t)
6924 (- (point) (vhdl-point 'boi)))))
6925 (curcol (progn
6926 (goto-char relpos)
6927 (current-column)))
6928 foundp)
6929 (while (and (not foundp)
6930 (< (point) (vhdl-point 'eol)))
6931 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6932 (if (vhdl-in-literal)
6933 (forward-char)
6934 (if (= (preceding-char) ?\()
6935 ;; skip over any parenthesized expressions
6936 (goto-char (min (vhdl-point 'eol)
6937 (scan-lists (point) 1 1)))
6938 ;; found an assignment operator (not at eol)
6939 (setq foundp (not (looking-at "\\s-*$"))))))
6940 (if (not foundp)
6941 ;; there's no assignment operator on the line
6942 vhdl-basic-offset
6943 ;; calculate indentation column after assign and ws, unless
6944 ;; our line contains an assignment operator
6945 (if (not assignp)
6946 (progn
6947 (forward-char)
6948 (skip-chars-forward " \t")
6949 (setq assignp 0)))
6950 (- (current-column) assignp curcol))
6951 )))
6952
6953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6954 ;; Progress reporting
6955
6956 (defvar vhdl-progress-info nil
6957 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6958
6959 (defun vhdl-update-progress-info (string pos)
6960 "Update progress information."
6961 (when (and vhdl-progress-info (not noninteractive)
6962 (< vhdl-progress-interval
6963 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6964 (let ((delta (- (aref vhdl-progress-info 1)
6965 (aref vhdl-progress-info 0))))
6966 (if (= 0 delta)
6967 (message (concat string "... (100%s)") "%")
6968 (message (concat string "... (%2d%s)")
6969 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6970 delta) "%")))
6971 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6972
6973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6974 ;; Indentation commands
6975
6976 (defun vhdl-electric-tab (&optional prefix-arg)
6977 "If preceding character is part of a word or a paren then hippie-expand,
6978 else if right of non whitespace on line then insert tab,
6979 else if last command was a tab or return then dedent one step or if a comment
6980 toggle between normal indent and inline comment indent,
6981 else indent `correctly'."
6982 (interactive "*P")
6983 (vhdl-prepare-search-2
6984 (cond
6985 ;; indent region if region is active
6986 ((and (not (featurep 'xemacs)) (use-region-p))
6987 (vhdl-indent-region (region-beginning) (region-end) nil))
6988 ;; expand word
6989 ((= (char-syntax (preceding-char)) ?w)
6990 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6991 (case-replace nil)
6992 (hippie-expand-only-buffers
6993 (or (and (boundp 'hippie-expand-only-buffers)
6994 hippie-expand-only-buffers)
6995 '(vhdl-mode))))
6996 (vhdl-expand-abbrev prefix-arg)))
6997 ;; expand parenthesis
6998 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6999 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7000 (case-replace nil))
7001 (vhdl-expand-paren prefix-arg)))
7002 ;; insert tab
7003 ((> (current-column) (current-indentation))
7004 (insert-tab))
7005 ;; toggle comment indent
7006 ((and (looking-at "--")
7007 (or (eq last-command 'vhdl-electric-tab)
7008 (eq last-command 'vhdl-electric-return)))
7009 (cond ((= (current-indentation) 0) ; no indent
7010 (indent-to 1)
7011 (indent-according-to-mode))
7012 ((< (current-indentation) comment-column) ; normal indent
7013 (indent-to comment-column)
7014 (indent-according-to-mode))
7015 (t ; inline comment indent
7016 (delete-region (line-beginning-position) (point)))))
7017 ;; dedent
7018 ((and (>= (current-indentation) vhdl-basic-offset)
7019 (or (eq last-command 'vhdl-electric-tab)
7020 (eq last-command 'vhdl-electric-return)))
7021 (backward-delete-char-untabify vhdl-basic-offset nil))
7022 ;; indent line
7023 (t (indent-according-to-mode)))
7024 (setq this-command 'vhdl-electric-tab)))
7025
7026 (defun vhdl-electric-return ()
7027 "newline-and-indent or indent-new-comment-line if in comment and preceding
7028 character is a space."
7029 (interactive)
7030 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7031 (indent-new-comment-line)
7032 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7033 (vhdl-fix-case-word -1))
7034 (newline-and-indent)))
7035
7036 (defun vhdl-indent-line ()
7037 "Indent the current line as VHDL code. Returns the amount of
7038 indentation change."
7039 (interactive)
7040 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7041 (pos (- (point-max) (point)))
7042 (indent
7043 (if syntax
7044 ;; indent syntax-based
7045 (if (and (eq (caar syntax) 'comment)
7046 (>= (vhdl-get-offset (car syntax)) comment-column))
7047 ;; special case: comments at or right of comment-column
7048 (vhdl-get-offset (car syntax))
7049 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7050 ;; indent like previous nonblank line
7051 (save-excursion (beginning-of-line)
7052 (re-search-backward "^[^\n]" nil t)
7053 (current-indentation))))
7054 (shift-amt (- indent (current-indentation))))
7055 (and vhdl-echo-syntactic-information-p
7056 (message "syntax: %s, indent= %d" syntax indent))
7057 (unless (zerop shift-amt)
7058 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7059 (beginning-of-line)
7060 (indent-to indent))
7061 (if (< (point) (vhdl-point 'boi))
7062 (back-to-indentation)
7063 ;; If initial point was within line's indentation, position after
7064 ;; the indentation. Else stay at same point in text.
7065 (when (> (- (point-max) pos) (point))
7066 (goto-char (- (point-max) pos))))
7067 (run-hooks 'vhdl-special-indent-hook)
7068 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7069 shift-amt))
7070
7071 (defun vhdl-indent-region (beg end column)
7072 "Indent region as VHDL code.
7073 Adds progress reporting to `indent-region'."
7074 (interactive "r\nP")
7075 (when vhdl-progress-interval
7076 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7077 (count-lines (point-min) end) 0)))
7078 (indent-region beg end column)
7079 (when vhdl-progress-interval (message "Indenting...done"))
7080 (setq vhdl-progress-info nil))
7081
7082 (defun vhdl-indent-buffer ()
7083 "Indent whole buffer as VHDL code.
7084 Calls `indent-region' for whole buffer and adds progress reporting."
7085 (interactive)
7086 (vhdl-indent-region (point-min) (point-max) nil))
7087
7088 (defun vhdl-indent-group ()
7089 "Indent group of lines between empty lines."
7090 (interactive)
7091 (let ((beg (save-excursion
7092 (if (re-search-backward vhdl-align-group-separate nil t)
7093 (point-marker)
7094 (point-min-marker))))
7095 (end (save-excursion
7096 (if (re-search-forward vhdl-align-group-separate nil t)
7097 (point-marker)
7098 (point-max-marker)))))
7099 (vhdl-indent-region beg end nil)))
7100
7101 (defun vhdl-indent-sexp (&optional endpos)
7102 "Indent each line of the list starting just after point.
7103 If optional arg ENDPOS is given, indent each line, stopping when
7104 ENDPOS is encountered."
7105 (interactive)
7106 (save-excursion
7107 (let ((beg (point))
7108 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7109 (indent-region beg end nil))))
7110
7111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7112 ;; Miscellaneous commands
7113
7114 (defun vhdl-show-syntactic-information ()
7115 "Show syntactic information for current line."
7116 (interactive)
7117 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7118 (vhdl-keep-region-active))
7119
7120 ;; Verification and regression functions:
7121
7122 (defun vhdl-regress-line (&optional arg)
7123 "Check syntactic information for current line."
7124 (interactive "P")
7125 (let ((expected (save-excursion
7126 (end-of-line)
7127 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7128 (forward-char 4)
7129 (read (current-buffer)))))
7130 (actual (vhdl-get-syntactic-context))
7131 (expurgated))
7132 ;; remove the library unit symbols
7133 (mapc
7134 (function
7135 (lambda (elt)
7136 (if (memq (car elt) '(entity configuration package
7137 package-body architecture))
7138 nil
7139 (setq expurgated (append expurgated (list elt))))))
7140 actual)
7141 (if (and (not arg) expected (listp expected))
7142 (if (not (equal expected expurgated))
7143 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7144 (save-excursion
7145 (beginning-of-line)
7146 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7147 (end-of-line)
7148 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7149 (delete-region (point) (line-end-position)))
7150 (insert " -- ")
7151 (insert (format "%s" expurgated))))))
7152 (vhdl-keep-region-active))
7153
7154
7155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7156 ;;; Alignment, whitespace fixup, beautifying
7157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7158
7159 (defconst vhdl-align-alist
7160 '(
7161 ;; after some keywords
7162 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7163 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7164 ;; before ':'
7165 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7166 ;; after direction specifications
7167 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7168 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7169 ;; before "==", ":=", "=>", and "<="
7170 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7171 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7172 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7173 ;; before some keywords
7174 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7175 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7176 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7177 ;; before "=>" since "when/else ... =>" can occur
7178 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7179 )
7180 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7181 It is searched in order. If REGEXP is found anywhere in the first
7182 line of a region to be aligned, ALIGN-PATTERN will be used for that
7183 region. ALIGN-PATTERN must include the whitespace to be expanded or
7184 contracted. It may also provide regexps for the text surrounding the
7185 whitespace. SUBEXP specifies which sub-expression of
7186 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7187
7188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7189 ;; Align code
7190
7191 (defvar vhdl-align-try-all-clauses t
7192 "If REGEXP is not found on the first line of the region that clause
7193 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7194
7195 (defun vhdl-do-group (function &optional spacing)
7196 "Apply FUNCTION on group of lines between empty lines."
7197 (let
7198 ;; search for group beginning
7199 ((beg (save-excursion
7200 (if (re-search-backward vhdl-align-group-separate nil t)
7201 (progn (beginning-of-line 2) (back-to-indentation) (point))
7202 (point-min))))
7203 ;; search for group end
7204 (end (save-excursion
7205 (if (re-search-forward vhdl-align-group-separate nil t)
7206 (progn (beginning-of-line) (point))
7207 (point-max)))))
7208 ;; run FUNCTION
7209 (funcall function beg end spacing)))
7210
7211 (defun vhdl-do-list (function &optional spacing)
7212 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7213 parentheses."
7214 (let (beg end)
7215 (save-excursion
7216 ;; search for beginning of balanced group of parentheses
7217 (setq beg (vhdl-re-search-backward "[()]" nil t))
7218 (while (looking-at ")")
7219 (forward-char) (backward-sexp)
7220 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7221 ;; search for end of balanced group of parentheses
7222 (when beg
7223 (forward-list)
7224 (setq end (point))
7225 (goto-char (1+ beg))
7226 (skip-chars-forward " \t\n")
7227 (setq beg (point))))
7228 ;; run FUNCTION
7229 (if beg
7230 (funcall function beg end spacing)
7231 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7232
7233 (defun vhdl-do-same-indent (function &optional spacing)
7234 "Apply FUNCTION to block of lines with same indent."
7235 (let ((indent (current-indentation))
7236 beg end)
7237 ;; search for first line with same indent
7238 (save-excursion
7239 (while (and (not (bobp))
7240 (or (looking-at "^\\s-*\\(--.*\\)?$")
7241 (= (current-indentation) indent)))
7242 (unless (looking-at "^\\s-*$")
7243 (back-to-indentation) (setq beg (point)))
7244 (beginning-of-line -0)))
7245 ;; search for last line with same indent
7246 (save-excursion
7247 (while (and (not (eobp))
7248 (or (looking-at "^\\s-*\\(--.*\\)?$")
7249 (= (current-indentation) indent)))
7250 (if (looking-at "^\\s-*$")
7251 (beginning-of-line 2)
7252 (beginning-of-line 2)
7253 (setq end (point)))))
7254 ;; run FUNCTION
7255 (funcall function beg end spacing)))
7256
7257 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7258 "Attempt to align a range of lines based on the content of the
7259 lines. The definition of `alignment-list' determines the matching
7260 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7261 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7262 indentation is done before aligning."
7263 (interactive "r\np")
7264 (setq alignment-list (or alignment-list vhdl-align-alist))
7265 (setq spacing (or spacing 1))
7266 (save-excursion
7267 (let (bol indent)
7268 (goto-char end)
7269 (setq end (point-marker))
7270 (goto-char begin)
7271 (setq bol (setq begin (progn (beginning-of-line) (point))))
7272 ; (untabify bol end)
7273 (when indent
7274 (indent-region bol end nil))))
7275 (let ((copy (copy-alist alignment-list)))
7276 (vhdl-prepare-search-2
7277 (while copy
7278 (save-excursion
7279 (goto-char begin)
7280 (let (element
7281 (eol (save-excursion (progn (end-of-line) (point)))))
7282 (setq element (nth 0 copy))
7283 (when (and (or (and (listp (car element))
7284 (memq major-mode (car element)))
7285 (eq major-mode (car element)))
7286 (or vhdl-align-try-all-clauses
7287 (re-search-forward (car (cdr element)) eol t)))
7288 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7289 (car (cdr (cdr (cdr element)))) spacing))
7290 (setq copy (cdr copy))))))))
7291
7292 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7293 "Align a range of lines from BEGIN to END. The regular expression
7294 MATCH must match exactly one field: the whitespace to be
7295 contracted/expanded. The alignment column will equal the
7296 rightmost column of the widest whitespace block. SPACING is
7297 the amount of extra spaces to add to the calculated maximum required.
7298 SPACING defaults to 1 so that at least one space is inserted after
7299 the token in MATCH."
7300 (setq spacing (or spacing 1))
7301 (setq substr (or substr 1))
7302 (save-excursion
7303 (let (distance (max 0) (lines 0) bol eol width)
7304 ;; Determine the greatest whitespace distance to the alignment
7305 ;; character
7306 (goto-char begin)
7307 (setq eol (progn (end-of-line) (point))
7308 bol (setq begin (progn (beginning-of-line) (point))))
7309 (while (< bol end)
7310 (save-excursion
7311 (when (and (re-search-forward match eol t)
7312 (not (vhdl-in-literal)))
7313 (setq distance (- (match-beginning substr) bol))
7314 (when (> distance max)
7315 (setq max distance))))
7316 (forward-line)
7317 (setq bol (point)
7318 eol (save-excursion (end-of-line) (point)))
7319 (setq lines (1+ lines)))
7320 ;; Now insert enough maxs to push each assignment operator to
7321 ;; the same column. We need to use 'lines' as a counter, since
7322 ;; the location of the mark may change
7323 (goto-char (setq bol begin))
7324 (setq eol (save-excursion (end-of-line) (point)))
7325 (while (> lines 0)
7326 (when (and (re-search-forward match eol t)
7327 (not (vhdl-in-literal)))
7328 (setq width (- (match-end substr) (match-beginning substr)))
7329 (setq distance (- (match-beginning substr) bol))
7330 (goto-char (match-beginning substr))
7331 (delete-char width)
7332 (insert-char ? (+ (- max distance) spacing)))
7333 (beginning-of-line)
7334 (forward-line)
7335 (setq bol (point)
7336 eol (save-excursion (end-of-line) (point)))
7337 (setq lines (1- lines))))))
7338
7339 (defun vhdl-align-region-groups (beg end &optional spacing
7340 no-message no-comments)
7341 "Align region, treat groups of lines separately."
7342 (interactive "r\nP")
7343 (save-excursion
7344 (let (orig pos)
7345 (goto-char beg)
7346 (beginning-of-line)
7347 (setq orig (point-marker))
7348 (setq beg (point))
7349 (goto-char end)
7350 (setq end (point-marker))
7351 (untabify beg end)
7352 (unless no-message
7353 (when vhdl-progress-interval
7354 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7355 (count-lines (point-min) end) 0))))
7356 (vhdl-fixup-whitespace-region beg end t)
7357 (goto-char beg)
7358 (if (not vhdl-align-groups)
7359 ;; align entire region
7360 (progn (vhdl-align-region-1 beg end spacing)
7361 (unless no-comments
7362 (vhdl-align-inline-comment-region-1 beg end)))
7363 ;; align groups
7364 (while (and (< beg end)
7365 (re-search-forward vhdl-align-group-separate end t))
7366 (setq pos (point-marker))
7367 (vhdl-align-region-1 beg pos spacing)
7368 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7369 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7370 (setq beg (1+ pos))
7371 (goto-char beg))
7372 ;; align last group
7373 (when (< beg end)
7374 (vhdl-align-region-1 beg end spacing)
7375 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7376 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7377 (when vhdl-indent-tabs-mode
7378 (tabify orig end))
7379 (unless no-message
7380 (when vhdl-progress-interval (message "Aligning...done"))
7381 (setq vhdl-progress-info nil)))))
7382
7383 (defun vhdl-align-region (beg end &optional spacing)
7384 "Align region, treat blocks with same indent and argument lists separately."
7385 (interactive "r\nP")
7386 (if (not vhdl-align-same-indent)
7387 ;; align entire region
7388 (vhdl-align-region-groups beg end spacing)
7389 ;; align blocks with same indent and argument lists
7390 (save-excursion
7391 (let ((cur-beg beg)
7392 indent cur-end)
7393 (when vhdl-progress-interval
7394 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7395 (count-lines (point-min) end) 0)))
7396 (goto-char end)
7397 (setq end (point-marker))
7398 (goto-char cur-beg)
7399 (while (< (point) end)
7400 ;; is argument list opening?
7401 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7402 (point) (vhdl-point 'eol)))))
7403 ;; determine region for argument list
7404 (progn (goto-char cur-beg)
7405 (forward-sexp)
7406 (setq cur-end (point))
7407 (beginning-of-line 2))
7408 ;; determine region with same indent
7409 (setq indent (current-indentation))
7410 (setq cur-beg (point))
7411 (setq cur-end (vhdl-point 'bonl))
7412 (beginning-of-line 2)
7413 (while (and (< (point) end)
7414 (or (looking-at "^\\s-*\\(--.*\\)?$")
7415 (= (current-indentation) indent))
7416 (<= (save-excursion
7417 (nth 0 (parse-partial-sexp
7418 (point) (vhdl-point 'eol)))) 0))
7419 (unless (looking-at "^\\s-*$")
7420 (setq cur-end (vhdl-point 'bonl)))
7421 (beginning-of-line 2)))
7422 ;; align region
7423 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7424 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7425 (when vhdl-progress-interval (message "Aligning...done"))
7426 (setq vhdl-progress-info nil)))))
7427
7428 (defun vhdl-align-group (&optional spacing)
7429 "Align group of lines between empty lines."
7430 (interactive)
7431 (vhdl-do-group 'vhdl-align-region spacing))
7432
7433 (defun vhdl-align-list (&optional spacing)
7434 "Align the lines of a list surrounded by a balanced group of parentheses."
7435 (interactive)
7436 (vhdl-do-list 'vhdl-align-region-groups spacing))
7437
7438 (defun vhdl-align-same-indent (&optional spacing)
7439 "Align block of lines with same indent."
7440 (interactive)
7441 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7442
7443 (defun vhdl-align-declarations (&optional spacing)
7444 "Align the lines within the declarative part of a design unit."
7445 (interactive)
7446 (let (beg end)
7447 (vhdl-prepare-search-2
7448 (save-excursion
7449 ;; search for declarative part
7450 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7451 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7452 (setq beg (point))
7453 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7454 (setq end (point)))))
7455 (if beg
7456 (vhdl-align-region-groups beg end spacing)
7457 (error "ERROR: Not within the declarative part of a design unit"))))
7458
7459 (defun vhdl-align-buffer ()
7460 "Align buffer."
7461 (interactive)
7462 (vhdl-align-region (point-min) (point-max)))
7463
7464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7465 ;; Align inline comments
7466
7467 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7468 "Align inline comments in region."
7469 (save-excursion
7470 (let ((start-max comment-column)
7471 (length-max 0)
7472 comment-list start-list tmp-list start length
7473 cur-start prev-start no-code)
7474 (setq spacing (or spacing 2))
7475 (vhdl-prepare-search-2
7476 (goto-char beg)
7477 ;; search for comment start positions and lengths
7478 (while (< (point) end)
7479 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7480 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7481 (not (save-excursion (goto-char (match-beginning 2))
7482 (vhdl-in-literal))))
7483 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7484 (setq length (- (match-end 2) (match-beginning 2)))
7485 (setq start-max (max start start-max))
7486 (setq length-max (max length length-max))
7487 (setq comment-list (cons (cons start length) comment-list)))
7488 (beginning-of-line 2))
7489 (setq comment-list
7490 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7491 ;; reduce start positions
7492 (setq start-list (list (caar comment-list)))
7493 (setq comment-list (cdr comment-list))
7494 (while comment-list
7495 (unless (or (= (caar comment-list) (car start-list))
7496 (<= (+ (car start-list) (cdar comment-list))
7497 end-comment-column))
7498 (setq start-list (cons (caar comment-list) start-list)))
7499 (setq comment-list (cdr comment-list)))
7500 ;; align lines as nicely as possible
7501 (goto-char beg)
7502 (while (< (point) end)
7503 (setq cur-start nil)
7504 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7505 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7506 (not (save-excursion
7507 (goto-char (match-beginning 3))
7508 (vhdl-in-literal))))
7509 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7510 (>= (- (match-end 2) (match-beginning 2))
7511 comment-column))))
7512 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7513 (setq length (- (match-end 3) (match-beginning 3)))
7514 (setq no-code (= (match-beginning 1) (match-end 1)))
7515 ;; insert minimum whitespace
7516 (goto-char (match-end 2))
7517 (delete-region (match-beginning 2) (match-end 2))
7518 (insert-char ?\ spacing)
7519 (setq tmp-list start-list)
7520 ;; insert additional whitespace to align
7521 (setq cur-start
7522 (cond
7523 ;; align comment-only line to inline comment of previous line
7524 ((and no-code prev-start
7525 (<= length (- end-comment-column prev-start)))
7526 prev-start)
7527 ;; align all comments at `start-max' if this is possible
7528 ((<= (+ start-max length-max) end-comment-column)
7529 start-max)
7530 ;; align at `comment-column' if possible
7531 ((and (<= start comment-column)
7532 (<= length (- end-comment-column comment-column)))
7533 comment-column)
7534 ;; align at left-most possible start position otherwise
7535 (t
7536 (while (and tmp-list (< (car tmp-list) start))
7537 (setq tmp-list (cdr tmp-list)))
7538 (car tmp-list))))
7539 (indent-to cur-start))
7540 (setq prev-start cur-start)
7541 (beginning-of-line 2))))))
7542
7543 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7544 "Align inline comments within a region. Groups of code lines separated by
7545 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7546 (interactive "r\nP")
7547 (save-excursion
7548 (let (orig pos)
7549 (goto-char beg)
7550 (beginning-of-line)
7551 (setq orig (point-marker))
7552 (setq beg (point))
7553 (goto-char end)
7554 (setq end (point-marker))
7555 (untabify beg end)
7556 (unless no-message (message "Aligning inline comments..."))
7557 (goto-char beg)
7558 (if (not vhdl-align-groups)
7559 ;; align entire region
7560 (vhdl-align-inline-comment-region-1 beg end spacing)
7561 ;; align groups
7562 (while (and (< beg end)
7563 (re-search-forward vhdl-align-group-separate end t))
7564 (setq pos (point-marker))
7565 (vhdl-align-inline-comment-region-1 beg pos spacing)
7566 (setq beg (1+ pos))
7567 (goto-char beg))
7568 ;; align last group
7569 (when (< beg end)
7570 (vhdl-align-inline-comment-region-1 beg end spacing)))
7571 (when vhdl-indent-tabs-mode
7572 (tabify orig end))
7573 (unless no-message (message "Aligning inline comments...done")))))
7574
7575 (defun vhdl-align-inline-comment-group (&optional spacing)
7576 "Align inline comments within a group of lines between empty lines."
7577 (interactive)
7578 (save-excursion
7579 (let ((start (point))
7580 beg end)
7581 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7582 (point-marker) (point-max)))
7583 (goto-char start)
7584 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7585 (point) (point-min)))
7586 (untabify beg end)
7587 (message "Aligning inline comments...")
7588 (vhdl-align-inline-comment-region-1 beg end)
7589 (when vhdl-indent-tabs-mode
7590 (tabify beg end))
7591 (message "Aligning inline comments...done"))))
7592
7593 (defun vhdl-align-inline-comment-buffer ()
7594 "Align inline comments within buffer. Groups of code lines separated by
7595 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7596 (interactive)
7597 (vhdl-align-inline-comment-region (point-min) (point-max)))
7598
7599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7600 ;; Fixup whitespace
7601
7602 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7603 "Fixup whitespace in region. Surround operator symbols by one space,
7604 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7605 end of line, do nothing in comments and strings."
7606 (interactive "r")
7607 (unless no-message (message "Fixing up whitespace..."))
7608 (save-excursion
7609 (goto-char end)
7610 (setq end (point-marker))
7611 ;; have no space before and one space after `,' and ';'
7612 (goto-char beg)
7613 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7614 (if (match-string 1)
7615 (goto-char (match-end 1))
7616 (replace-match "\\3 " nil nil nil 3)))
7617 ;; have no space after `('
7618 (goto-char beg)
7619 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7620 (if (match-string 1)
7621 (goto-char (match-end 1))
7622 (replace-match "\\2")))
7623 ;; have no space before `)'
7624 (goto-char beg)
7625 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7626 (if (match-string 1)
7627 (goto-char (match-end 1))
7628 (replace-match "\\2")))
7629 ;; surround operator symbols by one space
7630 (goto-char beg)
7631 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7632 (if (match-string 1)
7633 (goto-char (match-end 1))
7634 (replace-match "\\3 \\4 \\5")
7635 (goto-char (match-end 2))))
7636 ;; eliminate multiple spaces and spaces at end of line
7637 (goto-char beg)
7638 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7639 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7640 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7641 (progn (replace-match "" nil nil) t))
7642 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7643 (progn (replace-match ";" nil nil) t))
7644 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7645 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7646 (progn (replace-match " " nil nil) t))
7647 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7648 (progn (replace-match " " nil nil) t))
7649 ; (re-search-forward "[^ \t-]+" end t))))
7650 (re-search-forward "[^ \t\"-]+" end t))))
7651 (unless no-message (message "Fixing up whitespace...done")))
7652
7653 (defun vhdl-fixup-whitespace-buffer ()
7654 "Fixup whitespace in buffer. Surround operator symbols by one space,
7655 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7656 end of line, do nothing in comments."
7657 (interactive)
7658 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7659
7660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7661 ;; Beautify
7662
7663 (defun vhdl-beautify-region (beg end)
7664 "Beautify region by applying indentation, whitespace fixup, alignment, and
7665 case fixing to a region. Calls functions `vhdl-indent-buffer',
7666 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7667 `vhdl-fix-case-buffer'."
7668 (interactive "r")
7669 (setq end (save-excursion (goto-char end) (point-marker)))
7670 (vhdl-indent-region beg end nil)
7671 (let ((vhdl-align-groups t))
7672 (vhdl-align-region beg end))
7673 (vhdl-fix-case-region beg end))
7674
7675 (defun vhdl-beautify-buffer ()
7676 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7677 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7678 buffer."
7679 (interactive)
7680 (vhdl-beautify-region (point-min) (point-max))
7681 (when noninteractive (save-buffer)))
7682
7683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7684 ;; Code filling
7685
7686 (defun vhdl-fill-region (beg end &optional arg)
7687 "Fill lines for a region of code."
7688 (interactive "r\np")
7689 (save-excursion
7690 (goto-char beg)
7691 (let ((margin (if arg (current-indentation) (current-column))))
7692 (goto-char end)
7693 (setq end (point-marker))
7694 ;; remove inline comments, newlines and whitespace
7695 (vhdl-comment-kill-region beg end)
7696 (vhdl-comment-kill-inline-region beg end)
7697 (subst-char-in-region beg (1- end) ?\n ?\ )
7698 (vhdl-fixup-whitespace-region beg end)
7699 ;; wrap and end-comment-column
7700 (goto-char beg)
7701 (while (re-search-forward "\\s-" end t)
7702 (when(> (current-column) vhdl-end-comment-column)
7703 (backward-char)
7704 (when (re-search-backward "\\s-" beg t)
7705 (replace-match "\n")
7706 (indent-to margin)))))))
7707
7708 (defun vhdl-fill-group ()
7709 "Fill group of lines between empty lines."
7710 (interactive)
7711 (vhdl-do-group 'vhdl-fill-region))
7712
7713 (defun vhdl-fill-list ()
7714 "Fill the lines of a list surrounded by a balanced group of parentheses."
7715 (interactive)
7716 (vhdl-do-list 'vhdl-fill-region))
7717
7718 (defun vhdl-fill-same-indent ()
7719 "Fill the lines of block of lines with same indent."
7720 (interactive)
7721 (vhdl-do-same-indent 'vhdl-fill-region))
7722
7723
7724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7725 ;;; Code updating/fixing
7726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7727
7728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7729 ;; Sensitivity list update
7730
7731 ;; Strategy:
7732 ;; - no sensitivity list is generated for processes with wait statements
7733 ;; - otherwise, do the following:
7734 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7735 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7736 ;; manually entered global signals)
7737 ;; 3. signals from 1. and 2. form the list of visible signals
7738 ;; 4. search for if/elsif conditions containing an event (sequential code)
7739 ;; 5. scan for strings that are within syntactical regions where signals are
7740 ;; read but not within sequential code, and that correspond to visible
7741 ;; signals
7742 ;; 6. replace sensitivity list by list of signals from 5.
7743
7744 (defun vhdl-update-sensitivity-list-process ()
7745 "Update sensitivity list of current process."
7746 (interactive)
7747 (save-excursion
7748 (vhdl-prepare-search-2
7749 (end-of-line)
7750 ;; look whether in process
7751 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7752 (equal (upcase (match-string 2)) "PROCESS")
7753 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7754 (error "ERROR: Not within a process")
7755 (message "Updating sensitivity list...")
7756 (vhdl-update-sensitivity-list)
7757 (message "Updating sensitivity list...done")))))
7758
7759 (defun vhdl-update-sensitivity-list-buffer ()
7760 "Update sensitivity list of all processes in current buffer."
7761 (interactive)
7762 (save-excursion
7763 (vhdl-prepare-search-2
7764 (goto-char (point-min))
7765 (message "Updating sensitivity lists...")
7766 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7767 (goto-char (match-beginning 0))
7768 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7769 (message "Updating sensitivity lists...done"))))
7770
7771 (defun vhdl-update-sensitivity-list ()
7772 "Update sensitivity list."
7773 (let ((proc-beg (point))
7774 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7775 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7776 seq-region-list)
7777 (cond
7778 ;; search for wait statement (no sensitivity list allowed)
7779 ((progn (goto-char proc-mid)
7780 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7781 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7782 ;; combinational process (update sensitivity list)
7783 (t
7784 (let
7785 ;; scan for visible signals
7786 ((visible-list (vhdl-get-visible-signals))
7787 ;; define syntactic regions where signals are read
7788 (scan-regions-list
7789 '(;; right-hand side of signal/variable assignment
7790 ;; (special case: "<=" is relational operator in a condition)
7791 ((re-search-forward "[<:]=" proc-end t)
7792 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7793 ;; if condition
7794 ((re-search-forward "^\\s-*if\\>" proc-end t)
7795 (re-search-forward "\\<then\\>" proc-end t))
7796 ;; elsif condition
7797 ((re-search-forward "\\<elsif\\>" proc-end t)
7798 (re-search-forward "\\<then\\>" proc-end t))
7799 ;; while loop condition
7800 ((re-search-forward "^\\s-*while\\>" proc-end t)
7801 (re-search-forward "\\<loop\\>" proc-end t))
7802 ;; exit/next condition
7803 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7804 (re-search-forward ";" proc-end t))
7805 ;; assert condition
7806 ((re-search-forward "\\<assert\\>" proc-end t)
7807 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7808 ;; case expression
7809 ((re-search-forward "^\\s-*case\\>" proc-end t)
7810 (re-search-forward "\\<is\\>" proc-end t))
7811 ;; parameter list of procedure call
7812 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7813 (1- (point)))
7814 (progn (backward-char) (forward-sexp)
7815 (while (looking-at "(") (forward-sexp)) (point)))))
7816 name read-list sens-list signal-list
7817 sens-beg sens-end beg end margin)
7818 ;; scan for signals in old sensitivity list
7819 (goto-char proc-beg)
7820 (re-search-forward "\\<process\\>" proc-mid t)
7821 (if (not (looking-at "[ \t\n]*("))
7822 (setq sens-beg (point))
7823 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7824 (goto-char (match-end 1))
7825 (forward-sexp)
7826 (setq sens-end (1- (point)))
7827 (goto-char sens-beg)
7828 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7829 (setq sens-list
7830 (cons (downcase (match-string 0)) sens-list))
7831 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7832 (setq signal-list (append visible-list sens-list))
7833 ;; search for sequential parts
7834 (goto-char proc-mid)
7835 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7836 (setq end (re-search-forward "\\<then\\>" proc-end t))
7837 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7838 (goto-char end)
7839 (backward-word 1)
7840 (vhdl-forward-sexp)
7841 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7842 (beginning-of-line)))
7843 ;; scan for signals read in process
7844 (while scan-regions-list
7845 (goto-char proc-mid)
7846 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7847 (setq end (eval (nth 1 (car scan-regions-list)))))
7848 (goto-char beg)
7849 (unless (or (vhdl-in-literal)
7850 (and seq-region-list
7851 (let ((tmp-list seq-region-list))
7852 (while (and tmp-list
7853 (< (point) (caar tmp-list)))
7854 (setq tmp-list (cdr tmp-list)))
7855 (and tmp-list (< (point) (cdar tmp-list))))))
7856 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7857 (setq name (match-string 1))
7858 (when (and (not (match-string 4)) ; not when formal parameter
7859 (not (and (match-string 3) ; not event attribute
7860 (not (member (downcase (match-string 3))
7861 '("event" "last_event" "transaction")))))
7862 (member (downcase name) signal-list))
7863 (unless (member-ignore-case name read-list)
7864 (setq read-list (cons name read-list))))
7865 (goto-char (match-end 1)))))
7866 (setq scan-regions-list (cdr scan-regions-list)))
7867 ;; update sensitivity list
7868 (goto-char sens-beg)
7869 (if sens-end
7870 (delete-region sens-beg sens-end)
7871 (when read-list
7872 (insert " ()") (backward-char)))
7873 (setq read-list (sort read-list 'string<))
7874 (when read-list
7875 (setq margin (current-column))
7876 (insert (car read-list))
7877 (setq read-list (cdr read-list))
7878 (while read-list
7879 (insert ",")
7880 (if (<= (+ (current-column) (length (car read-list)) 2)
7881 end-comment-column)
7882 (insert " ")
7883 (insert "\n") (indent-to margin))
7884 (insert (car read-list))
7885 (setq read-list (cdr read-list)))))))))
7886
7887 (defun vhdl-get-visible-signals ()
7888 "Get all signals visible in the current block."
7889 (let (beg end signal-list entity-name file-name)
7890 (vhdl-prepare-search-2
7891 ;; get entity name
7892 (save-excursion
7893 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7894 (not (equal "END" (upcase (match-string 1))))
7895 (setq entity-name (match-string 2)))
7896 (error "ERROR: Not within an architecture")))
7897 ;; search for signals declared in entity port clause
7898 (save-excursion
7899 (goto-char (point-min))
7900 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7901 (setq file-name
7902 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7903 "." (file-name-extension (buffer-file-name)))))
7904 (vhdl-visit-file
7905 file-name t
7906 (vhdl-prepare-search-2
7907 (goto-char (point-min))
7908 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7909 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7910 (when (setq beg (re-search-forward
7911 "^\\s-*port[ \t\n]*("
7912 (save-excursion
7913 (re-search-forward "^end\\>" nil t)) t))
7914 (setq end (save-excursion
7915 (backward-char) (forward-sexp) (point)))
7916 (vhdl-forward-syntactic-ws)
7917 (while (< (point) end)
7918 (when (looking-at "signal[ \t\n]+")
7919 (goto-char (match-end 0)))
7920 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7921 (setq signal-list
7922 (cons (downcase (match-string 1)) signal-list))
7923 (goto-char (match-end 0))
7924 (vhdl-forward-syntactic-ws))
7925 (re-search-forward ";" end 1)
7926 (vhdl-forward-syntactic-ws)))))))
7927 ;; search for signals declared in architecture declarative part
7928 (save-excursion
7929 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7930 (not (equal "END" (upcase (match-string 1))))
7931 (setq end (re-search-forward "^begin\\>" nil t))))
7932 (error "ERROR: No architecture declarative part found")
7933 ;; scan for all declared signal and alias 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 (setq beg (point))))))
7950 ;; search for signals declared in surrounding block declarative parts
7951 (save-excursion
7952 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7953 (match-string 2))
7954 (goto-char (match-end 2))
7955 (vhdl-backward-sexp)
7956 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7957 beg)
7958 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7959 ;; scan for all declared signal names
7960 (goto-char beg)
7961 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7962 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7963 (if (match-string 2)
7964 ;; scan signal name
7965 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7966 (setq signal-list
7967 (cons (downcase (match-string 1)) signal-list))
7968 (goto-char (match-end 0)))
7969 ;; scan alias name, check is alias of (declared) signal
7970 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7971 (member (downcase (match-string 2)) signal-list))
7972 (setq signal-list
7973 (cons (downcase (match-string 1)) signal-list))
7974 (goto-char (match-end 0))))))
7975 (goto-char beg)))
7976 signal-list)))
7977
7978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7979 ;; Generic/port clause fixing
7980
7981 (defun vhdl-fix-clause ()
7982 "Fix closing parenthesis within generic/port clause."
7983 (interactive)
7984 (save-excursion
7985 (vhdl-prepare-search-2
7986 (let ((pos (point))
7987 beg end)
7988 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7989 (error "ERROR: Not within a generic/port clause")
7990 ;; search for end of clause
7991 (goto-char (match-end 0))
7992 (setq beg (1- (point)))
7993 (vhdl-forward-syntactic-ws)
7994 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7995 (goto-char (1- (match-end 0)))
7996 (setq end (point-marker))
7997 (forward-char)
7998 (vhdl-forward-syntactic-ws))
7999 (goto-char end)
8000 (when (> pos (save-excursion (end-of-line) (point)))
8001 (error "ERROR: Not within a generic/port clause"))
8002 ;; delete closing parenthesis on separate line (not supported style)
8003 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8004 (vhdl-line-kill)
8005 (vhdl-backward-syntactic-ws)
8006 (setq end (point-marker))
8007 (insert ";"))
8008 ;; delete superfluous parentheses
8009 (while (progn (goto-char beg)
8010 (condition-case () (forward-sexp)
8011 (error (goto-char (point-max))))
8012 (< (point) end))
8013 (delete-backward-char 1))
8014 ;; add closing parenthesis
8015 (when (> (point) end)
8016 (goto-char end)
8017 (insert ")")))))))
8018
8019 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8020 ;; Miscellaneous
8021
8022 (defun vhdl-remove-trailing-spaces ()
8023 "Remove trailing spaces in the whole buffer."
8024 (interactive)
8025 (save-match-data
8026 (save-excursion
8027 (goto-char (point-min))
8028 (while (re-search-forward "[ \t]+$" (point-max) t)
8029 (unless (vhdl-in-literal)
8030 (replace-match "" nil nil))))))
8031
8032
8033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8034 ;;; Electrification
8035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8036
8037 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8038 "Syntax of prompt inserted by template generators.")
8039
8040 (defvar vhdl-template-invoked-by-hook nil
8041 "Indicates whether a template has been invoked by a hook or by key or menu.
8042 Used for undoing after template abortion.")
8043
8044 ;; correct different behavior of function `unread-command-events' in XEmacs
8045 (defun vhdl-character-to-event (arg))
8046 (defalias 'vhdl-character-to-event
8047 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8048
8049 (defun vhdl-work-library ()
8050 "Return the working library name of the current project or \"work\" if no
8051 project is defined."
8052 (vhdl-resolve-env-variable
8053 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8054
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056 ;; Enabling/disabling
8057
8058 (defun vhdl-mode-line-update ()
8059 "Update the modeline string for VHDL major mode."
8060 (setq mode-name (concat "VHDL"
8061 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8062 (and vhdl-electric-mode "e")
8063 (and vhdl-stutter-mode "s")))
8064 (force-mode-line-update t))
8065
8066 (defun vhdl-electric-mode (arg)
8067 "Toggle VHDL electric mode.
8068 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8069 (interactive "P")
8070 (setq vhdl-electric-mode
8071 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8072 ((> arg 0) t) (t nil)))
8073 (vhdl-mode-line-update))
8074
8075 (defun vhdl-stutter-mode (arg)
8076 "Toggle VHDL stuttering mode.
8077 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8078 (interactive "P")
8079 (setq vhdl-stutter-mode
8080 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8081 ((> arg 0) t) (t nil)))
8082 (vhdl-mode-line-update))
8083
8084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8085 ;; Stuttering
8086
8087 (defun vhdl-electric-dash (count)
8088 "-- starts a comment, --- draws a horizontal line,
8089 ---- starts a display comment."
8090 (interactive "p")
8091 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8092 (cond
8093 ((and abbrev-start-location (= abbrev-start-location (point)))
8094 (setq abbrev-start-location nil)
8095 (goto-char last-abbrev-location)
8096 (beginning-of-line nil)
8097 (vhdl-comment-display))
8098 ((/= (preceding-char) ?-) ; standard dash (minus)
8099 (self-insert-command count))
8100 (t (self-insert-command count)
8101 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8102 (let ((next-input (read-char)))
8103 (if (= next-input ?-) ; triple dash
8104 (progn
8105 (vhdl-comment-display-line)
8106 (message
8107 "Enter '-' for display comment, else continue coding")
8108 (let ((next-input (read-char)))
8109 (if (= next-input ?-) ; four dashes
8110 (vhdl-comment-display t)
8111 (setq unread-command-events ; pushback the char
8112 (list (vhdl-character-to-event next-input))))))
8113 (setq unread-command-events ; pushback the char
8114 (list (vhdl-character-to-event next-input)))
8115 (vhdl-comment-insert)))))
8116 (self-insert-command count)))
8117
8118 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8119 (interactive "p")
8120 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8121 (if (= (preceding-char) ?\()
8122 (progn (delete-char -1) (insert-char ?\[ 1))
8123 (insert-char ?\( 1))
8124 (self-insert-command count)))
8125
8126 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8127 (interactive "p")
8128 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8129 (progn
8130 (if (= (preceding-char) ?\))
8131 (progn (delete-char -1) (insert-char ?\] 1))
8132 (insert-char ?\) 1))
8133 (blink-matching-open))
8134 (self-insert-command count)))
8135
8136 (defun vhdl-electric-quote (count) "'' --> \""
8137 (interactive "p")
8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8139 (if (= (preceding-char) last-input-event)
8140 (progn (delete-backward-char 1) (insert-char ?\" 1))
8141 (insert-char ?\' 1))
8142 (self-insert-command count)))
8143
8144 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8145 (interactive "p")
8146 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8147 (cond ((= (preceding-char) last-input-event)
8148 (progn (delete-char -1)
8149 (unless (eq (preceding-char) ? ) (insert " "))
8150 (insert ": ")
8151 (setq this-command 'vhdl-electric-colon)))
8152 ((and
8153 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8154 (progn (delete-char -1) (insert "= ")))
8155 (t (insert-char ?\; 1)))
8156 (self-insert-command count)))
8157
8158 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8159 (interactive "p")
8160 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8161 (cond ((= (preceding-char) last-input-event)
8162 (progn (delete-char -1)
8163 (unless (eq (preceding-char) ? ) (insert " "))
8164 (insert "<= ")))
8165 (t (insert-char ?\, 1)))
8166 (self-insert-command count)))
8167
8168 (defun vhdl-electric-period (count) "'..' --> ' => '"
8169 (interactive "p")
8170 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8171 (cond ((= (preceding-char) last-input-event)
8172 (progn (delete-char -1)
8173 (unless (eq (preceding-char) ? ) (insert " "))
8174 (insert "=> ")))
8175 (t (insert-char ?\. 1)))
8176 (self-insert-command count)))
8177
8178 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8179 (interactive "p")
8180 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8181 (cond ((= (preceding-char) last-input-event)
8182 (progn (delete-char -1)
8183 (unless (eq (preceding-char) ? ) (insert " "))
8184 (insert "== ")))
8185 (t (insert-char ?\= 1)))
8186 (self-insert-command count)))
8187
8188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8189 ;; VHDL templates
8190
8191 (defun vhdl-template-paired-parens ()
8192 "Insert a pair of round parentheses, placing point between them."
8193 (interactive)
8194 (insert "()")
8195 (backward-char))
8196
8197 (defun vhdl-template-alias ()
8198 "Insert alias declaration."
8199 (interactive)
8200 (let ((start (point)))
8201 (vhdl-insert-keyword "ALIAS ")
8202 (when (vhdl-template-field "name" nil t start (point))
8203 (insert " : ")
8204 (unless (vhdl-template-field
8205 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8206 nil t)
8207 (delete-backward-char 3))
8208 (vhdl-insert-keyword " IS ")
8209 (vhdl-template-field "name" ";")
8210 (vhdl-comment-insert-inline))))
8211
8212 (defun vhdl-template-architecture ()
8213 "Insert architecture."
8214 (interactive)
8215 (let ((margin (current-indentation))
8216 (start (point))
8217 arch-name)
8218 (vhdl-insert-keyword "ARCHITECTURE ")
8219 (when (setq arch-name
8220 (vhdl-template-field "name" nil t start (point)))
8221 (vhdl-insert-keyword " OF ")
8222 (if (save-excursion
8223 (vhdl-prepare-search-1
8224 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8225 (insert (match-string 1))
8226 (vhdl-template-field "entity name"))
8227 (vhdl-insert-keyword " IS\n")
8228 (vhdl-template-begin-end
8229 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8230 (memq vhdl-insert-empty-lines '(unit all))))))
8231
8232 (defun vhdl-template-array (kind &optional secondary)
8233 "Insert array type definition."
8234 (interactive)
8235 (let ((start (point)))
8236 (vhdl-insert-keyword "ARRAY (")
8237 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8238 secondary)
8239 (vhdl-insert-keyword ") OF ")
8240 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8241 (vhdl-insert-keyword ";"))))
8242
8243 (defun vhdl-template-assert ()
8244 "Insert an assertion statement."
8245 (interactive)
8246 (let ((start (point)))
8247 (vhdl-insert-keyword "ASSERT ")
8248 (when vhdl-conditions-in-parenthesis (insert "("))
8249 (when (vhdl-template-field "condition (negated)" nil t start (point))
8250 (when vhdl-conditions-in-parenthesis (insert ")"))
8251 (setq start (point))
8252 (vhdl-insert-keyword " REPORT ")
8253 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8254 (delete-region start (point)))
8255 (setq start (point))
8256 (vhdl-insert-keyword " SEVERITY ")
8257 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8258 (delete-region start (point)))
8259 (insert ";"))))
8260
8261 (defun vhdl-template-attribute ()
8262 "Insert an attribute declaration or specification."
8263 (interactive)
8264 (if (eq (vhdl-decision-query
8265 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8266 (vhdl-template-attribute-spec)
8267 (vhdl-template-attribute-decl)))
8268
8269 (defun vhdl-template-attribute-decl ()
8270 "Insert an attribute declaration."
8271 (interactive)
8272 (let ((start (point)))
8273 (vhdl-insert-keyword "ATTRIBUTE ")
8274 (when (vhdl-template-field "name" " : " t start (point))
8275 (vhdl-template-field "type" ";")
8276 (vhdl-comment-insert-inline))))
8277
8278 (defun vhdl-template-attribute-spec ()
8279 "Insert an attribute specification."
8280 (interactive)
8281 (let ((start (point)))
8282 (vhdl-insert-keyword "ATTRIBUTE ")
8283 (when (vhdl-template-field "name" nil t start (point))
8284 (vhdl-insert-keyword " OF ")
8285 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8286 (vhdl-template-field "entity class")
8287 (vhdl-insert-keyword " IS ")
8288 (vhdl-template-field "expression" ";"))))
8289
8290 (defun vhdl-template-block ()
8291 "Insert a block."
8292 (interactive)
8293 (let ((margin (current-indentation))
8294 (start (point))
8295 label)
8296 (vhdl-insert-keyword ": BLOCK ")
8297 (goto-char start)
8298 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8299 (forward-word 1)
8300 (forward-char 1)
8301 (insert "(")
8302 (if (vhdl-template-field "[guard expression]" nil t)
8303 (insert ")")
8304 (delete-char -2))
8305 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8306 (insert "\n")
8307 (vhdl-template-begin-end "BLOCK" label margin)
8308 (vhdl-comment-block))))
8309
8310 (defun vhdl-template-block-configuration ()
8311 "Insert a block configuration statement."
8312 (interactive)
8313 (let ((margin (current-indentation))
8314 (start (point)))
8315 (vhdl-insert-keyword "FOR ")
8316 (when (vhdl-template-field "block name" nil t start (point))
8317 (vhdl-insert-keyword "\n\n")
8318 (indent-to margin)
8319 (vhdl-insert-keyword "END FOR;")
8320 (end-of-line 0)
8321 (indent-to (+ margin vhdl-basic-offset)))))
8322
8323 (defun vhdl-template-break ()
8324 "Insert a break statement."
8325 (interactive)
8326 (let (position)
8327 (vhdl-insert-keyword "BREAK")
8328 (setq position (point))
8329 (insert " ")
8330 (while (or
8331 (progn (vhdl-insert-keyword "FOR ")
8332 (if (vhdl-template-field "[quantity name]" " USE " t)
8333 (progn (vhdl-template-field "quantity name" " => ") t)
8334 (delete-region (point)
8335 (progn (forward-word -1) (point)))
8336 nil))
8337 (vhdl-template-field "[quantity name]" " => " t))
8338 (vhdl-template-field "expression")
8339 (setq position (point))
8340 (insert ", "))
8341 (delete-region position (point))
8342 (unless (vhdl-sequential-statement-p)
8343 (vhdl-insert-keyword " ON ")
8344 (if (vhdl-template-field "[sensitivity list]" nil t)
8345 (setq position (point))
8346 (delete-region position (point))))
8347 (vhdl-insert-keyword " WHEN ")
8348 (when vhdl-conditions-in-parenthesis (insert "("))
8349 (if (vhdl-template-field "[condition]" nil t)
8350 (when vhdl-conditions-in-parenthesis (insert ")"))
8351 (delete-region position (point)))
8352 (insert ";")))
8353
8354 (defun vhdl-template-case (&optional kind)
8355 "Insert a case statement."
8356 (interactive)
8357 (let ((margin (current-indentation))
8358 (start (point))
8359 label)
8360 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8361 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8362 (vhdl-insert-keyword "CASE ")
8363 (vhdl-insert-keyword ": CASE ")
8364 (goto-char start)
8365 (setq label (vhdl-template-field "[label]" nil t))
8366 (unless label (delete-char 2))
8367 (forward-word 1)
8368 (forward-char 1))
8369 (when (vhdl-template-field "expression" nil t start (point))
8370 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8371 (indent-to margin)
8372 (vhdl-insert-keyword "END CASE")
8373 (when label (insert " " label))
8374 (insert ";")
8375 (forward-line -1)
8376 (indent-to (+ margin vhdl-basic-offset))
8377 (vhdl-insert-keyword "WHEN ")
8378 (let ((position (point)))
8379 (insert " => ;\n")
8380 (indent-to (+ margin vhdl-basic-offset))
8381 (vhdl-insert-keyword "WHEN OTHERS => null;")
8382 (goto-char position)))))
8383
8384 (defun vhdl-template-case-is ()
8385 "Insert a sequential case statement."
8386 (interactive)
8387 (vhdl-template-case 'is))
8388
8389 (defun vhdl-template-case-use ()
8390 "Insert a simultaneous case statement."
8391 (interactive)
8392 (vhdl-template-case 'use))
8393
8394 (defun vhdl-template-component ()
8395 "Insert a component declaration."
8396 (interactive)
8397 (vhdl-template-component-decl))
8398
8399 (defun vhdl-template-component-conf ()
8400 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8401 since these are almost equivalent)."
8402 (interactive)
8403 (let ((margin (current-indentation))
8404 (result (vhdl-template-configuration-spec t)))
8405 (when result
8406 (insert "\n")
8407 (indent-to margin)
8408 (vhdl-insert-keyword "END FOR;")
8409 (when (eq result 'no-use)
8410 (end-of-line -0)))))
8411
8412 (defun vhdl-template-component-decl ()
8413 "Insert a component declaration."
8414 (interactive)
8415 (let ((margin (current-indentation))
8416 (start (point))
8417 name end-column)
8418 (vhdl-insert-keyword "COMPONENT ")
8419 (when (setq name (vhdl-template-field "name" nil t start (point)))
8420 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8421 (insert "\n\n")
8422 (indent-to margin)
8423 (vhdl-insert-keyword "END COMPONENT")
8424 (unless (vhdl-standard-p '87) (insert " " name))
8425 (insert ";")
8426 (setq end-column (current-column))
8427 (end-of-line -0)
8428 (indent-to (+ margin vhdl-basic-offset))
8429 (vhdl-template-generic-list t t)
8430 (insert "\n")
8431 (indent-to (+ margin vhdl-basic-offset))
8432 (vhdl-template-port-list t)
8433 (beginning-of-line 2)
8434 (forward-char end-column))))
8435
8436 (defun vhdl-template-component-inst ()
8437 "Insert a component instantiation statement."
8438 (interactive)
8439 (let ((margin (current-indentation))
8440 (start (point))
8441 unit position)
8442 (when (vhdl-template-field "instance label" nil t start (point))
8443 (insert ": ")
8444 (if (not (vhdl-use-direct-instantiation))
8445 (vhdl-template-field "component name")
8446 ;; direct instantiation
8447 (setq unit (vhdl-template-field
8448 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8449 (setq unit (upcase (or unit "")))
8450 (cond ((equal unit "ENTITY")
8451 (vhdl-template-field "library name" "." nil nil nil nil
8452 (vhdl-work-library))
8453 (vhdl-template-field "entity name" "(")
8454 (if (vhdl-template-field "[architecture name]" nil t)
8455 (insert ")")
8456 (delete-char -1)))
8457 ((equal unit "CONFIGURATION")
8458 (vhdl-template-field "library name" "." nil nil nil nil
8459 (vhdl-work-library))
8460 (vhdl-template-field "configuration name"))
8461 (t (vhdl-template-field "component name"))))
8462 (insert "\n")
8463 (indent-to (+ margin vhdl-basic-offset))
8464 (setq position (point))
8465 (vhdl-insert-keyword "GENERIC ")
8466 (when (vhdl-template-map position t t)
8467 (insert "\n")
8468 (indent-to (+ margin vhdl-basic-offset)))
8469 (setq position (point))
8470 (vhdl-insert-keyword "PORT ")
8471 (unless (vhdl-template-map position t t)
8472 (delete-region (line-beginning-position) (point))
8473 (delete-char -1))
8474 (insert ";"))))
8475
8476 (defun vhdl-template-conditional-signal-asst ()
8477 "Insert a conditional signal assignment."
8478 (interactive)
8479 (when (vhdl-template-field "target signal")
8480 (insert " <= ")
8481 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8482 ; (insert " "))
8483 (let ((margin (current-column))
8484 (start (point))
8485 position)
8486 (vhdl-template-field "waveform")
8487 (setq position (point))
8488 (vhdl-insert-keyword " WHEN ")
8489 (when vhdl-conditions-in-parenthesis (insert "("))
8490 (while (and (vhdl-template-field "[condition]" nil t)
8491 (progn
8492 (when vhdl-conditions-in-parenthesis (insert ")"))
8493 (setq position (point))
8494 (vhdl-insert-keyword " ELSE")
8495 (insert "\n")
8496 (indent-to margin)
8497 (vhdl-template-field "[waveform]" nil t)))
8498 (setq position (point))
8499 (vhdl-insert-keyword " WHEN ")
8500 (when vhdl-conditions-in-parenthesis (insert "(")))
8501 (delete-region position (point))
8502 (insert ";")
8503 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8504
8505 (defun vhdl-template-configuration ()
8506 "Insert a configuration specification if within an architecture,
8507 a block or component configuration if within a configuration declaration,
8508 a configuration declaration if not within a design unit."
8509 (interactive)
8510 (vhdl-prepare-search-1
8511 (cond
8512 ((and (save-excursion ; architecture body
8513 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8514 (equal "ARCHITECTURE" (upcase (match-string 1))))
8515 (vhdl-template-configuration-spec))
8516 ((and (save-excursion ; configuration declaration
8517 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8518 (equal "CONFIGURATION" (upcase (match-string 1))))
8519 (if (eq (vhdl-decision-query
8520 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8521 (vhdl-template-component-conf)
8522 (vhdl-template-block-configuration)))
8523 (t (vhdl-template-configuration-decl))))) ; otherwise
8524
8525 (defun vhdl-template-configuration-spec (&optional optional-use)
8526 "Insert a configuration specification."
8527 (interactive)
8528 (let ((margin (current-indentation))
8529 (start (point))
8530 aspect position)
8531 (vhdl-insert-keyword "FOR ")
8532 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8533 t start (point))
8534 (vhdl-template-field "component name" "\n")
8535 (indent-to (+ margin vhdl-basic-offset))
8536 (setq start (point))
8537 (vhdl-insert-keyword "USE ")
8538 (if (and optional-use
8539 (not (setq aspect (vhdl-template-field
8540 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8541 (progn (delete-region start (point)) 'no-use)
8542 (unless optional-use
8543 (setq aspect (vhdl-template-field
8544 "ENTITY | CONFIGURATION | OPEN" " ")))
8545 (setq aspect (upcase (or aspect "")))
8546 (cond ((equal aspect "ENTITY")
8547 (vhdl-template-field "library name" "." nil nil nil nil
8548 (vhdl-work-library))
8549 (vhdl-template-field "entity name" "(")
8550 (if (vhdl-template-field "[architecture name]" nil t)
8551 (insert ")")
8552 (delete-char -1))
8553 (insert "\n")
8554 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8555 (setq position (point))
8556 (vhdl-insert-keyword "GENERIC ")
8557 (when (vhdl-template-map position t t)
8558 (insert "\n")
8559 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8560 (setq position (point))
8561 (vhdl-insert-keyword "PORT ")
8562 (unless (vhdl-template-map position t t)
8563 (delete-region (line-beginning-position) (point))
8564 (delete-char -1))
8565 (insert ";")
8566 t)
8567 ((equal aspect "CONFIGURATION")
8568 (vhdl-template-field "library name" "." nil nil nil nil
8569 (vhdl-work-library))
8570 (vhdl-template-field "configuration name" ";"))
8571 (t (delete-backward-char 1) (insert ";") t))))))
8572
8573
8574 (defun vhdl-template-configuration-decl ()
8575 "Insert a configuration declaration."
8576 (interactive)
8577 (let ((margin (current-indentation))
8578 (start (point))
8579 entity-exists string name position)
8580 (vhdl-insert-keyword "CONFIGURATION ")
8581 (when (setq name (vhdl-template-field "name" nil t start (point)))
8582 (vhdl-insert-keyword " OF ")
8583 (save-excursion
8584 (vhdl-prepare-search-1
8585 (setq entity-exists (vhdl-re-search-backward
8586 "\\<entity \\(\\w*\\) is\\>" nil t))
8587 (setq string (match-string 1))))
8588 (if (and entity-exists (not (equal string "")))
8589 (insert string)
8590 (vhdl-template-field "entity name"))
8591 (vhdl-insert-keyword " IS\n")
8592 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8593 (indent-to (+ margin vhdl-basic-offset))
8594 (setq position (point))
8595 (insert "\n")
8596 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8597 (indent-to margin)
8598 (vhdl-insert-keyword "END ")
8599 (unless (vhdl-standard-p '87)
8600 (vhdl-insert-keyword "CONFIGURATION "))
8601 (insert name ";")
8602 (goto-char position))))
8603
8604 (defun vhdl-template-constant ()
8605 "Insert a constant declaration."
8606 (interactive)
8607 (let ((start (point))
8608 (in-arglist (vhdl-in-argument-list-p)))
8609 (vhdl-insert-keyword "CONSTANT ")
8610 (when (vhdl-template-field "name" nil t start (point))
8611 (insert " : ")
8612 (when in-arglist (vhdl-insert-keyword "IN "))
8613 (vhdl-template-field "type")
8614 (if in-arglist
8615 (progn (insert ";")
8616 (vhdl-comment-insert-inline))
8617 (let ((position (point)))
8618 (insert " := ")
8619 (unless (vhdl-template-field "[initialization]" nil t)
8620 (delete-region position (point)))
8621 (insert ";")
8622 (vhdl-comment-insert-inline))))))
8623
8624 (defun vhdl-template-default ()
8625 "Insert nothing."
8626 (interactive)
8627 (insert " ")
8628 (unexpand-abbrev)
8629 (backward-word 1)
8630 (vhdl-case-word 1)
8631 (forward-char 1))
8632
8633 (defun vhdl-template-default-indent ()
8634 "Insert nothing and indent."
8635 (interactive)
8636 (insert " ")
8637 (unexpand-abbrev)
8638 (backward-word 1)
8639 (vhdl-case-word 1)
8640 (forward-char 1)
8641 (indent-according-to-mode))
8642
8643 (defun vhdl-template-disconnect ()
8644 "Insert a disconnect statement."
8645 (interactive)
8646 (let ((start (point)))
8647 (vhdl-insert-keyword "DISCONNECT ")
8648 (when (vhdl-template-field "signal names | OTHERS | ALL"
8649 " : " t start (point))
8650 (vhdl-template-field "type")
8651 (vhdl-insert-keyword " AFTER ")
8652 (vhdl-template-field "time expression" ";"))))
8653
8654 (defun vhdl-template-else ()
8655 "Insert an else statement."
8656 (interactive)
8657 (let (margin)
8658 (vhdl-prepare-search-1
8659 (vhdl-insert-keyword "ELSE")
8660 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8661 (equal "WHEN" (upcase (match-string 1))))
8662 (insert " ")
8663 (indent-according-to-mode)
8664 (setq margin (current-indentation))
8665 (insert "\n")
8666 (indent-to (+ margin vhdl-basic-offset))))))
8667
8668 (defun vhdl-template-elsif ()
8669 "Insert an elsif statement."
8670 (interactive)
8671 (let ((start (point))
8672 margin)
8673 (vhdl-insert-keyword "ELSIF ")
8674 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8675 (when vhdl-conditions-in-parenthesis (insert "("))
8676 (when (vhdl-template-field "condition" nil t start (point))
8677 (when vhdl-conditions-in-parenthesis (insert ")"))
8678 (indent-according-to-mode)
8679 (setq margin (current-indentation))
8680 (vhdl-insert-keyword
8681 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8682 (indent-to (+ margin vhdl-basic-offset))))))
8683
8684 (defun vhdl-template-entity ()
8685 "Insert an entity."
8686 (interactive)
8687 (let ((margin (current-indentation))
8688 (start (point))
8689 name end-column)
8690 (vhdl-insert-keyword "ENTITY ")
8691 (when (setq name (vhdl-template-field "name" nil t start (point)))
8692 (vhdl-insert-keyword " IS\n\n")
8693 (indent-to margin)
8694 (vhdl-insert-keyword "END ")
8695 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8696 (insert name ";")
8697 (setq end-column (current-column))
8698 (end-of-line -0)
8699 (indent-to (+ margin vhdl-basic-offset))
8700 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8701 (indent-to (+ margin vhdl-basic-offset))
8702 (when (vhdl-template-generic-list t)
8703 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8704 (insert "\n")
8705 (indent-to (+ margin vhdl-basic-offset))
8706 (when (vhdl-template-port-list t)
8707 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8708 (beginning-of-line 2)
8709 (forward-char end-column))))
8710
8711 (defun vhdl-template-exit ()
8712 "Insert an exit statement."
8713 (interactive)
8714 (let ((start (point)))
8715 (vhdl-insert-keyword "EXIT ")
8716 (if (vhdl-template-field "[loop label]" nil t start (point))
8717 (let ((position (point)))
8718 (vhdl-insert-keyword " WHEN ")
8719 (when vhdl-conditions-in-parenthesis (insert "("))
8720 (if (vhdl-template-field "[condition]" nil t)
8721 (when vhdl-conditions-in-parenthesis (insert ")"))
8722 (delete-region position (point))))
8723 (delete-char -1))
8724 (insert ";")))
8725
8726 (defun vhdl-template-file ()
8727 "Insert a file declaration."
8728 (interactive)
8729 (let ((start (point)))
8730 (vhdl-insert-keyword "FILE ")
8731 (when (vhdl-template-field "name" nil t start (point))
8732 (insert " : ")
8733 (vhdl-template-field "type")
8734 (unless (vhdl-standard-p '87)
8735 (vhdl-insert-keyword " OPEN ")
8736 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8737 nil t)
8738 (delete-backward-char 6)))
8739 (vhdl-insert-keyword " IS ")
8740 (when (vhdl-standard-p '87)
8741 (vhdl-template-field "[IN | OUT]" " " t))
8742 (vhdl-template-field "filename-string" nil nil nil nil t)
8743 (insert ";")
8744 (vhdl-comment-insert-inline))))
8745
8746 (defun vhdl-template-for ()
8747 "Insert a block or component configuration if within a configuration
8748 declaration, a configuration specification if within an architecture
8749 declarative part (and not within a subprogram), a for-loop if within a
8750 sequential statement part (subprogram or process), and a for-generate
8751 otherwise."
8752 (interactive)
8753 (vhdl-prepare-search-1
8754 (cond
8755 ((vhdl-sequential-statement-p) ; sequential statement
8756 (vhdl-template-for-loop))
8757 ((and (save-excursion ; configuration declaration
8758 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8759 (equal "CONFIGURATION" (upcase (match-string 1))))
8760 (if (eq (vhdl-decision-query
8761 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8762 (vhdl-template-component-conf)
8763 (vhdl-template-block-configuration)))
8764 ((and (save-excursion
8765 (re-search-backward ; architecture declarative part
8766 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8767 (equal "ARCHITECTURE" (upcase (match-string 1))))
8768 (vhdl-template-configuration-spec))
8769 (t (vhdl-template-for-generate))))) ; concurrent statement
8770
8771 (defun vhdl-template-for-generate ()
8772 "Insert a for-generate."
8773 (interactive)
8774 (let ((margin (current-indentation))
8775 (start (point))
8776 label position)
8777 (vhdl-insert-keyword ": FOR ")
8778 (setq position (point-marker))
8779 (goto-char start)
8780 (when (setq label (vhdl-template-field "label" nil t start position))
8781 (goto-char position)
8782 (vhdl-template-field "loop variable")
8783 (vhdl-insert-keyword " IN ")
8784 (vhdl-template-field "range")
8785 (vhdl-template-generate-body margin label))))
8786
8787 (defun vhdl-template-for-loop ()
8788 "Insert a for loop."
8789 (interactive)
8790 (let ((margin (current-indentation))
8791 (start (point))
8792 label index)
8793 (if (not (eq vhdl-optional-labels 'all))
8794 (vhdl-insert-keyword "FOR ")
8795 (vhdl-insert-keyword ": FOR ")
8796 (goto-char start)
8797 (setq label (vhdl-template-field "[label]" nil t))
8798 (unless label (delete-char 2))
8799 (forward-word 1)
8800 (forward-char 1))
8801 (when (setq index (vhdl-template-field "loop variable"
8802 nil t start (point)))
8803 (vhdl-insert-keyword " IN ")
8804 (vhdl-template-field "range")
8805 (vhdl-insert-keyword " LOOP\n\n")
8806 (indent-to margin)
8807 (vhdl-insert-keyword "END LOOP")
8808 (if label
8809 (insert " " label ";")
8810 (insert ";")
8811 (when vhdl-self-insert-comments (insert " -- " index)))
8812 (forward-line -1)
8813 (indent-to (+ margin vhdl-basic-offset)))))
8814
8815 (defun vhdl-template-function (&optional kind)
8816 "Insert a function declaration or body."
8817 (interactive)
8818 (let ((margin (current-indentation))
8819 (start (point))
8820 name)
8821 (vhdl-insert-keyword "FUNCTION ")
8822 (when (setq name (vhdl-template-field "name" nil t start (point)))
8823 (vhdl-template-argument-list t)
8824 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8825 (end-of-line)
8826 (insert "\n")
8827 (indent-to (+ margin vhdl-basic-offset))
8828 (vhdl-insert-keyword "RETURN ")
8829 (vhdl-template-field "type")
8830 (if (if kind (eq kind 'body)
8831 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8832 (progn (vhdl-insert-keyword " IS\n")
8833 (vhdl-template-begin-end
8834 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8835 (vhdl-comment-block))
8836 (insert ";")))))
8837
8838 (defun vhdl-template-function-decl ()
8839 "Insert a function declaration."
8840 (interactive)
8841 (vhdl-template-function 'decl))
8842
8843 (defun vhdl-template-function-body ()
8844 "Insert a function declaration."
8845 (interactive)
8846 (vhdl-template-function 'body))
8847
8848 (defun vhdl-template-generate ()
8849 "Insert a generation scheme."
8850 (interactive)
8851 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8852 (vhdl-template-if-generate)
8853 (vhdl-template-for-generate)))
8854
8855 (defun vhdl-template-generic ()
8856 "Insert generic declaration, or generic map in instantiation statements."
8857 (interactive)
8858 (let ((start (point)))
8859 (vhdl-prepare-search-1
8860 (cond
8861 ((and (save-excursion ; entity declaration
8862 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8863 (equal "ENTITY" (upcase (match-string 1))))
8864 (vhdl-template-generic-list nil))
8865 ((or (save-excursion
8866 (or (beginning-of-line)
8867 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8868 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8869 (vhdl-insert-keyword "GENERIC ")
8870 (vhdl-template-map start))
8871 (t (vhdl-template-generic-list nil t))))))
8872
8873 (defun vhdl-template-group ()
8874 "Insert group or group template declaration."
8875 (interactive)
8876 (let ((start (point)))
8877 (if (eq (vhdl-decision-query
8878 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8879 (vhdl-template-group-template)
8880 (vhdl-template-group-decl))))
8881
8882 (defun vhdl-template-group-decl ()
8883 "Insert group declaration."
8884 (interactive)
8885 (let ((start (point)))
8886 (vhdl-insert-keyword "GROUP ")
8887 (when (vhdl-template-field "name" " : " t start (point))
8888 (vhdl-template-field "template name" " (")
8889 (vhdl-template-field "constituent list" ");")
8890 (vhdl-comment-insert-inline))))
8891
8892 (defun vhdl-template-group-template ()
8893 "Insert group template declaration."
8894 (interactive)
8895 (let ((start (point)))
8896 (vhdl-insert-keyword "GROUP ")
8897 (when (vhdl-template-field "template name" nil t start (point))
8898 (vhdl-insert-keyword " IS (")
8899 (vhdl-template-field "entity class list" ");")
8900 (vhdl-comment-insert-inline))))
8901
8902 (defun vhdl-template-if ()
8903 "Insert a sequential if statement or an if-generate statement."
8904 (interactive)
8905 (if (vhdl-sequential-statement-p)
8906 (vhdl-template-if-then)
8907 (if (and (vhdl-standard-p 'ams)
8908 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8909 (vhdl-template-if-use)
8910 (vhdl-template-if-generate))))
8911
8912 (defun vhdl-template-if-generate ()
8913 "Insert an if-generate."
8914 (interactive)
8915 (let ((margin (current-indentation))
8916 (start (point))
8917 label position)
8918 (vhdl-insert-keyword ": IF ")
8919 (setq position (point-marker))
8920 (goto-char start)
8921 (when (setq label (vhdl-template-field "label" nil t start position))
8922 (goto-char position)
8923 (when vhdl-conditions-in-parenthesis (insert "("))
8924 (vhdl-template-field "condition")
8925 (when vhdl-conditions-in-parenthesis (insert ")"))
8926 (vhdl-template-generate-body margin label))))
8927
8928 (defun vhdl-template-if-then-use (kind)
8929 "Insert a sequential if statement."
8930 (interactive)
8931 (let ((margin (current-indentation))
8932 (start (point))
8933 label)
8934 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8935 (vhdl-insert-keyword "IF ")
8936 (vhdl-insert-keyword ": IF ")
8937 (goto-char start)
8938 (setq label (vhdl-template-field "[label]" nil t))
8939 (unless label (delete-char 2))
8940 (forward-word 1)
8941 (forward-char 1))
8942 (when vhdl-conditions-in-parenthesis (insert "("))
8943 (when (vhdl-template-field "condition" nil t start (point))
8944 (when vhdl-conditions-in-parenthesis (insert ")"))
8945 (vhdl-insert-keyword
8946 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8947 (indent-to margin)
8948 (vhdl-insert-keyword "END IF")
8949 (when label (insert " " label))
8950 (insert ";")
8951 (forward-line -1)
8952 (indent-to (+ margin vhdl-basic-offset)))))
8953
8954 (defun vhdl-template-if-then ()
8955 "Insert a sequential if statement."
8956 (interactive)
8957 (vhdl-template-if-then-use 'then))
8958
8959 (defun vhdl-template-if-use ()
8960 "Insert a simultaneous if statement."
8961 (interactive)
8962 (vhdl-template-if-then-use 'use))
8963
8964 (defun vhdl-template-instance ()
8965 "Insert a component instantiation statement."
8966 (interactive)
8967 (vhdl-template-component-inst))
8968
8969 (defun vhdl-template-library ()
8970 "Insert a library specification."
8971 (interactive)
8972 (let ((margin (current-indentation))
8973 (start (point))
8974 name end-pos)
8975 (vhdl-insert-keyword "LIBRARY ")
8976 (when (setq name (vhdl-template-field "names" nil t start (point)))
8977 (insert ";")
8978 (unless (string-match "," name)
8979 (setq end-pos (point))
8980 (insert "\n")
8981 (indent-to margin)
8982 (vhdl-insert-keyword "USE ")
8983 (insert name)
8984 (vhdl-insert-keyword "..ALL;")
8985 (backward-char 5)
8986 (if (vhdl-template-field "package name")
8987 (forward-char 5)
8988 (delete-region end-pos (+ (point) 5)))))))
8989
8990 (defun vhdl-template-limit ()
8991 "Insert a limit."
8992 (interactive)
8993 (let ((start (point)))
8994 (vhdl-insert-keyword "LIMIT ")
8995 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8996 t start (point))
8997 (vhdl-template-field "type")
8998 (vhdl-insert-keyword " WITH ")
8999 (vhdl-template-field "real expression" ";"))))
9000
9001 (defun vhdl-template-loop ()
9002 "Insert a loop."
9003 (interactive)
9004 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9005 (cond ((eq char ?w)
9006 (vhdl-template-while-loop))
9007 ((eq char ?f)
9008 (vhdl-template-for-loop))
9009 (t (vhdl-template-bare-loop)))))
9010
9011 (defun vhdl-template-bare-loop ()
9012 "Insert a loop."
9013 (interactive)
9014 (let ((margin (current-indentation))
9015 (start (point))
9016 label)
9017 (if (not (eq vhdl-optional-labels 'all))
9018 (vhdl-insert-keyword "LOOP ")
9019 (vhdl-insert-keyword ": LOOP ")
9020 (goto-char start)
9021 (setq label (vhdl-template-field "[label]" nil t))
9022 (unless label (delete-char 2))
9023 (forward-word 1)
9024 (delete-char 1))
9025 (insert "\n\n")
9026 (indent-to margin)
9027 (vhdl-insert-keyword "END LOOP")
9028 (insert (if label (concat " " label ";") ";"))
9029 (forward-line -1)
9030 (indent-to (+ margin vhdl-basic-offset))))
9031
9032 (defun vhdl-template-map (&optional start optional secondary)
9033 "Insert a map specification with association list."
9034 (interactive)
9035 (let ((start (or start (point)))
9036 margin end-pos)
9037 (vhdl-insert-keyword "MAP (")
9038 (if (not vhdl-association-list-with-formals)
9039 (if (vhdl-template-field
9040 (concat (and optional "[") "association list" (and optional "]"))
9041 ")" (or (not secondary) optional)
9042 (and (not secondary) start) (point))
9043 t
9044 (if (and optional secondary) (delete-region start (point)))
9045 nil)
9046 (if vhdl-argument-list-indent
9047 (setq margin (current-column))
9048 (setq margin (+ (current-indentation) vhdl-basic-offset))
9049 (insert "\n")
9050 (indent-to margin))
9051 (if (vhdl-template-field
9052 (concat (and optional "[") "formal" (and optional "]"))
9053 " => " (or (not secondary) optional)
9054 (and (not secondary) start) (point))
9055 (progn
9056 (vhdl-template-field "actual" ",")
9057 (setq end-pos (point))
9058 (insert "\n")
9059 (indent-to margin)
9060 (while (vhdl-template-field "[formal]" " => " t)
9061 (vhdl-template-field "actual" ",")
9062 (setq end-pos (point))
9063 (insert "\n")
9064 (indent-to margin))
9065 (delete-region end-pos (point))
9066 (delete-backward-char 1)
9067 (insert ")")
9068 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9069 t)
9070 (when (and optional secondary) (delete-region start (point)))
9071 nil))))
9072
9073 (defun vhdl-template-modify (&optional noerror)
9074 "Actualize modification date."
9075 (interactive)
9076 (vhdl-prepare-search-2
9077 (save-excursion
9078 (goto-char (point-min))
9079 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9080 (progn (delete-region (point) (progn (end-of-line) (point)))
9081 (vhdl-template-insert-date))
9082 (unless noerror
9083 (error "ERROR: Modification date prefix string \"%s\" not found"
9084 vhdl-modify-date-prefix-string))))))
9085
9086
9087 (defun vhdl-template-modify-noerror ()
9088 "Call `vhdl-template-modify' with NOERROR non-nil."
9089 (vhdl-template-modify t))
9090
9091 (defun vhdl-template-nature ()
9092 "Insert a nature declaration."
9093 (interactive)
9094 (let ((start (point))
9095 name mid-pos end-pos)
9096 (vhdl-insert-keyword "NATURE ")
9097 (when (setq name (vhdl-template-field "name" nil t start (point)))
9098 (vhdl-insert-keyword " IS ")
9099 (let ((definition
9100 (upcase
9101 (or (vhdl-template-field
9102 "across type | ARRAY | RECORD")
9103 ""))))
9104 (cond ((equal definition "")
9105 (insert ";"))
9106 ((equal definition "ARRAY")
9107 (delete-region (point) (progn (forward-word -1) (point)))
9108 (vhdl-template-array 'nature t))
9109 ((equal definition "RECORD")
9110 (setq mid-pos (point-marker))
9111 (delete-region (point) (progn (forward-word -1) (point)))
9112 (vhdl-template-record 'nature name t))
9113 (t
9114 (vhdl-insert-keyword " ACROSS ")
9115 (vhdl-template-field "through type")
9116 (vhdl-insert-keyword " THROUGH ")
9117 (vhdl-template-field "reference name")
9118 (vhdl-insert-keyword " REFERENCE;")))
9119 (when mid-pos
9120 (setq end-pos (point-marker))
9121 (goto-char mid-pos)
9122 (end-of-line))
9123 (vhdl-comment-insert-inline)
9124 (when end-pos (goto-char end-pos))))))
9125
9126 (defun vhdl-template-next ()
9127 "Insert a next statement."
9128 (interactive)
9129 (let ((start (point)))
9130 (vhdl-insert-keyword "NEXT ")
9131 (if (vhdl-template-field "[loop label]" nil t start (point))
9132 (let ((position (point)))
9133 (vhdl-insert-keyword " WHEN ")
9134 (when vhdl-conditions-in-parenthesis (insert "("))
9135 (if (vhdl-template-field "[condition]" nil t)
9136 (when vhdl-conditions-in-parenthesis (insert ")"))
9137 (delete-region position (point))))
9138 (delete-char -1))
9139 (insert ";")))
9140
9141 (defun vhdl-template-others ()
9142 "Insert an others aggregate."
9143 (interactive)
9144 (let ((start (point)))
9145 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9146 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9147 (vhdl-insert-keyword "OTHERS => '")
9148 (when (vhdl-template-field "value" nil t start (point))
9149 (insert "')")))
9150 (vhdl-insert-keyword "OTHERS "))))
9151
9152 (defun vhdl-template-package (&optional kind)
9153 "Insert a package specification or body."
9154 (interactive)
9155 (let ((margin (current-indentation))
9156 (start (point))
9157 name body position)
9158 (vhdl-insert-keyword "PACKAGE ")
9159 (setq body (if kind (eq kind 'body)
9160 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9161 (when body
9162 (vhdl-insert-keyword "BODY ")
9163 (when (save-excursion
9164 (vhdl-prepare-search-1
9165 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9166 (insert (setq name (match-string 1)))))
9167 (when (or name
9168 (setq name (vhdl-template-field "name" nil t start (point))))
9169 (vhdl-insert-keyword " IS\n")
9170 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9171 (indent-to (+ margin vhdl-basic-offset))
9172 (setq position (point))
9173 (insert "\n")
9174 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9175 (indent-to margin)
9176 (vhdl-insert-keyword "END ")
9177 (unless (vhdl-standard-p '87)
9178 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9179 (insert (or name "") ";")
9180 (goto-char position))))
9181
9182 (defun vhdl-template-package-decl ()
9183 "Insert a package specification."
9184 (interactive)
9185 (vhdl-template-package 'decl))
9186
9187 (defun vhdl-template-package-body ()
9188 "Insert a package body."
9189 (interactive)
9190 (vhdl-template-package 'body))
9191
9192 (defun vhdl-template-port ()
9193 "Insert a port declaration, or port map in instantiation statements."
9194 (interactive)
9195 (let ((start (point)))
9196 (vhdl-prepare-search-1
9197 (cond
9198 ((and (save-excursion ; entity declaration
9199 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9200 (equal "ENTITY" (upcase (match-string 1))))
9201 (vhdl-template-port-list nil))
9202 ((or (save-excursion
9203 (or (beginning-of-line)
9204 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9205 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9206 (vhdl-insert-keyword "PORT ")
9207 (vhdl-template-map start))
9208 (t (vhdl-template-port-list nil))))))
9209
9210 (defun vhdl-template-procedural ()
9211 "Insert a procedural."
9212 (interactive)
9213 (let ((margin (current-indentation))
9214 (start (point))
9215 (case-fold-search t)
9216 label)
9217 (vhdl-insert-keyword "PROCEDURAL ")
9218 (when (memq vhdl-optional-labels '(process all))
9219 (goto-char start)
9220 (insert ": ")
9221 (goto-char start)
9222 (setq label (vhdl-template-field "[label]" nil t))
9223 (unless label (delete-char 2))
9224 (forward-word 1)
9225 (forward-char 1))
9226 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9227 (insert "\n")
9228 (vhdl-template-begin-end "PROCEDURAL" label margin)
9229 (vhdl-comment-block)))
9230
9231 (defun vhdl-template-procedure (&optional kind)
9232 "Insert a procedure declaration or body."
9233 (interactive)
9234 (let ((margin (current-indentation))
9235 (start (point))
9236 name)
9237 (vhdl-insert-keyword "PROCEDURE ")
9238 (when (setq name (vhdl-template-field "name" nil t start (point)))
9239 (vhdl-template-argument-list)
9240 (if (if kind (eq kind 'body)
9241 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9242 (progn (vhdl-insert-keyword " IS")
9243 (when vhdl-auto-align
9244 (vhdl-align-region-groups start (point) 1))
9245 (end-of-line) (insert "\n")
9246 (vhdl-template-begin-end
9247 (unless (vhdl-standard-p '87) "PROCEDURE")
9248 name margin)
9249 (vhdl-comment-block))
9250 (insert ";")
9251 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9252 (end-of-line)))))
9253
9254 (defun vhdl-template-procedure-decl ()
9255 "Insert a procedure declaration."
9256 (interactive)
9257 (vhdl-template-procedure 'decl))
9258
9259 (defun vhdl-template-procedure-body ()
9260 "Insert a procedure body."
9261 (interactive)
9262 (vhdl-template-procedure 'body))
9263
9264 (defun vhdl-template-process (&optional kind)
9265 "Insert a process."
9266 (interactive)
9267 (let ((margin (current-indentation))
9268 (start (point))
9269 label seq input-signals clock reset final-pos)
9270 (setq seq (if kind (eq kind 'seq)
9271 (eq (vhdl-decision-query
9272 "process" "(c)ombinational or (s)equential?" t) ?s)))
9273 (vhdl-insert-keyword "PROCESS ")
9274 (when (memq vhdl-optional-labels '(process all))
9275 (goto-char start)
9276 (insert ": ")
9277 (goto-char start)
9278 (setq label (vhdl-template-field "[label]" nil t))
9279 (unless label (delete-char 2))
9280 (forward-word 1)
9281 (forward-char 1))
9282 (insert "(")
9283 (if (not seq)
9284 (unless (setq input-signals
9285 (vhdl-template-field "[sensitivity list]" ")" t))
9286 (setq input-signals "")
9287 (delete-char -2))
9288 (setq clock (or (and (not (equal "" vhdl-clock-name))
9289 (progn (insert vhdl-clock-name) vhdl-clock-name))
9290 (vhdl-template-field "clock name") "<clock>"))
9291 (when (eq vhdl-reset-kind 'async)
9292 (insert ", ")
9293 (setq reset (or (and (not (equal "" vhdl-reset-name))
9294 (progn (insert vhdl-reset-name) vhdl-reset-name))
9295 (vhdl-template-field "reset name") "<reset>")))
9296 (insert ")"))
9297 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9298 (insert "\n")
9299 (vhdl-template-begin-end "PROCESS" label margin)
9300 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9301 (when vhdl-prompt-for-comments
9302 (setq final-pos (point-marker))
9303 (vhdl-prepare-search-2
9304 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9305 (vhdl-re-search-backward "\\<process\\>" nil t))
9306 (end-of-line -0)
9307 (if (bobp)
9308 (progn (insert "\n") (forward-line -1))
9309 (insert "\n"))
9310 (indent-to margin)
9311 (insert "-- purpose: ")
9312 (if (not (vhdl-template-field "[description]" nil t))
9313 (vhdl-line-kill-entire)
9314 (insert "\n")
9315 (indent-to margin)
9316 (insert "-- type : ")
9317 (insert (if seq "sequential" "combinational") "\n")
9318 (indent-to margin)
9319 (insert "-- inputs : ")
9320 (if (not seq)
9321 (insert input-signals)
9322 (insert clock ", ")
9323 (when reset (insert reset ", "))
9324 (unless (vhdl-template-field "[signal names]" nil t)
9325 (delete-char -2)))
9326 (insert "\n")
9327 (indent-to margin)
9328 (insert "-- outputs: ")
9329 (vhdl-template-field "[signal names]" nil t))))
9330 (goto-char final-pos))))
9331
9332 (defun vhdl-template-process-comb ()
9333 "Insert a combinational process."
9334 (interactive)
9335 (vhdl-template-process 'comb))
9336
9337 (defun vhdl-template-process-seq ()
9338 "Insert a sequential process."
9339 (interactive)
9340 (vhdl-template-process 'seq))
9341
9342 (defun vhdl-template-quantity ()
9343 "Insert a quantity declaration."
9344 (interactive)
9345 (if (vhdl-in-argument-list-p)
9346 (let ((start (point)))
9347 (vhdl-insert-keyword "QUANTITY ")
9348 (when (vhdl-template-field "names" nil t start (point))
9349 (insert " : ")
9350 (vhdl-template-field "[IN | OUT]" " " t)
9351 (vhdl-template-field "type")
9352 (insert ";")
9353 (vhdl-comment-insert-inline)))
9354 (let ((char (vhdl-decision-query
9355 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9356 (cond ((eq char ?f) (vhdl-template-quantity-free))
9357 ((eq char ?b) (vhdl-template-quantity-branch))
9358 ((eq char ?s) (vhdl-template-quantity-source))
9359 (t (vhdl-template-undo (point) (point)))))))
9360
9361 (defun vhdl-template-quantity-free ()
9362 "Insert a free quantity declaration."
9363 (interactive)
9364 (vhdl-insert-keyword "QUANTITY ")
9365 (vhdl-template-field "names")
9366 (insert " : ")
9367 (vhdl-template-field "type")
9368 (let ((position (point)))
9369 (insert " := ")
9370 (unless (vhdl-template-field "[initialization]" nil t)
9371 (delete-region position (point)))
9372 (insert ";")
9373 (vhdl-comment-insert-inline)))
9374
9375 (defun vhdl-template-quantity-branch ()
9376 "Insert a branch quantity declaration."
9377 (interactive)
9378 (let (position)
9379 (vhdl-insert-keyword "QUANTITY ")
9380 (when (vhdl-template-field "[across names]" " " t)
9381 (vhdl-insert-keyword "ACROSS "))
9382 (when (vhdl-template-field "[through names]" " " t)
9383 (vhdl-insert-keyword "THROUGH "))
9384 (vhdl-template-field "plus terminal name")
9385 (setq position (point))
9386 (vhdl-insert-keyword " TO ")
9387 (unless (vhdl-template-field "[minus terminal name]" nil t)
9388 (delete-region position (point)))
9389 (insert ";")
9390 (vhdl-comment-insert-inline)))
9391
9392 (defun vhdl-template-quantity-source ()
9393 "Insert a source quantity declaration."
9394 (interactive)
9395 (vhdl-insert-keyword "QUANTITY ")
9396 (vhdl-template-field "names")
9397 (insert " : ")
9398 (vhdl-template-field "type" " ")
9399 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9400 (progn (vhdl-insert-keyword "NOISE ")
9401 (vhdl-template-field "power expression"))
9402 (vhdl-insert-keyword "SPECTRUM ")
9403 (vhdl-template-field "magnitude expression" ", ")
9404 (vhdl-template-field "phase expression"))
9405 (insert ";")
9406 (vhdl-comment-insert-inline))
9407
9408 (defun vhdl-template-record (kind &optional name secondary)
9409 "Insert a record type declaration."
9410 (interactive)
9411 (let ((margin (current-column))
9412 (start (point))
9413 (first t))
9414 (vhdl-insert-keyword "RECORD\n")
9415 (indent-to (+ margin vhdl-basic-offset))
9416 (when (or (vhdl-template-field "element names"
9417 nil (not secondary) start (point))
9418 secondary)
9419 (while (or first (vhdl-template-field "[element names]" nil t))
9420 (insert " : ")
9421 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9422 (vhdl-comment-insert-inline)
9423 (insert "\n")
9424 (indent-to (+ margin vhdl-basic-offset))
9425 (setq first nil))
9426 (delete-region (line-beginning-position) (point))
9427 (indent-to margin)
9428 (vhdl-insert-keyword "END RECORD")
9429 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9430 (insert ";")
9431 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9432
9433 (defun vhdl-template-report ()
9434 "Insert a report statement."
9435 (interactive)
9436 (let ((start (point)))
9437 (vhdl-insert-keyword "REPORT ")
9438 (if (equal "\"\"" (vhdl-template-field
9439 "string expression" nil t start (point) t))
9440 (delete-backward-char 2)
9441 (setq start (point))
9442 (vhdl-insert-keyword " SEVERITY ")
9443 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9444 (delete-region start (point)))
9445 (insert ";"))))
9446
9447 (defun vhdl-template-return ()
9448 "Insert a return statement."
9449 (interactive)
9450 (let ((start (point)))
9451 (vhdl-insert-keyword "RETURN ")
9452 (unless (vhdl-template-field "[expression]" nil t start (point))
9453 (delete-char -1))
9454 (insert ";")))
9455
9456 (defun vhdl-template-selected-signal-asst ()
9457 "Insert a selected signal assignment."
9458 (interactive)
9459 (let ((margin (current-indentation))
9460 (start (point))
9461 (choices t))
9462 (let ((position (point)))
9463 (vhdl-insert-keyword " SELECT ")
9464 (goto-char position))
9465 (vhdl-insert-keyword "WITH ")
9466 (when (vhdl-template-field "selector expression"
9467 nil t start (+ (point) 7))
9468 (forward-word 1)
9469 (delete-char 1)
9470 (insert "\n")
9471 (indent-to (+ margin vhdl-basic-offset))
9472 (vhdl-template-field "target signal" " <= ")
9473 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9474 (insert "\n")
9475 (indent-to (+ margin vhdl-basic-offset))
9476 (vhdl-template-field "waveform")
9477 (vhdl-insert-keyword " WHEN ")
9478 (vhdl-template-field "choices" ",")
9479 (insert "\n")
9480 (indent-to (+ margin vhdl-basic-offset))
9481 (while (and choices (vhdl-template-field "[waveform]" nil t))
9482 (vhdl-insert-keyword " WHEN ")
9483 (if (setq choices (vhdl-template-field "[choices]" "," t))
9484 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9485 (vhdl-insert-keyword "OTHERS")))
9486 (when choices
9487 (fixup-whitespace)
9488 (delete-char -2))
9489 (insert ";")
9490 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9491
9492 (defun vhdl-template-signal ()
9493 "Insert a signal declaration."
9494 (interactive)
9495 (let ((start (point))
9496 (in-arglist (vhdl-in-argument-list-p)))
9497 (vhdl-insert-keyword "SIGNAL ")
9498 (when (vhdl-template-field "names" nil t start (point))
9499 (insert " : ")
9500 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9501 (vhdl-template-field "type")
9502 (if in-arglist
9503 (progn (insert ";")
9504 (vhdl-comment-insert-inline))
9505 (let ((position (point)))
9506 (insert " := ")
9507 (unless (vhdl-template-field "[initialization]" nil t)
9508 (delete-region position (point)))
9509 (insert ";")
9510 (vhdl-comment-insert-inline))))))
9511
9512 (defun vhdl-template-subnature ()
9513 "Insert a subnature declaration."
9514 (interactive)
9515 (let ((start (point))
9516 position)
9517 (vhdl-insert-keyword "SUBNATURE ")
9518 (when (vhdl-template-field "name" nil t start (point))
9519 (vhdl-insert-keyword " IS ")
9520 (vhdl-template-field "nature" " (")
9521 (if (vhdl-template-field "[index range]" nil t)
9522 (insert ")")
9523 (delete-char -2))
9524 (setq position (point))
9525 (vhdl-insert-keyword " TOLERANCE ")
9526 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9527 nil t nil nil t))
9528 (delete-region position (point))
9529 (vhdl-insert-keyword " ACROSS ")
9530 (vhdl-template-field "string expression" nil nil nil nil t)
9531 (vhdl-insert-keyword " THROUGH"))
9532 (insert ";")
9533 (vhdl-comment-insert-inline))))
9534
9535 (defun vhdl-template-subprogram-body ()
9536 "Insert a subprogram body."
9537 (interactive)
9538 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9539 (vhdl-template-function-body)
9540 (vhdl-template-procedure-body)))
9541
9542 (defun vhdl-template-subprogram-decl ()
9543 "Insert a subprogram declaration."
9544 (interactive)
9545 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9546 (vhdl-template-function-decl)
9547 (vhdl-template-procedure-decl)))
9548
9549 (defun vhdl-template-subtype ()
9550 "Insert a subtype declaration."
9551 (interactive)
9552 (let ((start (point)))
9553 (vhdl-insert-keyword "SUBTYPE ")
9554 (when (vhdl-template-field "name" nil t start (point))
9555 (vhdl-insert-keyword " IS ")
9556 (vhdl-template-field "type" " ")
9557 (unless
9558 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9559 (delete-char -1))
9560 (insert ";")
9561 (vhdl-comment-insert-inline))))
9562
9563 (defun vhdl-template-terminal ()
9564 "Insert a terminal declaration."
9565 (interactive)
9566 (let ((start (point)))
9567 (vhdl-insert-keyword "TERMINAL ")
9568 (when (vhdl-template-field "names" nil t start (point))
9569 (insert " : ")
9570 (vhdl-template-field "nature")
9571 (insert ";")
9572 (vhdl-comment-insert-inline))))
9573
9574 (defun vhdl-template-type ()
9575 "Insert a type declaration."
9576 (interactive)
9577 (let ((start (point))
9578 name mid-pos end-pos)
9579 (vhdl-insert-keyword "TYPE ")
9580 (when (setq name (vhdl-template-field "name" nil t start (point)))
9581 (vhdl-insert-keyword " IS ")
9582 (let ((definition
9583 (upcase
9584 (or (vhdl-template-field
9585 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9586 ""))))
9587 (cond ((equal definition "")
9588 (delete-backward-char 4)
9589 (insert ";"))
9590 ((equal definition "ARRAY")
9591 (delete-region (point) (progn (forward-word -1) (point)))
9592 (vhdl-template-array 'type t))
9593 ((equal definition "RECORD")
9594 (setq mid-pos (point-marker))
9595 (delete-region (point) (progn (forward-word -1) (point)))
9596 (vhdl-template-record 'type name t))
9597 ((equal definition "ACCESS")
9598 (insert " ")
9599 (vhdl-template-field "type" ";"))
9600 ((equal definition "FILE")
9601 (vhdl-insert-keyword " OF ")
9602 (vhdl-template-field "type" ";"))
9603 (t (insert ";")))
9604 (when mid-pos
9605 (setq end-pos (point-marker))
9606 (goto-char mid-pos)
9607 (end-of-line))
9608 (vhdl-comment-insert-inline)
9609 (when end-pos (goto-char end-pos))))))
9610
9611 (defun vhdl-template-use ()
9612 "Insert a use clause."
9613 (interactive)
9614 (let ((start (point)))
9615 (vhdl-prepare-search-1
9616 (vhdl-insert-keyword "USE ")
9617 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9618 (vhdl-insert-keyword "..ALL;")
9619 (backward-char 6)
9620 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9621 (forward-char 1)
9622 (vhdl-template-field "package name")
9623 (forward-char 5))))))
9624
9625 (defun vhdl-template-variable ()
9626 "Insert a variable declaration."
9627 (interactive)
9628 (let ((start (point))
9629 (in-arglist (vhdl-in-argument-list-p)))
9630 (vhdl-prepare-search-2
9631 (if (or (save-excursion
9632 (and (vhdl-re-search-backward
9633 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9634 nil t)
9635 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9636 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9637 (vhdl-insert-keyword "VARIABLE ")
9638 (vhdl-insert-keyword "SHARED VARIABLE ")))
9639 (when (vhdl-template-field "names" nil t start (point))
9640 (insert " : ")
9641 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9642 (vhdl-template-field "type")
9643 (if in-arglist
9644 (progn (insert ";")
9645 (vhdl-comment-insert-inline))
9646 (let ((position (point)))
9647 (insert " := ")
9648 (unless (vhdl-template-field "[initialization]" nil t)
9649 (delete-region position (point)))
9650 (insert ";")
9651 (vhdl-comment-insert-inline))))))
9652
9653 (defun vhdl-template-wait ()
9654 "Insert a wait statement."
9655 (interactive)
9656 (vhdl-insert-keyword "WAIT ")
9657 (unless (vhdl-template-field
9658 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9659 nil t)
9660 (delete-char -1))
9661 (insert ";"))
9662
9663 (defun vhdl-template-when ()
9664 "Indent correctly if within a case statement."
9665 (interactive)
9666 (let ((position (point))
9667 margin)
9668 (vhdl-prepare-search-2
9669 (if (and (= (current-column) (current-indentation))
9670 (vhdl-re-search-forward "\\<end\\>" nil t)
9671 (looking-at "\\s-*\\<case\\>"))
9672 (progn
9673 (setq margin (current-indentation))
9674 (goto-char position)
9675 (delete-horizontal-space)
9676 (indent-to (+ margin vhdl-basic-offset)))
9677 (goto-char position)))
9678 (vhdl-insert-keyword "WHEN ")))
9679
9680 (defun vhdl-template-while-loop ()
9681 "Insert a while loop."
9682 (interactive)
9683 (let* ((margin (current-indentation))
9684 (start (point))
9685 label)
9686 (if (not (eq vhdl-optional-labels 'all))
9687 (vhdl-insert-keyword "WHILE ")
9688 (vhdl-insert-keyword ": WHILE ")
9689 (goto-char start)
9690 (setq label (vhdl-template-field "[label]" nil t))
9691 (unless label (delete-char 2))
9692 (forward-word 1)
9693 (forward-char 1))
9694 (when vhdl-conditions-in-parenthesis (insert "("))
9695 (when (vhdl-template-field "condition" nil t start (point))
9696 (when vhdl-conditions-in-parenthesis (insert ")"))
9697 (vhdl-insert-keyword " LOOP\n\n")
9698 (indent-to margin)
9699 (vhdl-insert-keyword "END LOOP")
9700 (insert (if label (concat " " label ";") ";"))
9701 (forward-line -1)
9702 (indent-to (+ margin vhdl-basic-offset)))))
9703
9704 (defun vhdl-template-with ()
9705 "Insert a with statement (i.e. selected signal assignment)."
9706 (interactive)
9707 (vhdl-prepare-search-1
9708 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9709 (equal ";" (match-string 1)))
9710 (vhdl-template-selected-signal-asst)
9711 (vhdl-insert-keyword "WITH "))))
9712
9713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9714 ;; Special templates
9715
9716 (defun vhdl-template-clocked-wait ()
9717 "Insert a wait statement for rising/falling clock edge."
9718 (interactive)
9719 (let ((start (point))
9720 clock)
9721 (vhdl-insert-keyword "WAIT UNTIL ")
9722 (when (setq clock
9723 (or (and (not (equal "" vhdl-clock-name))
9724 (progn (insert vhdl-clock-name) vhdl-clock-name))
9725 (vhdl-template-field "clock name" nil t start (point))))
9726 (insert "'event")
9727 (vhdl-insert-keyword " AND ")
9728 (insert clock)
9729 (insert
9730 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9731 (vhdl-comment-insert-inline
9732 (concat (if vhdl-clock-rising-edge "rising" "falling")
9733 " clock edge")))))
9734
9735 (defun vhdl-template-seq-process (clock reset)
9736 "Insert a template for the body of a sequential process."
9737 (let ((margin (current-indentation))
9738 position)
9739 (vhdl-insert-keyword "IF ")
9740 (when (eq vhdl-reset-kind 'async)
9741 (insert reset " = "
9742 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9743 (vhdl-insert-keyword " THEN")
9744 (vhdl-comment-insert-inline
9745 (concat "asynchronous reset (active "
9746 (if vhdl-reset-active-high "high" "low") ")"))
9747 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9748 (setq position (point))
9749 (insert "\n") (indent-to margin)
9750 (vhdl-insert-keyword "ELSIF "))
9751 (if (eq vhdl-clock-edge-condition 'function)
9752 (insert (if vhdl-clock-rising-edge "rising" "falling")
9753 "_edge(" clock ")")
9754 (insert clock "'event")
9755 (vhdl-insert-keyword " AND ")
9756 (insert clock " = "
9757 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9758 (vhdl-insert-keyword " THEN")
9759 (vhdl-comment-insert-inline
9760 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9761 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9762 (when (eq vhdl-reset-kind 'sync)
9763 (vhdl-insert-keyword "IF ")
9764 (setq reset (or (and (not (equal "" vhdl-reset-name))
9765 (progn (insert vhdl-reset-name) vhdl-reset-name))
9766 (vhdl-template-field "reset name") "<reset>"))
9767 (insert " = "
9768 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9769 (vhdl-insert-keyword " THEN")
9770 (vhdl-comment-insert-inline
9771 (concat "synchronous reset (active "
9772 (if vhdl-reset-active-high "high" "low") ")"))
9773 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9774 (setq position (point))
9775 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9776 (vhdl-insert-keyword "ELSE")
9777 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9778 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9779 (vhdl-insert-keyword "END IF;"))
9780 (when (eq vhdl-reset-kind 'none)
9781 (setq position (point)))
9782 (insert "\n") (indent-to margin)
9783 (vhdl-insert-keyword "END IF;")
9784 (goto-char position)
9785 reset))
9786
9787 (defun vhdl-template-standard-package (library package)
9788 "Insert specification of a standard package. Include a library
9789 specification, if not already there."
9790 (let ((margin (current-indentation)))
9791 (unless (equal library "std")
9792 (unless (or (save-excursion
9793 (vhdl-prepare-search-1
9794 (and (not (bobp))
9795 (re-search-backward
9796 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9797 library "\\|end\\)\\>") nil t)
9798 (match-string 2))))
9799 (equal (downcase library) "work"))
9800 (vhdl-insert-keyword "LIBRARY ")
9801 (insert library ";")
9802 (when package
9803 (insert "\n")
9804 (indent-to margin)))
9805 (when package
9806 (vhdl-insert-keyword "USE ")
9807 (insert library "." package)
9808 (vhdl-insert-keyword ".ALL;")))))
9809
9810 (defun vhdl-template-package-math-complex ()
9811 "Insert specification of `math_complex' package."
9812 (interactive)
9813 (vhdl-template-standard-package "ieee" "math_complex"))
9814
9815 (defun vhdl-template-package-math-real ()
9816 "Insert specification of `math_real' package."
9817 (interactive)
9818 (vhdl-template-standard-package "ieee" "math_real"))
9819
9820 (defun vhdl-template-package-numeric-bit ()
9821 "Insert specification of `numeric_bit' package."
9822 (interactive)
9823 (vhdl-template-standard-package "ieee" "numeric_bit"))
9824
9825 (defun vhdl-template-package-numeric-std ()
9826 "Insert specification of `numeric_std' package."
9827 (interactive)
9828 (vhdl-template-standard-package "ieee" "numeric_std"))
9829
9830 (defun vhdl-template-package-std-logic-1164 ()
9831 "Insert specification of `std_logic_1164' package."
9832 (interactive)
9833 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9834
9835 (defun vhdl-template-package-std-logic-arith ()
9836 "Insert specification of `std_logic_arith' package."
9837 (interactive)
9838 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9839
9840 (defun vhdl-template-package-std-logic-misc ()
9841 "Insert specification of `std_logic_misc' package."
9842 (interactive)
9843 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9844
9845 (defun vhdl-template-package-std-logic-signed ()
9846 "Insert specification of `std_logic_signed' package."
9847 (interactive)
9848 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9849
9850 (defun vhdl-template-package-std-logic-textio ()
9851 "Insert specification of `std_logic_textio' package."
9852 (interactive)
9853 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9854
9855 (defun vhdl-template-package-std-logic-unsigned ()
9856 "Insert specification of `std_logic_unsigned' package."
9857 (interactive)
9858 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9859
9860 (defun vhdl-template-package-textio ()
9861 "Insert specification of `textio' package."
9862 (interactive)
9863 (vhdl-template-standard-package "std" "textio"))
9864
9865 (defun vhdl-template-directive (directive)
9866 "Insert directive."
9867 (unless (= (current-indentation) (current-column))
9868 (delete-horizontal-space)
9869 (insert " "))
9870 (insert "-- pragma " directive))
9871
9872 (defun vhdl-template-directive-translate-on ()
9873 "Insert directive 'translate_on'."
9874 (interactive)
9875 (vhdl-template-directive "translate_on"))
9876
9877 (defun vhdl-template-directive-translate-off ()
9878 "Insert directive 'translate_off'."
9879 (interactive)
9880 (vhdl-template-directive "translate_off"))
9881
9882 (defun vhdl-template-directive-synthesis-on ()
9883 "Insert directive 'synthesis_on'."
9884 (interactive)
9885 (vhdl-template-directive "synthesis_on"))
9886
9887 (defun vhdl-template-directive-synthesis-off ()
9888 "Insert directive 'synthesis_off'."
9889 (interactive)
9890 (vhdl-template-directive "synthesis_off"))
9891
9892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9893 ;; Header and footer templates
9894
9895 (defun vhdl-template-header (&optional file-title)
9896 "Insert a VHDL file header."
9897 (interactive)
9898 (unless (equal vhdl-file-header "")
9899 (let (pos)
9900 (save-excursion
9901 (goto-char (point-min))
9902 (vhdl-insert-string-or-file vhdl-file-header)
9903 (setq pos (point-marker)))
9904 (vhdl-template-replace-header-keywords
9905 (point-min-marker) pos file-title))))
9906
9907 (defun vhdl-template-footer ()
9908 "Insert a VHDL file footer."
9909 (interactive)
9910 (unless (equal vhdl-file-footer "")
9911 (let (pos)
9912 (save-excursion
9913 (goto-char (point-max))
9914 (setq pos (point-marker))
9915 (vhdl-insert-string-or-file vhdl-file-footer)
9916 (unless (= (preceding-char) ?\n)
9917 (insert "\n")))
9918 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9919
9920 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9921 is-model)
9922 "Replace keywords in header and footer."
9923 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9924 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9925 pos)
9926 (vhdl-prepare-search-2
9927 (save-excursion
9928 (goto-char beg)
9929 (while (search-forward "<projectdesc>" end t)
9930 (replace-match project-desc t t))
9931 (goto-char beg)
9932 (while (search-forward "<filename>" end t)
9933 (replace-match (buffer-name) t t))
9934 (goto-char beg)
9935 (while (search-forward "<copyright>" end t)
9936 (replace-match vhdl-copyright-string t t))
9937 (goto-char beg)
9938 (while (search-forward "<author>" end t)
9939 (replace-match "" t t)
9940 (insert (user-full-name))
9941 (when user-mail-address (insert " <" user-mail-address ">")))
9942 (goto-char beg)
9943 (while (search-forward "<login>" end t)
9944 (replace-match (user-login-name) t t))
9945 (goto-char beg)
9946 (while (search-forward "<project>" end t)
9947 (replace-match project-title t t))
9948 (goto-char beg)
9949 (while (search-forward "<company>" end t)
9950 (replace-match vhdl-company-name t t))
9951 (goto-char beg)
9952 (while (search-forward "<platform>" end t)
9953 (replace-match vhdl-platform-spec t t))
9954 (goto-char beg)
9955 (while (search-forward "<standard>" end t)
9956 (replace-match
9957 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9958 ((vhdl-standard-p '93) "'93"))
9959 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9960 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9961 (goto-char beg)
9962 ;; Replace <RCS> with $, so that RCS for the source is
9963 ;; not over-enthusiastic with replacements
9964 (while (search-forward "<RCS>" end t)
9965 (replace-match "$" nil t))
9966 (goto-char beg)
9967 (while (search-forward "<date>" end t)
9968 (replace-match "" t t)
9969 (vhdl-template-insert-date))
9970 (goto-char beg)
9971 (while (search-forward "<year>" end t)
9972 (replace-match (format-time-string "%Y" nil) t t))
9973 (goto-char beg)
9974 (when file-title
9975 (while (search-forward "<title string>" end t)
9976 (replace-match file-title t t))
9977 (goto-char beg))
9978 (let (string)
9979 (while
9980 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9981 (setq string (read-string (concat (match-string 1) ": ")))
9982 (replace-match string t t)))
9983 (goto-char beg)
9984 (when (and (not is-model) (search-forward "<cursor>" end t))
9985 (replace-match "" t t)
9986 (setq pos (point))))
9987 (when pos (goto-char pos))
9988 (unless is-model
9989 (when (or (not project-title) (equal project-title ""))
9990 (message "You can specify a project title in user option `vhdl-project-alist'"))
9991 (when (or (not project-desc) (equal project-desc ""))
9992 (message "You can specify a project description in user option `vhdl-project-alist'"))
9993 (when (equal vhdl-platform-spec "")
9994 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9995 (when (equal vhdl-company-name "")
9996 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9997
9998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9999 ;; Comment templates and functions
10000
10001 (defun vhdl-comment-indent ()
10002 "Indent comments."
10003 (let* ((position (point))
10004 (col
10005 (progn
10006 (forward-line -1)
10007 (if (re-search-forward "--" position t)
10008 (- (current-column) 2) ; existing comment at bol stays there
10009 (goto-char position)
10010 (skip-chars-backward " \t")
10011 (max comment-column ; else indent to comment column
10012 (1+ (current-column))))))) ; except leave at least one space
10013 (goto-char position)
10014 col))
10015
10016 (defun vhdl-comment-insert ()
10017 "Start a comment at the end of the line.
10018 If on line with code, indent at least `comment-column'.
10019 If starting after end-comment-column, start a new line."
10020 (interactive)
10021 (when (> (current-column) end-comment-column) (newline-and-indent))
10022 (if (or (looking-at "\\s-*$") ; end of line
10023 (and (not unread-command-events) ; called with key binding or menu
10024 (not (end-of-line))))
10025 (let (margin)
10026 (while (= (preceding-char) ?-) (delete-char -1))
10027 (setq margin (current-column))
10028 (delete-horizontal-space)
10029 (if (bolp)
10030 (progn (indent-to margin) (insert "--"))
10031 (insert " ")
10032 (indent-to comment-column)
10033 (insert "--"))
10034 (if (not unread-command-events) (insert " ")))
10035 ;; else code following current point implies commenting out code
10036 (let (next-input code)
10037 (while (= (preceding-char) ?-) (delete-char -2))
10038 (while (= (setq next-input (read-char)) 13) ; CR
10039 (insert "--") ; or have a space after it?
10040 (forward-char -2)
10041 (forward-line 1)
10042 (message "Enter CR if commenting out a line of code.")
10043 (setq code t))
10044 (unless code
10045 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10046 (setq unread-command-events
10047 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10048
10049 (defun vhdl-comment-display (&optional line-exists)
10050 "Add 2 comment lines at the current indent, making a display comment."
10051 (interactive)
10052 (let ((margin (current-indentation)))
10053 (unless line-exists (vhdl-comment-display-line))
10054 (insert "\n") (indent-to margin)
10055 (insert "\n") (indent-to margin)
10056 (vhdl-comment-display-line)
10057 (end-of-line -0)
10058 (insert "-- ")))
10059
10060 (defun vhdl-comment-display-line ()
10061 "Displays one line of dashes."
10062 (interactive)
10063 (while (= (preceding-char) ?-) (delete-char -2))
10064 (let* ((col (current-column))
10065 (len (- end-comment-column col)))
10066 (insert-char ?- len)))
10067
10068 (defun vhdl-comment-append-inline ()
10069 "Append empty inline comment to current line."
10070 (interactive)
10071 (end-of-line)
10072 (delete-horizontal-space)
10073 (insert " ")
10074 (indent-to comment-column)
10075 (insert "-- "))
10076
10077 (defun vhdl-comment-insert-inline (&optional string always-insert)
10078 "Insert inline comment."
10079 (when (or (and string (or vhdl-self-insert-comments always-insert))
10080 (and (not string) vhdl-prompt-for-comments))
10081 (let ((position (point)))
10082 (insert " ")
10083 (indent-to comment-column)
10084 (insert "-- ")
10085 (if (not (or (and string (progn (insert string) t))
10086 (vhdl-template-field "[comment]" nil t)))
10087 (delete-region position (point))
10088 (while (= (preceding-char) ? ) (delete-backward-char 1))
10089 ; (when (> (current-column) end-comment-column)
10090 ; (setq position (point-marker))
10091 ; (re-search-backward "-- ")
10092 ; (insert "\n")
10093 ; (indent-to comment-column)
10094 ; (goto-char position))
10095 ))))
10096
10097 (defun vhdl-comment-block ()
10098 "Insert comment for code block."
10099 (when vhdl-prompt-for-comments
10100 (let ((final-pos (point-marker)))
10101 (vhdl-prepare-search-2
10102 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10103 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10104 (let (margin)
10105 (back-to-indentation)
10106 (setq margin (current-column))
10107 (end-of-line -0)
10108 (if (bobp)
10109 (progn (insert "\n") (forward-line -1))
10110 (insert "\n"))
10111 (indent-to margin)
10112 (insert "-- purpose: ")
10113 (unless (vhdl-template-field "[description]" nil t)
10114 (vhdl-line-kill-entire)))))
10115 (goto-char final-pos))))
10116
10117 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10118 "Comment out region if not commented out, uncomment otherwise."
10119 (interactive "r\nP")
10120 (save-excursion
10121 (goto-char (1- end))
10122 (end-of-line)
10123 (setq end (point-marker))
10124 (goto-char beg)
10125 (beginning-of-line)
10126 (setq beg (point))
10127 (if (looking-at comment-start)
10128 (comment-region beg end '(4))
10129 (comment-region beg end))))
10130
10131 (defun vhdl-comment-uncomment-line (&optional arg)
10132 "Comment out line if not commented out, uncomment otherwise."
10133 (interactive "p")
10134 (save-excursion
10135 (beginning-of-line)
10136 (let ((position (point)))
10137 (forward-line (or arg 1))
10138 (vhdl-comment-uncomment-region position (point)))))
10139
10140 (defun vhdl-comment-kill-region (beg end)
10141 "Kill comments in region."
10142 (interactive "r")
10143 (save-excursion
10144 (goto-char end)
10145 (setq end (point-marker))
10146 (goto-char beg)
10147 (beginning-of-line)
10148 (while (< (point) end)
10149 (if (looking-at "^\\(\\s-*--.*\n\\)")
10150 (progn (delete-region (match-beginning 1) (match-end 1)))
10151 (beginning-of-line 2)))))
10152
10153 (defun vhdl-comment-kill-inline-region (beg end)
10154 "Kill inline comments in region."
10155 (interactive "r")
10156 (save-excursion
10157 (goto-char end)
10158 (setq end (point-marker))
10159 (goto-char beg)
10160 (beginning-of-line)
10161 (while (< (point) end)
10162 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10163 (delete-region (match-beginning 1) (match-end 1)))
10164 (beginning-of-line 2))))
10165
10166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10167 ;; Subtemplates
10168
10169 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10170 "Insert a begin ... end pair with optional name after the end.
10171 Point is left between them."
10172 (let (position)
10173 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10174 (indent-to margin)
10175 (vhdl-insert-keyword "BEGIN")
10176 (when (and (or construct name) vhdl-self-insert-comments)
10177 (insert " --")
10178 (when construct (insert " ") (vhdl-insert-keyword construct))
10179 (when name (insert " " name)))
10180 (insert "\n")
10181 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10182 (indent-to (+ margin vhdl-basic-offset))
10183 (setq position (point))
10184 (insert "\n")
10185 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10186 (indent-to margin)
10187 (vhdl-insert-keyword "END")
10188 (when construct (insert " ") (vhdl-insert-keyword construct))
10189 (insert (if name (concat " " name) "") ";")
10190 (goto-char position)))
10191
10192 (defun vhdl-template-argument-list (&optional is-function)
10193 "Read from user a procedure or function argument list."
10194 (insert " (")
10195 (let ((margin (current-column))
10196 (start (point))
10197 (end-pos (point))
10198 not-empty interface semicolon-pos)
10199 (unless vhdl-argument-list-indent
10200 (setq margin (+ (current-indentation) vhdl-basic-offset))
10201 (insert "\n")
10202 (indent-to margin))
10203 (setq interface (vhdl-template-field
10204 (concat "[CONSTANT | SIGNAL"
10205 (unless is-function " | VARIABLE") "]") " " t))
10206 (while (vhdl-template-field "[names]" nil t)
10207 (setq not-empty t)
10208 (insert " : ")
10209 (unless is-function
10210 (if (and interface (equal (upcase interface) "CONSTANT"))
10211 (vhdl-insert-keyword "IN ")
10212 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10213 (vhdl-template-field "type")
10214 (setq semicolon-pos (point))
10215 (insert ";")
10216 (vhdl-comment-insert-inline)
10217 (setq end-pos (point))
10218 (insert "\n")
10219 (indent-to margin)
10220 (setq interface (vhdl-template-field
10221 (concat "[CONSTANT | SIGNAL"
10222 (unless is-function " | VARIABLE") "]") " " t)))
10223 (delete-region end-pos (point))
10224 (when semicolon-pos (goto-char semicolon-pos))
10225 (if not-empty
10226 (progn (delete-char 1) (insert ")"))
10227 (delete-backward-char 2))))
10228
10229 (defun vhdl-template-generic-list (optional &optional no-value)
10230 "Read from user a generic spec argument list."
10231 (let (margin
10232 (start (point)))
10233 (vhdl-insert-keyword "GENERIC (")
10234 (setq margin (current-column))
10235 (unless vhdl-argument-list-indent
10236 (let ((position (point)))
10237 (back-to-indentation)
10238 (setq margin (+ (current-column) vhdl-basic-offset))
10239 (goto-char position)
10240 (insert "\n")
10241 (indent-to margin)))
10242 (let ((vhdl-generics (vhdl-template-field
10243 (concat (and optional "[") "name"
10244 (and no-value "s") (and optional "]"))
10245 nil optional)))
10246 (if (not vhdl-generics)
10247 (if optional
10248 (progn (vhdl-line-kill-entire) (end-of-line -0)
10249 (unless vhdl-argument-list-indent
10250 (vhdl-line-kill-entire) (end-of-line -0)))
10251 (vhdl-template-undo start (point))
10252 nil )
10253 (insert " : ")
10254 (let (semicolon-pos end-pos)
10255 (while vhdl-generics
10256 (vhdl-template-field "type")
10257 (if no-value
10258 (progn (setq semicolon-pos (point))
10259 (insert ";"))
10260 (insert " := ")
10261 (unless (vhdl-template-field "[value]" nil t)
10262 (delete-char -4))
10263 (setq semicolon-pos (point))
10264 (insert ";"))
10265 (vhdl-comment-insert-inline)
10266 (setq end-pos (point))
10267 (insert "\n")
10268 (indent-to margin)
10269 (setq vhdl-generics (vhdl-template-field
10270 (concat "[name" (and no-value "s") "]")
10271 " : " t)))
10272 (delete-region end-pos (point))
10273 (goto-char semicolon-pos)
10274 (insert ")")
10275 (end-of-line)
10276 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10277 t)))))
10278
10279 (defun vhdl-template-port-list (optional)
10280 "Read from user a port spec argument list."
10281 (let ((start (point))
10282 margin vhdl-ports object)
10283 (vhdl-insert-keyword "PORT (")
10284 (setq margin (current-column))
10285 (unless vhdl-argument-list-indent
10286 (let ((position (point)))
10287 (back-to-indentation)
10288 (setq margin (+ (current-column) vhdl-basic-offset))
10289 (goto-char position)
10290 (insert "\n")
10291 (indent-to margin)))
10292 (when (vhdl-standard-p 'ams)
10293 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10294 " " t)))
10295 (setq vhdl-ports (vhdl-template-field
10296 (concat (and optional "[") "names" (and optional "]"))
10297 nil optional))
10298 (if (not vhdl-ports)
10299 (if optional
10300 (progn (vhdl-line-kill-entire) (end-of-line -0)
10301 (unless vhdl-argument-list-indent
10302 (vhdl-line-kill-entire) (end-of-line -0)))
10303 (vhdl-template-undo start (point))
10304 nil)
10305 (insert " : ")
10306 (let (semicolon-pos end-pos)
10307 (while vhdl-ports
10308 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10309 (vhdl-template-field "IN | OUT | INOUT" " "))
10310 ((equal "QUANTITY" (upcase object))
10311 (vhdl-template-field "[IN | OUT]" " " t)))
10312 (vhdl-template-field
10313 (if (and object (equal "TERMINAL" (upcase object)))
10314 "nature" "type"))
10315 (setq semicolon-pos (point))
10316 (insert ";")
10317 (vhdl-comment-insert-inline)
10318 (setq end-pos (point))
10319 (insert "\n")
10320 (indent-to margin)
10321 (when (vhdl-standard-p 'ams)
10322 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10323 " " t)))
10324 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10325 (delete-region end-pos (point))
10326 (goto-char semicolon-pos)
10327 (insert ")")
10328 (end-of-line)
10329 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10330 t))))
10331
10332 (defun vhdl-template-generate-body (margin label)
10333 "Insert body for generate template."
10334 (vhdl-insert-keyword " GENERATE")
10335 ; (if (not (vhdl-standard-p '87))
10336 ; (vhdl-template-begin-end "GENERATE" label margin)
10337 (insert "\n\n")
10338 (indent-to margin)
10339 (vhdl-insert-keyword "END GENERATE ")
10340 (insert label ";")
10341 (end-of-line 0)
10342 (indent-to (+ margin vhdl-basic-offset)))
10343
10344 (defun vhdl-template-insert-date ()
10345 "Insert date in appropriate format."
10346 (interactive)
10347 (insert
10348 (cond
10349 ;; 'american, 'european, 'scientific kept for backward compatibility
10350 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10351 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10352 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10353 (t (format-time-string vhdl-date-format nil)))))
10354
10355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10356 ;; Help functions
10357
10358 (defun vhdl-electric-space (count)
10359 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10360 if in comment and past end-comment-column."
10361 (interactive "p")
10362 (cond ((vhdl-in-comment-p)
10363 (self-insert-command count)
10364 (cond ((>= (current-column) (+ 2 end-comment-column))
10365 (backward-char 1)
10366 (skip-chars-backward "^ \t\n")
10367 (indent-new-comment-line)
10368 (skip-chars-forward "^ \t\n")
10369 (forward-char 1))
10370 ((>= (current-column) end-comment-column)
10371 (indent-new-comment-line))
10372 (t nil)))
10373 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10374 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10375 (vhdl-prepare-search-1
10376 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10377 (self-insert-command count))
10378 (t (self-insert-command count))))
10379
10380 (defun vhdl-template-field (prompt &optional follow-string optional
10381 begin end is-string default)
10382 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10383 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10384 an empty string is inserted, return nil and call `vhdl-template-undo' for
10385 the region between BEGIN and END. IS-STRING indicates whether a string
10386 with double-quotes is to be inserted. DEFAULT specifies a default string."
10387 (let ((position (point))
10388 string)
10389 (insert "<" prompt ">")
10390 (setq string
10391 (condition-case ()
10392 (read-from-minibuffer (concat prompt ": ")
10393 (or (and is-string '("\"\"" . 2)) default)
10394 vhdl-minibuffer-local-map)
10395 (quit (if (and optional begin end)
10396 (progn (beep) "")
10397 (keyboard-quit)))))
10398 (when (or (not (equal string "")) optional)
10399 (delete-region position (point)))
10400 (when (and (equal string "") optional begin end)
10401 (vhdl-template-undo begin end)
10402 (message "Template aborted"))
10403 (unless (equal string "")
10404 (insert string)
10405 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10406 vhdl-keywords-regexp)
10407 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10408 vhdl-types-regexp)
10409 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10410 (concat "'" vhdl-attributes-regexp))
10411 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10412 vhdl-enum-values-regexp))
10413 (when (or (not (equal string "")) (not optional))
10414 (insert (or follow-string "")))
10415 (if (equal string "") nil string)))
10416
10417 (defun vhdl-decision-query (string prompt &optional optional)
10418 "Query a decision from the user."
10419 (let ((start (point)))
10420 (when string (vhdl-insert-keyword (concat string " ")))
10421 (message "%s" (or prompt ""))
10422 (let ((char (read-char)))
10423 (delete-region start (point))
10424 (if (and optional (eq char ?\r))
10425 (progn (insert " ")
10426 (unexpand-abbrev)
10427 (throw 'abort "ERROR: Template aborted"))
10428 char))))
10429
10430 (defun vhdl-insert-keyword (keyword)
10431 "Insert KEYWORD and adjust case."
10432 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10433
10434 (defun vhdl-case-keyword (keyword)
10435 "Adjust case of KEYWORD."
10436 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10437
10438 (defun vhdl-case-word (num)
10439 "Adjust case of following NUM words."
10440 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10441
10442 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10443 "If preceding character is part of a word or a paren then hippie-expand,
10444 else insert tab (used for word completion in VHDL minibuffer)."
10445 (interactive "P")
10446 (cond
10447 ;; expand word
10448 ((= (char-syntax (preceding-char)) ?w)
10449 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10450 (case-replace nil)
10451 (hippie-expand-only-buffers
10452 (or (and (boundp 'hippie-expand-only-buffers)
10453 hippie-expand-only-buffers)
10454 '(vhdl-mode))))
10455 (vhdl-expand-abbrev prefix-arg)))
10456 ;; expand parenthesis
10457 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10458 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10459 (case-replace nil))
10460 (vhdl-expand-paren prefix-arg)))
10461 ;; insert tab
10462 (t (insert-tab))))
10463
10464 (defun vhdl-template-search-prompt ()
10465 "Search for left out template prompts and query again."
10466 (interactive)
10467 (vhdl-prepare-search-2
10468 (when (or (re-search-forward
10469 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10470 (re-search-backward
10471 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10472 (let ((string (match-string 1)))
10473 (replace-match "")
10474 (vhdl-template-field string)))))
10475
10476 (defun vhdl-template-undo (begin end)
10477 "Undo aborted template by deleting region and unexpanding the keyword."
10478 (cond (vhdl-template-invoked-by-hook
10479 (goto-char end)
10480 (insert " ")
10481 (delete-region begin end)
10482 (unexpand-abbrev))
10483 (t (delete-region begin end))))
10484
10485 (defun vhdl-insert-string-or-file (string)
10486 "Insert STRING or file contents if STRING is an existing file name."
10487 (unless (equal string "")
10488 (let ((file-name
10489 (progn (string-match "^\\([^\n]+\\)" string)
10490 (vhdl-resolve-env-variable (match-string 1 string)))))
10491 (if (file-exists-p file-name)
10492 (forward-char (cadr (insert-file-contents file-name)))
10493 (insert string)))))
10494
10495 (defun vhdl-beginning-of-block ()
10496 "Move cursor to the beginning of the enclosing block."
10497 (let (pos)
10498 (save-excursion
10499 (beginning-of-line)
10500 ;; search backward for block beginning or end
10501 (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))
10502 ;; not consider subprogram declarations
10503 (or (and (match-string 5)
10504 (save-match-data
10505 (save-excursion
10506 (goto-char (match-end 5))
10507 (forward-word 1)
10508 (vhdl-forward-syntactic-ws)
10509 (when (looking-at "(")
10510 (forward-sexp))
10511 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10512 (match-string 1)))
10513 ;; not consider configuration specifications
10514 (and (match-string 6)
10515 (save-match-data
10516 (save-excursion
10517 (vhdl-end-of-block)
10518 (beginning-of-line)
10519 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10520 (match-string 2))
10521 ;; skip subblock if block end found
10522 (vhdl-beginning-of-block)))
10523 (when pos (goto-char pos))))
10524
10525 (defun vhdl-end-of-block ()
10526 "Move cursor to the end of the enclosing block."
10527 (let (pos)
10528 (save-excursion
10529 (end-of-line)
10530 ;; search forward for block beginning or end
10531 (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))
10532 ;; not consider subprogram declarations
10533 (or (and (match-string 5)
10534 (save-match-data
10535 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10536 (match-string 1)))
10537 ;; not consider configuration specifications
10538 (and (match-string 6)
10539 (save-match-data
10540 (save-excursion
10541 (vhdl-end-of-block)
10542 (beginning-of-line)
10543 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10544 (not (match-string 2)))
10545 ;; skip subblock if block beginning found
10546 (vhdl-end-of-block)))
10547 (when pos (goto-char pos))))
10548
10549 (defun vhdl-sequential-statement-p ()
10550 "Check if point is within sequential statement part."
10551 (let ((start (point)))
10552 (save-excursion
10553 (vhdl-prepare-search-2
10554 ;; is sequential statement if ...
10555 (and (re-search-backward "^\\s-*begin\\>" nil t)
10556 ;; ... point is between "begin" and "end" of ...
10557 (progn (vhdl-end-of-block)
10558 (< start (point)))
10559 ;; ... a sequential block
10560 (progn (vhdl-beginning-of-block)
10561 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10562
10563 (defun vhdl-in-argument-list-p ()
10564 "Check if within an argument list."
10565 (save-excursion
10566 (vhdl-prepare-search-2
10567 (or (string-match "arglist"
10568 (format "%s" (caar (vhdl-get-syntactic-context))))
10569 (progn (beginning-of-line)
10570 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10571
10572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10573 ;; Abbrev hooks
10574
10575 (defun vhdl-hooked-abbrev (func)
10576 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10577 but not if inside a comment or quote."
10578 (if (or (vhdl-in-literal)
10579 (save-excursion
10580 (forward-word -1)
10581 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10582 (progn
10583 (insert " ")
10584 (unexpand-abbrev)
10585 (delete-char -1))
10586 (if (not vhdl-electric-mode)
10587 (progn
10588 (insert " ")
10589 (unexpand-abbrev)
10590 (backward-word 1)
10591 (vhdl-case-word 1)
10592 (delete-char 1))
10593 (let ((invoke-char last-command-event)
10594 (abbrev-mode -1)
10595 (vhdl-template-invoked-by-hook t))
10596 (let ((caught (catch 'abort
10597 (funcall func))))
10598 (when (stringp caught) (message "%s" caught)))
10599 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10600 ;; delete CR which is still in event queue
10601 (if (fboundp 'enqueue-eval-event)
10602 (enqueue-eval-event 'delete-char -1)
10603 (setq unread-command-events ; push back a delete char
10604 (list (vhdl-character-to-event ?\177))))))))
10605
10606 (defun vhdl-template-alias-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-alias))
10608 (defun vhdl-template-architecture-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10610 (defun vhdl-template-assert-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-assert))
10612 (defun vhdl-template-attribute-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10614 (defun vhdl-template-block-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-block))
10616 (defun vhdl-template-break-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-break))
10618 (defun vhdl-template-case-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-case))
10620 (defun vhdl-template-component-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-component))
10622 (defun vhdl-template-instance-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-instance))
10624 (defun vhdl-template-conditional-signal-asst-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10626 (defun vhdl-template-configuration-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10628 (defun vhdl-template-constant-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-constant))
10630 (defun vhdl-template-disconnect-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10632 (defun vhdl-template-display-comment-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-comment-display))
10634 (defun vhdl-template-else-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-else))
10636 (defun vhdl-template-elsif-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10638 (defun vhdl-template-entity-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-entity))
10640 (defun vhdl-template-exit-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-exit))
10642 (defun vhdl-template-file-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-file))
10644 (defun vhdl-template-for-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-for))
10646 (defun vhdl-template-function-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-function))
10648 (defun vhdl-template-generic-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-generic))
10650 (defun vhdl-template-group-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-group))
10652 (defun vhdl-template-library-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-library))
10654 (defun vhdl-template-limit-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-limit))
10656 (defun vhdl-template-if-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-if))
10658 (defun vhdl-template-bare-loop-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10660 (defun vhdl-template-map-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-map))
10662 (defun vhdl-template-nature-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-nature))
10664 (defun vhdl-template-next-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-next))
10666 (defun vhdl-template-others-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-others))
10668 (defun vhdl-template-package-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-package))
10670 (defun vhdl-template-port-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-port))
10672 (defun vhdl-template-procedural-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10674 (defun vhdl-template-procedure-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10676 (defun vhdl-template-process-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-process))
10678 (defun vhdl-template-quantity-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10680 (defun vhdl-template-report-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-report))
10682 (defun vhdl-template-return-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-return))
10684 (defun vhdl-template-selected-signal-asst-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10686 (defun vhdl-template-signal-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-signal))
10688 (defun vhdl-template-subnature-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10690 (defun vhdl-template-subtype-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10692 (defun vhdl-template-terminal-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10694 (defun vhdl-template-type-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-type))
10696 (defun vhdl-template-use-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-use))
10698 (defun vhdl-template-variable-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-variable))
10700 (defun vhdl-template-wait-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-wait))
10702 (defun vhdl-template-when-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-when))
10704 (defun vhdl-template-while-loop-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10706 (defun vhdl-template-with-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-with))
10708 (defun vhdl-template-and-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-and))
10710 (defun vhdl-template-or-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-or))
10712 (defun vhdl-template-nand-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-nand))
10714 (defun vhdl-template-nor-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-nor))
10716 (defun vhdl-template-xor-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-xor))
10718 (defun vhdl-template-xnor-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10720 (defun vhdl-template-not-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-not))
10722
10723 (defun vhdl-template-default-hook ()
10724 (vhdl-hooked-abbrev 'vhdl-template-default))
10725 (defun vhdl-template-default-indent-hook ()
10726 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10727
10728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10729 ;; Template insertion from completion list
10730
10731 (defun vhdl-template-insert-construct (name)
10732 "Insert the built-in construct template with NAME."
10733 (interactive
10734 (list (let ((completion-ignore-case t))
10735 (completing-read "Construct name: "
10736 vhdl-template-construct-alist nil t))))
10737 (vhdl-template-insert-fun
10738 (cadr (assoc name vhdl-template-construct-alist))))
10739
10740 (defun vhdl-template-insert-package (name)
10741 "Insert the built-in package template with NAME."
10742 (interactive
10743 (list (let ((completion-ignore-case t))
10744 (completing-read "Package name: "
10745 vhdl-template-package-alist nil t))))
10746 (vhdl-template-insert-fun
10747 (cadr (assoc name vhdl-template-package-alist))))
10748
10749 (defun vhdl-template-insert-directive (name)
10750 "Insert the built-in directive template with NAME."
10751 (interactive
10752 (list (let ((completion-ignore-case t))
10753 (completing-read "Directive name: "
10754 vhdl-template-directive-alist nil t))))
10755 (vhdl-template-insert-fun
10756 (cadr (assoc name vhdl-template-directive-alist))))
10757
10758 (defun vhdl-template-insert-fun (fun)
10759 "Call FUN to insert a built-in template."
10760 (let ((caught (catch 'abort (when fun (funcall fun)))))
10761 (when (stringp caught) (message "%s" caught))))
10762
10763
10764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10765 ;;; Models
10766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10767
10768 (defun vhdl-model-insert (model-name)
10769 "Insert the user model with name MODEL-NAME."
10770 (interactive
10771 (let ((completion-ignore-case t))
10772 (list (completing-read "Model name: " vhdl-model-alist))))
10773 (indent-according-to-mode)
10774 (let ((start (point-marker))
10775 (margin (current-indentation))
10776 model position prompt string end)
10777 (vhdl-prepare-search-2
10778 (when (setq model (assoc model-name vhdl-model-alist))
10779 ;; insert model
10780 (beginning-of-line)
10781 (delete-horizontal-space)
10782 (goto-char start)
10783 (vhdl-insert-string-or-file (nth 1 model))
10784 (setq end (point-marker))
10785 ;; indent code
10786 (goto-char start)
10787 (beginning-of-line)
10788 (while (< (point) end)
10789 (unless (looking-at "^$")
10790 (insert-char ? margin))
10791 (beginning-of-line 2))
10792 (goto-char start)
10793 ;; insert clock
10794 (unless (equal "" vhdl-clock-name)
10795 (while (re-search-forward "<clock>" end t)
10796 (replace-match vhdl-clock-name)))
10797 (goto-char start)
10798 ;; insert reset
10799 (unless (equal "" vhdl-reset-name)
10800 (while (re-search-forward "<reset>" end t)
10801 (replace-match vhdl-reset-name)))
10802 ;; replace header prompts
10803 (vhdl-template-replace-header-keywords start end nil t)
10804 (goto-char start)
10805 ;; query other prompts
10806 (while (re-search-forward
10807 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10808 (unless (equal "cursor" (match-string 1))
10809 (setq position (match-beginning 1))
10810 (setq prompt (match-string 1))
10811 (replace-match "")
10812 (setq string (vhdl-template-field prompt nil t))
10813 ;; replace occurrences of same prompt
10814 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10815 (replace-match (or string "")))
10816 (goto-char position)))
10817 (goto-char start)
10818 ;; goto final position
10819 (if (re-search-forward "<cursor>" end t)
10820 (replace-match "")
10821 (goto-char end))))))
10822
10823 (defun vhdl-model-defun ()
10824 "Define help and hook functions for user models."
10825 (let ((model-alist vhdl-model-alist)
10826 model-name model-keyword)
10827 (while model-alist
10828 ;; define functions for user models that can be invoked from menu and key
10829 ;; bindings and which themselves call `vhdl-model-insert' with the model
10830 ;; name as argument
10831 (setq model-name (nth 0 (car model-alist)))
10832 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10833 ,(concat "Insert model for \"" model-name "\".")
10834 (interactive)
10835 (vhdl-model-insert ,model-name)))
10836 ;; define hooks for user models that are invoked from keyword abbrevs
10837 (setq model-keyword (nth 3 (car model-alist)))
10838 (unless (equal model-keyword "")
10839 (eval `(defun
10840 ,(vhdl-function-name
10841 "vhdl-model" model-name "hook") ()
10842 (vhdl-hooked-abbrev
10843 ',(vhdl-function-name "vhdl-model" model-name)))))
10844 (setq model-alist (cdr model-alist)))))
10845
10846 (vhdl-model-defun)
10847
10848
10849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10850 ;;; Port translation
10851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10852
10853 (defvar vhdl-port-list nil
10854 "Variable to hold last port map parsed.")
10855 ;; structure: (parenthesised expression means list of such entries)
10856 ;; (ent-name
10857 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10858 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10859 ;; (lib-name pack-key))
10860
10861 (defun vhdl-parse-string (string &optional optional)
10862 "Check that the text following point matches the regexp in STRING."
10863 (if (looking-at string)
10864 (goto-char (match-end 0))
10865 (unless optional
10866 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10867 (vhdl-current-line) string)))
10868 nil))
10869
10870 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10871 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10872 (vhdl-prepare-search-1
10873 (if (string-match (car regexp-cons) string)
10874 (if adjust-case
10875 (funcall vhdl-file-name-case
10876 (replace-match (cdr regexp-cons) t nil string))
10877 (replace-match (cdr regexp-cons) t nil string))
10878 string)))
10879
10880 (defun vhdl-parse-group-comment ()
10881 "Parse comment and empty lines between groups of lines."
10882 (let ((start (point))
10883 string)
10884 (vhdl-forward-comment (point-max))
10885 (setq string (buffer-substring-no-properties start (point)))
10886 (vhdl-forward-syntactic-ws)
10887 ;; strip off leading blanks and first newline
10888 (while (string-match "^\\(\\s-+\\)" string)
10889 (setq string (concat (substring string 0 (match-beginning 1))
10890 (substring string (match-end 1)))))
10891 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10892 (substring string 1)
10893 string)))
10894
10895 (defun vhdl-paste-group-comment (string indent)
10896 "Paste comment and empty lines from STRING between groups of lines
10897 with INDENT."
10898 (let ((pos (point-marker)))
10899 (when (> indent 0)
10900 (while (string-match "^\\(--\\)" string)
10901 (setq string (concat (substring string 0 (match-beginning 1))
10902 (make-string indent ? )
10903 (substring string (match-beginning 1))))))
10904 (beginning-of-line)
10905 (insert string)
10906 (goto-char pos)))
10907
10908 (defvar vhdl-port-flattened nil
10909 "Indicates whether a port has been flattened.")
10910
10911 (defun vhdl-port-flatten (&optional as-alist)
10912 "Flatten port list so that only one generic/port exists per line.
10913 This operation is performed on an internally stored port and is only
10914 reflected in a subsequent paste operation."
10915 (interactive)
10916 (if (not vhdl-port-list)
10917 (error "ERROR: No port has been read")
10918 (message "Flattening port for next paste...")
10919 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10920 (old-vhdl-port-list (cdr vhdl-port-list))
10921 old-port-list new-port-list old-port new-port names)
10922 ;; traverse port list and flatten entries
10923 (while (cdr old-vhdl-port-list)
10924 (setq old-port-list (car old-vhdl-port-list))
10925 (setq new-port-list nil)
10926 (while old-port-list
10927 (setq old-port (car old-port-list))
10928 (setq names (car old-port))
10929 (while names
10930 (setq new-port (cons (if as-alist (car names) (list (car names)))
10931 (cdr old-port)))
10932 (setq new-port-list (append new-port-list (list new-port)))
10933 (setq names (cdr names)))
10934 (setq old-port-list (cdr old-port-list)))
10935 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10936 (setq new-vhdl-port-list (append new-vhdl-port-list
10937 (list new-port-list))))
10938 (setq vhdl-port-list
10939 (append new-vhdl-port-list (list old-vhdl-port-list))
10940 vhdl-port-flattened t)
10941 (message "Flattening port for next paste...done"))))
10942
10943 (defvar vhdl-port-reversed-direction nil
10944 "Indicates whether port directions are reversed.")
10945
10946 (defun vhdl-port-reverse-direction ()
10947 "Reverse direction for all ports (useful in testbenches).
10948 This operation is performed on an internally stored port and is only
10949 reflected in a subsequent paste operation."
10950 (interactive)
10951 (if (not vhdl-port-list)
10952 (error "ERROR: No port has been read")
10953 (message "Reversing port directions for next paste...")
10954 (let ((port-list (nth 2 vhdl-port-list))
10955 port-dir-car port-dir)
10956 ;; traverse port list and reverse directions
10957 (while port-list
10958 (setq port-dir-car (cddr (car port-list))
10959 port-dir (car port-dir-car))
10960 (setcar port-dir-car
10961 (cond ((equal port-dir "in") "out")
10962 ((equal port-dir "out") "in")
10963 (t port-dir)))
10964 (setq port-list (cdr port-list)))
10965 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10966 (message "Reversing port directions for next paste...done"))))
10967
10968 (defun vhdl-port-copy ()
10969 "Get generic and port information from an entity or component declaration."
10970 (interactive)
10971 (save-excursion
10972 (let (parse-error end-of-list
10973 decl-type name generic-list port-list context-clause
10974 object names direct type init comment group-comment)
10975 (vhdl-prepare-search-2
10976 (setq
10977 parse-error
10978 (catch 'parse
10979 ;; check if within entity or component declaration
10980 (end-of-line)
10981 (when (or (not (re-search-backward
10982 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10983 (equal "END" (upcase (match-string 1))))
10984 (throw 'parse "ERROR: Not within an entity or component declaration"))
10985 (setq decl-type (downcase (match-string-no-properties 1)))
10986 (forward-word 1)
10987 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10988 (setq name (match-string-no-properties 1))
10989 (message "Reading port of %s \"%s\"..." decl-type name)
10990 (vhdl-forward-syntactic-ws)
10991 ;; parse generic clause
10992 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10993 ;; parse group comment and spacing
10994 (setq group-comment (vhdl-parse-group-comment))
10995 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10996 (while (not end-of-list)
10997 ;; parse names (accept extended identifiers)
10998 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10999 (setq names (list (match-string-no-properties 1)))
11000 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11001 (setq names
11002 (append names (list (match-string-no-properties 1)))))
11003 ;; parse type
11004 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11005 (setq type (match-string-no-properties 1))
11006 (setq comment nil)
11007 (while (looking-at "(")
11008 (setq type
11009 (concat type
11010 (buffer-substring-no-properties
11011 (point) (progn (forward-sexp) (point)))
11012 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11013 (match-string-no-properties 1)))))
11014 ;; special case: closing parenthesis is on separate line
11015 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11016 (setq comment (substring type (match-beginning 2)))
11017 (setq type (substring type 0 (match-beginning 1))))
11018 ;; strip of trailing group-comment
11019 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11020 (setq type (substring type 0 (match-end 1)))
11021 ;; parse initialization expression
11022 (setq init nil)
11023 (when (vhdl-parse-string ":=[ \t\n]*" t)
11024 (vhdl-parse-string "\\([^();\n]*\\)")
11025 (setq init (match-string-no-properties 1))
11026 (while (looking-at "(")
11027 (setq init
11028 (concat init
11029 (buffer-substring-no-properties
11030 (point) (progn (forward-sexp) (point)))
11031 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11032 (match-string-no-properties 1))))))
11033 ;; special case: closing parenthesis is on separate line
11034 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11035 (setq comment (substring init (match-beginning 2)))
11036 (setq init (substring init 0 (match-beginning 1)))
11037 (vhdl-forward-syntactic-ws))
11038 (skip-chars-forward " \t")
11039 ;; parse inline comment, special case: as above, no initial.
11040 (unless comment
11041 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11042 (match-string-no-properties 1))))
11043 (vhdl-forward-syntactic-ws)
11044 (setq end-of-list (vhdl-parse-string ")" t))
11045 (vhdl-parse-string "\\s-*;\\s-*")
11046 ;; parse inline comment
11047 (unless comment
11048 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11049 (match-string-no-properties 1))))
11050 ;; save everything in list
11051 (setq generic-list (append generic-list
11052 (list (list names type init
11053 comment group-comment))))
11054 ;; parse group comment and spacing
11055 (setq group-comment (vhdl-parse-group-comment))))
11056 ;; parse port clause
11057 (when (vhdl-parse-string "port[ \t\n]*(" t)
11058 ;; parse group comment and spacing
11059 (setq group-comment (vhdl-parse-group-comment))
11060 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11061 (while (not end-of-list)
11062 ;; parse object
11063 (setq object
11064 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11065 (match-string-no-properties 1)))
11066 ;; parse names (accept extended identifiers)
11067 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11068 (setq names (list (match-string-no-properties 1)))
11069 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11070 (setq names (append names (list (match-string-no-properties 1)))))
11071 ;; parse direction
11072 (vhdl-parse-string ":[ \t\n]*")
11073 (setq direct
11074 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11075 (match-string-no-properties 1)))
11076 ;; parse type
11077 (vhdl-parse-string "\\([^();\n]+\\)")
11078 (setq type (match-string-no-properties 1))
11079 (setq comment nil)
11080 (while (looking-at "(")
11081 (setq type (concat type
11082 (buffer-substring-no-properties
11083 (point) (progn (forward-sexp) (point)))
11084 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11085 (match-string-no-properties 1)))))
11086 ;; special case: closing parenthesis is on separate line
11087 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11088 (setq comment (substring type (match-beginning 2)))
11089 (setq type (substring type 0 (match-beginning 1))))
11090 ;; strip of trailing group-comment
11091 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11092 (setq type (substring type 0 (match-end 1)))
11093 (vhdl-forward-syntactic-ws)
11094 (setq end-of-list (vhdl-parse-string ")" t))
11095 (vhdl-parse-string "\\s-*;\\s-*")
11096 ;; parse inline comment
11097 (unless comment
11098 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11099 (match-string-no-properties 1))))
11100 ;; save everything in list
11101 (setq port-list (append port-list
11102 (list (list names object direct type
11103 comment group-comment))))
11104 ;; parse group comment and spacing
11105 (setq group-comment (vhdl-parse-group-comment))))
11106 ; (vhdl-parse-string "end\\>")
11107 ;; parse context clause
11108 (setq context-clause (vhdl-scan-context-clause))
11109 ; ;; add surrounding package to context clause
11110 ; (when (and (equal decl-type "component")
11111 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11112 ; (setq context-clause
11113 ; (append context-clause
11114 ; (list (cons (vhdl-work-library)
11115 ; (match-string-no-properties 1))))))
11116 (message "Reading port of %s \"%s\"...done" decl-type name)
11117 nil)))
11118 ;; finish parsing
11119 (if parse-error
11120 (error parse-error)
11121 (setq vhdl-port-list (list name generic-list port-list context-clause)
11122 vhdl-port-reversed-direction nil
11123 vhdl-port-flattened nil)))))
11124
11125 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11126 "Paste a context clause."
11127 (let ((margin (current-indentation))
11128 (clause-list (nth 3 vhdl-port-list))
11129 clause)
11130 (while clause-list
11131 (setq clause (car clause-list))
11132 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11133 (downcase exclude-pack-name)))
11134 (save-excursion
11135 (re-search-backward
11136 (concat "^\\s-*use\\s-+" (car clause)
11137 "\." (cdr clause) "\\>") nil t)))
11138 (vhdl-template-standard-package (car clause) (cdr clause))
11139 (insert "\n"))
11140 (setq clause-list (cdr clause-list)))))
11141
11142 (defun vhdl-port-paste-generic (&optional no-init)
11143 "Paste a generic clause."
11144 (let ((margin (current-indentation))
11145 (generic-list (nth 1 vhdl-port-list))
11146 list-margin start names generic)
11147 ;; paste generic clause
11148 (when generic-list
11149 (setq start (point))
11150 (vhdl-insert-keyword "GENERIC (")
11151 (unless vhdl-argument-list-indent
11152 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11153 (setq list-margin (current-column))
11154 (while generic-list
11155 (setq generic (car generic-list))
11156 ;; paste group comment and spacing
11157 (when (memq vhdl-include-group-comments '(decl always))
11158 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11159 ;; paste names
11160 (setq names (nth 0 generic))
11161 (while names
11162 (insert (car names))
11163 (setq names (cdr names))
11164 (when names (insert ", ")))
11165 ;; paste type
11166 (insert " : " (nth 1 generic))
11167 ;; paste initialization
11168 (when (and (not no-init) (nth 2 generic))
11169 (insert " := " (nth 2 generic)))
11170 (unless (cdr generic-list) (insert ")"))
11171 (insert ";")
11172 ;; paste comment
11173 (when (and vhdl-include-port-comments (nth 3 generic))
11174 (vhdl-comment-insert-inline (nth 3 generic) t))
11175 (setq generic-list (cdr generic-list))
11176 (when generic-list (insert "\n") (indent-to list-margin)))
11177 ;; align generic clause
11178 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11179
11180 (defun vhdl-port-paste-port ()
11181 "Paste a port clause."
11182 (let ((margin (current-indentation))
11183 (port-list (nth 2 vhdl-port-list))
11184 list-margin start names port)
11185 ;; paste port clause
11186 (when port-list
11187 (setq start (point))
11188 (vhdl-insert-keyword "PORT (")
11189 (unless vhdl-argument-list-indent
11190 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11191 (setq list-margin (current-column))
11192 (while port-list
11193 (setq port (car port-list))
11194 ;; paste group comment and spacing
11195 (when (memq vhdl-include-group-comments '(decl always))
11196 (vhdl-paste-group-comment (nth 5 port) list-margin))
11197 ;; paste object
11198 (when (nth 1 port) (insert (nth 1 port) " "))
11199 ;; paste names
11200 (setq names (nth 0 port))
11201 (while names
11202 (insert (car names))
11203 (setq names (cdr names))
11204 (when names (insert ", ")))
11205 ;; paste direction
11206 (insert " : ")
11207 (when (nth 2 port) (insert (nth 2 port) " "))
11208 ;; paste type
11209 (insert (nth 3 port))
11210 (unless (cdr port-list) (insert ")"))
11211 (insert ";")
11212 ;; paste comment
11213 (when (and vhdl-include-port-comments (nth 4 port))
11214 (vhdl-comment-insert-inline (nth 4 port) t))
11215 (setq port-list (cdr port-list))
11216 (when port-list (insert "\n") (indent-to list-margin)))
11217 ;; align port clause
11218 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11219
11220 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11221 "Paste as an entity or component declaration."
11222 (unless no-indent (indent-according-to-mode))
11223 (let ((margin (current-indentation))
11224 (name (nth 0 vhdl-port-list)))
11225 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11226 (insert name)
11227 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11228 (vhdl-insert-keyword " IS"))
11229 ;; paste generic and port clause
11230 (when (nth 1 vhdl-port-list)
11231 (insert "\n")
11232 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11233 (insert "\n"))
11234 (indent-to (+ margin vhdl-basic-offset))
11235 (vhdl-port-paste-generic (eq kind 'component)))
11236 (when (nth 2 vhdl-port-list)
11237 (insert "\n")
11238 (when (and (memq vhdl-insert-empty-lines '(unit all))
11239 (eq kind 'entity))
11240 (insert "\n"))
11241 (indent-to (+ margin vhdl-basic-offset)))
11242 (vhdl-port-paste-port)
11243 (insert "\n")
11244 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11245 (insert "\n"))
11246 (indent-to margin)
11247 (vhdl-insert-keyword "END")
11248 (if (eq kind 'entity)
11249 (progn
11250 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11251 (insert " " name))
11252 (vhdl-insert-keyword " COMPONENT")
11253 (unless (vhdl-standard-p '87) (insert " " name)))
11254 (insert ";")))
11255
11256 (defun vhdl-port-paste-entity (&optional no-indent)
11257 "Paste as an entity declaration."
11258 (interactive)
11259 (if (not vhdl-port-list)
11260 (error "ERROR: No port read")
11261 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11262 (vhdl-port-paste-declaration 'entity no-indent)
11263 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11264
11265 (defun vhdl-port-paste-component (&optional no-indent)
11266 "Paste as a component declaration."
11267 (interactive)
11268 (if (not vhdl-port-list)
11269 (error "ERROR: No port read")
11270 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11271 (vhdl-port-paste-declaration 'component no-indent)
11272 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11273
11274 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11275 "Paste as a generic map."
11276 (interactive)
11277 (unless secondary (indent-according-to-mode))
11278 (let ((margin (current-indentation))
11279 list-margin start generic
11280 (generic-list (nth 1 vhdl-port-list)))
11281 (when generic-list
11282 (setq start (point))
11283 (vhdl-insert-keyword "GENERIC MAP (")
11284 (if (not vhdl-association-list-with-formals)
11285 ;; paste list of actual generics
11286 (while generic-list
11287 (insert (if no-constants
11288 (car (nth 0 (car generic-list)))
11289 (or (nth 2 (car generic-list)) " ")))
11290 (setq generic-list (cdr generic-list))
11291 (insert (if generic-list ", " ")"))
11292 (when (and (not generic-list) secondary
11293 (null (nth 2 vhdl-port-list)))
11294 (insert ";")))
11295 (unless vhdl-argument-list-indent
11296 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11297 (setq list-margin (current-column))
11298 (while generic-list
11299 (setq generic (car generic-list))
11300 ;; paste group comment and spacing
11301 (when (eq vhdl-include-group-comments 'always)
11302 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11303 ;; paste formal and actual generic
11304 (insert (car (nth 0 generic)) " => "
11305 (if no-constants
11306 (car (nth 0 generic))
11307 (or (nth 2 generic) "")))
11308 (setq generic-list (cdr generic-list))
11309 (insert (if generic-list "," ")"))
11310 (when (and (not generic-list) secondary
11311 (null (nth 2 vhdl-port-list)))
11312 (insert ";"))
11313 ;; paste comment
11314 (when (or vhdl-include-type-comments
11315 (and vhdl-include-port-comments (nth 3 generic)))
11316 (vhdl-comment-insert-inline
11317 (concat
11318 (when vhdl-include-type-comments
11319 (concat "[" (nth 1 generic) "] "))
11320 (when vhdl-include-port-comments (nth 3 generic))) t))
11321 (when generic-list (insert "\n") (indent-to list-margin)))
11322 ;; align generic map
11323 (when vhdl-auto-align
11324 (vhdl-align-region-groups start (point) 1 t))))))
11325
11326 (defun vhdl-port-paste-port-map ()
11327 "Paste as a port map."
11328 (let ((margin (current-indentation))
11329 list-margin start port
11330 (port-list (nth 2 vhdl-port-list)))
11331 (when port-list
11332 (setq start (point))
11333 (vhdl-insert-keyword "PORT MAP (")
11334 (if (not vhdl-association-list-with-formals)
11335 ;; paste list of actual ports
11336 (while port-list
11337 (insert (vhdl-replace-string vhdl-actual-port-name
11338 (car (nth 0 (car port-list)))))
11339 (setq port-list (cdr port-list))
11340 (insert (if port-list ", " ")")))
11341 (unless vhdl-argument-list-indent
11342 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11343 (setq list-margin (current-column))
11344 (while port-list
11345 (setq port (car port-list))
11346 ;; paste group comment and spacing
11347 (when (eq vhdl-include-group-comments 'always)
11348 (vhdl-paste-group-comment (nth 5 port) list-margin))
11349 ;; paste formal and actual port
11350 (insert (car (nth 0 port)) " => ")
11351 (insert (vhdl-replace-string vhdl-actual-port-name
11352 (car (nth 0 port))))
11353 (setq port-list (cdr port-list))
11354 (insert (if port-list "," ");"))
11355 ;; paste comment
11356 (when (or vhdl-include-direction-comments
11357 vhdl-include-type-comments
11358 (and vhdl-include-port-comments (nth 4 port)))
11359 (vhdl-comment-insert-inline
11360 (concat
11361 (cond ((and vhdl-include-direction-comments
11362 vhdl-include-type-comments)
11363 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11364 (nth 3 port) "] "))
11365 ((and vhdl-include-direction-comments (nth 2 port))
11366 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11367 (vhdl-include-direction-comments " ")
11368 (vhdl-include-type-comments
11369 (concat "[" (nth 3 port) "] ")))
11370 (when vhdl-include-port-comments (nth 4 port))) t))
11371 (when port-list (insert "\n") (indent-to list-margin)))
11372 ;; align port clause
11373 (when vhdl-auto-align
11374 (vhdl-align-region-groups start (point) 1))))))
11375
11376 (defun vhdl-port-paste-instance (&optional name no-indent title)
11377 "Paste as an instantiation."
11378 (interactive)
11379 (if (not vhdl-port-list)
11380 (error "ERROR: No port read")
11381 (let ((orig-vhdl-port-list vhdl-port-list))
11382 ;; flatten local copy of port list (must be flat for port mapping)
11383 (vhdl-port-flatten)
11384 (unless no-indent (indent-according-to-mode))
11385 (let ((margin (current-indentation)))
11386 ;; paste instantiation
11387 (cond (name
11388 (insert name))
11389 ((equal (cdr vhdl-instance-name) "")
11390 (setq name (vhdl-template-field "instance name")))
11391 ((string-match "\%d" (cdr vhdl-instance-name))
11392 (let ((n 1))
11393 (while (save-excursion
11394 (setq name (format (vhdl-replace-string
11395 vhdl-instance-name
11396 (nth 0 vhdl-port-list)) n))
11397 (goto-char (point-min))
11398 (vhdl-re-search-forward name nil t))
11399 (setq n (1+ n)))
11400 (insert name)))
11401 (t (insert (vhdl-replace-string vhdl-instance-name
11402 (nth 0 vhdl-port-list)))))
11403 (message "Pasting port as instantiation \"%s\"..." name)
11404 (insert ": ")
11405 (when title
11406 (save-excursion
11407 (beginning-of-line)
11408 (indent-to vhdl-basic-offset)
11409 (insert "-- instance \"" name "\"\n")))
11410 (if (not (vhdl-use-direct-instantiation))
11411 (insert (nth 0 vhdl-port-list))
11412 (vhdl-insert-keyword "ENTITY ")
11413 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11414 (when (nth 1 vhdl-port-list)
11415 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11416 (vhdl-port-paste-generic-map t t))
11417 (when (nth 2 vhdl-port-list)
11418 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11419 (vhdl-port-paste-port-map))
11420 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11421 (insert ";"))
11422 (message "Pasting port as instantiation \"%s\"...done" name))
11423 (setq vhdl-port-list orig-vhdl-port-list))))
11424
11425 (defun vhdl-port-paste-constants (&optional no-indent)
11426 "Paste generics as constants."
11427 (interactive)
11428 (if (not vhdl-port-list)
11429 (error "ERROR: No port read")
11430 (let ((orig-vhdl-port-list vhdl-port-list))
11431 (message "Pasting port as constants...")
11432 ;; flatten local copy of port list (must be flat for constant initial.)
11433 (vhdl-port-flatten)
11434 (unless no-indent (indent-according-to-mode))
11435 (let ((margin (current-indentation))
11436 start generic name
11437 (generic-list (nth 1 vhdl-port-list)))
11438 (when generic-list
11439 (setq start (point))
11440 (while generic-list
11441 (setq generic (car generic-list))
11442 ;; paste group comment and spacing
11443 (when (memq vhdl-include-group-comments '(decl always))
11444 (vhdl-paste-group-comment (nth 4 generic) margin))
11445 (vhdl-insert-keyword "CONSTANT ")
11446 ;; paste generic constants
11447 (setq name (nth 0 generic))
11448 (when name
11449 (insert (car name))
11450 ;; paste type
11451 (insert " : " (nth 1 generic))
11452 ;; paste initialization
11453 (when (nth 2 generic)
11454 (insert " := " (nth 2 generic)))
11455 (insert ";")
11456 ;; paste comment
11457 (when (and vhdl-include-port-comments (nth 3 generic))
11458 (vhdl-comment-insert-inline (nth 3 generic) t))
11459 (setq generic-list (cdr generic-list))
11460 (when generic-list (insert "\n") (indent-to margin))))
11461 ;; align signal list
11462 (when vhdl-auto-align
11463 (vhdl-align-region-groups start (point) 1))))
11464 (message "Pasting port as constants...done")
11465 (setq vhdl-port-list orig-vhdl-port-list))))
11466
11467 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11468 "Paste ports as internal signals."
11469 (interactive)
11470 (if (not vhdl-port-list)
11471 (error "ERROR: No port read")
11472 (message "Pasting port as signals...")
11473 (unless no-indent (indent-according-to-mode))
11474 (let ((margin (current-indentation))
11475 start port names
11476 (port-list (nth 2 vhdl-port-list)))
11477 (when port-list
11478 (setq start (point))
11479 (while port-list
11480 (setq port (car port-list))
11481 ;; paste group comment and spacing
11482 (when (memq vhdl-include-group-comments '(decl always))
11483 (vhdl-paste-group-comment (nth 5 port) margin))
11484 ;; paste object
11485 (if (nth 1 port)
11486 (insert (nth 1 port) " ")
11487 (vhdl-insert-keyword "SIGNAL "))
11488 ;; paste actual port signals
11489 (setq names (nth 0 port))
11490 (while names
11491 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11492 (setq names (cdr names))
11493 (when names (insert ", ")))
11494 ;; paste type
11495 (insert " : " (nth 3 port))
11496 ;; paste initialization (inputs only)
11497 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11498 (insert " := " (if (string-match "(.+)" (nth 3 port))
11499 "(others => '0')" "'0'")))
11500 (insert ";")
11501 ;; paste comment
11502 (when (or vhdl-include-direction-comments
11503 (and vhdl-include-port-comments (nth 4 port)))
11504 (vhdl-comment-insert-inline
11505 (concat
11506 (cond ((and vhdl-include-direction-comments (nth 2 port))
11507 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11508 (vhdl-include-direction-comments " "))
11509 (when vhdl-include-port-comments (nth 4 port))) t))
11510 (setq port-list (cdr port-list))
11511 (when port-list (insert "\n") (indent-to margin)))
11512 ;; align signal list
11513 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11514 (message "Pasting port as signals...done")))
11515
11516 (defun vhdl-port-paste-initializations (&optional no-indent)
11517 "Paste ports as signal initializations."
11518 (interactive)
11519 (if (not vhdl-port-list)
11520 (error "ERROR: No port read")
11521 (let ((orig-vhdl-port-list vhdl-port-list))
11522 (message "Pasting port as initializations...")
11523 ;; flatten local copy of port list (must be flat for signal initial.)
11524 (vhdl-port-flatten)
11525 (unless no-indent (indent-according-to-mode))
11526 (let ((margin (current-indentation))
11527 start port name
11528 (port-list (nth 2 vhdl-port-list)))
11529 (when port-list
11530 (setq start (point))
11531 (while port-list
11532 (setq port (car port-list))
11533 ;; paste actual port signal (inputs only)
11534 (when (equal "IN" (upcase (nth 2 port)))
11535 (setq name (car (nth 0 port)))
11536 (insert (vhdl-replace-string vhdl-actual-port-name name))
11537 ;; paste initialization
11538 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11539 "(others => '0')" "'0'") ";"))
11540 (setq port-list (cdr port-list))
11541 (when (and port-list
11542 (equal "IN" (upcase (nth 2 (car port-list)))))
11543 (insert "\n") (indent-to margin)))
11544 ;; align signal list
11545 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11546 (message "Pasting port as initializations...done")
11547 (setq vhdl-port-list orig-vhdl-port-list))))
11548
11549 (defun vhdl-port-paste-testbench ()
11550 "Paste as a bare-bones testbench."
11551 (interactive)
11552 (if (not vhdl-port-list)
11553 (error "ERROR: No port read")
11554 (let ((case-fold-search t)
11555 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11556 (nth 0 vhdl-port-list)))
11557 (source-buffer (current-buffer))
11558 arch-name config-name ent-file-name arch-file-name
11559 ent-buffer arch-buffer position)
11560 ;; open entity file
11561 (unless (eq vhdl-testbench-create-files 'none)
11562 (setq ent-file-name
11563 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11564 ent-name t)
11565 "." (file-name-extension (buffer-file-name))))
11566 (if (file-exists-p ent-file-name)
11567 (if (y-or-n-p
11568 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11569 (progn (find-file ent-file-name)
11570 (erase-buffer)
11571 (set-buffer-modified-p nil))
11572 (if (eq vhdl-testbench-create-files 'separate)
11573 (setq ent-file-name nil)
11574 (error "ERROR: Pasting port as testbench...aborted")))
11575 (find-file ent-file-name)))
11576 (unless (and (eq vhdl-testbench-create-files 'separate)
11577 (null ent-file-name))
11578 ;; paste entity header
11579 (if vhdl-testbench-include-header
11580 (progn (vhdl-template-header
11581 (concat "Testbench for design \""
11582 (nth 0 vhdl-port-list) "\""))
11583 (goto-char (point-max)))
11584 (vhdl-comment-display-line) (insert "\n\n"))
11585 ;; paste std_logic_1164 package
11586 (when vhdl-testbench-include-library
11587 (vhdl-template-package-std-logic-1164)
11588 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11589 ;; paste entity declaration
11590 (vhdl-insert-keyword "ENTITY ")
11591 (insert ent-name)
11592 (vhdl-insert-keyword " IS")
11593 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11594 (insert "\n")
11595 (vhdl-insert-keyword "END ")
11596 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11597 (insert ent-name ";")
11598 (insert "\n\n")
11599 (vhdl-comment-display-line) (insert "\n"))
11600 ;; get architecture name
11601 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11602 (read-from-minibuffer "architecture name: "
11603 nil vhdl-minibuffer-local-map)
11604 (vhdl-replace-string vhdl-testbench-architecture-name
11605 (nth 0 vhdl-port-list))))
11606 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11607 ;; open architecture file
11608 (if (not (eq vhdl-testbench-create-files 'separate))
11609 (insert "\n")
11610 (setq ent-buffer (current-buffer))
11611 (setq arch-file-name
11612 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11613 (concat ent-name " " arch-name) t)
11614 "." (file-name-extension (buffer-file-name))))
11615 (when (and (file-exists-p arch-file-name)
11616 (not (y-or-n-p (concat "File \"" arch-file-name
11617 "\" exists; overwrite? "))))
11618 (error "ERROR: Pasting port as testbench...aborted"))
11619 (find-file arch-file-name)
11620 (erase-buffer)
11621 (set-buffer-modified-p nil)
11622 ;; paste architecture header
11623 (if vhdl-testbench-include-header
11624 (progn (vhdl-template-header
11625 (concat "Testbench architecture for design \""
11626 (nth 0 vhdl-port-list) "\""))
11627 (goto-char (point-max)))
11628 (vhdl-comment-display-line) (insert "\n\n")))
11629 ;; paste architecture body
11630 (vhdl-insert-keyword "ARCHITECTURE ")
11631 (insert arch-name)
11632 (vhdl-insert-keyword " OF ")
11633 (insert ent-name)
11634 (vhdl-insert-keyword " IS")
11635 (insert "\n\n") (indent-to vhdl-basic-offset)
11636 ;; paste component declaration
11637 (unless (vhdl-use-direct-instantiation)
11638 (vhdl-port-paste-component t)
11639 (insert "\n\n") (indent-to vhdl-basic-offset))
11640 ;; paste constants
11641 (when (nth 1 vhdl-port-list)
11642 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11643 (vhdl-port-paste-constants t)
11644 (insert "\n\n") (indent-to vhdl-basic-offset))
11645 ;; paste internal signals
11646 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11647 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11648 (insert "\n")
11649 ;; paste custom declarations
11650 (unless (equal "" vhdl-testbench-declarations)
11651 (insert "\n")
11652 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11653 (setq position (point))
11654 (insert "\n\n")
11655 (vhdl-comment-display-line) (insert "\n")
11656 (when vhdl-testbench-include-configuration
11657 (setq config-name (vhdl-replace-string
11658 vhdl-testbench-configuration-name
11659 (concat ent-name " " arch-name)))
11660 (insert "\n")
11661 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11662 (vhdl-insert-keyword " OF ") (insert ent-name)
11663 (vhdl-insert-keyword " IS\n")
11664 (indent-to vhdl-basic-offset)
11665 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11666 (indent-to vhdl-basic-offset)
11667 (vhdl-insert-keyword "END FOR;\n")
11668 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11669 (vhdl-comment-display-line) (insert "\n"))
11670 (goto-char position)
11671 (vhdl-template-begin-end
11672 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11673 ;; paste instantiation
11674 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11675 (vhdl-port-paste-instance
11676 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11677 (insert "\n")
11678 ;; paste custom statements
11679 (unless (equal "" vhdl-testbench-statements)
11680 (insert "\n")
11681 (vhdl-insert-string-or-file vhdl-testbench-statements))
11682 (insert "\n")
11683 (indent-to vhdl-basic-offset)
11684 (unless (eq vhdl-testbench-create-files 'none)
11685 (setq arch-buffer (current-buffer))
11686 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11687 (set-buffer arch-buffer) (save-buffer))
11688 (message "%s"
11689 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11690 ent-name arch-name)
11691 (and ent-file-name
11692 (format "\n File created: \"%s\"" ent-file-name))
11693 (and arch-file-name
11694 (format "\n File created: \"%s\"" arch-file-name)))))))
11695
11696
11697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11698 ;;; Subprogram interface translation
11699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11700
11701 (defvar vhdl-subprog-list nil
11702 "Variable to hold last subprogram interface parsed.")
11703 ;; structure: (parenthesised expression means list of such entries)
11704 ;; (subprog-name kind
11705 ;; ((names) object direct type init comment group-comment)
11706 ;; return-type return-comment group-comment)
11707
11708 (defvar vhdl-subprog-flattened nil
11709 "Indicates whether an subprogram interface has been flattened.")
11710
11711 (defun vhdl-subprog-flatten ()
11712 "Flatten interface list so that only one parameter exists per line."
11713 (interactive)
11714 (if (not vhdl-subprog-list)
11715 (error "ERROR: No subprogram interface has been read")
11716 (message "Flattening subprogram interface...")
11717 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11718 new-subprog-list old-subprog new-subprog names)
11719 ;; traverse parameter list and flatten entries
11720 (while old-subprog-list
11721 (setq old-subprog (car old-subprog-list))
11722 (setq names (car old-subprog))
11723 (while names
11724 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11725 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11726 (setq names (cdr names)))
11727 (setq old-subprog-list (cdr old-subprog-list)))
11728 (setq vhdl-subprog-list
11729 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11730 new-subprog-list (nth 3 vhdl-subprog-list)
11731 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11732 vhdl-subprog-flattened t)
11733 (message "Flattening subprogram interface...done"))))
11734
11735 (defun vhdl-subprog-copy ()
11736 "Get interface information from a subprogram specification."
11737 (interactive)
11738 (save-excursion
11739 (let (parse-error pos end-of-list
11740 name kind param-list object names direct type init
11741 comment group-comment
11742 return-type return-comment return-group-comment)
11743 (vhdl-prepare-search-2
11744 (setq
11745 parse-error
11746 (catch 'parse
11747 ;; check if within function declaration
11748 (setq pos (point))
11749 (end-of-line)
11750 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11751 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11752 (goto-char (match-end 0))
11753 (save-excursion (backward-char)
11754 (forward-sexp)
11755 (<= pos (point))))
11756 (throw 'parse "ERROR: Not within a subprogram specification"))
11757 (setq name (match-string-no-properties 5))
11758 (setq kind (if (match-string 2) 'procedure 'function))
11759 (setq end-of-list (not (match-string 7)))
11760 (message "Reading interface of subprogram \"%s\"..." name)
11761 ;; parse parameter list
11762 (setq group-comment (vhdl-parse-group-comment))
11763 (setq end-of-list (or end-of-list
11764 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11765 (while (not end-of-list)
11766 ;; parse object
11767 (setq object
11768 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11769 (match-string-no-properties 1)))
11770 ;; parse names (accept extended identifiers)
11771 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11772 (setq names (list (match-string-no-properties 1)))
11773 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11774 (setq names (append names (list (match-string-no-properties 1)))))
11775 ;; parse direction
11776 (vhdl-parse-string ":[ \t\n]*")
11777 (setq direct
11778 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11779 (match-string-no-properties 1)))
11780 ;; parse type
11781 (vhdl-parse-string "\\([^():;\n]+\\)")
11782 (setq type (match-string-no-properties 1))
11783 (setq comment nil)
11784 (while (looking-at "(")
11785 (setq type
11786 (concat type
11787 (buffer-substring-no-properties
11788 (point) (progn (forward-sexp) (point)))
11789 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11790 (match-string-no-properties 1)))))
11791 ;; special case: closing parenthesis is on separate line
11792 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11793 (setq comment (substring type (match-beginning 2)))
11794 (setq type (substring type 0 (match-beginning 1))))
11795 ;; strip off trailing group-comment
11796 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11797 (setq type (substring type 0 (match-end 1)))
11798 ;; parse initialization expression
11799 (setq init nil)
11800 (when (vhdl-parse-string ":=[ \t\n]*" t)
11801 (vhdl-parse-string "\\([^();\n]*\\)")
11802 (setq init (match-string-no-properties 1))
11803 (while (looking-at "(")
11804 (setq init
11805 (concat init
11806 (buffer-substring-no-properties
11807 (point) (progn (forward-sexp) (point)))
11808 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11809 (match-string-no-properties 1))))))
11810 ;; special case: closing parenthesis is on separate line
11811 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11812 (setq comment (substring init (match-beginning 2)))
11813 (setq init (substring init 0 (match-beginning 1)))
11814 (vhdl-forward-syntactic-ws))
11815 (skip-chars-forward " \t")
11816 ;; parse inline comment, special case: as above, no initial.
11817 (unless comment
11818 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11819 (match-string-no-properties 1))))
11820 (vhdl-forward-syntactic-ws)
11821 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11822 ;; parse inline comment
11823 (unless comment
11824 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11825 (match-string-no-properties 1))))
11826 (setq return-group-comment (vhdl-parse-group-comment))
11827 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11828 ;; parse return type
11829 (when (match-string 3)
11830 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11831 (setq return-type (match-string-no-properties 1))
11832 (when (and return-type
11833 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11834 (setq return-comment (substring return-type (match-beginning 2)))
11835 (setq return-type (substring return-type 0 (match-beginning 1))))
11836 ;; strip of trailing group-comment
11837 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11838 (setq return-type (substring return-type 0 (match-end 1)))
11839 ;; parse return comment
11840 (unless return-comment
11841 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11842 (match-string-no-properties 1)))))
11843 ;; parse inline comment
11844 (unless comment
11845 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11846 (match-string-no-properties 1))))
11847 ;; save everything in list
11848 (setq param-list (append param-list
11849 (list (list names object direct type init
11850 comment group-comment))))
11851 ;; parse group comment and spacing
11852 (setq group-comment (vhdl-parse-group-comment)))
11853 (message "Reading interface of subprogram \"%s\"...done" name)
11854 nil)))
11855 ;; finish parsing
11856 (if parse-error
11857 (error parse-error)
11858 (setq vhdl-subprog-list
11859 (list name kind param-list return-type return-comment
11860 return-group-comment)
11861 vhdl-subprog-flattened nil)))))
11862
11863 (defun vhdl-subprog-paste-specification (kind)
11864 "Paste as a subprogram specification."
11865 (indent-according-to-mode)
11866 (let ((margin (current-column))
11867 (param-list (nth 2 vhdl-subprog-list))
11868 list-margin start names param)
11869 ;; paste keyword and name
11870 (vhdl-insert-keyword
11871 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11872 (insert (nth 0 vhdl-subprog-list))
11873 (if (not param-list)
11874 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11875 (setq start (point))
11876 ;; paste parameter list
11877 (insert " (")
11878 (unless vhdl-argument-list-indent
11879 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11880 (setq list-margin (current-column))
11881 (while param-list
11882 (setq param (car param-list))
11883 ;; paste group comment and spacing
11884 (when (memq vhdl-include-group-comments (list kind 'always))
11885 (vhdl-paste-group-comment (nth 6 param) list-margin))
11886 ;; paste object
11887 (when (nth 1 param) (insert (nth 1 param) " "))
11888 ;; paste names
11889 (setq names (nth 0 param))
11890 (while names
11891 (insert (car names))
11892 (setq names (cdr names))
11893 (when names (insert ", ")))
11894 ;; paste direction
11895 (insert " : ")
11896 (when (nth 2 param) (insert (nth 2 param) " "))
11897 ;; paste type
11898 (insert (nth 3 param))
11899 ;; paste initialization
11900 (when (nth 4 param) (insert " := " (nth 4 param)))
11901 ;; terminate line
11902 (if (cdr param-list)
11903 (insert ";")
11904 (insert ")")
11905 (when (null (nth 3 vhdl-subprog-list))
11906 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11907 ;; paste comment
11908 (when (and vhdl-include-port-comments (nth 5 param))
11909 (vhdl-comment-insert-inline (nth 5 param) t))
11910 (setq param-list (cdr param-list))
11911 (when param-list (insert "\n") (indent-to list-margin)))
11912 (when (nth 3 vhdl-subprog-list)
11913 (insert "\n") (indent-to list-margin)
11914 ;; paste group comment and spacing
11915 (when (memq vhdl-include-group-comments (list kind 'always))
11916 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11917 ;; paste return type
11918 (insert "return " (nth 3 vhdl-subprog-list))
11919 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11920 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11921 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11922 ;; align parameter list
11923 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11924 ;; paste body
11925 (when (eq kind 'body)
11926 (insert "\n")
11927 (vhdl-template-begin-end
11928 (unless (vhdl-standard-p '87)
11929 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11930 (nth 0 vhdl-subprog-list) margin))))
11931
11932 (defun vhdl-subprog-paste-declaration ()
11933 "Paste as a subprogram declaration."
11934 (interactive)
11935 (if (not vhdl-subprog-list)
11936 (error "ERROR: No subprogram interface read")
11937 (message "Pasting interface as subprogram declaration \"%s\"..."
11938 (car vhdl-subprog-list))
11939 ;; paste specification
11940 (vhdl-subprog-paste-specification 'decl)
11941 (message "Pasting interface as subprogram declaration \"%s\"...done"
11942 (car vhdl-subprog-list))))
11943
11944 (defun vhdl-subprog-paste-body ()
11945 "Paste as a subprogram body."
11946 (interactive)
11947 (if (not vhdl-subprog-list)
11948 (error "ERROR: No subprogram interface read")
11949 (message "Pasting interface as subprogram body \"%s\"..."
11950 (car vhdl-subprog-list))
11951 ;; paste specification and body
11952 (vhdl-subprog-paste-specification 'body)
11953 (message "Pasting interface as subprogram body \"%s\"...done"
11954 (car vhdl-subprog-list))))
11955
11956 (defun vhdl-subprog-paste-call ()
11957 "Paste as a subprogram call."
11958 (interactive)
11959 (if (not vhdl-subprog-list)
11960 (error "ERROR: No subprogram interface read")
11961 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11962 param-list margin list-margin param start)
11963 ;; flatten local copy of interface list (must be flat for parameter mapping)
11964 (vhdl-subprog-flatten)
11965 (setq param-list (nth 2 vhdl-subprog-list))
11966 (indent-according-to-mode)
11967 (setq margin (current-indentation))
11968 (message "Pasting interface as subprogram call \"%s\"..."
11969 (car vhdl-subprog-list))
11970 ;; paste name
11971 (insert (nth 0 vhdl-subprog-list))
11972 (if (not param-list)
11973 (insert ";")
11974 (setq start (point))
11975 ;; paste parameter list
11976 (insert " (")
11977 (unless vhdl-argument-list-indent
11978 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11979 (setq list-margin (current-column))
11980 (while param-list
11981 (setq param (car param-list))
11982 ;; paste group comment and spacing
11983 (when (eq vhdl-include-group-comments 'always)
11984 (vhdl-paste-group-comment (nth 6 param) list-margin))
11985 ;; paste formal port
11986 (insert (car (nth 0 param)) " => ")
11987 (setq param-list (cdr param-list))
11988 (insert (if param-list "," ");"))
11989 ;; paste comment
11990 (when (and vhdl-include-port-comments (nth 5 param))
11991 (vhdl-comment-insert-inline (nth 5 param)))
11992 (when param-list (insert "\n") (indent-to list-margin)))
11993 ;; align parameter list
11994 (when vhdl-auto-align
11995 (vhdl-align-region-groups start (point) 1)))
11996 (message "Pasting interface as subprogram call \"%s\"...done"
11997 (car vhdl-subprog-list))
11998 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11999
12000
12001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12002 ;;; Miscellaneous
12003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12004
12005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12006 ;; Hippie expand customization
12007
12008 (defvar vhdl-expand-upper-case nil)
12009
12010 (defun vhdl-try-expand-abbrev (old)
12011 "Try expanding abbreviations from `vhdl-abbrev-list'."
12012 (unless old
12013 (he-init-string (he-dabbrev-beg) (point))
12014 (setq he-expand-list
12015 (let ((abbrev-list vhdl-abbrev-list)
12016 (sel-abbrev-list '()))
12017 (while abbrev-list
12018 (when (or (not (stringp (car abbrev-list)))
12019 (string-match
12020 (concat "^" he-search-string) (car abbrev-list)))
12021 (setq sel-abbrev-list
12022 (cons (car abbrev-list) sel-abbrev-list)))
12023 (setq abbrev-list (cdr abbrev-list)))
12024 (nreverse sel-abbrev-list))))
12025 (while (and he-expand-list
12026 (or (not (stringp (car he-expand-list)))
12027 (he-string-member (car he-expand-list) he-tried-table t)))
12028 ; (equal (car he-expand-list) he-search-string)))
12029 (unless (stringp (car he-expand-list))
12030 (setq vhdl-expand-upper-case (car he-expand-list)))
12031 (setq he-expand-list (cdr he-expand-list)))
12032 (if (null he-expand-list)
12033 (progn (when old (he-reset-string))
12034 nil)
12035 (he-substitute-string
12036 (if vhdl-expand-upper-case
12037 (upcase (car he-expand-list))
12038 (car he-expand-list))
12039 t)
12040 (setq he-expand-list (cdr he-expand-list))
12041 t))
12042
12043 (defun vhdl-he-list-beg ()
12044 "Also looks at the word before `(' in order to better match parenthesized
12045 expressions (e.g. for index ranges of types and signals)."
12046 (save-excursion
12047 (condition-case ()
12048 (progn (backward-up-list 1)
12049 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12050 (error ()))
12051 (point)))
12052
12053 ;; override `he-list-beg' from `hippie-exp'
12054 (unless (and (boundp 'viper-mode) viper-mode)
12055 (defalias 'he-list-beg 'vhdl-he-list-beg))
12056
12057 ;; function for expanding abbrevs and dabbrevs
12058 (defun vhdl-expand-abbrev (arg))
12059 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12060 '(try-expand-dabbrev
12061 try-expand-dabbrev-all-buffers
12062 vhdl-try-expand-abbrev)))
12063
12064 ;; function for expanding parenthesis
12065 (defun vhdl-expand-paren (arg))
12066 (fset 'vhdl-expand-paren (make-hippie-expand-function
12067 '(try-expand-list
12068 try-expand-list-all-buffers)))
12069
12070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12071 ;; Case fixing
12072
12073 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12074 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12075 depending on parameter UPPER-CASE."
12076 (let ((case-replace nil)
12077 (last-update 0))
12078 (vhdl-prepare-search-2
12079 (save-excursion
12080 (goto-char end)
12081 (setq end (point-marker))
12082 (goto-char beg)
12083 (while (re-search-forward word-regexp end t)
12084 (or (vhdl-in-literal)
12085 (if upper-case
12086 (upcase-word -1)
12087 (downcase-word -1)))
12088 (when (and count vhdl-progress-interval (not noninteractive)
12089 (< vhdl-progress-interval
12090 (- (nth 1 (current-time)) last-update)))
12091 (message "Fixing case... (%2d%s)"
12092 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12093 "%")
12094 (setq last-update (nth 1 (current-time)))))
12095 (goto-char end)))))
12096
12097 (defun vhdl-fix-case-region (beg end &optional arg)
12098 "Convert all VHDL words in region to lower or upper case, depending on
12099 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12100 (interactive "r\nP")
12101 (vhdl-fix-case-region-1
12102 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12103 (vhdl-fix-case-region-1
12104 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12105 (vhdl-fix-case-region-1
12106 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12107 (vhdl-fix-case-region-1
12108 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12109 (when vhdl-progress-interval (message "Fixing case...done")))
12110
12111 (defun vhdl-fix-case-buffer ()
12112 "Convert all VHDL words in buffer to lower or upper case, depending on
12113 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12114 (interactive)
12115 (vhdl-fix-case-region (point-min) (point-max)))
12116
12117 (defun vhdl-fix-case-word (&optional arg)
12118 "Convert word after cursor to upper case if necessary."
12119 (interactive "p")
12120 (save-excursion
12121 (when arg (backward-word 1))
12122 (vhdl-prepare-search-1
12123 (when (and vhdl-upper-case-keywords
12124 (looking-at vhdl-keywords-regexp))
12125 (upcase-word 1))
12126 (when (and vhdl-upper-case-types
12127 (looking-at vhdl-types-regexp))
12128 (upcase-word 1))
12129 (when (and vhdl-upper-case-attributes
12130 (looking-at vhdl-attributes-regexp))
12131 (upcase-word 1))
12132 (when (and vhdl-upper-case-enum-values
12133 (looking-at vhdl-enum-values-regexp))
12134 (upcase-word 1)))))
12135
12136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12137 ;; Line handling functions
12138
12139 (defun vhdl-current-line ()
12140 "Return the line number of the line containing point."
12141 (save-restriction
12142 (widen)
12143 (save-excursion
12144 (beginning-of-line)
12145 (1+ (count-lines (point-min) (point))))))
12146
12147 (defun vhdl-line-kill-entire (&optional arg)
12148 "Delete entire line."
12149 (interactive "p")
12150 (beginning-of-line)
12151 (kill-line (or arg 1)))
12152
12153 (defun vhdl-line-kill (&optional arg)
12154 "Kill current line."
12155 (interactive "p")
12156 (vhdl-line-kill-entire arg))
12157
12158 (defun vhdl-line-copy (&optional arg)
12159 "Copy current line."
12160 (interactive "p")
12161 (save-excursion
12162 (beginning-of-line)
12163 (let ((position (point)))
12164 (forward-line (or arg 1))
12165 (copy-region-as-kill position (point)))))
12166
12167 (defun vhdl-line-yank ()
12168 "Yank entire line."
12169 (interactive)
12170 (beginning-of-line)
12171 (yank))
12172
12173 (defun vhdl-line-expand (&optional prefix-arg)
12174 "Hippie-expand current line."
12175 (interactive "P")
12176 (let ((case-fold-search t) (case-replace nil)
12177 (hippie-expand-try-functions-list
12178 '(try-expand-line try-expand-line-all-buffers)))
12179 (hippie-expand prefix-arg)))
12180
12181 (defun vhdl-line-transpose-next (&optional arg)
12182 "Interchange this line with next line."
12183 (interactive "p")
12184 (forward-line 1)
12185 (transpose-lines (or arg 1))
12186 (forward-line -1))
12187
12188 (defun vhdl-line-transpose-previous (&optional arg)
12189 "Interchange this line with previous line."
12190 (interactive "p")
12191 (forward-line 1)
12192 (transpose-lines (- 0 (or arg 0)))
12193 (forward-line -1))
12194
12195 (defun vhdl-line-open ()
12196 "Open a new line and indent."
12197 (interactive)
12198 (end-of-line -0)
12199 (newline-and-indent))
12200
12201 (defun vhdl-delete-indentation ()
12202 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12203 it works within comments too."
12204 (interactive)
12205 (let ((fill-prefix "-- "))
12206 (delete-indentation)))
12207
12208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12209 ;; Move functions
12210
12211 (defun vhdl-forward-same-indent ()
12212 "Move forward to next line with same indent."
12213 (interactive)
12214 (let ((pos (point))
12215 (indent (current-indentation)))
12216 (beginning-of-line 2)
12217 (while (and (not (eobp))
12218 (or (looking-at "^\\s-*\\(--.*\\)?$")
12219 (> (current-indentation) indent)))
12220 (beginning-of-line 2))
12221 (if (= (current-indentation) indent)
12222 (back-to-indentation)
12223 (message "No following line with same indent found in this block")
12224 (goto-char pos)
12225 nil)))
12226
12227 (defun vhdl-backward-same-indent ()
12228 "Move backward to previous line with same indent."
12229 (interactive)
12230 (let ((pos (point))
12231 (indent (current-indentation)))
12232 (beginning-of-line -0)
12233 (while (and (not (bobp))
12234 (or (looking-at "^\\s-*\\(--.*\\)?$")
12235 (> (current-indentation) indent)))
12236 (beginning-of-line -0))
12237 (if (= (current-indentation) indent)
12238 (back-to-indentation)
12239 (message "No preceding line with same indent found in this block")
12240 (goto-char pos)
12241 nil)))
12242
12243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12244 ;; Statistics
12245
12246 (defun vhdl-statistics-buffer ()
12247 "Get some file statistics."
12248 (interactive)
12249 (let ((no-stats 0)
12250 (no-code-lines 0)
12251 (no-lines (count-lines (point-min) (point-max))))
12252 (save-excursion
12253 ;; count statements
12254 (goto-char (point-min))
12255 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12256 (if (match-string 1)
12257 (goto-char (match-end 1))
12258 (setq no-stats (1+ no-stats))))
12259 ;; count code lines
12260 (goto-char (point-min))
12261 (while (not (eobp))
12262 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12263 (setq no-code-lines (1+ no-code-lines)))
12264 (beginning-of-line 2)))
12265 ;; print results
12266 (message "\n\
12267 File statistics: \"%s\"\n\
12268 ---------------------\n\
12269 # statements : %5d\n\
12270 # code lines : %5d\n\
12271 # total lines : %5d\n\ "
12272 (buffer-file-name) no-stats no-code-lines no-lines)
12273 (unless vhdl-emacs-21 (vhdl-show-messages))))
12274
12275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12276 ;; Help functions
12277
12278 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12279 "Like `re-search-forward', but does not match within literals."
12280 (let (pos)
12281 (save-excursion
12282 (while (and (setq pos (re-search-forward regexp bound noerror count))
12283 (vhdl-in-literal))))
12284 (when pos (goto-char pos))
12285 pos))
12286
12287 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12288 "Like `re-search-backward', but does not match within literals."
12289 (let (pos)
12290 (save-excursion
12291 (while (and (setq pos (re-search-backward regexp bound noerror count))
12292 (vhdl-in-literal))))
12293 (when pos (goto-char pos))
12294 pos))
12295
12296
12297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12298 ;;; Project
12299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12300
12301 (defun vhdl-set-project (name)
12302 "Set current project to NAME."
12303 (interactive
12304 (list (let ((completion-ignore-case t))
12305 (completing-read "Project name: " vhdl-project-alist nil t))))
12306 (cond ((equal name "")
12307 (setq vhdl-project nil)
12308 (message "Current VHDL project: None"))
12309 ((assoc name vhdl-project-alist)
12310 (setq vhdl-project name)
12311 (message "Current VHDL project: \"%s\"" name))
12312 (t
12313 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12314 (vhdl-speedbar-update-current-project))
12315
12316 (defun vhdl-set-default-project ()
12317 "Set current project as default on startup."
12318 (interactive)
12319 (customize-set-variable 'vhdl-project vhdl-project)
12320 (customize-save-customized))
12321
12322 (defun vhdl-toggle-project (name token indent)
12323 "Set current project to NAME or unset if NAME is current project."
12324 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12325
12326 (defun vhdl-export-project (file-name)
12327 "Write project setup for current project."
12328 (interactive
12329 (let ((name (vhdl-resolve-env-variable
12330 (vhdl-replace-string
12331 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12332 (concat (subst-char-in-string
12333 ? ?_ (or (vhdl-project-p)
12334 (error "ERROR: No current project")))
12335 " " (user-login-name))))))
12336 (list (read-file-name
12337 "Write project file: "
12338 (when (file-name-absolute-p name) "") nil nil name))))
12339 (setq file-name (abbreviate-file-name file-name))
12340 (let ((orig-buffer (current-buffer)))
12341 (unless (file-exists-p (file-name-directory file-name))
12342 (make-directory (file-name-directory file-name) t))
12343 (if (not (file-writable-p file-name))
12344 (error "ERROR: File not writable: \"%s\"" file-name)
12345 (set-buffer (find-file-noselect file-name t t))
12346 (erase-buffer)
12347 (insert ";; -*- Emacs-Lisp -*-\n\n"
12348 ";;; " (file-name-nondirectory file-name)
12349 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12350 ";; Project : " vhdl-project "\n"
12351 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12352 (user-login-name) "\n\n\n"
12353 ";; project name\n"
12354 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12355 ";; project setup\n"
12356 "(aput 'vhdl-project-alist vhdl-project\n'")
12357 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12358 (insert ")\n")
12359 (save-buffer)
12360 (kill-buffer (current-buffer))
12361 (set-buffer orig-buffer))))
12362
12363 (defun vhdl-import-project (file-name &optional auto not-make-current)
12364 "Read project setup and set current project."
12365 (interactive
12366 (let ((name (vhdl-resolve-env-variable
12367 (vhdl-replace-string
12368 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12369 (concat "" " " (user-login-name))))))
12370 (list (read-file-name
12371 "Read project file: " (when (file-name-absolute-p name) "") nil t
12372 (file-name-directory name)))))
12373 (when (file-exists-p file-name)
12374 (condition-case ()
12375 (let ((current-project vhdl-project))
12376 (load-file file-name)
12377 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12378 (adelete 'vhdl-project-alist vhdl-project)
12379 (error ""))
12380 (when not-make-current
12381 (setq vhdl-project current-project))
12382 (vhdl-update-mode-menu)
12383 (vhdl-speedbar-refresh)
12384 (unless not-make-current
12385 (message "Current VHDL project: \"%s\"%s"
12386 vhdl-project (if auto " (auto-loaded)" ""))))
12387 (error (vhdl-warning
12388 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12389
12390 (defun vhdl-duplicate-project ()
12391 "Duplicate setup of current project."
12392 (interactive)
12393 (let ((new-name (read-from-minibuffer "New project name: "))
12394 (project-entry (aget vhdl-project-alist vhdl-project t)))
12395 (setq vhdl-project-alist
12396 (append vhdl-project-alist
12397 (list (cons new-name project-entry))))
12398 (vhdl-update-mode-menu)))
12399
12400 (defun vhdl-auto-load-project ()
12401 "Automatically load project setup at startup."
12402 (let ((file-name-list vhdl-project-file-name)
12403 file-list list-length)
12404 (while file-name-list
12405 (setq file-list
12406 (append file-list
12407 (file-expand-wildcards
12408 (vhdl-resolve-env-variable
12409 (vhdl-replace-string
12410 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12411 (concat "\*" " " (user-login-name)))))))
12412 (setq list-length (or list-length (length file-list)))
12413 (setq file-name-list (cdr file-name-list)))
12414 (while file-list
12415 (vhdl-import-project (expand-file-name (car file-list)) t
12416 (not (> list-length 0)))
12417 (setq list-length (1- list-length))
12418 (setq file-list (cdr file-list)))))
12419
12420 ;; automatically load project setup when idle after startup
12421 (when (memq 'startup vhdl-project-auto-load)
12422 (if noninteractive
12423 (vhdl-auto-load-project)
12424 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12425
12426
12427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12428 ;;; Hideshow
12429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12430 ;; (using `hideshow.el')
12431
12432 (defconst vhdl-hs-start-regexp
12433 (concat
12434 "\\(^\\)\\s-*\\("
12435 ;; generic/port clause
12436 "\\(generic\\|port\\)[ \t\n]*(\\|"
12437 ;; component
12438 "component\\>\\|"
12439 ;; component instantiation
12440 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12441 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12442 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12443 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12444 ;; subprogram
12445 "\\(function\\|procedure\\)\\>\\|"
12446 ;; process, block
12447 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12448 ;; configuration declaration
12449 "configuration\\>"
12450 "\\)")
12451 "Regexp to match start of construct to hide.")
12452
12453 (defun vhdl-hs-forward-sexp-func (count)
12454 "Find end of construct to hide (for hideshow). Only searches forward."
12455 (let ((pos (point)))
12456 (vhdl-prepare-search-2
12457 (beginning-of-line)
12458 (cond
12459 ;; generic/port clause
12460 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12461 (goto-char (match-end 0))
12462 (backward-char)
12463 (forward-sexp))
12464 ;; component declaration
12465 ((looking-at "^\\s-*component\\>")
12466 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12467 ;; component instantiation
12468 ((looking-at
12469 (concat
12470 "^\\s-*\\w+\\s-*:[ \t\n]*"
12471 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12472 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12473 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12474 (goto-char (match-end 0))
12475 (backward-char)
12476 (forward-sexp)
12477 (setq pos (point))
12478 (vhdl-forward-syntactic-ws)
12479 (when (looking-at "port\\s-+map[ \t\n]*(")
12480 (goto-char (match-end 0))
12481 (backward-char)
12482 (forward-sexp)
12483 (setq pos (point)))
12484 (goto-char pos))
12485 ;; subprogram declaration/body
12486 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12487 (goto-char (match-end 0))
12488 (vhdl-forward-syntactic-ws)
12489 (when (looking-at "(")
12490 (forward-sexp))
12491 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12492 (vhdl-in-literal)))
12493 ;; subprogram body
12494 (when (match-string 2)
12495 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12496 (backward-word 1)
12497 (vhdl-forward-sexp)))
12498 ;; block (recursive)
12499 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12500 (goto-char (match-end 0))
12501 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12502 (match-beginning 2))
12503 (vhdl-hs-forward-sexp-func count)))
12504 ;; process
12505 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12506 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12507 ;; configuration declaration
12508 ((looking-at "^\\s-*configuration\\>")
12509 (forward-word 4)
12510 (vhdl-forward-sexp))
12511 (t (goto-char pos))))))
12512
12513 (defun vhdl-hideshow-init ()
12514 "Initialize `hideshow'."
12515 (when vhdl-hideshow-menu
12516 (vhdl-hs-minor-mode 1)))
12517
12518 (defun vhdl-hs-minor-mode (&optional arg)
12519 "Toggle hideshow minor mode and update menu bar."
12520 (interactive "P")
12521 (require 'hideshow)
12522 ;; check for hideshow version 5.x
12523 (if (not (boundp 'hs-block-start-mdata-select))
12524 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12525 ;; initialize hideshow
12526 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12527 (setq hs-special-modes-alist
12528 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12529 'vhdl-hs-forward-sexp-func nil)
12530 hs-special-modes-alist)))
12531 (make-local-variable 'hs-minor-mode-hook)
12532 (if vhdl-hide-all-init
12533 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12534 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12535 (hs-minor-mode arg)
12536 (vhdl-mode-line-update))) ; hack to update menu bar
12537
12538
12539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12540 ;;; Font locking
12541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12542 ;; (using `font-lock.el')
12543
12544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12545 ;; Help functions
12546
12547 (defun vhdl-within-translate-off ()
12548 "Return point if within translate-off region, else nil."
12549 (and (save-excursion
12550 (re-search-backward
12551 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12552 (equal "off" (match-string 1))
12553 (point)))
12554
12555 (defun vhdl-start-translate-off (limit)
12556 "Return point before translate-off pragma if before LIMIT, else nil."
12557 (when (re-search-forward
12558 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12559 (match-beginning 0)))
12560
12561 (defun vhdl-end-translate-off (limit)
12562 "Return point after translate-on pragma if before LIMIT, else nil."
12563 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12564
12565 (defun vhdl-match-translate-off (limit)
12566 "Match a translate-off block, setting match-data and returning t, else nil."
12567 (when (< (point) limit)
12568 (let ((start (or (vhdl-within-translate-off)
12569 (vhdl-start-translate-off limit)))
12570 (case-fold-search t))
12571 (when start
12572 (let ((end (or (vhdl-end-translate-off limit) limit)))
12573 (set-match-data (list start end))
12574 (goto-char end))))))
12575
12576 (defun vhdl-font-lock-match-item (limit)
12577 "Match, and move over, any declaration item after point. Adapted from
12578 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12579 (condition-case nil
12580 (save-restriction
12581 (narrow-to-region (point-min) limit)
12582 ;; match item
12583 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12584 (save-match-data
12585 (goto-char (match-end 1))
12586 ;; move to next item
12587 (if (looking-at "\\(\\s-*,\\)")
12588 (goto-char (match-end 1))
12589 (end-of-line) t))))
12590 (error t)))
12591
12592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12593 ;; Syntax definitions
12594
12595 (defconst vhdl-font-lock-syntactic-keywords
12596 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12597 "Mark single quotes as having string quote syntax in 'c' instances.")
12598
12599 (defvar vhdl-font-lock-keywords nil
12600 "Regular expressions to highlight in VHDL Mode.")
12601
12602 (defvar vhdl-font-lock-keywords-0
12603 ;; set in `vhdl-font-lock-init' because dependent on user options
12604 "For consideration as a value of `vhdl-font-lock-keywords'.
12605 This does highlighting of template prompts and directives (pragmas).")
12606
12607 (defvar vhdl-font-lock-keywords-1 nil
12608 ;; set in `vhdl-font-lock-init' because dependent on user options
12609 "For consideration as a value of `vhdl-font-lock-keywords'.
12610 This does highlighting of keywords and standard identifiers.")
12611
12612 (defconst vhdl-font-lock-keywords-2
12613 (list
12614 ;; highlight names of units, subprograms, and components when declared
12615 (list
12616 (concat
12617 "^\\s-*\\("
12618 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12619 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12620 "\\)\\s-+\\(\\w+\\)")
12621 5 'font-lock-function-name-face)
12622
12623 ;; highlight entity names of architectures and configurations
12624 (list
12625 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12626 2 'font-lock-function-name-face)
12627
12628 ;; highlight labels of common constructs
12629 (list
12630 (concat
12631 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12632 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12633 "postponed\\|process\\|"
12634 (when (vhdl-standard-p 'ams) "procedural\\|")
12635 "with\\|while"
12636 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12637 1 'font-lock-function-name-face)
12638
12639 ;; highlight label and component name of component instantiations
12640 (list
12641 (concat
12642 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12643 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12644 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12645
12646 ;; highlight label and instantiated unit of component instantiations
12647 (list
12648 (concat
12649 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12650 "\\(component\\|configuration\\|entity\\)\\s-+"
12651 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12652 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12653 '(5 font-lock-function-name-face nil t)
12654 '(7 font-lock-function-name-face nil t))
12655
12656 ;; highlight names and labels at end of constructs
12657 (list
12658 (concat
12659 "^\\s-*end\\s-+\\(\\("
12660 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12661 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12662 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12663 (when (vhdl-standard-p 'ams) "procedural\\|")
12664 "units"
12665 "\\)\\s-+\\)?\\(\\w*\\)")
12666 5 'font-lock-function-name-face)
12667
12668 ;; highlight labels in exit and next statements
12669 (list
12670 (concat
12671 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12672 3 'font-lock-function-name-face)
12673
12674 ;; highlight entity name in attribute specifications
12675 (list
12676 (concat
12677 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12678 1 'font-lock-function-name-face)
12679
12680 ;; highlight labels in block and component specifications
12681 (list
12682 (concat
12683 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12684 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12685 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12686
12687 ;; highlight names in library clauses
12688 (list "^\\s-*library\\>"
12689 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12690
12691 ;; highlight names in use clauses
12692 (list
12693 (concat
12694 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12695 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12696 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12697 '(7 font-lock-function-name-face nil t))
12698
12699 ;; highlight attribute name in attribute declarations/specifications
12700 (list
12701 (concat
12702 "^\\s-*attribute\\s-+\\(\\w+\\)")
12703 1 'vhdl-font-lock-attribute-face)
12704
12705 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12706 (list
12707 (concat
12708 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12709 3 'font-lock-type-face)
12710
12711 ;; highlight signal/variable/constant declaration names
12712 (list "\\(:[^=]\\)"
12713 '(vhdl-font-lock-match-item
12714 (progn (goto-char (match-beginning 1))
12715 (skip-syntax-backward " ")
12716 (skip-syntax-backward "w_")
12717 (skip-syntax-backward " ")
12718 (while (= (preceding-char) ?,)
12719 (backward-char 1)
12720 (skip-syntax-backward " ")
12721 (skip-syntax-backward "w_")
12722 (skip-syntax-backward " ")))
12723 ; (skip-chars-backward "^-(\n\";")
12724 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12725
12726 ;; highlight formal parameters in component instantiations and subprogram
12727 ;; calls
12728 (list "\\(=>\\)"
12729 '(vhdl-font-lock-match-item
12730 (progn (goto-char (match-beginning 1))
12731 (skip-syntax-backward " ")
12732 (while (= (preceding-char) ?\)) (backward-sexp))
12733 (skip-syntax-backward "w_")
12734 (skip-syntax-backward " ")
12735 (when (memq (preceding-char) '(?n ?N ?|))
12736 (goto-char (point-max))))
12737 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12738
12739 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12740 ;; variables
12741 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12742 '(vhdl-font-lock-match-item
12743 (progn (goto-char (match-end 1)) (match-beginning 2))
12744 nil (1 font-lock-variable-name-face)))
12745 )
12746 "For consideration as a value of `vhdl-font-lock-keywords'.
12747 This does context sensitive highlighting of names and labels.")
12748
12749 (defvar vhdl-font-lock-keywords-3 nil
12750 ;; set in `vhdl-font-lock-init' because dependent on user options
12751 "For consideration as a value of `vhdl-font-lock-keywords'.
12752 This does highlighting of words with special syntax.")
12753
12754 (defvar vhdl-font-lock-keywords-4 nil
12755 ;; set in `vhdl-font-lock-init' because dependent on user options
12756 "For consideration as a value of `vhdl-font-lock-keywords'.
12757 This does highlighting of additional reserved words.")
12758
12759 (defconst vhdl-font-lock-keywords-5
12760 ;; background highlight translate-off regions
12761 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12762 "For consideration as a value of `vhdl-font-lock-keywords'.
12763 This does background highlighting of translate-off regions.")
12764
12765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12766 ;; Font and color definitions
12767
12768 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12769 "Face name to use for prompts.")
12770
12771 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12772 "Face name to use for standardized attributes.")
12773
12774 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12775 "Face name to use for standardized enumeration values.")
12776
12777 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12778 "Face name to use for standardized functions and packages.")
12779
12780 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12781 "Face name to use for directives.")
12782
12783 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12784 "Face name to use for additional reserved words.")
12785
12786 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12787 "Face name to use for translate-off regions.")
12788
12789 ;; face names to use for words with special syntax.
12790 (let ((syntax-alist vhdl-special-syntax-alist)
12791 name)
12792 (while syntax-alist
12793 (setq name (vhdl-function-name
12794 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12795 (eval `(defvar ,name ',name
12796 ,(concat "Face name to use for "
12797 (nth 0 (car syntax-alist)) ".")))
12798 (setq syntax-alist (cdr syntax-alist))))
12799
12800 (defgroup vhdl-highlight-faces nil
12801 "Faces for highlighting."
12802 :group 'vhdl-highlight)
12803
12804 ;; add faces used from `font-lock'
12805 (custom-add-to-group
12806 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12807 (custom-add-to-group
12808 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12809 (custom-add-to-group
12810 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12811 (custom-add-to-group
12812 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12813 (custom-add-to-group
12814 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12815 (custom-add-to-group
12816 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12817
12818 (defface vhdl-font-lock-prompt-face
12819 '((((min-colors 88) (class color) (background light))
12820 (:foreground "Red1" :bold t))
12821 (((class color) (background light)) (:foreground "Red" :bold t))
12822 (((class color) (background dark)) (:foreground "Pink" :bold t))
12823 (t (:inverse-video t)))
12824 "Font lock mode face used to highlight prompts."
12825 :group 'vhdl-highlight-faces)
12826
12827 (defface vhdl-font-lock-attribute-face
12828 '((((class color) (background light)) (:foreground "Orchid"))
12829 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12830 (t (:italic t :bold t)))
12831 "Font lock mode face used to highlight standardized attributes."
12832 :group 'vhdl-highlight-faces)
12833
12834 (defface vhdl-font-lock-enumvalue-face
12835 '((((class color) (background light)) (:foreground "SaddleBrown"))
12836 (((class color) (background dark)) (:foreground "BurlyWood"))
12837 (t (:italic t :bold t)))
12838 "Font lock mode face used to highlight standardized enumeration values."
12839 :group 'vhdl-highlight-faces)
12840
12841 (defface vhdl-font-lock-function-face
12842 '((((class color) (background light)) (:foreground "Cyan4"))
12843 (((class color) (background dark)) (:foreground "Orchid1"))
12844 (t (:italic t :bold t)))
12845 "Font lock mode face used to highlight standardized functions and packages."
12846 :group 'vhdl-highlight-faces)
12847
12848 (defface vhdl-font-lock-directive-face
12849 '((((class color) (background light)) (:foreground "CadetBlue"))
12850 (((class color) (background dark)) (:foreground "Aquamarine"))
12851 (t (:italic t :bold t)))
12852 "Font lock mode face used to highlight directives."
12853 :group 'vhdl-highlight-faces)
12854
12855 (defface vhdl-font-lock-reserved-words-face
12856 '((((class color) (background light)) (:foreground "Orange" :bold t))
12857 (((min-colors 88) (class color) (background dark))
12858 (:foreground "Yellow1" :bold t))
12859 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12860 (t ()))
12861 "Font lock mode face used to highlight additional reserved words."
12862 :group 'vhdl-highlight-faces)
12863
12864 (defface vhdl-font-lock-translate-off-face
12865 '((((class color) (background light)) (:background "LightGray"))
12866 (((class color) (background dark)) (:background "DimGray"))
12867 (t ()))
12868 "Font lock mode face used to background highlight translate-off regions."
12869 :group 'vhdl-highlight-faces)
12870
12871 ;; font lock mode faces used to highlight words with special syntax.
12872 (let ((syntax-alist vhdl-special-syntax-alist))
12873 (while syntax-alist
12874 (eval `(defface ,(vhdl-function-name
12875 "vhdl-font-lock" (caar syntax-alist) "face")
12876 '((((class color) (background light))
12877 (:foreground ,(nth 2 (car syntax-alist))))
12878 (((class color) (background dark))
12879 (:foreground ,(nth 3 (car syntax-alist))))
12880 (t ()))
12881 ,(concat "Font lock mode face used to highlight "
12882 (nth 0 (car syntax-alist)) ".")
12883 :group 'vhdl-highlight-faces))
12884 (setq syntax-alist (cdr syntax-alist))))
12885
12886 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12887 ;; Font lock initialization
12888
12889 (defun vhdl-font-lock-init ()
12890 "Initialize fontification."
12891 ;; highlight template prompts and directives
12892 (setq vhdl-font-lock-keywords-0
12893 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12894 vhdl-template-prompt-syntax ">\\)")
12895 2 'vhdl-font-lock-prompt-face t)
12896 (list (concat "--\\s-*"
12897 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12898 2 'vhdl-font-lock-directive-face t)
12899 ;; highlight c-preprocessor directives
12900 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12901 '(1 font-lock-builtin-face)
12902 '(3 font-lock-variable-name-face nil t))))
12903 ;; highlight keywords and standardized types, attributes, enumeration
12904 ;; values, and subprograms
12905 (setq vhdl-font-lock-keywords-1
12906 (list
12907 (list (concat "'" vhdl-attributes-regexp)
12908 1 'vhdl-font-lock-attribute-face)
12909 (list vhdl-types-regexp 1 'font-lock-type-face)
12910 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12911 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12912 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12913 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12914 ;; highlight words with special syntax.
12915 (setq vhdl-font-lock-keywords-3
12916 (let ((syntax-alist vhdl-special-syntax-alist)
12917 keywords)
12918 (while syntax-alist
12919 (setq keywords
12920 (cons
12921 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12922 (vhdl-function-name
12923 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12924 keywords))
12925 (setq syntax-alist (cdr syntax-alist)))
12926 keywords))
12927 ;; highlight additional reserved words
12928 (setq vhdl-font-lock-keywords-4
12929 (list (list vhdl-reserved-words-regexp 1
12930 'vhdl-font-lock-reserved-words-face)))
12931 ;; highlight everything together
12932 (setq vhdl-font-lock-keywords
12933 (append
12934 vhdl-font-lock-keywords-0
12935 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12936 (when (or vhdl-highlight-forbidden-words
12937 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12938 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12939 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12940 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12941
12942 ;; initialize fontification for VHDL Mode
12943 (vhdl-font-lock-init)
12944
12945 (defun vhdl-fontify-buffer ()
12946 "Re-initialize fontification and fontify buffer."
12947 (interactive)
12948 (setq font-lock-defaults
12949 (list
12950 'vhdl-font-lock-keywords nil
12951 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12952 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12953 (when (fboundp 'font-lock-unset-defaults)
12954 (font-lock-unset-defaults)) ; not implemented in XEmacs
12955 (font-lock-set-defaults)
12956 (font-lock-mode nil)
12957 (font-lock-mode t))
12958
12959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12960 ;; Initialization for postscript printing
12961
12962 (defun vhdl-ps-print-settings ()
12963 "Initialize custom face and page settings for postscript printing."
12964 ;; define custom face settings
12965 (unless (or (not vhdl-print-customize-faces)
12966 ps-print-color-p)
12967 (set (make-local-variable 'ps-bold-faces)
12968 '(font-lock-keyword-face
12969 font-lock-type-face
12970 vhdl-font-lock-attribute-face
12971 vhdl-font-lock-enumvalue-face
12972 vhdl-font-lock-directive-face))
12973 (set (make-local-variable 'ps-italic-faces)
12974 '(font-lock-comment-face
12975 font-lock-function-name-face
12976 font-lock-type-face
12977 vhdl-font-lock-attribute-face
12978 vhdl-font-lock-enumvalue-face
12979 vhdl-font-lock-directive-face))
12980 (set (make-local-variable 'ps-underlined-faces)
12981 '(font-lock-string-face))
12982 (setq ps-always-build-face-reference t))
12983 ;; define page settings, so that a line containing 79 characters (default)
12984 ;; fits into one column
12985 (when vhdl-print-two-column
12986 (set (make-local-variable 'ps-landscape-mode) t)
12987 (set (make-local-variable 'ps-number-of-columns) 2)
12988 (set (make-local-variable 'ps-font-size) 7.0)
12989 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12990 (set (make-local-variable 'ps-header-font-size) 9.0)
12991 (set (make-local-variable 'ps-header-offset) 12.0)
12992 (when (eq ps-paper-type 'letter)
12993 (set (make-local-variable 'ps-inter-column) 40.0)
12994 (set (make-local-variable 'ps-left-margin) 40.0)
12995 (set (make-local-variable 'ps-right-margin) 40.0))))
12996
12997 (defun vhdl-ps-print-init ()
12998 "Initialize postscript printing."
12999 (if (featurep 'xemacs)
13000 (when (boundp 'ps-print-color-p)
13001 (vhdl-ps-print-settings))
13002 (make-local-variable 'ps-print-hook)
13003 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13004
13005
13006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13007 ;;; Hierarchy browser (using `speedbar.el')
13008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13009 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13010 ;; directory by using the speedbar.
13011
13012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13013 ;; Variables
13014
13015 (defvar vhdl-entity-alist nil
13016 "Cache with entities and corresponding architectures for each
13017 project/directory.")
13018 ;; structure: (parenthesised expression means list of such entries)
13019 ;; (cache-key
13020 ;; (ent-key ent-name ent-file ent-line
13021 ;; (arch-key arch-name arch-file arch-line
13022 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13023 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13024 ;; (lib-name pack-key))
13025 ;; mra-key (lib-name pack-key))
13026
13027 (defvar vhdl-config-alist nil
13028 "Cache with configurations for each project/directory.")
13029 ;; structure: (parenthesised expression means list of such entries)
13030 ;; (cache-key
13031 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13032 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13033 ;; inst-conf-key inst-lib-key)
13034 ;; (lib-name pack-key)))
13035
13036 (defvar vhdl-package-alist nil
13037 "Cache with packages for each project/directory.")
13038 ;; structure: (parenthesised expression means list of such entries)
13039 ;; (cache-key
13040 ;; (pack-key pack-name pack-file pack-line
13041 ;; (comp-key comp-name comp-file comp-line)
13042 ;; (func-key func-name func-file func-line)
13043 ;; (lib-name pack-key)
13044 ;; pack-body-file pack-body-line
13045 ;; (func-key func-name func-body-file func-body-line)
13046 ;; (lib-name pack-key)))
13047
13048 (defvar vhdl-ent-inst-alist nil
13049 "Cache with instantiated entities for each project/directory.")
13050 ;; structure: (parenthesised expression means list of such entries)
13051 ;; (cache-key (inst-ent-key))
13052
13053 (defvar vhdl-file-alist nil
13054 "Cache with design units in each file for each project/directory.")
13055 ;; structure: (parenthesised expression means list of such entries)
13056 ;; (cache-key
13057 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13058 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13059
13060 (defvar vhdl-directory-alist nil
13061 "Cache with source directories for each project.")
13062 ;; structure: (parenthesised expression means list of such entries)
13063 ;; (cache-key (directory))
13064
13065 (defvar vhdl-speedbar-shown-unit-alist nil
13066 "Alist of design units simultaneously open in the current speedbar for each
13067 directory and project.")
13068
13069 (defvar vhdl-speedbar-shown-project-list nil
13070 "List of projects simultaneously open in the current speedbar.")
13071
13072 (defvar vhdl-updated-project-list nil
13073 "List of projects and directories with updated files.")
13074
13075 (defvar vhdl-modified-file-list nil
13076 "List of modified files to be rescanned for hierarchy updating.")
13077
13078 (defvar vhdl-speedbar-hierarchy-depth 0
13079 "Depth of instantiation hierarchy to display.")
13080
13081 (defvar vhdl-speedbar-show-projects nil
13082 "Non-nil means project hierarchy is displayed in speedbar, directory
13083 hierarchy otherwise.")
13084
13085 (defun vhdl-get-end-of-unit ()
13086 "Return position of end of current unit."
13087 (let ((pos (point)))
13088 (save-excursion
13089 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13090 (save-excursion
13091 (goto-char (match-beginning 0))
13092 (vhdl-backward-syntactic-ws)
13093 (and (/= (preceding-char) ?\;) (not (bobp))))))
13094 (re-search-backward "^[ \t]*end\\>" pos 1)
13095 (point))))
13096
13097 (defun vhdl-match-string-downcase (num &optional string)
13098 "Like `match-string-no-properties' with down-casing."
13099 (let ((match (match-string-no-properties num string)))
13100 (and match (downcase match))))
13101
13102
13103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13104 ;; Scan functions
13105
13106 (defun vhdl-scan-context-clause ()
13107 "Scan the context clause that precedes a design unit."
13108 (let (lib-alist)
13109 (save-excursion
13110 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13111 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13112 (equal "USE" (upcase (match-string 1))))
13113 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13114 (setq lib-alist (cons (cons (match-string-no-properties 1)
13115 (vhdl-match-string-downcase 2))
13116 lib-alist))))))
13117 lib-alist))
13118
13119 (defun vhdl-scan-directory-contents (name &optional project update num-string
13120 non-final)
13121 "Scan contents of VHDL files in directory or file pattern NAME."
13122 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13123 ; (unless (file-directory-p (match-string 1 name))
13124 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13125 (let* ((dir-name (match-string 1 name))
13126 (file-pattern (match-string 2 name))
13127 (is-directory (= 0 (length file-pattern)))
13128 (file-list
13129 (if update
13130 (list name)
13131 (if is-directory
13132 (vhdl-get-source-files t dir-name)
13133 (vhdl-directory-files
13134 dir-name t (wildcard-to-regexp file-pattern)))))
13135 (key (or project dir-name))
13136 (file-exclude-regexp
13137 (or (nth 3 (aget vhdl-project-alist project)) ""))
13138 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13139 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13140 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13141 ent-alist conf-alist pack-alist ent-inst-list file-alist
13142 tmp-list tmp-entry no-files files-exist big-files)
13143 (when (or project update)
13144 (setq ent-alist (aget vhdl-entity-alist key t)
13145 conf-alist (aget vhdl-config-alist key t)
13146 pack-alist (aget vhdl-package-alist key t)
13147 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13148 file-alist (aget vhdl-file-alist key t)))
13149 (when (and (not is-directory) (null file-list))
13150 (message "No such file: \"%s\"" name))
13151 (setq files-exist file-list)
13152 (when file-list
13153 (setq no-files (length file-list))
13154 (message "Scanning %s %s\"%s\"..."
13155 (if is-directory "directory" "files") (or num-string "") name)
13156 ;; exclude files
13157 (unless (equal file-exclude-regexp "")
13158 (let ((case-fold-search nil)
13159 file-tmp-list)
13160 (while file-list
13161 (unless (string-match file-exclude-regexp (car file-list))
13162 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13163 (setq file-list (cdr file-list)))
13164 (setq file-list (nreverse file-tmp-list))))
13165 ;; do for all files
13166 (while file-list
13167 (unless noninteractive
13168 (message "Scanning %s %s\"%s\"... (%2d%s)"
13169 (if is-directory "directory" "files")
13170 (or num-string "") name
13171 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13172 (let ((file-name (abbreviate-file-name (car file-list)))
13173 ent-list arch-list arch-ent-list conf-list
13174 pack-list pack-body-list inst-list inst-ent-list)
13175 ;; scan file
13176 (vhdl-visit-file
13177 file-name nil
13178 (vhdl-prepare-search-2
13179 (save-excursion
13180 ;; scan for design units
13181 (if (and limit-design-file-size
13182 (< limit-design-file-size (buffer-size)))
13183 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13184 (setq big-files t))
13185 ;; scan for entities
13186 (goto-char (point-min))
13187 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13188 (let* ((ent-name (match-string-no-properties 1))
13189 (ent-key (downcase ent-name))
13190 (ent-entry (aget ent-alist ent-key t))
13191 (lib-alist (vhdl-scan-context-clause)))
13192 (if (nth 1 ent-entry)
13193 (vhdl-warning-when-idle
13194 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13195 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13196 file-name (vhdl-current-line))
13197 (setq ent-list (cons ent-key ent-list))
13198 (aput 'ent-alist ent-key
13199 (list ent-name file-name (vhdl-current-line)
13200 (nth 3 ent-entry) (nth 4 ent-entry)
13201 lib-alist)))))
13202 ;; scan for architectures
13203 (goto-char (point-min))
13204 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13205 (let* ((arch-name (match-string-no-properties 1))
13206 (arch-key (downcase arch-name))
13207 (ent-name (match-string-no-properties 2))
13208 (ent-key (downcase ent-name))
13209 (ent-entry (aget ent-alist ent-key t))
13210 (arch-alist (nth 3 ent-entry))
13211 (arch-entry (aget arch-alist arch-key t))
13212 (lib-arch-alist (vhdl-scan-context-clause)))
13213 (if arch-entry
13214 (vhdl-warning-when-idle
13215 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13216 arch-name ent-name (nth 1 arch-entry)
13217 (nth 2 arch-entry) file-name (vhdl-current-line))
13218 (setq arch-list (cons arch-key arch-list)
13219 arch-ent-list (cons ent-key arch-ent-list))
13220 (aput 'arch-alist arch-key
13221 (list arch-name file-name (vhdl-current-line) nil
13222 lib-arch-alist))
13223 (aput 'ent-alist ent-key
13224 (list (or (nth 0 ent-entry) ent-name)
13225 (nth 1 ent-entry) (nth 2 ent-entry)
13226 (vhdl-sort-alist arch-alist)
13227 arch-key (nth 5 ent-entry))))))
13228 ;; scan for configurations
13229 (goto-char (point-min))
13230 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13231 (let* ((conf-name (match-string-no-properties 1))
13232 (conf-key (downcase conf-name))
13233 (conf-entry (aget conf-alist conf-key t))
13234 (ent-name (match-string-no-properties 2))
13235 (ent-key (downcase ent-name))
13236 (lib-alist (vhdl-scan-context-clause))
13237 (conf-line (vhdl-current-line))
13238 (end-of-unit (vhdl-get-end-of-unit))
13239 arch-key comp-conf-list inst-key-list
13240 inst-comp-key inst-ent-key inst-arch-key
13241 inst-conf-key inst-lib-key)
13242 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13243 (setq arch-key (vhdl-match-string-downcase 1)))
13244 (if conf-entry
13245 (vhdl-warning-when-idle
13246 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13247 conf-name ent-name (nth 1 conf-entry)
13248 (nth 2 conf-entry) file-name conf-line)
13249 (setq conf-list (cons conf-key conf-list))
13250 ;; scan for subconfigurations and subentities
13251 (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)
13252 (setq inst-comp-key (vhdl-match-string-downcase 3)
13253 inst-key-list (split-string
13254 (vhdl-match-string-downcase 1)
13255 "[ \t\n]*,[ \t\n]*"))
13256 (vhdl-forward-syntactic-ws)
13257 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13258 (setq
13259 inst-lib-key (vhdl-match-string-downcase 3)
13260 inst-ent-key (and (match-string 2)
13261 (vhdl-match-string-downcase 4))
13262 inst-arch-key (and (match-string 2)
13263 (vhdl-match-string-downcase 6))
13264 inst-conf-key (and (not (match-string 2))
13265 (vhdl-match-string-downcase 4)))
13266 (while inst-key-list
13267 (setq comp-conf-list
13268 (cons (list (car inst-key-list)
13269 inst-comp-key inst-ent-key
13270 inst-arch-key inst-conf-key
13271 inst-lib-key)
13272 comp-conf-list))
13273 (setq inst-key-list (cdr inst-key-list)))))
13274 (aput 'conf-alist conf-key
13275 (list conf-name file-name conf-line ent-key
13276 arch-key comp-conf-list lib-alist)))))
13277 ;; scan for packages
13278 (goto-char (point-min))
13279 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13280 (let* ((pack-name (match-string-no-properties 2))
13281 (pack-key (downcase pack-name))
13282 (is-body (match-string-no-properties 1))
13283 (pack-entry (aget pack-alist pack-key t))
13284 (pack-line (vhdl-current-line))
13285 (end-of-unit (vhdl-get-end-of-unit))
13286 comp-name func-name comp-alist func-alist lib-alist)
13287 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13288 (vhdl-warning-when-idle
13289 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13290 (if is-body " body" "") pack-name
13291 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13292 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13293 file-name (vhdl-current-line))
13294 ;; scan for context clauses
13295 (setq lib-alist (vhdl-scan-context-clause))
13296 ;; scan for component and subprogram declarations/bodies
13297 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13298 (if (equal (upcase (match-string 1)) "COMPONENT")
13299 (setq comp-name (match-string-no-properties 2)
13300 comp-alist
13301 (cons (list (downcase comp-name) comp-name
13302 file-name (vhdl-current-line))
13303 comp-alist))
13304 (setq func-name (match-string-no-properties 2)
13305 func-alist
13306 (cons (list (downcase func-name) func-name
13307 file-name (vhdl-current-line))
13308 func-alist))))
13309 (setq func-alist (nreverse func-alist))
13310 (setq comp-alist (nreverse comp-alist))
13311 (if is-body
13312 (setq pack-body-list (cons pack-key pack-body-list))
13313 (setq pack-list (cons pack-key pack-list)))
13314 (aput
13315 'pack-alist pack-key
13316 (if is-body
13317 (list (or (nth 0 pack-entry) pack-name)
13318 (nth 1 pack-entry) (nth 2 pack-entry)
13319 (nth 3 pack-entry) (nth 4 pack-entry)
13320 (nth 5 pack-entry)
13321 file-name pack-line func-alist lib-alist)
13322 (list pack-name file-name pack-line
13323 comp-alist func-alist lib-alist
13324 (nth 6 pack-entry) (nth 7 pack-entry)
13325 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13326 ;; scan for hierarchy
13327 (if (and limit-hier-file-size
13328 (< limit-hier-file-size (buffer-size)))
13329 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13330 (setq big-files t))
13331 ;; scan for architectures
13332 (goto-char (point-min))
13333 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13334 (let* ((ent-name (match-string-no-properties 2))
13335 (ent-key (downcase ent-name))
13336 (arch-name (match-string-no-properties 1))
13337 (arch-key (downcase arch-name))
13338 (ent-entry (aget ent-alist ent-key t))
13339 (arch-alist (nth 3 ent-entry))
13340 (arch-entry (aget arch-alist arch-key t))
13341 (beg-of-unit (point))
13342 (end-of-unit (vhdl-get-end-of-unit))
13343 (inst-no 0)
13344 inst-alist inst-path)
13345 ;; scan for contained instantiations
13346 (while (and (re-search-forward
13347 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13348 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13349 "component[ \t\n]+\\(\\w+\\)\\|"
13350 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13351 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13352 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13353 (or (not limit-hier-inst-no)
13354 (<= (setq inst-no (1+ inst-no))
13355 limit-hier-inst-no)))
13356 (cond
13357 ;; block/generate beginning found
13358 ((match-string 14)
13359 (setq inst-path
13360 (cons (match-string-no-properties 1) inst-path)))
13361 ;; block/generate end found
13362 ((match-string 16)
13363 (setq inst-path (cdr inst-path)))
13364 ;; instantiation found
13365 (t
13366 (let* ((inst-name (match-string-no-properties 1))
13367 (inst-key (downcase inst-name))
13368 (inst-comp-name
13369 (or (match-string-no-properties 3)
13370 (match-string-no-properties 6)))
13371 (inst-ent-key
13372 (or (and (match-string 8)
13373 (vhdl-match-string-downcase 11))
13374 (and inst-comp-name
13375 (downcase inst-comp-name))))
13376 (inst-arch-key (vhdl-match-string-downcase 13))
13377 (inst-conf-key
13378 (and (not (match-string 8))
13379 (vhdl-match-string-downcase 11)))
13380 (inst-lib-key (vhdl-match-string-downcase 10)))
13381 (goto-char (match-end 1))
13382 (setq inst-list (cons inst-key inst-list)
13383 inst-ent-list
13384 (cons inst-ent-key inst-ent-list))
13385 (setq inst-alist
13386 (append
13387 inst-alist
13388 (list (list inst-key inst-name file-name
13389 (vhdl-current-line) inst-comp-name
13390 inst-ent-key inst-arch-key
13391 inst-conf-key inst-lib-key
13392 (reverse inst-path)))))))))
13393 ;; scan for contained configuration specifications
13394 (goto-char beg-of-unit)
13395 (while (re-search-forward
13396 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13397 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13398 (let* ((inst-comp-name (match-string-no-properties 3))
13399 (inst-ent-key
13400 (and (match-string 6)
13401 (vhdl-match-string-downcase 9)))
13402 (inst-arch-key (vhdl-match-string-downcase 11))
13403 (inst-conf-key
13404 (and (not (match-string 6))
13405 (vhdl-match-string-downcase 9)))
13406 (inst-lib-key (vhdl-match-string-downcase 8))
13407 (inst-key-list
13408 (split-string (vhdl-match-string-downcase 1)
13409 "[ \t\n]*,[ \t\n]*"))
13410 (tmp-inst-alist inst-alist)
13411 inst-entry)
13412 (while tmp-inst-alist
13413 (when (and (or (equal "all" (car inst-key-list))
13414 (member (nth 0 (car tmp-inst-alist))
13415 inst-key-list))
13416 (equal
13417 (downcase
13418 (or (nth 4 (car tmp-inst-alist)) ""))
13419 (downcase inst-comp-name)))
13420 (setq inst-entry (car tmp-inst-alist))
13421 (setq inst-ent-list
13422 (cons (or inst-ent-key (nth 5 inst-entry))
13423 (vhdl-delete
13424 (nth 5 inst-entry) inst-ent-list)))
13425 (setq inst-entry
13426 (list (nth 0 inst-entry) (nth 1 inst-entry)
13427 (nth 2 inst-entry) (nth 3 inst-entry)
13428 (nth 4 inst-entry)
13429 (or inst-ent-key (nth 5 inst-entry))
13430 (or inst-arch-key (nth 6 inst-entry))
13431 inst-conf-key inst-lib-key))
13432 (setcar tmp-inst-alist inst-entry))
13433 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13434 ;; save in cache
13435 (aput 'arch-alist arch-key
13436 (list (nth 0 arch-entry) (nth 1 arch-entry)
13437 (nth 2 arch-entry) inst-alist
13438 (nth 4 arch-entry)))
13439 (aput 'ent-alist ent-key
13440 (list (nth 0 ent-entry) (nth 1 ent-entry)
13441 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13442 (nth 4 ent-entry) (nth 5 ent-entry)))
13443 (when (and limit-hier-inst-no
13444 (> inst-no limit-hier-inst-no))
13445 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13446 (setq big-files t))
13447 (goto-char end-of-unit))))
13448 ;; remember design units for this file
13449 (aput 'file-alist file-name
13450 (list ent-list arch-list arch-ent-list conf-list
13451 pack-list pack-body-list inst-list inst-ent-list))
13452 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13453 (setq file-list (cdr file-list))))
13454 (when (or (and (not project) files-exist)
13455 (and project (not non-final)))
13456 ;; consistency checks:
13457 ;; check whether each architecture has a corresponding entity
13458 (setq tmp-list ent-alist)
13459 (while tmp-list
13460 (when (null (nth 2 (car tmp-list)))
13461 (setq tmp-entry (car (nth 4 (car tmp-list))))
13462 (vhdl-warning-when-idle
13463 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13464 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13465 (nth 3 tmp-entry)))
13466 (setq tmp-list (cdr tmp-list)))
13467 ;; check whether configuration has a corresponding entity/architecture
13468 (setq tmp-list conf-alist)
13469 (while tmp-list
13470 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13471 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13472 (setq tmp-entry (car tmp-list))
13473 (vhdl-warning-when-idle
13474 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13475 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13476 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13477 (setq tmp-entry (car tmp-list))
13478 (vhdl-warning-when-idle
13479 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13480 (nth 1 tmp-entry) (nth 4 tmp-entry)
13481 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13482 (setq tmp-list (cdr tmp-list)))
13483 ;; check whether each package body has a package declaration
13484 (setq tmp-list pack-alist)
13485 (while tmp-list
13486 (when (null (nth 2 (car tmp-list)))
13487 (setq tmp-entry (car tmp-list))
13488 (vhdl-warning-when-idle
13489 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13490 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13491 (setq tmp-list (cdr tmp-list)))
13492 ;; sort lists
13493 (setq ent-alist (vhdl-sort-alist ent-alist))
13494 (setq conf-alist (vhdl-sort-alist conf-alist))
13495 (setq pack-alist (vhdl-sort-alist pack-alist))
13496 ;; remember updated directory/project
13497 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13498 ;; clear directory alists
13499 (unless project
13500 (adelete 'vhdl-entity-alist key)
13501 (adelete 'vhdl-config-alist key)
13502 (adelete 'vhdl-package-alist key)
13503 (adelete 'vhdl-ent-inst-alist key)
13504 (adelete 'vhdl-file-alist key))
13505 ;; put directory contents into cache
13506 (aput 'vhdl-entity-alist key ent-alist)
13507 (aput 'vhdl-config-alist key conf-alist)
13508 (aput 'vhdl-package-alist key pack-alist)
13509 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13510 (aput 'vhdl-file-alist key file-alist)
13511 ;; final messages
13512 (message "Scanning %s %s\"%s\"...done"
13513 (if is-directory "directory" "files") (or num-string "") name)
13514 (unless project (message "Scanning directory...done"))
13515 (when big-files
13516 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13517 ;; save cache when scanned non-interactively
13518 (when (or (not project) (not non-final))
13519 (when (and noninteractive vhdl-speedbar-save-cache)
13520 (vhdl-save-cache key)))
13521 t))
13522
13523 (defun vhdl-scan-project-contents (project)
13524 "Scan the contents of all VHDL files found in the directories and files
13525 of PROJECT."
13526 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13527 (default-dir (vhdl-resolve-env-variable
13528 (nth 1 (aget vhdl-project-alist project))))
13529 (file-exclude-regexp
13530 (or (nth 3 (aget vhdl-project-alist project)) ""))
13531 dir-list-tmp dir dir-name num-dir act-dir recursive)
13532 ;; clear project alists
13533 (adelete 'vhdl-entity-alist project)
13534 (adelete 'vhdl-config-alist project)
13535 (adelete 'vhdl-package-alist project)
13536 (adelete 'vhdl-ent-inst-alist project)
13537 (adelete 'vhdl-file-alist project)
13538 ;; expand directory names by default-directory
13539 (message "Collecting source files...")
13540 (while dir-list
13541 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13542 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13543 (setq recursive (match-string 1 dir)
13544 dir-name (match-string 3 dir))
13545 (setq dir-list-tmp
13546 (cons (concat recursive
13547 (if (file-name-absolute-p dir-name) "" default-dir)
13548 dir-name)
13549 dir-list-tmp))
13550 (setq dir-list (cdr dir-list)))
13551 ;; resolve path wildcards
13552 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13553 ;; expand directories
13554 (while dir-list-tmp
13555 (setq dir (car dir-list-tmp))
13556 ;; get subdirectories
13557 (if (string-match "-r \\(.*[/\\]\\)" dir)
13558 (setq dir-list (append dir-list (vhdl-get-subdirs
13559 (match-string 1 dir))))
13560 (setq dir-list (append dir-list (list dir))))
13561 (setq dir-list-tmp (cdr dir-list-tmp)))
13562 ;; exclude files
13563 (unless (equal file-exclude-regexp "")
13564 (let ((case-fold-search nil))
13565 (while dir-list
13566 (unless (string-match file-exclude-regexp (car dir-list))
13567 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13568 (setq dir-list (cdr dir-list)))
13569 (setq dir-list (nreverse dir-list-tmp))))
13570 (message "Collecting source files...done")
13571 ;; scan for design units for each directory in DIR-LIST
13572 (setq dir-list-tmp nil
13573 num-dir (length dir-list)
13574 act-dir 1)
13575 (while dir-list
13576 (setq dir-name (abbreviate-file-name
13577 (expand-file-name (car dir-list))))
13578 (vhdl-scan-directory-contents dir-name project nil
13579 (format "(%s/%s) " act-dir num-dir)
13580 (cdr dir-list))
13581 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13582 (setq dir-list (cdr dir-list)
13583 act-dir (1+ act-dir)))
13584 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13585 (message "Scanning project \"%s\"...done" project)))
13586
13587 (defun vhdl-update-file-contents (file-name)
13588 "Update hierarchy information by contents of current buffer."
13589 (setq file-name (abbreviate-file-name file-name))
13590 (let* ((dir-name (file-name-directory file-name))
13591 (directory-alist vhdl-directory-alist)
13592 updated)
13593 (while directory-alist
13594 (when (member dir-name (nth 1 (car directory-alist)))
13595 (let* ((vhdl-project (nth 0 (car directory-alist)))
13596 (project (vhdl-project-p))
13597 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13598 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13599 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13600 (ent-inst-list (car (aget vhdl-ent-inst-alist
13601 (or project dir-name) t)))
13602 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13603 (file-entry (aget file-alist file-name t))
13604 (ent-list (nth 0 file-entry))
13605 (arch-list (nth 1 file-entry))
13606 (arch-ent-list (nth 2 file-entry))
13607 (conf-list (nth 3 file-entry))
13608 (pack-list (nth 4 file-entry))
13609 (pack-body-list (nth 5 file-entry))
13610 (inst-ent-list (nth 7 file-entry))
13611 (cache-key (or project dir-name))
13612 arch-alist key ent-key entry)
13613 ;; delete design units previously contained in this file:
13614 ;; entities
13615 (while ent-list
13616 (setq key (car ent-list)
13617 entry (aget ent-alist key t))
13618 (when (equal file-name (nth 1 entry))
13619 (if (nth 3 entry)
13620 (aput 'ent-alist key
13621 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13622 (adelete 'ent-alist key)))
13623 (setq ent-list (cdr ent-list)))
13624 ;; architectures
13625 (while arch-list
13626 (setq key (car arch-list)
13627 ent-key (car arch-ent-list)
13628 entry (aget ent-alist ent-key t)
13629 arch-alist (nth 3 entry))
13630 (when (equal file-name (nth 1 (aget arch-alist key t)))
13631 (adelete 'arch-alist key)
13632 (if (or (nth 1 entry) arch-alist)
13633 (aput 'ent-alist ent-key
13634 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13635 arch-alist (nth 4 entry) (nth 5 entry)))
13636 (adelete 'ent-alist ent-key)))
13637 (setq arch-list (cdr arch-list)
13638 arch-ent-list (cdr arch-ent-list)))
13639 ;; configurations
13640 (while conf-list
13641 (setq key (car conf-list))
13642 (when (equal file-name (nth 1 (aget conf-alist key t)))
13643 (adelete 'conf-alist key))
13644 (setq conf-list (cdr conf-list)))
13645 ;; package declarations
13646 (while pack-list
13647 (setq key (car pack-list)
13648 entry (aget pack-alist key t))
13649 (when (equal file-name (nth 1 entry))
13650 (if (nth 6 entry)
13651 (aput 'pack-alist key
13652 (list (nth 0 entry) nil nil nil nil nil
13653 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13654 (nth 9 entry)))
13655 (adelete 'pack-alist key)))
13656 (setq pack-list (cdr pack-list)))
13657 ;; package bodies
13658 (while pack-body-list
13659 (setq key (car pack-body-list)
13660 entry (aget pack-alist key t))
13661 (when (equal file-name (nth 6 entry))
13662 (if (nth 1 entry)
13663 (aput 'pack-alist key
13664 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13665 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13666 nil nil nil nil))
13667 (adelete 'pack-alist key)))
13668 (setq pack-body-list (cdr pack-body-list)))
13669 ;; instantiated entities
13670 (while inst-ent-list
13671 (setq ent-inst-list
13672 (vhdl-delete (car inst-ent-list) ent-inst-list))
13673 (setq inst-ent-list (cdr inst-ent-list)))
13674 ;; update caches
13675 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13676 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13677 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13678 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13679 ;; scan file
13680 (vhdl-scan-directory-contents file-name project t)
13681 (when (or (and vhdl-speedbar-show-projects project)
13682 (and (not vhdl-speedbar-show-projects) (not project)))
13683 (vhdl-speedbar-refresh project))
13684 (setq updated t)))
13685 (setq directory-alist (cdr directory-alist)))
13686 updated))
13687
13688 (defun vhdl-update-hierarchy ()
13689 "Update directory and hierarchy information in speedbar."
13690 (let ((file-list (reverse vhdl-modified-file-list))
13691 updated)
13692 (when (and vhdl-speedbar-update-on-saving file-list)
13693 (while file-list
13694 (setq updated
13695 (or (vhdl-update-file-contents (car file-list))
13696 updated))
13697 (setq file-list (cdr file-list)))
13698 (setq vhdl-modified-file-list nil)
13699 (vhdl-speedbar-update-current-unit)
13700 (when updated (message "Updating hierarchy...done")))))
13701
13702 ;; structure (parenthesised expression means list of such entries)
13703 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13704 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13705 ;; comp-lib-name level)
13706 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13707 conf-inst-alist level indent
13708 &optional include-top ent-hier)
13709 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13710 entity ENT-KEY."
13711 (let* ((ent-entry (aget ent-alist ent-key t))
13712 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13713 (cdar (last (nth 3 ent-entry)))))
13714 (inst-alist (nth 3 arch-entry))
13715 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13716 hier-list subcomp-list tmp-list inst-key inst-comp-name
13717 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13718 (when (= level 0) (message "Extract design hierarchy..."))
13719 (when include-top
13720 (setq level (1+ level)))
13721 (when (member ent-key ent-hier)
13722 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13723 ;; check configured architecture (already checked during scanning)
13724 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13725 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13726 ;; process all instances
13727 (while inst-alist
13728 (setq inst-entry (car inst-alist)
13729 inst-key (nth 0 inst-entry)
13730 inst-comp-name (nth 4 inst-entry)
13731 inst-conf-key (nth 7 inst-entry))
13732 ;; search entry in configuration's instantiations list
13733 (setq tmp-list conf-inst-alist)
13734 (while (and tmp-list
13735 (not (and (member (nth 0 (car tmp-list))
13736 (list "all" inst-key))
13737 (equal (nth 1 (car tmp-list))
13738 (downcase (or inst-comp-name ""))))))
13739 (setq tmp-list (cdr tmp-list)))
13740 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13741 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13742 (when (and inst-conf-key (not inst-conf-entry))
13743 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13744 ;; determine entity
13745 (setq inst-ent-key
13746 (or (nth 2 (car tmp-list)) ; from configuration
13747 (nth 3 inst-conf-entry) ; from subconfiguration
13748 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13749 ; from configuration spec.
13750 (nth 5 inst-entry))) ; from direct instantiation
13751 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13752 ;; determine architecture
13753 (setq inst-arch-key
13754 (or (nth 3 (car tmp-list)) ; from configuration
13755 (nth 4 inst-conf-entry) ; from subconfiguration
13756 (nth 6 inst-entry) ; from direct instantiation
13757 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13758 ; from configuration spec.
13759 (nth 4 inst-ent-entry) ; MRA
13760 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13761 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13762 ;; set library
13763 (setq inst-lib-key
13764 (or (nth 5 (car tmp-list)) ; from configuration
13765 (nth 8 inst-entry))) ; from direct instantiation
13766 ;; gather information for this instance
13767 (setq comp-entry
13768 (list (nth 1 inst-entry)
13769 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13770 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13771 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13772 (or (nth 0 inst-arch-entry) inst-arch-key)
13773 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13774 (or (nth 0 inst-conf-entry) inst-conf-key)
13775 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13776 inst-lib-key level))
13777 ;; get subcomponent hierarchy
13778 (setq subcomp-list (vhdl-get-hierarchy
13779 ent-alist conf-alist
13780 inst-ent-key inst-arch-key inst-conf-key
13781 (nth 5 inst-conf-entry)
13782 (1+ level) indent nil (cons ent-key ent-hier)))
13783 ;; add to list
13784 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13785 (setq inst-alist (cdr inst-alist)))
13786 (when include-top
13787 (setq hier-list
13788 (cons (list nil nil (nth 0 ent-entry)
13789 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13790 (nth 0 arch-entry)
13791 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13792 nil nil
13793 nil (1- level))
13794 hier-list)))
13795 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13796 hier-list))
13797
13798 (defun vhdl-get-instantiations (ent-key indent)
13799 "Get all instantiations of entity ENT-KEY."
13800 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13801 arch-alist inst-alist ent-inst-list
13802 ent-entry arch-entry inst-entry)
13803 (while ent-alist
13804 (setq ent-entry (car ent-alist))
13805 (setq arch-alist (nth 4 ent-entry))
13806 (while arch-alist
13807 (setq arch-entry (car arch-alist))
13808 (setq inst-alist (nth 4 arch-entry))
13809 (while inst-alist
13810 (setq inst-entry (car inst-alist))
13811 (when (equal ent-key (nth 5 inst-entry))
13812 (setq ent-inst-list
13813 (cons (list (nth 1 inst-entry)
13814 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13815 (nth 1 ent-entry)
13816 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13817 (nth 1 arch-entry)
13818 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13819 ent-inst-list)))
13820 (setq inst-alist (cdr inst-alist)))
13821 (setq arch-alist (cdr arch-alist)))
13822 (setq ent-alist (cdr ent-alist)))
13823 (nreverse ent-inst-list)))
13824
13825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13826 ;; Caching in file
13827
13828 (defun vhdl-save-caches ()
13829 "Save all updated hierarchy caches to file."
13830 (interactive)
13831 (condition-case nil
13832 (when vhdl-speedbar-save-cache
13833 ;; update hierarchy
13834 (vhdl-update-hierarchy)
13835 (let ((project-list vhdl-updated-project-list))
13836 (message "Saving hierarchy caches...")
13837 ;; write updated project caches
13838 (while project-list
13839 (vhdl-save-cache (car project-list))
13840 (setq project-list (cdr project-list)))
13841 (message "Saving hierarchy caches...done")))
13842 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13843 (sit-for 2)))))
13844
13845 (defun vhdl-save-cache (key)
13846 "Save current hierarchy cache to file."
13847 (let* ((orig-buffer (current-buffer))
13848 (vhdl-project key)
13849 (project (vhdl-project-p))
13850 (default-directory key)
13851 (directory (abbreviate-file-name (vhdl-default-directory)))
13852 (file-name (vhdl-resolve-env-variable
13853 (vhdl-replace-string
13854 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13855 (concat
13856 (subst-char-in-string ? ?_ (or project "dir"))
13857 " " (user-login-name)))))
13858 (file-dir-name (expand-file-name file-name directory))
13859 (cache-key (or project directory))
13860 (key (if project "project" "directory")))
13861 (unless (file-exists-p (file-name-directory file-dir-name))
13862 (make-directory (file-name-directory file-dir-name) t))
13863 (if (not (file-writable-p file-dir-name))
13864 (progn (vhdl-warning (format "File not writable: \"%s\""
13865 (abbreviate-file-name file-dir-name)))
13866 (sit-for 2))
13867 (message "Saving cache: \"%s\"" file-dir-name)
13868 (set-buffer (find-file-noselect file-dir-name t t))
13869 (erase-buffer)
13870 (insert ";; -*- Emacs-Lisp -*-\n\n"
13871 ";;; " (file-name-nondirectory file-name)
13872 " - design hierarchy cache file for Emacs VHDL Mode "
13873 vhdl-version "\n")
13874 (insert "\n;; " (if project "Project " "Directory") " : ")
13875 (if project (insert project) (prin1 directory (current-buffer)))
13876 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13877 (user-login-name) "\n\n"
13878 "\n;; version number\n"
13879 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13880 "\n;; " (if project "project" "directory") " name"
13881 "\n(setq " key " ")
13882 (prin1 (or project directory) (current-buffer))
13883 (insert ")\n")
13884 (when (member 'hierarchy vhdl-speedbar-save-cache)
13885 (insert "\n;; entity and architecture cache\n"
13886 "(aput 'vhdl-entity-alist " key " '")
13887 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13888 (insert ")\n\n;; configuration cache\n"
13889 "(aput 'vhdl-config-alist " key " '")
13890 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13891 (insert ")\n\n;; package cache\n"
13892 "(aput 'vhdl-package-alist " key " '")
13893 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13894 (insert ")\n\n;; instantiated entities cache\n"
13895 "(aput 'vhdl-ent-inst-alist " key " '")
13896 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13897 (insert ")\n\n;; design units per file cache\n"
13898 "(aput 'vhdl-file-alist " key " '")
13899 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13900 (when project
13901 (insert ")\n\n;; source directories in project cache\n"
13902 "(aput 'vhdl-directory-alist " key " '")
13903 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13904 (insert ")\n"))
13905 (when (member 'display vhdl-speedbar-save-cache)
13906 (insert "\n;; shown design units cache\n"
13907 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13908 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13909 (current-buffer))
13910 (insert ")\n"))
13911 (setq vhdl-updated-project-list
13912 (delete cache-key vhdl-updated-project-list))
13913 (save-buffer)
13914 (kill-buffer (current-buffer))
13915 (set-buffer orig-buffer))))
13916
13917 (defun vhdl-load-cache (key)
13918 "Load hierarchy cache information from file."
13919 (let* ((vhdl-project key)
13920 (default-directory key)
13921 (directory (vhdl-default-directory))
13922 (file-name (vhdl-resolve-env-variable
13923 (vhdl-replace-string
13924 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13925 (concat
13926 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13927 " " (user-login-name)))))
13928 (file-dir-name (expand-file-name file-name directory))
13929 vhdl-cache-version)
13930 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13931 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13932 (when (file-exists-p file-dir-name)
13933 (condition-case ()
13934 (progn (load-file file-dir-name)
13935 (string< (mapconcat
13936 (lambda (a) (format "%3d" (string-to-number a)))
13937 (split-string "3.33" "\\.") "")
13938 (mapconcat
13939 (lambda (a) (format "%3d" (string-to-number a)))
13940 (split-string vhdl-cache-version "\\.") "")))
13941 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13942 nil))))))
13943
13944 (defun vhdl-require-hierarchy-info ()
13945 "Make sure that hierarchy information is available. Load cache or scan files
13946 if required."
13947 (if (vhdl-project-p)
13948 (unless (or (assoc vhdl-project vhdl-file-alist)
13949 (vhdl-load-cache vhdl-project))
13950 (vhdl-scan-project-contents vhdl-project))
13951 (let ((directory (abbreviate-file-name default-directory)))
13952 (unless (or (assoc directory vhdl-file-alist)
13953 (vhdl-load-cache directory))
13954 (vhdl-scan-directory-contents directory)))))
13955
13956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13957 ;; Add hierarchy browser functionality to speedbar
13958
13959 (defvar vhdl-speedbar-key-map nil
13960 "Keymap used when in the VHDL hierarchy browser mode.")
13961
13962 (defvar vhdl-speedbar-menu-items nil
13963 "Additional menu-items to add to speedbar frame.")
13964
13965 (defun vhdl-speedbar-initialize ()
13966 "Initialize speedbar."
13967 ;; general settings
13968 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13969 ;; VHDL file extensions (extracted from `auto-mode-alist')
13970 (let ((mode-alist auto-mode-alist))
13971 (while mode-alist
13972 (when (eq (cdar mode-alist) 'vhdl-mode)
13973 (speedbar-add-supported-extension (caar mode-alist)))
13974 (setq mode-alist (cdr mode-alist))))
13975 ;; hierarchy browser settings
13976 (when (boundp 'speedbar-mode-functions-list)
13977 ;; special functions
13978 (speedbar-add-mode-functions-list
13979 '("vhdl directory"
13980 (speedbar-item-info . vhdl-speedbar-item-info)
13981 (speedbar-line-directory . speedbar-files-line-path)))
13982 (speedbar-add-mode-functions-list
13983 '("vhdl project"
13984 (speedbar-item-info . vhdl-speedbar-item-info)
13985 (speedbar-line-directory . vhdl-speedbar-line-project)))
13986 ;; keymap
13987 (unless vhdl-speedbar-key-map
13988 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13989 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13990 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13991 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13992 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13993 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13994 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13995 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13996 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13997 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13998 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13999 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14000 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14001 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14002 (let ((key 0))
14003 (while (<= key 9)
14004 (define-key vhdl-speedbar-key-map (int-to-string key)
14005 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14006 (setq key (1+ key)))))
14007 (define-key speedbar-key-map "h"
14008 (lambda () (interactive)
14009 (speedbar-change-initial-expansion-list "vhdl directory")))
14010 (define-key speedbar-key-map "H"
14011 (lambda () (interactive)
14012 (speedbar-change-initial-expansion-list "vhdl project")))
14013 ;; menu
14014 (unless vhdl-speedbar-menu-items
14015 (setq
14016 vhdl-speedbar-menu-items
14017 `(["Edit" speedbar-edit-line t]
14018 ["Expand" speedbar-expand-line
14019 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14020 ["Contract" vhdl-speedbar-contract-level t]
14021 ["Expand All" vhdl-speedbar-expand-all t]
14022 ["Contract All" vhdl-speedbar-contract-all t]
14023 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14024 (while (<= key 9)
14025 (setq menu-list
14026 (cons `[,(if (= key 0) "All" (int-to-string key))
14027 (vhdl-speedbar-set-depth ,key)
14028 :style radio
14029 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14030 :keys ,(int-to-string key)]
14031 menu-list))
14032 (setq key (1+ key)))
14033 (nreverse menu-list))
14034 "--"
14035 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14036 (or (vhdl-speedbar-check-unit 'entity)
14037 (vhdl-speedbar-check-unit 'subprogram))]
14038 ["Place Component" vhdl-speedbar-place-component
14039 (vhdl-speedbar-check-unit 'entity)]
14040 ["Generate Configuration" vhdl-speedbar-configuration
14041 (vhdl-speedbar-check-unit 'architecture)]
14042 ["Select as MRA" vhdl-speedbar-select-mra
14043 (vhdl-speedbar-check-unit 'architecture)]
14044 ["Make" vhdl-speedbar-make-design
14045 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14046 ["Generate Makefile" vhdl-speedbar-generate-makefile
14047 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14048 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14049 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14050 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14051 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14052 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14053 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14054 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14055 ;; hook-ups
14056 (speedbar-add-expansion-list
14057 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14058 vhdl-speedbar-display-directory))
14059 (speedbar-add-expansion-list
14060 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14061 vhdl-speedbar-display-projects))
14062 (setq speedbar-stealthy-function-list
14063 (append
14064 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14065 ("vhdl project" vhdl-speedbar-update-current-project
14066 vhdl-speedbar-update-current-unit)
14067 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14068 ; (speedbar-extension-list-to-regex
14069 ; speedbar-ignored-path-expressions))))
14070 )
14071 speedbar-stealthy-function-list))
14072 (when (eq vhdl-speedbar-display-mode 'directory)
14073 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14074 (when (eq vhdl-speedbar-display-mode 'project)
14075 (setq speedbar-initial-expansion-list-name "vhdl project"))
14076 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14077
14078 (defun vhdl-speedbar (&optional arg)
14079 "Open/close speedbar."
14080 (interactive)
14081 (if (not (fboundp 'speedbar))
14082 (error "WARNING: Speedbar is not available or not installed")
14083 (condition-case ()
14084 (speedbar-frame-mode arg)
14085 (error (error "WARNING: An error occurred while opening speedbar")))))
14086
14087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14088 ;; Display functions
14089
14090 (defvar vhdl-speedbar-last-selected-project nil
14091 "Name of last selected project.")
14092
14093 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14094 (defmacro speedbar-with-writable (&rest forms)
14095 "Allow the buffer to be writable and evaluate FORMS."
14096 (list 'let '((inhibit-read-only t))
14097 (cons 'progn forms)))
14098 (put 'speedbar-with-writable 'lisp-indent-function 0)
14099
14100 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14101 "Display directory and hierarchy information in speedbar."
14102 (setq vhdl-speedbar-show-projects nil)
14103 (setq speedbar-ignored-directory-regexp
14104 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14105 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14106 (setq speedbar-last-selected-file nil)
14107 (speedbar-with-writable
14108 (condition-case nil
14109 (progn
14110 ;; insert directory path
14111 (speedbar-directory-buttons directory depth)
14112 ;; insert subdirectories
14113 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14114 ;; scan and insert hierarchy of current directory
14115 (vhdl-speedbar-insert-dir-hierarchy directory depth
14116 speedbar-power-click)
14117 ;; expand subdirectories
14118 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14119 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14120
14121 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14122 "Display projects and hierarchy information in speedbar."
14123 (setq vhdl-speedbar-show-projects t)
14124 (setq speedbar-ignored-directory-regexp ".")
14125 (setq speedbar-last-selected-file nil)
14126 (setq vhdl-speedbar-last-selected-project nil)
14127 (speedbar-with-writable
14128 (condition-case nil
14129 ;; insert projects
14130 (vhdl-speedbar-insert-projects)
14131 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14132 (setq speedbar-full-text-cache nil)) ; prevent caching
14133
14134 (defun vhdl-speedbar-insert-projects ()
14135 "Insert all projects in speedbar."
14136 (vhdl-speedbar-make-title-line "Projects:")
14137 (let ((project-alist (if vhdl-project-sort
14138 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14139 vhdl-project-alist))
14140 (vhdl-speedbar-update-current-unit nil))
14141 ;; insert projects
14142 (while project-alist
14143 (speedbar-make-tag-line
14144 'angle ?+ 'vhdl-speedbar-expand-project
14145 (caar project-alist) (caar project-alist)
14146 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14147 (setq project-alist (cdr project-alist)))
14148 (setq project-alist vhdl-project-alist)
14149 ;; expand projects
14150 (while project-alist
14151 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14152 (goto-char (point-min))
14153 (when (re-search-forward
14154 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14155 (goto-char (match-end 1))
14156 (speedbar-do-function-pointer)))
14157 (setq project-alist (cdr project-alist))))
14158 ; (vhdl-speedbar-update-current-project)
14159 ; (vhdl-speedbar-update-current-unit nil t)
14160 )
14161
14162 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14163 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14164 otherwise use cached data."
14165 (when (or rescan (and (not (assoc project vhdl-file-alist))
14166 (not (vhdl-load-cache project))))
14167 (vhdl-scan-project-contents project))
14168 ;; insert design hierarchy
14169 (vhdl-speedbar-insert-hierarchy
14170 (aget vhdl-entity-alist project t)
14171 (aget vhdl-config-alist project t)
14172 (aget vhdl-package-alist project t)
14173 (car (aget vhdl-ent-inst-alist project t)) indent)
14174 (insert (int-to-string indent) ":\n")
14175 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14176 (put-text-property (1- (point)) (point) 'invisible nil)
14177 ;; expand design units
14178 (vhdl-speedbar-expand-units project))
14179
14180 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14181 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14182 otherwise use cached data."
14183 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14184 (not (vhdl-load-cache directory))))
14185 (vhdl-scan-directory-contents directory))
14186 ;; insert design hierarchy
14187 (vhdl-speedbar-insert-hierarchy
14188 (aget vhdl-entity-alist directory t)
14189 (aget vhdl-config-alist directory t)
14190 (aget vhdl-package-alist directory t)
14191 (car (aget vhdl-ent-inst-alist directory t)) depth)
14192 ;; expand design units
14193 (vhdl-speedbar-expand-units directory)
14194 (aput 'vhdl-directory-alist directory (list (list directory))))
14195
14196 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14197 ent-inst-list depth)
14198 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14199 (if (not (or ent-alist conf-alist pack-alist))
14200 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14201 (let (ent-entry conf-entry pack-entry)
14202 ;; insert entities
14203 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14204 (while ent-alist
14205 (setq ent-entry (car ent-alist))
14206 (speedbar-make-tag-line
14207 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14208 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14209 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14210 'vhdl-speedbar-entity-face depth)
14211 (unless (nth 2 ent-entry)
14212 (end-of-line 0) (insert "!") (forward-char 1))
14213 (unless (member (nth 0 ent-entry) ent-inst-list)
14214 (end-of-line 0) (insert " (top)") (forward-char 1))
14215 (setq ent-alist (cdr ent-alist)))
14216 ;; insert configurations
14217 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14218 (while conf-alist
14219 (setq conf-entry (car conf-alist))
14220 (speedbar-make-tag-line
14221 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14222 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14223 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14224 'vhdl-speedbar-configuration-face depth)
14225 (setq conf-alist (cdr conf-alist)))
14226 ;; insert packages
14227 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14228 (while pack-alist
14229 (setq pack-entry (car pack-alist))
14230 (vhdl-speedbar-make-pack-line
14231 (nth 0 pack-entry) (nth 1 pack-entry)
14232 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14233 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14234 depth)
14235 (setq pack-alist (cdr pack-alist))))))
14236
14237 (defun vhdl-speedbar-rescan-hierarchy ()
14238 "Rescan hierarchy for the directory or project under the cursor."
14239 (interactive)
14240 (let (key path)
14241 (cond
14242 ;; current project
14243 (vhdl-speedbar-show-projects
14244 (setq key (vhdl-speedbar-line-project))
14245 (vhdl-scan-project-contents key))
14246 ;; top-level directory
14247 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14248 (re-search-forward "[0-9]+:" nil t)
14249 (vhdl-scan-directory-contents
14250 (abbreviate-file-name (speedbar-line-directory))))
14251 ;; current directory
14252 (t (setq path (speedbar-line-directory))
14253 (string-match "^\\(.+[/\\]\\)" path)
14254 (vhdl-scan-directory-contents
14255 (abbreviate-file-name (match-string 1 path)))))
14256 (vhdl-speedbar-refresh key)))
14257
14258 (defun vhdl-speedbar-expand-dirs (directory)
14259 "Expand subdirectories in DIRECTORY according to
14260 `speedbar-shown-directories'."
14261 ;; (nicked from `speedbar-default-directory-list')
14262 (let ((sf (cdr (reverse speedbar-shown-directories)))
14263 (vhdl-speedbar-update-current-unit nil))
14264 (setq speedbar-shown-directories
14265 (list (expand-file-name default-directory)))
14266 (while sf
14267 (when (speedbar-goto-this-file (car sf))
14268 (beginning-of-line)
14269 (when (looking-at "[0-9]+:\\s-*<")
14270 (goto-char (match-end 0))
14271 (speedbar-do-function-pointer)))
14272 (setq sf (cdr sf))))
14273 (vhdl-speedbar-update-current-unit nil t))
14274
14275 (defun vhdl-speedbar-expand-units (key)
14276 "Expand design units in directory/project KEY according to
14277 `vhdl-speedbar-shown-unit-alist'."
14278 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14279 (vhdl-speedbar-update-current-unit nil)
14280 vhdl-updated-project-list)
14281 (adelete 'vhdl-speedbar-shown-unit-alist key)
14282 (vhdl-prepare-search-1
14283 (while unit-alist ; expand units
14284 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14285 (beginning-of-line)
14286 (let ((arch-alist (nth 1 (car unit-alist)))
14287 position)
14288 (when (looking-at "^[0-9]+:\\s-*\\[")
14289 (goto-char (match-end 0))
14290 (setq position (point))
14291 (speedbar-do-function-pointer)
14292 (select-frame speedbar-frame)
14293 (while arch-alist ; expand architectures
14294 (goto-char position)
14295 (when (re-search-forward
14296 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14297 (car arch-alist) "\\>\\)") nil t)
14298 (beginning-of-line)
14299 (when (looking-at "^[0-9]+:\\s-*{")
14300 (goto-char (match-end 0))
14301 (speedbar-do-function-pointer)
14302 (select-frame speedbar-frame)))
14303 (setq arch-alist (cdr arch-alist))))
14304 (setq unit-alist (cdr unit-alist))))))
14305 (vhdl-speedbar-update-current-unit nil t))
14306
14307 (defun vhdl-speedbar-contract-level ()
14308 "Contract current level in current directory/project."
14309 (interactive)
14310 (when (or (save-excursion
14311 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14312 (and (save-excursion
14313 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14314 (re-search-backward
14315 (format "^[0-%d]:\\s-*[[{<]-"
14316 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14317 (goto-char (match-end 0))
14318 (speedbar-do-function-pointer)
14319 (speedbar-center-buffer-smartly)))
14320
14321 (defun vhdl-speedbar-contract-all ()
14322 "Contract all expanded design units in current directory/project."
14323 (interactive)
14324 (if (and vhdl-speedbar-show-projects
14325 (save-excursion (beginning-of-line) (looking-at "^0:")))
14326 (progn (setq vhdl-speedbar-shown-project-list nil)
14327 (vhdl-speedbar-refresh))
14328 (let ((key (vhdl-speedbar-line-key)))
14329 (adelete 'vhdl-speedbar-shown-unit-alist key)
14330 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14331 (when (memq 'display vhdl-speedbar-save-cache)
14332 (add-to-list 'vhdl-updated-project-list key)))))
14333
14334 (defun vhdl-speedbar-expand-all ()
14335 "Expand all design units in current directory/project."
14336 (interactive)
14337 (let* ((key (vhdl-speedbar-line-key))
14338 (ent-alist (aget vhdl-entity-alist key t))
14339 (conf-alist (aget vhdl-config-alist key t))
14340 (pack-alist (aget vhdl-package-alist key t))
14341 arch-alist unit-alist subunit-alist)
14342 (add-to-list 'vhdl-speedbar-shown-project-list key)
14343 (while ent-alist
14344 (setq arch-alist (nth 4 (car ent-alist)))
14345 (setq subunit-alist nil)
14346 (while arch-alist
14347 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14348 (setq arch-alist (cdr arch-alist)))
14349 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14350 (setq ent-alist (cdr ent-alist)))
14351 (while conf-alist
14352 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14353 (setq conf-alist (cdr conf-alist)))
14354 (while pack-alist
14355 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14356 (setq pack-alist (cdr pack-alist)))
14357 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14358 (vhdl-speedbar-refresh)
14359 (when (memq 'display vhdl-speedbar-save-cache)
14360 (add-to-list 'vhdl-updated-project-list key))))
14361
14362 (defun vhdl-speedbar-expand-project (text token indent)
14363 "Expand/contract the project under the cursor."
14364 (cond
14365 ((string-match "+" text) ; expand project
14366 (speedbar-change-expand-button-char ?-)
14367 (unless (member token vhdl-speedbar-shown-project-list)
14368 (setq vhdl-speedbar-shown-project-list
14369 (cons token vhdl-speedbar-shown-project-list)))
14370 (speedbar-with-writable
14371 (save-excursion
14372 (end-of-line) (forward-char 1)
14373 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14374 speedbar-power-click))))
14375 ((string-match "-" text) ; contract project
14376 (speedbar-change-expand-button-char ?+)
14377 (setq vhdl-speedbar-shown-project-list
14378 (delete token vhdl-speedbar-shown-project-list))
14379 (speedbar-delete-subblock indent))
14380 (t (error "Nothing to display")))
14381 (when (equal (selected-frame) speedbar-frame)
14382 (speedbar-center-buffer-smartly)))
14383
14384 (defun vhdl-speedbar-expand-entity (text token indent)
14385 "Expand/contract the entity under the cursor."
14386 (cond
14387 ((string-match "+" text) ; expand entity
14388 (let* ((key (vhdl-speedbar-line-key indent))
14389 (ent-alist (aget vhdl-entity-alist key t))
14390 (ent-entry (aget ent-alist token t))
14391 (arch-alist (nth 3 ent-entry))
14392 (inst-alist (vhdl-get-instantiations token indent))
14393 (subpack-alist (nth 5 ent-entry))
14394 (multiple-arch (> (length arch-alist) 1))
14395 arch-entry inst-entry)
14396 (if (not (or arch-alist inst-alist subpack-alist))
14397 (speedbar-change-expand-button-char ??)
14398 (speedbar-change-expand-button-char ?-)
14399 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14400 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14401 (aput 'unit-alist token nil)
14402 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14403 (speedbar-with-writable
14404 (save-excursion
14405 (end-of-line) (forward-char 1)
14406 ;; insert architectures
14407 (when arch-alist
14408 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14409 (while arch-alist
14410 (setq arch-entry (car arch-alist))
14411 (speedbar-make-tag-line
14412 'curly ?+ 'vhdl-speedbar-expand-architecture
14413 (cons token (nth 0 arch-entry))
14414 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14415 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14416 'vhdl-speedbar-architecture-face (1+ indent))
14417 (when (and multiple-arch
14418 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14419 (end-of-line 0) (insert " (mra)") (forward-char 1))
14420 (setq arch-alist (cdr arch-alist)))
14421 ;; insert instantiations
14422 (when inst-alist
14423 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14424 (while inst-alist
14425 (setq inst-entry (car inst-alist))
14426 (vhdl-speedbar-make-inst-line
14427 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14428 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14429 nil nil nil (1+ indent) 0 " in ")
14430 (setq inst-alist (cdr inst-alist)))
14431 ;; insert required packages
14432 (vhdl-speedbar-insert-subpackages
14433 subpack-alist (1+ indent) indent)))
14434 (when (memq 'display vhdl-speedbar-save-cache)
14435 (add-to-list 'vhdl-updated-project-list key))
14436 (vhdl-speedbar-update-current-unit t t))))
14437 ((string-match "-" text) ; contract entity
14438 (speedbar-change-expand-button-char ?+)
14439 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14440 (let* ((key (vhdl-speedbar-line-key indent))
14441 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14442 (adelete 'unit-alist token)
14443 (if unit-alist
14444 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14445 (adelete 'vhdl-speedbar-shown-unit-alist key))
14446 (speedbar-delete-subblock indent)
14447 (when (memq 'display vhdl-speedbar-save-cache)
14448 (add-to-list 'vhdl-updated-project-list key))))
14449 (t (error "Nothing to display")))
14450 (when (equal (selected-frame) speedbar-frame)
14451 (speedbar-center-buffer-smartly)))
14452
14453 (defun vhdl-speedbar-expand-architecture (text token indent)
14454 "Expand/contract the architecture under the cursor."
14455 (cond
14456 ((string-match "+" text) ; expand architecture
14457 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14458 (ent-alist (aget vhdl-entity-alist key t))
14459 (conf-alist (aget vhdl-config-alist key t))
14460 (hier-alist (vhdl-get-hierarchy
14461 ent-alist conf-alist (car token) (cdr token) nil nil
14462 0 (1- indent)))
14463 (ent-entry (aget ent-alist (car token) t))
14464 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14465 (subpack-alist (nth 4 arch-entry))
14466 entry)
14467 (if (not (or hier-alist subpack-alist))
14468 (speedbar-change-expand-button-char ??)
14469 (speedbar-change-expand-button-char ?-)
14470 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14471 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14472 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14473 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14474 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14475 (speedbar-with-writable
14476 (save-excursion
14477 (end-of-line) (forward-char 1)
14478 ;; insert instance hierarchy
14479 (when hier-alist
14480 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14481 (1+ indent)))
14482 (while hier-alist
14483 (setq entry (car hier-alist))
14484 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14485 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14486 (vhdl-speedbar-make-inst-line
14487 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14488 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14489 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14490 (setq hier-alist (cdr hier-alist)))
14491 ;; insert required packages
14492 (vhdl-speedbar-insert-subpackages
14493 subpack-alist (1+ indent) (1- indent))))
14494 (when (memq 'display vhdl-speedbar-save-cache)
14495 (add-to-list 'vhdl-updated-project-list key))
14496 (vhdl-speedbar-update-current-unit t t))))
14497 ((string-match "-" text) ; contract architecture
14498 (speedbar-change-expand-button-char ?+)
14499 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14500 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14501 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14502 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14503 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14504 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14505 (speedbar-delete-subblock indent)
14506 (when (memq 'display vhdl-speedbar-save-cache)
14507 (add-to-list 'vhdl-updated-project-list key))))
14508 (t (error "Nothing to display")))
14509 (when (equal (selected-frame) speedbar-frame)
14510 (speedbar-center-buffer-smartly)))
14511
14512 (defun vhdl-speedbar-expand-config (text token indent)
14513 "Expand/contract the configuration under the cursor."
14514 (cond
14515 ((string-match "+" text) ; expand configuration
14516 (let* ((key (vhdl-speedbar-line-key indent))
14517 (conf-alist (aget vhdl-config-alist key t))
14518 (conf-entry (aget conf-alist token))
14519 (ent-alist (aget vhdl-entity-alist key t))
14520 (hier-alist (vhdl-get-hierarchy
14521 ent-alist conf-alist (nth 3 conf-entry)
14522 (nth 4 conf-entry) token (nth 5 conf-entry)
14523 0 indent t))
14524 (subpack-alist (nth 6 conf-entry))
14525 entry)
14526 (if (not (or hier-alist subpack-alist))
14527 (speedbar-change-expand-button-char ??)
14528 (speedbar-change-expand-button-char ?-)
14529 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14530 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14531 (aput 'unit-alist token nil)
14532 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14533 (speedbar-with-writable
14534 (save-excursion
14535 (end-of-line) (forward-char 1)
14536 ;; insert instance hierarchy
14537 (when hier-alist
14538 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14539 (while hier-alist
14540 (setq entry (car hier-alist))
14541 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14542 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14543 (vhdl-speedbar-make-inst-line
14544 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14545 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14546 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14547 (setq hier-alist (cdr hier-alist)))
14548 ;; insert required packages
14549 (vhdl-speedbar-insert-subpackages
14550 subpack-alist (1+ indent) indent)))
14551 (when (memq 'display vhdl-speedbar-save-cache)
14552 (add-to-list 'vhdl-updated-project-list key))
14553 (vhdl-speedbar-update-current-unit t t))))
14554 ((string-match "-" text) ; contract configuration
14555 (speedbar-change-expand-button-char ?+)
14556 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14557 (let* ((key (vhdl-speedbar-line-key indent))
14558 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14559 (adelete 'unit-alist token)
14560 (if unit-alist
14561 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14562 (adelete 'vhdl-speedbar-shown-unit-alist key))
14563 (speedbar-delete-subblock indent)
14564 (when (memq 'display vhdl-speedbar-save-cache)
14565 (add-to-list 'vhdl-updated-project-list key))))
14566 (t (error "Nothing to display")))
14567 (when (equal (selected-frame) speedbar-frame)
14568 (speedbar-center-buffer-smartly)))
14569
14570 (defun vhdl-speedbar-expand-package (text token indent)
14571 "Expand/contract the package under the cursor."
14572 (cond
14573 ((string-match "+" text) ; expand package
14574 (let* ((key (vhdl-speedbar-line-key indent))
14575 (pack-alist (aget vhdl-package-alist key t))
14576 (pack-entry (aget pack-alist token t))
14577 (comp-alist (nth 3 pack-entry))
14578 (func-alist (nth 4 pack-entry))
14579 (func-body-alist (nth 8 pack-entry))
14580 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14581 comp-entry func-entry func-body-entry)
14582 (if (not (or comp-alist func-alist subpack-alist))
14583 (speedbar-change-expand-button-char ??)
14584 (speedbar-change-expand-button-char ?-)
14585 ;; add package to `vhdl-speedbar-shown-unit-alist'
14586 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14587 (aput 'unit-alist token nil)
14588 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14589 (speedbar-with-writable
14590 (save-excursion
14591 (end-of-line) (forward-char 1)
14592 ;; insert components
14593 (when comp-alist
14594 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14595 (while comp-alist
14596 (setq comp-entry (car comp-alist))
14597 (speedbar-make-tag-line
14598 nil nil nil
14599 (cons token (nth 0 comp-entry))
14600 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14601 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14602 'vhdl-speedbar-entity-face (1+ indent))
14603 (setq comp-alist (cdr comp-alist)))
14604 ;; insert subprograms
14605 (when func-alist
14606 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14607 (while func-alist
14608 (setq func-entry (car func-alist)
14609 func-body-entry (aget func-body-alist (car func-entry) t))
14610 (when (nth 2 func-entry)
14611 (vhdl-speedbar-make-subprogram-line
14612 (nth 1 func-entry)
14613 (cons (nth 2 func-entry) (nth 3 func-entry))
14614 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14615 (1+ indent)))
14616 (setq func-alist (cdr func-alist)))
14617 ;; insert required packages
14618 (vhdl-speedbar-insert-subpackages
14619 subpack-alist (1+ indent) indent)))
14620 (when (memq 'display vhdl-speedbar-save-cache)
14621 (add-to-list 'vhdl-updated-project-list key))
14622 (vhdl-speedbar-update-current-unit t t))))
14623 ((string-match "-" text) ; contract package
14624 (speedbar-change-expand-button-char ?+)
14625 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14626 (let* ((key (vhdl-speedbar-line-key indent))
14627 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14628 (adelete 'unit-alist token)
14629 (if unit-alist
14630 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14631 (adelete 'vhdl-speedbar-shown-unit-alist key))
14632 (speedbar-delete-subblock indent)
14633 (when (memq 'display vhdl-speedbar-save-cache)
14634 (add-to-list 'vhdl-updated-project-list key))))
14635 (t (error "Nothing to display")))
14636 (when (equal (selected-frame) speedbar-frame)
14637 (speedbar-center-buffer-smartly)))
14638
14639 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14640 "Insert required packages."
14641 (let* ((pack-alist (aget vhdl-package-alist
14642 (vhdl-speedbar-line-key dir-indent) t))
14643 pack-key lib-name pack-entry)
14644 (when subpack-alist
14645 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14646 (while subpack-alist
14647 (setq pack-key (cdar subpack-alist)
14648 lib-name (caar subpack-alist))
14649 (setq pack-entry (aget pack-alist pack-key t))
14650 (vhdl-speedbar-make-subpack-line
14651 (or (nth 0 pack-entry) pack-key) lib-name
14652 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14653 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14654 (setq subpack-alist (cdr subpack-alist)))))
14655
14656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14657 ;; Display help functions
14658
14659 (defvar vhdl-speedbar-update-current-unit t
14660 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14661
14662 (defun vhdl-speedbar-update-current-project ()
14663 "Highlight project that is currently active."
14664 (when (and vhdl-speedbar-show-projects
14665 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14666 (and (boundp 'speedbar-frame)
14667 (frame-live-p speedbar-frame)))
14668 (let ((last-frame (selected-frame))
14669 (project-alist vhdl-project-alist)
14670 pos)
14671 (select-frame speedbar-frame)
14672 (speedbar-with-writable
14673 (save-excursion
14674 (while project-alist
14675 (goto-char (point-min))
14676 (when (re-search-forward
14677 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14678 (put-text-property (match-beginning 1) (match-end 1) 'face
14679 (if (equal (caar project-alist) vhdl-project)
14680 'speedbar-selected-face
14681 'speedbar-directory-face))
14682 (when (equal (caar project-alist) vhdl-project)
14683 (setq pos (1- (match-beginning 1)))))
14684 (setq project-alist (cdr project-alist))))
14685 (when pos (goto-char pos)))
14686 (select-frame last-frame)
14687 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14688 t)
14689
14690 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14691 "Highlight all design units that are contained in the current file.
14692 NO-POSITION non-nil means do not re-position cursor."
14693 (let ((last-frame (selected-frame))
14694 (project-list vhdl-speedbar-shown-project-list)
14695 file-alist pos file-name)
14696 ;; get current file name
14697 (if (fboundp 'speedbar-select-attached-frame)
14698 (speedbar-select-attached-frame)
14699 (select-frame speedbar-attached-frame))
14700 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14701 (when (and vhdl-speedbar-update-current-unit
14702 (or always (not (equal file-name speedbar-last-selected-file))))
14703 (if vhdl-speedbar-show-projects
14704 (while project-list
14705 (setq file-alist (append file-alist (aget vhdl-file-alist
14706 (car project-list) t)))
14707 (setq project-list (cdr project-list)))
14708 (setq file-alist (aget vhdl-file-alist
14709 (abbreviate-file-name default-directory) t)))
14710 (select-frame speedbar-frame)
14711 (set-buffer speedbar-buffer)
14712 (speedbar-with-writable
14713 (vhdl-prepare-search-1
14714 (save-excursion
14715 ;; unhighlight last units
14716 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14717 (vhdl-speedbar-update-units
14718 "\\[.\\] " (nth 0 file-entry)
14719 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14720 (vhdl-speedbar-update-units
14721 "{.} " (nth 1 file-entry)
14722 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14723 (vhdl-speedbar-update-units
14724 "\\[.\\] " (nth 3 file-entry)
14725 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14726 (vhdl-speedbar-update-units
14727 "[]>] " (nth 4 file-entry)
14728 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14729 (vhdl-speedbar-update-units
14730 "\\[.\\].+(" '("body")
14731 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14732 (vhdl-speedbar-update-units
14733 "> " (nth 6 file-entry)
14734 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14735 ;; highlight current units
14736 (let* ((file-entry (aget file-alist file-name t)))
14737 (setq
14738 pos (vhdl-speedbar-update-units
14739 "\\[.\\] " (nth 0 file-entry)
14740 file-name 'vhdl-speedbar-entity-selected-face pos)
14741 pos (vhdl-speedbar-update-units
14742 "{.} " (nth 1 file-entry)
14743 file-name 'vhdl-speedbar-architecture-selected-face pos)
14744 pos (vhdl-speedbar-update-units
14745 "\\[.\\] " (nth 3 file-entry)
14746 file-name 'vhdl-speedbar-configuration-selected-face pos)
14747 pos (vhdl-speedbar-update-units
14748 "[]>] " (nth 4 file-entry)
14749 file-name 'vhdl-speedbar-package-selected-face pos)
14750 pos (vhdl-speedbar-update-units
14751 "\\[.\\].+(" '("body")
14752 file-name 'vhdl-speedbar-package-selected-face pos)
14753 pos (vhdl-speedbar-update-units
14754 "> " (nth 6 file-entry)
14755 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14756 ;; move speedbar so the first highlighted unit is visible
14757 (when (and pos (not no-position))
14758 (goto-char pos)
14759 (speedbar-center-buffer-smartly)
14760 (speedbar-position-cursor-on-line))
14761 (setq speedbar-last-selected-file file-name))
14762 (select-frame last-frame)
14763 t))
14764
14765 (defun vhdl-speedbar-update-units (text unit-list file-name face
14766 &optional pos)
14767 "Help function to highlight design units."
14768 (while unit-list
14769 (goto-char (point-min))
14770 (while (re-search-forward
14771 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14772 (when (equal file-name (car (get-text-property
14773 (match-beginning 1) 'speedbar-token)))
14774 (setq pos (or pos (point-marker)))
14775 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14776 (setq unit-list (cdr unit-list)))
14777 pos)
14778
14779 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14780 ent-name ent-file-marker
14781 arch-name arch-file-marker
14782 conf-name conf-file-marker
14783 lib-name depth offset delimiter)
14784 "Insert instantiation entry."
14785 (let ((start (point))
14786 visible-start)
14787 (insert (int-to-string depth) ":")
14788 (put-text-property start (point) 'invisible t)
14789 (setq visible-start (point))
14790 (insert-char ? (* depth speedbar-indentation-width))
14791 (while (> offset 0)
14792 (insert "|")
14793 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14794 (setq offset (1- offset)))
14795 (put-text-property visible-start (point) 'invisible nil)
14796 (setq start (point))
14797 (insert ">")
14798 (speedbar-make-button start (point) nil nil nil)
14799 (setq visible-start (point))
14800 (insert " ")
14801 (setq start (point))
14802 (if (not inst-name)
14803 (insert "(top)")
14804 (insert inst-name)
14805 (speedbar-make-button
14806 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14807 'vhdl-speedbar-find-file inst-file-marker))
14808 (insert delimiter)
14809 (when ent-name
14810 (setq start (point))
14811 (insert ent-name)
14812 (speedbar-make-button
14813 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14814 'vhdl-speedbar-find-file ent-file-marker)
14815 (when arch-name
14816 (insert " (")
14817 (setq start (point))
14818 (insert arch-name)
14819 (speedbar-make-button
14820 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14821 'vhdl-speedbar-find-file arch-file-marker)
14822 (insert ")"))
14823 (when conf-name
14824 (insert " (")
14825 (setq start (point))
14826 (insert conf-name)
14827 (speedbar-make-button
14828 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14829 'vhdl-speedbar-find-file conf-file-marker)
14830 (insert ")")))
14831 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14832 (setq start (point))
14833 (insert " (" lib-name ")")
14834 (put-text-property (+ 2 start) (1- (point)) 'face
14835 'vhdl-speedbar-library-face))
14836 (insert-char ?\n 1)
14837 (put-text-property visible-start (point) 'invisible nil)))
14838
14839 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14840 body-file-marker depth)
14841 "Insert package entry."
14842 (let ((start (point))
14843 visible-start)
14844 (insert (int-to-string depth) ":")
14845 (put-text-property start (point) 'invisible t)
14846 (setq visible-start (point))
14847 (insert-char ? (* depth speedbar-indentation-width))
14848 (put-text-property visible-start (point) 'invisible nil)
14849 (setq start (point))
14850 (insert "[+]")
14851 (speedbar-make-button
14852 start (point) 'speedbar-button-face 'speedbar-highlight-face
14853 'vhdl-speedbar-expand-package pack-key)
14854 (setq visible-start (point))
14855 (insert-char ? 1 nil)
14856 (setq start (point))
14857 (insert pack-name)
14858 (speedbar-make-button
14859 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14860 'vhdl-speedbar-find-file pack-file-marker)
14861 (unless (car pack-file-marker)
14862 (insert "!"))
14863 (when (car body-file-marker)
14864 (insert " (")
14865 (setq start (point))
14866 (insert "body")
14867 (speedbar-make-button
14868 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14869 'vhdl-speedbar-find-file body-file-marker)
14870 (insert ")"))
14871 (insert-char ?\n 1)
14872 (put-text-property visible-start (point) 'invisible nil)))
14873
14874 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14875 pack-body-file-marker depth)
14876 "Insert used package entry."
14877 (let ((start (point))
14878 visible-start)
14879 (insert (int-to-string depth) ":")
14880 (put-text-property start (point) 'invisible t)
14881 (setq visible-start (point))
14882 (insert-char ? (* depth speedbar-indentation-width))
14883 (put-text-property visible-start (point) 'invisible nil)
14884 (setq start (point))
14885 (insert ">")
14886 (speedbar-make-button start (point) nil nil nil)
14887 (setq visible-start (point))
14888 (insert " ")
14889 (setq start (point))
14890 (insert pack-name)
14891 (speedbar-make-button
14892 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14893 'vhdl-speedbar-find-file pack-file-marker)
14894 (when (car pack-body-file-marker)
14895 (insert " (")
14896 (setq start (point))
14897 (insert "body")
14898 (speedbar-make-button
14899 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14900 'vhdl-speedbar-find-file pack-body-file-marker)
14901 (insert ")"))
14902 (setq start (point))
14903 (insert " (" lib-name ")")
14904 (put-text-property (+ 2 start) (1- (point)) 'face
14905 'vhdl-speedbar-library-face)
14906 (insert-char ?\n 1)
14907 (put-text-property visible-start (point) 'invisible nil)))
14908
14909 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14910 func-body-file-marker
14911 depth)
14912 "Insert subprogram entry."
14913 (let ((start (point))
14914 visible-start)
14915 (insert (int-to-string depth) ":")
14916 (put-text-property start (point) 'invisible t)
14917 (setq visible-start (point))
14918 (insert-char ? (* depth speedbar-indentation-width))
14919 (put-text-property visible-start (point) 'invisible nil)
14920 (setq start (point))
14921 (insert ">")
14922 (speedbar-make-button start (point) nil nil nil)
14923 (setq visible-start (point))
14924 (insert " ")
14925 (setq start (point))
14926 (insert func-name)
14927 (speedbar-make-button
14928 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14929 'vhdl-speedbar-find-file func-file-marker)
14930 (when (car func-body-file-marker)
14931 (insert " (")
14932 (setq start (point))
14933 (insert "body")
14934 (speedbar-make-button
14935 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14936 'vhdl-speedbar-find-file func-body-file-marker)
14937 (insert ")"))
14938 (insert-char ?\n 1)
14939 (put-text-property visible-start (point) 'invisible nil)))
14940
14941 (defun vhdl-speedbar-make-title-line (text &optional depth)
14942 "Insert design unit title entry."
14943 (let ((start (point))
14944 visible-start)
14945 (when depth
14946 (insert (int-to-string depth) ":")
14947 (put-text-property start (point) 'invisible t))
14948 (setq visible-start (point))
14949 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14950 (setq start (point))
14951 (insert text)
14952 (speedbar-make-button start (point) nil nil nil nil)
14953 (insert-char ?\n 1)
14954 (put-text-property visible-start (point) 'invisible nil)))
14955
14956 (defun vhdl-speedbar-insert-dirs (files level)
14957 "Insert subdirectories."
14958 (let ((dirs (car files)))
14959 (while dirs
14960 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14961 (car dirs) 'speedbar-dir-follow nil
14962 'speedbar-directory-face level)
14963 (setq dirs (cdr dirs)))))
14964
14965 (defun vhdl-speedbar-dired (text token indent)
14966 "Speedbar click handler for directory expand button in hierarchy mode."
14967 (cond ((string-match "+" text) ; we have to expand this dir
14968 (setq speedbar-shown-directories
14969 (cons (expand-file-name
14970 (concat (speedbar-line-directory indent) token "/"))
14971 speedbar-shown-directories))
14972 (speedbar-change-expand-button-char ?-)
14973 (speedbar-reset-scanners)
14974 (speedbar-with-writable
14975 (save-excursion
14976 (end-of-line) (forward-char 1)
14977 (vhdl-speedbar-insert-dirs
14978 (speedbar-file-lists
14979 (concat (speedbar-line-directory indent) token "/"))
14980 (1+ indent))
14981 (speedbar-reset-scanners)
14982 (vhdl-speedbar-insert-dir-hierarchy
14983 (abbreviate-file-name
14984 (concat (speedbar-line-directory indent) token "/"))
14985 (1+ indent) speedbar-power-click)))
14986 (vhdl-speedbar-update-current-unit t t))
14987 ((string-match "-" text) ; we have to contract this node
14988 (speedbar-reset-scanners)
14989 (let ((oldl speedbar-shown-directories)
14990 (newl nil)
14991 (td (expand-file-name
14992 (concat (speedbar-line-directory indent) token))))
14993 (while oldl
14994 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14995 (setq newl (cons (car oldl) newl)))
14996 (setq oldl (cdr oldl)))
14997 (setq speedbar-shown-directories (nreverse newl)))
14998 (speedbar-change-expand-button-char ?+)
14999 (speedbar-delete-subblock indent))
15000 (t (error "Nothing to display")))
15001 (when (equal (selected-frame) speedbar-frame)
15002 (speedbar-center-buffer-smartly)))
15003
15004 (defun vhdl-speedbar-item-info ()
15005 "Derive and display information about this line item."
15006 (save-excursion
15007 (beginning-of-line)
15008 ;; skip invisible number info
15009 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15010 (cond
15011 ;; project/directory entry
15012 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15013 (if vhdl-speedbar-show-projects
15014 (message "Project \"%s\"" (match-string-no-properties 1))
15015 (speedbar-files-item-info)))
15016 ;; design unit entry
15017 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15018 (goto-char (match-end 1))
15019 (let ((face (get-text-property (point) 'face)))
15020 (message
15021 "%s \"%s\" in \"%s\""
15022 ;; design unit kind
15023 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15024 (eq face 'vhdl-speedbar-entity-selected-face))
15025 (if (equal (match-string 2) ">") "Component" "Entity"))
15026 ((or (eq face 'vhdl-speedbar-architecture-face)
15027 (eq face 'vhdl-speedbar-architecture-selected-face))
15028 "Architecture")
15029 ((or (eq face 'vhdl-speedbar-configuration-face)
15030 (eq face 'vhdl-speedbar-configuration-selected-face))
15031 "Configuration")
15032 ((or (eq face 'vhdl-speedbar-package-face)
15033 (eq face 'vhdl-speedbar-package-selected-face))
15034 "Package")
15035 ((or (eq face 'vhdl-speedbar-instantiation-face)
15036 (eq face 'vhdl-speedbar-instantiation-selected-face))
15037 "Instantiation")
15038 ((eq face 'vhdl-speedbar-subprogram-face)
15039 "Subprogram")
15040 (t ""))
15041 ;; design unit name
15042 (buffer-substring-no-properties
15043 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15044 (match-end 1))
15045 ;; file name
15046 (file-relative-name
15047 (or (car (get-text-property (point) 'speedbar-token))
15048 "?")
15049 (vhdl-default-directory)))))
15050 (t (message "")))))
15051
15052 (defun vhdl-speedbar-line-text ()
15053 "Calls `speedbar-line-text' and removes text properties."
15054 (let ((string (speedbar-line-text)))
15055 (set-text-properties 0 (length string) nil string)
15056 string))
15057
15058 (defun vhdl-speedbar-higher-text ()
15059 "Get speedbar-line-text of higher level."
15060 (let (depth string)
15061 (save-excursion
15062 (beginning-of-line)
15063 (looking-at "^\\([0-9]+\\):")
15064 (setq depth (string-to-number (match-string 1)))
15065 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15066 (setq string (match-string 1))
15067 (set-text-properties 0 (length string) nil string)
15068 string))))
15069
15070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15071 ;; Help functions
15072
15073 (defun vhdl-speedbar-line-key (&optional indent)
15074 "Get currently displayed directory of project name."
15075 (if vhdl-speedbar-show-projects
15076 (vhdl-speedbar-line-project)
15077 (abbreviate-file-name
15078 (file-name-as-directory (speedbar-line-directory indent)))))
15079
15080 (defun vhdl-speedbar-line-project (&optional indent)
15081 "Get currently displayed project name."
15082 (and vhdl-speedbar-show-projects
15083 (save-excursion
15084 (end-of-line)
15085 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15086 (match-string-no-properties 1))))
15087
15088 (defun vhdl-add-modified-file ()
15089 "Add file to `vhdl-modified-file-list'."
15090 (when vhdl-file-alist
15091 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15092 nil)
15093
15094 (defun vhdl-resolve-paths (path-list)
15095 "Resolve path wildcards in PATH-LIST."
15096 (let (path-list-1 path-list-2 path-beg path-end dir)
15097 ;; eliminate non-existent directories
15098 (while path-list
15099 (setq dir (car path-list))
15100 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15101 (if (file-directory-p (match-string 2 dir))
15102 (setq path-list-1 (cons dir path-list-1))
15103 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15104 (setq path-list (cdr path-list)))
15105 ;; resolve path wildcards
15106 (while path-list-1
15107 (setq dir (car path-list-1))
15108 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15109 (progn
15110 (setq path-beg (match-string 1 dir)
15111 path-end (match-string 5 dir))
15112 (setq path-list-1
15113 (append
15114 (mapcar
15115 (function
15116 (lambda (var) (concat path-beg var path-end)))
15117 (let ((all-list (vhdl-directory-files
15118 (match-string 2 dir) t
15119 (concat "\\<" (wildcard-to-regexp
15120 (match-string 4 dir)))))
15121 dir-list)
15122 (while all-list
15123 (when (file-directory-p (car all-list))
15124 (setq dir-list (cons (car all-list) dir-list)))
15125 (setq all-list (cdr all-list)))
15126 dir-list))
15127 (cdr path-list-1))))
15128 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15129 (when (file-directory-p (match-string 2 dir))
15130 (setq path-list-2 (cons dir path-list-2)))
15131 (setq path-list-1 (cdr path-list-1))))
15132 (nreverse path-list-2)))
15133
15134 (defun vhdl-speedbar-goto-this-unit (directory unit)
15135 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15136 (let ((dest (point)))
15137 (if (and (if vhdl-speedbar-show-projects
15138 (progn (goto-char (point-min)) t)
15139 (speedbar-goto-this-file directory))
15140 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15141 (progn (speedbar-position-cursor-on-line)
15142 t)
15143 (goto-char dest)
15144 nil)))
15145
15146 (defun vhdl-speedbar-find-file (text token indent)
15147 "When user clicks on TEXT, load file with name and position in TOKEN.
15148 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15149 is already shown in a buffer."
15150 (if (not (car token))
15151 (error "ERROR: File cannot be found")
15152 (let ((buffer (get-file-buffer (car token))))
15153 (speedbar-find-file-in-frame (car token))
15154 (when (or vhdl-speedbar-jump-to-unit buffer)
15155 (goto-char (point-min))
15156 (forward-line (1- (cdr token)))
15157 (recenter))
15158 (vhdl-speedbar-update-current-unit t t)
15159 (speedbar-set-timer dframe-update-speed)
15160 (speedbar-maybee-jump-to-attached-frame))))
15161
15162 (defun vhdl-speedbar-port-copy ()
15163 "Copy the port of the entity/component or subprogram under the cursor."
15164 (interactive)
15165 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15166 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15167 (error "ERROR: No entity/component or subprogram under cursor")
15168 (beginning-of-line)
15169 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15170 (condition-case info
15171 (let ((token (get-text-property
15172 (match-beginning 3) 'speedbar-token)))
15173 (vhdl-visit-file (car token) t
15174 (progn (goto-char (point-min))
15175 (forward-line (1- (cdr token)))
15176 (end-of-line)
15177 (if is-entity
15178 (vhdl-port-copy)
15179 (vhdl-subprog-copy)))))
15180 (error (error "ERROR: %s not scanned successfully\n (%s)"
15181 (if is-entity "Port" "Interface") (cadr info))))
15182 (error "ERROR: No entity/component or subprogram on current line")))))
15183
15184 (defun vhdl-speedbar-place-component ()
15185 "Place the entity/component under the cursor as component."
15186 (interactive)
15187 (if (not (vhdl-speedbar-check-unit 'entity))
15188 (error "ERROR: No entity/component under cursor")
15189 (vhdl-speedbar-port-copy)
15190 (if (fboundp 'speedbar-select-attached-frame)
15191 (speedbar-select-attached-frame)
15192 (select-frame speedbar-attached-frame))
15193 (vhdl-compose-place-component)
15194 (select-frame speedbar-frame)))
15195
15196 (defun vhdl-speedbar-configuration ()
15197 "Generate configuration for the architecture under the cursor."
15198 (interactive)
15199 (if (not (vhdl-speedbar-check-unit 'architecture))
15200 (error "ERROR: No architecture under cursor")
15201 (let ((arch-name (vhdl-speedbar-line-text))
15202 (ent-name (vhdl-speedbar-higher-text)))
15203 (if (fboundp 'speedbar-select-attached-frame)
15204 (speedbar-select-attached-frame)
15205 (select-frame speedbar-attached-frame))
15206 (vhdl-compose-configuration ent-name arch-name))))
15207
15208 (defun vhdl-speedbar-select-mra ()
15209 "Select the architecture under the cursor as MRA."
15210 (interactive)
15211 (if (not (vhdl-speedbar-check-unit 'architecture))
15212 (error "ERROR: No architecture under cursor")
15213 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15214 (ent-key (downcase (vhdl-speedbar-higher-text)))
15215 (ent-alist (aget vhdl-entity-alist
15216 (or (vhdl-project-p) default-directory) t))
15217 (ent-entry (aget ent-alist ent-key t)))
15218 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15219 (speedbar-refresh))))
15220
15221 (defun vhdl-speedbar-make-design ()
15222 "Make (compile) design unit or directory/project under the cursor."
15223 (interactive)
15224 (if (not (save-excursion (beginning-of-line)
15225 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15226 (error "ERROR: No primary design unit or directory/project under cursor")
15227 (let ((is-unit (match-string 2))
15228 (unit-name (vhdl-speedbar-line-text))
15229 (vhdl-project (vhdl-speedbar-line-project))
15230 (directory (file-name-as-directory
15231 (or (speedbar-line-file) (speedbar-line-directory)))))
15232 (if (fboundp 'speedbar-select-attached-frame)
15233 (speedbar-select-attached-frame)
15234 (select-frame speedbar-attached-frame))
15235 (let ((default-directory directory))
15236 (vhdl-make (and is-unit unit-name))))))
15237
15238 (defun vhdl-speedbar-generate-makefile ()
15239 "Generate Makefile for directory/project under the cursor."
15240 (interactive)
15241 (let ((vhdl-project (vhdl-speedbar-line-project))
15242 (default-directory (file-name-as-directory
15243 (or (speedbar-line-file) (speedbar-line-directory)))))
15244 (vhdl-generate-makefile)))
15245
15246 (defun vhdl-speedbar-check-unit (design-unit)
15247 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15248 expansion function)."
15249 (save-excursion
15250 (speedbar-position-cursor-on-line)
15251 (cond ((eq design-unit 'entity)
15252 (memq (get-text-property (match-end 0) 'face)
15253 '(vhdl-speedbar-entity-face
15254 vhdl-speedbar-entity-selected-face)))
15255 ((eq design-unit 'architecture)
15256 (memq (get-text-property (match-end 0) 'face)
15257 '(vhdl-speedbar-architecture-face
15258 vhdl-speedbar-architecture-selected-face)))
15259 ((eq design-unit 'subprogram)
15260 (eq (get-text-property (match-end 0) 'face)
15261 'vhdl-speedbar-subprogram-face))
15262 (t nil))))
15263
15264 (defun vhdl-speedbar-set-depth (depth)
15265 "Set hierarchy display depth to DEPTH and refresh speedbar."
15266 (setq vhdl-speedbar-hierarchy-depth depth)
15267 (speedbar-refresh))
15268
15269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15270 ;; Fontification
15271
15272 (defface vhdl-speedbar-entity-face
15273 '((((class color) (background light)) (:foreground "ForestGreen"))
15274 (((class color) (background dark)) (:foreground "PaleGreen")))
15275 "Face used for displaying entity names."
15276 :group 'speedbar-faces)
15277
15278 (defface vhdl-speedbar-architecture-face
15279 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15280 (((class color) (background light)) (:foreground "Blue"))
15281
15282 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15283 "Face used for displaying architecture names."
15284 :group 'speedbar-faces)
15285
15286 (defface vhdl-speedbar-configuration-face
15287 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15288 (((class color) (background dark)) (:foreground "Salmon")))
15289 "Face used for displaying configuration names."
15290 :group 'speedbar-faces)
15291
15292 (defface vhdl-speedbar-package-face
15293 '((((class color) (background light)) (:foreground "Grey50"))
15294 (((class color) (background dark)) (:foreground "Grey80")))
15295 "Face used for displaying package names."
15296 :group 'speedbar-faces)
15297
15298 (defface vhdl-speedbar-library-face
15299 '((((class color) (background light)) (:foreground "Purple"))
15300 (((class color) (background dark)) (:foreground "Orchid1")))
15301 "Face used for displaying library names."
15302 :group 'speedbar-faces)
15303
15304 (defface vhdl-speedbar-instantiation-face
15305 '((((class color) (background light)) (:foreground "Brown"))
15306 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15307 (((class color) (background dark)) (:foreground "Yellow")))
15308 "Face used for displaying instantiation names."
15309 :group 'speedbar-faces)
15310
15311 (defface vhdl-speedbar-subprogram-face
15312 '((((class color) (background light)) (:foreground "Orchid4"))
15313 (((class color) (background dark)) (:foreground "BurlyWood2")))
15314 "Face used for displaying subprogram names."
15315 :group 'speedbar-faces)
15316
15317 (defface vhdl-speedbar-entity-selected-face
15318 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15319 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15320 "Face used for displaying entity names."
15321 :group 'speedbar-faces)
15322
15323 (defface vhdl-speedbar-architecture-selected-face
15324 '((((min-colors 88) (class color) (background light)) (:foreground
15325 "Blue1" :underline t))
15326 (((class color) (background light)) (:foreground "Blue" :underline t))
15327 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15328 "Face used for displaying architecture names."
15329 :group 'speedbar-faces)
15330
15331 (defface vhdl-speedbar-configuration-selected-face
15332 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15333 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15334 "Face used for displaying configuration names."
15335 :group 'speedbar-faces)
15336
15337 (defface vhdl-speedbar-package-selected-face
15338 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15339 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15340 "Face used for displaying package names."
15341 :group 'speedbar-faces)
15342
15343 (defface vhdl-speedbar-instantiation-selected-face
15344 '((((class color) (background light)) (:foreground "Brown" :underline t))
15345 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15346 "Face used for displaying instantiation names."
15347 :group 'speedbar-faces)
15348
15349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15350 ;; Initialization
15351
15352 ;; add speedbar
15353 (when (fboundp 'speedbar)
15354 (condition-case ()
15355 (when (and vhdl-speedbar-auto-open
15356 (not (and (boundp 'speedbar-frame)
15357 (frame-live-p speedbar-frame))))
15358 (speedbar-frame-mode 1)
15359 (if (fboundp 'speedbar-select-attached-frame)
15360 (speedbar-select-attached-frame)
15361 (select-frame speedbar-attached-frame)))
15362 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15363
15364 ;; initialize speedbar
15365 (if (not (boundp 'speedbar-frame))
15366 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15367 (vhdl-speedbar-initialize)
15368 (when speedbar-frame (vhdl-speedbar-refresh)))
15369
15370
15371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15372 ;;; Structural composition
15373 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15374
15375 (defun vhdl-get-components-package-name ()
15376 "Return the name of the components package."
15377 (let ((project (vhdl-project-p)))
15378 (if project
15379 (vhdl-replace-string (car vhdl-components-package-name)
15380 (subst-char-in-string ? ?_ project))
15381 (cdr vhdl-components-package-name))))
15382
15383 (defun vhdl-compose-new-component ()
15384 "Create entity and architecture for new component."
15385 (interactive)
15386 (let* ((case-fold-search t)
15387 (ent-name (read-from-minibuffer "entity name: "
15388 nil vhdl-minibuffer-local-map))
15389 (arch-name
15390 (if (equal (cdr vhdl-compose-architecture-name) "")
15391 (read-from-minibuffer "architecture name: "
15392 nil vhdl-minibuffer-local-map)
15393 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15394 ent-file-name arch-file-name ent-buffer arch-buffer project)
15395 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15396 ;; open entity file
15397 (unless (eq vhdl-compose-create-files 'none)
15398 (setq ent-file-name
15399 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15400 "." (file-name-extension (buffer-file-name))))
15401 (when (and (file-exists-p ent-file-name)
15402 (not (y-or-n-p (concat "File \"" ent-file-name
15403 "\" exists; overwrite? "))))
15404 (error "ERROR: Creating component...aborted"))
15405 (find-file ent-file-name)
15406 (erase-buffer)
15407 (set-buffer-modified-p nil))
15408 ;; insert header
15409 (if vhdl-compose-include-header
15410 (progn (vhdl-template-header)
15411 (goto-char (point-max)))
15412 (vhdl-comment-display-line) (insert "\n\n"))
15413 ;; insert library clause
15414 (vhdl-template-package-std-logic-1164)
15415 (when vhdl-use-components-package
15416 (insert "\n")
15417 (vhdl-template-standard-package (vhdl-work-library)
15418 (vhdl-get-components-package-name)))
15419 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15420 ;; insert entity declaration
15421 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15422 (vhdl-insert-keyword " IS\n")
15423 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15424 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15425 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15426 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15427 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15428 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15429 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15430 (vhdl-insert-keyword "END ")
15431 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15432 (insert ent-name ";\n\n")
15433 (vhdl-comment-display-line) (insert "\n")
15434 ;; open architecture file
15435 (if (not (eq vhdl-compose-create-files 'separate))
15436 (insert "\n")
15437 (setq ent-buffer (current-buffer))
15438 (setq arch-file-name
15439 (concat (vhdl-replace-string vhdl-architecture-file-name
15440 (concat ent-name " " arch-name) t)
15441 "." (file-name-extension (buffer-file-name))))
15442 (when (and (file-exists-p arch-file-name)
15443 (not (y-or-n-p (concat "File \"" arch-file-name
15444 "\" exists; overwrite? "))))
15445 (error "ERROR: Creating component...aborted"))
15446 (find-file arch-file-name)
15447 (erase-buffer)
15448 (set-buffer-modified-p nil)
15449 ;; insert header
15450 (if vhdl-compose-include-header
15451 (progn (vhdl-template-header)
15452 (goto-char (point-max)))
15453 (vhdl-comment-display-line) (insert "\n\n")))
15454 ;; insert architecture body
15455 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15456 (vhdl-insert-keyword " OF ") (insert ent-name)
15457 (vhdl-insert-keyword " IS\n\n")
15458 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15459 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15460 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15461 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15462 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15463 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15464 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15465 (vhdl-insert-keyword "BEGIN")
15466 (when vhdl-self-insert-comments
15467 (insert " -- ")
15468 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15469 (insert arch-name))
15470 (insert "\n\n")
15471 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15472 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15473 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15474 (vhdl-insert-keyword "END ")
15475 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15476 (insert arch-name ";\n\n")
15477 ;; insert footer and save
15478 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15479 (vhdl-template-footer)
15480 (vhdl-comment-display-line) (insert "\n"))
15481 (goto-char (point-min))
15482 (setq arch-buffer (current-buffer))
15483 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15484 (set-buffer arch-buffer) (save-buffer)
15485 (message "%s"
15486 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15487 (and ent-file-name
15488 (format "\n File created: \"%s\"" ent-file-name))
15489 (and arch-file-name
15490 (format "\n File created: \"%s\"" arch-file-name))))))
15491
15492 (defun vhdl-compose-place-component ()
15493 "Place new component by pasting current port as component declaration and
15494 component instantiation."
15495 (interactive)
15496 (if (not vhdl-port-list)
15497 (error "ERROR: No port has been read")
15498 (save-excursion
15499 (vhdl-prepare-search-2
15500 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15501 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15502 (error "ERROR: No architecture found"))
15503 (let* ((ent-name (match-string 1))
15504 (ent-file-name
15505 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15506 "." (file-name-extension (buffer-file-name))))
15507 (orig-buffer (current-buffer)))
15508 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15509 ;; place component declaration
15510 (unless (or vhdl-use-components-package
15511 (vhdl-use-direct-instantiation)
15512 (save-excursion
15513 (re-search-forward
15514 (concat "^\\s-*component\\s-+"
15515 (car vhdl-port-list) "\\>") nil t)))
15516 (re-search-forward "^begin\\>" nil)
15517 (beginning-of-line)
15518 (skip-chars-backward " \t\n")
15519 (insert "\n\n") (indent-to vhdl-basic-offset)
15520 (vhdl-port-paste-component t))
15521 ;; place component instantiation
15522 (re-search-forward "^end\\>" nil)
15523 (beginning-of-line)
15524 (skip-chars-backward " \t\n")
15525 (insert "\n\n") (indent-to vhdl-basic-offset)
15526 (vhdl-port-paste-instance nil t t)
15527 ;; place use clause for used packages
15528 (when (nth 3 vhdl-port-list)
15529 ;; open entity file
15530 (when (file-exists-p ent-file-name)
15531 (find-file ent-file-name))
15532 (goto-char (point-min))
15533 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15534 (error "ERROR: Entity not found: \"%s\"" ent-name))
15535 (goto-char (match-beginning 0))
15536 (if (and (save-excursion
15537 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15538 (match-string 1))
15539 (progn (goto-char (match-end 0))
15540 (beginning-of-line 2))
15541 (insert "\n")
15542 (backward-char))
15543 (vhdl-port-paste-context-clause)
15544 (switch-to-buffer orig-buffer))
15545 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15546
15547 (defun vhdl-compose-wire-components ()
15548 "Connect components."
15549 (interactive)
15550 (save-excursion
15551 (vhdl-prepare-search-2
15552 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15553 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15554 (error "ERROR: No architecture found"))
15555 (let* ((ent-name (match-string 1))
15556 (ent-file-name
15557 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15558 "." (file-name-extension (buffer-file-name))))
15559 (arch-decl-pos (point-marker))
15560 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15561 (arch-end-pos (re-search-forward "^end\\>" nil))
15562 (pack-name (vhdl-get-components-package-name))
15563 (pack-file-name
15564 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15565 "." (file-name-extension (buffer-file-name))))
15566 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15567 port-alist generic-alist inst-alist
15568 signal-name signal-entry signal-alist local-list written-list
15569 single-in-list multi-in-list single-out-list multi-out-list
15570 constant-name constant-entry constant-alist single-list multi-list
15571 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15572 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15573 signal-beg-pos signal-pos
15574 constant-temp-pos port-temp-pos signal-temp-pos)
15575 (message "Wiring components...")
15576 ;; process all instances
15577 (goto-char arch-stat-pos)
15578 (while (re-search-forward
15579 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15580 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15581 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15582 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15583 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15584 (setq inst-name (match-string-no-properties 1)
15585 comp-name (match-string-no-properties 4)
15586 comp-ent-name (match-string-no-properties 12)
15587 has-generic (or (match-string 7) (match-string 17)))
15588 ;; get port ...
15589 (if comp-name
15590 ;; ... from component declaration
15591 (vhdl-visit-file
15592 (when vhdl-use-components-package pack-file-name) t
15593 (save-excursion
15594 (goto-char (point-min))
15595 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15596 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15597 (vhdl-port-copy)))
15598 ;; ... from entity declaration (direct instantiation)
15599 (setq comp-ent-file-name
15600 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15601 "." (file-name-extension (buffer-file-name))))
15602 (vhdl-visit-file
15603 comp-ent-file-name t
15604 (save-excursion
15605 (goto-char (point-min))
15606 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15607 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15608 (vhdl-port-copy))))
15609 (vhdl-port-flatten t)
15610 (setq generic-alist (nth 1 vhdl-port-list)
15611 port-alist (nth 2 vhdl-port-list)
15612 vhdl-port-list nil)
15613 (setq constant-alist nil
15614 signal-alist nil)
15615 (when has-generic
15616 ;; process all constants in generic map
15617 (vhdl-forward-syntactic-ws)
15618 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15619 (setq constant-name (match-string-no-properties 3))
15620 (setq constant-entry
15621 (cons constant-name
15622 (if (match-string 1)
15623 (or (aget generic-alist (match-string 2) t)
15624 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15625 (cdar generic-alist))))
15626 (setq constant-alist (cons constant-entry constant-alist))
15627 (setq constant-name (downcase constant-name))
15628 (if (or (member constant-name single-list)
15629 (member constant-name multi-list))
15630 (progn (setq single-list (delete constant-name single-list))
15631 (add-to-list 'multi-list constant-name))
15632 (add-to-list 'single-list constant-name))
15633 (unless (match-string 1)
15634 (setq generic-alist (cdr generic-alist)))
15635 (vhdl-forward-syntactic-ws))
15636 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15637 ;; process all signals in port map
15638 (vhdl-forward-syntactic-ws)
15639 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15640 (setq signal-name (match-string-no-properties 3))
15641 (setq signal-entry (cons signal-name
15642 (if (match-string 1)
15643 (or (aget port-alist (match-string 2) t)
15644 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15645 (cdar port-alist))))
15646 (setq signal-alist (cons signal-entry signal-alist))
15647 (setq signal-name (downcase signal-name))
15648 (if (equal (upcase (nth 2 signal-entry)) "IN")
15649 ;; input signal
15650 (cond
15651 ((member signal-name local-list)
15652 nil)
15653 ((or (member signal-name single-out-list)
15654 (member signal-name multi-out-list))
15655 (setq single-out-list (delete signal-name single-out-list))
15656 (setq multi-out-list (delete signal-name multi-out-list))
15657 (add-to-list 'local-list signal-name))
15658 ((member signal-name single-in-list)
15659 (setq single-in-list (delete signal-name single-in-list))
15660 (add-to-list 'multi-in-list signal-name))
15661 ((not (member signal-name multi-in-list))
15662 (add-to-list 'single-in-list signal-name)))
15663 ;; output signal
15664 (cond
15665 ((member signal-name local-list)
15666 nil)
15667 ((or (member signal-name single-in-list)
15668 (member signal-name multi-in-list))
15669 (setq single-in-list (delete signal-name single-in-list))
15670 (setq multi-in-list (delete signal-name multi-in-list))
15671 (add-to-list 'local-list signal-name))
15672 ((member signal-name single-out-list)
15673 (setq single-out-list (delete signal-name single-out-list))
15674 (add-to-list 'multi-out-list signal-name))
15675 ((not (member signal-name multi-out-list))
15676 (add-to-list 'single-out-list signal-name))))
15677 (unless (match-string 1)
15678 (setq port-alist (cdr port-alist)))
15679 (vhdl-forward-syntactic-ws))
15680 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15681 (nreverse signal-alist)) inst-alist)))
15682 ;; prepare signal insertion
15683 (vhdl-goto-marker arch-decl-pos)
15684 (forward-line 1)
15685 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15686 (setq signal-pos (point-marker))
15687 (while (progn (vhdl-forward-syntactic-ws)
15688 (looking-at "signal\\>"))
15689 (beginning-of-line 2)
15690 (delete-region signal-pos (point)))
15691 (setq signal-beg-pos signal-pos)
15692 ;; open entity file
15693 (when (file-exists-p ent-file-name)
15694 (find-file ent-file-name))
15695 (goto-char (point-min))
15696 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15697 (error "ERROR: Entity not found: \"%s\"" ent-name))
15698 ;; prepare generic clause insertion
15699 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15700 (match-string 1))
15701 (goto-char (match-beginning 0))
15702 (indent-to vhdl-basic-offset)
15703 (insert "generic ();\n\n")
15704 (backward-char 4))
15705 (backward-char)
15706 (setq generic-pos (point-marker))
15707 (forward-sexp) (end-of-line)
15708 (delete-region generic-pos (point)) (delete-char 1)
15709 (insert "(\n")
15710 (when multi-list
15711 (insert "\n")
15712 (indent-to (* 2 vhdl-basic-offset))
15713 (insert "-- global generics\n"))
15714 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15715 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15716 ;; prepare port clause insertion
15717 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15718 (match-string 1))
15719 (goto-char (match-beginning 0))
15720 (indent-to vhdl-basic-offset)
15721 (insert "port ();\n\n")
15722 (backward-char 4))
15723 (backward-char)
15724 (setq port-in-pos (point-marker))
15725 (forward-sexp) (end-of-line)
15726 (delete-region port-in-pos (point)) (delete-char 1)
15727 (insert "(\n")
15728 (when (or multi-in-list multi-out-list)
15729 (insert "\n")
15730 (indent-to (* 2 vhdl-basic-offset))
15731 (insert "-- global ports\n"))
15732 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15733 port-out-pos (point-marker) port-inst-pos (point-marker)
15734 port-end-pos (point-marker))
15735 ;; insert generics, ports and signals
15736 (setq inst-alist (nreverse inst-alist))
15737 (while inst-alist
15738 (setq inst-name (nth 0 (car inst-alist))
15739 constant-alist (nth 1 (car inst-alist))
15740 signal-alist (nth 2 (car inst-alist))
15741 constant-temp-pos generic-inst-pos
15742 port-temp-pos port-inst-pos
15743 signal-temp-pos signal-pos)
15744 ;; generics
15745 (while constant-alist
15746 (setq constant-name (downcase (caar constant-alist))
15747 constant-entry (car constant-alist))
15748 (cond ((member constant-name written-list)
15749 nil)
15750 ((member constant-name multi-list)
15751 (vhdl-goto-marker generic-pos)
15752 (setq generic-end-pos
15753 (vhdl-max-marker
15754 generic-end-pos
15755 (vhdl-compose-insert-generic constant-entry)))
15756 (setq generic-pos (point-marker))
15757 (add-to-list 'written-list constant-name))
15758 (t
15759 (vhdl-goto-marker
15760 (vhdl-max-marker generic-inst-pos generic-pos))
15761 (setq generic-end-pos
15762 (vhdl-compose-insert-generic constant-entry))
15763 (setq generic-inst-pos (point-marker))
15764 (add-to-list 'written-list constant-name)))
15765 (setq constant-alist (cdr constant-alist)))
15766 (when (/= constant-temp-pos generic-inst-pos)
15767 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15768 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15769 (insert "-- generics for \"" inst-name "\"\n")
15770 (vhdl-goto-marker generic-inst-pos))
15771 ;; ports and signals
15772 (while signal-alist
15773 (setq signal-name (downcase (caar signal-alist))
15774 signal-entry (car signal-alist))
15775 (cond ((member signal-name written-list)
15776 nil)
15777 ((member signal-name multi-in-list)
15778 (vhdl-goto-marker port-in-pos)
15779 (setq port-end-pos
15780 (vhdl-max-marker
15781 port-end-pos (vhdl-compose-insert-port signal-entry)))
15782 (setq port-in-pos (point-marker))
15783 (add-to-list 'written-list signal-name))
15784 ((member signal-name multi-out-list)
15785 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15786 (setq port-end-pos
15787 (vhdl-max-marker
15788 port-end-pos (vhdl-compose-insert-port signal-entry)))
15789 (setq port-out-pos (point-marker))
15790 (add-to-list 'written-list signal-name))
15791 ((or (member signal-name single-in-list)
15792 (member signal-name single-out-list))
15793 (vhdl-goto-marker
15794 (vhdl-max-marker
15795 port-inst-pos
15796 (vhdl-max-marker port-out-pos port-in-pos)))
15797 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15798 (setq port-inst-pos (point-marker))
15799 (add-to-list 'written-list signal-name))
15800 ((equal (upcase (nth 2 signal-entry)) "OUT")
15801 (vhdl-goto-marker signal-pos)
15802 (vhdl-compose-insert-signal signal-entry)
15803 (setq signal-pos (point-marker))
15804 (add-to-list 'written-list signal-name)))
15805 (setq signal-alist (cdr signal-alist)))
15806 (when (/= port-temp-pos port-inst-pos)
15807 (vhdl-goto-marker
15808 (vhdl-max-marker port-temp-pos
15809 (vhdl-max-marker port-in-pos port-out-pos)))
15810 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15811 (insert "-- ports to \"" inst-name "\"\n")
15812 (vhdl-goto-marker port-inst-pos))
15813 (when (/= signal-temp-pos signal-pos)
15814 (vhdl-goto-marker signal-temp-pos)
15815 (insert "\n") (indent-to vhdl-basic-offset)
15816 (insert "-- outputs of \"" inst-name "\"\n")
15817 (vhdl-goto-marker signal-pos))
15818 (setq inst-alist (cdr inst-alist)))
15819 ;; finalize generic/port clause
15820 (vhdl-goto-marker generic-end-pos) (backward-char)
15821 (when (= generic-beg-pos generic-end-pos)
15822 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15823 (insert ";") (backward-char))
15824 (insert ")")
15825 (vhdl-goto-marker port-end-pos) (backward-char)
15826 (when (= port-beg-pos port-end-pos)
15827 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15828 (insert ";") (backward-char))
15829 (insert ")")
15830 ;; align everything
15831 (when vhdl-auto-align
15832 (vhdl-goto-marker generic-beg-pos)
15833 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15834 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15835 (vhdl-goto-marker signal-beg-pos)
15836 (vhdl-align-region-groups signal-beg-pos signal-pos))
15837 (switch-to-buffer (marker-buffer signal-beg-pos))
15838 (message "Wiring components...done")))))
15839
15840 (defun vhdl-compose-insert-generic (entry)
15841 "Insert ENTRY as generic declaration."
15842 (let (pos)
15843 (indent-to (* 2 vhdl-basic-offset))
15844 (insert (nth 0 entry) " : " (nth 1 entry))
15845 (when (nth 2 entry)
15846 (insert " := " (nth 2 entry)))
15847 (insert ";")
15848 (setq pos (point-marker))
15849 (when (and vhdl-include-port-comments (nth 3 entry))
15850 (vhdl-comment-insert-inline (nth 3 entry) t))
15851 (insert "\n")
15852 pos))
15853
15854 (defun vhdl-compose-insert-port (entry)
15855 "Insert ENTRY as port declaration."
15856 (let (pos)
15857 (indent-to (* 2 vhdl-basic-offset))
15858 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15859 (setq pos (point-marker))
15860 (when (and vhdl-include-port-comments (nth 4 entry))
15861 (vhdl-comment-insert-inline (nth 4 entry) t))
15862 (insert "\n")
15863 pos))
15864
15865 (defun vhdl-compose-insert-signal (entry)
15866 "Insert ENTRY as signal declaration."
15867 (indent-to vhdl-basic-offset)
15868 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15869 (when (and vhdl-include-port-comments (nth 4 entry))
15870 (vhdl-comment-insert-inline (nth 4 entry) t))
15871 (insert "\n"))
15872
15873 (defun vhdl-compose-components-package ()
15874 "Generate a package containing component declarations for all entities in the
15875 current project/directory."
15876 (interactive)
15877 (vhdl-require-hierarchy-info)
15878 (let* ((project (vhdl-project-p))
15879 (pack-name (vhdl-get-components-package-name))
15880 (pack-file-name
15881 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15882 "." (file-name-extension (buffer-file-name))))
15883 (ent-alist (aget vhdl-entity-alist
15884 (or project default-directory) t))
15885 (lazy-lock-minimum-size 0)
15886 clause-pos component-pos)
15887 (message "Generating components package \"%s\"..." pack-name)
15888 ;; open package file
15889 (when (and (file-exists-p pack-file-name)
15890 (not (y-or-n-p (concat "File \"" pack-file-name
15891 "\" exists; overwrite? "))))
15892 (error "ERROR: Generating components package...aborted"))
15893 (find-file pack-file-name)
15894 (erase-buffer)
15895 ;; insert header
15896 (if vhdl-compose-include-header
15897 (progn (vhdl-template-header
15898 (concat "Components package (generated by Emacs VHDL Mode "
15899 vhdl-version ")"))
15900 (goto-char (point-max)))
15901 (vhdl-comment-display-line) (insert "\n\n"))
15902 ;; insert std_logic_1164 package
15903 (vhdl-template-package-std-logic-1164)
15904 (insert "\n") (setq clause-pos (point-marker))
15905 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15906 ;; insert package declaration
15907 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15908 (vhdl-insert-keyword " IS\n\n")
15909 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15910 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15911 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15912 (indent-to vhdl-basic-offset)
15913 (setq component-pos (point-marker))
15914 (insert "\n\n") (vhdl-insert-keyword "END ")
15915 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15916 (insert pack-name ";\n\n")
15917 ;; insert footer
15918 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15919 (vhdl-template-footer)
15920 (vhdl-comment-display-line) (insert "\n"))
15921 ;; insert component declarations
15922 (while ent-alist
15923 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15924 (progn (goto-char (point-min))
15925 (forward-line (1- (nth 3 (car ent-alist))))
15926 (end-of-line)
15927 (vhdl-port-copy)))
15928 (goto-char component-pos)
15929 (vhdl-port-paste-component t)
15930 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15931 (setq component-pos (point-marker))
15932 (goto-char clause-pos)
15933 (vhdl-port-paste-context-clause pack-name)
15934 (setq clause-pos (point-marker))
15935 (setq ent-alist (cdr ent-alist)))
15936 (goto-char (point-min))
15937 (save-buffer)
15938 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15939 pack-name pack-file-name)))
15940
15941 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15942 &optional insert-conf)
15943 "Generate block configuration for architecture."
15944 (let ((margin (current-indentation))
15945 (beg (save-excursion (beginning-of-line) (point)))
15946 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15947 ;; insert block configuration (for architecture)
15948 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15949 (setq margin (+ margin vhdl-basic-offset))
15950 ;; process all instances
15951 (while inst-alist
15952 (setq inst-entry (car inst-alist))
15953 ;; is component?
15954 (when (nth 4 inst-entry)
15955 (setq insert-conf t)
15956 (setq inst-path (nth 9 inst-entry))
15957 ;; skip common path with previous instance
15958 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15959 (setq inst-path (cdr inst-path)
15960 inst-prev-path (cdr inst-prev-path)))
15961 ;; insert block configuration end (for previous block/generate)
15962 (while inst-prev-path
15963 (setq margin (- margin vhdl-basic-offset))
15964 (indent-to margin)
15965 (vhdl-insert-keyword "END FOR;\n")
15966 (setq inst-prev-path (cdr inst-prev-path)))
15967 ;; insert block configuration beginning (for current block/generate)
15968 (indent-to margin)
15969 (while inst-path
15970 (setq margin (+ margin vhdl-basic-offset))
15971 (vhdl-insert-keyword "FOR ")
15972 (insert (car inst-path) "\n")
15973 (indent-to margin)
15974 (setq inst-path (cdr inst-path)))
15975 ;; insert component configuration beginning
15976 (vhdl-insert-keyword "FOR ")
15977 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15978 ;; find subconfiguration
15979 (setq conf-key (nth 7 inst-entry))
15980 (setq tmp-alist conf-alist)
15981 ;; use first configuration found for instance's entity
15982 (while (and tmp-alist (null conf-key))
15983 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15984 (setq conf-key (nth 0 (car tmp-alist))))
15985 (setq tmp-alist (cdr tmp-alist)))
15986 (setq conf-entry (aget conf-alist conf-key t))
15987 ;; insert binding indication ...
15988 ;; ... with subconfiguration (if exists)
15989 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15990 (progn
15991 (indent-to (+ margin vhdl-basic-offset))
15992 (vhdl-insert-keyword "USE CONFIGURATION ")
15993 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15994 (insert ";\n"))
15995 ;; ... with entity (if exists)
15996 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15997 (when ent-entry
15998 (indent-to (+ margin vhdl-basic-offset))
15999 (vhdl-insert-keyword "USE ENTITY ")
16000 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16001 ;; insert architecture name (if architecture exists)
16002 (when (nth 3 ent-entry)
16003 (setq arch-name
16004 ;; choose architecture name a) from configuration,
16005 ;; b) from mra, or c) from first architecture
16006 (or (nth 0 (aget (nth 3 ent-entry)
16007 (or (nth 6 inst-entry)
16008 (nth 4 ent-entry)) t))
16009 (nth 1 (car (nth 3 ent-entry)))))
16010 (insert "(" arch-name ")"))
16011 (insert ";\n")
16012 ;; insert block configuration (for architecture of subcomponent)
16013 (when (and vhdl-compose-configuration-hierarchical
16014 (nth 3 ent-entry))
16015 (indent-to (+ margin vhdl-basic-offset))
16016 (vhdl-compose-configuration-architecture
16017 (nth 0 ent-entry) arch-name
16018 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16019 ;; insert component configuration end
16020 (indent-to margin)
16021 (vhdl-insert-keyword "END FOR;\n")
16022 (setq inst-prev-path (nth 9 inst-entry)))
16023 (setq inst-alist (cdr inst-alist)))
16024 ;; insert block configuration end (for block/generate)
16025 (while inst-prev-path
16026 (setq margin (- margin vhdl-basic-offset))
16027 (indent-to margin)
16028 (vhdl-insert-keyword "END FOR;\n")
16029 (setq inst-prev-path (cdr inst-prev-path)))
16030 (indent-to (- margin vhdl-basic-offset))
16031 ;; insert block configuration end or remove beginning (for architecture)
16032 (if insert-conf
16033 (vhdl-insert-keyword "END FOR;\n")
16034 (delete-region beg (point)))))
16035
16036 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16037 "Generate configuration declaration."
16038 (interactive)
16039 (vhdl-require-hierarchy-info)
16040 (let ((ent-alist (aget vhdl-entity-alist
16041 (or (vhdl-project-p) default-directory) t))
16042 (conf-alist (aget vhdl-config-alist
16043 (or (vhdl-project-p) default-directory) t))
16044 (from-speedbar ent-name)
16045 inst-alist conf-name conf-file-name pos)
16046 (vhdl-prepare-search-2
16047 ;; get entity and architecture name
16048 (unless ent-name
16049 (save-excursion
16050 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16051 (not (equal "END" (upcase (match-string 1))))
16052 (setq ent-name (match-string-no-properties 3))
16053 (setq arch-name (match-string-no-properties 2)))
16054 (error "ERROR: Not within an architecture"))))
16055 (setq conf-name (vhdl-replace-string
16056 vhdl-compose-configuration-name
16057 (concat ent-name " " arch-name)))
16058 (setq inst-alist
16059 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16060 (downcase arch-name) t))))
16061 (message "Generating configuration \"%s\"..." conf-name)
16062 (if vhdl-compose-configuration-create-file
16063 ;; open configuration file
16064 (progn
16065 (setq conf-file-name
16066 (concat (vhdl-replace-string vhdl-configuration-file-name
16067 conf-name t)
16068 "." (file-name-extension (buffer-file-name))))
16069 (when (and (file-exists-p conf-file-name)
16070 (not (y-or-n-p (concat "File \"" conf-file-name
16071 "\" exists; overwrite? "))))
16072 (error "ERROR: Creating configuration...aborted"))
16073 (find-file conf-file-name)
16074 (erase-buffer)
16075 (set-buffer-modified-p nil)
16076 ;; insert header
16077 (if vhdl-compose-include-header
16078 (progn (vhdl-template-header
16079 (concat "Configuration declaration for design \""
16080 ent-name "(" arch-name ")\""))
16081 (goto-char (point-max)))
16082 (vhdl-comment-display-line) (insert "\n\n")))
16083 ;; goto end of architecture
16084 (unless from-speedbar
16085 (re-search-forward "^end\\>" nil)
16086 (end-of-line) (insert "\n\n")
16087 (vhdl-comment-display-line) (insert "\n\n")))
16088 ;; insert library clause
16089 (setq pos (point))
16090 (vhdl-template-standard-package (vhdl-work-library) nil)
16091 (when (/= pos (point))
16092 (insert "\n\n"))
16093 ;; insert configuration
16094 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16095 (vhdl-insert-keyword " OF ") (insert ent-name)
16096 (vhdl-insert-keyword " IS\n")
16097 (indent-to vhdl-basic-offset)
16098 ;; insert block configuration (for architecture)
16099 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16100 (vhdl-insert-keyword "END ") (insert conf-name ";")
16101 (when conf-file-name
16102 ;; insert footer and save
16103 (insert "\n\n")
16104 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16105 (vhdl-template-footer)
16106 (vhdl-comment-display-line) (insert "\n"))
16107 (save-buffer))
16108 (message "%s"
16109 (concat (format "Generating configuration \"%s\"...done" conf-name)
16110 (and conf-file-name
16111 (format "\n File created: \"%s\"" conf-file-name))))))
16112
16113
16114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16115 ;;; Compilation / Makefile generation
16116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16117 ;; (using `compile.el')
16118
16119 (defun vhdl-makefile-name ()
16120 "Return the Makefile name of the current project or the current compiler if
16121 no project is defined."
16122 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16123 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16124 (vhdl-replace-string
16125 (cons "\\(.*\\)\n\\(.*\\)"
16126 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16127 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16128
16129 (defun vhdl-compile-directory ()
16130 "Return the directory where compilation/make should be run."
16131 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16132 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16133 (directory (vhdl-resolve-env-variable
16134 (if project
16135 (vhdl-replace-string
16136 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16137 (nth 6 compiler)))))
16138 (file-name-as-directory
16139 (if (file-name-absolute-p directory)
16140 directory
16141 (expand-file-name directory (vhdl-default-directory))))))
16142
16143 (defun vhdl-uniquify (in-list)
16144 "Remove duplicate elements from IN-LIST."
16145 (let (out-list)
16146 (while in-list
16147 (add-to-list 'out-list (car in-list))
16148 (setq in-list (cdr in-list)))
16149 out-list))
16150
16151 (defun vhdl-set-compiler (name)
16152 "Set current compiler to NAME."
16153 (interactive
16154 (list (let ((completion-ignore-case t))
16155 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16156 (if (assoc name vhdl-compiler-alist)
16157 (progn (setq vhdl-compiler name)
16158 (message "Current compiler: \"%s\"" vhdl-compiler))
16159 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16160
16161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16162 ;; Compilation
16163
16164 (defun vhdl-compile-init ()
16165 "Initialize for compilation."
16166 (when (or (null compilation-error-regexp-alist)
16167 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16168 compilation-error-regexp-alist)))
16169 ;; `compilation-error-regexp-alist'
16170 (let ((commands-alist vhdl-compiler-alist)
16171 regexp-alist sublist)
16172 (while commands-alist
16173 (setq sublist (nth 11 (car commands-alist)))
16174 (unless (or (equal "" (car sublist))
16175 (assoc (car sublist) regexp-alist))
16176 (setq regexp-alist (cons (list (nth 0 sublist)
16177 (if (= 0 (nth 1 sublist))
16178 (if (featurep 'xemacs) 9 nil)
16179 (nth 1 sublist))
16180 (nth 2 sublist) (nth 3 sublist))
16181 regexp-alist)))
16182 (setq commands-alist (cdr commands-alist)))
16183 (setq compilation-error-regexp-alist
16184 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16185 ;; `compilation-file-regexp-alist'
16186 (let ((commands-alist vhdl-compiler-alist)
16187 regexp-alist sublist)
16188 ;; matches vhdl-mode file name output
16189 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16190 (while commands-alist
16191 (setq sublist (nth 12 (car commands-alist)))
16192 (unless (or (equal "" (car sublist))
16193 (assoc (car sublist) regexp-alist))
16194 (setq regexp-alist (cons sublist regexp-alist)))
16195 (setq commands-alist (cdr commands-alist)))
16196 (setq compilation-file-regexp-alist
16197 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16198
16199 (defvar vhdl-compile-file-name nil
16200 "Name of file to be compiled.")
16201
16202 (defun vhdl-compile-print-file-name ()
16203 "Function called within `compile' to print out file name for compilers that
16204 do not print any file names."
16205 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16206
16207 (defun vhdl-get-compile-options (project compiler file-name
16208 &optional file-options-only)
16209 "Get compiler options. Returning nil means do not compile this file."
16210 (let* ((compiler-options (nth 1 compiler))
16211 (project-entry (aget (nth 4 project) vhdl-compiler))
16212 (project-options (nth 0 project-entry))
16213 (exception-list (and file-name (nth 2 project-entry)))
16214 (work-library (vhdl-work-library))
16215 (case-fold-search nil)
16216 file-options)
16217 (while (and exception-list
16218 (not (string-match (caar exception-list) file-name)))
16219 (setq exception-list (cdr exception-list)))
16220 (if (and exception-list (not (cdar exception-list)))
16221 nil
16222 (if (and file-options-only (not exception-list))
16223 'default
16224 (setq file-options (cdar exception-list))
16225 ;; insert library name in compiler-specific options
16226 (setq compiler-options
16227 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16228 work-library))
16229 ;; insert compiler-specific options in project-specific options
16230 (when project-options
16231 (setq project-options
16232 (vhdl-replace-string
16233 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16234 (concat work-library "\n" compiler-options))))
16235 ;; insert project-specific options in file-specific options
16236 (when file-options
16237 (setq file-options
16238 (vhdl-replace-string
16239 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16240 (concat work-library "\n" compiler-options "\n"
16241 project-options))))
16242 ;; return options
16243 (or file-options project-options compiler-options)))))
16244
16245 (defun vhdl-get-make-options (project compiler)
16246 "Get make options."
16247 (let* ((compiler-options (nth 3 compiler))
16248 (project-entry (aget (nth 4 project) vhdl-compiler))
16249 (project-options (nth 1 project-entry))
16250 (makefile-name (vhdl-makefile-name)))
16251 ;; insert Makefile name in compiler-specific options
16252 (setq compiler-options
16253 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16254 makefile-name))
16255 ;; insert compiler-specific options in project-specific options
16256 (when project-options
16257 (setq project-options
16258 (vhdl-replace-string
16259 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16260 (concat makefile-name "\n" compiler-options))))
16261 ;; return options
16262 (or project-options compiler-options)))
16263
16264 (defun vhdl-compile ()
16265 "Compile current buffer using the VHDL compiler specified in
16266 `vhdl-compiler'."
16267 (interactive)
16268 (vhdl-compile-init)
16269 (let* ((project (aget vhdl-project-alist vhdl-project))
16270 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16271 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16272 (command (nth 0 compiler))
16273 (file-name (buffer-file-name))
16274 (options (vhdl-get-compile-options project compiler file-name))
16275 (default-directory (vhdl-compile-directory))
16276 compilation-process-setup-function)
16277 (unless (file-directory-p default-directory)
16278 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16279 ;; put file name into quotes if it contains spaces
16280 (when (string-match " " file-name)
16281 (setq file-name (concat "\"" file-name "\"")))
16282 ;; print out file name if compiler does not
16283 (setq vhdl-compile-file-name (buffer-file-name))
16284 (when (and (= 0 (nth 1 (nth 10 compiler)))
16285 (= 0 (nth 1 (nth 11 compiler))))
16286 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16287 ;; run compilation
16288 (if options
16289 (when command
16290 (compile (concat command " " options " " file-name)))
16291 (vhdl-warning "Your project settings tell me not to compile this file"))))
16292
16293 (defvar vhdl-make-target "all"
16294 "Default target for `vhdl-make' command.")
16295
16296 (defun vhdl-make (&optional target)
16297 "Call make command for compilation of all updated source files (requires
16298 `Makefile'). Optional argument TARGET allows to compile the design
16299 specified by a target."
16300 (interactive)
16301 (setq vhdl-make-target
16302 (or target (read-from-minibuffer "Target: " vhdl-make-target
16303 vhdl-minibuffer-local-map)))
16304 (vhdl-compile-init)
16305 (let* ((project (aget vhdl-project-alist vhdl-project))
16306 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16307 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16308 (command (nth 2 compiler))
16309 (options (vhdl-get-make-options project compiler))
16310 (default-directory (vhdl-compile-directory)))
16311 (unless (file-directory-p default-directory)
16312 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16313 ;; run make
16314 (compile (concat (if (equal command "") "make" command)
16315 " " options " " vhdl-make-target))))
16316
16317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16318 ;; Makefile generation
16319
16320 (defun vhdl-generate-makefile ()
16321 "Generate `Makefile'."
16322 (interactive)
16323 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16324 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16325 (command (nth 4 compiler)))
16326 ;; generate makefile
16327 (if command
16328 (let ((default-directory (vhdl-compile-directory)))
16329 (compile (vhdl-replace-string
16330 (cons "\\(.*\\) \\(.*\\)" command)
16331 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16332 (vhdl-generate-makefile-1))))
16333
16334 (defun vhdl-get-packages (lib-alist work-library)
16335 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16336 (let (pack-list)
16337 (while lib-alist
16338 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16339 (setq pack-list (cons (cdar lib-alist) pack-list)))
16340 (setq lib-alist (cdr lib-alist)))
16341 pack-list))
16342
16343 (defun vhdl-generate-makefile-1 ()
16344 "Generate Makefile for current project or directory."
16345 ;; scan hierarchy if required
16346 (if (vhdl-project-p)
16347 (unless (or (assoc vhdl-project vhdl-file-alist)
16348 (vhdl-load-cache vhdl-project))
16349 (vhdl-scan-project-contents vhdl-project))
16350 (let ((directory (abbreviate-file-name default-directory)))
16351 (unless (or (assoc directory vhdl-file-alist)
16352 (vhdl-load-cache directory))
16353 (vhdl-scan-directory-contents directory))))
16354 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16355 (project (vhdl-project-p))
16356 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16357 (conf-alist (aget vhdl-config-alist (or project directory) t))
16358 (pack-alist (aget vhdl-package-alist (or project directory) t))
16359 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16360 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16361 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16362 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16363 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16364 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16365 (adjust-case (nth 5 regexp-list))
16366 (work-library (downcase (vhdl-work-library)))
16367 (compile-directory (expand-file-name (vhdl-compile-directory)
16368 default-directory))
16369 (makefile-name (vhdl-makefile-name))
16370 rule-alist arch-alist inst-alist
16371 target-list depend-list unit-list prim-list second-list subcomp-list
16372 lib-alist lib-body-alist pack-list all-pack-list
16373 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16374 conf-key conf-file-name pack-key pack-file-name
16375 ent-entry arch-entry conf-entry pack-entry inst-entry
16376 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16377 tmp-key tmp-list rule)
16378 ;; check prerequisites
16379 (unless (file-exists-p compile-directory)
16380 (make-directory compile-directory t))
16381 (unless regexp-list
16382 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16383 vhdl-compiler))
16384 (message "Generating makefile \"%s\"..." makefile-name)
16385 ;; rules for all entities
16386 (setq tmp-list ent-alist)
16387 (while ent-alist
16388 (setq ent-entry (car ent-alist)
16389 ent-key (nth 0 ent-entry))
16390 (when (nth 2 ent-entry)
16391 (setq ent-file-name (file-relative-name
16392 (nth 2 ent-entry) compile-directory)
16393 arch-alist (nth 4 ent-entry)
16394 lib-alist (nth 6 ent-entry)
16395 rule (aget rule-alist ent-file-name)
16396 target-list (nth 0 rule)
16397 depend-list (nth 1 rule)
16398 second-list nil
16399 subcomp-list nil)
16400 (setq tmp-key (vhdl-replace-string
16401 ent-regexp (funcall adjust-case ent-key)))
16402 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16403 ;; rule target for this entity
16404 (setq target-list (cons ent-key target-list))
16405 ;; rule dependencies for all used packages
16406 (setq pack-list (vhdl-get-packages lib-alist work-library))
16407 (setq depend-list (append depend-list pack-list))
16408 (setq all-pack-list pack-list)
16409 ;; add rule
16410 (aput 'rule-alist ent-file-name (list target-list depend-list))
16411 ;; rules for all corresponding architectures
16412 (while arch-alist
16413 (setq arch-entry (car arch-alist)
16414 arch-key (nth 0 arch-entry)
16415 ent-arch-key (concat ent-key "-" arch-key)
16416 arch-file-name (file-relative-name (nth 2 arch-entry)
16417 compile-directory)
16418 inst-alist (nth 4 arch-entry)
16419 lib-alist (nth 5 arch-entry)
16420 rule (aget rule-alist arch-file-name)
16421 target-list (nth 0 rule)
16422 depend-list (nth 1 rule))
16423 (setq tmp-key (vhdl-replace-string
16424 arch-regexp
16425 (funcall adjust-case (concat arch-key " " ent-key))))
16426 (setq unit-list
16427 (cons (cons ent-arch-key tmp-key) unit-list))
16428 (setq second-list (cons ent-arch-key second-list))
16429 ;; rule target for this architecture
16430 (setq target-list (cons ent-arch-key target-list))
16431 ;; rule dependency for corresponding entity
16432 (setq depend-list (cons ent-key depend-list))
16433 ;; rule dependencies for contained component instantiations
16434 (while inst-alist
16435 (setq inst-entry (car inst-alist))
16436 (when (or (null (nth 8 inst-entry))
16437 (equal (downcase (nth 8 inst-entry)) work-library))
16438 (setq inst-ent-key (or (nth 7 inst-entry)
16439 (nth 5 inst-entry)))
16440 (setq depend-list (cons inst-ent-key depend-list)
16441 subcomp-list (cons inst-ent-key subcomp-list)))
16442 (setq inst-alist (cdr inst-alist)))
16443 ;; rule dependencies for all used packages
16444 (setq pack-list (vhdl-get-packages lib-alist work-library))
16445 (setq depend-list (append depend-list pack-list))
16446 (setq all-pack-list (append all-pack-list pack-list))
16447 ;; add rule
16448 (aput 'rule-alist arch-file-name (list target-list depend-list))
16449 (setq arch-alist (cdr arch-alist)))
16450 (setq prim-list (cons (list ent-key second-list
16451 (append subcomp-list all-pack-list))
16452 prim-list)))
16453 (setq ent-alist (cdr ent-alist)))
16454 (setq ent-alist tmp-list)
16455 ;; rules for all configurations
16456 (setq tmp-list conf-alist)
16457 (while conf-alist
16458 (setq conf-entry (car conf-alist)
16459 conf-key (nth 0 conf-entry)
16460 conf-file-name (file-relative-name
16461 (nth 2 conf-entry) compile-directory)
16462 ent-key (nth 4 conf-entry)
16463 arch-key (nth 5 conf-entry)
16464 inst-alist (nth 6 conf-entry)
16465 lib-alist (nth 7 conf-entry)
16466 rule (aget rule-alist conf-file-name)
16467 target-list (nth 0 rule)
16468 depend-list (nth 1 rule)
16469 subcomp-list (list ent-key))
16470 (setq tmp-key (vhdl-replace-string
16471 conf-regexp (funcall adjust-case conf-key)))
16472 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16473 ;; rule target for this configuration
16474 (setq target-list (cons conf-key target-list))
16475 ;; rule dependency for corresponding entity and architecture
16476 (setq depend-list
16477 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16478 ;; rule dependencies for used packages
16479 (setq pack-list (vhdl-get-packages lib-alist work-library))
16480 (setq depend-list (append depend-list pack-list))
16481 ;; rule dependencies for contained component configurations
16482 (while inst-alist
16483 (setq inst-entry (car inst-alist))
16484 (setq inst-ent-key (nth 2 inst-entry)
16485 ; comp-arch-key (nth 2 inst-entry))
16486 inst-conf-key (nth 4 inst-entry))
16487 (when (equal (downcase (nth 5 inst-entry)) work-library)
16488 (when inst-ent-key
16489 (setq depend-list (cons inst-ent-key depend-list)
16490 subcomp-list (cons inst-ent-key subcomp-list)))
16491 ; (when comp-arch-key
16492 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16493 ; depend-list)))
16494 (when inst-conf-key
16495 (setq depend-list (cons inst-conf-key depend-list)
16496 subcomp-list (cons inst-conf-key subcomp-list))))
16497 (setq inst-alist (cdr inst-alist)))
16498 ;; add rule
16499 (aput 'rule-alist conf-file-name (list target-list depend-list))
16500 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16501 prim-list))
16502 (setq conf-alist (cdr conf-alist)))
16503 (setq conf-alist tmp-list)
16504 ;; rules for all packages
16505 (setq tmp-list pack-alist)
16506 (while pack-alist
16507 (setq pack-entry (car pack-alist)
16508 pack-key (nth 0 pack-entry)
16509 pack-body-key nil)
16510 (when (nth 2 pack-entry)
16511 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16512 compile-directory)
16513 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16514 rule (aget rule-alist pack-file-name)
16515 target-list (nth 0 rule) depend-list (nth 1 rule))
16516 (setq tmp-key (vhdl-replace-string
16517 pack-regexp (funcall adjust-case pack-key)))
16518 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16519 ;; rule target for this package
16520 (setq target-list (cons pack-key target-list))
16521 ;; rule dependencies for all used packages
16522 (setq pack-list (vhdl-get-packages lib-alist work-library))
16523 (setq depend-list (append depend-list pack-list))
16524 (setq all-pack-list pack-list)
16525 ;; add rule
16526 (aput 'rule-alist pack-file-name (list target-list depend-list))
16527 ;; rules for this package's body
16528 (when (nth 7 pack-entry)
16529 (setq pack-body-key (concat pack-key "-body")
16530 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16531 compile-directory)
16532 rule (aget rule-alist pack-body-file-name)
16533 target-list (nth 0 rule)
16534 depend-list (nth 1 rule))
16535 (setq tmp-key (vhdl-replace-string
16536 pack-body-regexp (funcall adjust-case pack-key)))
16537 (setq unit-list
16538 (cons (cons pack-body-key tmp-key) unit-list))
16539 ;; rule target for this package's body
16540 (setq target-list (cons pack-body-key target-list))
16541 ;; rule dependency for corresponding package declaration
16542 (setq depend-list (cons pack-key depend-list))
16543 ;; rule dependencies for all used packages
16544 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16545 (setq depend-list (append depend-list pack-list))
16546 (setq all-pack-list (append all-pack-list pack-list))
16547 ;; add rule
16548 (aput 'rule-alist pack-body-file-name
16549 (list target-list depend-list)))
16550 (setq prim-list
16551 (cons (list pack-key (when pack-body-key (list pack-body-key))
16552 all-pack-list)
16553 prim-list)))
16554 (setq pack-alist (cdr pack-alist)))
16555 (setq pack-alist tmp-list)
16556 ;; generate Makefile
16557 (let* ((project (aget vhdl-project-alist project))
16558 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16559 (compiler-id (nth 9 compiler))
16560 (library-directory
16561 (vhdl-resolve-env-variable
16562 (vhdl-replace-string
16563 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16564 compiler-id)))
16565 (makefile-path-name (expand-file-name
16566 makefile-name compile-directory))
16567 (orig-buffer (current-buffer))
16568 cell second-list subcomp-list options unit-key unit-name)
16569 ;; sort lists
16570 (setq unit-list (vhdl-sort-alist unit-list))
16571 (setq prim-list (vhdl-sort-alist prim-list))
16572 (setq tmp-list rule-alist)
16573 (while tmp-list ; pre-sort rule targets
16574 (setq cell (cdar tmp-list))
16575 (setcar cell (sort (car cell) 'string<))
16576 (setq tmp-list (cdr tmp-list)))
16577 (setq rule-alist ; sort by first rule target
16578 (sort rule-alist
16579 (function (lambda (a b)
16580 (string< (car (cadr a)) (car (cadr b)))))))
16581 ;; open and clear Makefile
16582 (set-buffer (find-file-noselect makefile-path-name t t))
16583 (erase-buffer)
16584 (insert "# -*- Makefile -*-\n"
16585 "### " (file-name-nondirectory makefile-name)
16586 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16587 "\n")
16588 (if project
16589 (insert "\n# Project : " (nth 0 project))
16590 (insert "\n# Directory : \"" directory "\""))
16591 (insert "\n# Platform : " vhdl-compiler
16592 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16593 (user-login-name) "\n")
16594 ;; insert compile and option variable settings
16595 (insert "\n\n# Define compilation command and options\n"
16596 "\nCOMPILE = " (nth 0 compiler)
16597 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16598 "\n")
16599 ;; insert library paths
16600 (setq library-directory
16601 (directory-file-name
16602 (if (file-name-absolute-p library-directory)
16603 library-directory
16604 (file-relative-name
16605 (expand-file-name library-directory directory)
16606 compile-directory))))
16607 (insert "\n\n# Define library paths\n"
16608 "\nLIBRARY-" work-library " = " library-directory "\n")
16609 ;; insert variable definitions for all library unit files
16610 (insert "\n\n# Define library unit files\n")
16611 (setq tmp-list unit-list)
16612 (while unit-list
16613 (insert "\nUNIT-" work-library "-" (caar unit-list)
16614 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16615 (setq unit-list (cdr unit-list)))
16616 ;; insert variable definition for list of all library unit files
16617 (insert "\n\n\n# Define list of all library unit files\n"
16618 "\nALL_UNITS =")
16619 (setq unit-list tmp-list)
16620 (while unit-list
16621 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16622 (setq unit-list (cdr unit-list)))
16623 (insert "\n")
16624 (setq unit-list tmp-list)
16625 ;; insert `make all' rule
16626 (insert "\n\n\n# Rule for compiling entire design\n"
16627 "\nall :"
16628 " \\\n\t\tlibrary"
16629 " \\\n\t\t$(ALL_UNITS)\n")
16630 ;; insert `make clean' rule
16631 (insert "\n\n# Rule for cleaning entire design\n"
16632 "\nclean : "
16633 "\n\t-rm -f $(ALL_UNITS)\n")
16634 ;; insert `make library' rule
16635 (insert "\n\n# Rule for creating library directory\n"
16636 "\nlibrary :"
16637 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16638 "\n$(LIBRARY-" work-library ") :"
16639 "\n\t"
16640 (vhdl-replace-string
16641 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16642 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16643 "\n")
16644 ;; insert rule for each library unit
16645 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16646 (while prim-list
16647 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16648 (setq subcomp-list
16649 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16650 (setq unit-key (caar prim-list)
16651 unit-name (or (nth 0 (aget ent-alist unit-key t))
16652 (nth 0 (aget conf-alist unit-key t))
16653 (nth 0 (aget pack-alist unit-key t))))
16654 (insert "\n" unit-key)
16655 (unless (equal unit-key unit-name)
16656 (insert " \\\n" unit-name))
16657 (insert " :"
16658 " \\\n\t\tlibrary"
16659 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16660 (while second-list
16661 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16662 (setq second-list (cdr second-list)))
16663 (while subcomp-list
16664 (when (and (assoc (car subcomp-list) unit-list)
16665 (not (equal unit-key (car subcomp-list))))
16666 (insert " \\\n\t\t" (car subcomp-list)))
16667 (setq subcomp-list (cdr subcomp-list)))
16668 (insert "\n")
16669 (setq prim-list (cdr prim-list)))
16670 ;; insert rule for each library unit file
16671 (insert "\n\n# Rules for compiling single library unit files\n")
16672 (while rule-alist
16673 (setq rule (car rule-alist))
16674 ;; get compiler options for this file
16675 (setq options
16676 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16677 ;; insert rule if file is supposed to be compiled
16678 (setq target-list (nth 1 rule)
16679 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16680 ;; insert targets
16681 (setq tmp-list target-list)
16682 (while target-list
16683 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16684 (if (cdr target-list) " \\" " :"))
16685 (setq target-list (cdr target-list)))
16686 (setq target-list tmp-list)
16687 ;; insert file name as first dependency
16688 (insert " \\\n\t\t" (nth 0 rule))
16689 ;; insert dependencies (except if also target or unit does not exist)
16690 (while depend-list
16691 (when (and (not (member (car depend-list) target-list))
16692 (assoc (car depend-list) unit-list))
16693 (insert " \\\n\t\t"
16694 "$(UNIT-" work-library "-" (car depend-list) ")"))
16695 (setq depend-list (cdr depend-list)))
16696 ;; insert compile command
16697 (if options
16698 (insert "\n\t$(COMPILE) "
16699 (if (eq options 'default) "$(OPTIONS)" options) " "
16700 (nth 0 rule) "\n")
16701 (setq tmp-list target-list)
16702 (while target-list
16703 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16704 (if (cdr target-list) " \\" "\n"))
16705 (setq target-list (cdr target-list)))
16706 (setq target-list tmp-list))
16707 (setq rule-alist (cdr rule-alist)))
16708 (insert "\n\n### " makefile-name " ends here\n")
16709 ;; run Makefile generation hook
16710 (run-hooks 'vhdl-makefile-generation-hook)
16711 (message "Generating makefile \"%s\"...done" makefile-name)
16712 ;; save and close file
16713 (if (file-writable-p makefile-path-name)
16714 (progn (save-buffer)
16715 (kill-buffer (current-buffer))
16716 (set-buffer orig-buffer)
16717 (add-to-history 'file-name-history makefile-path-name))
16718 (vhdl-warning-when-idle
16719 (format "File not writable: \"%s\""
16720 (abbreviate-file-name makefile-path-name)))
16721 (switch-to-buffer (current-buffer))))))
16722
16723
16724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16725 ;;; Bug reports
16726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16727 ;; (using `reporter.el')
16728
16729 (defconst vhdl-mode-help-address
16730 "Reto Zimmermann <reto@gnu.org>"
16731 "Address for VHDL Mode bug reports.")
16732
16733 (defun vhdl-submit-bug-report ()
16734 "Submit via mail a bug report on VHDL Mode."
16735 (interactive)
16736 ;; load in reporter
16737 (and
16738 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16739 (let ((reporter-prompt-for-summary-p t))
16740 (reporter-submit-bug-report
16741 vhdl-mode-help-address
16742 (concat "VHDL Mode " vhdl-version)
16743 (list
16744 ;; report all important user options
16745 'vhdl-offsets-alist
16746 'vhdl-comment-only-line-offset
16747 'tab-width
16748 'vhdl-electric-mode
16749 'vhdl-stutter-mode
16750 'vhdl-indent-tabs-mode
16751 'vhdl-project-alist
16752 'vhdl-project
16753 'vhdl-project-file-name
16754 'vhdl-project-auto-load
16755 'vhdl-project-sort
16756 'vhdl-compiler-alist
16757 'vhdl-compiler
16758 'vhdl-compile-use-local-error-regexp
16759 'vhdl-makefile-generation-hook
16760 'vhdl-default-library
16761 'vhdl-standard
16762 'vhdl-basic-offset
16763 'vhdl-upper-case-keywords
16764 'vhdl-upper-case-types
16765 'vhdl-upper-case-attributes
16766 'vhdl-upper-case-enum-values
16767 'vhdl-upper-case-constants
16768 'vhdl-use-direct-instantiation
16769 'vhdl-compose-configuration-name
16770 'vhdl-entity-file-name
16771 'vhdl-architecture-file-name
16772 'vhdl-configuration-file-name
16773 'vhdl-package-file-name
16774 'vhdl-file-name-case
16775 'vhdl-electric-keywords
16776 'vhdl-optional-labels
16777 'vhdl-insert-empty-lines
16778 'vhdl-argument-list-indent
16779 'vhdl-association-list-with-formals
16780 'vhdl-conditions-in-parenthesis
16781 'vhdl-zero-string
16782 'vhdl-one-string
16783 'vhdl-file-header
16784 'vhdl-file-footer
16785 'vhdl-company-name
16786 'vhdl-copyright-string
16787 'vhdl-platform-spec
16788 'vhdl-date-format
16789 'vhdl-modify-date-prefix-string
16790 'vhdl-modify-date-on-saving
16791 'vhdl-reset-kind
16792 'vhdl-reset-active-high
16793 'vhdl-clock-rising-edge
16794 'vhdl-clock-edge-condition
16795 'vhdl-clock-name
16796 'vhdl-reset-name
16797 'vhdl-model-alist
16798 'vhdl-include-port-comments
16799 'vhdl-include-direction-comments
16800 'vhdl-include-type-comments
16801 'vhdl-include-group-comments
16802 'vhdl-actual-port-name
16803 'vhdl-instance-name
16804 'vhdl-testbench-entity-name
16805 'vhdl-testbench-architecture-name
16806 'vhdl-testbench-configuration-name
16807 'vhdl-testbench-dut-name
16808 'vhdl-testbench-include-header
16809 'vhdl-testbench-declarations
16810 'vhdl-testbench-statements
16811 'vhdl-testbench-initialize-signals
16812 'vhdl-testbench-include-library
16813 'vhdl-testbench-include-configuration
16814 'vhdl-testbench-create-files
16815 'vhdl-testbench-entity-file-name
16816 'vhdl-testbench-architecture-file-name
16817 'vhdl-compose-create-files
16818 'vhdl-compose-configuration-create-file
16819 'vhdl-compose-configuration-hierarchical
16820 'vhdl-compose-configuration-use-subconfiguration
16821 'vhdl-compose-include-header
16822 'vhdl-compose-architecture-name
16823 'vhdl-components-package-name
16824 'vhdl-use-components-package
16825 'vhdl-self-insert-comments
16826 'vhdl-prompt-for-comments
16827 'vhdl-inline-comment-column
16828 'vhdl-end-comment-column
16829 'vhdl-auto-align
16830 'vhdl-align-groups
16831 'vhdl-align-group-separate
16832 'vhdl-align-same-indent
16833 'vhdl-highlight-keywords
16834 'vhdl-highlight-names
16835 'vhdl-highlight-special-words
16836 'vhdl-highlight-forbidden-words
16837 'vhdl-highlight-verilog-keywords
16838 'vhdl-highlight-translate-off
16839 'vhdl-highlight-case-sensitive
16840 'vhdl-special-syntax-alist
16841 'vhdl-forbidden-words
16842 'vhdl-forbidden-syntax
16843 'vhdl-directive-keywords
16844 'vhdl-speedbar-auto-open
16845 'vhdl-speedbar-display-mode
16846 'vhdl-speedbar-scan-limit
16847 'vhdl-speedbar-jump-to-unit
16848 'vhdl-speedbar-update-on-saving
16849 'vhdl-speedbar-save-cache
16850 'vhdl-speedbar-cache-file-name
16851 'vhdl-index-menu
16852 'vhdl-source-file-menu
16853 'vhdl-hideshow-menu
16854 'vhdl-hide-all-init
16855 'vhdl-print-two-column
16856 'vhdl-print-customize-faces
16857 'vhdl-intelligent-tab
16858 'vhdl-indent-syntax-based
16859 'vhdl-word-completion-case-sensitive
16860 'vhdl-word-completion-in-minibuffer
16861 'vhdl-underscore-is-part-of-word
16862 'vhdl-mode-hook)
16863 (function
16864 (lambda ()
16865 (insert
16866 (if vhdl-special-indent-hook
16867 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16868 "vhdl-special-indent-hook is set to '"
16869 (format "%s" vhdl-special-indent-hook)
16870 ".\nPerhaps this is your problem?\n"
16871 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16872 "\n"))))
16873 nil
16874 "Hi Reto,"))))
16875
16876
16877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16878 ;;; Documentation
16879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16880
16881 (defconst vhdl-doc-release-notes nil
16882 "\
16883 Release Notes for VHDL Mode 3.33
16884 ================================
16885
16886 - New Features
16887 - User Options
16888
16889
16890 New Features
16891 ------------
16892
16893 CONFIGURATION DECLARATION GENERATION:
16894 - Automatic generation of a configuration declaration for a design.
16895 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16896
16897
16898 User Options
16899 ------------
16900
16901 `vhdl-configuration-file-name': (new)
16902 Specify how the configuration file name is obtained.
16903 `vhdl-compose-configuration-name': (new)
16904 Specify how the configuration name is optained.
16905 `vhdl-compose-configuration-create-file': (new)
16906 Specify whether a new file should be created for a configuration.
16907 `vhdl-compose-configuration-hierarchical': (new)
16908 Specify whether hierarchical configurations should be created.
16909 `vhdl-compose-configuration-use-subconfiguration': (new)
16910 Specify whether subconfigurations should be used inside configurations.
16911 ")
16912
16913
16914 (defconst vhdl-doc-keywords nil
16915 "\
16916 Reserved words in VHDL
16917 ----------------------
16918
16919 VHDL'93 (IEEE Std 1076-1993):
16920 `vhdl-93-keywords' : keywords
16921 `vhdl-93-types' : standardized types
16922 `vhdl-93-attributes' : standardized attributes
16923 `vhdl-93-enum-values' : standardized enumeration values
16924 `vhdl-93-functions' : standardized functions
16925 `vhdl-93-packages' : standardized packages and libraries
16926
16927 VHDL-AMS (IEEE Std 1076.1):
16928 `vhdl-ams-keywords' : keywords
16929 `vhdl-ams-types' : standardized types
16930 `vhdl-ams-attributes' : standardized attributes
16931 `vhdl-ams-enum-values' : standardized enumeration values
16932 `vhdl-ams-functions' : standardized functions
16933
16934 Math Packages (IEEE Std 1076.2):
16935 `vhdl-math-types' : standardized types
16936 `vhdl-math-constants' : standardized constants
16937 `vhdl-math-functions' : standardized functions
16938 `vhdl-math-packages' : standardized packages
16939
16940 Forbidden words:
16941 `vhdl-verilog-keywords' : Verilog reserved words
16942
16943 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16944
16945
16946 (defconst vhdl-doc-coding-style nil
16947 "\
16948 For VHDL coding style and naming convention guidelines, see the following
16949 references:
16950
16951 \[1] Ben Cohen.
16952 \"VHDL Coding Styles and Methodologies\".
16953 Kluwer Academic Publishers, 1999.
16954 http://members.aol.com/vhdlcohen/vhdl/
16955
16956 \[2] Michael Keating and Pierre Bricaud.
16957 \"Reuse Methodology Manual, Second Edition\".
16958 Kluwer Academic Publishers, 1999.
16959 http://www.openmore.com/openmore/rmm2.html
16960
16961 \[3] European Space Agency.
16962 \"VHDL Modelling Guidelines\".
16963 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16964
16965 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16966 to visually support naming conventions.")
16967
16968
16969 (defun vhdl-version ()
16970 "Echo the current version of VHDL Mode in the minibuffer."
16971 (interactive)
16972 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16973 (vhdl-keep-region-active))
16974
16975 (defun vhdl-doc-variable (variable)
16976 "Display VARIABLE's documentation in *Help* buffer."
16977 (interactive)
16978 (unless (featurep 'xemacs)
16979 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16980 (with-output-to-temp-buffer
16981 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16982 (princ (documentation-property variable 'variable-documentation))
16983 (with-current-buffer standard-output
16984 (help-mode))
16985 (help-print-return-message)))
16986
16987 (defun vhdl-doc-mode ()
16988 "Display VHDL Mode documentation in *Help* buffer."
16989 (interactive)
16990 (unless (featurep 'xemacs)
16991 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16992 (with-output-to-temp-buffer
16993 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16994 (princ mode-name)
16995 (princ " mode:\n")
16996 (princ (documentation 'vhdl-mode))
16997 (with-current-buffer standard-output
16998 (help-mode))
16999 (help-print-return-message)))
17000
17001
17002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17003
17004 (provide 'vhdl-mode)
17005
17006 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17007 ;;; vhdl-mode.el ends here