Switch to recommended form of GPLv3 permissions notice.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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 preceeding character is part of a word then complete word,
1796 else if not at beginning of line then insert tab,
1797 else if last command was a `TAB' or `RET' then dedent one step,
1798 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1799 If nil, TAB always indents current line (i.e. `TAB' is bound to
1800 `indent-according-to-mode').
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 (current-syntax-table (syntax-table))
2333 result
2334 (restore-prog ; program to restore enviroment
2335 '(progn
2336 ;; restore syntax table
2337 (set-syntax-table current-syntax-table))))
2338 ;; use extended syntax table
2339 (set-syntax-table vhdl-mode-ext-syntax-table)
2340 ;; execute BODY safely
2341 (setq result
2342 (condition-case info
2343 (progn ,@body)
2344 (error (eval restore-prog) ; restore environment on error
2345 (error (cadr info))))) ; pass error up
2346 ;; restore environment
2347 (eval restore-prog)
2348 result))
2349
2350 (defmacro vhdl-prepare-search-2 (&rest body)
2351 "Enable case insensitive search, switch to syntax table that includes '_',
2352 and remove `intangible' overlays, then execute BODY, and finally restore the
2353 old environment. Used for consistent searching."
2354 `(let ((case-fold-search t) ; case insensitive search
2355 (current-syntax-table (syntax-table))
2356 result overlay-all-list overlay-intangible-list overlay
2357 (restore-prog ; program to restore enviroment
2358 '(progn
2359 ;; restore syntax table
2360 (set-syntax-table current-syntax-table)
2361 ;; restore `intangible' overlays
2362 (when (fboundp 'overlay-lists)
2363 (while overlay-intangible-list
2364 (overlay-put (car overlay-intangible-list) 'intangible t)
2365 (setq overlay-intangible-list
2366 (cdr overlay-intangible-list)))))))
2367 ;; use extended syntax table
2368 (set-syntax-table vhdl-mode-ext-syntax-table)
2369 ;; remove `intangible' overlays
2370 (when (fboundp 'overlay-lists)
2371 (setq overlay-all-list (overlay-lists))
2372 (setq overlay-all-list
2373 (append (car overlay-all-list) (cdr overlay-all-list)))
2374 (while overlay-all-list
2375 (setq overlay (car overlay-all-list))
2376 (when (memq 'intangible (overlay-properties overlay))
2377 (setq overlay-intangible-list
2378 (cons overlay overlay-intangible-list))
2379 (overlay-put overlay 'intangible nil))
2380 (setq overlay-all-list (cdr overlay-all-list))))
2381 ;; execute BODY safely
2382 (setq result
2383 (condition-case info
2384 (progn ,@body)
2385 (error (eval restore-prog) ; restore environment on error
2386 (error (cadr info))))) ; pass error up
2387 ;; restore environment
2388 (eval restore-prog)
2389 result))
2390
2391 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2392 "Visit file FILE-NAME and execute BODY."
2393 `(if (null ,file-name)
2394 (progn ,@body)
2395 (unless (file-directory-p ,file-name)
2396 (let ((source-buffer (current-buffer))
2397 (visiting-buffer (find-buffer-visiting ,file-name))
2398 file-opened)
2399 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2400 (condition-case ()
2401 (progn (set-buffer (create-file-buffer ,file-name))
2402 (setq file-opened t)
2403 (vhdl-insert-file-contents ,file-name)
2404 (modify-syntax-entry ?\- ". 12" (syntax-table))
2405 (modify-syntax-entry ?\n ">" (syntax-table))
2406 (modify-syntax-entry ?\^M ">" (syntax-table))
2407 (modify-syntax-entry ?_ "w" (syntax-table))
2408 t)
2409 (error
2410 (if ,issue-error
2411 (progn
2412 (when file-opened (kill-buffer (current-buffer)))
2413 (set-buffer source-buffer)
2414 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2415 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2416 nil))))
2417 (condition-case info
2418 (progn ,@body)
2419 (error
2420 (if ,issue-error
2421 (progn
2422 (when file-opened (kill-buffer (current-buffer)))
2423 (set-buffer source-buffer)
2424 (error (cadr info)))
2425 (vhdl-warning (cadr info))))))
2426 (when file-opened (kill-buffer (current-buffer)))
2427 (set-buffer source-buffer)))))
2428
2429 (defun vhdl-insert-file-contents (filename)
2430 "Nicked from `insert-file-contents-literally', but allow coding system
2431 conversion."
2432 (let ((format-alist nil)
2433 (after-insert-file-functions nil)
2434 (jka-compr-compression-info-list nil))
2435 (insert-file-contents filename t)))
2436
2437 (defun vhdl-sort-alist (alist)
2438 "Sort ALIST."
2439 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2440
2441 (defun vhdl-get-subdirs (directory)
2442 "Recursively get subdirectories of DIRECTORY."
2443 (let ((dir-list (list (file-name-as-directory directory)))
2444 file-list)
2445 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2446 (while file-list
2447 (when (file-directory-p (car file-list))
2448 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2449 (setq file-list (cdr file-list)))
2450 dir-list))
2451
2452 (defun vhdl-aput (alist-symbol key &optional value)
2453 "As `aput', but delete key-value pair if VALUE is nil."
2454 (if value
2455 (aput alist-symbol key value)
2456 (adelete alist-symbol key)))
2457
2458 (defun vhdl-delete (elt list)
2459 "Delete by side effect the first occurrence of ELT as a member of LIST."
2460 (setq list (cons nil list))
2461 (let ((list1 list))
2462 (while (and (cdr list1) (not (equal elt (cadr list1))))
2463 (setq list1 (cdr list1)))
2464 (when list
2465 (setcdr list1 (cddr list1))))
2466 (cdr list))
2467
2468 (defun vhdl-speedbar-refresh (&optional key)
2469 "Refresh directory or project with name KEY."
2470 (when (and (boundp 'speedbar-frame)
2471 (frame-live-p speedbar-frame))
2472 (let ((pos (point))
2473 (last-frame (selected-frame)))
2474 (if (null key)
2475 (speedbar-refresh)
2476 (select-frame speedbar-frame)
2477 (when (save-excursion
2478 (goto-char (point-min))
2479 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2480 (goto-char (match-end 1))
2481 (speedbar-do-function-pointer)
2482 (backward-char 2)
2483 (speedbar-do-function-pointer)
2484 (message "Refreshing speedbar...done"))
2485 (select-frame last-frame)))))
2486
2487 (defun vhdl-show-messages ()
2488 "Get *Messages* buffer to show recent messages."
2489 (interactive)
2490 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2491
2492 (defun vhdl-use-direct-instantiation ()
2493 "Return whether direct instantiation is used."
2494 (or (eq vhdl-use-direct-instantiation 'always)
2495 (and (eq vhdl-use-direct-instantiation 'standard)
2496 (not (vhdl-standard-p '87)))))
2497
2498 (defun vhdl-max-marker (marker1 marker2)
2499 "Return larger marker."
2500 (if (> marker1 marker2) marker1 marker2))
2501
2502 (defun vhdl-goto-marker (marker)
2503 "Goto marker in appropriate buffer."
2504 (when (markerp marker)
2505 (set-buffer (marker-buffer marker)))
2506 (goto-char marker))
2507
2508 (defun vhdl-menu-split (list title)
2509 "Split menu LIST into several submenues, if number of
2510 elements > `vhdl-menu-max-size'."
2511 (if (> (length list) vhdl-menu-max-size)
2512 (let ((remain list)
2513 (result '())
2514 (sublist '())
2515 (menuno 1)
2516 (i 0))
2517 (while remain
2518 (setq sublist (cons (car remain) sublist))
2519 (setq remain (cdr remain))
2520 (setq i (+ i 1))
2521 (if (= i vhdl-menu-max-size)
2522 (progn
2523 (setq result (cons (cons (format "%s %s" title menuno)
2524 (nreverse sublist)) result))
2525 (setq i 0)
2526 (setq menuno (+ menuno 1))
2527 (setq sublist '()))))
2528 (and sublist
2529 (setq result (cons (cons (format "%s %s" title menuno)
2530 (nreverse sublist)) result)))
2531 (nreverse result))
2532 list))
2533
2534
2535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2536 ;;; Bindings
2537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2538
2539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2540 ;; Key bindings
2541
2542 (defvar vhdl-template-map nil
2543 "Keymap for VHDL templates.")
2544
2545 (defun vhdl-template-map-init ()
2546 "Initialize `vhdl-template-map'."
2547 (setq vhdl-template-map (make-sparse-keymap))
2548 ;; key bindings for VHDL templates
2549 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2550 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2551 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2552 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2553 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2554 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2555 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2556 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2557 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2558 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2559 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2560 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2561 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2562 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2563 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2564 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2565 (define-key vhdl-template-map "el" 'vhdl-template-else)
2566 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2567 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2568 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2569 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2570 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2571 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2572 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2573 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2574 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2575 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2576 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2577 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2578 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2579 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2580 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2581 (define-key vhdl-template-map "li" 'vhdl-template-library)
2582 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2583 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2584 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2585 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2586 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2587 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2588 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2589 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2590 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2591 (define-key vhdl-template-map "po" 'vhdl-template-port)
2592 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2593 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2594 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2595 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2596 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2597 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2598 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2599 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2600 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2601 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2602 (define-key vhdl-template-map "us" 'vhdl-template-use)
2603 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2604 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2605 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2606 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2607 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2608 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2609 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2610 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2611 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2612 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2613 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2614 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2615 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2616 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2617 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2618 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2619 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2620 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2621 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2622 (when (vhdl-standard-p 'ams)
2623 (define-key vhdl-template-map "br" 'vhdl-template-break)
2624 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2625 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2626 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2627 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2628 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2629 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2630 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2631 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2632 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2633 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2634 )
2635 (when (vhdl-standard-p 'math)
2636 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2637 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2638 ))
2639
2640 ;; initialize template map for VHDL Mode
2641 (vhdl-template-map-init)
2642
2643 (defun vhdl-function-name (prefix string &optional postfix)
2644 "Generate a Lisp function name.
2645 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2646 STRING are replaced by `-' and substrings are converted to lower case."
2647 (let ((name prefix))
2648 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2649 (setq name
2650 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2651 (setq string (substring string (match-beginning 2))))
2652 (when postfix (setq name (concat name "-" postfix)))
2653 (intern name)))
2654
2655 (defvar vhdl-model-map nil
2656 "Keymap for VHDL models.")
2657
2658 (defun vhdl-model-map-init ()
2659 "Initialize `vhdl-model-map'."
2660 (setq vhdl-model-map (make-sparse-keymap))
2661 ;; key bindings for VHDL models
2662 (let ((model-alist vhdl-model-alist) model)
2663 (while model-alist
2664 (setq model (car model-alist))
2665 (define-key vhdl-model-map (nth 2 model)
2666 (vhdl-function-name "vhdl-model" (nth 0 model)))
2667 (setq model-alist (cdr model-alist)))))
2668
2669 ;; initialize user model map for VHDL Mode
2670 (vhdl-model-map-init)
2671
2672 (defvar vhdl-mode-map nil
2673 "Keymap for VHDL Mode.")
2674
2675 (defun vhdl-mode-map-init ()
2676 "Initialize `vhdl-mode-map'."
2677 (setq vhdl-mode-map (make-sparse-keymap))
2678 ;; template key bindings
2679 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2680 ;; model key bindings
2681 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2682 ;; standard key bindings
2683 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2684 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2685 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2686 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2687 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2688 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2689 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2690 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2691 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2692 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2693 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2694 ;; backspace/delete key bindings
2695 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2696 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2697 (define-key vhdl-mode-map [delete] 'delete-char)
2698 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2699 ;; mode specific key bindings
2700 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2701 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2702 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2703 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2704 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2705 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2706 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2707 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2708 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2709 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2710 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2711 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2712 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2713 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2714 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2715 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2716 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2717 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2718 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2719 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2720 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2721 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2722 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2723 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2724 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2725 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2726 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2727 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2728 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2729 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2730 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2731 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2732 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2733 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2734 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2735 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2736 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2737 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2740 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2741 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2743 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2746 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2747 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2748 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2749 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2750 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2751 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2752 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2753 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2754 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2755 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2756 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2757 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2758 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2759 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2761 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2762 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2763 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2764 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2765 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2766 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2767 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2768 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2769 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2770 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2771 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2772 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2773 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2774 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2775 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2776 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2777 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2778 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2779 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2780 ;; insert commands bindings
2781 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2782 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2783 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2784 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2785 ;; electric key bindings
2786 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2787 (when vhdl-intelligent-tab
2788 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2789 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2790 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2791 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2792 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2793 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2794 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2795 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2796 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2797 (when (vhdl-standard-p 'ams)
2798 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2799
2800 ;; initialize mode map for VHDL Mode
2801 (vhdl-mode-map-init)
2802
2803 ;; define special minibuffer keymap for enabling word completion in minibuffer
2804 ;; (useful in template generator prompts)
2805 (defvar vhdl-minibuffer-local-map
2806 (let ((map (make-sparse-keymap)))
2807 (set-keymap-parent map minibuffer-local-map)
2808 (when vhdl-word-completion-in-minibuffer
2809 (define-key map "\t" 'vhdl-minibuffer-tab))
2810 map)
2811 "Keymap for minibuffer used in VHDL Mode.")
2812
2813 ;; set up electric character functions to work with
2814 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2815 (mapc
2816 (function
2817 (lambda (sym)
2818 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2819 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2820 '(vhdl-electric-space
2821 vhdl-electric-tab
2822 vhdl-electric-return
2823 vhdl-electric-dash
2824 vhdl-electric-open-bracket
2825 vhdl-electric-close-bracket
2826 vhdl-electric-quote
2827 vhdl-electric-semicolon
2828 vhdl-electric-comma
2829 vhdl-electric-period
2830 vhdl-electric-equal))
2831
2832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2833 ;; Syntax table
2834
2835 (defvar vhdl-mode-syntax-table nil
2836 "Syntax table used in `vhdl-mode' buffers.")
2837
2838 (defvar vhdl-mode-ext-syntax-table nil
2839 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2840
2841 (defun vhdl-mode-syntax-table-init ()
2842 "Initialize `vhdl-mode-syntax-table'."
2843 (setq vhdl-mode-syntax-table (make-syntax-table))
2844 ;; define punctuation
2845 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2846 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2857 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2859 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2860 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2861 ;; define string
2862 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2863 ;; define underscore
2864 (when vhdl-underscore-is-part-of-word
2865 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2866 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2867 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2868 ;; and \n and \^M end a comment
2869 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2870 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2871 ;; define parentheses to match
2872 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2873 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2874 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2877 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2878 ;; extended syntax table including '_' (for simpler search regexps)
2879 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2880 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2881
2882 ;; initialize syntax table for VHDL Mode
2883 (vhdl-mode-syntax-table-init)
2884
2885 (defvar vhdl-syntactic-context nil
2886 "Buffer local variable containing syntactic analysis list.")
2887 (make-variable-buffer-local 'vhdl-syntactic-context)
2888
2889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2890 ;; Abbrev ook bindings
2891
2892 (defvar vhdl-mode-abbrev-table nil
2893 "Abbrev table to use in `vhdl-mode' buffers.")
2894
2895 (defun vhdl-mode-abbrev-table-init ()
2896 "Initialize `vhdl-mode-abbrev-table'."
2897 (define-abbrev-table 'vhdl-mode-abbrev-table
2898 (append
2899 (when (memq 'vhdl vhdl-electric-keywords)
2900 ;; VHDL'93 keywords
2901 '(
2902 ("--" "" vhdl-template-display-comment-hook 0)
2903 ("abs" "" vhdl-template-default-hook 0)
2904 ("access" "" vhdl-template-default-hook 0)
2905 ("after" "" vhdl-template-default-hook 0)
2906 ("alias" "" vhdl-template-alias-hook 0)
2907 ("all" "" vhdl-template-default-hook 0)
2908 ("and" "" vhdl-template-default-hook 0)
2909 ("arch" "" vhdl-template-architecture-hook 0)
2910 ("architecture" "" vhdl-template-architecture-hook 0)
2911 ("array" "" vhdl-template-default-hook 0)
2912 ("assert" "" vhdl-template-assert-hook 0)
2913 ("attr" "" vhdl-template-attribute-hook 0)
2914 ("attribute" "" vhdl-template-attribute-hook 0)
2915 ("begin" "" vhdl-template-default-indent-hook 0)
2916 ("block" "" vhdl-template-block-hook 0)
2917 ("body" "" vhdl-template-default-hook 0)
2918 ("buffer" "" vhdl-template-default-hook 0)
2919 ("bus" "" vhdl-template-default-hook 0)
2920 ("case" "" vhdl-template-case-hook 0)
2921 ("comp" "" vhdl-template-component-hook 0)
2922 ("component" "" vhdl-template-component-hook 0)
2923 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2924 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2925 ("conf" "" vhdl-template-configuration-hook 0)
2926 ("configuration" "" vhdl-template-configuration-hook 0)
2927 ("cons" "" vhdl-template-constant-hook 0)
2928 ("constant" "" vhdl-template-constant-hook 0)
2929 ("disconnect" "" vhdl-template-disconnect-hook 0)
2930 ("downto" "" vhdl-template-default-hook 0)
2931 ("else" "" vhdl-template-else-hook 0)
2932 ("elseif" "" vhdl-template-elsif-hook 0)
2933 ("elsif" "" vhdl-template-elsif-hook 0)
2934 ("end" "" vhdl-template-default-indent-hook 0)
2935 ("entity" "" vhdl-template-entity-hook 0)
2936 ("exit" "" vhdl-template-exit-hook 0)
2937 ("file" "" vhdl-template-file-hook 0)
2938 ("for" "" vhdl-template-for-hook 0)
2939 ("func" "" vhdl-template-function-hook 0)
2940 ("function" "" vhdl-template-function-hook 0)
2941 ("generic" "" vhdl-template-generic-hook 0)
2942 ("group" "" vhdl-template-group-hook 0)
2943 ("guarded" "" vhdl-template-default-hook 0)
2944 ("if" "" vhdl-template-if-hook 0)
2945 ("impure" "" vhdl-template-default-hook 0)
2946 ("in" "" vhdl-template-default-hook 0)
2947 ("inertial" "" vhdl-template-default-hook 0)
2948 ("inout" "" vhdl-template-default-hook 0)
2949 ("inst" "" vhdl-template-instance-hook 0)
2950 ("instance" "" vhdl-template-instance-hook 0)
2951 ("is" "" vhdl-template-default-hook 0)
2952 ("label" "" vhdl-template-default-hook 0)
2953 ("library" "" vhdl-template-library-hook 0)
2954 ("linkage" "" vhdl-template-default-hook 0)
2955 ("literal" "" vhdl-template-default-hook 0)
2956 ("loop" "" vhdl-template-bare-loop-hook 0)
2957 ("map" "" vhdl-template-map-hook 0)
2958 ("mod" "" vhdl-template-default-hook 0)
2959 ("nand" "" vhdl-template-default-hook 0)
2960 ("new" "" vhdl-template-default-hook 0)
2961 ("next" "" vhdl-template-next-hook 0)
2962 ("nor" "" vhdl-template-default-hook 0)
2963 ("not" "" vhdl-template-default-hook 0)
2964 ("null" "" vhdl-template-default-hook 0)
2965 ("of" "" vhdl-template-default-hook 0)
2966 ("on" "" vhdl-template-default-hook 0)
2967 ("open" "" vhdl-template-default-hook 0)
2968 ("or" "" vhdl-template-default-hook 0)
2969 ("others" "" vhdl-template-others-hook 0)
2970 ("out" "" vhdl-template-default-hook 0)
2971 ("pack" "" vhdl-template-package-hook 0)
2972 ("package" "" vhdl-template-package-hook 0)
2973 ("port" "" vhdl-template-port-hook 0)
2974 ("postponed" "" vhdl-template-default-hook 0)
2975 ("procedure" "" vhdl-template-procedure-hook 0)
2976 ("process" "" vhdl-template-process-hook 0)
2977 ("pure" "" vhdl-template-default-hook 0)
2978 ("range" "" vhdl-template-default-hook 0)
2979 ("record" "" vhdl-template-default-hook 0)
2980 ("register" "" vhdl-template-default-hook 0)
2981 ("reject" "" vhdl-template-default-hook 0)
2982 ("rem" "" vhdl-template-default-hook 0)
2983 ("report" "" vhdl-template-report-hook 0)
2984 ("return" "" vhdl-template-return-hook 0)
2985 ("rol" "" vhdl-template-default-hook 0)
2986 ("ror" "" vhdl-template-default-hook 0)
2987 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2988 ("severity" "" vhdl-template-default-hook 0)
2989 ("shared" "" vhdl-template-default-hook 0)
2990 ("sig" "" vhdl-template-signal-hook 0)
2991 ("signal" "" vhdl-template-signal-hook 0)
2992 ("sla" "" vhdl-template-default-hook 0)
2993 ("sll" "" vhdl-template-default-hook 0)
2994 ("sra" "" vhdl-template-default-hook 0)
2995 ("srl" "" vhdl-template-default-hook 0)
2996 ("subtype" "" vhdl-template-subtype-hook 0)
2997 ("then" "" vhdl-template-default-hook 0)
2998 ("to" "" vhdl-template-default-hook 0)
2999 ("transport" "" vhdl-template-default-hook 0)
3000 ("type" "" vhdl-template-type-hook 0)
3001 ("unaffected" "" vhdl-template-default-hook 0)
3002 ("units" "" vhdl-template-default-hook 0)
3003 ("until" "" vhdl-template-default-hook 0)
3004 ("use" "" vhdl-template-use-hook 0)
3005 ("var" "" vhdl-template-variable-hook 0)
3006 ("variable" "" vhdl-template-variable-hook 0)
3007 ("wait" "" vhdl-template-wait-hook 0)
3008 ("when" "" vhdl-template-when-hook 0)
3009 ("while" "" vhdl-template-while-loop-hook 0)
3010 ("with" "" vhdl-template-with-hook 0)
3011 ("xnor" "" vhdl-template-default-hook 0)
3012 ("xor" "" vhdl-template-default-hook 0)
3013 ))
3014 ;; VHDL-AMS keywords
3015 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3016 '(
3017 ("across" "" vhdl-template-default-hook 0)
3018 ("break" "" vhdl-template-break-hook 0)
3019 ("limit" "" vhdl-template-limit-hook 0)
3020 ("nature" "" vhdl-template-nature-hook 0)
3021 ("noise" "" vhdl-template-default-hook 0)
3022 ("procedural" "" vhdl-template-procedural-hook 0)
3023 ("quantity" "" vhdl-template-quantity-hook 0)
3024 ("reference" "" vhdl-template-default-hook 0)
3025 ("spectrum" "" vhdl-template-default-hook 0)
3026 ("subnature" "" vhdl-template-subnature-hook 0)
3027 ("terminal" "" vhdl-template-terminal-hook 0)
3028 ("through" "" vhdl-template-default-hook 0)
3029 ("tolerance" "" vhdl-template-default-hook 0)
3030 ))
3031 ;; user model keywords
3032 (when (memq 'user vhdl-electric-keywords)
3033 (let ((alist vhdl-model-alist)
3034 abbrev-list keyword)
3035 (while alist
3036 (setq keyword (nth 3 (car alist)))
3037 (unless (equal keyword "")
3038 (setq abbrev-list
3039 (cons (list keyword ""
3040 (vhdl-function-name
3041 "vhdl-model" (nth 0 (car alist)) "hook") 0)
3042 abbrev-list)))
3043 (setq alist (cdr alist)))
3044 abbrev-list)))))
3045
3046 ;; initialize abbrev table for VHDL Mode
3047 (vhdl-mode-abbrev-table-init)
3048
3049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3050 ;; Template completion lists
3051
3052 (defvar vhdl-template-construct-alist nil
3053 "List of built-in construct templates.")
3054
3055 (defun vhdl-template-construct-alist-init ()
3056 "Initialize `vhdl-template-construct-alist'."
3057 (setq
3058 vhdl-template-construct-alist
3059 (append
3060 '(
3061 ("alias declaration" vhdl-template-alias)
3062 ("architecture body" vhdl-template-architecture)
3063 ("assertion" vhdl-template-assert)
3064 ("attribute declaration" vhdl-template-attribute-decl)
3065 ("attribute specification" vhdl-template-attribute-spec)
3066 ("block configuration" vhdl-template-block-configuration)
3067 ("block statement" vhdl-template-block)
3068 ("case statement" vhdl-template-case-is)
3069 ("component configuration" vhdl-template-component-conf)
3070 ("component declaration" vhdl-template-component-decl)
3071 ("component instantiation statement" vhdl-template-component-inst)
3072 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3073 ("configuration declaration" vhdl-template-configuration-decl)
3074 ("configuration specification" vhdl-template-configuration-spec)
3075 ("constant declaration" vhdl-template-constant)
3076 ("disconnection specification" vhdl-template-disconnect)
3077 ("entity declaration" vhdl-template-entity)
3078 ("exit statement" vhdl-template-exit)
3079 ("file declaration" vhdl-template-file)
3080 ("generate statement" vhdl-template-generate)
3081 ("generic clause" vhdl-template-generic)
3082 ("group declaration" vhdl-template-group-decl)
3083 ("group template declaration" vhdl-template-group-template)
3084 ("if statement" vhdl-template-if-then)
3085 ("library clause" vhdl-template-library)
3086 ("loop statement" vhdl-template-loop)
3087 ("next statement" vhdl-template-next)
3088 ("package declaration" vhdl-template-package-decl)
3089 ("package body" vhdl-template-package-body)
3090 ("port clause" vhdl-template-port)
3091 ("process statement" vhdl-template-process)
3092 ("report statement" vhdl-template-report)
3093 ("return statement" vhdl-template-return)
3094 ("selected signal assignment" vhdl-template-selected-signal-asst)
3095 ("signal declaration" vhdl-template-signal)
3096 ("subprogram declaration" vhdl-template-subprogram-decl)
3097 ("subprogram body" vhdl-template-subprogram-body)
3098 ("subtype declaration" vhdl-template-subtype)
3099 ("type declaration" vhdl-template-type)
3100 ("use clause" vhdl-template-use)
3101 ("variable declaration" vhdl-template-variable)
3102 ("wait statement" vhdl-template-wait)
3103 )
3104 (when (vhdl-standard-p 'ams)
3105 '(
3106 ("break statement" vhdl-template-break)
3107 ("nature declaration" vhdl-template-nature)
3108 ("quantity declaration" vhdl-template-quantity)
3109 ("simultaneous case statement" vhdl-template-case-use)
3110 ("simultaneous if statement" vhdl-template-if-use)
3111 ("simultaneous procedural statement" vhdl-template-procedural)
3112 ("step limit specification" vhdl-template-limit)
3113 ("subnature declaration" vhdl-template-subnature)
3114 ("terminal declaration" vhdl-template-terminal)
3115 )))))
3116
3117 ;; initialize for VHDL Mode
3118 (vhdl-template-construct-alist-init)
3119
3120 (defvar vhdl-template-package-alist nil
3121 "List of built-in package templates.")
3122
3123 (defun vhdl-template-package-alist-init ()
3124 "Initialize `vhdl-template-package-alist'."
3125 (setq
3126 vhdl-template-package-alist
3127 (append
3128 '(
3129 ("numeric_bit" vhdl-template-package-numeric-bit)
3130 ("numeric_std" vhdl-template-package-numeric-std)
3131 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3132 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3133 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3134 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3135 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3136 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3137 ("textio" vhdl-template-package-textio)
3138 )
3139 (when (vhdl-standard-p 'math)
3140 '(
3141 ("math_complex" vhdl-template-package-math-complex)
3142 ("math_real" vhdl-template-package-math-real)
3143 )))))
3144
3145 ;; initialize for VHDL Mode
3146 (vhdl-template-package-alist-init)
3147
3148 (defvar vhdl-template-directive-alist
3149 '(
3150 ("translate_on" vhdl-template-directive-translate-on)
3151 ("translate_off" vhdl-template-directive-translate-off)
3152 ("synthesis_on" vhdl-template-directive-synthesis-on)
3153 ("synthesis_off" vhdl-template-directive-synthesis-off)
3154 )
3155 "List of built-in directive templates.")
3156
3157
3158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3159 ;;; Menues
3160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3161
3162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3163 ;; VHDL menu (using `easy-menu.el')
3164
3165 (defun vhdl-customize ()
3166 "Call the customize function with `vhdl' as argument."
3167 (interactive)
3168 (customize-browse 'vhdl))
3169
3170 (defun vhdl-create-mode-menu ()
3171 "Create VHDL Mode menu."
3172 `("VHDL"
3173 ,(append
3174 '("Project"
3175 ["None" (vhdl-set-project "")
3176 :style radio :selected (null vhdl-project)]
3177 "--")
3178 ;; add menu entries for defined projects
3179 (let ((project-alist vhdl-project-alist) menu-list name)
3180 (while project-alist
3181 (setq name (caar project-alist))
3182 (setq menu-list
3183 (cons `[,name (vhdl-set-project ,name)
3184 :style radio :selected (equal ,name vhdl-project)]
3185 menu-list))
3186 (setq project-alist (cdr project-alist)))
3187 (setq menu-list
3188 (if vhdl-project-sort
3189 (sort menu-list
3190 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3191 (nreverse menu-list)))
3192 (vhdl-menu-split menu-list "Project"))
3193 '("--" "--"
3194 ["Select Project..." vhdl-set-project t]
3195 ["Set As Default Project" vhdl-set-default-project t]
3196 "--"
3197 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3198 ["Import Project..." vhdl-import-project
3199 :keys "C-c C-p C-m" :active t]
3200 ["Export Project" vhdl-export-project vhdl-project]
3201 "--"
3202 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3203 "--"
3204 ("Compile"
3205 ["Compile Buffer" vhdl-compile t]
3206 ["Stop Compilation" kill-compilation t]
3207 "--"
3208 ["Make" vhdl-make t]
3209 ["Generate Makefile" vhdl-generate-makefile t]
3210 "--"
3211 ["Next Error" next-error t]
3212 ["Previous Error" previous-error t]
3213 ["First Error" first-error t]
3214 "--"
3215 ,(append
3216 '("Compiler")
3217 ;; add menu entries for defined compilers
3218 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3219 (while comp-alist
3220 (setq name (caar comp-alist))
3221 (setq menu-list
3222 (cons `[,name (setq vhdl-compiler ,name)
3223 :style radio :selected (equal ,name vhdl-compiler)]
3224 menu-list))
3225 (setq comp-alist (cdr comp-alist)))
3226 (setq menu-list (nreverse menu-list))
3227 (vhdl-menu-split menu-list "Compiler"))
3228 '("--" "--"
3229 ["Select Compiler..." vhdl-set-compiler t]
3230 "--"
3231 ["Customize Compiler..."
3232 (customize-option 'vhdl-compiler-alist) t])))
3233 "--"
3234 ,(append
3235 '("Template"
3236 ("VHDL Construct 1"
3237 ["Alias" vhdl-template-alias t]
3238 ["Architecture" vhdl-template-architecture t]
3239 ["Assert" vhdl-template-assert t]
3240 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3241 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3242 ["Block" vhdl-template-block t]
3243 ["Case" vhdl-template-case-is t]
3244 ["Component (Decl)" vhdl-template-component-decl t]
3245 ["(Component) Instance" vhdl-template-component-inst t]
3246 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3247 ["Configuration (Block)" vhdl-template-block-configuration t]
3248 ["Configuration (Comp)" vhdl-template-component-conf t]
3249 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3250 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3251 ["Constant" vhdl-template-constant t]
3252 ["Disconnect" vhdl-template-disconnect t]
3253 ["Else" vhdl-template-else t]
3254 ["Elsif" vhdl-template-elsif t]
3255 ["Entity" vhdl-template-entity t]
3256 ["Exit" vhdl-template-exit t]
3257 ["File" vhdl-template-file t]
3258 ["For (Generate)" vhdl-template-for-generate t]
3259 ["For (Loop)" vhdl-template-for-loop t]
3260 ["Function (Body)" vhdl-template-function-body t]
3261 ["Function (Decl)" vhdl-template-function-decl t]
3262 ["Generic" vhdl-template-generic t]
3263 ["Group (Decl)" vhdl-template-group-decl t]
3264 ["Group (Template)" vhdl-template-group-template t])
3265 ("VHDL Construct 2"
3266 ["If (Generate)" vhdl-template-if-generate t]
3267 ["If (Then)" vhdl-template-if-then t]
3268 ["Library" vhdl-template-library t]
3269 ["Loop" vhdl-template-bare-loop t]
3270 ["Map" vhdl-template-map t]
3271 ["Next" vhdl-template-next t]
3272 ["Others (Aggregate)" vhdl-template-others t]
3273 ["Package (Decl)" vhdl-template-package-decl t]
3274 ["Package (Body)" vhdl-template-package-body t]
3275 ["Port" vhdl-template-port t]
3276 ["Procedure (Body)" vhdl-template-procedure-body t]
3277 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3278 ["Process (Comb)" vhdl-template-process-comb t]
3279 ["Process (Seq)" vhdl-template-process-seq t]
3280 ["Report" vhdl-template-report t]
3281 ["Return" vhdl-template-return t]
3282 ["Select" vhdl-template-selected-signal-asst t]
3283 ["Signal" vhdl-template-signal t]
3284 ["Subtype" vhdl-template-subtype t]
3285 ["Type" vhdl-template-type t]
3286 ["Use" vhdl-template-use t]
3287 ["Variable" vhdl-template-variable t]
3288 ["Wait" vhdl-template-wait t]
3289 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3290 ["When" vhdl-template-when t]
3291 ["While (Loop)" vhdl-template-while-loop t]
3292 ["With" vhdl-template-with t]))
3293 (when (vhdl-standard-p 'ams)
3294 '(("VHDL-AMS Construct"
3295 ["Break" vhdl-template-break t]
3296 ["Case (Use)" vhdl-template-case-use t]
3297 ["If (Use)" vhdl-template-if-use t]
3298 ["Limit" vhdl-template-limit t]
3299 ["Nature" vhdl-template-nature t]
3300 ["Procedural" vhdl-template-procedural t]
3301 ["Quantity (Free)" vhdl-template-quantity-free t]
3302 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3303 ["Quantity (Source)" vhdl-template-quantity-source t]
3304 ["Subnature" vhdl-template-subnature t]
3305 ["Terminal" vhdl-template-terminal t])))
3306 '(["Insert Construct..." vhdl-template-insert-construct
3307 :keys "C-c C-i C-t"]
3308 "--")
3309 (list
3310 (append
3311 '("Package")
3312 (when (vhdl-standard-p 'math)
3313 '(["math_complex" vhdl-template-package-math-complex t]
3314 ["math_real" vhdl-template-package-math-real t]))
3315 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3316 ["numeric_std" vhdl-template-package-numeric-std t]
3317 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3318 ["textio" vhdl-template-package-textio t]
3319 "--"
3320 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3321 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3322 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3323 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3324 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3325 "--"
3326 ["Insert Package..." vhdl-template-insert-package
3327 :keys "C-c C-i C-p"])))
3328 '(("Directive"
3329 ["translate_on" vhdl-template-directive-translate-on t]
3330 ["translate_off" vhdl-template-directive-translate-off t]
3331 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3332 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3333 "--"
3334 ["Insert Directive..." vhdl-template-insert-directive
3335 :keys "C-c C-i C-d"])
3336 "--"
3337 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3338 ["Insert Footer" vhdl-template-footer t]
3339 ["Insert Date" vhdl-template-insert-date t]
3340 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3341 "--"
3342 ["Query Next Prompt" vhdl-template-search-prompt t]))
3343 ,(append
3344 '("Model")
3345 ;; add menu entries for defined models
3346 (let ((model-alist vhdl-model-alist) menu-list model)
3347 (while model-alist
3348 (setq model (car model-alist))
3349 (setq menu-list
3350 (cons
3351 (vector
3352 (nth 0 model)
3353 (vhdl-function-name "vhdl-model" (nth 0 model))
3354 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3355 menu-list))
3356 (setq model-alist (cdr model-alist)))
3357 (setq menu-list (nreverse menu-list))
3358 (vhdl-menu-split menu-list "Model"))
3359 '("--" "--"
3360 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3361 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3362 ("Port"
3363 ["Copy" vhdl-port-copy t]
3364 "--"
3365 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3366 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3367 ["Paste As Instance" vhdl-port-paste-instance
3368 :keys "C-c C-p C-i" :active vhdl-port-list]
3369 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3370 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3371 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3372 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3373 "--"
3374 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3375 "--"
3376 ["Flatten" vhdl-port-flatten
3377 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3378 ["Reverse Direction" vhdl-port-reverse-direction
3379 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3380 ("Compose"
3381 ["New Component" vhdl-compose-new-component t]
3382 ["Copy Component" vhdl-port-copy t]
3383 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3384 ["Wire Components" vhdl-compose-wire-components t]
3385 "--"
3386 ["Generate Configuration" vhdl-compose-configuration t]
3387 ["Generate Components Package" vhdl-compose-components-package t])
3388 ("Subprogram"
3389 ["Copy" vhdl-subprog-copy t]
3390 "--"
3391 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3392 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3393 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3394 "--"
3395 ["Flatten" vhdl-subprog-flatten
3396 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3397 "--"
3398 ("Comment"
3399 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3400 "--"
3401 ["Insert Inline Comment" vhdl-comment-append-inline t]
3402 ["Insert Horizontal Line" vhdl-comment-display-line t]
3403 ["Insert Display Comment" vhdl-comment-display t]
3404 "--"
3405 ["Fill Comment" fill-paragraph t]
3406 ["Fill Comment Region" fill-region (mark)]
3407 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3408 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3409 ("Line"
3410 ["Kill" vhdl-line-kill t]
3411 ["Copy" vhdl-line-copy t]
3412 ["Yank" vhdl-line-yank t]
3413 ["Expand" vhdl-line-expand t]
3414 "--"
3415 ["Transpose Next" vhdl-line-transpose-next t]
3416 ["Transpose Prev" vhdl-line-transpose-previous t]
3417 ["Open" vhdl-line-open t]
3418 ["Join" vhdl-delete-indentation t]
3419 "--"
3420 ["Goto" goto-line t]
3421 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3422 ("Move"
3423 ["Forward Statement" vhdl-end-of-statement t]
3424 ["Backward Statement" vhdl-beginning-of-statement t]
3425 ["Forward Expression" vhdl-forward-sexp t]
3426 ["Backward Expression" vhdl-backward-sexp t]
3427 ["Forward Same Indent" vhdl-forward-same-indent t]
3428 ["Backward Same Indent" vhdl-backward-same-indent t]
3429 ["Forward Function" vhdl-end-of-defun t]
3430 ["Backward Function" vhdl-beginning-of-defun t]
3431 ["Mark Function" vhdl-mark-defun t])
3432 "--"
3433 ("Indent"
3434 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3435 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3436 ["Region" vhdl-indent-region (mark)]
3437 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3438 ("Align"
3439 ["Group" vhdl-align-group t]
3440 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3441 ["List" vhdl-align-list t]
3442 ["Declarations" vhdl-align-declarations t]
3443 ["Region" vhdl-align-region (mark)]
3444 ["Buffer" vhdl-align-buffer t]
3445 "--"
3446 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3447 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3448 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3449 ("Fill"
3450 ["List" vhdl-fill-list t]
3451 ["Group" vhdl-fill-group t]
3452 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3453 ["Region" vhdl-fill-region (mark)])
3454 ("Beautify"
3455 ["Region" vhdl-beautify-region (mark)]
3456 ["Buffer" vhdl-beautify-buffer t])
3457 ("Fix"
3458 ["Generic/Port Clause" vhdl-fix-clause t]
3459 "--"
3460 ["Case Region" vhdl-fix-case-region (mark)]
3461 ["Case Buffer" vhdl-fix-case-buffer t]
3462 "--"
3463 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3464 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3465 "--"
3466 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3467 ("Update"
3468 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3469 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3470 "--"
3471 ["Fontify Buffer" vhdl-fontify-buffer t]
3472 ["Statistics Buffer" vhdl-statistics-buffer t]
3473 ["Show Messages" vhdl-show-messages t]
3474 ["Syntactic Info" vhdl-show-syntactic-information t]
3475 "--"
3476 ["Speedbar" vhdl-speedbar t]
3477 ["Hide/Show" vhdl-hs-minor-mode t]
3478 "--"
3479 ("Documentation"
3480 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3481 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3482 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3483 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3484 ["Version" vhdl-version t]
3485 ["Bug Report..." vhdl-submit-bug-report t]
3486 "--"
3487 ("Options"
3488 ("Mode"
3489 ["Electric Mode"
3490 (progn (customize-set-variable 'vhdl-electric-mode
3491 (not vhdl-electric-mode))
3492 (vhdl-mode-line-update))
3493 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3494 ["Stutter Mode"
3495 (progn (customize-set-variable 'vhdl-stutter-mode
3496 (not vhdl-stutter-mode))
3497 (vhdl-mode-line-update))
3498 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3499 ["Indent Tabs Mode"
3500 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3501 (not vhdl-indent-tabs-mode))
3502 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3503 :style toggle :selected vhdl-indent-tabs-mode]
3504 "--"
3505 ["Customize Group..." (customize-group 'vhdl-mode) t])
3506 ("Project"
3507 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3508 ,(append
3509 '("Selected Project at Startup"
3510 ["None" (progn (customize-set-variable 'vhdl-project nil)
3511 (vhdl-set-project ""))
3512 :style radio :selected (null vhdl-project)]
3513 "--")
3514 ;; add menu entries for defined projects
3515 (let ((project-alist vhdl-project-alist) menu-list name)
3516 (while project-alist
3517 (setq name (caar project-alist))
3518 (setq menu-list
3519 (cons `[,name (progn (customize-set-variable
3520 'vhdl-project ,name)
3521 (vhdl-set-project ,name))
3522 :style radio :selected (equal ,name vhdl-project)]
3523 menu-list))
3524 (setq project-alist (cdr project-alist)))
3525 (setq menu-list (nreverse menu-list))
3526 (vhdl-menu-split menu-list "Project")))
3527 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3528 ("Auto Load Setup File"
3529 ["At Startup"
3530 (customize-set-variable 'vhdl-project-auto-load
3531 (if (memq 'startup vhdl-project-auto-load)
3532 (delq 'startup vhdl-project-auto-load)
3533 (cons 'startup vhdl-project-auto-load)))
3534 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3535 ["Sort Projects"
3536 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3537 :style toggle :selected vhdl-project-sort]
3538 "--"
3539 ["Customize Group..." (customize-group 'vhdl-project) t])
3540 ("Compiler"
3541 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3542 ,(append
3543 '("Selected Compiler at Startup")
3544 ;; add menu entries for defined compilers
3545 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3546 (while comp-alist
3547 (setq name (caar comp-alist))
3548 (setq menu-list
3549 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3550 :style radio :selected (equal ,name vhdl-compiler)]
3551 menu-list))
3552 (setq comp-alist (cdr comp-alist)))
3553 (setq menu-list (nreverse menu-list))
3554 (vhdl-menu-split menu-list "Compler")))
3555 ["Use Local Error Regexp"
3556 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3557 (not vhdl-compile-use-local-error-regexp))
3558 :style toggle :selected vhdl-compile-use-local-error-regexp]
3559 ["Makefile Generation Hook..."
3560 (customize-option 'vhdl-makefile-generation-hook) t]
3561 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3562 "--"
3563 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3564 ("Style"
3565 ("VHDL Standard"
3566 ["VHDL'87"
3567 (progn (customize-set-variable 'vhdl-standard
3568 (list '87 (cadr vhdl-standard)))
3569 (vhdl-activate-customizations))
3570 :style radio :selected (eq '87 (car vhdl-standard))]
3571 ["VHDL'93"
3572 (progn (customize-set-variable 'vhdl-standard
3573 (list '93 (cadr vhdl-standard)))
3574 (vhdl-activate-customizations))
3575 :style radio :selected (eq '93 (car vhdl-standard))]
3576 "--"
3577 ["VHDL-AMS"
3578 (progn (customize-set-variable
3579 'vhdl-standard (list (car vhdl-standard)
3580 (if (memq 'ams (cadr vhdl-standard))
3581 (delq 'ams (cadr vhdl-standard))
3582 (cons 'ams (cadr vhdl-standard)))))
3583 (vhdl-activate-customizations))
3584 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3585 ["Math Packages"
3586 (progn (customize-set-variable
3587 'vhdl-standard (list (car vhdl-standard)
3588 (if (memq 'math (cadr vhdl-standard))
3589 (delq 'math (cadr vhdl-standard))
3590 (cons 'math (cadr vhdl-standard)))))
3591 (vhdl-activate-customizations))
3592 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3593 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3594 ["Upper Case Keywords"
3595 (customize-set-variable 'vhdl-upper-case-keywords
3596 (not vhdl-upper-case-keywords))
3597 :style toggle :selected vhdl-upper-case-keywords]
3598 ["Upper Case Types"
3599 (customize-set-variable 'vhdl-upper-case-types
3600 (not vhdl-upper-case-types))
3601 :style toggle :selected vhdl-upper-case-types]
3602 ["Upper Case Attributes"
3603 (customize-set-variable 'vhdl-upper-case-attributes
3604 (not vhdl-upper-case-attributes))
3605 :style toggle :selected vhdl-upper-case-attributes]
3606 ["Upper Case Enumeration Values"
3607 (customize-set-variable 'vhdl-upper-case-enum-values
3608 (not vhdl-upper-case-enum-values))
3609 :style toggle :selected vhdl-upper-case-enum-values]
3610 ["Upper Case Constants"
3611 (customize-set-variable 'vhdl-upper-case-constants
3612 (not vhdl-upper-case-constants))
3613 :style toggle :selected vhdl-upper-case-constants]
3614 ("Use Direct Instantiation"
3615 ["Never"
3616 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3617 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3618 ["Standard"
3619 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3620 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3621 ["Always"
3622 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3623 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3624 "--"
3625 ["Customize Group..." (customize-group 'vhdl-style) t])
3626 ("Naming"
3627 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3628 ["Architecture File Name..."
3629 (customize-option 'vhdl-architecture-file-name) t]
3630 ["Configuration File Name..."
3631 (customize-option 'vhdl-configuration-file-name) t]
3632 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3633 ("File Name Case"
3634 ["As Is"
3635 (customize-set-variable 'vhdl-file-name-case 'identity)
3636 :style radio :selected (eq 'identity vhdl-file-name-case)]
3637 ["Lower Case"
3638 (customize-set-variable 'vhdl-file-name-case 'downcase)
3639 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3640 ["Upper Case"
3641 (customize-set-variable 'vhdl-file-name-case 'upcase)
3642 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3643 ["Capitalize"
3644 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3645 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3646 "--"
3647 ["Customize Group..." (customize-group 'vhdl-naming) t])
3648 ("Template"
3649 ("Electric Keywords"
3650 ["VHDL Keywords"
3651 (customize-set-variable 'vhdl-electric-keywords
3652 (if (memq 'vhdl vhdl-electric-keywords)
3653 (delq 'vhdl vhdl-electric-keywords)
3654 (cons 'vhdl vhdl-electric-keywords)))
3655 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3656 ["User Model Keywords"
3657 (customize-set-variable 'vhdl-electric-keywords
3658 (if (memq 'user vhdl-electric-keywords)
3659 (delq 'user vhdl-electric-keywords)
3660 (cons 'user vhdl-electric-keywords)))
3661 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3662 ("Insert Optional Labels"
3663 ["None"
3664 (customize-set-variable 'vhdl-optional-labels 'none)
3665 :style radio :selected (eq 'none vhdl-optional-labels)]
3666 ["Processes Only"
3667 (customize-set-variable 'vhdl-optional-labels 'process)
3668 :style radio :selected (eq 'process vhdl-optional-labels)]
3669 ["All Constructs"
3670 (customize-set-variable 'vhdl-optional-labels 'all)
3671 :style radio :selected (eq 'all vhdl-optional-labels)])
3672 ("Insert Empty Lines"
3673 ["None"
3674 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3675 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3676 ["Design Units Only"
3677 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3678 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3679 ["All Constructs"
3680 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3681 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3682 ["Argument List Indent"
3683 (customize-set-variable 'vhdl-argument-list-indent
3684 (not vhdl-argument-list-indent))
3685 :style toggle :selected vhdl-argument-list-indent]
3686 ["Association List with Formals"
3687 (customize-set-variable 'vhdl-association-list-with-formals
3688 (not vhdl-association-list-with-formals))
3689 :style toggle :selected vhdl-association-list-with-formals]
3690 ["Conditions in Parenthesis"
3691 (customize-set-variable 'vhdl-conditions-in-parenthesis
3692 (not vhdl-conditions-in-parenthesis))
3693 :style toggle :selected vhdl-conditions-in-parenthesis]
3694 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3695 ["One String..." (customize-option 'vhdl-one-string) t]
3696 ("File Header"
3697 ["Header String..." (customize-option 'vhdl-file-header) t]
3698 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3699 ["Company Name..." (customize-option 'vhdl-company-name) t]
3700 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3701 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3702 ["Date Format..." (customize-option 'vhdl-date-format) t]
3703 ["Modify Date Prefix String..."
3704 (customize-option 'vhdl-modify-date-prefix-string) t]
3705 ["Modify Date on Saving"
3706 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3707 (not vhdl-modify-date-on-saving))
3708 (vhdl-activate-customizations))
3709 :style toggle :selected vhdl-modify-date-on-saving])
3710 ("Sequential Process"
3711 ("Kind of Reset"
3712 ["None"
3713 (customize-set-variable 'vhdl-reset-kind 'none)
3714 :style radio :selected (eq 'none vhdl-reset-kind)]
3715 ["Synchronous"
3716 (customize-set-variable 'vhdl-reset-kind 'sync)
3717 :style radio :selected (eq 'sync vhdl-reset-kind)]
3718 ["Asynchronous"
3719 (customize-set-variable 'vhdl-reset-kind 'async)
3720 :style radio :selected (eq 'async vhdl-reset-kind)])
3721 ["Reset is Active High"
3722 (customize-set-variable 'vhdl-reset-active-high
3723 (not vhdl-reset-active-high))
3724 :style toggle :selected vhdl-reset-active-high]
3725 ["Use Rising Clock Edge"
3726 (customize-set-variable 'vhdl-clock-rising-edge
3727 (not vhdl-clock-rising-edge))
3728 :style toggle :selected vhdl-clock-rising-edge]
3729 ("Clock Edge Condition"
3730 ["Standard"
3731 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3732 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3733 ["Function \"rising_edge\""
3734 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3735 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3736 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3737 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3738 "--"
3739 ["Customize Group..." (customize-group 'vhdl-template) t])
3740 ("Model"
3741 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3742 ("Port"
3743 ["Include Port Comments"
3744 (customize-set-variable 'vhdl-include-port-comments
3745 (not vhdl-include-port-comments))
3746 :style toggle :selected vhdl-include-port-comments]
3747 ["Include Direction Comments"
3748 (customize-set-variable 'vhdl-include-direction-comments
3749 (not vhdl-include-direction-comments))
3750 :style toggle :selected vhdl-include-direction-comments]
3751 ["Include Type Comments"
3752 (customize-set-variable 'vhdl-include-type-comments
3753 (not vhdl-include-type-comments))
3754 :style toggle :selected vhdl-include-type-comments]
3755 ("Include Group Comments"
3756 ["Never"
3757 (customize-set-variable 'vhdl-include-group-comments 'never)
3758 :style radio :selected (eq 'never vhdl-include-group-comments)]
3759 ["Declarations"
3760 (customize-set-variable 'vhdl-include-group-comments 'decl)
3761 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3762 ["Always"
3763 (customize-set-variable 'vhdl-include-group-comments 'always)
3764 :style radio :selected (eq 'always vhdl-include-group-comments)])
3765 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3766 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3767 ("Testbench"
3768 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3769 ["Architecture Name..."
3770 (customize-option 'vhdl-testbench-architecture-name) t]
3771 ["Configuration Name..."
3772 (customize-option 'vhdl-testbench-configuration-name) t]
3773 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3774 ["Include Header"
3775 (customize-set-variable 'vhdl-testbench-include-header
3776 (not vhdl-testbench-include-header))
3777 :style toggle :selected vhdl-testbench-include-header]
3778 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3779 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3780 ["Initialize Signals"
3781 (customize-set-variable 'vhdl-testbench-initialize-signals
3782 (not vhdl-testbench-initialize-signals))
3783 :style toggle :selected vhdl-testbench-initialize-signals]
3784 ["Include Library Clause"
3785 (customize-set-variable 'vhdl-testbench-include-library
3786 (not vhdl-testbench-include-library))
3787 :style toggle :selected vhdl-testbench-include-library]
3788 ["Include Configuration"
3789 (customize-set-variable 'vhdl-testbench-include-configuration
3790 (not vhdl-testbench-include-configuration))
3791 :style toggle :selected vhdl-testbench-include-configuration]
3792 ("Create Files"
3793 ["None"
3794 (customize-set-variable 'vhdl-testbench-create-files 'none)
3795 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3796 ["Single"
3797 (customize-set-variable 'vhdl-testbench-create-files 'single)
3798 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3799 ["Separate"
3800 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3801 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3802 ["Testbench Entity File Name..."
3803 (customize-option 'vhdl-testbench-entity-file-name) t]
3804 ["Testbench Architecture File Name..."
3805 (customize-option 'vhdl-testbench-architecture-file-name) t])
3806 "--"
3807 ["Customize Group..." (customize-group 'vhdl-port) t])
3808 ("Compose"
3809 ["Architecture Name..."
3810 (customize-option 'vhdl-compose-architecture-name) t]
3811 ["Configuration Name..."
3812 (customize-option 'vhdl-compose-configuration-name) t]
3813 ["Components Package Name..."
3814 (customize-option 'vhdl-components-package-name) t]
3815 ["Use Components Package"
3816 (customize-set-variable 'vhdl-use-components-package
3817 (not vhdl-use-components-package))
3818 :style toggle :selected vhdl-use-components-package]
3819 ["Include Header"
3820 (customize-set-variable 'vhdl-compose-include-header
3821 (not vhdl-compose-include-header))
3822 :style toggle :selected vhdl-compose-include-header]
3823 ("Create Entity/Architecture Files"
3824 ["None"
3825 (customize-set-variable 'vhdl-compose-create-files 'none)
3826 :style radio :selected (eq 'none vhdl-compose-create-files)]
3827 ["Single"
3828 (customize-set-variable 'vhdl-compose-create-files 'single)
3829 :style radio :selected (eq 'single vhdl-compose-create-files)]
3830 ["Separate"
3831 (customize-set-variable 'vhdl-compose-create-files 'separate)
3832 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3833 ["Create Configuration File"
3834 (customize-set-variable 'vhdl-compose-configuration-create-file
3835 (not vhdl-compose-configuration-create-file))
3836 :style toggle :selected vhdl-compose-configuration-create-file]
3837 ["Hierarchical Configuration"
3838 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3839 (not vhdl-compose-configuration-hierarchical))
3840 :style toggle :selected vhdl-compose-configuration-hierarchical]
3841 ["Use Subconfiguration"
3842 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3843 (not vhdl-compose-configuration-use-subconfiguration))
3844 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3845 "--"
3846 ["Customize Group..." (customize-group 'vhdl-compose) t])
3847 ("Comment"
3848 ["Self Insert Comments"
3849 (customize-set-variable 'vhdl-self-insert-comments
3850 (not vhdl-self-insert-comments))
3851 :style toggle :selected vhdl-self-insert-comments]
3852 ["Prompt for Comments"
3853 (customize-set-variable 'vhdl-prompt-for-comments
3854 (not vhdl-prompt-for-comments))
3855 :style toggle :selected vhdl-prompt-for-comments]
3856 ["Inline Comment Column..."
3857 (customize-option 'vhdl-inline-comment-column) t]
3858 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3859 "--"
3860 ["Customize Group..." (customize-group 'vhdl-comment) t])
3861 ("Align"
3862 ["Auto Align Templates"
3863 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3864 :style toggle :selected vhdl-auto-align]
3865 ["Align Line Groups"
3866 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3867 :style toggle :selected vhdl-align-groups]
3868 ["Group Separation String..."
3869 (customize-set-variable 'vhdl-align-group-separate) t]
3870 ["Align Lines with Same Indent"
3871 (customize-set-variable 'vhdl-align-same-indent
3872 (not vhdl-align-same-indent))
3873 :style toggle :selected vhdl-align-same-indent]
3874 "--"
3875 ["Customize Group..." (customize-group 'vhdl-align) t])
3876 ("Highlight"
3877 ["Highlighting On/Off..."
3878 (customize-option
3879 (if (fboundp 'global-font-lock-mode)
3880 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3881 ["Highlight Keywords"
3882 (progn (customize-set-variable 'vhdl-highlight-keywords
3883 (not vhdl-highlight-keywords))
3884 (vhdl-fontify-buffer))
3885 :style toggle :selected vhdl-highlight-keywords]
3886 ["Highlight Names"
3887 (progn (customize-set-variable 'vhdl-highlight-names
3888 (not vhdl-highlight-names))
3889 (vhdl-fontify-buffer))
3890 :style toggle :selected vhdl-highlight-names]
3891 ["Highlight Special Words"
3892 (progn (customize-set-variable 'vhdl-highlight-special-words
3893 (not vhdl-highlight-special-words))
3894 (vhdl-fontify-buffer))
3895 :style toggle :selected vhdl-highlight-special-words]
3896 ["Highlight Forbidden Words"
3897 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3898 (not vhdl-highlight-forbidden-words))
3899 (vhdl-fontify-buffer))
3900 :style toggle :selected vhdl-highlight-forbidden-words]
3901 ["Highlight Verilog Keywords"
3902 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3903 (not vhdl-highlight-verilog-keywords))
3904 (vhdl-fontify-buffer))
3905 :style toggle :selected vhdl-highlight-verilog-keywords]
3906 ["Highlight \"translate_off\""
3907 (progn (customize-set-variable 'vhdl-highlight-translate-off
3908 (not vhdl-highlight-translate-off))
3909 (vhdl-fontify-buffer))
3910 :style toggle :selected vhdl-highlight-translate-off]
3911 ["Case Sensitive Highlighting"
3912 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3913 (not vhdl-highlight-case-sensitive))
3914 (vhdl-fontify-buffer))
3915 :style toggle :selected vhdl-highlight-case-sensitive]
3916 ["Special Syntax Definition..."
3917 (customize-option 'vhdl-special-syntax-alist) t]
3918 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3919 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3920 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3921 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3922 "--"
3923 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3924 ("Speedbar"
3925 ["Auto Open at Startup"
3926 (customize-set-variable 'vhdl-speedbar-auto-open
3927 (not vhdl-speedbar-auto-open))
3928 :style toggle :selected vhdl-speedbar-auto-open]
3929 ("Default Displaying Mode"
3930 ["Files"
3931 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3932 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3933 ["Directory Hierarchy"
3934 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3935 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3936 ["Project Hierarchy"
3937 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3938 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3939 ["Indentation Offset..."
3940 (customize-option 'speedbar-indentation-width) t]
3941 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3942 ["Jump to Unit when Opening"
3943 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3944 (not vhdl-speedbar-jump-to-unit))
3945 :style toggle :selected vhdl-speedbar-jump-to-unit]
3946 ["Update Hierarchy on File Saving"
3947 (customize-set-variable 'vhdl-speedbar-update-on-saving
3948 (not vhdl-speedbar-update-on-saving))
3949 :style toggle :selected vhdl-speedbar-update-on-saving]
3950 ("Save in Cache File"
3951 ["Hierarchy Information"
3952 (customize-set-variable 'vhdl-speedbar-save-cache
3953 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3954 (delq 'hierarchy vhdl-speedbar-save-cache)
3955 (cons 'hierarchy vhdl-speedbar-save-cache)))
3956 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3957 ["Displaying Status"
3958 (customize-set-variable 'vhdl-speedbar-save-cache
3959 (if (memq 'display vhdl-speedbar-save-cache)
3960 (delq 'display vhdl-speedbar-save-cache)
3961 (cons 'display vhdl-speedbar-save-cache)))
3962 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3963 ["Cache File Name..."
3964 (customize-option 'vhdl-speedbar-cache-file-name) t]
3965 "--"
3966 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3967 ("Menu"
3968 ["Add Index Menu when Loading File"
3969 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3970 (vhdl-index-menu-init))
3971 :style toggle :selected vhdl-index-menu]
3972 ["Add Source File Menu when Loading File"
3973 (progn (customize-set-variable 'vhdl-source-file-menu
3974 (not vhdl-source-file-menu))
3975 (vhdl-add-source-files-menu))
3976 :style toggle :selected vhdl-source-file-menu]
3977 ["Add Hideshow Menu at Startup"
3978 (progn (customize-set-variable 'vhdl-hideshow-menu
3979 (not vhdl-hideshow-menu))
3980 (vhdl-activate-customizations))
3981 :style toggle :selected vhdl-hideshow-menu]
3982 ["Hide Everything Initially"
3983 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3984 :style toggle :selected vhdl-hide-all-init]
3985 "--"
3986 ["Customize Group..." (customize-group 'vhdl-menu) t])
3987 ("Print"
3988 ["In Two Column Format"
3989 (progn (customize-set-variable 'vhdl-print-two-column
3990 (not vhdl-print-two-column))
3991 (message "Activate new setting by saving options and restarting Emacs"))
3992 :style toggle :selected vhdl-print-two-column]
3993 ["Use Customized Faces"
3994 (progn (customize-set-variable 'vhdl-print-customize-faces
3995 (not vhdl-print-customize-faces))
3996 (message "Activate new setting by saving options and restarting Emacs"))
3997 :style toggle :selected vhdl-print-customize-faces]
3998 "--"
3999 ["Customize Group..." (customize-group 'vhdl-print) t])
4000 ("Miscellaneous"
4001 ["Use Intelligent Tab"
4002 (progn (customize-set-variable 'vhdl-intelligent-tab
4003 (not vhdl-intelligent-tab))
4004 (vhdl-activate-customizations))
4005 :style toggle :selected vhdl-intelligent-tab]
4006 ["Indent Syntax-Based"
4007 (customize-set-variable 'vhdl-indent-syntax-based
4008 (not vhdl-indent-syntax-based))
4009 :style toggle :selected vhdl-indent-syntax-based]
4010 ["Word Completion is Case Sensitive"
4011 (customize-set-variable 'vhdl-word-completion-case-sensitive
4012 (not vhdl-word-completion-case-sensitive))
4013 :style toggle :selected vhdl-word-completion-case-sensitive]
4014 ["Word Completion in Minibuffer"
4015 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4016 (not vhdl-word-completion-in-minibuffer))
4017 (message "Activate new setting by saving options and restarting Emacs"))
4018 :style toggle :selected vhdl-word-completion-in-minibuffer]
4019 ["Underscore is Part of Word"
4020 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4021 (not vhdl-underscore-is-part-of-word))
4022 (vhdl-activate-customizations))
4023 :style toggle :selected vhdl-underscore-is-part-of-word]
4024 "--"
4025 ["Customize Group..." (customize-group 'vhdl-misc) t])
4026 ["Related..." (customize-browse 'vhdl-related) t]
4027 "--"
4028 ["Save Options" customize-save-customized t]
4029 ["Activate Options" vhdl-activate-customizations t]
4030 ["Browse Options..." vhdl-customize t])))
4031
4032 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4033 "VHDL Mode menu.")
4034
4035 (defun vhdl-update-mode-menu ()
4036 "Update VHDL Mode menu."
4037 (interactive)
4038 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4039 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4040 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4041 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4042 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4043
4044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4045 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4046
4047 (defconst vhdl-imenu-generic-expression
4048 '(
4049 ("Subprogram"
4050 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4051 4)
4052 ("Instance"
4053 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4054 1)
4055 ("Component"
4056 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4057 2)
4058 ("Procedural"
4059 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4060 1)
4061 ("Process"
4062 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4063 1)
4064 ("Block"
4065 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4066 1)
4067 ("Package"
4068 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4069 3)
4070 ("Configuration"
4071 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4072 2)
4073 ("Architecture"
4074 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4075 2)
4076 ("Entity"
4077 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4078 2)
4079 )
4080 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4081
4082 (defun vhdl-index-menu-init ()
4083 "Initialize index menu."
4084 (set (make-local-variable 'imenu-case-fold-search) t)
4085 (set (make-local-variable 'imenu-generic-expression)
4086 vhdl-imenu-generic-expression)
4087 (when (and vhdl-index-menu (fboundp 'imenu))
4088 (if (or (not (boundp 'font-lock-maximum-size))
4089 (> font-lock-maximum-size (buffer-size)))
4090 (imenu-add-to-menubar "Index")
4091 (message "Scanning buffer for index...buffer too big"))))
4092
4093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4094 ;; Source file menu (using `easy-menu.el')
4095
4096 (defvar vhdl-sources-menu nil)
4097
4098 (defun vhdl-directory-files (directory &optional full match)
4099 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4100 message."
4101 (if (not (file-directory-p directory))
4102 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4103 (let ((dir (directory-files directory full match)))
4104 (setq dir (delete "." dir))
4105 (setq dir (delete ".." dir))
4106 dir)))
4107
4108 (defun vhdl-get-source-files (&optional full directory)
4109 "Get list of VHDL source files in DIRECTORY or current directory."
4110 (let ((mode-alist auto-mode-alist)
4111 filename-regexp)
4112 ;; create regular expressions for matching file names
4113 (setq filename-regexp "\\`[^.].*\\(")
4114 (while mode-alist
4115 (when (eq (cdar mode-alist) 'vhdl-mode)
4116 (setq filename-regexp
4117 (concat filename-regexp (caar mode-alist) "\\|")))
4118 (setq mode-alist (cdr mode-alist)))
4119 (setq filename-regexp
4120 (concat (substring filename-regexp 0
4121 (string-match "\\\\|$" filename-regexp)) "\\)"))
4122 ;; find files
4123 (vhdl-directory-files
4124 (or directory default-directory) full filename-regexp)))
4125
4126 (defun vhdl-add-source-files-menu ()
4127 "Scan directory for all VHDL source files and generate menu.
4128 The directory of the current source file is scanned."
4129 (interactive)
4130 (message "Scanning directory for source files ...")
4131 (let ((newmap (current-local-map))
4132 (file-list (vhdl-get-source-files))
4133 menu-list found)
4134 ;; Create list for menu
4135 (setq found nil)
4136 (while file-list
4137 (setq found t)
4138 (setq menu-list (cons (vector (car file-list)
4139 (list 'find-file (car file-list)) t)
4140 menu-list))
4141 (setq file-list (cdr file-list)))
4142 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4143 (when found (setq menu-list (cons "--" menu-list)))
4144 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4145 (setq menu-list (cons "Sources" menu-list))
4146 ;; Create menu
4147 (easy-menu-add menu-list)
4148 (easy-menu-define vhdl-sources-menu newmap
4149 "VHDL source files menu" menu-list))
4150 (message ""))
4151
4152
4153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4154 ;;; Mode definition
4155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4156 ;; performs all buffer local initializations
4157
4158 ;;;###autoload
4159 (defun vhdl-mode ()
4160 "Major mode for editing VHDL code.
4161
4162 Usage:
4163 ------
4164
4165 TEMPLATE INSERTION (electrification):
4166 After typing a VHDL keyword and entering `SPC', you are prompted for
4167 arguments while a template is generated for that VHDL construct. Typing
4168 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4169 template generation. Optional arguments are indicated by square
4170 brackets and removed if the queried string is left empty. Prompts for
4171 mandatory arguments remain in the code if the queried string is left
4172 empty. They can be queried again by `C-c C-t C-q'. Enabled
4173 electrification is indicated by `/e' in the modeline.
4174
4175 Typing `M-SPC' after a keyword inserts a space without calling the
4176 template generator. Automatic template generation (i.e.
4177 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4178 setting option `vhdl-electric-mode' (see OPTIONS).
4179
4180 Template generators can be invoked from the VHDL menu, by key
4181 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4182 the keyword (i.e. first word of menu entry not in parenthesis) and
4183 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4184 conf, comp, cons, func, inst, pack, sig, var.
4185
4186 Template styles can be customized in customization group
4187 `vhdl-template' \(see OPTIONS).
4188
4189
4190 HEADER INSERTION:
4191 A file header can be inserted by `C-c C-t C-h'. A file footer
4192 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4193 See customization group `vhdl-header'.
4194
4195
4196 STUTTERING:
4197 Double striking of some keys inserts cumbersome VHDL syntax elements.
4198 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4199 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4200 the modeline. The stuttering keys and their effects are:
4201
4202 ;; --> \" : \" [ --> ( -- --> comment
4203 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4204 .. --> \" => \" ] --> ) --- --> horizontal line
4205 ,, --> \" <= \" ]] --> ] ---- --> display comment
4206 == --> \" == \" '' --> \\\"
4207
4208
4209 WORD COMPLETION:
4210 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4211 word in the buffer that starts alike, inserts it and adjusts case.
4212 Re-typing `TAB' toggles through alternative word completions. This also
4213 works in the minibuffer (i.e. in template generator prompts).
4214
4215 Typing `TAB' after `(' looks for and inserts complete parenthesized
4216 expressions (e.g. for array index ranges). All keywords as well as
4217 standard types and subprograms of VHDL have predefined abbreviations
4218 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4219 beginning with \"std\").
4220
4221 Typing `TAB' after a non-word character indents the line if at the
4222 beginning of a line (i.e. no preceding non-blank characters), and
4223 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4224 stop.
4225
4226
4227 COMMENTS:
4228 `--' puts a single comment.
4229 `---' draws a horizontal line for separating code segments.
4230 `----' inserts a display comment, i.e. two horizontal lines
4231 with a comment in between.
4232 `--CR' comments out code on that line. Re-hitting CR comments
4233 out following lines.
4234 `C-c c' comments out a region if not commented out,
4235 uncomments a region if already commented out.
4236
4237 You are prompted for comments after object definitions (i.e. signals,
4238 variables, constants, ports) and after subprogram and process
4239 specifications if option `vhdl-prompt-for-comments' is non-nil.
4240 Comments are automatically inserted as additional labels (e.g. after
4241 begin statements) and as help comments if `vhdl-self-insert-comments' is
4242 non-nil.
4243
4244 Inline comments (i.e. comments after a piece of code on the same line)
4245 are indented at least to `vhdl-inline-comment-column'. Comments go at
4246 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4247 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4248 in a comment automatically opens a new comment line. `M-q' re-fills
4249 multi-line comments.
4250
4251
4252 INDENTATION:
4253 `TAB' indents a line if at the beginning of the line. The amount of
4254 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4255 always indents the current line (is bound to `TAB' if option
4256 `vhdl-intelligent-tab' is nil).
4257
4258 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4259 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4260 indented normally (nil) or relative to the opening parenthesis (non-nil)
4261 according to option `vhdl-argument-list-indent'.
4262
4263 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4264 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4265 and vice versa.
4266
4267 Syntax-based indentation can be very slow in large files. Option
4268 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4269
4270
4271 ALIGNMENT:
4272 The alignment functions align operators, keywords, and inline comments
4273 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4274 separated by blank lines, `C-c C-a C-i' a block of lines with same
4275 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4276 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4277 C-a C-d' all lines within the declarative part of a design unit. `C-c
4278 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4279 for a group of lines, and `C-c C-a M-c' for a region.
4280
4281 If option `vhdl-align-groups' is non-nil, groups of code lines
4282 separated by special lines (see option `vhdl-align-group-separate') are
4283 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4284 blocks of lines with same indent are aligned separately. Some templates
4285 are automatically aligned after generation if option `vhdl-auto-align'
4286 is non-nil.
4287
4288 Alignment tries to align inline comments at
4289 `vhdl-inline-comment-column' and tries inline comment not to exceed
4290 `vhdl-end-comment-column'.
4291
4292 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4293 symbols are surrounded by one space, and multiple spaces are eliminated.
4294
4295
4296 CODE FILLING:
4297 Code filling allows to condense code (e.g. sensitivity lists or port
4298 maps) by removing comments and newlines and re-wrapping so that all
4299 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4300 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4301 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4302 `C-c C-f M-f' an entire region.
4303
4304
4305 CODE BEAUTIFICATION:
4306 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4307 buffer respectively. This inludes indentation, alignment, and case
4308 fixing. Code beautification can also be run non-interactively using the
4309 command:
4310
4311 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4312
4313
4314 PORT TRANSLATION:
4315 Generic and port clauses from entity or component declarations can be
4316 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4317 as component instantiations and corresponding internal constants and
4318 signals, as a generic map with constants as actual generics, and as
4319 internal signal initializations (menu).
4320
4321 To include formals in component instantiations, see option
4322 `vhdl-association-list-with-formals'. To include comments in pasting,
4323 see options `vhdl-include-...-comments'.
4324
4325 A clause with several generic/port names on the same line can be
4326 flattened (`C-c C-p C-f') so that only one name per line exists. The
4327 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4328 outputs and vice versa, which can be useful in testbenches. (This
4329 reversion is done on the internal data structure and is only reflected
4330 in subsequent paste operations.)
4331
4332 Names for actual ports, instances, testbenches, and
4333 design-under-test instances can be derived from existing names according
4334 to options `vhdl-...-name'. See customization group `vhdl-port'.
4335
4336
4337 SUBPROGRAM TRANSLATION:
4338 Similar functionality exists for copying/pasting the interface of
4339 subprograms (function/procedure). A subprogram interface can be copied
4340 and then pasted as a subprogram declaration, body or call (uses
4341 association list with formals).
4342
4343
4344 TESTBENCH GENERATION:
4345 A copied port can also be pasted as a testbench. The generated
4346 testbench includes an entity, an architecture, and an optional
4347 configuration. The architecture contains the component declaration and
4348 instantiation of the DUT as well as internal constant and signal
4349 declarations. Additional user-defined templates can be inserted. The
4350 names used for entity/architecture/configuration/DUT as well as the file
4351 structure to be generated can be customized. See customization group
4352 `vhdl-testbench'.
4353
4354
4355 KEY BINDINGS:
4356 Key bindings (`C-c ...') exist for most commands (see in menu).
4357
4358
4359 VHDL MENU:
4360 All commands can be found in the VHDL menu including their key bindings.
4361
4362
4363 FILE BROWSER:
4364 The speedbar allows browsing of directories and file contents. It can
4365 be accessed from the VHDL menu and is automatically opened if option
4366 `vhdl-speedbar-auto-open' is non-nil.
4367
4368 In speedbar, open files and directories with `mouse-2' on the name and
4369 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4370
4371
4372 DESIGN HIERARCHY BROWSER:
4373 The speedbar can also be used for browsing the hierarchy of design units
4374 contained in the source files of the current directory or the specified
4375 projects (see option `vhdl-project-alist').
4376
4377 The speedbar can be switched between file, directory hierarchy and
4378 project hierarchy browsing mode in the speedbar menu or by typing `f',
4379 `h' or `H' in speedbar.
4380
4381 In speedbar, open design units with `mouse-2' on the name and browse
4382 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4383 from entities and components (in packages). Individual design units and
4384 complete designs can directly be compiled (\"Make\" menu entry).
4385
4386 The hierarchy is automatically updated upon saving a modified source
4387 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4388 hierarchy is only updated for projects that have been opened once in the
4389 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4390 options in group `vhdl-speedbar').
4391
4392 Simple design consistency checks are done during scanning, such as
4393 multiple declarations of the same unit or missing primary units that are
4394 required by secondary units.
4395
4396
4397 STRUCTURAL COMPOSITION:
4398 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4399 for a new component. Subcomponents (i.e. component declaration and
4400 instantiation) can be automatically placed from a previously read port
4401 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4402 all subcomponents can be automatically connected using internal signals
4403 and ports (`C-c C-c C-w') following these rules:
4404 - subcomponent actual ports with same name are considered to be
4405 connected by a signal (internal signal or port)
4406 - signals that are only inputs to subcomponents are considered as
4407 inputs to this component -> input port created
4408 - signals that are only outputs from subcomponents are considered as
4409 outputs from this component -> output port created
4410 - signals that are inputs to AND outputs from subcomponents are
4411 considered as internal connections -> internal signal created
4412
4413 Purpose: With appropriate naming conventions it is possible to
4414 create higher design levels with only a few mouse clicks or key
4415 strokes. A new design level can be created by simply generating a new
4416 component, placing the required subcomponents from the hierarchy
4417 browser, and wiring everything automatically.
4418
4419 Note: Automatic wiring only works reliably on templates of new
4420 components and component instantiations that were created by VHDL mode.
4421
4422 Component declarations can be placed in a components package (option
4423 `vhdl-use-components-package') which can be automatically generated for
4424 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4425 component instantiation is also supported (option
4426 `vhdl-use-direct-instantiation').
4427
4428 | Configuration declarations can automatically be generated either from
4429 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4430 | the speedbar menu (for the architecture under the cursor). The
4431 | configurations can optionally be hierarchical (i.e. include all
4432 | component levels of a hierarchical design, option
4433 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4434 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4435 | subcomponents in hierarchical configurations, the most-recently-analyzed
4436 | (mra) architecture is selected. If another architecture is desired, it
4437 | can be marked as most-recently-analyzed (speedbar menu) before
4438 | generating the configuration.
4439 |
4440 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4441 | declarations) are currently not considered when displaying
4442 | configurations in speedbar.
4443
4444 See the options group `vhdl-compose' for all relevant user options.
4445
4446
4447 SOURCE FILE COMPILATION:
4448 The syntax of the current buffer can be analyzed by calling a VHDL
4449 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4450 option `vhdl-compiler'. The available compilers are listed in option
4451 `vhdl-compiler-alist' including all required compilation command,
4452 command options, compilation directory, and error message syntax
4453 information. New compilers can be added.
4454
4455 All the source files of an entire design can be compiled by the `make'
4456 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4457
4458
4459 MAKEFILE GENERATION:
4460 Makefiles can be generated automatically by an internal generation
4461 routine (`C-c M-k'). The library unit dependency information is
4462 obtained from the hierarchy browser. Makefile generation can be
4463 customized for each compiler in option `vhdl-compiler-alist'.
4464
4465 Makefile generation can also be run non-interactively using the
4466 command:
4467
4468 emacs -batch -l ~/.emacs -l vhdl-mode
4469 [-compiler compilername] [-project projectname]
4470 -f vhdl-generate-makefile
4471
4472 The Makefile's default target \"all\" compiles the entire design, the
4473 target \"clean\" removes it and the target \"library\" creates the
4474 library directory if not existent. The Makefile also includes a target
4475 for each primary library unit which allows selective compilation of this
4476 unit, its secondary units and its subhierarchy (example: compilation of
4477 a design specified by a configuration). User specific parts can be
4478 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4479
4480 Limitations:
4481 - Only library units and dependencies within the current library are
4482 considered. Makefiles for designs that span multiple libraries are
4483 not (yet) supported.
4484 - Only one-level configurations are supported (also hierarchical),
4485 but configurations that go down several levels are not.
4486 - The \"others\" keyword in configurations is not supported.
4487
4488
4489 PROJECTS:
4490 Projects can be defined in option `vhdl-project-alist' and a current
4491 project be selected using option `vhdl-project' (permanently) or from
4492 the menu or speedbar (temporarily). For each project, title and
4493 description strings (for the file headers), source files/directories
4494 (for the hierarchy browser and Makefile generation), library name, and
4495 compiler-dependent options, exceptions and compilation directory can be
4496 specified. Compilation settings overwrite the settings of option
4497 `vhdl-compiler-alist'.
4498
4499 Project setups can be exported (i.e. written to a file) and imported.
4500 Imported setups are not automatically saved in `vhdl-project-alist' but
4501 can be saved afterwards in its customization buffer. When starting
4502 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4503 vhdl-mode\") in a directory with an existing project setup file, it is
4504 automatically loaded and its project activated if option
4505 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4506 files can be specified in option `vhdl-project-file-name'. Multiple
4507 project setups can be automatically loaded from global directories.
4508 This is an alternative to specifying project setups with option
4509 `vhdl-project-alist'.
4510
4511
4512 SPECIAL MENUES:
4513 As an alternative to the speedbar, an index menu can be added (set
4514 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4515 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4516 file) for browsing the file contents (is not populated if buffer is
4517 larger than `font-lock-maximum-size'). Also, a source file menu can be
4518 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4519 current directory for VHDL source files.
4520
4521
4522 VHDL STANDARDS:
4523 The VHDL standards to be used are specified in option `vhdl-standard'.
4524 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4525
4526
4527 KEYWORD CASE:
4528 Lower and upper case for keywords and standardized types, attributes,
4529 and enumeration values is supported. If the option
4530 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4531 lower case and are converted into upper case automatically (not for
4532 types, attributes, and enumeration values). The case of keywords,
4533 types, attributes,and enumeration values can be fixed for an entire
4534 region (menu) or buffer (`C-c C-x C-c') according to the options
4535 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4536
4537
4538 HIGHLIGHTING (fontification):
4539 Keywords and standardized types, attributes, enumeration values, and
4540 function names (controlled by option `vhdl-highlight-keywords'), as well
4541 as comments, strings, and template prompts are highlighted using
4542 different colors. Unit, subprogram, signal, variable, constant,
4543 parameter and generic/port names in declarations as well as labels are
4544 highlighted if option `vhdl-highlight-names' is non-nil.
4545
4546 Additional reserved words or words with a forbidden syntax (e.g. words
4547 that should be avoided) can be specified in option
4548 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4549 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4550 keywords are highlighted as forbidden words if option
4551 `vhdl-highlight-verilog-keywords' is non-nil.
4552
4553 Words with special syntax can be highlighted by specifying their
4554 syntax and color in option `vhdl-special-syntax-alist' and by setting
4555 option `vhdl-highlight-special-words' to non-nil. This allows to
4556 establish some naming conventions (e.g. to distinguish different kinds
4557 of signals or other objects by using name suffices) and to support them
4558 visually.
4559
4560 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4561 to support case-sensitive highlighting. However, keywords are then only
4562 highlighted if written in lower case.
4563
4564 Code between \"translate_off\" and \"translate_on\" pragmas is
4565 highlighted using a different background color if option
4566 `vhdl-highlight-translate-off' is non-nil.
4567
4568 For documentation and customization of the used colors see
4569 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4570 highlighting of matching parenthesis, see customization group
4571 `paren-showing'. Automatic buffer highlighting is turned on/off by
4572 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4573
4574
4575 USER MODELS:
4576 VHDL models (templates) can be specified by the user and made accessible
4577 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4578 electrification. See option `vhdl-model-alist'.
4579
4580
4581 HIDE/SHOW:
4582 The code of blocks, processes, subprograms, component declarations and
4583 instantiations, generic/port clauses, and configuration declarations can
4584 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4585 the code (see customization group `vhdl-menu'). XEmacs: limited
4586 functionality due to old `hideshow.el' package.
4587
4588
4589 CODE UPDATING:
4590 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4591 current process, `C-c C-u M-s' of all processes in the current buffer.
4592 Limitations:
4593 - Only declared local signals (ports, signals declared in
4594 architecture and blocks) are automatically inserted.
4595 - Global signals declared in packages are not automatically inserted.
4596 Insert them once manually (will be kept afterwards).
4597 - Out parameters of procedures are considered to be read.
4598 Use option `vhdl-entity-file-name' to specify the entity file name
4599 \(used to obtain the port names).
4600
4601
4602 CODE FIXING:
4603 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4604 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4605
4606
4607 PRINTING:
4608 Postscript printing with different faces (an optimized set of faces is
4609 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4610 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4611 postscript printing commands. Option `vhdl-print-two-column' defines
4612 appropriate default settings for nice landscape two-column printing.
4613 The paper format can be set by option `ps-paper-type'. Do not forget to
4614 switch `ps-print-color-p' to nil for printing on black-and-white
4615 printers.
4616
4617
4618 OPTIONS:
4619 User options allow customization of VHDL Mode. All options are
4620 accessible from the \"Options\" menu entry. Simple options (switches
4621 and choices) can directly be changed, while for complex options a
4622 customization buffer is opened. Changed options can be saved for future
4623 sessions using the \"Save Options\" menu entry.
4624
4625 Options and their detailed descriptions can also be accessed by using
4626 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4627 customize-group' for groups). Some customizations only take effect
4628 after some action (read the NOTE in the option documentation).
4629 Customization can also be done globally (i.e. site-wide, read the
4630 INSTALL file).
4631
4632 Not all options are described in this documentation, so go and see
4633 what other useful user options there are (`M-x vhdl-customize' or menu)!
4634
4635
4636 FILE EXTENSIONS:
4637 As default, files with extensions \".vhd\" and \".vhdl\" are
4638 automatically recognized as VHDL source files. To add an extension
4639 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4640
4641 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4642
4643
4644 HINTS:
4645 - To start Emacs with open VHDL hierarchy browser without having to load
4646 a VHDL file first, use the command:
4647
4648 emacs -l vhdl-mode -f speedbar-frame-mode
4649
4650 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4651
4652 - Some features only work on properly indented code.
4653
4654
4655 RELEASE NOTES:
4656 See also the release notes (menu) for added features in new releases.
4657
4658
4659 Maintenance:
4660 ------------
4661
4662 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4663 Add a description of the problem and include a reproducible test case.
4664
4665 Questions and enhancement requests can be sent to <reto@gnu.org>.
4666
4667 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4668 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4669 releases. You are kindly invited to participate in beta testing. Subscribe
4670 to above mailing lists by sending an email to <reto@gnu.org>.
4671
4672 VHDL Mode is officially distributed at
4673 http://opensource.ethz.ch/emacs/vhdl-mode.html
4674 where the latest version can be found.
4675
4676
4677 Known problems:
4678 ---------------
4679
4680 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4681 - XEmacs: Incorrect start-up when automatically opening speedbar.
4682 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4683
4684
4685 The VHDL Mode Authors
4686 Reto Zimmermann and Rod Whitby
4687
4688 Key bindings:
4689 -------------
4690
4691 \\{vhdl-mode-map}"
4692 (interactive)
4693 (kill-all-local-variables)
4694 (setq major-mode 'vhdl-mode)
4695 (setq mode-name "VHDL")
4696
4697 ;; set maps and tables
4698 (use-local-map vhdl-mode-map)
4699 (set-syntax-table vhdl-mode-syntax-table)
4700 (setq local-abbrev-table vhdl-mode-abbrev-table)
4701
4702 ;; set local variables
4703 (set (make-local-variable 'paragraph-start)
4704 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4705 (set (make-local-variable 'paragraph-separate) paragraph-start)
4706 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4707 (set (make-local-variable 'require-final-newline)
4708 (if vhdl-emacs-22 mode-require-final-newline t))
4709 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4710 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4711 (set (make-local-variable 'comment-start) "--")
4712 (set (make-local-variable 'comment-end) "")
4713 (when vhdl-emacs-21
4714 (set (make-local-variable 'comment-padding) ""))
4715 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4716 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4717 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4718 (set (make-local-variable 'comment-multi-line) nil)
4719 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4720 (set (make-local-variable 'hippie-expand-verbose) nil)
4721
4722 ;; setup the comment indent variable in a Emacs version portable way
4723 ;; ignore any byte compiler warnings you might get here
4724 (when (boundp 'comment-indent-function)
4725 (make-local-variable 'comment-indent-function)
4726 (setq comment-indent-function 'vhdl-comment-indent))
4727
4728 ;; initialize font locking
4729 (set (make-local-variable 'font-lock-defaults)
4730 (list
4731 '(nil vhdl-font-lock-keywords) nil
4732 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4733 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4734 (unless vhdl-emacs-21
4735 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4736 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4737 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4738 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4739 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4740 ; (turn-on-font-lock)
4741
4742 ;; variables for source file compilation
4743 (when vhdl-compile-use-local-error-regexp
4744 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4745 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4746
4747 ;; add index menu
4748 (vhdl-index-menu-init)
4749 ;; add source file menu
4750 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4751 ;; add VHDL menu
4752 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4753 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4754 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4755 ;; initialize hideshow and add menu
4756 (vhdl-hideshow-init)
4757 (run-hooks 'menu-bar-update-hook)
4758
4759 ;; miscellaneous
4760 (vhdl-ps-print-init)
4761 (vhdl-write-file-hooks-init)
4762 (vhdl-mode-line-update)
4763 (message "VHDL Mode %s.%s" vhdl-version
4764 (if noninteractive "" " See menu for documentation and release notes."))
4765
4766 ;; run hooks
4767 (if vhdl-emacs-22
4768 (run-mode-hooks 'vhdl-mode-hook)
4769 (run-hooks 'vhdl-mode-hook)))
4770
4771 (defun vhdl-activate-customizations ()
4772 "Activate all customizations on local variables."
4773 (interactive)
4774 (vhdl-mode-map-init)
4775 (use-local-map vhdl-mode-map)
4776 (set-syntax-table vhdl-mode-syntax-table)
4777 (setq comment-column vhdl-inline-comment-column)
4778 (setq end-comment-column vhdl-end-comment-column)
4779 (vhdl-write-file-hooks-init)
4780 (vhdl-update-mode-menu)
4781 (vhdl-hideshow-init)
4782 (run-hooks 'menu-bar-update-hook)
4783 (vhdl-mode-line-update))
4784
4785 (defun vhdl-write-file-hooks-init ()
4786 "Add/remove hooks when buffer is saved."
4787 (if vhdl-modify-date-on-saving
4788 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4789 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4790 (make-local-variable 'after-save-hook)
4791 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4792
4793 (defun vhdl-process-command-line-option (option)
4794 "Process command line options for VHDL Mode."
4795 (cond
4796 ;; set compiler
4797 ((equal option "-compiler")
4798 (vhdl-set-compiler (car command-line-args-left))
4799 (setq command-line-args-left (cdr command-line-args-left)))
4800 ;; set project
4801 ((equal option "-project")
4802 (vhdl-set-project (car command-line-args-left))
4803 (setq command-line-args-left (cdr command-line-args-left)))))
4804
4805 ;; make Emacs process VHDL Mode options
4806 (setq command-switch-alist
4807 (append command-switch-alist
4808 '(("-compiler" . vhdl-process-command-line-option)
4809 ("-project" . vhdl-process-command-line-option))))
4810
4811
4812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4813 ;;; Keywords and standardized words
4814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4815
4816 (defconst vhdl-93-keywords
4817 '(
4818 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4819 "assert" "attribute"
4820 "begin" "block" "body" "buffer" "bus"
4821 "case" "component" "configuration" "constant"
4822 "disconnect" "downto"
4823 "else" "elsif" "end" "entity" "exit"
4824 "file" "for" "function"
4825 "generate" "generic" "group" "guarded"
4826 "if" "impure" "in" "inertial" "inout" "is"
4827 "label" "library" "linkage" "literal" "loop"
4828 "map" "mod"
4829 "nand" "new" "next" "nor" "not" "null"
4830 "of" "on" "open" "or" "others" "out"
4831 "package" "port" "postponed" "procedure" "process" "pure"
4832 "range" "record" "register" "reject" "rem" "report" "return"
4833 "rol" "ror"
4834 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4835 "then" "to" "transport" "type"
4836 "unaffected" "units" "until" "use"
4837 "variable"
4838 "wait" "when" "while" "with"
4839 "xnor" "xor"
4840 )
4841 "List of VHDL'93 keywords.")
4842
4843 (defconst vhdl-ams-keywords
4844 '(
4845 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4846 "reference" "spectrum" "subnature" "terminal" "through"
4847 "tolerance"
4848 )
4849 "List of VHDL-AMS keywords.")
4850
4851 (defconst vhdl-verilog-keywords
4852 '(
4853 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4854 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4855 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4856 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4857 "endprimitive" "endspecify" "endtable" "endtask" "event"
4858 "for" "force" "forever" "fork" "function"
4859 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4860 "macromodule" "makefile" "medium" "module"
4861 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4862 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4863 "pullup"
4864 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4865 "rtranif0" "rtranif1"
4866 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4867 "strong1" "supply" "supply0" "supply1"
4868 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4869 "triand" "trior" "trireg"
4870 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4871 )
4872 "List of Verilog keywords as candidate for additional reserved words.")
4873
4874 (defconst vhdl-93-types
4875 '(
4876 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4877 "real" "time" "natural" "positive" "string" "line" "text" "side"
4878 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4879 "std_logic" "std_logic_vector"
4880 "std_ulogic" "std_ulogic_vector"
4881 )
4882 "List of VHDL'93 standardized types.")
4883
4884 (defconst vhdl-ams-types
4885 '(
4886 "domain_type" "real_vector"
4887 ;; from `nature_pkg' package
4888 "voltage" "current" "electrical" "position" "velocity" "force"
4889 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4890 "pressure" "flowrate" "fluid"
4891 )
4892 "List of VHDL-AMS standardized types.")
4893
4894 (defconst vhdl-math-types
4895 '(
4896 "complex" "complex_polar"
4897 )
4898 "List of Math Packages standardized types.")
4899
4900 (defconst vhdl-93-attributes
4901 '(
4902 "base" "left" "right" "high" "low" "pos" "val" "succ"
4903 "pred" "leftof" "rightof" "range" "reverse_range"
4904 "length" "delayed" "stable" "quiet" "transaction"
4905 "event" "active" "last_event" "last_active" "last_value"
4906 "driving" "driving_value" "ascending" "value" "image"
4907 "simple_name" "instance_name" "path_name"
4908 "foreign"
4909 )
4910 "List of VHDL'93 standardized attributes.")
4911
4912 (defconst vhdl-ams-attributes
4913 '(
4914 "across" "through"
4915 "reference" "contribution" "tolerance"
4916 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4917 "ramp" "slew"
4918 )
4919 "List of VHDL-AMS standardized attributes.")
4920
4921 (defconst vhdl-93-enum-values
4922 '(
4923 "true" "false"
4924 "note" "warning" "error" "failure"
4925 "read_mode" "write_mode" "append_mode"
4926 "open_ok" "status_error" "name_error" "mode_error"
4927 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4928 "right" "left"
4929 )
4930 "List of VHDL'93 standardized enumeration values.")
4931
4932 (defconst vhdl-ams-enum-values
4933 '(
4934 "quiescent_domain" "time_domain" "frequency_domain"
4935 ;; from `nature_pkg' package
4936 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4937 )
4938 "List of VHDL-AMS standardized enumeration values.")
4939
4940 (defconst vhdl-math-constants
4941 '(
4942 "math_e" "math_1_over_e"
4943 "math_pi" "math_two_pi" "math_1_over_pi"
4944 "math_half_pi" "math_q_pi" "math_3_half_pi"
4945 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4946 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4947 "math_deg_to_rad" "math_rad_to_deg"
4948 "cbase_1" "cbase_j" "czero"
4949 )
4950 "List of Math Packages standardized constants.")
4951
4952 (defconst vhdl-93-functions
4953 '(
4954 "now" "resolved" "rising_edge" "falling_edge"
4955 "read" "readline" "write" "writeline" "endfile"
4956 "resize" "is_X" "std_match"
4957 "shift_left" "shift_right" "rotate_left" "rotate_right"
4958 "to_unsigned" "to_signed" "to_integer"
4959 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4960 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4961 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4962 "shl" "shr" "ext" "sxt"
4963 "deallocate"
4964 )
4965 "List of VHDL'93 standardized functions.")
4966
4967 (defconst vhdl-ams-functions
4968 '(
4969 "frequency"
4970 )
4971 "List of VHDL-AMS standardized functions.")
4972
4973 (defconst vhdl-math-functions
4974 '(
4975 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4976 "sqrt" "cbrt" "exp" "log"
4977 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4978 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4979 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4980 )
4981 "List of Math Packages standardized functions.")
4982
4983 (defconst vhdl-93-packages
4984 '(
4985 "std_logic_1164" "numeric_std" "numeric_bit"
4986 "standard" "textio"
4987 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4988 "std_logic_misc" "std_logic_textio"
4989 "ieee" "std" "work"
4990 )
4991 "List of VHDL'93 standardized packages and libraries.")
4992
4993 (defconst vhdl-ams-packages
4994 '(
4995 ;; from `nature_pkg' package
4996 "nature_pkg"
4997 )
4998 "List of VHDL-AMS standardized packages and libraries.")
4999
5000 (defconst vhdl-math-packages
5001 '(
5002 "math_real" "math_complex"
5003 )
5004 "List of Math Packages standardized packages and libraries.")
5005
5006 (defvar vhdl-keywords nil
5007 "List of VHDL keywords.")
5008
5009 (defvar vhdl-types nil
5010 "List of VHDL standardized types.")
5011
5012 (defvar vhdl-attributes nil
5013 "List of VHDL standardized attributes.")
5014
5015 (defvar vhdl-enum-values nil
5016 "List of VHDL standardized enumeration values.")
5017
5018 (defvar vhdl-constants nil
5019 "List of VHDL standardized constants.")
5020
5021 (defvar vhdl-functions nil
5022 "List of VHDL standardized functions.")
5023
5024 (defvar vhdl-packages nil
5025 "List of VHDL standardized packages and libraries.")
5026
5027 (defvar vhdl-reserved-words nil
5028 "List of additional reserved words.")
5029
5030 (defvar vhdl-keywords-regexp nil
5031 "Regexp for VHDL keywords.")
5032
5033 (defvar vhdl-types-regexp nil
5034 "Regexp for VHDL standardized types.")
5035
5036 (defvar vhdl-attributes-regexp nil
5037 "Regexp for VHDL standardized attributes.")
5038
5039 (defvar vhdl-enum-values-regexp nil
5040 "Regexp for VHDL standardized enumeration values.")
5041
5042 (defvar vhdl-functions-regexp nil
5043 "Regexp for VHDL standardized functions.")
5044
5045 (defvar vhdl-packages-regexp nil
5046 "Regexp for VHDL standardized packages and libraries.")
5047
5048 (defvar vhdl-reserved-words-regexp nil
5049 "Regexp for additional reserved words.")
5050
5051 (defvar vhdl-directive-keywords-regexp nil
5052 "Regexp for compiler directive keywords.")
5053
5054 (defun vhdl-words-init ()
5055 "Initialize reserved words."
5056 (setq vhdl-keywords
5057 (append vhdl-93-keywords
5058 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5059 (setq vhdl-types
5060 (append vhdl-93-types
5061 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5062 (when (vhdl-standard-p 'math) vhdl-math-types)))
5063 (setq vhdl-attributes
5064 (append vhdl-93-attributes
5065 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5066 (setq vhdl-enum-values
5067 (append vhdl-93-enum-values
5068 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5069 (setq vhdl-constants
5070 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5071 (setq vhdl-functions
5072 (append vhdl-93-functions
5073 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5074 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5075 (setq vhdl-packages
5076 (append vhdl-93-packages
5077 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5078 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5079 (setq vhdl-reserved-words
5080 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5081 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5082 '("")))
5083 (setq vhdl-keywords-regexp
5084 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5085 (setq vhdl-types-regexp
5086 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5087 (setq vhdl-attributes-regexp
5088 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5089 (setq vhdl-enum-values-regexp
5090 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5091 (setq vhdl-functions-regexp
5092 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5093 (setq vhdl-packages-regexp
5094 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5095 (setq vhdl-reserved-words-regexp
5096 (concat "\\<\\("
5097 (unless (equal vhdl-forbidden-syntax "")
5098 (concat vhdl-forbidden-syntax "\\|"))
5099 (regexp-opt vhdl-reserved-words)
5100 "\\)\\>"))
5101 (setq vhdl-directive-keywords-regexp
5102 (concat "\\<\\(" (mapconcat 'regexp-quote
5103 vhdl-directive-keywords "\\|") "\\)\\>"))
5104 (vhdl-abbrev-list-init))
5105
5106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5107 ;; Words to expand
5108
5109 (defvar vhdl-abbrev-list nil
5110 "Predefined abbreviations for VHDL.")
5111
5112 (defun vhdl-abbrev-list-init ()
5113 (setq vhdl-abbrev-list
5114 (append
5115 (list vhdl-upper-case-keywords) vhdl-keywords
5116 (list vhdl-upper-case-types) vhdl-types
5117 (list vhdl-upper-case-attributes) vhdl-attributes
5118 (list vhdl-upper-case-enum-values) vhdl-enum-values
5119 (list vhdl-upper-case-constants) vhdl-constants
5120 (list nil) vhdl-functions
5121 (list nil) vhdl-packages)))
5122
5123 ;; initialize reserved words for VHDL Mode
5124 (vhdl-words-init)
5125
5126
5127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5128 ;;; Indentation
5129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5130
5131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5132 ;; Syntax analysis
5133
5134 ;; constant regular expressions for looking at various constructs
5135
5136 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5137 "Regexp describing a VHDL symbol.
5138 We cannot use just `word' syntax class since `_' cannot be in word
5139 class. Putting underscore in word class breaks forward word movement
5140 behavior that users are familiar with.")
5141
5142 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5143 "Regexp describing a case statement header key.")
5144
5145 (defconst vhdl-label-key
5146 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5147 "Regexp describing a VHDL label.")
5148
5149 ;; Macro definitions:
5150
5151 (defmacro vhdl-point (position)
5152 "Return the value of point at certain commonly referenced POSITIONs.
5153 POSITION can be one of the following symbols:
5154
5155 bol -- beginning of line
5156 eol -- end of line
5157 bod -- beginning of defun
5158 boi -- back to indentation
5159 eoi -- last whitespace on line
5160 ionl -- indentation of next line
5161 iopl -- indentation of previous line
5162 bonl -- beginning of next line
5163 bopl -- beginning of previous line
5164
5165 This function does not modify point or mark."
5166 (or (and (eq 'quote (car-safe position))
5167 (null (cddr position)))
5168 (error "ERROR: Bad buffer position requested: %s" position))
5169 (setq position (nth 1 position))
5170 `(let ((here (point)))
5171 ,@(cond
5172 ((eq position 'bol) '((beginning-of-line)))
5173 ((eq position 'eol) '((end-of-line)))
5174 ((eq position 'bod) '((save-match-data
5175 (vhdl-beginning-of-defun))))
5176 ((eq position 'boi) '((back-to-indentation)))
5177 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5178 ((eq position 'bonl) '((forward-line 1)))
5179 ((eq position 'bopl) '((forward-line -1)))
5180 ((eq position 'iopl)
5181 '((forward-line -1)
5182 (back-to-indentation)))
5183 ((eq position 'ionl)
5184 '((forward-line 1)
5185 (back-to-indentation)))
5186 (t (error "ERROR: Unknown buffer position requested: %s" position))
5187 )
5188 (prog1
5189 (point)
5190 (goto-char here))
5191 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5192 ;; doesn't hurt for v19
5193 ,@nil
5194 ))
5195
5196 (defmacro vhdl-safe (&rest body)
5197 "Safely execute BODY, return nil if an error occurred."
5198 `(condition-case nil
5199 (progn ,@body)
5200 (error nil)))
5201
5202 (defmacro vhdl-add-syntax (symbol &optional relpos)
5203 "A simple macro to append the syntax in SYMBOL to the syntax list.
5204 Try to increase performance by using this macro."
5205 `(setq vhdl-syntactic-context
5206 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5207
5208 (defmacro vhdl-has-syntax (symbol)
5209 "A simple macro to return check the syntax list.
5210 Try to increase performance by using this macro."
5211 `(assoc ,symbol vhdl-syntactic-context))
5212
5213 ;; Syntactic element offset manipulation:
5214
5215 (defun vhdl-read-offset (langelem)
5216 "Read new offset value for LANGELEM from minibuffer.
5217 Return a valid value only."
5218 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5219 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5220 (prompt "Offset: ")
5221 offset input interned)
5222 (while (not offset)
5223 (setq input (read-string prompt oldoff)
5224 offset (cond ((string-equal "+" input) '+)
5225 ((string-equal "-" input) '-)
5226 ((string-equal "++" input) '++)
5227 ((string-equal "--" input) '--)
5228 ((string-match "^-?[0-9]+$" input)
5229 (string-to-number input))
5230 ((fboundp (setq interned (intern input)))
5231 interned)
5232 ((boundp interned) interned)
5233 ;; error, but don't signal one, keep trying
5234 ;; to read an input value
5235 (t (ding)
5236 (setq prompt errmsg)
5237 nil))))
5238 offset))
5239
5240 (defun vhdl-set-offset (symbol offset &optional add-p)
5241 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5242 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5243 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5244 `vhdl-offsets-alist' if it doesn't already appear there."
5245 (interactive
5246 (let* ((langelem
5247 (intern (completing-read
5248 (concat "Syntactic symbol to change"
5249 (if current-prefix-arg " or add" "")
5250 ": ")
5251 (mapcar
5252 (function
5253 (lambda (langelem)
5254 (cons (format "%s" (car langelem)) nil)))
5255 vhdl-offsets-alist)
5256 nil (not current-prefix-arg)
5257 ;; initial contents tries to be the last element
5258 ;; on the syntactic analysis list for the current
5259 ;; line
5260 (let* ((syntax (vhdl-get-syntactic-context))
5261 (len (length syntax))
5262 (ic (format "%s" (car (nth (1- len) syntax)))))
5263 ic)
5264 )))
5265 (offset (vhdl-read-offset langelem)))
5266 (list langelem offset current-prefix-arg)))
5267 ;; sanity check offset
5268 (or (eq offset '+)
5269 (eq offset '-)
5270 (eq offset '++)
5271 (eq offset '--)
5272 (integerp offset)
5273 (fboundp offset)
5274 (boundp offset)
5275 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5276 offset))
5277 (let ((entry (assq symbol vhdl-offsets-alist)))
5278 (if entry
5279 (setcdr entry offset)
5280 (if add-p
5281 (setq vhdl-offsets-alist
5282 (cons (cons symbol offset) vhdl-offsets-alist))
5283 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5284 (vhdl-keep-region-active))
5285
5286 (defun vhdl-set-style (style &optional local)
5287 "Set `vhdl-mode' variables to use one of several different indentation styles.
5288 STYLE is a string representing the desired style and optional LOCAL is
5289 a flag which, if non-nil, means to make the style variables being
5290 changed buffer local, instead of the default, which is to set the
5291 global variables. Interactively, the flag comes from the prefix
5292 argument. The styles are chosen from the `vhdl-style-alist' variable."
5293 (interactive (list (completing-read "Use which VHDL indentation style? "
5294 vhdl-style-alist nil t)
5295 current-prefix-arg))
5296 (let ((vars (cdr (assoc style vhdl-style-alist))))
5297 (or vars
5298 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5299 ;; set all the variables
5300 (mapc
5301 (function
5302 (lambda (varentry)
5303 (let ((var (car varentry))
5304 (val (cdr varentry)))
5305 (and local
5306 (make-local-variable var))
5307 ;; special case for vhdl-offsets-alist
5308 (if (not (eq var 'vhdl-offsets-alist))
5309 (set var val)
5310 ;; reset vhdl-offsets-alist to the default value first
5311 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5312 ;; now set the langelems that are different
5313 (mapcar
5314 (function
5315 (lambda (langentry)
5316 (let ((langelem (car langentry))
5317 (offset (cdr langentry)))
5318 (vhdl-set-offset langelem offset)
5319 )))
5320 val))
5321 )))
5322 vars))
5323 (vhdl-keep-region-active))
5324
5325 (defun vhdl-get-offset (langelem)
5326 "Get offset from LANGELEM which is a cons cell of the form:
5327 \(SYMBOL . RELPOS). The symbol is matched against
5328 vhdl-offsets-alist and the offset found there is either returned,
5329 or added to the indentation at RELPOS. If RELPOS is nil, then
5330 the offset is simply returned."
5331 (let* ((symbol (car langelem))
5332 (relpos (cdr langelem))
5333 (match (assq symbol vhdl-offsets-alist))
5334 (offset (cdr-safe match)))
5335 ;; offset can be a number, a function, a variable, or one of the
5336 ;; symbols + or -
5337 (cond
5338 ((not match)
5339 (if vhdl-strict-syntax-p
5340 (error "ERROR: Don't know how to indent a %s" symbol)
5341 (setq offset 0
5342 relpos 0)))
5343 ((eq offset '+) (setq offset vhdl-basic-offset))
5344 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5345 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5346 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5347 ((and (not (numberp offset))
5348 (fboundp offset))
5349 (setq offset (funcall offset langelem)))
5350 ((not (numberp offset))
5351 (setq offset (eval offset)))
5352 )
5353 (+ (if (and relpos
5354 (< relpos (vhdl-point 'bol)))
5355 (save-excursion
5356 (goto-char relpos)
5357 (current-column))
5358 0)
5359 offset)))
5360
5361 ;; Syntactic support functions:
5362
5363 (defun vhdl-in-comment-p ()
5364 "Check if point is in a comment."
5365 (eq (vhdl-in-literal) 'comment))
5366
5367 (defun vhdl-in-string-p ()
5368 "Check if point is in a string."
5369 (eq (vhdl-in-literal) 'string))
5370
5371 (defun vhdl-in-literal ()
5372 "Determine if point is in a VHDL literal."
5373 (save-excursion
5374 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5375 (cond
5376 ((nth 3 state) 'string)
5377 ((nth 4 state) 'comment)
5378 ((vhdl-beginning-of-macro) 'pound)
5379 (t nil)))))
5380
5381 (defun vhdl-forward-comment (&optional direction)
5382 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5383 negative, skip forward otherwise."
5384 (interactive "p")
5385 (if (and direction (< direction 0))
5386 ;; skip backwards
5387 (progn
5388 (skip-chars-backward " \t\n")
5389 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5390 (goto-char (match-beginning 3))
5391 (skip-chars-backward " \t\n")))
5392 ;; skip forwards
5393 (skip-chars-forward " \t\n")
5394 (while (looking-at "--.*")
5395 (goto-char (match-end 0))
5396 (skip-chars-forward " \t\n"))))
5397
5398 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5399 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5400 (defalias 'vhdl-forward-comment 'forward-comment))
5401
5402 ;; This is the best we can do in Win-Emacs.
5403 (defun vhdl-win-il (&optional lim)
5404 "Determine if point is in a VHDL literal."
5405 (save-excursion
5406 (let* ((here (point))
5407 (state nil)
5408 (match nil)
5409 (lim (or lim (vhdl-point 'bod))))
5410 (goto-char lim )
5411 (while (< (point) here)
5412 (setq match
5413 (and (re-search-forward "--\\|[\"']"
5414 here 'move)
5415 (buffer-substring (match-beginning 0) (match-end 0))))
5416 (setq state
5417 (cond
5418 ;; no match
5419 ((null match) nil)
5420 ;; looking at the opening of a VHDL style comment
5421 ((string= "--" match)
5422 (if (<= here (progn (end-of-line) (point))) 'comment))
5423 ;; looking at the opening of a double quote string
5424 ((string= "\"" match)
5425 (if (not (save-restriction
5426 ;; this seems to be necessary since the
5427 ;; re-search-forward will not work without it
5428 (narrow-to-region (point) here)
5429 (re-search-forward
5430 ;; this regexp matches a double quote
5431 ;; which is preceded by an even number
5432 ;; of backslashes, including zero
5433 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5434 'string))
5435 ;; looking at the opening of a single quote string
5436 ((string= "'" match)
5437 (if (not (save-restriction
5438 ;; see comments from above
5439 (narrow-to-region (point) here)
5440 (re-search-forward
5441 ;; this matches a single quote which is
5442 ;; preceded by zero or two backslashes.
5443 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5444 here 'move)))
5445 'string))
5446 (t nil)))
5447 ) ; end-while
5448 state)))
5449
5450 (and (string-match "Win-Emacs" emacs-version)
5451 (fset 'vhdl-in-literal 'vhdl-win-il))
5452
5453 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5454 ;; defined as lexical whitespace or comments. Search no farther back
5455 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5456 ;; used for backward skipping, (point-max) is used for forward
5457 ;; skipping.
5458
5459 (defun vhdl-forward-syntactic-ws (&optional lim)
5460 "Forward skip of syntactic whitespace."
5461 (let* ((here (point-max))
5462 (hugenum (point-max)))
5463 (while (/= here (point))
5464 (setq here (point))
5465 (vhdl-forward-comment hugenum)
5466 ;; skip preprocessor directives
5467 (when (and (eq (char-after) ?#)
5468 (= (vhdl-point 'boi) (point)))
5469 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5470 (= (forward-line 1) 0)))
5471 (end-of-line)))
5472 (if lim (goto-char (min (point) lim)))))
5473
5474
5475 ;; This is the best we can do in Win-Emacs.
5476 (defun vhdl-win-fsws (&optional lim)
5477 "Forward skip syntactic whitespace for Win-Emacs."
5478 (let ((lim (or lim (point-max)))
5479 stop)
5480 (while (not stop)
5481 (skip-chars-forward " \t\n\r\f" lim)
5482 (cond
5483 ;; vhdl comment
5484 ((looking-at "--") (end-of-line))
5485 ;; none of the above
5486 (t (setq stop t))))))
5487
5488 (and (string-match "Win-Emacs" emacs-version)
5489 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5490
5491 (defun vhdl-beginning-of-macro (&optional lim)
5492 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5493 (let ((here (point)))
5494 (beginning-of-line)
5495 (while (eq (char-before (1- (point))) ?\\)
5496 (forward-line -1))
5497 (back-to-indentation)
5498 (if (and (<= (point) here)
5499 (eq (char-after) ?#))
5500 t
5501 (goto-char here)
5502 nil)))
5503
5504 (defun vhdl-backward-syntactic-ws (&optional lim)
5505 "Backward skip over syntactic whitespace."
5506 (let* ((here (point-min))
5507 (hugenum (- (point-max))))
5508 (while (/= here (point))
5509 (setq here (point))
5510 (vhdl-forward-comment hugenum)
5511 (vhdl-beginning-of-macro))
5512 (if lim (goto-char (max (point) lim)))))
5513
5514 ;; This is the best we can do in Win-Emacs.
5515 (defun vhdl-win-bsws (&optional lim)
5516 "Backward skip syntactic whitespace for Win-Emacs."
5517 (let ((lim (or lim (vhdl-point 'bod)))
5518 stop)
5519 (while (not stop)
5520 (skip-chars-backward " \t\n\r\f" lim)
5521 (cond
5522 ;; vhdl comment
5523 ((eq (vhdl-in-literal) 'comment)
5524 (skip-chars-backward "^-" lim)
5525 (skip-chars-backward "-" lim)
5526 (while (not (or (and (= (following-char) ?-)
5527 (= (char-after (1+ (point))) ?-))
5528 (<= (point) lim)))
5529 (skip-chars-backward "^-" lim)
5530 (skip-chars-backward "-" lim)))
5531 ;; none of the above
5532 (t (setq stop t))))))
5533
5534 (and (string-match "Win-Emacs" emacs-version)
5535 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5536
5537 ;; Functions to help finding the correct indentation column:
5538
5539 (defun vhdl-first-word (point)
5540 "If the keyword at POINT is at boi, then return (current-column) at
5541 that point, else nil."
5542 (save-excursion
5543 (and (goto-char point)
5544 (eq (point) (vhdl-point 'boi))
5545 (current-column))))
5546
5547 (defun vhdl-last-word (point)
5548 "If the keyword at POINT is at eoi, then return (current-column) at
5549 that point, else nil."
5550 (save-excursion
5551 (and (goto-char point)
5552 (save-excursion (or (eq (progn (forward-sexp) (point))
5553 (vhdl-point 'eoi))
5554 (looking-at "\\s-*\\(--\\)?")))
5555 (current-column))))
5556
5557 ;; Core syntactic evaluation functions:
5558
5559 (defconst vhdl-libunit-re
5560 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5561
5562 (defun vhdl-libunit-p ()
5563 (and
5564 (save-excursion
5565 (forward-sexp)
5566 (skip-chars-forward " \t\n")
5567 (not (looking-at "is\\b[^_]")))
5568 (save-excursion
5569 (backward-sexp)
5570 (and (not (looking-at "use\\b[^_]"))
5571 (progn
5572 (forward-sexp)
5573 (vhdl-forward-syntactic-ws)
5574 (/= (following-char) ?:))))
5575 ))
5576
5577 (defconst vhdl-defun-re
5578 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5579
5580 (defun vhdl-defun-p ()
5581 (save-excursion
5582 (if (looking-at "block\\|process\\|procedural")
5583 ;; "block", "process", "procedural":
5584 (save-excursion
5585 (backward-sexp)
5586 (not (looking-at "end\\s-+\\w")))
5587 ;; "architecture", "configuration", "entity",
5588 ;; "package", "procedure", "function":
5589 t)))
5590
5591 (defun vhdl-corresponding-defun ()
5592 "If the word at the current position corresponds to a \"defun\"
5593 keyword, then return a string that can be used to find the
5594 corresponding \"begin\" keyword, else return nil."
5595 (save-excursion
5596 (and (looking-at vhdl-defun-re)
5597 (vhdl-defun-p)
5598 (if (looking-at "block\\|process\\|procedural")
5599 ;; "block", "process". "procedural:
5600 (buffer-substring (match-beginning 0) (match-end 0))
5601 ;; "architecture", "configuration", "entity", "package",
5602 ;; "procedure", "function":
5603 "is"))))
5604
5605 (defconst vhdl-begin-fwd-re
5606 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5607 "A regular expression for searching forward that matches all known
5608 \"begin\" keywords.")
5609
5610 (defconst vhdl-begin-bwd-re
5611 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5612 "A regular expression for searching backward that matches all known
5613 \"begin\" keywords.")
5614
5615 (defun vhdl-begin-p (&optional lim)
5616 "Return t if we are looking at a real \"begin\" keyword.
5617 Assumes that the caller will make sure that we are looking at
5618 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5619 the middle of an identifier that just happens to contain a \"begin\"
5620 keyword."
5621 (cond
5622 ;; "[architecture|case|configuration|entity|package|
5623 ;; procedure|function] ... is":
5624 ((and (looking-at "i")
5625 (save-excursion
5626 ;; Skip backward over first sexp (needed to skip over a
5627 ;; procedure interface list, and is harmless in other
5628 ;; situations). Note that we need "return" in the
5629 ;; following search list so that we don't run into
5630 ;; semicolons in the function interface list.
5631 (backward-sexp)
5632 (let (foundp)
5633 (while (and (not foundp)
5634 (re-search-backward
5635 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5636 lim 'move))
5637 (if (or (= (preceding-char) ?_)
5638 (vhdl-in-literal))
5639 (backward-char)
5640 (setq foundp t))))
5641 (and (/= (following-char) ?\;)
5642 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5643 t)
5644 ;; "begin", "then":
5645 ((looking-at "be\\|t")
5646 t)
5647 ;; "else":
5648 ((and (looking-at "e")
5649 ;; make sure that the "else" isn't inside a
5650 ;; conditional signal assignment.
5651 (save-excursion
5652 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5653 (or (eq (following-char) ?\;)
5654 (eq (point) lim))))
5655 t)
5656 ;; "block", "generate", "loop", "process", "procedural",
5657 ;; "units", "record":
5658 ((and (looking-at "bl\\|[glpur]")
5659 (save-excursion
5660 (backward-sexp)
5661 (not (looking-at "end\\s-+\\w"))))
5662 t)
5663 ;; "component":
5664 ((and (looking-at "c")
5665 (save-excursion
5666 (backward-sexp)
5667 (not (looking-at "end\\s-+\\w")))
5668 ;; look out for the dreaded entity class in an attribute
5669 (save-excursion
5670 (vhdl-backward-syntactic-ws lim)
5671 (/= (preceding-char) ?:)))
5672 t)
5673 ;; "for" (inside configuration declaration):
5674 ((and (looking-at "f")
5675 (save-excursion
5676 (backward-sexp)
5677 (not (looking-at "end\\s-+\\w")))
5678 (vhdl-has-syntax 'configuration))
5679 t)
5680 ))
5681
5682 (defun vhdl-corresponding-mid (&optional lim)
5683 (cond
5684 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5685 "begin")
5686 ((looking-at "then")
5687 "<else>")
5688 (t
5689 "end")))
5690
5691 (defun vhdl-corresponding-end (&optional lim)
5692 "If the word at the current position corresponds to a \"begin\"
5693 keyword, then return a vector containing enough information to find
5694 the corresponding \"end\" keyword, else return nil. The keyword to
5695 search forward for is aref 0. The column in which the keyword must
5696 appear is aref 1 or nil if any column is suitable.
5697 Assumes that the caller will make sure that we are not in the middle
5698 of an identifier that just happens to contain a \"begin\" keyword."
5699 (save-excursion
5700 (and (looking-at vhdl-begin-fwd-re)
5701 (/= (preceding-char) ?_)
5702 (not (vhdl-in-literal))
5703 (vhdl-begin-p lim)
5704 (cond
5705 ;; "is", "generate", "loop":
5706 ((looking-at "[igl]")
5707 (vector "end"
5708 (and (vhdl-last-word (point))
5709 (or (vhdl-first-word (point))
5710 (save-excursion
5711 (vhdl-beginning-of-statement-1 lim)
5712 (vhdl-backward-skip-label lim)
5713 (vhdl-first-word (point)))))))
5714 ;; "begin", "else", "for":
5715 ((looking-at "be\\|[ef]")
5716 (vector "end"
5717 (and (vhdl-last-word (point))
5718 (or (vhdl-first-word (point))
5719 (save-excursion
5720 (vhdl-beginning-of-statement-1 lim)
5721 (vhdl-backward-skip-label lim)
5722 (vhdl-first-word (point)))))))
5723 ;; "component", "units", "record":
5724 ((looking-at "[cur]")
5725 ;; The first end found will close the block
5726 (vector "end" nil))
5727 ;; "block", "process", "procedural":
5728 ((looking-at "bl\\|p")
5729 (vector "end"
5730 (or (vhdl-first-word (point))
5731 (save-excursion
5732 (vhdl-beginning-of-statement-1 lim)
5733 (vhdl-backward-skip-label lim)
5734 (vhdl-first-word (point))))))
5735 ;; "then":
5736 ((looking-at "t")
5737 (vector "elsif\\|else\\|end\\s-+if"
5738 (and (vhdl-last-word (point))
5739 (or (vhdl-first-word (point))
5740 (save-excursion
5741 (vhdl-beginning-of-statement-1 lim)
5742 (vhdl-backward-skip-label lim)
5743 (vhdl-first-word (point)))))))
5744 ))))
5745
5746 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5747
5748 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5749
5750 (defun vhdl-end-p (&optional lim)
5751 "Return t if we are looking at a real \"end\" keyword.
5752 Assumes that the caller will make sure that we are looking at
5753 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5754 the middle of an identifier that just happens to contain an \"end\"
5755 keyword."
5756 (or (not (looking-at "else"))
5757 ;; make sure that the "else" isn't inside a conditional signal
5758 ;; assignment.
5759 (save-excursion
5760 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5761 (or (eq (following-char) ?\;)
5762 (eq (point) lim)
5763 (vhdl-in-literal)))))
5764
5765 (defun vhdl-corresponding-begin (&optional lim)
5766 "If the word at the current position corresponds to an \"end\"
5767 keyword, then return a vector containing enough information to find
5768 the corresponding \"begin\" keyword, else return nil. The keyword to
5769 search backward for is aref 0. The column in which the keyword must
5770 appear is aref 1 or nil if any column is suitable. The supplementary
5771 keyword to search forward for is aref 2 or nil if this is not
5772 required. If aref 3 is t, then the \"begin\" keyword may be found in
5773 the middle of a statement.
5774 Assumes that the caller will make sure that we are not in the middle
5775 of an identifier that just happens to contain an \"end\" keyword."
5776 (save-excursion
5777 (let (pos)
5778 (if (and (looking-at vhdl-end-fwd-re)
5779 (not (vhdl-in-literal))
5780 (vhdl-end-p lim))
5781 (if (looking-at "el")
5782 ;; "else", "elsif":
5783 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5784 ;; "end ...":
5785 (setq pos (point))
5786 (forward-sexp)
5787 (skip-chars-forward " \t\n")
5788 (cond
5789 ;; "end if":
5790 ((looking-at "if\\b[^_]")
5791 (vector "else\\|elsif\\|if"
5792 (vhdl-first-word pos)
5793 "else\\|then" nil))
5794 ;; "end component":
5795 ((looking-at "component\\b[^_]")
5796 (vector (buffer-substring (match-beginning 1)
5797 (match-end 1))
5798 (vhdl-first-word pos)
5799 nil nil))
5800 ;; "end units", "end record":
5801 ((looking-at "\\(units\\|record\\)\\b[^_]")
5802 (vector (buffer-substring (match-beginning 1)
5803 (match-end 1))
5804 (vhdl-first-word pos)
5805 nil t))
5806 ;; "end block", "end process", "end procedural":
5807 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5808 (vector "begin" (vhdl-first-word pos) nil nil))
5809 ;; "end case":
5810 ((looking-at "case\\b[^_]")
5811 (vector "case" (vhdl-first-word pos) "is" nil))
5812 ;; "end generate":
5813 ((looking-at "generate\\b[^_]")
5814 (vector "generate\\|for\\|if"
5815 (vhdl-first-word pos)
5816 "generate" nil))
5817 ;; "end loop":
5818 ((looking-at "loop\\b[^_]")
5819 (vector "loop\\|while\\|for"
5820 (vhdl-first-word pos)
5821 "loop" nil))
5822 ;; "end for" (inside configuration declaration):
5823 ((looking-at "for\\b[^_]")
5824 (vector "for" (vhdl-first-word pos) nil nil))
5825 ;; "end [id]":
5826 (t
5827 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5828 (vhdl-first-word pos)
5829 ;; return an alist of (statement . keyword) mappings
5830 '(
5831 ;; "begin ... end [id]":
5832 ("begin" . nil)
5833 ;; "architecture ... is ... begin ... end [id]":
5834 ("architecture" . "is")
5835 ;; "configuration ... is ... end [id]":
5836 ("configuration" . "is")
5837 ;; "entity ... is ... end [id]":
5838 ("entity" . "is")
5839 ;; "package ... is ... end [id]":
5840 ("package" . "is")
5841 ;; "procedure ... is ... begin ... end [id]":
5842 ("procedure" . "is")
5843 ;; "function ... is ... begin ... end [id]":
5844 ("function" . "is")
5845 )
5846 nil))
5847 ))) ; "end ..."
5848 )))
5849
5850 (defconst vhdl-leader-re
5851 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5852
5853 (defun vhdl-end-of-leader ()
5854 (save-excursion
5855 (cond ((looking-at "block\\|process\\|procedural")
5856 (if (save-excursion
5857 (forward-sexp)
5858 (skip-chars-forward " \t\n")
5859 (= (following-char) ?\())
5860 (forward-sexp 2)
5861 (forward-sexp))
5862 (when (looking-at "[ \t\n]*is")
5863 (goto-char (match-end 0)))
5864 (point))
5865 ((looking-at "component")
5866 (forward-sexp 2)
5867 (when (looking-at "[ \t\n]*is")
5868 (goto-char (match-end 0)))
5869 (point))
5870 ((looking-at "for")
5871 (forward-sexp 2)
5872 (skip-chars-forward " \t\n")
5873 (while (looking-at "[,:(]")
5874 (forward-sexp)
5875 (skip-chars-forward " \t\n"))
5876 (point))
5877 (t nil)
5878 )))
5879
5880 (defconst vhdl-trailer-re
5881 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5882
5883 (defconst vhdl-statement-fwd-re
5884 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5885 "A regular expression for searching forward that matches all known
5886 \"statement\" keywords.")
5887
5888 (defconst vhdl-statement-bwd-re
5889 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5890 "A regular expression for searching backward that matches all known
5891 \"statement\" keywords.")
5892
5893 (defun vhdl-statement-p (&optional lim)
5894 "Return t if we are looking at a real \"statement\" keyword.
5895 Assumes that the caller will make sure that we are looking at
5896 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5897 in the middle of an identifier that just happens to contain a
5898 \"statement\" keyword."
5899 (cond
5900 ;; "for" ... "generate":
5901 ((and (looking-at "f")
5902 ;; Make sure it's the start of a parameter specification.
5903 (save-excursion
5904 (forward-sexp 2)
5905 (skip-chars-forward " \t\n")
5906 (looking-at "in\\b[^_]"))
5907 ;; Make sure it's not an "end for".
5908 (save-excursion
5909 (backward-sexp)
5910 (not (looking-at "end\\s-+\\w"))))
5911 t)
5912 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5913 ((and (looking-at "i")
5914 ;; Make sure it's not an "end if".
5915 (save-excursion
5916 (backward-sexp)
5917 (not (looking-at "end\\s-+\\w"))))
5918 t)
5919 ;; "while" ... "loop":
5920 ((looking-at "w")
5921 t)
5922 ))
5923
5924 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5925 "Regexp describing a case statement alternative key.")
5926
5927 (defun vhdl-case-alternative-p (&optional lim)
5928 "Return t if we are looking at a real case alternative.
5929 Assumes that the caller will make sure that we are looking at
5930 vhdl-case-alternative-re, and are not inside a literal, and that
5931 we are not in the middle of an identifier that just happens to
5932 contain a \"when\" keyword."
5933 (save-excursion
5934 (let (foundp)
5935 (while (and (not foundp)
5936 (re-search-backward ";\\|<=" lim 'move))
5937 (if (or (= (preceding-char) ?_)
5938 (vhdl-in-literal))
5939 (backward-char)
5940 (setq foundp t)))
5941 (or (eq (following-char) ?\;)
5942 (eq (point) lim)))
5943 ))
5944
5945 ;; Core syntactic movement functions:
5946
5947 (defconst vhdl-b-t-b-re
5948 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5949
5950 (defun vhdl-backward-to-block (&optional lim)
5951 "Move backward to the previous \"begin\" or \"end\" keyword."
5952 (let (foundp)
5953 (while (and (not foundp)
5954 (re-search-backward vhdl-b-t-b-re lim 'move))
5955 (if (or (= (preceding-char) ?_)
5956 (vhdl-in-literal))
5957 (backward-char)
5958 (cond
5959 ;; "begin" keyword:
5960 ((and (looking-at vhdl-begin-fwd-re)
5961 (/= (preceding-char) ?_)
5962 (vhdl-begin-p lim))
5963 (setq foundp 'begin))
5964 ;; "end" keyword:
5965 ((and (looking-at vhdl-end-fwd-re)
5966 (/= (preceding-char) ?_)
5967 (vhdl-end-p lim))
5968 (setq foundp 'end))
5969 ))
5970 )
5971 foundp
5972 ))
5973
5974 (defun vhdl-forward-sexp (&optional count lim)
5975 "Move forward across one balanced expression (sexp).
5976 With COUNT, do it that many times."
5977 (interactive "p")
5978 (let ((count (or count 1))
5979 (case-fold-search t)
5980 end-vec target)
5981 (save-excursion
5982 (while (> count 0)
5983 ;; skip whitespace
5984 (skip-chars-forward " \t\n")
5985 ;; Check for an unbalanced "end" keyword
5986 (if (and (looking-at vhdl-end-fwd-re)
5987 (/= (preceding-char) ?_)
5988 (not (vhdl-in-literal))
5989 (vhdl-end-p lim)
5990 (not (looking-at "else")))
5991 (error
5992 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5993 ;; If the current keyword is a "begin" keyword, then find the
5994 ;; corresponding "end" keyword.
5995 (if (setq end-vec (vhdl-corresponding-end lim))
5996 (let (
5997 ;; end-re is the statement keyword to search for
5998 (end-re
5999 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6000 ;; column is either the statement keyword target column
6001 ;; or nil
6002 (column (aref end-vec 1))
6003 (eol (vhdl-point 'eol))
6004 foundp literal placeholder)
6005 ;; Look for the statement keyword.
6006 (while (and (not foundp)
6007 (re-search-forward end-re nil t)
6008 (setq placeholder (match-end 1))
6009 (goto-char (match-beginning 0)))
6010 ;; If we are in a literal, or not in the right target
6011 ;; column and not on the same line as the begin, then
6012 ;; try again.
6013 (if (or (and column
6014 (/= (current-indentation) column)
6015 (> (point) eol))
6016 (= (preceding-char) ?_)
6017 (setq literal (vhdl-in-literal)))
6018 (if (eq literal 'comment)
6019 (end-of-line)
6020 (forward-char))
6021 ;; An "else" keyword corresponds to both the opening brace
6022 ;; of the following sexp and the closing brace of the
6023 ;; previous sexp.
6024 (if (not (looking-at "else"))
6025 (goto-char placeholder))
6026 (setq foundp t))
6027 )
6028 (if (not foundp)
6029 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6030 )
6031 ;; If the current keyword is not a "begin" keyword, then just
6032 ;; perform the normal forward-sexp.
6033 (forward-sexp)
6034 )
6035 (setq count (1- count))
6036 )
6037 (setq target (point)))
6038 (goto-char target)
6039 nil))
6040
6041 (defun vhdl-backward-sexp (&optional count lim)
6042 "Move backward across one balanced expression (sexp).
6043 With COUNT, do it that many times. LIM bounds any required backward
6044 searches."
6045 (interactive "p")
6046 (let ((count (or count 1))
6047 (case-fold-search t)
6048 begin-vec target)
6049 (save-excursion
6050 (while (> count 0)
6051 ;; Perform the normal backward-sexp, unless we are looking at
6052 ;; "else" - an "else" keyword corresponds to both the opening brace
6053 ;; of the following sexp and the closing brace of the previous sexp.
6054 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6055 (/= (preceding-char) ?_)
6056 (not (vhdl-in-literal)))
6057 nil
6058 (backward-sexp)
6059 (if (and (looking-at vhdl-begin-fwd-re)
6060 (/= (preceding-char) ?_)
6061 (not (vhdl-in-literal))
6062 (vhdl-begin-p lim))
6063 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6064 ;; If the current keyword is an "end" keyword, then find the
6065 ;; corresponding "begin" keyword.
6066 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6067 (/= (preceding-char) ?_))
6068 (let (
6069 ;; begin-re is the statement keyword to search for
6070 (begin-re
6071 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6072 ;; column is either the statement keyword target column
6073 ;; or nil
6074 (column (aref begin-vec 1))
6075 ;; internal-p controls where the statement keyword can
6076 ;; be found.
6077 (internal-p (aref begin-vec 3))
6078 (last-backward (point)) last-forward
6079 foundp literal keyword)
6080 ;; Look for the statement keyword.
6081 (while (and (not foundp)
6082 (re-search-backward begin-re lim t)
6083 (setq keyword
6084 (buffer-substring (match-beginning 1)
6085 (match-end 1))))
6086 ;; If we are in a literal or in the wrong column,
6087 ;; then try again.
6088 (if (or (and column
6089 (and (/= (current-indentation) column)
6090 ;; possibly accept current-column as
6091 ;; well as current-indentation.
6092 (or (not internal-p)
6093 (/= (current-column) column))))
6094 (= (preceding-char) ?_)
6095 (vhdl-in-literal))
6096 (backward-char)
6097 ;; If there is a supplementary keyword, then
6098 ;; search forward for it.
6099 (if (and (setq begin-re (aref begin-vec 2))
6100 (or (not (listp begin-re))
6101 ;; If begin-re is an alist, then find the
6102 ;; element corresponding to the actual
6103 ;; keyword that we found.
6104 (progn
6105 (setq begin-re
6106 (assoc keyword begin-re))
6107 (and begin-re
6108 (setq begin-re (cdr begin-re))))))
6109 (and
6110 (setq begin-re
6111 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6112 (save-excursion
6113 (setq last-forward (point))
6114 ;; Look for the supplementary keyword
6115 ;; (bounded by the backward search start
6116 ;; point).
6117 (while (and (not foundp)
6118 (re-search-forward begin-re
6119 last-backward t)
6120 (goto-char (match-beginning 1)))
6121 ;; If we are in a literal, then try again.
6122 (if (or (= (preceding-char) ?_)
6123 (setq literal
6124 (vhdl-in-literal)))
6125 (if (eq literal 'comment)
6126 (goto-char
6127 (min (vhdl-point 'eol) last-backward))
6128 (forward-char))
6129 ;; We have found the supplementary keyword.
6130 ;; Save the position of the keyword in foundp.
6131 (setq foundp (point)))
6132 )
6133 foundp)
6134 ;; If the supplementary keyword was found, then
6135 ;; move point to the supplementary keyword.
6136 (goto-char foundp))
6137 ;; If there was no supplementary keyword, then
6138 ;; point is already at the statement keyword.
6139 (setq foundp t)))
6140 ) ; end of the search for the statement keyword
6141 (if (not foundp)
6142 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6143 ))
6144 (setq count (1- count))
6145 )
6146 (setq target (point)))
6147 (goto-char target)
6148 nil))
6149
6150 (defun vhdl-backward-up-list (&optional count limit)
6151 "Move backward out of one level of blocks.
6152 With argument, do this that many times."
6153 (interactive "p")
6154 (let ((count (or count 1))
6155 target)
6156 (save-excursion
6157 (while (> count 0)
6158 (if (looking-at vhdl-defun-re)
6159 (error "ERROR: Unbalanced blocks"))
6160 (vhdl-backward-to-block limit)
6161 (setq count (1- count)))
6162 (setq target (point)))
6163 (goto-char target)))
6164
6165 (defun vhdl-end-of-defun (&optional count)
6166 "Move forward to the end of a VHDL defun."
6167 (interactive)
6168 (let ((case-fold-search t))
6169 (vhdl-beginning-of-defun)
6170 (if (not (looking-at "block\\|process\\|procedural"))
6171 (re-search-forward "\\bis\\b"))
6172 (vhdl-forward-sexp)))
6173
6174 (defun vhdl-mark-defun ()
6175 "Put mark at end of this \"defun\", point at beginning."
6176 (interactive)
6177 (let ((case-fold-search t))
6178 (push-mark)
6179 (vhdl-beginning-of-defun)
6180 (push-mark)
6181 (if (not (looking-at "block\\|process\\|procedural"))
6182 (re-search-forward "\\bis\\b"))
6183 (vhdl-forward-sexp)
6184 (exchange-point-and-mark)))
6185
6186 (defun vhdl-beginning-of-libunit ()
6187 "Move backward to the beginning of a VHDL library unit.
6188 Returns the location of the corresponding begin keyword, unless search
6189 stops due to beginning or end of buffer.
6190 Note that if point is between the \"libunit\" keyword and the
6191 corresponding \"begin\" keyword, then that libunit will not be
6192 recognized, and the search will continue backwards. If point is
6193 at the \"begin\" keyword, then the defun will be recognized. The
6194 returned point is at the first character of the \"libunit\" keyword."
6195 (let ((last-forward (point))
6196 (last-backward
6197 ;; Just in case we are actually sitting on the "begin"
6198 ;; keyword, allow for the keyword and an extra character,
6199 ;; as this will be used when looking forward for the
6200 ;; "begin" keyword.
6201 (save-excursion (forward-word 1) (1+ (point))))
6202 foundp literal placeholder)
6203 ;; Find the "libunit" keyword.
6204 (while (and (not foundp)
6205 (re-search-backward vhdl-libunit-re nil 'move))
6206 ;; If we are in a literal, or not at a real libunit, then try again.
6207 (if (or (= (preceding-char) ?_)
6208 (vhdl-in-literal)
6209 (not (vhdl-libunit-p)))
6210 (backward-char)
6211 ;; Find the corresponding "begin" keyword.
6212 (setq last-forward (point))
6213 (while (and (not foundp)
6214 (re-search-forward "\\bis\\b[^_]" last-backward t)
6215 (setq placeholder (match-beginning 0)))
6216 (if (or (= (preceding-char) ?_)
6217 (setq literal (vhdl-in-literal)))
6218 ;; It wasn't a real keyword, so keep searching.
6219 (if (eq literal 'comment)
6220 (goto-char
6221 (min (vhdl-point 'eol) last-backward))
6222 (forward-char))
6223 ;; We have found the begin keyword, loop will exit.
6224 (setq foundp placeholder)))
6225 ;; Go back to the libunit keyword
6226 (goto-char last-forward)))
6227 foundp))
6228
6229 (defun vhdl-beginning-of-defun (&optional count)
6230 "Move backward to the beginning of a VHDL defun.
6231 With argument, do it that many times.
6232 Returns the location of the corresponding begin keyword, unless search
6233 stops due to beginning or end of buffer."
6234 ;; Note that if point is between the "defun" keyword and the
6235 ;; corresponding "begin" keyword, then that defun will not be
6236 ;; recognized, and the search will continue backwards. If point is
6237 ;; at the "begin" keyword, then the defun will be recognized. The
6238 ;; returned point is at the first character of the "defun" keyword.
6239 (interactive "p")
6240 (let ((count (or count 1))
6241 (case-fold-search t)
6242 (last-forward (point))
6243 foundp)
6244 (while (> count 0)
6245 (setq foundp nil)
6246 (goto-char last-forward)
6247 (let ((last-backward
6248 ;; Just in case we are actually sitting on the "begin"
6249 ;; keyword, allow for the keyword and an extra character,
6250 ;; as this will be used when looking forward for the
6251 ;; "begin" keyword.
6252 (save-excursion (forward-word 1) (1+ (point))))
6253 begin-string literal)
6254 (while (and (not foundp)
6255 (re-search-backward vhdl-defun-re nil 'move))
6256 ;; If we are in a literal, then try again.
6257 (if (or (= (preceding-char) ?_)
6258 (vhdl-in-literal))
6259 (backward-char)
6260 (if (setq begin-string (vhdl-corresponding-defun))
6261 ;; This is a real defun keyword.
6262 ;; Find the corresponding "begin" keyword.
6263 ;; Look for the begin keyword.
6264 (progn
6265 ;; Save the search start point.
6266 (setq last-forward (point))
6267 (while (and (not foundp)
6268 (search-forward begin-string last-backward t))
6269 (if (or (= (preceding-char) ?_)
6270 (save-match-data
6271 (setq literal (vhdl-in-literal))))
6272 ;; It wasn't a real keyword, so keep searching.
6273 (if (eq literal 'comment)
6274 (goto-char
6275 (min (vhdl-point 'eol) last-backward))
6276 (forward-char))
6277 ;; We have found the begin keyword, loop will exit.
6278 (setq foundp (match-beginning 0)))
6279 )
6280 ;; Go back to the defun keyword
6281 (goto-char last-forward)) ; end search for begin keyword
6282 ))
6283 ) ; end of the search for the defun keyword
6284 )
6285 (setq count (1- count))
6286 )
6287 (vhdl-keep-region-active)
6288 foundp))
6289
6290 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6291 "Go to the beginning of the innermost VHDL statement.
6292 With prefix arg, go back N - 1 statements. If already at the
6293 beginning of a statement then go to the beginning of the preceding
6294 one. If within a string or comment, or next to a comment (only
6295 whitespace between), move by sentences instead of statements.
6296
6297 When called from a program, this function takes 3 optional args: the
6298 prefix arg, a buffer position limit which is the farthest back to
6299 search, and an argument indicating an interactive call."
6300 (interactive "p\np")
6301 (let ((count (or count 1))
6302 (case-fold-search t)
6303 (lim (or lim (point-min)))
6304 (here (point))
6305 state)
6306 (save-excursion
6307 (goto-char lim)
6308 (setq state (parse-partial-sexp (point) here nil nil)))
6309 (if (and interactive
6310 (or (nth 3 state)
6311 (nth 4 state)
6312 (looking-at (concat "[ \t]*" comment-start-skip))))
6313 (forward-sentence (- count))
6314 (while (> count 0)
6315 (vhdl-beginning-of-statement-1 lim)
6316 (setq count (1- count))))
6317 ;; its possible we've been left up-buf of lim
6318 (goto-char (max (point) lim))
6319 )
6320 (vhdl-keep-region-active))
6321
6322 (defconst vhdl-e-o-s-re
6323 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6324
6325 (defun vhdl-end-of-statement ()
6326 "Very simple implementation."
6327 (interactive)
6328 (re-search-forward vhdl-e-o-s-re))
6329
6330 (defconst vhdl-b-o-s-re
6331 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6332 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6333
6334 (defun vhdl-beginning-of-statement-1 (&optional lim)
6335 "Move to the start of the current statement, or the previous
6336 statement if already at the beginning of one."
6337 (let ((lim (or lim (point-min)))
6338 (here (point))
6339 (pos (point))
6340 donep)
6341 ;; go backwards one balanced expression, but be careful of
6342 ;; unbalanced paren being reached
6343 (if (not (vhdl-safe (progn (backward-sexp) t)))
6344 (progn
6345 (backward-up-list 1)
6346 (forward-char)
6347 (vhdl-forward-syntactic-ws here)
6348 (setq donep t)))
6349 (while (and (not donep)
6350 (not (bobp))
6351 ;; look backwards for a statement boundary
6352 (re-search-backward vhdl-b-o-s-re lim 'move))
6353 (if (or (= (preceding-char) ?_)
6354 (vhdl-in-literal))
6355 (backward-char)
6356 (cond
6357 ;; If we are looking at an open paren, then stop after it
6358 ((eq (following-char) ?\()
6359 (forward-char)
6360 (vhdl-forward-syntactic-ws here)
6361 (setq donep t))
6362 ;; If we are looking at a close paren, then skip it
6363 ((eq (following-char) ?\))
6364 (forward-char)
6365 (setq pos (point))
6366 (backward-sexp)
6367 (if (< (point) lim)
6368 (progn (goto-char pos)
6369 (vhdl-forward-syntactic-ws here)
6370 (setq donep t))))
6371 ;; If we are looking at a semicolon, then stop
6372 ((eq (following-char) ?\;)
6373 (progn
6374 (forward-char)
6375 (vhdl-forward-syntactic-ws here)
6376 (setq donep t)))
6377 ;; If we are looking at a "begin", then stop
6378 ((and (looking-at vhdl-begin-fwd-re)
6379 (/= (preceding-char) ?_)
6380 (vhdl-begin-p nil))
6381 ;; If it's a leader "begin", then find the
6382 ;; right place
6383 (if (looking-at vhdl-leader-re)
6384 (save-excursion
6385 ;; set a default stop point at the begin
6386 (setq pos (point))
6387 ;; is the start point inside the leader area ?
6388 (goto-char (vhdl-end-of-leader))
6389 (vhdl-forward-syntactic-ws here)
6390 (if (< (point) here)
6391 ;; start point was not inside leader area
6392 ;; set stop point at word after leader
6393 (setq pos (point))))
6394 (forward-word 1)
6395 (vhdl-forward-syntactic-ws here)
6396 (setq pos (point)))
6397 (goto-char pos)
6398 (setq donep t))
6399 ;; If we are looking at a "statement", then stop
6400 ((and (looking-at vhdl-statement-fwd-re)
6401 (/= (preceding-char) ?_)
6402 (vhdl-statement-p nil))
6403 (setq donep t))
6404 ;; If we are looking at a case alternative key, then stop
6405 ((and (looking-at vhdl-case-alternative-re)
6406 (vhdl-case-alternative-p lim))
6407 (save-excursion
6408 ;; set a default stop point at the when
6409 (setq pos (point))
6410 ;; is the start point inside the case alternative key ?
6411 (looking-at vhdl-case-alternative-re)
6412 (goto-char (match-end 0))
6413 (vhdl-forward-syntactic-ws here)
6414 (if (< (point) here)
6415 ;; start point was not inside the case alternative key
6416 ;; set stop point at word after case alternative keyleader
6417 (setq pos (point))))
6418 (goto-char pos)
6419 (setq donep t))
6420 ;; Bogus find, continue
6421 (t
6422 (backward-char)))))
6423 ))
6424
6425 ;; Defuns for calculating the current syntactic state:
6426
6427 (defun vhdl-get-library-unit (bod placeholder)
6428 "If there is an enclosing library unit at BOD, with its \"begin\"
6429 keyword at PLACEHOLDER, then return the library unit type."
6430 (let ((here (vhdl-point 'bol)))
6431 (if (save-excursion
6432 (goto-char placeholder)
6433 (vhdl-safe (vhdl-forward-sexp 1 bod))
6434 (<= here (point)))
6435 (save-excursion
6436 (goto-char bod)
6437 (cond
6438 ((looking-at "e") 'entity)
6439 ((looking-at "a") 'architecture)
6440 ((looking-at "c") 'configuration)
6441 ((looking-at "p")
6442 (save-excursion
6443 (goto-char bod)
6444 (forward-sexp)
6445 (vhdl-forward-syntactic-ws here)
6446 (if (looking-at "body\\b[^_]")
6447 'package-body 'package))))))
6448 ))
6449
6450 (defun vhdl-get-block-state (&optional lim)
6451 "Finds and records all the closest opens.
6452 LIM is the furthest back we need to search (it should be the
6453 previous libunit keyword)."
6454 (let ((here (point))
6455 (lim (or lim (point-min)))
6456 keyword sexp-start sexp-mid sexp-end
6457 preceding-sexp containing-sexp
6458 containing-begin containing-mid containing-paren)
6459 (save-excursion
6460 ;; Find the containing-paren, and use that as the limit
6461 (if (setq containing-paren
6462 (save-restriction
6463 (narrow-to-region lim (point))
6464 (vhdl-safe (scan-lists (point) -1 1))))
6465 (setq lim containing-paren))
6466 ;; Look backwards for "begin" and "end" keywords.
6467 (while (and (> (point) lim)
6468 (not containing-sexp))
6469 (setq keyword (vhdl-backward-to-block lim))
6470 (cond
6471 ((eq keyword 'begin)
6472 ;; Found a "begin" keyword
6473 (setq sexp-start (point))
6474 (setq sexp-mid (vhdl-corresponding-mid lim))
6475 (setq sexp-end (vhdl-safe
6476 (save-excursion
6477 (vhdl-forward-sexp 1 lim) (point))))
6478 (if (and sexp-end (<= sexp-end here))
6479 ;; we want to record this sexp, but we only want to
6480 ;; record the last-most of any of them before here
6481 (or preceding-sexp
6482 (setq preceding-sexp sexp-start))
6483 ;; we're contained in this sexp so put sexp-start on
6484 ;; front of list
6485 (setq containing-sexp sexp-start)
6486 (setq containing-mid sexp-mid)
6487 (setq containing-begin t)))
6488 ((eq keyword 'end)
6489 ;; Found an "end" keyword
6490 (forward-sexp)
6491 (setq sexp-end (point))
6492 (setq sexp-mid nil)
6493 (setq sexp-start
6494 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6495 (progn (backward-sexp) (point))))
6496 ;; we want to record this sexp, but we only want to
6497 ;; record the last-most of any of them before here
6498 (or preceding-sexp
6499 (setq preceding-sexp sexp-start)))
6500 )))
6501 ;; Check if the containing-paren should be the containing-sexp
6502 (if (and containing-paren
6503 (or (null containing-sexp)
6504 (< containing-sexp containing-paren)))
6505 (setq containing-sexp containing-paren
6506 preceding-sexp nil
6507 containing-begin nil
6508 containing-mid nil))
6509 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6510 ))
6511
6512
6513 (defconst vhdl-s-c-a-re
6514 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6515
6516 (defun vhdl-skip-case-alternative (&optional lim)
6517 "Skip forward over case/when bodies, with optional maximal
6518 limit. If no next case alternative is found, nil is returned and
6519 point is not moved."
6520 (let ((lim (or lim (point-max)))
6521 (here (point))
6522 donep foundp)
6523 (while (and (< (point) lim)
6524 (not donep))
6525 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6526 (save-match-data
6527 (not (vhdl-in-literal)))
6528 (/= (match-beginning 0) here))
6529 (progn
6530 (goto-char (match-beginning 0))
6531 (cond
6532 ((and (looking-at "case")
6533 (re-search-forward "\\bis[^_]" lim t))
6534 (backward-sexp)
6535 (vhdl-forward-sexp))
6536 (t
6537 (setq donep t
6538 foundp t))))))
6539 (if (not foundp)
6540 (goto-char here))
6541 foundp))
6542
6543 (defun vhdl-backward-skip-label (&optional lim)
6544 "Skip backward over a label, with optional maximal
6545 limit. If label is not found, nil is returned and point
6546 is not moved."
6547 (let ((lim (or lim (point-min)))
6548 placeholder)
6549 (if (save-excursion
6550 (vhdl-backward-syntactic-ws lim)
6551 (and (eq (preceding-char) ?:)
6552 (progn
6553 (backward-sexp)
6554 (setq placeholder (point))
6555 (looking-at vhdl-label-key))))
6556 (goto-char placeholder))
6557 ))
6558
6559 (defun vhdl-forward-skip-label (&optional lim)
6560 "Skip forward over a label, with optional maximal
6561 limit. If label is not found, nil is returned and point
6562 is not moved."
6563 (let ((lim (or lim (point-max))))
6564 (if (looking-at vhdl-label-key)
6565 (progn
6566 (goto-char (match-end 0))
6567 (vhdl-forward-syntactic-ws lim)))
6568 ))
6569
6570 (defun vhdl-get-syntactic-context ()
6571 "Guess the syntactic description of the current line of VHDL code."
6572 (save-excursion
6573 (save-restriction
6574 (beginning-of-line)
6575 (let* ((indent-point (point))
6576 (case-fold-search t)
6577 vec literal containing-sexp preceding-sexp
6578 containing-begin containing-mid containing-leader
6579 char-before-ip char-after-ip begin-after-ip end-after-ip
6580 placeholder lim library-unit
6581 )
6582
6583 ;; Reset the syntactic context
6584 (setq vhdl-syntactic-context nil)
6585
6586 (save-excursion
6587 ;; Move to the start of the previous library unit, and
6588 ;; record the position of the "begin" keyword.
6589 (setq placeholder (vhdl-beginning-of-libunit))
6590 ;; The position of the "libunit" keyword gives us a gross
6591 ;; limit point.
6592 (setq lim (point))
6593 )
6594
6595 ;; If there is a previous library unit, and we are enclosed by
6596 ;; it, then set the syntax accordingly.
6597 (and placeholder
6598 (setq library-unit (vhdl-get-library-unit lim placeholder))
6599 (vhdl-add-syntax library-unit lim))
6600
6601 ;; Find the surrounding state.
6602 (if (setq vec (vhdl-get-block-state lim))
6603 (progn
6604 (setq containing-sexp (aref vec 0))
6605 (setq preceding-sexp (aref vec 1))
6606 (setq containing-begin (aref vec 2))
6607 (setq containing-mid (aref vec 3))
6608 ))
6609
6610 ;; set the limit on the farthest back we need to search
6611 (setq lim (if containing-sexp
6612 (save-excursion
6613 (goto-char containing-sexp)
6614 ;; set containing-leader if required
6615 (if (looking-at vhdl-leader-re)
6616 (setq containing-leader (vhdl-end-of-leader)))
6617 (vhdl-point 'bol))
6618 (point-min)))
6619
6620 ;; cache char before and after indent point, and move point to
6621 ;; the most likely position to perform the majority of tests
6622 (goto-char indent-point)
6623 (skip-chars-forward " \t")
6624 (setq literal (vhdl-in-literal))
6625 (setq char-after-ip (following-char))
6626 (setq begin-after-ip (and
6627 (not literal)
6628 (looking-at vhdl-begin-fwd-re)
6629 (vhdl-begin-p)))
6630 (setq end-after-ip (and
6631 (not literal)
6632 (looking-at vhdl-end-fwd-re)
6633 (vhdl-end-p)))
6634 (vhdl-backward-syntactic-ws lim)
6635 (setq char-before-ip (preceding-char))
6636 (goto-char indent-point)
6637 (skip-chars-forward " \t")
6638
6639 ;; now figure out syntactic qualities of the current line
6640 (cond
6641 ;; CASE 1: in a string or comment.
6642 ((memq literal '(string comment))
6643 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6644 ;; CASE 2: Line is at top level.
6645 ((null containing-sexp)
6646 ;; Find the point to which indentation will be relative
6647 (save-excursion
6648 (if (null preceding-sexp)
6649 ;; CASE 2X.1
6650 ;; no preceding-sexp -> use the preceding statement
6651 (vhdl-beginning-of-statement-1 lim)
6652 ;; CASE 2X.2
6653 ;; if there is a preceding-sexp then indent relative to it
6654 (goto-char preceding-sexp)
6655 ;; if not at boi, then the block-opening keyword is
6656 ;; probably following a label, so we need a different
6657 ;; relpos
6658 (if (/= (point) (vhdl-point 'boi))
6659 ;; CASE 2X.3
6660 (vhdl-beginning-of-statement-1 lim)))
6661 ;; v-b-o-s could have left us at point-min
6662 (and (bobp)
6663 ;; CASE 2X.4
6664 (vhdl-forward-syntactic-ws indent-point))
6665 (setq placeholder (point)))
6666 (cond
6667 ;; CASE 2A : we are looking at a block-open
6668 (begin-after-ip
6669 (vhdl-add-syntax 'block-open placeholder))
6670 ;; CASE 2B: we are looking at a block-close
6671 (end-after-ip
6672 (vhdl-add-syntax 'block-close placeholder))
6673 ;; CASE 2C: we are looking at a top-level statement
6674 ((progn
6675 (vhdl-backward-syntactic-ws lim)
6676 (or (bobp)
6677 (= (preceding-char) ?\;)))
6678 (vhdl-add-syntax 'statement placeholder))
6679 ;; CASE 2D: we are looking at a top-level statement-cont
6680 (t
6681 (vhdl-beginning-of-statement-1 lim)
6682 ;; v-b-o-s could have left us at point-min
6683 (and (bobp)
6684 ;; CASE 2D.1
6685 (vhdl-forward-syntactic-ws indent-point))
6686 (vhdl-add-syntax 'statement-cont (point)))
6687 )) ; end CASE 2
6688 ;; CASE 3: line is inside parentheses. Most likely we are
6689 ;; either in a subprogram argument (interface) list, or a
6690 ;; continued expression containing parentheses.
6691 ((null containing-begin)
6692 (vhdl-backward-syntactic-ws containing-sexp)
6693 (cond
6694 ;; CASE 3A: we are looking at the arglist closing paren
6695 ((eq char-after-ip ?\))
6696 (goto-char containing-sexp)
6697 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6698 ;; CASE 3B: we are looking at the first argument in an empty
6699 ;; argument list.
6700 ((eq char-before-ip ?\()
6701 (goto-char containing-sexp)
6702 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6703 ;; CASE 3C: we are looking at an arglist continuation line,
6704 ;; but the preceding argument is on the same line as the
6705 ;; opening paren. This case includes multi-line
6706 ;; expression paren groupings.
6707 ((and (save-excursion
6708 (goto-char (1+ containing-sexp))
6709 (skip-chars-forward " \t")
6710 (not (eolp))
6711 (not (looking-at "--")))
6712 (save-excursion
6713 (vhdl-beginning-of-statement-1 containing-sexp)
6714 (skip-chars-backward " \t(")
6715 (<= (point) containing-sexp)))
6716 (goto-char containing-sexp)
6717 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6718 ;; CASE 3D: we are looking at just a normal arglist
6719 ;; continuation line
6720 (t (vhdl-beginning-of-statement-1 containing-sexp)
6721 (vhdl-forward-syntactic-ws indent-point)
6722 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6723 ))
6724 ;; CASE 4: A block mid open
6725 ((and begin-after-ip
6726 (looking-at containing-mid))
6727 (goto-char containing-sexp)
6728 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6729 (if (looking-at vhdl-trailer-re)
6730 ;; CASE 4.1
6731 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6732 (vhdl-backward-skip-label (vhdl-point 'boi))
6733 (vhdl-add-syntax 'block-open (point)))
6734 ;; CASE 5: block close brace
6735 (end-after-ip
6736 (goto-char containing-sexp)
6737 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6738 (if (looking-at vhdl-trailer-re)
6739 ;; CASE 5.1
6740 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6741 (vhdl-backward-skip-label (vhdl-point 'boi))
6742 (vhdl-add-syntax 'block-close (point)))
6743 ;; CASE 6: A continued statement
6744 ((and (/= char-before-ip ?\;)
6745 ;; check it's not a trailer begin keyword, or a begin
6746 ;; keyword immediately following a label.
6747 (not (and begin-after-ip
6748 (or (looking-at vhdl-trailer-re)
6749 (save-excursion
6750 (vhdl-backward-skip-label containing-sexp)))))
6751 ;; check it's not a statement keyword
6752 (not (and (looking-at vhdl-statement-fwd-re)
6753 (vhdl-statement-p)))
6754 ;; see if the b-o-s is before the indent point
6755 (> indent-point
6756 (save-excursion
6757 (vhdl-beginning-of-statement-1 containing-sexp)
6758 ;; If we ended up after a leader, then this will
6759 ;; move us forward to the start of the first
6760 ;; statement. Note that a containing sexp here is
6761 ;; always a keyword, not a paren, so this will
6762 ;; have no effect if we hit the containing-sexp.
6763 (vhdl-forward-syntactic-ws indent-point)
6764 (setq placeholder (point))))
6765 ;; check it's not a block-intro
6766 (/= placeholder containing-sexp)
6767 ;; check it's not a case block-intro
6768 (save-excursion
6769 (goto-char placeholder)
6770 (or (not (looking-at vhdl-case-alternative-re))
6771 (> (match-end 0) indent-point))))
6772 ;; Make placeholder skip a label, but only if it puts us
6773 ;; before the indent point at the start of a line.
6774 (let ((new placeholder))
6775 (if (and (> indent-point
6776 (save-excursion
6777 (goto-char placeholder)
6778 (vhdl-forward-skip-label indent-point)
6779 (setq new (point))))
6780 (save-excursion
6781 (goto-char new)
6782 (eq new (progn (back-to-indentation) (point)))))
6783 (setq placeholder new)))
6784 (vhdl-add-syntax 'statement-cont placeholder)
6785 (if begin-after-ip
6786 (vhdl-add-syntax 'block-open)))
6787 ;; Statement. But what kind?
6788 ;; CASE 7: A case alternative key
6789 ((and (looking-at vhdl-case-alternative-re)
6790 (vhdl-case-alternative-p containing-sexp))
6791 ;; for a case alternative key, we set relpos to the first
6792 ;; non-whitespace char on the line containing the "case"
6793 ;; keyword.
6794 (goto-char containing-sexp)
6795 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6796 (if (looking-at vhdl-trailer-re)
6797 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6798 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6799 ;; CASE 8: statement catchall
6800 (t
6801 ;; we know its a statement, but we need to find out if it is
6802 ;; the first statement in a block
6803 (if containing-leader
6804 (goto-char containing-leader)
6805 (goto-char containing-sexp)
6806 ;; Note that a containing sexp here is always a keyword,
6807 ;; not a paren, so skip over the keyword.
6808 (forward-sexp))
6809 ;; move to the start of the first statement
6810 (vhdl-forward-syntactic-ws indent-point)
6811 (setq placeholder (point))
6812 ;; we want to ignore case alternatives keys when skipping forward
6813 (let (incase-p)
6814 (while (looking-at vhdl-case-alternative-re)
6815 (setq incase-p (point))
6816 ;; we also want to skip over the body of the
6817 ;; case/when statement if that doesn't put us at
6818 ;; after the indent-point
6819 (while (vhdl-skip-case-alternative indent-point))
6820 ;; set up the match end
6821 (looking-at vhdl-case-alternative-re)
6822 (goto-char (match-end 0))
6823 ;; move to the start of the first case alternative statement
6824 (vhdl-forward-syntactic-ws indent-point)
6825 (setq placeholder (point)))
6826 (cond
6827 ;; CASE 8A: we saw a case/when statement so we must be
6828 ;; in a switch statement. find out if we are at the
6829 ;; statement just after a case alternative key
6830 ((and incase-p
6831 (= (point) indent-point))
6832 ;; relpos is the "when" keyword
6833 (vhdl-add-syntax 'statement-case-intro incase-p))
6834 ;; CASE 8B: any old statement
6835 ((< (point) indent-point)
6836 ;; relpos is the first statement of the block
6837 (vhdl-add-syntax 'statement placeholder)
6838 (if begin-after-ip
6839 (vhdl-add-syntax 'block-open)))
6840 ;; CASE 8C: first statement in a block
6841 (t
6842 (goto-char containing-sexp)
6843 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6844 (if (looking-at vhdl-trailer-re)
6845 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6846 (vhdl-backward-skip-label (vhdl-point 'boi))
6847 (vhdl-add-syntax 'statement-block-intro (point))
6848 (if begin-after-ip
6849 (vhdl-add-syntax 'block-open)))
6850 )))
6851 )
6852
6853 ;; now we need to look at any modifiers
6854 (goto-char indent-point)
6855 (skip-chars-forward " \t")
6856 (if (looking-at "--")
6857 (vhdl-add-syntax 'comment))
6858 (if (eq literal 'pound)
6859 (vhdl-add-syntax 'cpp-macro))
6860 ;; return the syntax
6861 vhdl-syntactic-context))))
6862
6863 ;; Standard indentation line-ups:
6864
6865 (defun vhdl-lineup-arglist (langelem)
6866 "Lineup the current arglist line with the arglist appearing just
6867 after the containing paren which starts the arglist."
6868 (save-excursion
6869 (let* ((containing-sexp
6870 (save-excursion
6871 ;; arglist-cont-nonempty gives relpos ==
6872 ;; to boi of containing-sexp paren. This
6873 ;; is good when offset is +, but bad
6874 ;; when it is vhdl-lineup-arglist, so we
6875 ;; have to special case a kludge here.
6876 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6877 (progn
6878 (beginning-of-line)
6879 (backward-up-list 1)
6880 (skip-chars-forward " \t" (vhdl-point 'eol)))
6881 (goto-char (cdr langelem)))
6882 (point)))
6883 (cs-curcol (save-excursion
6884 (goto-char (cdr langelem))
6885 (current-column))))
6886 (if (save-excursion
6887 (beginning-of-line)
6888 (looking-at "[ \t]*)"))
6889 (progn (goto-char (match-end 0))
6890 (backward-sexp)
6891 (forward-char)
6892 (vhdl-forward-syntactic-ws)
6893 (- (current-column) cs-curcol))
6894 (goto-char containing-sexp)
6895 (or (eolp)
6896 (let ((eol (vhdl-point 'eol))
6897 (here (progn
6898 (forward-char)
6899 (skip-chars-forward " \t")
6900 (point))))
6901 (vhdl-forward-syntactic-ws)
6902 (if (< (point) eol)
6903 (goto-char here))))
6904 (- (current-column) cs-curcol)
6905 ))))
6906
6907 (defun vhdl-lineup-arglist-intro (langelem)
6908 "Lineup an arglist-intro line to just after the open paren."
6909 (save-excursion
6910 (let ((cs-curcol (save-excursion
6911 (goto-char (cdr langelem))
6912 (current-column)))
6913 (ce-curcol (save-excursion
6914 (beginning-of-line)
6915 (backward-up-list 1)
6916 (skip-chars-forward " \t" (vhdl-point 'eol))
6917 (current-column))))
6918 (- ce-curcol cs-curcol -1))))
6919
6920 (defun vhdl-lineup-comment (langelem)
6921 "Support old behavior for comment indentation. We look at
6922 vhdl-comment-only-line-offset to decide how to indent comment
6923 only-lines."
6924 (save-excursion
6925 (back-to-indentation)
6926 ;; at or to the right of comment-column
6927 (if (>= (current-column) comment-column)
6928 (vhdl-comment-indent)
6929 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6930 (if (not (bolp))
6931 (or (car-safe vhdl-comment-only-line-offset)
6932 vhdl-comment-only-line-offset)
6933 (or (cdr-safe vhdl-comment-only-line-offset)
6934 (car-safe vhdl-comment-only-line-offset)
6935 -1000 ;jam it against the left side
6936 )))))
6937
6938 (defun vhdl-lineup-statement-cont (langelem)
6939 "Line up statement-cont after the assignment operator."
6940 (save-excursion
6941 (let* ((relpos (cdr langelem))
6942 (assignp (save-excursion
6943 (goto-char (vhdl-point 'boi))
6944 (and (re-search-forward "\\(<\\|:\\)="
6945 (vhdl-point 'eol) t)
6946 (- (point) (vhdl-point 'boi)))))
6947 (curcol (progn
6948 (goto-char relpos)
6949 (current-column)))
6950 foundp)
6951 (while (and (not foundp)
6952 (< (point) (vhdl-point 'eol)))
6953 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6954 (if (vhdl-in-literal)
6955 (forward-char)
6956 (if (= (preceding-char) ?\()
6957 ;; skip over any parenthesized expressions
6958 (goto-char (min (vhdl-point 'eol)
6959 (scan-lists (point) 1 1)))
6960 ;; found an assignment operator (not at eol)
6961 (setq foundp (not (looking-at "\\s-*$"))))))
6962 (if (not foundp)
6963 ;; there's no assignment operator on the line
6964 vhdl-basic-offset
6965 ;; calculate indentation column after assign and ws, unless
6966 ;; our line contains an assignment operator
6967 (if (not assignp)
6968 (progn
6969 (forward-char)
6970 (skip-chars-forward " \t")
6971 (setq assignp 0)))
6972 (- (current-column) assignp curcol))
6973 )))
6974
6975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6976 ;; Progress reporting
6977
6978 (defvar vhdl-progress-info nil
6979 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6980
6981 (defun vhdl-update-progress-info (string pos)
6982 "Update progress information."
6983 (when (and vhdl-progress-info (not noninteractive)
6984 (< vhdl-progress-interval
6985 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6986 (let ((delta (- (aref vhdl-progress-info 1)
6987 (aref vhdl-progress-info 0))))
6988 (if (= 0 delta)
6989 (message (concat string "... (100%s)") "%")
6990 (message (concat string "... (%2d%s)")
6991 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6992 delta) "%")))
6993 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6994
6995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6996 ;; Indentation commands
6997
6998 (defun vhdl-electric-tab (&optional prefix-arg)
6999 "If preceeding character is part of a word or a paren then hippie-expand,
7000 else if right of non whitespace on line then insert tab,
7001 else if last command was a tab or return then dedent one step or if a comment
7002 toggle between normal indent and inline comment indent,
7003 else indent `correctly'."
7004 (interactive "*P")
7005 (vhdl-prepare-search-2
7006 (cond
7007 ;; expand word
7008 ((= (char-syntax (preceding-char)) ?w)
7009 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7010 (case-replace nil)
7011 (hippie-expand-only-buffers
7012 (or (and (boundp 'hippie-expand-only-buffers)
7013 hippie-expand-only-buffers)
7014 '(vhdl-mode))))
7015 (vhdl-expand-abbrev prefix-arg)))
7016 ;; expand parenthesis
7017 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7018 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7019 (case-replace nil))
7020 (vhdl-expand-paren prefix-arg)))
7021 ;; insert tab
7022 ((> (current-column) (current-indentation))
7023 (insert-tab))
7024 ;; toggle comment indent
7025 ((and (looking-at "--")
7026 (or (eq last-command 'vhdl-electric-tab)
7027 (eq last-command 'vhdl-electric-return)))
7028 (cond ((= (current-indentation) 0) ; no indent
7029 (indent-to 1)
7030 (indent-according-to-mode))
7031 ((< (current-indentation) comment-column) ; normal indent
7032 (indent-to comment-column)
7033 (indent-according-to-mode))
7034 (t ; inline comment indent
7035 (delete-region (line-beginning-position) (point)))))
7036 ;; dedent
7037 ((and (>= (current-indentation) vhdl-basic-offset)
7038 (or (eq last-command 'vhdl-electric-tab)
7039 (eq last-command 'vhdl-electric-return)))
7040 (backward-delete-char-untabify vhdl-basic-offset nil))
7041 ;; indent line
7042 (t (indent-according-to-mode)))
7043 (setq this-command 'vhdl-electric-tab)))
7044
7045 (defun vhdl-electric-return ()
7046 "newline-and-indent or indent-new-comment-line if in comment and preceding
7047 character is a space."
7048 (interactive)
7049 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7050 (indent-new-comment-line)
7051 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7052 (vhdl-fix-case-word -1))
7053 (newline-and-indent)))
7054
7055 (defun vhdl-indent-line ()
7056 "Indent the current line as VHDL code. Returns the amount of
7057 indentation change."
7058 (interactive)
7059 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7060 (pos (- (point-max) (point)))
7061 (indent
7062 (if syntax
7063 ;; indent syntax-based
7064 (if (and (eq (caar syntax) 'comment)
7065 (>= (vhdl-get-offset (car syntax)) comment-column))
7066 ;; special case: comments at or right of comment-column
7067 (vhdl-get-offset (car syntax))
7068 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7069 ;; indent like previous nonblank line
7070 (save-excursion (beginning-of-line)
7071 (re-search-backward "^[^\n]" nil t)
7072 (current-indentation))))
7073 (shift-amt (- indent (current-indentation))))
7074 (and vhdl-echo-syntactic-information-p
7075 (message "syntax: %s, indent= %d" syntax indent))
7076 (unless (zerop shift-amt)
7077 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7078 (beginning-of-line)
7079 (indent-to indent))
7080 (if (< (point) (vhdl-point 'boi))
7081 (back-to-indentation)
7082 ;; If initial point was within line's indentation, position after
7083 ;; the indentation. Else stay at same point in text.
7084 (when (> (- (point-max) pos) (point))
7085 (goto-char (- (point-max) pos))))
7086 (run-hooks 'vhdl-special-indent-hook)
7087 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7088 shift-amt))
7089
7090 (defun vhdl-indent-region (beg end column)
7091 "Indent region as VHDL code.
7092 Adds progress reporting to `indent-region'."
7093 (interactive "r\nP")
7094 (when vhdl-progress-interval
7095 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7096 (count-lines (point-min) end) 0)))
7097 (indent-region beg end column)
7098 (when vhdl-progress-interval (message "Indenting...done"))
7099 (setq vhdl-progress-info nil))
7100
7101 (defun vhdl-indent-buffer ()
7102 "Indent whole buffer as VHDL code.
7103 Calls `indent-region' for whole buffer and adds progress reporting."
7104 (interactive)
7105 (vhdl-indent-region (point-min) (point-max) nil))
7106
7107 (defun vhdl-indent-group ()
7108 "Indent group of lines between empty lines."
7109 (interactive)
7110 (let ((beg (save-excursion
7111 (if (re-search-backward vhdl-align-group-separate nil t)
7112 (point-marker)
7113 (point-min-marker))))
7114 (end (save-excursion
7115 (if (re-search-forward vhdl-align-group-separate nil t)
7116 (point-marker)
7117 (point-max-marker)))))
7118 (vhdl-indent-region beg end nil)))
7119
7120 (defun vhdl-indent-sexp (&optional endpos)
7121 "Indent each line of the list starting just after point.
7122 If optional arg ENDPOS is given, indent each line, stopping when
7123 ENDPOS is encountered."
7124 (interactive)
7125 (save-excursion
7126 (let ((beg (point))
7127 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7128 (indent-region beg end nil))))
7129
7130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7131 ;; Miscellaneous commands
7132
7133 (defun vhdl-show-syntactic-information ()
7134 "Show syntactic information for current line."
7135 (interactive)
7136 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7137 (vhdl-keep-region-active))
7138
7139 ;; Verification and regression functions:
7140
7141 (defun vhdl-regress-line (&optional arg)
7142 "Check syntactic information for current line."
7143 (interactive "P")
7144 (let ((expected (save-excursion
7145 (end-of-line)
7146 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7147 (forward-char 4)
7148 (read (current-buffer)))))
7149 (actual (vhdl-get-syntactic-context))
7150 (expurgated))
7151 ;; remove the library unit symbols
7152 (mapc
7153 (function
7154 (lambda (elt)
7155 (if (memq (car elt) '(entity configuration package
7156 package-body architecture))
7157 nil
7158 (setq expurgated (append expurgated (list elt))))))
7159 actual)
7160 (if (and (not arg) expected (listp expected))
7161 (if (not (equal expected expurgated))
7162 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7163 (save-excursion
7164 (beginning-of-line)
7165 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7166 (end-of-line)
7167 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7168 (delete-region (point) (line-end-position)))
7169 (insert " -- ")
7170 (insert (format "%s" expurgated))))))
7171 (vhdl-keep-region-active))
7172
7173
7174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7175 ;;; Alignment, whitespace fixup, beautifying
7176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7177
7178 (defconst vhdl-align-alist
7179 '(
7180 ;; after some keywords
7181 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7182 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7183 ;; before ':'
7184 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7185 ;; after direction specifications
7186 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7187 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7188 ;; before "==", ":=", "=>", and "<="
7189 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7190 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7191 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7192 ;; before some keywords
7193 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7194 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7195 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7196 ;; before "=>" since "when/else ... =>" can occur
7197 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7198 )
7199 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7200 It is searched in order. If REGEXP is found anywhere in the first
7201 line of a region to be aligned, ALIGN-PATTERN will be used for that
7202 region. ALIGN-PATTERN must include the whitespace to be expanded or
7203 contracted. It may also provide regexps for the text surrounding the
7204 whitespace. SUBEXP specifies which sub-expression of
7205 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7206
7207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7208 ;; Align code
7209
7210 (defvar vhdl-align-try-all-clauses t
7211 "If REGEXP is not found on the first line of the region that clause
7212 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7213
7214 (defun vhdl-do-group (function &optional spacing)
7215 "Apply FUNCTION on group of lines between empty lines."
7216 (let
7217 ;; search for group beginning
7218 ((beg (save-excursion
7219 (if (re-search-backward vhdl-align-group-separate nil t)
7220 (progn (beginning-of-line 2) (back-to-indentation) (point))
7221 (point-min))))
7222 ;; search for group end
7223 (end (save-excursion
7224 (if (re-search-forward vhdl-align-group-separate nil t)
7225 (progn (beginning-of-line) (point))
7226 (point-max)))))
7227 ;; run FUNCTION
7228 (funcall function beg end spacing)))
7229
7230 (defun vhdl-do-list (function &optional spacing)
7231 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7232 parentheses."
7233 (let (beg end)
7234 (save-excursion
7235 ;; search for beginning of balanced group of parentheses
7236 (setq beg (vhdl-re-search-backward "[()]" nil t))
7237 (while (looking-at ")")
7238 (forward-char) (backward-sexp)
7239 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7240 ;; search for end of balanced group of parentheses
7241 (when beg
7242 (forward-list)
7243 (setq end (point))
7244 (goto-char (1+ beg))
7245 (skip-chars-forward " \t\n")
7246 (setq beg (point))))
7247 ;; run FUNCTION
7248 (if beg
7249 (funcall function beg end spacing)
7250 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7251
7252 (defun vhdl-do-same-indent (function &optional spacing)
7253 "Apply FUNCTION to block of lines with same indent."
7254 (let ((indent (current-indentation))
7255 beg end)
7256 ;; search for first line with same indent
7257 (save-excursion
7258 (while (and (not (bobp))
7259 (or (looking-at "^\\s-*\\(--.*\\)?$")
7260 (= (current-indentation) indent)))
7261 (unless (looking-at "^\\s-*$")
7262 (back-to-indentation) (setq beg (point)))
7263 (beginning-of-line -0)))
7264 ;; search for last line with same indent
7265 (save-excursion
7266 (while (and (not (eobp))
7267 (or (looking-at "^\\s-*\\(--.*\\)?$")
7268 (= (current-indentation) indent)))
7269 (if (looking-at "^\\s-*$")
7270 (beginning-of-line 2)
7271 (beginning-of-line 2)
7272 (setq end (point)))))
7273 ;; run FUNCTION
7274 (funcall function beg end spacing)))
7275
7276 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7277 "Attempt to align a range of lines based on the content of the
7278 lines. The definition of `alignment-list' determines the matching
7279 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7280 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7281 indentation is done before aligning."
7282 (interactive "r\np")
7283 (setq alignment-list (or alignment-list vhdl-align-alist))
7284 (setq spacing (or spacing 1))
7285 (save-excursion
7286 (let (bol indent)
7287 (goto-char end)
7288 (setq end (point-marker))
7289 (goto-char begin)
7290 (setq bol (setq begin (progn (beginning-of-line) (point))))
7291 ; (untabify bol end)
7292 (when indent
7293 (indent-region bol end nil))))
7294 (let ((copy (copy-alist alignment-list)))
7295 (vhdl-prepare-search-2
7296 (while copy
7297 (save-excursion
7298 (goto-char begin)
7299 (let (element
7300 (eol (save-excursion (progn (end-of-line) (point)))))
7301 (setq element (nth 0 copy))
7302 (when (and (or (and (listp (car element))
7303 (memq major-mode (car element)))
7304 (eq major-mode (car element)))
7305 (or vhdl-align-try-all-clauses
7306 (re-search-forward (car (cdr element)) eol t)))
7307 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7308 (car (cdr (cdr (cdr element)))) spacing))
7309 (setq copy (cdr copy))))))))
7310
7311 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7312 "Align a range of lines from BEGIN to END. The regular expression
7313 MATCH must match exactly one field: the whitespace to be
7314 contracted/expanded. The alignment column will equal the
7315 rightmost column of the widest whitespace block. SPACING is
7316 the amount of extra spaces to add to the calculated maximum required.
7317 SPACING defaults to 1 so that at least one space is inserted after
7318 the token in MATCH."
7319 (setq spacing (or spacing 1))
7320 (setq substr (or substr 1))
7321 (save-excursion
7322 (let (distance (max 0) (lines 0) bol eol width)
7323 ;; Determine the greatest whitespace distance to the alignment
7324 ;; character
7325 (goto-char begin)
7326 (setq eol (progn (end-of-line) (point))
7327 bol (setq begin (progn (beginning-of-line) (point))))
7328 (while (< bol end)
7329 (save-excursion
7330 (when (and (re-search-forward match eol t)
7331 (not (vhdl-in-literal)))
7332 (setq distance (- (match-beginning substr) bol))
7333 (when (> distance max)
7334 (setq max distance))))
7335 (forward-line)
7336 (setq bol (point)
7337 eol (save-excursion (end-of-line) (point)))
7338 (setq lines (1+ lines)))
7339 ;; Now insert enough maxs to push each assignment operator to
7340 ;; the same column. We need to use 'lines' as a counter, since
7341 ;; the location of the mark may change
7342 (goto-char (setq bol begin))
7343 (setq eol (save-excursion (end-of-line) (point)))
7344 (while (> lines 0)
7345 (when (and (re-search-forward match eol t)
7346 (not (vhdl-in-literal)))
7347 (setq width (- (match-end substr) (match-beginning substr)))
7348 (setq distance (- (match-beginning substr) bol))
7349 (goto-char (match-beginning substr))
7350 (delete-char width)
7351 (insert-char ? (+ (- max distance) spacing)))
7352 (beginning-of-line)
7353 (forward-line)
7354 (setq bol (point)
7355 eol (save-excursion (end-of-line) (point)))
7356 (setq lines (1- lines))))))
7357
7358 (defun vhdl-align-region-groups (beg end &optional spacing
7359 no-message no-comments)
7360 "Align region, treat groups of lines separately."
7361 (interactive "r\nP")
7362 (save-excursion
7363 (let (orig pos)
7364 (goto-char beg)
7365 (beginning-of-line)
7366 (setq orig (point-marker))
7367 (setq beg (point))
7368 (goto-char end)
7369 (setq end (point-marker))
7370 (untabify beg end)
7371 (unless no-message
7372 (when vhdl-progress-interval
7373 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7374 (count-lines (point-min) end) 0))))
7375 (vhdl-fixup-whitespace-region beg end t)
7376 (goto-char beg)
7377 (if (not vhdl-align-groups)
7378 ;; align entire region
7379 (progn (vhdl-align-region-1 beg end spacing)
7380 (unless no-comments
7381 (vhdl-align-inline-comment-region-1 beg end)))
7382 ;; align groups
7383 (while (and (< beg end)
7384 (re-search-forward vhdl-align-group-separate end t))
7385 (setq pos (point-marker))
7386 (vhdl-align-region-1 beg pos spacing)
7387 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7388 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7389 (setq beg (1+ pos))
7390 (goto-char beg))
7391 ;; align last group
7392 (when (< beg end)
7393 (vhdl-align-region-1 beg end spacing)
7394 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7395 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7396 (when vhdl-indent-tabs-mode
7397 (tabify orig end))
7398 (unless no-message
7399 (when vhdl-progress-interval (message "Aligning...done"))
7400 (setq vhdl-progress-info nil)))))
7401
7402 (defun vhdl-align-region (beg end &optional spacing)
7403 "Align region, treat blocks with same indent and argument lists separately."
7404 (interactive "r\nP")
7405 (if (not vhdl-align-same-indent)
7406 ;; align entire region
7407 (vhdl-align-region-groups beg end spacing)
7408 ;; align blocks with same indent and argument lists
7409 (save-excursion
7410 (let ((cur-beg beg)
7411 indent cur-end)
7412 (when vhdl-progress-interval
7413 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7414 (count-lines (point-min) end) 0)))
7415 (goto-char end)
7416 (setq end (point-marker))
7417 (goto-char cur-beg)
7418 (while (< (point) end)
7419 ;; is argument list opening?
7420 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7421 (point) (vhdl-point 'eol)))))
7422 ;; determine region for argument list
7423 (progn (goto-char cur-beg)
7424 (forward-sexp)
7425 (setq cur-end (point))
7426 (beginning-of-line 2))
7427 ;; determine region with same indent
7428 (setq indent (current-indentation))
7429 (setq cur-beg (point))
7430 (setq cur-end (vhdl-point 'bonl))
7431 (beginning-of-line 2)
7432 (while (and (< (point) end)
7433 (or (looking-at "^\\s-*\\(--.*\\)?$")
7434 (= (current-indentation) indent))
7435 (<= (save-excursion
7436 (nth 0 (parse-partial-sexp
7437 (point) (vhdl-point 'eol)))) 0))
7438 (unless (looking-at "^\\s-*$")
7439 (setq cur-end (vhdl-point 'bonl)))
7440 (beginning-of-line 2)))
7441 ;; align region
7442 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7443 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7444 (when vhdl-progress-interval (message "Aligning...done"))
7445 (setq vhdl-progress-info nil)))))
7446
7447 (defun vhdl-align-group (&optional spacing)
7448 "Align group of lines between empty lines."
7449 (interactive)
7450 (vhdl-do-group 'vhdl-align-region spacing))
7451
7452 (defun vhdl-align-list (&optional spacing)
7453 "Align the lines of a list surrounded by a balanced group of parentheses."
7454 (interactive)
7455 (vhdl-do-list 'vhdl-align-region-groups spacing))
7456
7457 (defun vhdl-align-same-indent (&optional spacing)
7458 "Align block of lines with same indent."
7459 (interactive)
7460 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7461
7462 (defun vhdl-align-declarations (&optional spacing)
7463 "Align the lines within the declarative part of a design unit."
7464 (interactive)
7465 (let (beg end)
7466 (vhdl-prepare-search-2
7467 (save-excursion
7468 ;; search for declarative part
7469 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7470 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7471 (setq beg (point))
7472 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7473 (setq end (point)))))
7474 (if beg
7475 (vhdl-align-region-groups beg end spacing)
7476 (error "ERROR: Not within the declarative part of a design unit"))))
7477
7478 (defun vhdl-align-buffer ()
7479 "Align buffer."
7480 (interactive)
7481 (vhdl-align-region (point-min) (point-max)))
7482
7483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7484 ;; Align inline comments
7485
7486 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7487 "Align inline comments in region."
7488 (save-excursion
7489 (let ((start-max comment-column)
7490 (length-max 0)
7491 comment-list start-list tmp-list start length
7492 cur-start prev-start no-code)
7493 (setq spacing (or spacing 2))
7494 (vhdl-prepare-search-2
7495 (goto-char beg)
7496 ;; search for comment start positions and lengths
7497 (while (< (point) end)
7498 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7499 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7500 (not (save-excursion (goto-char (match-beginning 2))
7501 (vhdl-in-literal))))
7502 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7503 (setq length (- (match-end 2) (match-beginning 2)))
7504 (setq start-max (max start start-max))
7505 (setq length-max (max length length-max))
7506 (setq comment-list (cons (cons start length) comment-list)))
7507 (beginning-of-line 2))
7508 (setq comment-list
7509 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7510 ;; reduce start positions
7511 (setq start-list (list (caar comment-list)))
7512 (setq comment-list (cdr comment-list))
7513 (while comment-list
7514 (unless (or (= (caar comment-list) (car start-list))
7515 (<= (+ (car start-list) (cdar comment-list))
7516 end-comment-column))
7517 (setq start-list (cons (caar comment-list) start-list)))
7518 (setq comment-list (cdr comment-list)))
7519 ;; align lines as nicely as possible
7520 (goto-char beg)
7521 (while (< (point) end)
7522 (setq cur-start nil)
7523 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7524 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7525 (not (save-excursion
7526 (goto-char (match-beginning 3))
7527 (vhdl-in-literal))))
7528 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7529 (>= (- (match-end 2) (match-beginning 2))
7530 comment-column))))
7531 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7532 (setq length (- (match-end 3) (match-beginning 3)))
7533 (setq no-code (= (match-beginning 1) (match-end 1)))
7534 ;; insert minimum whitespace
7535 (goto-char (match-end 2))
7536 (delete-region (match-beginning 2) (match-end 2))
7537 (insert-char ?\ spacing)
7538 (setq tmp-list start-list)
7539 ;; insert additional whitespace to align
7540 (setq cur-start
7541 (cond
7542 ;; align comment-only line to inline comment of previous line
7543 ((and no-code prev-start
7544 (<= length (- end-comment-column prev-start)))
7545 prev-start)
7546 ;; align all comments at `start-max' if this is possible
7547 ((<= (+ start-max length-max) end-comment-column)
7548 start-max)
7549 ;; align at `comment-column' if possible
7550 ((and (<= start comment-column)
7551 (<= length (- end-comment-column comment-column)))
7552 comment-column)
7553 ;; align at left-most possible start position otherwise
7554 (t
7555 (while (and tmp-list (< (car tmp-list) start))
7556 (setq tmp-list (cdr tmp-list)))
7557 (car tmp-list))))
7558 (indent-to cur-start))
7559 (setq prev-start cur-start)
7560 (beginning-of-line 2))))))
7561
7562 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7563 "Align inline comments within a region. Groups of code lines separated by
7564 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7565 (interactive "r\nP")
7566 (save-excursion
7567 (let (orig pos)
7568 (goto-char beg)
7569 (beginning-of-line)
7570 (setq orig (point-marker))
7571 (setq beg (point))
7572 (goto-char end)
7573 (setq end (point-marker))
7574 (untabify beg end)
7575 (unless no-message (message "Aligning inline comments..."))
7576 (goto-char beg)
7577 (if (not vhdl-align-groups)
7578 ;; align entire region
7579 (vhdl-align-inline-comment-region-1 beg end spacing)
7580 ;; align groups
7581 (while (and (< beg end)
7582 (re-search-forward vhdl-align-group-separate end t))
7583 (setq pos (point-marker))
7584 (vhdl-align-inline-comment-region-1 beg pos spacing)
7585 (setq beg (1+ pos))
7586 (goto-char beg))
7587 ;; align last group
7588 (when (< beg end)
7589 (vhdl-align-inline-comment-region-1 beg end spacing)))
7590 (when vhdl-indent-tabs-mode
7591 (tabify orig end))
7592 (unless no-message (message "Aligning inline comments...done")))))
7593
7594 (defun vhdl-align-inline-comment-group (&optional spacing)
7595 "Align inline comments within a group of lines between empty lines."
7596 (interactive)
7597 (save-excursion
7598 (let ((start (point))
7599 beg end)
7600 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7601 (point-marker) (point-max)))
7602 (goto-char start)
7603 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7604 (point) (point-min)))
7605 (untabify beg end)
7606 (message "Aligning inline comments...")
7607 (vhdl-align-inline-comment-region-1 beg end)
7608 (when vhdl-indent-tabs-mode
7609 (tabify beg end))
7610 (message "Aligning inline comments...done"))))
7611
7612 (defun vhdl-align-inline-comment-buffer ()
7613 "Align inline comments within buffer. Groups of code lines separated by
7614 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7615 (interactive)
7616 (vhdl-align-inline-comment-region (point-min) (point-max)))
7617
7618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7619 ;; Fixup whitespace
7620
7621 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7622 "Fixup whitespace in region. Surround operator symbols by one space,
7623 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7624 end of line, do nothing in comments and strings."
7625 (interactive "r")
7626 (unless no-message (message "Fixing up whitespace..."))
7627 (save-excursion
7628 (goto-char end)
7629 (setq end (point-marker))
7630 ;; have no space before and one space after `,' and ';'
7631 (goto-char beg)
7632 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7633 (if (match-string 1)
7634 (goto-char (match-end 1))
7635 (replace-match "\\3 " nil nil nil 3)))
7636 ;; have no space after `('
7637 (goto-char beg)
7638 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7639 (if (match-string 1)
7640 (goto-char (match-end 1))
7641 (replace-match "\\2")))
7642 ;; have no space before `)'
7643 (goto-char beg)
7644 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7645 (if (match-string 1)
7646 (goto-char (match-end 1))
7647 (replace-match "\\2")))
7648 ;; surround operator symbols by one space
7649 (goto-char beg)
7650 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7651 (if (match-string 1)
7652 (goto-char (match-end 1))
7653 (replace-match "\\3 \\4 \\5")
7654 (goto-char (match-end 2))))
7655 ;; eliminate multiple spaces and spaces at end of line
7656 (goto-char beg)
7657 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7658 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7659 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7660 (progn (replace-match "" nil nil) t))
7661 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7662 (progn (replace-match ";" nil nil) t))
7663 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7664 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7665 (progn (replace-match " " nil nil) t))
7666 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7667 (progn (replace-match " " nil nil) t))
7668 ; (re-search-forward "[^ \t-]+" end t))))
7669 (re-search-forward "[^ \t\"-]+" end t))))
7670 (unless no-message (message "Fixing up whitespace...done")))
7671
7672 (defun vhdl-fixup-whitespace-buffer ()
7673 "Fixup whitespace in buffer. Surround operator symbols by one space,
7674 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7675 end of line, do nothing in comments."
7676 (interactive)
7677 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7678
7679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7680 ;; Beautify
7681
7682 (defun vhdl-beautify-region (beg end)
7683 "Beautify region by applying indentation, whitespace fixup, alignment, and
7684 case fixing to a region. Calls functions `vhdl-indent-buffer',
7685 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7686 `vhdl-fix-case-buffer'."
7687 (interactive "r")
7688 (setq end (save-excursion (goto-char end) (point-marker)))
7689 (vhdl-indent-region beg end nil)
7690 (let ((vhdl-align-groups t))
7691 (vhdl-align-region beg end))
7692 (vhdl-fix-case-region beg end))
7693
7694 (defun vhdl-beautify-buffer ()
7695 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7696 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7697 buffer."
7698 (interactive)
7699 (vhdl-beautify-region (point-min) (point-max))
7700 (when noninteractive (save-buffer)))
7701
7702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7703 ;; Code filling
7704
7705 (defun vhdl-fill-region (beg end &optional arg)
7706 "Fill lines for a region of code."
7707 (interactive "r\np")
7708 (save-excursion
7709 (goto-char beg)
7710 (let ((margin (if arg (current-indentation) (current-column))))
7711 (goto-char end)
7712 (setq end (point-marker))
7713 ;; remove inline comments, newlines and whitespace
7714 (vhdl-comment-kill-region beg end)
7715 (vhdl-comment-kill-inline-region beg end)
7716 (subst-char-in-region beg (1- end) ?\n ?\ )
7717 (vhdl-fixup-whitespace-region beg end)
7718 ;; wrap and end-comment-column
7719 (goto-char beg)
7720 (while (re-search-forward "\\s-" end t)
7721 (when(> (current-column) vhdl-end-comment-column)
7722 (backward-char)
7723 (when (re-search-backward "\\s-" beg t)
7724 (replace-match "\n")
7725 (indent-to margin)))))))
7726
7727 (defun vhdl-fill-group ()
7728 "Fill group of lines between empty lines."
7729 (interactive)
7730 (vhdl-do-group 'vhdl-fill-region))
7731
7732 (defun vhdl-fill-list ()
7733 "Fill the lines of a list surrounded by a balanced group of parentheses."
7734 (interactive)
7735 (vhdl-do-list 'vhdl-fill-region))
7736
7737 (defun vhdl-fill-same-indent ()
7738 "Fill the lines of block of lines with same indent."
7739 (interactive)
7740 (vhdl-do-same-indent 'vhdl-fill-region))
7741
7742
7743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7744 ;;; Code updating/fixing
7745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7746
7747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7748 ;; Sensitivity list update
7749
7750 ;; Strategy:
7751 ;; - no sensitivity list is generated for processes with wait statements
7752 ;; - otherwise, do the following:
7753 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7754 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7755 ;; manually entered global signals)
7756 ;; 3. signals from 1. and 2. form the list of visible signals
7757 ;; 4. search for if/elsif conditions containing an event (sequential code)
7758 ;; 5. scan for strings that are within syntactical regions where signals are
7759 ;; read but not within sequential code, and that correspond to visible
7760 ;; signals
7761 ;; 6. replace sensitivity list by list of signals from 5.
7762
7763 (defun vhdl-update-sensitivity-list-process ()
7764 "Update sensitivity list of current process."
7765 (interactive)
7766 (save-excursion
7767 (vhdl-prepare-search-2
7768 (end-of-line)
7769 ;; look whether in process
7770 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7771 (equal (upcase (match-string 2)) "PROCESS")
7772 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7773 (error "ERROR: Not within a process")
7774 (message "Updating sensitivity list...")
7775 (vhdl-update-sensitivity-list)
7776 (message "Updating sensitivity list...done")))))
7777
7778 (defun vhdl-update-sensitivity-list-buffer ()
7779 "Update sensitivity list of all processes in current buffer."
7780 (interactive)
7781 (save-excursion
7782 (vhdl-prepare-search-2
7783 (goto-char (point-min))
7784 (message "Updating sensitivity lists...")
7785 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7786 (goto-char (match-beginning 0))
7787 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7788 (message "Updating sensitivity lists...done"))))
7789
7790 (defun vhdl-update-sensitivity-list ()
7791 "Update sensitivity list."
7792 (let ((proc-beg (point))
7793 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7794 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7795 seq-region-list)
7796 (cond
7797 ;; search for wait statement (no sensitivity list allowed)
7798 ((progn (goto-char proc-mid)
7799 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7800 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7801 ;; combinational process (update sensitivity list)
7802 (t
7803 (let
7804 ;; scan for visible signals
7805 ((visible-list (vhdl-get-visible-signals))
7806 ;; define syntactic regions where signals are read
7807 (scan-regions-list
7808 '(;; right-hand side of signal/variable assignment
7809 ;; (special case: "<=" is relational operator in a condition)
7810 ((re-search-forward "[<:]=" proc-end t)
7811 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7812 ;; if condition
7813 ((re-search-forward "^\\s-*if\\>" proc-end t)
7814 (re-search-forward "\\<then\\>" proc-end t))
7815 ;; elsif condition
7816 ((re-search-forward "\\<elsif\\>" proc-end t)
7817 (re-search-forward "\\<then\\>" proc-end t))
7818 ;; while loop condition
7819 ((re-search-forward "^\\s-*while\\>" proc-end t)
7820 (re-search-forward "\\<loop\\>" proc-end t))
7821 ;; exit/next condition
7822 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7823 (re-search-forward ";" proc-end t))
7824 ;; assert condition
7825 ((re-search-forward "\\<assert\\>" proc-end t)
7826 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7827 ;; case expression
7828 ((re-search-forward "^\\s-*case\\>" proc-end t)
7829 (re-search-forward "\\<is\\>" proc-end t))
7830 ;; parameter list of procedure call
7831 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7832 (1- (point)))
7833 (progn (backward-char) (forward-sexp)
7834 (while (looking-at "(") (forward-sexp)) (point)))))
7835 name read-list sens-list signal-list
7836 sens-beg sens-end beg end margin)
7837 ;; scan for signals in old sensitivity list
7838 (goto-char proc-beg)
7839 (re-search-forward "\\<process\\>" proc-mid t)
7840 (if (not (looking-at "[ \t\n]*("))
7841 (setq sens-beg (point))
7842 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7843 (goto-char (match-end 1))
7844 (forward-sexp)
7845 (setq sens-end (1- (point)))
7846 (goto-char sens-beg)
7847 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7848 (setq sens-list
7849 (cons (downcase (match-string 0)) sens-list))
7850 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7851 (setq signal-list (append visible-list sens-list))
7852 ;; search for sequential parts
7853 (goto-char proc-mid)
7854 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7855 (setq end (re-search-forward "\\<then\\>" proc-end t))
7856 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7857 (goto-char end)
7858 (backward-word 1)
7859 (vhdl-forward-sexp)
7860 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7861 (beginning-of-line)))
7862 ;; scan for signals read in process
7863 (while scan-regions-list
7864 (goto-char proc-mid)
7865 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7866 (setq end (eval (nth 1 (car scan-regions-list)))))
7867 (goto-char beg)
7868 (unless (or (vhdl-in-literal)
7869 (and seq-region-list
7870 (let ((tmp-list seq-region-list))
7871 (while (and tmp-list
7872 (< (point) (caar tmp-list)))
7873 (setq tmp-list (cdr tmp-list)))
7874 (and tmp-list (< (point) (cdar tmp-list))))))
7875 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7876 (setq name (match-string 1))
7877 (when (and (not (match-string 4)) ; not when formal parameter
7878 (not (and (match-string 3) ; not event attribute
7879 (not (member (downcase (match-string 3))
7880 '("event" "last_event" "transaction")))))
7881 (member (downcase name) signal-list))
7882 (unless (member-ignore-case name read-list)
7883 (setq read-list (cons name read-list))))
7884 (goto-char (match-end 1)))))
7885 (setq scan-regions-list (cdr scan-regions-list)))
7886 ;; update sensitivity list
7887 (goto-char sens-beg)
7888 (if sens-end
7889 (delete-region sens-beg sens-end)
7890 (when read-list
7891 (insert " ()") (backward-char)))
7892 (setq read-list (sort read-list 'string<))
7893 (when read-list
7894 (setq margin (current-column))
7895 (insert (car read-list))
7896 (setq read-list (cdr read-list))
7897 (while read-list
7898 (insert ",")
7899 (if (<= (+ (current-column) (length (car read-list)) 2)
7900 end-comment-column)
7901 (insert " ")
7902 (insert "\n") (indent-to margin))
7903 (insert (car read-list))
7904 (setq read-list (cdr read-list)))))))))
7905
7906 (defun vhdl-get-visible-signals ()
7907 "Get all signals visible in the current block."
7908 (let (beg end signal-list entity-name file-name)
7909 (vhdl-prepare-search-2
7910 ;; get entity name
7911 (save-excursion
7912 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7913 (not (equal "END" (upcase (match-string 1))))
7914 (setq entity-name (match-string 2)))
7915 (error "ERROR: Not within an architecture")))
7916 ;; search for signals declared in entity port clause
7917 (save-excursion
7918 (goto-char (point-min))
7919 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7920 (setq file-name
7921 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7922 "." (file-name-extension (buffer-file-name)))))
7923 (vhdl-visit-file
7924 file-name t
7925 (vhdl-prepare-search-2
7926 (goto-char (point-min))
7927 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7928 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7929 (when (setq beg (re-search-forward
7930 "^\\s-*port[ \t\n]*("
7931 (save-excursion
7932 (re-search-forward "^end\\>" nil t)) t))
7933 (setq end (save-excursion
7934 (backward-char) (forward-sexp) (point)))
7935 (vhdl-forward-syntactic-ws)
7936 (while (< (point) end)
7937 (when (looking-at "signal[ \t\n]+")
7938 (goto-char (match-end 0)))
7939 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7940 (setq signal-list
7941 (cons (downcase (match-string 1)) signal-list))
7942 (goto-char (match-end 0))
7943 (vhdl-forward-syntactic-ws))
7944 (re-search-forward ";" end 1)
7945 (vhdl-forward-syntactic-ws)))))))
7946 ;; search for signals declared in architecture declarative part
7947 (save-excursion
7948 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7949 (not (equal "END" (upcase (match-string 1))))
7950 (setq end (re-search-forward "^begin\\>" nil t))))
7951 (error "ERROR: No architecture declarative part found")
7952 ;; scan for all declared signal and alias names
7953 (goto-char beg)
7954 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7955 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7956 (if (match-string 2)
7957 ;; scan signal name
7958 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7959 (setq signal-list
7960 (cons (downcase (match-string 1)) signal-list))
7961 (goto-char (match-end 0)))
7962 ;; scan alias name, check is alias of (declared) signal
7963 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7964 (member (downcase (match-string 2)) signal-list))
7965 (setq signal-list
7966 (cons (downcase (match-string 1)) signal-list))
7967 (goto-char (match-end 0))))
7968 (setq beg (point))))))
7969 ;; search for signals declared in surrounding block declarative parts
7970 (save-excursion
7971 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7972 (match-string 2))
7973 (goto-char (match-end 2))
7974 (vhdl-backward-sexp)
7975 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7976 beg)
7977 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7978 ;; scan for all declared signal names
7979 (goto-char beg)
7980 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7981 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7982 (if (match-string 2)
7983 ;; scan signal name
7984 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7985 (setq signal-list
7986 (cons (downcase (match-string 1)) signal-list))
7987 (goto-char (match-end 0)))
7988 ;; scan alias name, check is alias of (declared) signal
7989 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7990 (member (downcase (match-string 2)) signal-list))
7991 (setq signal-list
7992 (cons (downcase (match-string 1)) signal-list))
7993 (goto-char (match-end 0))))))
7994 (goto-char beg)))
7995 signal-list)))
7996
7997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7998 ;; Generic/port clause fixing
7999
8000 (defun vhdl-fix-clause ()
8001 "Fix closing parenthesis within generic/port clause."
8002 (interactive)
8003 (save-excursion
8004 (vhdl-prepare-search-2
8005 (let ((pos (point))
8006 beg end)
8007 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8008 (error "ERROR: Not within a generic/port clause")
8009 ;; search for end of clause
8010 (goto-char (match-end 0))
8011 (setq beg (1- (point)))
8012 (vhdl-forward-syntactic-ws)
8013 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8014 (goto-char (1- (match-end 0)))
8015 (setq end (point-marker))
8016 (forward-char)
8017 (vhdl-forward-syntactic-ws))
8018 (goto-char end)
8019 (when (> pos (save-excursion (end-of-line) (point)))
8020 (error "ERROR: Not within a generic/port clause"))
8021 ;; delete closing parenthesis on separate line (not supported style)
8022 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8023 (vhdl-line-kill)
8024 (vhdl-backward-syntactic-ws)
8025 (setq end (point-marker))
8026 (insert ";"))
8027 ;; delete superfluous parentheses
8028 (while (progn (goto-char beg)
8029 (condition-case () (forward-sexp)
8030 (error (goto-char (point-max))))
8031 (< (point) end))
8032 (delete-backward-char 1))
8033 ;; add closing parenthesis
8034 (when (> (point) end)
8035 (goto-char end)
8036 (insert ")")))))))
8037
8038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8039 ;; Miscellaneous
8040
8041 (defun vhdl-remove-trailing-spaces ()
8042 "Remove trailing spaces in the whole buffer."
8043 (interactive)
8044 (save-match-data
8045 (save-excursion
8046 (goto-char (point-min))
8047 (while (re-search-forward "[ \t]+$" (point-max) t)
8048 (unless (vhdl-in-literal)
8049 (replace-match "" nil nil))))))
8050
8051
8052 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8053 ;;; Electrification
8054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8055
8056 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8057 "Syntax of prompt inserted by template generators.")
8058
8059 (defvar vhdl-template-invoked-by-hook nil
8060 "Indicates whether a template has been invoked by a hook or by key or menu.
8061 Used for undoing after template abortion.")
8062
8063 ;; correct different behavior of function `unread-command-events' in XEmacs
8064 (defun vhdl-character-to-event (arg))
8065 (defalias 'vhdl-character-to-event
8066 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8067
8068 (defun vhdl-work-library ()
8069 "Return the working library name of the current project or \"work\" if no
8070 project is defined."
8071 (vhdl-resolve-env-variable
8072 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8073
8074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8075 ;; Enabling/disabling
8076
8077 (defun vhdl-mode-line-update ()
8078 "Update the modeline string for VHDL major mode."
8079 (setq mode-name (concat "VHDL"
8080 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8081 (and vhdl-electric-mode "e")
8082 (and vhdl-stutter-mode "s")))
8083 (force-mode-line-update t))
8084
8085 (defun vhdl-electric-mode (arg)
8086 "Toggle VHDL electric mode.
8087 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8088 (interactive "P")
8089 (setq vhdl-electric-mode
8090 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8091 ((> arg 0) t) (t nil)))
8092 (vhdl-mode-line-update))
8093
8094 (defun vhdl-stutter-mode (arg)
8095 "Toggle VHDL stuttering mode.
8096 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8097 (interactive "P")
8098 (setq vhdl-stutter-mode
8099 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8100 ((> arg 0) t) (t nil)))
8101 (vhdl-mode-line-update))
8102
8103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8104 ;; Stuttering
8105
8106 (defun vhdl-electric-dash (count)
8107 "-- starts a comment, --- draws a horizontal line,
8108 ---- starts a display comment."
8109 (interactive "p")
8110 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8111 (cond
8112 ((and abbrev-start-location (= abbrev-start-location (point)))
8113 (setq abbrev-start-location nil)
8114 (goto-char last-abbrev-location)
8115 (beginning-of-line nil)
8116 (vhdl-comment-display))
8117 ((/= (preceding-char) ?-) ; standard dash (minus)
8118 (self-insert-command count))
8119 (t (self-insert-command count)
8120 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8121 (let ((next-input (read-char)))
8122 (if (= next-input ?-) ; triple dash
8123 (progn
8124 (vhdl-comment-display-line)
8125 (message
8126 "Enter '-' for display comment, else continue coding")
8127 (let ((next-input (read-char)))
8128 (if (= next-input ?-) ; four dashes
8129 (vhdl-comment-display t)
8130 (setq unread-command-events ; pushback the char
8131 (list (vhdl-character-to-event next-input))))))
8132 (setq unread-command-events ; pushback the char
8133 (list (vhdl-character-to-event next-input)))
8134 (vhdl-comment-insert)))))
8135 (self-insert-command count)))
8136
8137 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8138 (interactive "p")
8139 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8140 (if (= (preceding-char) ?\()
8141 (progn (delete-char -1) (insert-char ?\[ 1))
8142 (insert-char ?\( 1))
8143 (self-insert-command count)))
8144
8145 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8146 (interactive "p")
8147 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8148 (progn
8149 (if (= (preceding-char) ?\))
8150 (progn (delete-char -1) (insert-char ?\] 1))
8151 (insert-char ?\) 1))
8152 (blink-matching-open))
8153 (self-insert-command count)))
8154
8155 (defun vhdl-electric-quote (count) "'' --> \""
8156 (interactive "p")
8157 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8158 (if (= (preceding-char) last-input-char)
8159 (progn (delete-backward-char 1) (insert-char ?\" 1))
8160 (insert-char ?\' 1))
8161 (self-insert-command count)))
8162
8163 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8164 (interactive "p")
8165 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8166 (cond ((= (preceding-char) last-input-char)
8167 (progn (delete-char -1)
8168 (unless (eq (preceding-char) ? ) (insert " "))
8169 (insert ": ")
8170 (setq this-command 'vhdl-electric-colon)))
8171 ((and
8172 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8173 (progn (delete-char -1) (insert "= ")))
8174 (t (insert-char ?\; 1)))
8175 (self-insert-command count)))
8176
8177 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8178 (interactive "p")
8179 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8180 (cond ((= (preceding-char) last-input-char)
8181 (progn (delete-char -1)
8182 (unless (eq (preceding-char) ? ) (insert " "))
8183 (insert "<= ")))
8184 (t (insert-char ?\, 1)))
8185 (self-insert-command count)))
8186
8187 (defun vhdl-electric-period (count) "'..' --> ' => '"
8188 (interactive "p")
8189 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8190 (cond ((= (preceding-char) last-input-char)
8191 (progn (delete-char -1)
8192 (unless (eq (preceding-char) ? ) (insert " "))
8193 (insert "=> ")))
8194 (t (insert-char ?\. 1)))
8195 (self-insert-command count)))
8196
8197 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8198 (interactive "p")
8199 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8200 (cond ((= (preceding-char) last-input-char)
8201 (progn (delete-char -1)
8202 (unless (eq (preceding-char) ? ) (insert " "))
8203 (insert "== ")))
8204 (t (insert-char ?\= 1)))
8205 (self-insert-command count)))
8206
8207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8208 ;; VHDL templates
8209
8210 (defun vhdl-template-paired-parens ()
8211 "Insert a pair of round parentheses, placing point between them."
8212 (interactive)
8213 (insert "()")
8214 (backward-char))
8215
8216 (defun vhdl-template-alias ()
8217 "Insert alias declaration."
8218 (interactive)
8219 (let ((start (point)))
8220 (vhdl-insert-keyword "ALIAS ")
8221 (when (vhdl-template-field "name" nil t start (point))
8222 (insert " : ")
8223 (unless (vhdl-template-field
8224 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8225 nil t)
8226 (delete-backward-char 3))
8227 (vhdl-insert-keyword " IS ")
8228 (vhdl-template-field "name" ";")
8229 (vhdl-comment-insert-inline))))
8230
8231 (defun vhdl-template-architecture ()
8232 "Insert architecture."
8233 (interactive)
8234 (let ((margin (current-indentation))
8235 (start (point))
8236 arch-name)
8237 (vhdl-insert-keyword "ARCHITECTURE ")
8238 (when (setq arch-name
8239 (vhdl-template-field "name" nil t start (point)))
8240 (vhdl-insert-keyword " OF ")
8241 (if (save-excursion
8242 (vhdl-prepare-search-1
8243 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8244 (insert (match-string 1))
8245 (vhdl-template-field "entity name"))
8246 (vhdl-insert-keyword " IS\n")
8247 (vhdl-template-begin-end
8248 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8249 (memq vhdl-insert-empty-lines '(unit all))))))
8250
8251 (defun vhdl-template-array (kind &optional secondary)
8252 "Insert array type definition."
8253 (interactive)
8254 (let ((start (point)))
8255 (vhdl-insert-keyword "ARRAY (")
8256 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8257 secondary)
8258 (vhdl-insert-keyword ") OF ")
8259 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8260 (vhdl-insert-keyword ";"))))
8261
8262 (defun vhdl-template-assert ()
8263 "Insert an assertion statement."
8264 (interactive)
8265 (let ((start (point)))
8266 (vhdl-insert-keyword "ASSERT ")
8267 (when vhdl-conditions-in-parenthesis (insert "("))
8268 (when (vhdl-template-field "condition (negated)" nil t start (point))
8269 (when vhdl-conditions-in-parenthesis (insert ")"))
8270 (setq start (point))
8271 (vhdl-insert-keyword " REPORT ")
8272 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8273 (delete-region start (point)))
8274 (setq start (point))
8275 (vhdl-insert-keyword " SEVERITY ")
8276 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8277 (delete-region start (point)))
8278 (insert ";"))))
8279
8280 (defun vhdl-template-attribute ()
8281 "Insert an attribute declaration or specification."
8282 (interactive)
8283 (if (eq (vhdl-decision-query
8284 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8285 (vhdl-template-attribute-spec)
8286 (vhdl-template-attribute-decl)))
8287
8288 (defun vhdl-template-attribute-decl ()
8289 "Insert an attribute declaration."
8290 (interactive)
8291 (let ((start (point)))
8292 (vhdl-insert-keyword "ATTRIBUTE ")
8293 (when (vhdl-template-field "name" " : " t start (point))
8294 (vhdl-template-field "type" ";")
8295 (vhdl-comment-insert-inline))))
8296
8297 (defun vhdl-template-attribute-spec ()
8298 "Insert an attribute specification."
8299 (interactive)
8300 (let ((start (point)))
8301 (vhdl-insert-keyword "ATTRIBUTE ")
8302 (when (vhdl-template-field "name" nil t start (point))
8303 (vhdl-insert-keyword " OF ")
8304 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8305 (vhdl-template-field "entity class")
8306 (vhdl-insert-keyword " IS ")
8307 (vhdl-template-field "expression" ";"))))
8308
8309 (defun vhdl-template-block ()
8310 "Insert a block."
8311 (interactive)
8312 (let ((margin (current-indentation))
8313 (start (point))
8314 label)
8315 (vhdl-insert-keyword ": BLOCK ")
8316 (goto-char start)
8317 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8318 (forward-word 1)
8319 (forward-char 1)
8320 (insert "(")
8321 (if (vhdl-template-field "[guard expression]" nil t)
8322 (insert ")")
8323 (delete-char -2))
8324 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8325 (insert "\n")
8326 (vhdl-template-begin-end "BLOCK" label margin)
8327 (vhdl-comment-block))))
8328
8329 (defun vhdl-template-block-configuration ()
8330 "Insert a block configuration statement."
8331 (interactive)
8332 (let ((margin (current-indentation))
8333 (start (point)))
8334 (vhdl-insert-keyword "FOR ")
8335 (when (vhdl-template-field "block name" nil t start (point))
8336 (vhdl-insert-keyword "\n\n")
8337 (indent-to margin)
8338 (vhdl-insert-keyword "END FOR;")
8339 (end-of-line 0)
8340 (indent-to (+ margin vhdl-basic-offset)))))
8341
8342 (defun vhdl-template-break ()
8343 "Insert a break statement."
8344 (interactive)
8345 (let (position)
8346 (vhdl-insert-keyword "BREAK")
8347 (setq position (point))
8348 (insert " ")
8349 (while (or
8350 (progn (vhdl-insert-keyword "FOR ")
8351 (if (vhdl-template-field "[quantity name]" " USE " t)
8352 (progn (vhdl-template-field "quantity name" " => ") t)
8353 (delete-region (point)
8354 (progn (forward-word -1) (point)))
8355 nil))
8356 (vhdl-template-field "[quantity name]" " => " t))
8357 (vhdl-template-field "expression")
8358 (setq position (point))
8359 (insert ", "))
8360 (delete-region position (point))
8361 (unless (vhdl-sequential-statement-p)
8362 (vhdl-insert-keyword " ON ")
8363 (if (vhdl-template-field "[sensitivity list]" nil t)
8364 (setq position (point))
8365 (delete-region position (point))))
8366 (vhdl-insert-keyword " WHEN ")
8367 (when vhdl-conditions-in-parenthesis (insert "("))
8368 (if (vhdl-template-field "[condition]" nil t)
8369 (when vhdl-conditions-in-parenthesis (insert ")"))
8370 (delete-region position (point)))
8371 (insert ";")))
8372
8373 (defun vhdl-template-case (&optional kind)
8374 "Insert a case statement."
8375 (interactive)
8376 (let ((margin (current-indentation))
8377 (start (point))
8378 label)
8379 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8380 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8381 (vhdl-insert-keyword "CASE ")
8382 (vhdl-insert-keyword ": CASE ")
8383 (goto-char start)
8384 (setq label (vhdl-template-field "[label]" nil t))
8385 (unless label (delete-char 2))
8386 (forward-word 1)
8387 (forward-char 1))
8388 (when (vhdl-template-field "expression" nil t start (point))
8389 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8390 (indent-to margin)
8391 (vhdl-insert-keyword "END CASE")
8392 (when label (insert " " label))
8393 (insert ";")
8394 (forward-line -1)
8395 (indent-to (+ margin vhdl-basic-offset))
8396 (vhdl-insert-keyword "WHEN ")
8397 (let ((position (point)))
8398 (insert " => ;\n")
8399 (indent-to (+ margin vhdl-basic-offset))
8400 (vhdl-insert-keyword "WHEN OTHERS => null;")
8401 (goto-char position)))))
8402
8403 (defun vhdl-template-case-is ()
8404 "Insert a sequential case statement."
8405 (interactive)
8406 (vhdl-template-case 'is))
8407
8408 (defun vhdl-template-case-use ()
8409 "Insert a simultaneous case statement."
8410 (interactive)
8411 (vhdl-template-case 'use))
8412
8413 (defun vhdl-template-component ()
8414 "Insert a component declaration."
8415 (interactive)
8416 (vhdl-template-component-decl))
8417
8418 (defun vhdl-template-component-conf ()
8419 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8420 since these are almost equivalent)."
8421 (interactive)
8422 (let ((margin (current-indentation))
8423 (result (vhdl-template-configuration-spec t)))
8424 (when result
8425 (insert "\n")
8426 (indent-to margin)
8427 (vhdl-insert-keyword "END FOR;")
8428 (when (eq result 'no-use)
8429 (end-of-line -0)))))
8430
8431 (defun vhdl-template-component-decl ()
8432 "Insert a component declaration."
8433 (interactive)
8434 (let ((margin (current-indentation))
8435 (start (point))
8436 name end-column)
8437 (vhdl-insert-keyword "COMPONENT ")
8438 (when (setq name (vhdl-template-field "name" nil t start (point)))
8439 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8440 (insert "\n\n")
8441 (indent-to margin)
8442 (vhdl-insert-keyword "END COMPONENT")
8443 (unless (vhdl-standard-p '87) (insert " " name))
8444 (insert ";")
8445 (setq end-column (current-column))
8446 (end-of-line -0)
8447 (indent-to (+ margin vhdl-basic-offset))
8448 (vhdl-template-generic-list t t)
8449 (insert "\n")
8450 (indent-to (+ margin vhdl-basic-offset))
8451 (vhdl-template-port-list t)
8452 (beginning-of-line 2)
8453 (forward-char end-column))))
8454
8455 (defun vhdl-template-component-inst ()
8456 "Insert a component instantiation statement."
8457 (interactive)
8458 (let ((margin (current-indentation))
8459 (start (point))
8460 unit position)
8461 (when (vhdl-template-field "instance label" nil t start (point))
8462 (insert ": ")
8463 (if (not (vhdl-use-direct-instantiation))
8464 (vhdl-template-field "component name")
8465 ;; direct instantiation
8466 (setq unit (vhdl-template-field
8467 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8468 (setq unit (upcase (or unit "")))
8469 (cond ((equal unit "ENTITY")
8470 (vhdl-template-field "library name" "." nil nil nil nil
8471 (vhdl-work-library))
8472 (vhdl-template-field "entity name" "(")
8473 (if (vhdl-template-field "[architecture name]" nil t)
8474 (insert ")")
8475 (delete-char -1)))
8476 ((equal unit "CONFIGURATION")
8477 (vhdl-template-field "library name" "." nil nil nil nil
8478 (vhdl-work-library))
8479 (vhdl-template-field "configuration name"))
8480 (t (vhdl-template-field "component name"))))
8481 (insert "\n")
8482 (indent-to (+ margin vhdl-basic-offset))
8483 (setq position (point))
8484 (vhdl-insert-keyword "GENERIC ")
8485 (when (vhdl-template-map position t t)
8486 (insert "\n")
8487 (indent-to (+ margin vhdl-basic-offset)))
8488 (setq position (point))
8489 (vhdl-insert-keyword "PORT ")
8490 (unless (vhdl-template-map position t t)
8491 (delete-region (line-beginning-position) (point))
8492 (delete-char -1))
8493 (insert ";"))))
8494
8495 (defun vhdl-template-conditional-signal-asst ()
8496 "Insert a conditional signal assignment."
8497 (interactive)
8498 (when (vhdl-template-field "target signal")
8499 (insert " <= ")
8500 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8501 ; (insert " "))
8502 (let ((margin (current-column))
8503 (start (point))
8504 position)
8505 (vhdl-template-field "waveform")
8506 (setq position (point))
8507 (vhdl-insert-keyword " WHEN ")
8508 (when vhdl-conditions-in-parenthesis (insert "("))
8509 (while (and (vhdl-template-field "[condition]" nil t)
8510 (progn
8511 (when vhdl-conditions-in-parenthesis (insert ")"))
8512 (setq position (point))
8513 (vhdl-insert-keyword " ELSE")
8514 (insert "\n")
8515 (indent-to margin)
8516 (vhdl-template-field "[waveform]" nil t)))
8517 (setq position (point))
8518 (vhdl-insert-keyword " WHEN ")
8519 (when vhdl-conditions-in-parenthesis (insert "(")))
8520 (delete-region position (point))
8521 (insert ";")
8522 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8523
8524 (defun vhdl-template-configuration ()
8525 "Insert a configuration specification if within an architecture,
8526 a block or component configuration if within a configuration declaration,
8527 a configuration declaration if not within a design unit."
8528 (interactive)
8529 (vhdl-prepare-search-1
8530 (cond
8531 ((and (save-excursion ; architecture body
8532 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8533 (equal "ARCHITECTURE" (upcase (match-string 1))))
8534 (vhdl-template-configuration-spec))
8535 ((and (save-excursion ; configuration declaration
8536 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8537 (equal "CONFIGURATION" (upcase (match-string 1))))
8538 (if (eq (vhdl-decision-query
8539 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8540 (vhdl-template-component-conf)
8541 (vhdl-template-block-configuration)))
8542 (t (vhdl-template-configuration-decl))))) ; otherwise
8543
8544 (defun vhdl-template-configuration-spec (&optional optional-use)
8545 "Insert a configuration specification."
8546 (interactive)
8547 (let ((margin (current-indentation))
8548 (start (point))
8549 aspect position)
8550 (vhdl-insert-keyword "FOR ")
8551 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8552 t start (point))
8553 (vhdl-template-field "component name" "\n")
8554 (indent-to (+ margin vhdl-basic-offset))
8555 (setq start (point))
8556 (vhdl-insert-keyword "USE ")
8557 (if (and optional-use
8558 (not (setq aspect (vhdl-template-field
8559 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8560 (progn (delete-region start (point)) 'no-use)
8561 (unless optional-use
8562 (setq aspect (vhdl-template-field
8563 "ENTITY | CONFIGURATION | OPEN" " ")))
8564 (setq aspect (upcase (or aspect "")))
8565 (cond ((equal aspect "ENTITY")
8566 (vhdl-template-field "library name" "." nil nil nil nil
8567 (vhdl-work-library))
8568 (vhdl-template-field "entity name" "(")
8569 (if (vhdl-template-field "[architecture name]" nil t)
8570 (insert ")")
8571 (delete-char -1))
8572 (insert "\n")
8573 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8574 (setq position (point))
8575 (vhdl-insert-keyword "GENERIC ")
8576 (when (vhdl-template-map position t t)
8577 (insert "\n")
8578 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8579 (setq position (point))
8580 (vhdl-insert-keyword "PORT ")
8581 (unless (vhdl-template-map position t t)
8582 (delete-region (line-beginning-position) (point))
8583 (delete-char -1))
8584 (insert ";")
8585 t)
8586 ((equal aspect "CONFIGURATION")
8587 (vhdl-template-field "library name" "." nil nil nil nil
8588 (vhdl-work-library))
8589 (vhdl-template-field "configuration name" ";"))
8590 (t (delete-backward-char 1) (insert ";") t))))))
8591
8592
8593 (defun vhdl-template-configuration-decl ()
8594 "Insert a configuration declaration."
8595 (interactive)
8596 (let ((margin (current-indentation))
8597 (start (point))
8598 entity-exists string name position)
8599 (vhdl-insert-keyword "CONFIGURATION ")
8600 (when (setq name (vhdl-template-field "name" nil t start (point)))
8601 (vhdl-insert-keyword " OF ")
8602 (save-excursion
8603 (vhdl-prepare-search-1
8604 (setq entity-exists (vhdl-re-search-backward
8605 "\\<entity \\(\\w*\\) is\\>" nil t))
8606 (setq string (match-string 1))))
8607 (if (and entity-exists (not (equal string "")))
8608 (insert string)
8609 (vhdl-template-field "entity name"))
8610 (vhdl-insert-keyword " IS\n")
8611 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8612 (indent-to (+ margin vhdl-basic-offset))
8613 (setq position (point))
8614 (insert "\n")
8615 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8616 (indent-to margin)
8617 (vhdl-insert-keyword "END ")
8618 (unless (vhdl-standard-p '87)
8619 (vhdl-insert-keyword "CONFIGURATION "))
8620 (insert name ";")
8621 (goto-char position))))
8622
8623 (defun vhdl-template-constant ()
8624 "Insert a constant declaration."
8625 (interactive)
8626 (let ((start (point))
8627 (in-arglist (vhdl-in-argument-list-p)))
8628 (vhdl-insert-keyword "CONSTANT ")
8629 (when (vhdl-template-field "name" nil t start (point))
8630 (insert " : ")
8631 (when in-arglist (vhdl-insert-keyword "IN "))
8632 (vhdl-template-field "type")
8633 (if in-arglist
8634 (progn (insert ";")
8635 (vhdl-comment-insert-inline))
8636 (let ((position (point)))
8637 (insert " := ")
8638 (unless (vhdl-template-field "[initialization]" nil t)
8639 (delete-region position (point)))
8640 (insert ";")
8641 (vhdl-comment-insert-inline))))))
8642
8643 (defun vhdl-template-default ()
8644 "Insert nothing."
8645 (interactive)
8646 (insert " ")
8647 (unexpand-abbrev)
8648 (backward-word 1)
8649 (vhdl-case-word 1)
8650 (forward-char 1))
8651
8652 (defun vhdl-template-default-indent ()
8653 "Insert nothing and indent."
8654 (interactive)
8655 (insert " ")
8656 (unexpand-abbrev)
8657 (backward-word 1)
8658 (vhdl-case-word 1)
8659 (forward-char 1)
8660 (indent-according-to-mode))
8661
8662 (defun vhdl-template-disconnect ()
8663 "Insert a disconnect statement."
8664 (interactive)
8665 (let ((start (point)))
8666 (vhdl-insert-keyword "DISCONNECT ")
8667 (when (vhdl-template-field "signal names | OTHERS | ALL"
8668 " : " t start (point))
8669 (vhdl-template-field "type")
8670 (vhdl-insert-keyword " AFTER ")
8671 (vhdl-template-field "time expression" ";"))))
8672
8673 (defun vhdl-template-else ()
8674 "Insert an else statement."
8675 (interactive)
8676 (let (margin)
8677 (vhdl-prepare-search-1
8678 (vhdl-insert-keyword "ELSE")
8679 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8680 (equal "WHEN" (upcase (match-string 1))))
8681 (insert " ")
8682 (indent-according-to-mode)
8683 (setq margin (current-indentation))
8684 (insert "\n")
8685 (indent-to (+ margin vhdl-basic-offset))))))
8686
8687 (defun vhdl-template-elsif ()
8688 "Insert an elsif statement."
8689 (interactive)
8690 (let ((start (point))
8691 margin)
8692 (vhdl-insert-keyword "ELSIF ")
8693 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8694 (when vhdl-conditions-in-parenthesis (insert "("))
8695 (when (vhdl-template-field "condition" nil t start (point))
8696 (when vhdl-conditions-in-parenthesis (insert ")"))
8697 (indent-according-to-mode)
8698 (setq margin (current-indentation))
8699 (vhdl-insert-keyword
8700 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8701 (indent-to (+ margin vhdl-basic-offset))))))
8702
8703 (defun vhdl-template-entity ()
8704 "Insert an entity."
8705 (interactive)
8706 (let ((margin (current-indentation))
8707 (start (point))
8708 name end-column)
8709 (vhdl-insert-keyword "ENTITY ")
8710 (when (setq name (vhdl-template-field "name" nil t start (point)))
8711 (vhdl-insert-keyword " IS\n\n")
8712 (indent-to margin)
8713 (vhdl-insert-keyword "END ")
8714 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8715 (insert name ";")
8716 (setq end-column (current-column))
8717 (end-of-line -0)
8718 (indent-to (+ margin vhdl-basic-offset))
8719 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8720 (indent-to (+ margin vhdl-basic-offset))
8721 (when (vhdl-template-generic-list t)
8722 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8723 (insert "\n")
8724 (indent-to (+ margin vhdl-basic-offset))
8725 (when (vhdl-template-port-list t)
8726 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8727 (beginning-of-line 2)
8728 (forward-char end-column))))
8729
8730 (defun vhdl-template-exit ()
8731 "Insert an exit statement."
8732 (interactive)
8733 (let ((start (point)))
8734 (vhdl-insert-keyword "EXIT ")
8735 (if (vhdl-template-field "[loop label]" nil t start (point))
8736 (let ((position (point)))
8737 (vhdl-insert-keyword " WHEN ")
8738 (when vhdl-conditions-in-parenthesis (insert "("))
8739 (if (vhdl-template-field "[condition]" nil t)
8740 (when vhdl-conditions-in-parenthesis (insert ")"))
8741 (delete-region position (point))))
8742 (delete-char -1))
8743 (insert ";")))
8744
8745 (defun vhdl-template-file ()
8746 "Insert a file declaration."
8747 (interactive)
8748 (let ((start (point)))
8749 (vhdl-insert-keyword "FILE ")
8750 (when (vhdl-template-field "name" nil t start (point))
8751 (insert " : ")
8752 (vhdl-template-field "type")
8753 (unless (vhdl-standard-p '87)
8754 (vhdl-insert-keyword " OPEN ")
8755 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8756 nil t)
8757 (delete-backward-char 6)))
8758 (vhdl-insert-keyword " IS ")
8759 (when (vhdl-standard-p '87)
8760 (vhdl-template-field "[IN | OUT]" " " t))
8761 (vhdl-template-field "filename-string" nil nil nil nil t)
8762 (insert ";")
8763 (vhdl-comment-insert-inline))))
8764
8765 (defun vhdl-template-for ()
8766 "Insert a block or component configuration if within a configuration
8767 declaration, a configuration specification if within an architecture
8768 declarative part (and not within a subprogram), a for-loop if within a
8769 sequential statement part (subprogram or process), and a for-generate
8770 otherwise."
8771 (interactive)
8772 (vhdl-prepare-search-1
8773 (cond
8774 ((vhdl-sequential-statement-p) ; sequential statement
8775 (vhdl-template-for-loop))
8776 ((and (save-excursion ; configuration declaration
8777 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8778 (equal "CONFIGURATION" (upcase (match-string 1))))
8779 (if (eq (vhdl-decision-query
8780 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8781 (vhdl-template-component-conf)
8782 (vhdl-template-block-configuration)))
8783 ((and (save-excursion
8784 (re-search-backward ; architecture declarative part
8785 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8786 (equal "ARCHITECTURE" (upcase (match-string 1))))
8787 (vhdl-template-configuration-spec))
8788 (t (vhdl-template-for-generate))))) ; concurrent statement
8789
8790 (defun vhdl-template-for-generate ()
8791 "Insert a for-generate."
8792 (interactive)
8793 (let ((margin (current-indentation))
8794 (start (point))
8795 label position)
8796 (vhdl-insert-keyword ": FOR ")
8797 (setq position (point-marker))
8798 (goto-char start)
8799 (when (setq label (vhdl-template-field "label" nil t start position))
8800 (goto-char position)
8801 (vhdl-template-field "loop variable")
8802 (vhdl-insert-keyword " IN ")
8803 (vhdl-template-field "range")
8804 (vhdl-template-generate-body margin label))))
8805
8806 (defun vhdl-template-for-loop ()
8807 "Insert a for loop."
8808 (interactive)
8809 (let ((margin (current-indentation))
8810 (start (point))
8811 label index)
8812 (if (not (eq vhdl-optional-labels 'all))
8813 (vhdl-insert-keyword "FOR ")
8814 (vhdl-insert-keyword ": FOR ")
8815 (goto-char start)
8816 (setq label (vhdl-template-field "[label]" nil t))
8817 (unless label (delete-char 2))
8818 (forward-word 1)
8819 (forward-char 1))
8820 (when (setq index (vhdl-template-field "loop variable"
8821 nil t start (point)))
8822 (vhdl-insert-keyword " IN ")
8823 (vhdl-template-field "range")
8824 (vhdl-insert-keyword " LOOP\n\n")
8825 (indent-to margin)
8826 (vhdl-insert-keyword "END LOOP")
8827 (if label
8828 (insert " " label ";")
8829 (insert ";")
8830 (when vhdl-self-insert-comments (insert " -- " index)))
8831 (forward-line -1)
8832 (indent-to (+ margin vhdl-basic-offset)))))
8833
8834 (defun vhdl-template-function (&optional kind)
8835 "Insert a function declaration or body."
8836 (interactive)
8837 (let ((margin (current-indentation))
8838 (start (point))
8839 name)
8840 (vhdl-insert-keyword "FUNCTION ")
8841 (when (setq name (vhdl-template-field "name" nil t start (point)))
8842 (vhdl-template-argument-list t)
8843 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8844 (end-of-line)
8845 (insert "\n")
8846 (indent-to (+ margin vhdl-basic-offset))
8847 (vhdl-insert-keyword "RETURN ")
8848 (vhdl-template-field "type")
8849 (if (if kind (eq kind 'body)
8850 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8851 (progn (vhdl-insert-keyword " IS\n")
8852 (vhdl-template-begin-end
8853 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8854 (vhdl-comment-block))
8855 (insert ";")))))
8856
8857 (defun vhdl-template-function-decl ()
8858 "Insert a function declaration."
8859 (interactive)
8860 (vhdl-template-function 'decl))
8861
8862 (defun vhdl-template-function-body ()
8863 "Insert a function declaration."
8864 (interactive)
8865 (vhdl-template-function 'body))
8866
8867 (defun vhdl-template-generate ()
8868 "Insert a generation scheme."
8869 (interactive)
8870 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8871 (vhdl-template-if-generate)
8872 (vhdl-template-for-generate)))
8873
8874 (defun vhdl-template-generic ()
8875 "Insert generic declaration, or generic map in instantiation statements."
8876 (interactive)
8877 (let ((start (point)))
8878 (vhdl-prepare-search-1
8879 (cond
8880 ((and (save-excursion ; entity declaration
8881 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8882 (equal "ENTITY" (upcase (match-string 1))))
8883 (vhdl-template-generic-list nil))
8884 ((or (save-excursion
8885 (or (beginning-of-line)
8886 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8887 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8888 (vhdl-insert-keyword "GENERIC ")
8889 (vhdl-template-map start))
8890 (t (vhdl-template-generic-list nil t))))))
8891
8892 (defun vhdl-template-group ()
8893 "Insert group or group template declaration."
8894 (interactive)
8895 (let ((start (point)))
8896 (if (eq (vhdl-decision-query
8897 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8898 (vhdl-template-group-template)
8899 (vhdl-template-group-decl))))
8900
8901 (defun vhdl-template-group-decl ()
8902 "Insert group declaration."
8903 (interactive)
8904 (let ((start (point)))
8905 (vhdl-insert-keyword "GROUP ")
8906 (when (vhdl-template-field "name" " : " t start (point))
8907 (vhdl-template-field "template name" " (")
8908 (vhdl-template-field "constituent list" ");")
8909 (vhdl-comment-insert-inline))))
8910
8911 (defun vhdl-template-group-template ()
8912 "Insert group template declaration."
8913 (interactive)
8914 (let ((start (point)))
8915 (vhdl-insert-keyword "GROUP ")
8916 (when (vhdl-template-field "template name" nil t start (point))
8917 (vhdl-insert-keyword " IS (")
8918 (vhdl-template-field "entity class list" ");")
8919 (vhdl-comment-insert-inline))))
8920
8921 (defun vhdl-template-if ()
8922 "Insert a sequential if statement or an if-generate statement."
8923 (interactive)
8924 (if (vhdl-sequential-statement-p)
8925 (vhdl-template-if-then)
8926 (if (and (vhdl-standard-p 'ams)
8927 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8928 (vhdl-template-if-use)
8929 (vhdl-template-if-generate))))
8930
8931 (defun vhdl-template-if-generate ()
8932 "Insert an if-generate."
8933 (interactive)
8934 (let ((margin (current-indentation))
8935 (start (point))
8936 label position)
8937 (vhdl-insert-keyword ": IF ")
8938 (setq position (point-marker))
8939 (goto-char start)
8940 (when (setq label (vhdl-template-field "label" nil t start position))
8941 (goto-char position)
8942 (when vhdl-conditions-in-parenthesis (insert "("))
8943 (vhdl-template-field "condition")
8944 (when vhdl-conditions-in-parenthesis (insert ")"))
8945 (vhdl-template-generate-body margin label))))
8946
8947 (defun vhdl-template-if-then-use (kind)
8948 "Insert a sequential if statement."
8949 (interactive)
8950 (let ((margin (current-indentation))
8951 (start (point))
8952 label)
8953 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8954 (vhdl-insert-keyword "IF ")
8955 (vhdl-insert-keyword ": IF ")
8956 (goto-char start)
8957 (setq label (vhdl-template-field "[label]" nil t))
8958 (unless label (delete-char 2))
8959 (forward-word 1)
8960 (forward-char 1))
8961 (when vhdl-conditions-in-parenthesis (insert "("))
8962 (when (vhdl-template-field "condition" nil t start (point))
8963 (when vhdl-conditions-in-parenthesis (insert ")"))
8964 (vhdl-insert-keyword
8965 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8966 (indent-to margin)
8967 (vhdl-insert-keyword "END IF")
8968 (when label (insert " " label))
8969 (insert ";")
8970 (forward-line -1)
8971 (indent-to (+ margin vhdl-basic-offset)))))
8972
8973 (defun vhdl-template-if-then ()
8974 "Insert a sequential if statement."
8975 (interactive)
8976 (vhdl-template-if-then-use 'then))
8977
8978 (defun vhdl-template-if-use ()
8979 "Insert a simultaneous if statement."
8980 (interactive)
8981 (vhdl-template-if-then-use 'use))
8982
8983 (defun vhdl-template-instance ()
8984 "Insert a component instantiation statement."
8985 (interactive)
8986 (vhdl-template-component-inst))
8987
8988 (defun vhdl-template-library ()
8989 "Insert a library specification."
8990 (interactive)
8991 (let ((margin (current-indentation))
8992 (start (point))
8993 name end-pos)
8994 (vhdl-insert-keyword "LIBRARY ")
8995 (when (setq name (vhdl-template-field "names" nil t start (point)))
8996 (insert ";")
8997 (unless (string-match "," name)
8998 (setq end-pos (point))
8999 (insert "\n")
9000 (indent-to margin)
9001 (vhdl-insert-keyword "USE ")
9002 (insert name)
9003 (vhdl-insert-keyword "..ALL;")
9004 (backward-char 5)
9005 (if (vhdl-template-field "package name")
9006 (forward-char 5)
9007 (delete-region end-pos (+ (point) 5)))))))
9008
9009 (defun vhdl-template-limit ()
9010 "Insert a limit."
9011 (interactive)
9012 (let ((start (point)))
9013 (vhdl-insert-keyword "LIMIT ")
9014 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9015 t start (point))
9016 (vhdl-template-field "type")
9017 (vhdl-insert-keyword " WITH ")
9018 (vhdl-template-field "real expression" ";"))))
9019
9020 (defun vhdl-template-loop ()
9021 "Insert a loop."
9022 (interactive)
9023 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9024 (cond ((eq char ?w)
9025 (vhdl-template-while-loop))
9026 ((eq char ?f)
9027 (vhdl-template-for-loop))
9028 (t (vhdl-template-bare-loop)))))
9029
9030 (defun vhdl-template-bare-loop ()
9031 "Insert a loop."
9032 (interactive)
9033 (let ((margin (current-indentation))
9034 (start (point))
9035 label)
9036 (if (not (eq vhdl-optional-labels 'all))
9037 (vhdl-insert-keyword "LOOP ")
9038 (vhdl-insert-keyword ": LOOP ")
9039 (goto-char start)
9040 (setq label (vhdl-template-field "[label]" nil t))
9041 (unless label (delete-char 2))
9042 (forward-word 1)
9043 (delete-char 1))
9044 (insert "\n\n")
9045 (indent-to margin)
9046 (vhdl-insert-keyword "END LOOP")
9047 (insert (if label (concat " " label ";") ";"))
9048 (forward-line -1)
9049 (indent-to (+ margin vhdl-basic-offset))))
9050
9051 (defun vhdl-template-map (&optional start optional secondary)
9052 "Insert a map specification with association list."
9053 (interactive)
9054 (let ((start (or start (point)))
9055 margin end-pos)
9056 (vhdl-insert-keyword "MAP (")
9057 (if (not vhdl-association-list-with-formals)
9058 (if (vhdl-template-field
9059 (concat (and optional "[") "association list" (and optional "]"))
9060 ")" (or (not secondary) optional)
9061 (and (not secondary) start) (point))
9062 t
9063 (if (and optional secondary) (delete-region start (point)))
9064 nil)
9065 (if vhdl-argument-list-indent
9066 (setq margin (current-column))
9067 (setq margin (+ (current-indentation) vhdl-basic-offset))
9068 (insert "\n")
9069 (indent-to margin))
9070 (if (vhdl-template-field
9071 (concat (and optional "[") "formal" (and optional "]"))
9072 " => " (or (not secondary) optional)
9073 (and (not secondary) start) (point))
9074 (progn
9075 (vhdl-template-field "actual" ",")
9076 (setq end-pos (point))
9077 (insert "\n")
9078 (indent-to margin)
9079 (while (vhdl-template-field "[formal]" " => " t)
9080 (vhdl-template-field "actual" ",")
9081 (setq end-pos (point))
9082 (insert "\n")
9083 (indent-to margin))
9084 (delete-region end-pos (point))
9085 (delete-backward-char 1)
9086 (insert ")")
9087 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9088 t)
9089 (when (and optional secondary) (delete-region start (point)))
9090 nil))))
9091
9092 (defun vhdl-template-modify (&optional noerror)
9093 "Actualize modification date."
9094 (interactive)
9095 (vhdl-prepare-search-2
9096 (save-excursion
9097 (goto-char (point-min))
9098 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9099 (progn (delete-region (point) (progn (end-of-line) (point)))
9100 (vhdl-template-insert-date))
9101 (unless noerror
9102 (error "ERROR: Modification date prefix string \"%s\" not found"
9103 vhdl-modify-date-prefix-string))))))
9104
9105
9106 (defun vhdl-template-modify-noerror ()
9107 "Call `vhdl-template-modify' with NOERROR non-nil."
9108 (vhdl-template-modify t))
9109
9110 (defun vhdl-template-nature ()
9111 "Insert a nature declaration."
9112 (interactive)
9113 (let ((start (point))
9114 name mid-pos end-pos)
9115 (vhdl-insert-keyword "NATURE ")
9116 (when (setq name (vhdl-template-field "name" nil t start (point)))
9117 (vhdl-insert-keyword " IS ")
9118 (let ((definition
9119 (upcase
9120 (or (vhdl-template-field
9121 "across type | ARRAY | RECORD")
9122 ""))))
9123 (cond ((equal definition "")
9124 (insert ";"))
9125 ((equal definition "ARRAY")
9126 (delete-region (point) (progn (forward-word -1) (point)))
9127 (vhdl-template-array 'nature t))
9128 ((equal definition "RECORD")
9129 (setq mid-pos (point-marker))
9130 (delete-region (point) (progn (forward-word -1) (point)))
9131 (vhdl-template-record 'nature name t))
9132 (t
9133 (vhdl-insert-keyword " ACROSS ")
9134 (vhdl-template-field "through type")
9135 (vhdl-insert-keyword " THROUGH ")
9136 (vhdl-template-field "reference name")
9137 (vhdl-insert-keyword " REFERENCE;")))
9138 (when mid-pos
9139 (setq end-pos (point-marker))
9140 (goto-char mid-pos)
9141 (end-of-line))
9142 (vhdl-comment-insert-inline)
9143 (when end-pos (goto-char end-pos))))))
9144
9145 (defun vhdl-template-next ()
9146 "Insert a next statement."
9147 (interactive)
9148 (let ((start (point)))
9149 (vhdl-insert-keyword "NEXT ")
9150 (if (vhdl-template-field "[loop label]" nil t start (point))
9151 (let ((position (point)))
9152 (vhdl-insert-keyword " WHEN ")
9153 (when vhdl-conditions-in-parenthesis (insert "("))
9154 (if (vhdl-template-field "[condition]" nil t)
9155 (when vhdl-conditions-in-parenthesis (insert ")"))
9156 (delete-region position (point))))
9157 (delete-char -1))
9158 (insert ";")))
9159
9160 (defun vhdl-template-others ()
9161 "Insert an others aggregate."
9162 (interactive)
9163 (let ((start (point)))
9164 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9165 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9166 (vhdl-insert-keyword "OTHERS => '")
9167 (when (vhdl-template-field "value" nil t start (point))
9168 (insert "')")))
9169 (vhdl-insert-keyword "OTHERS "))))
9170
9171 (defun vhdl-template-package (&optional kind)
9172 "Insert a package specification or body."
9173 (interactive)
9174 (let ((margin (current-indentation))
9175 (start (point))
9176 name body position)
9177 (vhdl-insert-keyword "PACKAGE ")
9178 (setq body (if kind (eq kind 'body)
9179 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9180 (when body
9181 (vhdl-insert-keyword "BODY ")
9182 (when (save-excursion
9183 (vhdl-prepare-search-1
9184 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9185 (insert (setq name (match-string 1)))))
9186 (when (or name
9187 (setq name (vhdl-template-field "name" nil t start (point))))
9188 (vhdl-insert-keyword " IS\n")
9189 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9190 (indent-to (+ margin vhdl-basic-offset))
9191 (setq position (point))
9192 (insert "\n")
9193 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9194 (indent-to margin)
9195 (vhdl-insert-keyword "END ")
9196 (unless (vhdl-standard-p '87)
9197 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9198 (insert (or name "") ";")
9199 (goto-char position))))
9200
9201 (defun vhdl-template-package-decl ()
9202 "Insert a package specification."
9203 (interactive)
9204 (vhdl-template-package 'decl))
9205
9206 (defun vhdl-template-package-body ()
9207 "Insert a package body."
9208 (interactive)
9209 (vhdl-template-package 'body))
9210
9211 (defun vhdl-template-port ()
9212 "Insert a port declaration, or port map in instantiation statements."
9213 (interactive)
9214 (let ((start (point)))
9215 (vhdl-prepare-search-1
9216 (cond
9217 ((and (save-excursion ; entity declaration
9218 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9219 (equal "ENTITY" (upcase (match-string 1))))
9220 (vhdl-template-port-list nil))
9221 ((or (save-excursion
9222 (or (beginning-of-line)
9223 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9224 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9225 (vhdl-insert-keyword "PORT ")
9226 (vhdl-template-map start))
9227 (t (vhdl-template-port-list nil))))))
9228
9229 (defun vhdl-template-procedural ()
9230 "Insert a procedural."
9231 (interactive)
9232 (let ((margin (current-indentation))
9233 (start (point))
9234 (case-fold-search t)
9235 label)
9236 (vhdl-insert-keyword "PROCEDURAL ")
9237 (when (memq vhdl-optional-labels '(process all))
9238 (goto-char start)
9239 (insert ": ")
9240 (goto-char start)
9241 (setq label (vhdl-template-field "[label]" nil t))
9242 (unless label (delete-char 2))
9243 (forward-word 1)
9244 (forward-char 1))
9245 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9246 (insert "\n")
9247 (vhdl-template-begin-end "PROCEDURAL" label margin)
9248 (vhdl-comment-block)))
9249
9250 (defun vhdl-template-procedure (&optional kind)
9251 "Insert a procedure declaration or body."
9252 (interactive)
9253 (let ((margin (current-indentation))
9254 (start (point))
9255 name)
9256 (vhdl-insert-keyword "PROCEDURE ")
9257 (when (setq name (vhdl-template-field "name" nil t start (point)))
9258 (vhdl-template-argument-list)
9259 (if (if kind (eq kind 'body)
9260 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9261 (progn (vhdl-insert-keyword " IS")
9262 (when vhdl-auto-align
9263 (vhdl-align-region-groups start (point) 1))
9264 (end-of-line) (insert "\n")
9265 (vhdl-template-begin-end
9266 (unless (vhdl-standard-p '87) "PROCEDURE")
9267 name margin)
9268 (vhdl-comment-block))
9269 (insert ";")
9270 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9271 (end-of-line)))))
9272
9273 (defun vhdl-template-procedure-decl ()
9274 "Insert a procedure declaration."
9275 (interactive)
9276 (vhdl-template-procedure 'decl))
9277
9278 (defun vhdl-template-procedure-body ()
9279 "Insert a procedure body."
9280 (interactive)
9281 (vhdl-template-procedure 'body))
9282
9283 (defun vhdl-template-process (&optional kind)
9284 "Insert a process."
9285 (interactive)
9286 (let ((margin (current-indentation))
9287 (start (point))
9288 label seq input-signals clock reset final-pos)
9289 (setq seq (if kind (eq kind 'seq)
9290 (eq (vhdl-decision-query
9291 "process" "(c)ombinational or (s)equential?" t) ?s)))
9292 (vhdl-insert-keyword "PROCESS ")
9293 (when (memq vhdl-optional-labels '(process all))
9294 (goto-char start)
9295 (insert ": ")
9296 (goto-char start)
9297 (setq label (vhdl-template-field "[label]" nil t))
9298 (unless label (delete-char 2))
9299 (forward-word 1)
9300 (forward-char 1))
9301 (insert "(")
9302 (if (not seq)
9303 (unless (setq input-signals
9304 (vhdl-template-field "[sensitivity list]" ")" t))
9305 (setq input-signals "")
9306 (delete-char -2))
9307 (setq clock (or (and (not (equal "" vhdl-clock-name))
9308 (progn (insert vhdl-clock-name) vhdl-clock-name))
9309 (vhdl-template-field "clock name") "<clock>"))
9310 (when (eq vhdl-reset-kind 'async)
9311 (insert ", ")
9312 (setq reset (or (and (not (equal "" vhdl-reset-name))
9313 (progn (insert vhdl-reset-name) vhdl-reset-name))
9314 (vhdl-template-field "reset name") "<reset>")))
9315 (insert ")"))
9316 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9317 (insert "\n")
9318 (vhdl-template-begin-end "PROCESS" label margin)
9319 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9320 (when vhdl-prompt-for-comments
9321 (setq final-pos (point-marker))
9322 (vhdl-prepare-search-2
9323 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9324 (vhdl-re-search-backward "\\<process\\>" nil t))
9325 (end-of-line -0)
9326 (if (bobp)
9327 (progn (insert "\n") (forward-line -1))
9328 (insert "\n"))
9329 (indent-to margin)
9330 (insert "-- purpose: ")
9331 (if (not (vhdl-template-field "[description]" nil t))
9332 (vhdl-line-kill-entire)
9333 (insert "\n")
9334 (indent-to margin)
9335 (insert "-- type : ")
9336 (insert (if seq "sequential" "combinational") "\n")
9337 (indent-to margin)
9338 (insert "-- inputs : ")
9339 (if (not seq)
9340 (insert input-signals)
9341 (insert clock ", ")
9342 (when reset (insert reset ", "))
9343 (unless (vhdl-template-field "[signal names]" nil t)
9344 (delete-char -2)))
9345 (insert "\n")
9346 (indent-to margin)
9347 (insert "-- outputs: ")
9348 (vhdl-template-field "[signal names]" nil t))))
9349 (goto-char final-pos))))
9350
9351 (defun vhdl-template-process-comb ()
9352 "Insert a combinational process."
9353 (interactive)
9354 (vhdl-template-process 'comb))
9355
9356 (defun vhdl-template-process-seq ()
9357 "Insert a sequential process."
9358 (interactive)
9359 (vhdl-template-process 'seq))
9360
9361 (defun vhdl-template-quantity ()
9362 "Insert a quantity declaration."
9363 (interactive)
9364 (if (vhdl-in-argument-list-p)
9365 (let ((start (point)))
9366 (vhdl-insert-keyword "QUANTITY ")
9367 (when (vhdl-template-field "names" nil t start (point))
9368 (insert " : ")
9369 (vhdl-template-field "[IN | OUT]" " " t)
9370 (vhdl-template-field "type")
9371 (insert ";")
9372 (vhdl-comment-insert-inline)))
9373 (let ((char (vhdl-decision-query
9374 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9375 (cond ((eq char ?f) (vhdl-template-quantity-free))
9376 ((eq char ?b) (vhdl-template-quantity-branch))
9377 ((eq char ?s) (vhdl-template-quantity-source))
9378 (t (vhdl-template-undo (point) (point)))))))
9379
9380 (defun vhdl-template-quantity-free ()
9381 "Insert a free quantity declaration."
9382 (interactive)
9383 (vhdl-insert-keyword "QUANTITY ")
9384 (vhdl-template-field "names")
9385 (insert " : ")
9386 (vhdl-template-field "type")
9387 (let ((position (point)))
9388 (insert " := ")
9389 (unless (vhdl-template-field "[initialization]" nil t)
9390 (delete-region position (point)))
9391 (insert ";")
9392 (vhdl-comment-insert-inline)))
9393
9394 (defun vhdl-template-quantity-branch ()
9395 "Insert a branch quantity declaration."
9396 (interactive)
9397 (let (position)
9398 (vhdl-insert-keyword "QUANTITY ")
9399 (when (vhdl-template-field "[across names]" " " t)
9400 (vhdl-insert-keyword "ACROSS "))
9401 (when (vhdl-template-field "[through names]" " " t)
9402 (vhdl-insert-keyword "THROUGH "))
9403 (vhdl-template-field "plus terminal name")
9404 (setq position (point))
9405 (vhdl-insert-keyword " TO ")
9406 (unless (vhdl-template-field "[minus terminal name]" nil t)
9407 (delete-region position (point)))
9408 (insert ";")
9409 (vhdl-comment-insert-inline)))
9410
9411 (defun vhdl-template-quantity-source ()
9412 "Insert a source quantity declaration."
9413 (interactive)
9414 (vhdl-insert-keyword "QUANTITY ")
9415 (vhdl-template-field "names")
9416 (insert " : ")
9417 (vhdl-template-field "type" " ")
9418 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9419 (progn (vhdl-insert-keyword "NOISE ")
9420 (vhdl-template-field "power expression"))
9421 (vhdl-insert-keyword "SPECTRUM ")
9422 (vhdl-template-field "magnitude expression" ", ")
9423 (vhdl-template-field "phase expression"))
9424 (insert ";")
9425 (vhdl-comment-insert-inline))
9426
9427 (defun vhdl-template-record (kind &optional name secondary)
9428 "Insert a record type declaration."
9429 (interactive)
9430 (let ((margin (current-column))
9431 (start (point))
9432 (first t))
9433 (vhdl-insert-keyword "RECORD\n")
9434 (indent-to (+ margin vhdl-basic-offset))
9435 (when (or (vhdl-template-field "element names"
9436 nil (not secondary) start (point))
9437 secondary)
9438 (while (or first (vhdl-template-field "[element names]" nil t))
9439 (insert " : ")
9440 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9441 (vhdl-comment-insert-inline)
9442 (insert "\n")
9443 (indent-to (+ margin vhdl-basic-offset))
9444 (setq first nil))
9445 (delete-region (line-beginning-position) (point))
9446 (indent-to margin)
9447 (vhdl-insert-keyword "END RECORD")
9448 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9449 (insert ";")
9450 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9451
9452 (defun vhdl-template-report ()
9453 "Insert a report statement."
9454 (interactive)
9455 (let ((start (point)))
9456 (vhdl-insert-keyword "REPORT ")
9457 (if (equal "\"\"" (vhdl-template-field
9458 "string expression" nil t start (point) t))
9459 (delete-backward-char 2)
9460 (setq start (point))
9461 (vhdl-insert-keyword " SEVERITY ")
9462 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9463 (delete-region start (point)))
9464 (insert ";"))))
9465
9466 (defun vhdl-template-return ()
9467 "Insert a return statement."
9468 (interactive)
9469 (let ((start (point)))
9470 (vhdl-insert-keyword "RETURN ")
9471 (unless (vhdl-template-field "[expression]" nil t start (point))
9472 (delete-char -1))
9473 (insert ";")))
9474
9475 (defun vhdl-template-selected-signal-asst ()
9476 "Insert a selected signal assignment."
9477 (interactive)
9478 (let ((margin (current-indentation))
9479 (start (point))
9480 (choices t))
9481 (let ((position (point)))
9482 (vhdl-insert-keyword " SELECT ")
9483 (goto-char position))
9484 (vhdl-insert-keyword "WITH ")
9485 (when (vhdl-template-field "selector expression"
9486 nil t start (+ (point) 7))
9487 (forward-word 1)
9488 (delete-char 1)
9489 (insert "\n")
9490 (indent-to (+ margin vhdl-basic-offset))
9491 (vhdl-template-field "target signal" " <= ")
9492 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9493 (insert "\n")
9494 (indent-to (+ margin vhdl-basic-offset))
9495 (vhdl-template-field "waveform")
9496 (vhdl-insert-keyword " WHEN ")
9497 (vhdl-template-field "choices" ",")
9498 (insert "\n")
9499 (indent-to (+ margin vhdl-basic-offset))
9500 (while (and choices (vhdl-template-field "[waveform]" nil t))
9501 (vhdl-insert-keyword " WHEN ")
9502 (if (setq choices (vhdl-template-field "[choices]" "," t))
9503 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9504 (vhdl-insert-keyword "OTHERS")))
9505 (when choices
9506 (fixup-whitespace)
9507 (delete-char -2))
9508 (insert ";")
9509 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9510
9511 (defun vhdl-template-signal ()
9512 "Insert a signal declaration."
9513 (interactive)
9514 (let ((start (point))
9515 (in-arglist (vhdl-in-argument-list-p)))
9516 (vhdl-insert-keyword "SIGNAL ")
9517 (when (vhdl-template-field "names" nil t start (point))
9518 (insert " : ")
9519 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9520 (vhdl-template-field "type")
9521 (if in-arglist
9522 (progn (insert ";")
9523 (vhdl-comment-insert-inline))
9524 (let ((position (point)))
9525 (insert " := ")
9526 (unless (vhdl-template-field "[initialization]" nil t)
9527 (delete-region position (point)))
9528 (insert ";")
9529 (vhdl-comment-insert-inline))))))
9530
9531 (defun vhdl-template-subnature ()
9532 "Insert a subnature declaration."
9533 (interactive)
9534 (let ((start (point))
9535 position)
9536 (vhdl-insert-keyword "SUBNATURE ")
9537 (when (vhdl-template-field "name" nil t start (point))
9538 (vhdl-insert-keyword " IS ")
9539 (vhdl-template-field "nature" " (")
9540 (if (vhdl-template-field "[index range]" nil t)
9541 (insert ")")
9542 (delete-char -2))
9543 (setq position (point))
9544 (vhdl-insert-keyword " TOLERANCE ")
9545 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9546 nil t nil nil t))
9547 (delete-region position (point))
9548 (vhdl-insert-keyword " ACROSS ")
9549 (vhdl-template-field "string expression" nil nil nil nil t)
9550 (vhdl-insert-keyword " THROUGH"))
9551 (insert ";")
9552 (vhdl-comment-insert-inline))))
9553
9554 (defun vhdl-template-subprogram-body ()
9555 "Insert a subprogram body."
9556 (interactive)
9557 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9558 (vhdl-template-function-body)
9559 (vhdl-template-procedure-body)))
9560
9561 (defun vhdl-template-subprogram-decl ()
9562 "Insert a subprogram declaration."
9563 (interactive)
9564 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9565 (vhdl-template-function-decl)
9566 (vhdl-template-procedure-decl)))
9567
9568 (defun vhdl-template-subtype ()
9569 "Insert a subtype declaration."
9570 (interactive)
9571 (let ((start (point)))
9572 (vhdl-insert-keyword "SUBTYPE ")
9573 (when (vhdl-template-field "name" nil t start (point))
9574 (vhdl-insert-keyword " IS ")
9575 (vhdl-template-field "type" " ")
9576 (unless
9577 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9578 (delete-char -1))
9579 (insert ";")
9580 (vhdl-comment-insert-inline))))
9581
9582 (defun vhdl-template-terminal ()
9583 "Insert a terminal declaration."
9584 (interactive)
9585 (let ((start (point)))
9586 (vhdl-insert-keyword "TERMINAL ")
9587 (when (vhdl-template-field "names" nil t start (point))
9588 (insert " : ")
9589 (vhdl-template-field "nature")
9590 (insert ";")
9591 (vhdl-comment-insert-inline))))
9592
9593 (defun vhdl-template-type ()
9594 "Insert a type declaration."
9595 (interactive)
9596 (let ((start (point))
9597 name mid-pos end-pos)
9598 (vhdl-insert-keyword "TYPE ")
9599 (when (setq name (vhdl-template-field "name" nil t start (point)))
9600 (vhdl-insert-keyword " IS ")
9601 (let ((definition
9602 (upcase
9603 (or (vhdl-template-field
9604 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9605 ""))))
9606 (cond ((equal definition "")
9607 (delete-backward-char 4)
9608 (insert ";"))
9609 ((equal definition "ARRAY")
9610 (delete-region (point) (progn (forward-word -1) (point)))
9611 (vhdl-template-array 'type t))
9612 ((equal definition "RECORD")
9613 (setq mid-pos (point-marker))
9614 (delete-region (point) (progn (forward-word -1) (point)))
9615 (vhdl-template-record 'type name t))
9616 ((equal definition "ACCESS")
9617 (insert " ")
9618 (vhdl-template-field "type" ";"))
9619 ((equal definition "FILE")
9620 (vhdl-insert-keyword " OF ")
9621 (vhdl-template-field "type" ";"))
9622 (t (insert ";")))
9623 (when mid-pos
9624 (setq end-pos (point-marker))
9625 (goto-char mid-pos)
9626 (end-of-line))
9627 (vhdl-comment-insert-inline)
9628 (when end-pos (goto-char end-pos))))))
9629
9630 (defun vhdl-template-use ()
9631 "Insert a use clause."
9632 (interactive)
9633 (let ((start (point)))
9634 (vhdl-prepare-search-1
9635 (vhdl-insert-keyword "USE ")
9636 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9637 (vhdl-insert-keyword "..ALL;")
9638 (backward-char 6)
9639 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9640 (forward-char 1)
9641 (vhdl-template-field "package name")
9642 (forward-char 5))))))
9643
9644 (defun vhdl-template-variable ()
9645 "Insert a variable declaration."
9646 (interactive)
9647 (let ((start (point))
9648 (in-arglist (vhdl-in-argument-list-p)))
9649 (vhdl-prepare-search-2
9650 (if (or (save-excursion
9651 (and (vhdl-re-search-backward
9652 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9653 nil t)
9654 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9655 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9656 (vhdl-insert-keyword "VARIABLE ")
9657 (vhdl-insert-keyword "SHARED VARIABLE ")))
9658 (when (vhdl-template-field "names" nil t start (point))
9659 (insert " : ")
9660 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9661 (vhdl-template-field "type")
9662 (if in-arglist
9663 (progn (insert ";")
9664 (vhdl-comment-insert-inline))
9665 (let ((position (point)))
9666 (insert " := ")
9667 (unless (vhdl-template-field "[initialization]" nil t)
9668 (delete-region position (point)))
9669 (insert ";")
9670 (vhdl-comment-insert-inline))))))
9671
9672 (defun vhdl-template-wait ()
9673 "Insert a wait statement."
9674 (interactive)
9675 (vhdl-insert-keyword "WAIT ")
9676 (unless (vhdl-template-field
9677 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9678 nil t)
9679 (delete-char -1))
9680 (insert ";"))
9681
9682 (defun vhdl-template-when ()
9683 "Indent correctly if within a case statement."
9684 (interactive)
9685 (let ((position (point))
9686 margin)
9687 (vhdl-prepare-search-2
9688 (if (and (= (current-column) (current-indentation))
9689 (vhdl-re-search-forward "\\<end\\>" nil t)
9690 (looking-at "\\s-*\\<case\\>"))
9691 (progn
9692 (setq margin (current-indentation))
9693 (goto-char position)
9694 (delete-horizontal-space)
9695 (indent-to (+ margin vhdl-basic-offset)))
9696 (goto-char position)))
9697 (vhdl-insert-keyword "WHEN ")))
9698
9699 (defun vhdl-template-while-loop ()
9700 "Insert a while loop."
9701 (interactive)
9702 (let* ((margin (current-indentation))
9703 (start (point))
9704 label)
9705 (if (not (eq vhdl-optional-labels 'all))
9706 (vhdl-insert-keyword "WHILE ")
9707 (vhdl-insert-keyword ": WHILE ")
9708 (goto-char start)
9709 (setq label (vhdl-template-field "[label]" nil t))
9710 (unless label (delete-char 2))
9711 (forward-word 1)
9712 (forward-char 1))
9713 (when vhdl-conditions-in-parenthesis (insert "("))
9714 (when (vhdl-template-field "condition" nil t start (point))
9715 (when vhdl-conditions-in-parenthesis (insert ")"))
9716 (vhdl-insert-keyword " LOOP\n\n")
9717 (indent-to margin)
9718 (vhdl-insert-keyword "END LOOP")
9719 (insert (if label (concat " " label ";") ";"))
9720 (forward-line -1)
9721 (indent-to (+ margin vhdl-basic-offset)))))
9722
9723 (defun vhdl-template-with ()
9724 "Insert a with statement (i.e. selected signal assignment)."
9725 (interactive)
9726 (vhdl-prepare-search-1
9727 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9728 (equal ";" (match-string 1)))
9729 (vhdl-template-selected-signal-asst)
9730 (vhdl-insert-keyword "WITH "))))
9731
9732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9733 ;; Special templates
9734
9735 (defun vhdl-template-clocked-wait ()
9736 "Insert a wait statement for rising/falling clock edge."
9737 (interactive)
9738 (let ((start (point))
9739 clock)
9740 (vhdl-insert-keyword "WAIT UNTIL ")
9741 (when (setq clock
9742 (or (and (not (equal "" vhdl-clock-name))
9743 (progn (insert vhdl-clock-name) vhdl-clock-name))
9744 (vhdl-template-field "clock name" nil t start (point))))
9745 (insert "'event")
9746 (vhdl-insert-keyword " AND ")
9747 (insert clock)
9748 (insert
9749 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9750 (vhdl-comment-insert-inline
9751 (concat (if vhdl-clock-rising-edge "rising" "falling")
9752 " clock edge")))))
9753
9754 (defun vhdl-template-seq-process (clock reset)
9755 "Insert a template for the body of a sequential process."
9756 (let ((margin (current-indentation))
9757 position)
9758 (vhdl-insert-keyword "IF ")
9759 (when (eq vhdl-reset-kind 'async)
9760 (insert reset " = "
9761 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9762 (vhdl-insert-keyword " THEN")
9763 (vhdl-comment-insert-inline
9764 (concat "asynchronous reset (active "
9765 (if vhdl-reset-active-high "high" "low") ")"))
9766 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9767 (setq position (point))
9768 (insert "\n") (indent-to margin)
9769 (vhdl-insert-keyword "ELSIF "))
9770 (if (eq vhdl-clock-edge-condition 'function)
9771 (insert (if vhdl-clock-rising-edge "rising" "falling")
9772 "_edge(" clock ")")
9773 (insert clock "'event")
9774 (vhdl-insert-keyword " AND ")
9775 (insert clock " = "
9776 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9777 (vhdl-insert-keyword " THEN")
9778 (vhdl-comment-insert-inline
9779 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9780 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9781 (when (eq vhdl-reset-kind 'sync)
9782 (vhdl-insert-keyword "IF ")
9783 (setq reset (or (and (not (equal "" vhdl-reset-name))
9784 (progn (insert vhdl-reset-name) vhdl-reset-name))
9785 (vhdl-template-field "reset name") "<reset>"))
9786 (insert " = "
9787 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9788 (vhdl-insert-keyword " THEN")
9789 (vhdl-comment-insert-inline
9790 (concat "synchronous reset (active "
9791 (if vhdl-reset-active-high "high" "low") ")"))
9792 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9793 (setq position (point))
9794 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9795 (vhdl-insert-keyword "ELSE")
9796 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9797 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9798 (vhdl-insert-keyword "END IF;"))
9799 (when (eq vhdl-reset-kind 'none)
9800 (setq position (point)))
9801 (insert "\n") (indent-to margin)
9802 (vhdl-insert-keyword "END IF;")
9803 (goto-char position)
9804 reset))
9805
9806 (defun vhdl-template-standard-package (library package)
9807 "Insert specification of a standard package. Include a library
9808 specification, if not already there."
9809 (let ((margin (current-indentation)))
9810 (unless (equal library "std")
9811 (unless (or (save-excursion
9812 (vhdl-prepare-search-1
9813 (and (not (bobp))
9814 (re-search-backward
9815 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9816 library "\\|end\\)\\>") nil t)
9817 (match-string 2))))
9818 (equal (downcase library) "work"))
9819 (vhdl-insert-keyword "LIBRARY ")
9820 (insert library ";")
9821 (when package
9822 (insert "\n")
9823 (indent-to margin)))
9824 (when package
9825 (vhdl-insert-keyword "USE ")
9826 (insert library "." package)
9827 (vhdl-insert-keyword ".ALL;")))))
9828
9829 (defun vhdl-template-package-math-complex ()
9830 "Insert specification of `math_complex' package."
9831 (interactive)
9832 (vhdl-template-standard-package "ieee" "math_complex"))
9833
9834 (defun vhdl-template-package-math-real ()
9835 "Insert specification of `math_real' package."
9836 (interactive)
9837 (vhdl-template-standard-package "ieee" "math_real"))
9838
9839 (defun vhdl-template-package-numeric-bit ()
9840 "Insert specification of `numeric_bit' package."
9841 (interactive)
9842 (vhdl-template-standard-package "ieee" "numeric_bit"))
9843
9844 (defun vhdl-template-package-numeric-std ()
9845 "Insert specification of `numeric_std' package."
9846 (interactive)
9847 (vhdl-template-standard-package "ieee" "numeric_std"))
9848
9849 (defun vhdl-template-package-std-logic-1164 ()
9850 "Insert specification of `std_logic_1164' package."
9851 (interactive)
9852 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9853
9854 (defun vhdl-template-package-std-logic-arith ()
9855 "Insert specification of `std_logic_arith' package."
9856 (interactive)
9857 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9858
9859 (defun vhdl-template-package-std-logic-misc ()
9860 "Insert specification of `std_logic_misc' package."
9861 (interactive)
9862 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9863
9864 (defun vhdl-template-package-std-logic-signed ()
9865 "Insert specification of `std_logic_signed' package."
9866 (interactive)
9867 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9868
9869 (defun vhdl-template-package-std-logic-textio ()
9870 "Insert specification of `std_logic_textio' package."
9871 (interactive)
9872 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9873
9874 (defun vhdl-template-package-std-logic-unsigned ()
9875 "Insert specification of `std_logic_unsigned' package."
9876 (interactive)
9877 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9878
9879 (defun vhdl-template-package-textio ()
9880 "Insert specification of `textio' package."
9881 (interactive)
9882 (vhdl-template-standard-package "std" "textio"))
9883
9884 (defun vhdl-template-directive (directive)
9885 "Insert directive."
9886 (unless (= (current-indentation) (current-column))
9887 (delete-horizontal-space)
9888 (insert " "))
9889 (insert "-- pragma " directive))
9890
9891 (defun vhdl-template-directive-translate-on ()
9892 "Insert directive 'translate_on'."
9893 (interactive)
9894 (vhdl-template-directive "translate_on"))
9895
9896 (defun vhdl-template-directive-translate-off ()
9897 "Insert directive 'translate_off'."
9898 (interactive)
9899 (vhdl-template-directive "translate_off"))
9900
9901 (defun vhdl-template-directive-synthesis-on ()
9902 "Insert directive 'synthesis_on'."
9903 (interactive)
9904 (vhdl-template-directive "synthesis_on"))
9905
9906 (defun vhdl-template-directive-synthesis-off ()
9907 "Insert directive 'synthesis_off'."
9908 (interactive)
9909 (vhdl-template-directive "synthesis_off"))
9910
9911 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9912 ;; Header and footer templates
9913
9914 (defun vhdl-template-header (&optional file-title)
9915 "Insert a VHDL file header."
9916 (interactive)
9917 (unless (equal vhdl-file-header "")
9918 (let (pos)
9919 (save-excursion
9920 (goto-char (point-min))
9921 (vhdl-insert-string-or-file vhdl-file-header)
9922 (setq pos (point-marker)))
9923 (vhdl-template-replace-header-keywords
9924 (point-min-marker) pos file-title))))
9925
9926 (defun vhdl-template-footer ()
9927 "Insert a VHDL file footer."
9928 (interactive)
9929 (unless (equal vhdl-file-footer "")
9930 (let (pos)
9931 (save-excursion
9932 (goto-char (point-max))
9933 (setq pos (point-marker))
9934 (vhdl-insert-string-or-file vhdl-file-footer)
9935 (unless (= (preceding-char) ?\n)
9936 (insert "\n")))
9937 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9938
9939 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9940 is-model)
9941 "Replace keywords in header and footer."
9942 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9943 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9944 pos)
9945 (vhdl-prepare-search-2
9946 (save-excursion
9947 (goto-char beg)
9948 (while (search-forward "<projectdesc>" end t)
9949 (replace-match project-desc t t))
9950 (goto-char beg)
9951 (while (search-forward "<filename>" end t)
9952 (replace-match (buffer-name) t t))
9953 (goto-char beg)
9954 (while (search-forward "<copyright>" end t)
9955 (replace-match vhdl-copyright-string t t))
9956 (goto-char beg)
9957 (while (search-forward "<author>" end t)
9958 (replace-match "" t t)
9959 (insert (user-full-name))
9960 (when user-mail-address (insert " <" user-mail-address ">")))
9961 (goto-char beg)
9962 (while (search-forward "<login>" end t)
9963 (replace-match (user-login-name) t t))
9964 (goto-char beg)
9965 (while (search-forward "<project>" end t)
9966 (replace-match project-title t t))
9967 (goto-char beg)
9968 (while (search-forward "<company>" end t)
9969 (replace-match vhdl-company-name t t))
9970 (goto-char beg)
9971 (while (search-forward "<platform>" end t)
9972 (replace-match vhdl-platform-spec t t))
9973 (goto-char beg)
9974 (while (search-forward "<standard>" end t)
9975 (replace-match
9976 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9977 ((vhdl-standard-p '93) "'93"))
9978 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9979 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9980 (goto-char beg)
9981 ;; Replace <RCS> with $, so that RCS for the source is
9982 ;; not over-enthusiastic with replacements
9983 (while (search-forward "<RCS>" end t)
9984 (replace-match "$" nil t))
9985 (goto-char beg)
9986 (while (search-forward "<date>" end t)
9987 (replace-match "" t t)
9988 (vhdl-template-insert-date))
9989 (goto-char beg)
9990 (while (search-forward "<year>" end t)
9991 (replace-match (format-time-string "%Y" nil) t t))
9992 (goto-char beg)
9993 (when file-title
9994 (while (search-forward "<title string>" end t)
9995 (replace-match file-title t t))
9996 (goto-char beg))
9997 (let (string)
9998 (while
9999 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10000 (setq string (read-string (concat (match-string 1) ": ")))
10001 (replace-match string t t)))
10002 (goto-char beg)
10003 (when (and (not is-model) (search-forward "<cursor>" end t))
10004 (replace-match "" t t)
10005 (setq pos (point))))
10006 (when pos (goto-char pos))
10007 (unless is-model
10008 (when (or (not project-title) (equal project-title ""))
10009 (message "You can specify a project title in user option `vhdl-project-alist'"))
10010 (when (or (not project-desc) (equal project-desc ""))
10011 (message "You can specify a project description in user option `vhdl-project-alist'"))
10012 (when (equal vhdl-platform-spec "")
10013 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10014 (when (equal vhdl-company-name "")
10015 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10016
10017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10018 ;; Comment templates and functions
10019
10020 (defun vhdl-comment-indent ()
10021 "Indent comments."
10022 (let* ((position (point))
10023 (col
10024 (progn
10025 (forward-line -1)
10026 (if (re-search-forward "--" position t)
10027 (- (current-column) 2) ; existing comment at bol stays there
10028 (goto-char position)
10029 (skip-chars-backward " \t")
10030 (max comment-column ; else indent to comment column
10031 (1+ (current-column))))))) ; except leave at least one space
10032 (goto-char position)
10033 col))
10034
10035 (defun vhdl-comment-insert ()
10036 "Start a comment at the end of the line.
10037 If on line with code, indent at least `comment-column'.
10038 If starting after end-comment-column, start a new line."
10039 (interactive)
10040 (when (> (current-column) end-comment-column) (newline-and-indent))
10041 (if (or (looking-at "\\s-*$") ; end of line
10042 (and (not unread-command-events) ; called with key binding or menu
10043 (not (end-of-line))))
10044 (let (margin)
10045 (while (= (preceding-char) ?-) (delete-char -1))
10046 (setq margin (current-column))
10047 (delete-horizontal-space)
10048 (if (bolp)
10049 (progn (indent-to margin) (insert "--"))
10050 (insert " ")
10051 (indent-to comment-column)
10052 (insert "--"))
10053 (if (not unread-command-events) (insert " ")))
10054 ;; else code following current point implies commenting out code
10055 (let (next-input code)
10056 (while (= (preceding-char) ?-) (delete-char -2))
10057 (while (= (setq next-input (read-char)) 13) ; CR
10058 (insert "--") ; or have a space after it?
10059 (forward-char -2)
10060 (forward-line 1)
10061 (message "Enter CR if commenting out a line of code.")
10062 (setq code t))
10063 (unless code
10064 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10065 (setq unread-command-events
10066 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10067
10068 (defun vhdl-comment-display (&optional line-exists)
10069 "Add 2 comment lines at the current indent, making a display comment."
10070 (interactive)
10071 (let ((margin (current-indentation)))
10072 (unless line-exists (vhdl-comment-display-line))
10073 (insert "\n") (indent-to margin)
10074 (insert "\n") (indent-to margin)
10075 (vhdl-comment-display-line)
10076 (end-of-line -0)
10077 (insert "-- ")))
10078
10079 (defun vhdl-comment-display-line ()
10080 "Displays one line of dashes."
10081 (interactive)
10082 (while (= (preceding-char) ?-) (delete-char -2))
10083 (let* ((col (current-column))
10084 (len (- end-comment-column col)))
10085 (insert-char ?- len)))
10086
10087 (defun vhdl-comment-append-inline ()
10088 "Append empty inline comment to current line."
10089 (interactive)
10090 (end-of-line)
10091 (delete-horizontal-space)
10092 (insert " ")
10093 (indent-to comment-column)
10094 (insert "-- "))
10095
10096 (defun vhdl-comment-insert-inline (&optional string always-insert)
10097 "Insert inline comment."
10098 (when (or (and string (or vhdl-self-insert-comments always-insert))
10099 (and (not string) vhdl-prompt-for-comments))
10100 (let ((position (point)))
10101 (insert " ")
10102 (indent-to comment-column)
10103 (insert "-- ")
10104 (if (not (or (and string (progn (insert string) t))
10105 (vhdl-template-field "[comment]" nil t)))
10106 (delete-region position (point))
10107 (while (= (preceding-char) ? ) (delete-backward-char 1))
10108 ; (when (> (current-column) end-comment-column)
10109 ; (setq position (point-marker))
10110 ; (re-search-backward "-- ")
10111 ; (insert "\n")
10112 ; (indent-to comment-column)
10113 ; (goto-char position))
10114 ))))
10115
10116 (defun vhdl-comment-block ()
10117 "Insert comment for code block."
10118 (when vhdl-prompt-for-comments
10119 (let ((final-pos (point-marker)))
10120 (vhdl-prepare-search-2
10121 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10122 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10123 (let (margin)
10124 (back-to-indentation)
10125 (setq margin (current-column))
10126 (end-of-line -0)
10127 (if (bobp)
10128 (progn (insert "\n") (forward-line -1))
10129 (insert "\n"))
10130 (indent-to margin)
10131 (insert "-- purpose: ")
10132 (unless (vhdl-template-field "[description]" nil t)
10133 (vhdl-line-kill-entire)))))
10134 (goto-char final-pos))))
10135
10136 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10137 "Comment out region if not commented out, uncomment otherwise."
10138 (interactive "r\nP")
10139 (save-excursion
10140 (goto-char (1- end))
10141 (end-of-line)
10142 (setq end (point-marker))
10143 (goto-char beg)
10144 (beginning-of-line)
10145 (setq beg (point))
10146 (if (looking-at comment-start)
10147 (comment-region beg end '(4))
10148 (comment-region beg end))))
10149
10150 (defun vhdl-comment-uncomment-line (&optional arg)
10151 "Comment out line if not commented out, uncomment otherwise."
10152 (interactive "p")
10153 (save-excursion
10154 (beginning-of-line)
10155 (let ((position (point)))
10156 (forward-line (or arg 1))
10157 (vhdl-comment-uncomment-region position (point)))))
10158
10159 (defun vhdl-comment-kill-region (beg end)
10160 "Kill comments in region."
10161 (interactive "r")
10162 (save-excursion
10163 (goto-char end)
10164 (setq end (point-marker))
10165 (goto-char beg)
10166 (beginning-of-line)
10167 (while (< (point) end)
10168 (if (looking-at "^\\(\\s-*--.*\n\\)")
10169 (progn (delete-region (match-beginning 1) (match-end 1)))
10170 (beginning-of-line 2)))))
10171
10172 (defun vhdl-comment-kill-inline-region (beg end)
10173 "Kill inline comments in region."
10174 (interactive "r")
10175 (save-excursion
10176 (goto-char end)
10177 (setq end (point-marker))
10178 (goto-char beg)
10179 (beginning-of-line)
10180 (while (< (point) end)
10181 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10182 (delete-region (match-beginning 1) (match-end 1)))
10183 (beginning-of-line 2))))
10184
10185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10186 ;; Subtemplates
10187
10188 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10189 "Insert a begin ... end pair with optional name after the end.
10190 Point is left between them."
10191 (let (position)
10192 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10193 (indent-to margin)
10194 (vhdl-insert-keyword "BEGIN")
10195 (when (and (or construct name) vhdl-self-insert-comments)
10196 (insert " --")
10197 (when construct (insert " ") (vhdl-insert-keyword construct))
10198 (when name (insert " " name)))
10199 (insert "\n")
10200 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10201 (indent-to (+ margin vhdl-basic-offset))
10202 (setq position (point))
10203 (insert "\n")
10204 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10205 (indent-to margin)
10206 (vhdl-insert-keyword "END")
10207 (when construct (insert " ") (vhdl-insert-keyword construct))
10208 (insert (if name (concat " " name) "") ";")
10209 (goto-char position)))
10210
10211 (defun vhdl-template-argument-list (&optional is-function)
10212 "Read from user a procedure or function argument list."
10213 (insert " (")
10214 (let ((margin (current-column))
10215 (start (point))
10216 (end-pos (point))
10217 not-empty interface semicolon-pos)
10218 (unless vhdl-argument-list-indent
10219 (setq margin (+ (current-indentation) vhdl-basic-offset))
10220 (insert "\n")
10221 (indent-to margin))
10222 (setq interface (vhdl-template-field
10223 (concat "[CONSTANT | SIGNAL"
10224 (unless is-function " | VARIABLE") "]") " " t))
10225 (while (vhdl-template-field "[names]" nil t)
10226 (setq not-empty t)
10227 (insert " : ")
10228 (unless is-function
10229 (if (and interface (equal (upcase interface) "CONSTANT"))
10230 (vhdl-insert-keyword "IN ")
10231 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10232 (vhdl-template-field "type")
10233 (setq semicolon-pos (point))
10234 (insert ";")
10235 (vhdl-comment-insert-inline)
10236 (setq end-pos (point))
10237 (insert "\n")
10238 (indent-to margin)
10239 (setq interface (vhdl-template-field
10240 (concat "[CONSTANT | SIGNAL"
10241 (unless is-function " | VARIABLE") "]") " " t)))
10242 (delete-region end-pos (point))
10243 (when semicolon-pos (goto-char semicolon-pos))
10244 (if not-empty
10245 (progn (delete-char 1) (insert ")"))
10246 (delete-backward-char 2))))
10247
10248 (defun vhdl-template-generic-list (optional &optional no-value)
10249 "Read from user a generic spec argument list."
10250 (let (margin
10251 (start (point)))
10252 (vhdl-insert-keyword "GENERIC (")
10253 (setq margin (current-column))
10254 (unless vhdl-argument-list-indent
10255 (let ((position (point)))
10256 (back-to-indentation)
10257 (setq margin (+ (current-column) vhdl-basic-offset))
10258 (goto-char position)
10259 (insert "\n")
10260 (indent-to margin)))
10261 (let ((vhdl-generics (vhdl-template-field
10262 (concat (and optional "[") "name"
10263 (and no-value "s") (and optional "]"))
10264 nil optional)))
10265 (if (not vhdl-generics)
10266 (if optional
10267 (progn (vhdl-line-kill-entire) (end-of-line -0)
10268 (unless vhdl-argument-list-indent
10269 (vhdl-line-kill-entire) (end-of-line -0)))
10270 (vhdl-template-undo start (point))
10271 nil )
10272 (insert " : ")
10273 (let (semicolon-pos end-pos)
10274 (while vhdl-generics
10275 (vhdl-template-field "type")
10276 (if no-value
10277 (progn (setq semicolon-pos (point))
10278 (insert ";"))
10279 (insert " := ")
10280 (unless (vhdl-template-field "[value]" nil t)
10281 (delete-char -4))
10282 (setq semicolon-pos (point))
10283 (insert ";"))
10284 (vhdl-comment-insert-inline)
10285 (setq end-pos (point))
10286 (insert "\n")
10287 (indent-to margin)
10288 (setq vhdl-generics (vhdl-template-field
10289 (concat "[name" (and no-value "s") "]")
10290 " : " t)))
10291 (delete-region end-pos (point))
10292 (goto-char semicolon-pos)
10293 (insert ")")
10294 (end-of-line)
10295 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10296 t)))))
10297
10298 (defun vhdl-template-port-list (optional)
10299 "Read from user a port spec argument list."
10300 (let ((start (point))
10301 margin vhdl-ports object)
10302 (vhdl-insert-keyword "PORT (")
10303 (setq margin (current-column))
10304 (unless vhdl-argument-list-indent
10305 (let ((position (point)))
10306 (back-to-indentation)
10307 (setq margin (+ (current-column) vhdl-basic-offset))
10308 (goto-char position)
10309 (insert "\n")
10310 (indent-to margin)))
10311 (when (vhdl-standard-p 'ams)
10312 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10313 " " t)))
10314 (setq vhdl-ports (vhdl-template-field
10315 (concat (and optional "[") "names" (and optional "]"))
10316 nil optional))
10317 (if (not vhdl-ports)
10318 (if optional
10319 (progn (vhdl-line-kill-entire) (end-of-line -0)
10320 (unless vhdl-argument-list-indent
10321 (vhdl-line-kill-entire) (end-of-line -0)))
10322 (vhdl-template-undo start (point))
10323 nil)
10324 (insert " : ")
10325 (let (semicolon-pos end-pos)
10326 (while vhdl-ports
10327 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10328 (vhdl-template-field "IN | OUT | INOUT" " "))
10329 ((equal "QUANTITY" (upcase object))
10330 (vhdl-template-field "[IN | OUT]" " " t)))
10331 (vhdl-template-field
10332 (if (and object (equal "TERMINAL" (upcase object)))
10333 "nature" "type"))
10334 (setq semicolon-pos (point))
10335 (insert ";")
10336 (vhdl-comment-insert-inline)
10337 (setq end-pos (point))
10338 (insert "\n")
10339 (indent-to margin)
10340 (when (vhdl-standard-p 'ams)
10341 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10342 " " t)))
10343 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10344 (delete-region end-pos (point))
10345 (goto-char semicolon-pos)
10346 (insert ")")
10347 (end-of-line)
10348 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10349 t))))
10350
10351 (defun vhdl-template-generate-body (margin label)
10352 "Insert body for generate template."
10353 (vhdl-insert-keyword " GENERATE")
10354 ; (if (not (vhdl-standard-p '87))
10355 ; (vhdl-template-begin-end "GENERATE" label margin)
10356 (insert "\n\n")
10357 (indent-to margin)
10358 (vhdl-insert-keyword "END GENERATE ")
10359 (insert label ";")
10360 (end-of-line 0)
10361 (indent-to (+ margin vhdl-basic-offset)))
10362
10363 (defun vhdl-template-insert-date ()
10364 "Insert date in appropriate format."
10365 (interactive)
10366 (insert
10367 (cond
10368 ;; 'american, 'european, 'scientific kept for backward compatibility
10369 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10370 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10371 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10372 (t (format-time-string vhdl-date-format nil)))))
10373
10374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10375 ;; Help functions
10376
10377 (defun vhdl-electric-space (count)
10378 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10379 if in comment and past end-comment-column."
10380 (interactive "p")
10381 (cond ((vhdl-in-comment-p)
10382 (self-insert-command count)
10383 (cond ((>= (current-column) (+ 2 end-comment-column))
10384 (backward-char 1)
10385 (skip-chars-backward "^ \t\n")
10386 (indent-new-comment-line)
10387 (skip-chars-forward "^ \t\n")
10388 (forward-char 1))
10389 ((>= (current-column) end-comment-column)
10390 (indent-new-comment-line))
10391 (t nil)))
10392 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10393 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10394 (vhdl-prepare-search-1
10395 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10396 (self-insert-command count))
10397 (t (self-insert-command count))))
10398
10399 (defun vhdl-template-field (prompt &optional follow-string optional
10400 begin end is-string default)
10401 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10402 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10403 an empty string is inserted, return nil and call `vhdl-template-undo' for
10404 the region between BEGIN and END. IS-STRING indicates whether a string
10405 with double-quotes is to be inserted. DEFAULT specifies a default string."
10406 (let ((position (point))
10407 string)
10408 (insert "<" prompt ">")
10409 (setq string
10410 (condition-case ()
10411 (read-from-minibuffer (concat prompt ": ")
10412 (or (and is-string '("\"\"" . 2)) default)
10413 vhdl-minibuffer-local-map)
10414 (quit (if (and optional begin end)
10415 (progn (beep) "")
10416 (keyboard-quit)))))
10417 (when (or (not (equal string "")) optional)
10418 (delete-region position (point)))
10419 (when (and (equal string "") optional begin end)
10420 (vhdl-template-undo begin end)
10421 (message "Template aborted"))
10422 (unless (equal string "")
10423 (insert string)
10424 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10425 vhdl-keywords-regexp)
10426 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10427 vhdl-types-regexp)
10428 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10429 (concat "'" vhdl-attributes-regexp))
10430 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10431 vhdl-enum-values-regexp))
10432 (when (or (not (equal string "")) (not optional))
10433 (insert (or follow-string "")))
10434 (if (equal string "") nil string)))
10435
10436 (defun vhdl-decision-query (string prompt &optional optional)
10437 "Query a decision from the user."
10438 (let ((start (point)))
10439 (when string (vhdl-insert-keyword (concat string " ")))
10440 (message "%s" (or prompt ""))
10441 (let ((char (read-char)))
10442 (delete-region start (point))
10443 (if (and optional (eq char ?\r))
10444 (progn (insert " ")
10445 (unexpand-abbrev)
10446 (throw 'abort "ERROR: Template aborted"))
10447 char))))
10448
10449 (defun vhdl-insert-keyword (keyword)
10450 "Insert KEYWORD and adjust case."
10451 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10452
10453 (defun vhdl-case-keyword (keyword)
10454 "Adjust case of KEYWORD."
10455 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10456
10457 (defun vhdl-case-word (num)
10458 "Adjust case of following NUM words."
10459 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10460
10461 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10462 "If preceeding character is part of a word or a paren then hippie-expand,
10463 else insert tab (used for word completion in VHDL minibuffer)."
10464 (interactive "P")
10465 (cond
10466 ;; expand word
10467 ((= (char-syntax (preceding-char)) ?w)
10468 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10469 (case-replace nil)
10470 (hippie-expand-only-buffers
10471 (or (and (boundp 'hippie-expand-only-buffers)
10472 hippie-expand-only-buffers)
10473 '(vhdl-mode))))
10474 (vhdl-expand-abbrev prefix-arg)))
10475 ;; expand parenthesis
10476 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10477 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10478 (case-replace nil))
10479 (vhdl-expand-paren prefix-arg)))
10480 ;; insert tab
10481 (t (insert-tab))))
10482
10483 (defun vhdl-template-search-prompt ()
10484 "Search for left out template prompts and query again."
10485 (interactive)
10486 (vhdl-prepare-search-2
10487 (when (or (re-search-forward
10488 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10489 (re-search-backward
10490 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10491 (let ((string (match-string 1)))
10492 (replace-match "")
10493 (vhdl-template-field string)))))
10494
10495 (defun vhdl-template-undo (begin end)
10496 "Undo aborted template by deleting region and unexpanding the keyword."
10497 (cond (vhdl-template-invoked-by-hook
10498 (goto-char end)
10499 (insert " ")
10500 (delete-region begin end)
10501 (unexpand-abbrev))
10502 (t (delete-region begin end))))
10503
10504 (defun vhdl-insert-string-or-file (string)
10505 "Insert STRING or file contents if STRING is an existing file name."
10506 (unless (equal string "")
10507 (let ((file-name
10508 (progn (string-match "^\\([^\n]+\\)" string)
10509 (vhdl-resolve-env-variable (match-string 1 string)))))
10510 (if (file-exists-p file-name)
10511 (forward-char (cadr (insert-file-contents file-name)))
10512 (insert string)))))
10513
10514 (defun vhdl-beginning-of-block ()
10515 "Move cursor to the beginning of the enclosing block."
10516 (let (pos)
10517 (save-excursion
10518 (beginning-of-line)
10519 ;; search backward for block beginning or end
10520 (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))
10521 ;; not consider subprogram declarations
10522 (or (and (match-string 5)
10523 (save-match-data
10524 (save-excursion
10525 (goto-char (match-end 5))
10526 (forward-word 1)
10527 (vhdl-forward-syntactic-ws)
10528 (when (looking-at "(")
10529 (forward-sexp))
10530 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10531 (match-string 1)))
10532 ;; not consider configuration specifications
10533 (and (match-string 6)
10534 (save-match-data
10535 (save-excursion
10536 (vhdl-end-of-block)
10537 (beginning-of-line)
10538 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10539 (match-string 2))
10540 ;; skip subblock if block end found
10541 (vhdl-beginning-of-block)))
10542 (when pos (goto-char pos))))
10543
10544 (defun vhdl-end-of-block ()
10545 "Move cursor to the end of the enclosing block."
10546 (let (pos)
10547 (save-excursion
10548 (end-of-line)
10549 ;; search forward for block beginning or end
10550 (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))
10551 ;; not consider subprogram declarations
10552 (or (and (match-string 5)
10553 (save-match-data
10554 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10555 (match-string 1)))
10556 ;; not consider configuration specifications
10557 (and (match-string 6)
10558 (save-match-data
10559 (save-excursion
10560 (vhdl-end-of-block)
10561 (beginning-of-line)
10562 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10563 (not (match-string 2)))
10564 ;; skip subblock if block beginning found
10565 (vhdl-end-of-block)))
10566 (when pos (goto-char pos))))
10567
10568 (defun vhdl-sequential-statement-p ()
10569 "Check if point is within sequential statement part."
10570 (let ((start (point)))
10571 (save-excursion
10572 (vhdl-prepare-search-2
10573 ;; is sequential statement if ...
10574 (and (re-search-backward "^\\s-*begin\\>" nil t)
10575 ;; ... point is between "begin" and "end" of ...
10576 (progn (vhdl-end-of-block)
10577 (< start (point)))
10578 ;; ... a sequential block
10579 (progn (vhdl-beginning-of-block)
10580 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10581
10582 (defun vhdl-in-argument-list-p ()
10583 "Check if within an argument list."
10584 (save-excursion
10585 (vhdl-prepare-search-2
10586 (or (string-match "arglist"
10587 (format "%s" (caar (vhdl-get-syntactic-context))))
10588 (progn (beginning-of-line)
10589 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10590
10591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10592 ;; Abbrev hooks
10593
10594 (defun vhdl-hooked-abbrev (func)
10595 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10596 but not if inside a comment or quote."
10597 (if (or (vhdl-in-literal)
10598 (save-excursion
10599 (forward-word -1)
10600 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10601 (progn
10602 (insert " ")
10603 (unexpand-abbrev)
10604 (delete-char -1))
10605 (if (not vhdl-electric-mode)
10606 (progn
10607 (insert " ")
10608 (unexpand-abbrev)
10609 (backward-word 1)
10610 (vhdl-case-word 1)
10611 (delete-char 1))
10612 (let ((invoke-char last-command-char)
10613 (abbrev-mode -1)
10614 (vhdl-template-invoked-by-hook t))
10615 (let ((caught (catch 'abort
10616 (funcall func))))
10617 (when (stringp caught) (message "%s" caught)))
10618 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10619 ;; delete CR which is still in event queue
10620 (if (fboundp 'enqueue-eval-event)
10621 (enqueue-eval-event 'delete-char -1)
10622 (setq unread-command-events ; push back a delete char
10623 (list (vhdl-character-to-event ?\177))))))))
10624
10625 (defun vhdl-template-alias-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-alias))
10627 (defun vhdl-template-architecture-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10629 (defun vhdl-template-assert-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-assert))
10631 (defun vhdl-template-attribute-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10633 (defun vhdl-template-block-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-block))
10635 (defun vhdl-template-break-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-break))
10637 (defun vhdl-template-case-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-case))
10639 (defun vhdl-template-component-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-component))
10641 (defun vhdl-template-instance-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-instance))
10643 (defun vhdl-template-conditional-signal-asst-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10645 (defun vhdl-template-configuration-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10647 (defun vhdl-template-constant-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-constant))
10649 (defun vhdl-template-disconnect-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10651 (defun vhdl-template-display-comment-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-comment-display))
10653 (defun vhdl-template-else-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-else))
10655 (defun vhdl-template-elsif-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10657 (defun vhdl-template-entity-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-entity))
10659 (defun vhdl-template-exit-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-exit))
10661 (defun vhdl-template-file-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-file))
10663 (defun vhdl-template-for-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-for))
10665 (defun vhdl-template-function-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-function))
10667 (defun vhdl-template-generic-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-generic))
10669 (defun vhdl-template-group-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-group))
10671 (defun vhdl-template-library-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-library))
10673 (defun vhdl-template-limit-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-limit))
10675 (defun vhdl-template-if-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-if))
10677 (defun vhdl-template-bare-loop-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10679 (defun vhdl-template-map-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-map))
10681 (defun vhdl-template-nature-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-nature))
10683 (defun vhdl-template-next-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-next))
10685 (defun vhdl-template-others-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-others))
10687 (defun vhdl-template-package-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-package))
10689 (defun vhdl-template-port-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-port))
10691 (defun vhdl-template-procedural-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10693 (defun vhdl-template-procedure-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10695 (defun vhdl-template-process-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-process))
10697 (defun vhdl-template-quantity-hook ()
10698 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10699 (defun vhdl-template-report-hook ()
10700 (vhdl-hooked-abbrev 'vhdl-template-report))
10701 (defun vhdl-template-return-hook ()
10702 (vhdl-hooked-abbrev 'vhdl-template-return))
10703 (defun vhdl-template-selected-signal-asst-hook ()
10704 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10705 (defun vhdl-template-signal-hook ()
10706 (vhdl-hooked-abbrev 'vhdl-template-signal))
10707 (defun vhdl-template-subnature-hook ()
10708 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10709 (defun vhdl-template-subtype-hook ()
10710 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10711 (defun vhdl-template-terminal-hook ()
10712 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10713 (defun vhdl-template-type-hook ()
10714 (vhdl-hooked-abbrev 'vhdl-template-type))
10715 (defun vhdl-template-use-hook ()
10716 (vhdl-hooked-abbrev 'vhdl-template-use))
10717 (defun vhdl-template-variable-hook ()
10718 (vhdl-hooked-abbrev 'vhdl-template-variable))
10719 (defun vhdl-template-wait-hook ()
10720 (vhdl-hooked-abbrev 'vhdl-template-wait))
10721 (defun vhdl-template-when-hook ()
10722 (vhdl-hooked-abbrev 'vhdl-template-when))
10723 (defun vhdl-template-while-loop-hook ()
10724 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10725 (defun vhdl-template-with-hook ()
10726 (vhdl-hooked-abbrev 'vhdl-template-with))
10727 (defun vhdl-template-and-hook ()
10728 (vhdl-hooked-abbrev 'vhdl-template-and))
10729 (defun vhdl-template-or-hook ()
10730 (vhdl-hooked-abbrev 'vhdl-template-or))
10731 (defun vhdl-template-nand-hook ()
10732 (vhdl-hooked-abbrev 'vhdl-template-nand))
10733 (defun vhdl-template-nor-hook ()
10734 (vhdl-hooked-abbrev 'vhdl-template-nor))
10735 (defun vhdl-template-xor-hook ()
10736 (vhdl-hooked-abbrev 'vhdl-template-xor))
10737 (defun vhdl-template-xnor-hook ()
10738 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10739 (defun vhdl-template-not-hook ()
10740 (vhdl-hooked-abbrev 'vhdl-template-not))
10741
10742 (defun vhdl-template-default-hook ()
10743 (vhdl-hooked-abbrev 'vhdl-template-default))
10744 (defun vhdl-template-default-indent-hook ()
10745 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10746
10747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10748 ;; Template insertion from completion list
10749
10750 (defun vhdl-template-insert-construct (name)
10751 "Insert the built-in construct template with NAME."
10752 (interactive
10753 (list (let ((completion-ignore-case t))
10754 (completing-read "Construct name: "
10755 vhdl-template-construct-alist nil t))))
10756 (vhdl-template-insert-fun
10757 (cadr (assoc name vhdl-template-construct-alist))))
10758
10759 (defun vhdl-template-insert-package (name)
10760 "Insert the built-in package template with NAME."
10761 (interactive
10762 (list (let ((completion-ignore-case t))
10763 (completing-read "Package name: "
10764 vhdl-template-package-alist nil t))))
10765 (vhdl-template-insert-fun
10766 (cadr (assoc name vhdl-template-package-alist))))
10767
10768 (defun vhdl-template-insert-directive (name)
10769 "Insert the built-in directive template with NAME."
10770 (interactive
10771 (list (let ((completion-ignore-case t))
10772 (completing-read "Directive name: "
10773 vhdl-template-directive-alist nil t))))
10774 (vhdl-template-insert-fun
10775 (cadr (assoc name vhdl-template-directive-alist))))
10776
10777 (defun vhdl-template-insert-fun (fun)
10778 "Call FUN to insert a built-in template."
10779 (let ((caught (catch 'abort (when fun (funcall fun)))))
10780 (when (stringp caught) (message "%s" caught))))
10781
10782
10783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10784 ;;; Models
10785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10786
10787 (defun vhdl-model-insert (model-name)
10788 "Insert the user model with name MODEL-NAME."
10789 (interactive
10790 (let ((completion-ignore-case t))
10791 (list (completing-read "Model name: " vhdl-model-alist))))
10792 (indent-according-to-mode)
10793 (let ((start (point-marker))
10794 (margin (current-indentation))
10795 model position prompt string end)
10796 (vhdl-prepare-search-2
10797 (when (setq model (assoc model-name vhdl-model-alist))
10798 ;; insert model
10799 (beginning-of-line)
10800 (delete-horizontal-space)
10801 (goto-char start)
10802 (vhdl-insert-string-or-file (nth 1 model))
10803 (setq end (point-marker))
10804 ;; indent code
10805 (goto-char start)
10806 (beginning-of-line)
10807 (while (< (point) end)
10808 (unless (looking-at "^$")
10809 (insert-char ? margin))
10810 (beginning-of-line 2))
10811 (goto-char start)
10812 ;; insert clock
10813 (unless (equal "" vhdl-clock-name)
10814 (while (re-search-forward "<clock>" end t)
10815 (replace-match vhdl-clock-name)))
10816 (goto-char start)
10817 ;; insert reset
10818 (unless (equal "" vhdl-reset-name)
10819 (while (re-search-forward "<reset>" end t)
10820 (replace-match vhdl-reset-name)))
10821 ;; replace header prompts
10822 (vhdl-template-replace-header-keywords start end nil t)
10823 (goto-char start)
10824 ;; query other prompts
10825 (while (re-search-forward
10826 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10827 (unless (equal "cursor" (match-string 1))
10828 (setq position (match-beginning 1))
10829 (setq prompt (match-string 1))
10830 (replace-match "")
10831 (setq string (vhdl-template-field prompt nil t))
10832 ;; replace occurrences of same prompt
10833 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10834 (replace-match (or string "")))
10835 (goto-char position)))
10836 (goto-char start)
10837 ;; goto final position
10838 (if (re-search-forward "<cursor>" end t)
10839 (replace-match "")
10840 (goto-char end))))))
10841
10842 (defun vhdl-model-defun ()
10843 "Define help and hook functions for user models."
10844 (let ((model-alist vhdl-model-alist)
10845 model-name model-keyword)
10846 (while model-alist
10847 ;; define functions for user models that can be invoked from menu and key
10848 ;; bindings and which themselves call `vhdl-model-insert' with the model
10849 ;; name as argument
10850 (setq model-name (nth 0 (car model-alist)))
10851 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10852 ,(concat "Insert model for \"" model-name "\".")
10853 (interactive)
10854 (vhdl-model-insert ,model-name)))
10855 ;; define hooks for user models that are invoked from keyword abbrevs
10856 (setq model-keyword (nth 3 (car model-alist)))
10857 (unless (equal model-keyword "")
10858 (eval `(defun
10859 ,(vhdl-function-name
10860 "vhdl-model" model-name "hook") ()
10861 (vhdl-hooked-abbrev
10862 ',(vhdl-function-name "vhdl-model" model-name)))))
10863 (setq model-alist (cdr model-alist)))))
10864
10865 (vhdl-model-defun)
10866
10867
10868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10869 ;;; Port translation
10870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10871
10872 (defvar vhdl-port-list nil
10873 "Variable to hold last port map parsed.")
10874 ;; structure: (parenthesised expression means list of such entries)
10875 ;; (ent-name
10876 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10877 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10878 ;; (lib-name pack-key))
10879
10880 (defun vhdl-parse-string (string &optional optional)
10881 "Check that the text following point matches the regexp in STRING."
10882 (if (looking-at string)
10883 (goto-char (match-end 0))
10884 (unless optional
10885 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10886 (vhdl-current-line) string)))
10887 nil))
10888
10889 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10890 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10891 (vhdl-prepare-search-1
10892 (if (string-match (car regexp-cons) string)
10893 (if adjust-case
10894 (funcall vhdl-file-name-case
10895 (replace-match (cdr regexp-cons) t nil string))
10896 (replace-match (cdr regexp-cons) t nil string))
10897 string)))
10898
10899 (defun vhdl-parse-group-comment ()
10900 "Parse comment and empty lines between groups of lines."
10901 (let ((start (point))
10902 string)
10903 (vhdl-forward-comment (point-max))
10904 (setq string (buffer-substring-no-properties start (point)))
10905 (vhdl-forward-syntactic-ws)
10906 ;; strip off leading blanks and first newline
10907 (while (string-match "^\\(\\s-+\\)" string)
10908 (setq string (concat (substring string 0 (match-beginning 1))
10909 (substring string (match-end 1)))))
10910 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10911 (substring string 1)
10912 string)))
10913
10914 (defun vhdl-paste-group-comment (string indent)
10915 "Paste comment and empty lines from STRING between groups of lines
10916 with INDENT."
10917 (let ((pos (point-marker)))
10918 (when (> indent 0)
10919 (while (string-match "^\\(--\\)" string)
10920 (setq string (concat (substring string 0 (match-beginning 1))
10921 (make-string indent ? )
10922 (substring string (match-beginning 1))))))
10923 (beginning-of-line)
10924 (insert string)
10925 (goto-char pos)))
10926
10927 (defvar vhdl-port-flattened nil
10928 "Indicates whether a port has been flattened.")
10929
10930 (defun vhdl-port-flatten (&optional as-alist)
10931 "Flatten port list so that only one generic/port exists per line.
10932 This operation is performed on an internally stored port and is only
10933 reflected in a subsequent paste operation."
10934 (interactive)
10935 (if (not vhdl-port-list)
10936 (error "ERROR: No port has been read")
10937 (message "Flattening port for next paste...")
10938 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10939 (old-vhdl-port-list (cdr vhdl-port-list))
10940 old-port-list new-port-list old-port new-port names)
10941 ;; traverse port list and flatten entries
10942 (while (cdr old-vhdl-port-list)
10943 (setq old-port-list (car old-vhdl-port-list))
10944 (setq new-port-list nil)
10945 (while old-port-list
10946 (setq old-port (car old-port-list))
10947 (setq names (car old-port))
10948 (while names
10949 (setq new-port (cons (if as-alist (car names) (list (car names)))
10950 (cdr old-port)))
10951 (setq new-port-list (append new-port-list (list new-port)))
10952 (setq names (cdr names)))
10953 (setq old-port-list (cdr old-port-list)))
10954 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10955 (setq new-vhdl-port-list (append new-vhdl-port-list
10956 (list new-port-list))))
10957 (setq vhdl-port-list
10958 (append new-vhdl-port-list (list old-vhdl-port-list))
10959 vhdl-port-flattened t)
10960 (message "Flattening port for next paste...done"))))
10961
10962 (defvar vhdl-port-reversed-direction nil
10963 "Indicates whether port directions are reversed.")
10964
10965 (defun vhdl-port-reverse-direction ()
10966 "Reverse direction for all ports (useful in testbenches).
10967 This operation is performed on an internally stored port and is only
10968 reflected in a subsequent paste operation."
10969 (interactive)
10970 (if (not vhdl-port-list)
10971 (error "ERROR: No port has been read")
10972 (message "Reversing port directions for next paste...")
10973 (let ((port-list (nth 2 vhdl-port-list))
10974 port-dir-car port-dir)
10975 ;; traverse port list and reverse directions
10976 (while port-list
10977 (setq port-dir-car (cddr (car port-list))
10978 port-dir (car port-dir-car))
10979 (setcar port-dir-car
10980 (cond ((equal port-dir "in") "out")
10981 ((equal port-dir "out") "in")
10982 (t port-dir)))
10983 (setq port-list (cdr port-list)))
10984 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10985 (message "Reversing port directions for next paste...done"))))
10986
10987 (defun vhdl-port-copy ()
10988 "Get generic and port information from an entity or component declaration."
10989 (interactive)
10990 (save-excursion
10991 (let (parse-error end-of-list
10992 decl-type name generic-list port-list context-clause
10993 object names direct type init comment group-comment)
10994 (vhdl-prepare-search-2
10995 (setq
10996 parse-error
10997 (catch 'parse
10998 ;; check if within entity or component declaration
10999 (end-of-line)
11000 (when (or (not (re-search-backward
11001 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11002 (equal "END" (upcase (match-string 1))))
11003 (throw 'parse "ERROR: Not within an entity or component declaration"))
11004 (setq decl-type (downcase (match-string-no-properties 1)))
11005 (forward-word 1)
11006 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11007 (setq name (match-string-no-properties 1))
11008 (message "Reading port of %s \"%s\"..." decl-type name)
11009 (vhdl-forward-syntactic-ws)
11010 ;; parse generic clause
11011 (when (vhdl-parse-string "generic[ \t\n]*(" t)
11012 ;; parse group comment and spacing
11013 (setq group-comment (vhdl-parse-group-comment))
11014 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11015 (while (not end-of-list)
11016 ;; parse names (accept extended identifiers)
11017 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11018 (setq names (list (match-string-no-properties 1)))
11019 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11020 (setq names
11021 (append names (list (match-string-no-properties 1)))))
11022 ;; parse type
11023 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11024 (setq type (match-string-no-properties 1))
11025 (setq comment nil)
11026 (while (looking-at "(")
11027 (setq type
11028 (concat type
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 type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11035 (setq comment (substring type (match-beginning 2)))
11036 (setq type (substring type 0 (match-beginning 1))))
11037 ;; strip of trailing group-comment
11038 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11039 (setq type (substring type 0 (match-end 1)))
11040 ;; parse initialization expression
11041 (setq init nil)
11042 (when (vhdl-parse-string ":=[ \t\n]*" t)
11043 (vhdl-parse-string "\\([^();\n]*\\)")
11044 (setq init (match-string-no-properties 1))
11045 (while (looking-at "(")
11046 (setq init
11047 (concat init
11048 (buffer-substring-no-properties
11049 (point) (progn (forward-sexp) (point)))
11050 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11051 (match-string-no-properties 1))))))
11052 ;; special case: closing parenthesis is on separate line
11053 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11054 (setq comment (substring init (match-beginning 2)))
11055 (setq init (substring init 0 (match-beginning 1)))
11056 (vhdl-forward-syntactic-ws))
11057 (skip-chars-forward " \t")
11058 ;; parse inline comment, special case: as above, no initial.
11059 (unless comment
11060 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11061 (match-string-no-properties 1))))
11062 (vhdl-forward-syntactic-ws)
11063 (setq end-of-list (vhdl-parse-string ")" t))
11064 (vhdl-parse-string "\\s-*;\\s-*")
11065 ;; parse inline comment
11066 (unless comment
11067 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11068 (match-string-no-properties 1))))
11069 ;; save everything in list
11070 (setq generic-list (append generic-list
11071 (list (list names type init
11072 comment group-comment))))
11073 ;; parse group comment and spacing
11074 (setq group-comment (vhdl-parse-group-comment))))
11075 ;; parse port clause
11076 (when (vhdl-parse-string "port[ \t\n]*(" t)
11077 ;; parse group comment and spacing
11078 (setq group-comment (vhdl-parse-group-comment))
11079 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11080 (while (not end-of-list)
11081 ;; parse object
11082 (setq object
11083 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11084 (match-string-no-properties 1)))
11085 ;; parse names (accept extended identifiers)
11086 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11087 (setq names (list (match-string-no-properties 1)))
11088 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11089 (setq names (append names (list (match-string-no-properties 1)))))
11090 ;; parse direction
11091 (vhdl-parse-string ":[ \t\n]*")
11092 (setq direct
11093 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11094 (match-string-no-properties 1)))
11095 ;; parse type
11096 (vhdl-parse-string "\\([^();\n]+\\)")
11097 (setq type (match-string-no-properties 1))
11098 (setq comment nil)
11099 (while (looking-at "(")
11100 (setq type (concat type
11101 (buffer-substring-no-properties
11102 (point) (progn (forward-sexp) (point)))
11103 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11104 (match-string-no-properties 1)))))
11105 ;; special case: closing parenthesis is on separate line
11106 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11107 (setq comment (substring type (match-beginning 2)))
11108 (setq type (substring type 0 (match-beginning 1))))
11109 ;; strip of trailing group-comment
11110 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11111 (setq type (substring type 0 (match-end 1)))
11112 (vhdl-forward-syntactic-ws)
11113 (setq end-of-list (vhdl-parse-string ")" t))
11114 (vhdl-parse-string "\\s-*;\\s-*")
11115 ;; parse inline comment
11116 (unless comment
11117 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11118 (match-string-no-properties 1))))
11119 ;; save everything in list
11120 (setq port-list (append port-list
11121 (list (list names object direct type
11122 comment group-comment))))
11123 ;; parse group comment and spacing
11124 (setq group-comment (vhdl-parse-group-comment))))
11125 ; (vhdl-parse-string "end\\>")
11126 ;; parse context clause
11127 (setq context-clause (vhdl-scan-context-clause))
11128 ; ;; add surrounding package to context clause
11129 ; (when (and (equal decl-type "component")
11130 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11131 ; (setq context-clause
11132 ; (append context-clause
11133 ; (list (cons (vhdl-work-library)
11134 ; (match-string-no-properties 1))))))
11135 (message "Reading port of %s \"%s\"...done" decl-type name)
11136 nil)))
11137 ;; finish parsing
11138 (if parse-error
11139 (error parse-error)
11140 (setq vhdl-port-list (list name generic-list port-list context-clause)
11141 vhdl-port-reversed-direction nil
11142 vhdl-port-flattened nil)))))
11143
11144 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11145 "Paste a context clause."
11146 (let ((margin (current-indentation))
11147 (clause-list (nth 3 vhdl-port-list))
11148 clause)
11149 (while clause-list
11150 (setq clause (car clause-list))
11151 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11152 (downcase exclude-pack-name)))
11153 (save-excursion
11154 (re-search-backward
11155 (concat "^\\s-*use\\s-+" (car clause)
11156 "\." (cdr clause) "\\>") nil t)))
11157 (vhdl-template-standard-package (car clause) (cdr clause))
11158 (insert "\n"))
11159 (setq clause-list (cdr clause-list)))))
11160
11161 (defun vhdl-port-paste-generic (&optional no-init)
11162 "Paste a generic clause."
11163 (let ((margin (current-indentation))
11164 (generic-list (nth 1 vhdl-port-list))
11165 list-margin start names generic)
11166 ;; paste generic clause
11167 (when generic-list
11168 (setq start (point))
11169 (vhdl-insert-keyword "GENERIC (")
11170 (unless vhdl-argument-list-indent
11171 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11172 (setq list-margin (current-column))
11173 (while generic-list
11174 (setq generic (car generic-list))
11175 ;; paste group comment and spacing
11176 (when (memq vhdl-include-group-comments '(decl always))
11177 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11178 ;; paste names
11179 (setq names (nth 0 generic))
11180 (while names
11181 (insert (car names))
11182 (setq names (cdr names))
11183 (when names (insert ", ")))
11184 ;; paste type
11185 (insert " : " (nth 1 generic))
11186 ;; paste initialization
11187 (when (and (not no-init) (nth 2 generic))
11188 (insert " := " (nth 2 generic)))
11189 (unless (cdr generic-list) (insert ")"))
11190 (insert ";")
11191 ;; paste comment
11192 (when (and vhdl-include-port-comments (nth 3 generic))
11193 (vhdl-comment-insert-inline (nth 3 generic) t))
11194 (setq generic-list (cdr generic-list))
11195 (when generic-list (insert "\n") (indent-to list-margin)))
11196 ;; align generic clause
11197 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11198
11199 (defun vhdl-port-paste-port ()
11200 "Paste a port clause."
11201 (let ((margin (current-indentation))
11202 (port-list (nth 2 vhdl-port-list))
11203 list-margin start names port)
11204 ;; paste port clause
11205 (when port-list
11206 (setq start (point))
11207 (vhdl-insert-keyword "PORT (")
11208 (unless vhdl-argument-list-indent
11209 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11210 (setq list-margin (current-column))
11211 (while port-list
11212 (setq port (car port-list))
11213 ;; paste group comment and spacing
11214 (when (memq vhdl-include-group-comments '(decl always))
11215 (vhdl-paste-group-comment (nth 5 port) list-margin))
11216 ;; paste object
11217 (when (nth 1 port) (insert (nth 1 port) " "))
11218 ;; paste names
11219 (setq names (nth 0 port))
11220 (while names
11221 (insert (car names))
11222 (setq names (cdr names))
11223 (when names (insert ", ")))
11224 ;; paste direction
11225 (insert " : ")
11226 (when (nth 2 port) (insert (nth 2 port) " "))
11227 ;; paste type
11228 (insert (nth 3 port))
11229 (unless (cdr port-list) (insert ")"))
11230 (insert ";")
11231 ;; paste comment
11232 (when (and vhdl-include-port-comments (nth 4 port))
11233 (vhdl-comment-insert-inline (nth 4 port) t))
11234 (setq port-list (cdr port-list))
11235 (when port-list (insert "\n") (indent-to list-margin)))
11236 ;; align port clause
11237 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11238
11239 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11240 "Paste as an entity or component declaration."
11241 (unless no-indent (indent-according-to-mode))
11242 (let ((margin (current-indentation))
11243 (name (nth 0 vhdl-port-list)))
11244 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11245 (insert name)
11246 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11247 (vhdl-insert-keyword " IS"))
11248 ;; paste generic and port clause
11249 (when (nth 1 vhdl-port-list)
11250 (insert "\n")
11251 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11252 (insert "\n"))
11253 (indent-to (+ margin vhdl-basic-offset))
11254 (vhdl-port-paste-generic (eq kind 'component)))
11255 (when (nth 2 vhdl-port-list)
11256 (insert "\n")
11257 (when (and (memq vhdl-insert-empty-lines '(unit all))
11258 (eq kind 'entity))
11259 (insert "\n"))
11260 (indent-to (+ margin vhdl-basic-offset)))
11261 (vhdl-port-paste-port)
11262 (insert "\n")
11263 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11264 (insert "\n"))
11265 (indent-to margin)
11266 (vhdl-insert-keyword "END")
11267 (if (eq kind 'entity)
11268 (progn
11269 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11270 (insert " " name))
11271 (vhdl-insert-keyword " COMPONENT")
11272 (unless (vhdl-standard-p '87) (insert " " name)))
11273 (insert ";")))
11274
11275 (defun vhdl-port-paste-entity (&optional no-indent)
11276 "Paste as an entity declaration."
11277 (interactive)
11278 (if (not vhdl-port-list)
11279 (error "ERROR: No port read")
11280 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11281 (vhdl-port-paste-declaration 'entity no-indent)
11282 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11283
11284 (defun vhdl-port-paste-component (&optional no-indent)
11285 "Paste as a component declaration."
11286 (interactive)
11287 (if (not vhdl-port-list)
11288 (error "ERROR: No port read")
11289 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11290 (vhdl-port-paste-declaration 'component no-indent)
11291 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11292
11293 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11294 "Paste as a generic map."
11295 (interactive)
11296 (unless secondary (indent-according-to-mode))
11297 (let ((margin (current-indentation))
11298 list-margin start generic
11299 (generic-list (nth 1 vhdl-port-list)))
11300 (when generic-list
11301 (setq start (point))
11302 (vhdl-insert-keyword "GENERIC MAP (")
11303 (if (not vhdl-association-list-with-formals)
11304 ;; paste list of actual generics
11305 (while generic-list
11306 (insert (if no-constants
11307 (car (nth 0 (car generic-list)))
11308 (or (nth 2 (car generic-list)) " ")))
11309 (setq generic-list (cdr generic-list))
11310 (insert (if generic-list ", " ")"))
11311 (when (and (not generic-list) secondary
11312 (null (nth 2 vhdl-port-list)))
11313 (insert ";")))
11314 (unless vhdl-argument-list-indent
11315 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11316 (setq list-margin (current-column))
11317 (while generic-list
11318 (setq generic (car generic-list))
11319 ;; paste group comment and spacing
11320 (when (eq vhdl-include-group-comments 'always)
11321 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11322 ;; paste formal and actual generic
11323 (insert (car (nth 0 generic)) " => "
11324 (if no-constants
11325 (car (nth 0 generic))
11326 (or (nth 2 generic) "")))
11327 (setq generic-list (cdr generic-list))
11328 (insert (if generic-list "," ")"))
11329 (when (and (not generic-list) secondary
11330 (null (nth 2 vhdl-port-list)))
11331 (insert ";"))
11332 ;; paste comment
11333 (when (or vhdl-include-type-comments
11334 (and vhdl-include-port-comments (nth 3 generic)))
11335 (vhdl-comment-insert-inline
11336 (concat
11337 (when vhdl-include-type-comments
11338 (concat "[" (nth 1 generic) "] "))
11339 (when vhdl-include-port-comments (nth 3 generic))) t))
11340 (when generic-list (insert "\n") (indent-to list-margin)))
11341 ;; align generic map
11342 (when vhdl-auto-align
11343 (vhdl-align-region-groups start (point) 1 t))))))
11344
11345 (defun vhdl-port-paste-port-map ()
11346 "Paste as a port map."
11347 (let ((margin (current-indentation))
11348 list-margin start port
11349 (port-list (nth 2 vhdl-port-list)))
11350 (when port-list
11351 (setq start (point))
11352 (vhdl-insert-keyword "PORT MAP (")
11353 (if (not vhdl-association-list-with-formals)
11354 ;; paste list of actual ports
11355 (while port-list
11356 (insert (vhdl-replace-string vhdl-actual-port-name
11357 (car (nth 0 (car port-list)))))
11358 (setq port-list (cdr port-list))
11359 (insert (if port-list ", " ")")))
11360 (unless vhdl-argument-list-indent
11361 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11362 (setq list-margin (current-column))
11363 (while port-list
11364 (setq port (car port-list))
11365 ;; paste group comment and spacing
11366 (when (eq vhdl-include-group-comments 'always)
11367 (vhdl-paste-group-comment (nth 5 port) list-margin))
11368 ;; paste formal and actual port
11369 (insert (car (nth 0 port)) " => ")
11370 (insert (vhdl-replace-string vhdl-actual-port-name
11371 (car (nth 0 port))))
11372 (setq port-list (cdr port-list))
11373 (insert (if port-list "," ");"))
11374 ;; paste comment
11375 (when (or vhdl-include-direction-comments
11376 vhdl-include-type-comments
11377 (and vhdl-include-port-comments (nth 4 port)))
11378 (vhdl-comment-insert-inline
11379 (concat
11380 (cond ((and vhdl-include-direction-comments
11381 vhdl-include-type-comments)
11382 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11383 (nth 3 port) "] "))
11384 ((and vhdl-include-direction-comments (nth 2 port))
11385 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11386 (vhdl-include-direction-comments " ")
11387 (vhdl-include-type-comments
11388 (concat "[" (nth 3 port) "] ")))
11389 (when vhdl-include-port-comments (nth 4 port))) t))
11390 (when port-list (insert "\n") (indent-to list-margin)))
11391 ;; align port clause
11392 (when vhdl-auto-align
11393 (vhdl-align-region-groups start (point) 1))))))
11394
11395 (defun vhdl-port-paste-instance (&optional name no-indent title)
11396 "Paste as an instantiation."
11397 (interactive)
11398 (if (not vhdl-port-list)
11399 (error "ERROR: No port read")
11400 (let ((orig-vhdl-port-list vhdl-port-list))
11401 ;; flatten local copy of port list (must be flat for port mapping)
11402 (vhdl-port-flatten)
11403 (unless no-indent (indent-according-to-mode))
11404 (let ((margin (current-indentation)))
11405 ;; paste instantiation
11406 (cond (name
11407 (insert name))
11408 ((equal (cdr vhdl-instance-name) "")
11409 (setq name (vhdl-template-field "instance name")))
11410 ((string-match "\%d" (cdr vhdl-instance-name))
11411 (let ((n 1))
11412 (while (save-excursion
11413 (setq name (format (vhdl-replace-string
11414 vhdl-instance-name
11415 (nth 0 vhdl-port-list)) n))
11416 (goto-char (point-min))
11417 (vhdl-re-search-forward name nil t))
11418 (setq n (1+ n)))
11419 (insert name)))
11420 (t (insert (vhdl-replace-string vhdl-instance-name
11421 (nth 0 vhdl-port-list)))))
11422 (message "Pasting port as instantiation \"%s\"..." name)
11423 (insert ": ")
11424 (when title
11425 (save-excursion
11426 (beginning-of-line)
11427 (indent-to vhdl-basic-offset)
11428 (insert "-- instance \"" name "\"\n")))
11429 (if (not (vhdl-use-direct-instantiation))
11430 (insert (nth 0 vhdl-port-list))
11431 (vhdl-insert-keyword "ENTITY ")
11432 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11433 (when (nth 1 vhdl-port-list)
11434 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11435 (vhdl-port-paste-generic-map t t))
11436 (when (nth 2 vhdl-port-list)
11437 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11438 (vhdl-port-paste-port-map))
11439 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11440 (insert ";"))
11441 (message "Pasting port as instantiation \"%s\"...done" name))
11442 (setq vhdl-port-list orig-vhdl-port-list))))
11443
11444 (defun vhdl-port-paste-constants (&optional no-indent)
11445 "Paste generics as constants."
11446 (interactive)
11447 (if (not vhdl-port-list)
11448 (error "ERROR: No port read")
11449 (let ((orig-vhdl-port-list vhdl-port-list))
11450 (message "Pasting port as constants...")
11451 ;; flatten local copy of port list (must be flat for constant initial.)
11452 (vhdl-port-flatten)
11453 (unless no-indent (indent-according-to-mode))
11454 (let ((margin (current-indentation))
11455 start generic name
11456 (generic-list (nth 1 vhdl-port-list)))
11457 (when generic-list
11458 (setq start (point))
11459 (while generic-list
11460 (setq generic (car generic-list))
11461 ;; paste group comment and spacing
11462 (when (memq vhdl-include-group-comments '(decl always))
11463 (vhdl-paste-group-comment (nth 4 generic) margin))
11464 (vhdl-insert-keyword "CONSTANT ")
11465 ;; paste generic constants
11466 (setq name (nth 0 generic))
11467 (when name
11468 (insert (car name))
11469 ;; paste type
11470 (insert " : " (nth 1 generic))
11471 ;; paste initialization
11472 (when (nth 2 generic)
11473 (insert " := " (nth 2 generic)))
11474 (insert ";")
11475 ;; paste comment
11476 (when (and vhdl-include-port-comments (nth 3 generic))
11477 (vhdl-comment-insert-inline (nth 3 generic) t))
11478 (setq generic-list (cdr generic-list))
11479 (when generic-list (insert "\n") (indent-to margin))))
11480 ;; align signal list
11481 (when vhdl-auto-align
11482 (vhdl-align-region-groups start (point) 1))))
11483 (message "Pasting port as constants...done")
11484 (setq vhdl-port-list orig-vhdl-port-list))))
11485
11486 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11487 "Paste ports as internal signals."
11488 (interactive)
11489 (if (not vhdl-port-list)
11490 (error "ERROR: No port read")
11491 (message "Pasting port as signals...")
11492 (unless no-indent (indent-according-to-mode))
11493 (let ((margin (current-indentation))
11494 start port names
11495 (port-list (nth 2 vhdl-port-list)))
11496 (when port-list
11497 (setq start (point))
11498 (while port-list
11499 (setq port (car port-list))
11500 ;; paste group comment and spacing
11501 (when (memq vhdl-include-group-comments '(decl always))
11502 (vhdl-paste-group-comment (nth 5 port) margin))
11503 ;; paste object
11504 (if (nth 1 port)
11505 (insert (nth 1 port) " ")
11506 (vhdl-insert-keyword "SIGNAL "))
11507 ;; paste actual port signals
11508 (setq names (nth 0 port))
11509 (while names
11510 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11511 (setq names (cdr names))
11512 (when names (insert ", ")))
11513 ;; paste type
11514 (insert " : " (nth 3 port))
11515 ;; paste initialization (inputs only)
11516 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11517 (insert " := " (if (string-match "(.+)" (nth 3 port))
11518 "(others => '0')" "'0'")))
11519 (insert ";")
11520 ;; paste comment
11521 (when (or vhdl-include-direction-comments
11522 (and vhdl-include-port-comments (nth 4 port)))
11523 (vhdl-comment-insert-inline
11524 (concat
11525 (cond ((and vhdl-include-direction-comments (nth 2 port))
11526 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11527 (vhdl-include-direction-comments " "))
11528 (when vhdl-include-port-comments (nth 4 port))) t))
11529 (setq port-list (cdr port-list))
11530 (when port-list (insert "\n") (indent-to margin)))
11531 ;; align signal list
11532 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11533 (message "Pasting port as signals...done")))
11534
11535 (defun vhdl-port-paste-initializations (&optional no-indent)
11536 "Paste ports as signal initializations."
11537 (interactive)
11538 (if (not vhdl-port-list)
11539 (error "ERROR: No port read")
11540 (let ((orig-vhdl-port-list vhdl-port-list))
11541 (message "Pasting port as initializations...")
11542 ;; flatten local copy of port list (must be flat for signal initial.)
11543 (vhdl-port-flatten)
11544 (unless no-indent (indent-according-to-mode))
11545 (let ((margin (current-indentation))
11546 start port name
11547 (port-list (nth 2 vhdl-port-list)))
11548 (when port-list
11549 (setq start (point))
11550 (while port-list
11551 (setq port (car port-list))
11552 ;; paste actual port signal (inputs only)
11553 (when (equal "IN" (upcase (nth 2 port)))
11554 (setq name (car (nth 0 port)))
11555 (insert (vhdl-replace-string vhdl-actual-port-name name))
11556 ;; paste initialization
11557 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11558 "(others => '0')" "'0'") ";"))
11559 (setq port-list (cdr port-list))
11560 (when (and port-list
11561 (equal "IN" (upcase (nth 2 (car port-list)))))
11562 (insert "\n") (indent-to margin)))
11563 ;; align signal list
11564 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11565 (message "Pasting port as initializations...done")
11566 (setq vhdl-port-list orig-vhdl-port-list))))
11567
11568 (defun vhdl-port-paste-testbench ()
11569 "Paste as a bare-bones testbench."
11570 (interactive)
11571 (if (not vhdl-port-list)
11572 (error "ERROR: No port read")
11573 (let ((case-fold-search t)
11574 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11575 (nth 0 vhdl-port-list)))
11576 (source-buffer (current-buffer))
11577 arch-name config-name ent-file-name arch-file-name
11578 ent-buffer arch-buffer position)
11579 ;; open entity file
11580 (unless (eq vhdl-testbench-create-files 'none)
11581 (setq ent-file-name
11582 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11583 ent-name t)
11584 "." (file-name-extension (buffer-file-name))))
11585 (if (file-exists-p ent-file-name)
11586 (if (y-or-n-p
11587 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11588 (progn (find-file ent-file-name)
11589 (erase-buffer)
11590 (set-buffer-modified-p nil))
11591 (if (eq vhdl-testbench-create-files 'separate)
11592 (setq ent-file-name nil)
11593 (error "ERROR: Pasting port as testbench...aborted")))
11594 (find-file ent-file-name)))
11595 (unless (and (eq vhdl-testbench-create-files 'separate)
11596 (null ent-file-name))
11597 ;; paste entity header
11598 (if vhdl-testbench-include-header
11599 (progn (vhdl-template-header
11600 (concat "Testbench for design \""
11601 (nth 0 vhdl-port-list) "\""))
11602 (goto-char (point-max)))
11603 (vhdl-comment-display-line) (insert "\n\n"))
11604 ;; paste std_logic_1164 package
11605 (when vhdl-testbench-include-library
11606 (vhdl-template-package-std-logic-1164)
11607 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11608 ;; paste entity declaration
11609 (vhdl-insert-keyword "ENTITY ")
11610 (insert ent-name)
11611 (vhdl-insert-keyword " IS")
11612 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11613 (insert "\n")
11614 (vhdl-insert-keyword "END ")
11615 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11616 (insert ent-name ";")
11617 (insert "\n\n")
11618 (vhdl-comment-display-line) (insert "\n"))
11619 ;; get architecture name
11620 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11621 (read-from-minibuffer "architecture name: "
11622 nil vhdl-minibuffer-local-map)
11623 (vhdl-replace-string vhdl-testbench-architecture-name
11624 (nth 0 vhdl-port-list))))
11625 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11626 ;; open architecture file
11627 (if (not (eq vhdl-testbench-create-files 'separate))
11628 (insert "\n")
11629 (setq ent-buffer (current-buffer))
11630 (setq arch-file-name
11631 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11632 (concat ent-name " " arch-name) t)
11633 "." (file-name-extension (buffer-file-name))))
11634 (when (and (file-exists-p arch-file-name)
11635 (not (y-or-n-p (concat "File \"" arch-file-name
11636 "\" exists; overwrite? "))))
11637 (error "ERROR: Pasting port as testbench...aborted"))
11638 (find-file arch-file-name)
11639 (erase-buffer)
11640 (set-buffer-modified-p nil)
11641 ;; paste architecture header
11642 (if vhdl-testbench-include-header
11643 (progn (vhdl-template-header
11644 (concat "Testbench architecture for design \""
11645 (nth 0 vhdl-port-list) "\""))
11646 (goto-char (point-max)))
11647 (vhdl-comment-display-line) (insert "\n\n")))
11648 ;; paste architecture body
11649 (vhdl-insert-keyword "ARCHITECTURE ")
11650 (insert arch-name)
11651 (vhdl-insert-keyword " OF ")
11652 (insert ent-name)
11653 (vhdl-insert-keyword " IS")
11654 (insert "\n\n") (indent-to vhdl-basic-offset)
11655 ;; paste component declaration
11656 (unless (vhdl-use-direct-instantiation)
11657 (vhdl-port-paste-component t)
11658 (insert "\n\n") (indent-to vhdl-basic-offset))
11659 ;; paste constants
11660 (when (nth 1 vhdl-port-list)
11661 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11662 (vhdl-port-paste-constants t)
11663 (insert "\n\n") (indent-to vhdl-basic-offset))
11664 ;; paste internal signals
11665 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11666 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11667 (insert "\n")
11668 ;; paste custom declarations
11669 (unless (equal "" vhdl-testbench-declarations)
11670 (insert "\n")
11671 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11672 (setq position (point))
11673 (insert "\n\n")
11674 (vhdl-comment-display-line) (insert "\n")
11675 (when vhdl-testbench-include-configuration
11676 (setq config-name (vhdl-replace-string
11677 vhdl-testbench-configuration-name
11678 (concat ent-name " " arch-name)))
11679 (insert "\n")
11680 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11681 (vhdl-insert-keyword " OF ") (insert ent-name)
11682 (vhdl-insert-keyword " IS\n")
11683 (indent-to vhdl-basic-offset)
11684 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11685 (indent-to vhdl-basic-offset)
11686 (vhdl-insert-keyword "END FOR;\n")
11687 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11688 (vhdl-comment-display-line) (insert "\n"))
11689 (goto-char position)
11690 (vhdl-template-begin-end
11691 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11692 ;; paste instantiation
11693 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11694 (vhdl-port-paste-instance
11695 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11696 (insert "\n")
11697 ;; paste custom statements
11698 (unless (equal "" vhdl-testbench-statements)
11699 (insert "\n")
11700 (vhdl-insert-string-or-file vhdl-testbench-statements))
11701 (insert "\n")
11702 (indent-to vhdl-basic-offset)
11703 (unless (eq vhdl-testbench-create-files 'none)
11704 (setq arch-buffer (current-buffer))
11705 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11706 (set-buffer arch-buffer) (save-buffer))
11707 (message "%s"
11708 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11709 ent-name arch-name)
11710 (and ent-file-name
11711 (format "\n File created: \"%s\"" ent-file-name))
11712 (and arch-file-name
11713 (format "\n File created: \"%s\"" arch-file-name)))))))
11714
11715
11716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11717 ;;; Subprogram interface translation
11718 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11719
11720 (defvar vhdl-subprog-list nil
11721 "Variable to hold last subprogram interface parsed.")
11722 ;; structure: (parenthesised expression means list of such entries)
11723 ;; (subprog-name kind
11724 ;; ((names) object direct type init comment group-comment)
11725 ;; return-type return-comment group-comment)
11726
11727 (defvar vhdl-subprog-flattened nil
11728 "Indicates whether an subprogram interface has been flattened.")
11729
11730 (defun vhdl-subprog-flatten ()
11731 "Flatten interface list so that only one parameter exists per line."
11732 (interactive)
11733 (if (not vhdl-subprog-list)
11734 (error "ERROR: No subprogram interface has been read")
11735 (message "Flattening subprogram interface...")
11736 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11737 new-subprog-list old-subprog new-subprog names)
11738 ;; traverse parameter list and flatten entries
11739 (while old-subprog-list
11740 (setq old-subprog (car old-subprog-list))
11741 (setq names (car old-subprog))
11742 (while names
11743 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11744 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11745 (setq names (cdr names)))
11746 (setq old-subprog-list (cdr old-subprog-list)))
11747 (setq vhdl-subprog-list
11748 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11749 new-subprog-list (nth 3 vhdl-subprog-list)
11750 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11751 vhdl-subprog-flattened t)
11752 (message "Flattening subprogram interface...done"))))
11753
11754 (defun vhdl-subprog-copy ()
11755 "Get interface information from a subprogram specification."
11756 (interactive)
11757 (save-excursion
11758 (let (parse-error pos end-of-list
11759 name kind param-list object names direct type init
11760 comment group-comment
11761 return-type return-comment return-group-comment)
11762 (vhdl-prepare-search-2
11763 (setq
11764 parse-error
11765 (catch 'parse
11766 ;; check if within function declaration
11767 (setq pos (point))
11768 (end-of-line)
11769 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11770 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11771 (goto-char (match-end 0))
11772 (save-excursion (backward-char)
11773 (forward-sexp)
11774 (<= pos (point))))
11775 (throw 'parse "ERROR: Not within a subprogram specification"))
11776 (setq name (match-string-no-properties 5))
11777 (setq kind (if (match-string 2) 'procedure 'function))
11778 (setq end-of-list (not (match-string 7)))
11779 (message "Reading interface of subprogram \"%s\"..." name)
11780 ;; parse parameter list
11781 (setq group-comment (vhdl-parse-group-comment))
11782 (setq end-of-list (or end-of-list
11783 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11784 (while (not end-of-list)
11785 ;; parse object
11786 (setq object
11787 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11788 (match-string-no-properties 1)))
11789 ;; parse names (accept extended identifiers)
11790 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11791 (setq names (list (match-string-no-properties 1)))
11792 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11793 (setq names (append names (list (match-string-no-properties 1)))))
11794 ;; parse direction
11795 (vhdl-parse-string ":[ \t\n]*")
11796 (setq direct
11797 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11798 (match-string-no-properties 1)))
11799 ;; parse type
11800 (vhdl-parse-string "\\([^():;\n]+\\)")
11801 (setq type (match-string-no-properties 1))
11802 (setq comment nil)
11803 (while (looking-at "(")
11804 (setq type
11805 (concat type
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 type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11812 (setq comment (substring type (match-beginning 2)))
11813 (setq type (substring type 0 (match-beginning 1))))
11814 ;; strip off trailing group-comment
11815 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11816 (setq type (substring type 0 (match-end 1)))
11817 ;; parse initialization expression
11818 (setq init nil)
11819 (when (vhdl-parse-string ":=[ \t\n]*" t)
11820 (vhdl-parse-string "\\([^();\n]*\\)")
11821 (setq init (match-string-no-properties 1))
11822 (while (looking-at "(")
11823 (setq init
11824 (concat init
11825 (buffer-substring-no-properties
11826 (point) (progn (forward-sexp) (point)))
11827 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11828 (match-string-no-properties 1))))))
11829 ;; special case: closing parenthesis is on separate line
11830 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11831 (setq comment (substring init (match-beginning 2)))
11832 (setq init (substring init 0 (match-beginning 1)))
11833 (vhdl-forward-syntactic-ws))
11834 (skip-chars-forward " \t")
11835 ;; parse inline comment, special case: as above, no initial.
11836 (unless comment
11837 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11838 (match-string-no-properties 1))))
11839 (vhdl-forward-syntactic-ws)
11840 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11841 ;; parse inline comment
11842 (unless comment
11843 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11844 (match-string-no-properties 1))))
11845 (setq return-group-comment (vhdl-parse-group-comment))
11846 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11847 ;; parse return type
11848 (when (match-string 3)
11849 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11850 (setq return-type (match-string-no-properties 1))
11851 (when (and return-type
11852 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11853 (setq return-comment (substring return-type (match-beginning 2)))
11854 (setq return-type (substring return-type 0 (match-beginning 1))))
11855 ;; strip of trailing group-comment
11856 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11857 (setq return-type (substring return-type 0 (match-end 1)))
11858 ;; parse return comment
11859 (unless return-comment
11860 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11861 (match-string-no-properties 1)))))
11862 ;; parse inline comment
11863 (unless comment
11864 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11865 (match-string-no-properties 1))))
11866 ;; save everything in list
11867 (setq param-list (append param-list
11868 (list (list names object direct type init
11869 comment group-comment))))
11870 ;; parse group comment and spacing
11871 (setq group-comment (vhdl-parse-group-comment)))
11872 (message "Reading interface of subprogram \"%s\"...done" name)
11873 nil)))
11874 ;; finish parsing
11875 (if parse-error
11876 (error parse-error)
11877 (setq vhdl-subprog-list
11878 (list name kind param-list return-type return-comment
11879 return-group-comment)
11880 vhdl-subprog-flattened nil)))))
11881
11882 (defun vhdl-subprog-paste-specification (kind)
11883 "Paste as a subprogram specification."
11884 (indent-according-to-mode)
11885 (let ((margin (current-column))
11886 (param-list (nth 2 vhdl-subprog-list))
11887 list-margin start names param)
11888 ;; paste keyword and name
11889 (vhdl-insert-keyword
11890 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11891 (insert (nth 0 vhdl-subprog-list))
11892 (if (not param-list)
11893 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11894 (setq start (point))
11895 ;; paste parameter list
11896 (insert " (")
11897 (unless vhdl-argument-list-indent
11898 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11899 (setq list-margin (current-column))
11900 (while param-list
11901 (setq param (car param-list))
11902 ;; paste group comment and spacing
11903 (when (memq vhdl-include-group-comments (list kind 'always))
11904 (vhdl-paste-group-comment (nth 6 param) list-margin))
11905 ;; paste object
11906 (when (nth 1 param) (insert (nth 1 param) " "))
11907 ;; paste names
11908 (setq names (nth 0 param))
11909 (while names
11910 (insert (car names))
11911 (setq names (cdr names))
11912 (when names (insert ", ")))
11913 ;; paste direction
11914 (insert " : ")
11915 (when (nth 2 param) (insert (nth 2 param) " "))
11916 ;; paste type
11917 (insert (nth 3 param))
11918 ;; paste initialization
11919 (when (nth 4 param) (insert " := " (nth 4 param)))
11920 ;; terminate line
11921 (if (cdr param-list)
11922 (insert ";")
11923 (insert ")")
11924 (when (null (nth 3 vhdl-subprog-list))
11925 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11926 ;; paste comment
11927 (when (and vhdl-include-port-comments (nth 5 param))
11928 (vhdl-comment-insert-inline (nth 5 param) t))
11929 (setq param-list (cdr param-list))
11930 (when param-list (insert "\n") (indent-to list-margin)))
11931 (when (nth 3 vhdl-subprog-list)
11932 (insert "\n") (indent-to list-margin)
11933 ;; paste group comment and spacing
11934 (when (memq vhdl-include-group-comments (list kind 'always))
11935 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11936 ;; paste return type
11937 (insert "return " (nth 3 vhdl-subprog-list))
11938 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11939 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11940 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11941 ;; align parameter list
11942 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11943 ;; paste body
11944 (when (eq kind 'body)
11945 (insert "\n")
11946 (vhdl-template-begin-end
11947 (unless (vhdl-standard-p '87)
11948 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11949 (nth 0 vhdl-subprog-list) margin))))
11950
11951 (defun vhdl-subprog-paste-declaration ()
11952 "Paste as a subprogram declaration."
11953 (interactive)
11954 (if (not vhdl-subprog-list)
11955 (error "ERROR: No subprogram interface read")
11956 (message "Pasting interface as subprogram declaration \"%s\"..."
11957 (car vhdl-subprog-list))
11958 ;; paste specification
11959 (vhdl-subprog-paste-specification 'decl)
11960 (message "Pasting interface as subprogram declaration \"%s\"...done"
11961 (car vhdl-subprog-list))))
11962
11963 (defun vhdl-subprog-paste-body ()
11964 "Paste as a subprogram body."
11965 (interactive)
11966 (if (not vhdl-subprog-list)
11967 (error "ERROR: No subprogram interface read")
11968 (message "Pasting interface as subprogram body \"%s\"..."
11969 (car vhdl-subprog-list))
11970 ;; paste specification and body
11971 (vhdl-subprog-paste-specification 'body)
11972 (message "Pasting interface as subprogram body \"%s\"...done"
11973 (car vhdl-subprog-list))))
11974
11975 (defun vhdl-subprog-paste-call ()
11976 "Paste as a subprogram call."
11977 (interactive)
11978 (if (not vhdl-subprog-list)
11979 (error "ERROR: No subprogram interface read")
11980 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11981 param-list margin list-margin param start)
11982 ;; flatten local copy of interface list (must be flat for parameter mapping)
11983 (vhdl-subprog-flatten)
11984 (setq param-list (nth 2 vhdl-subprog-list))
11985 (indent-according-to-mode)
11986 (setq margin (current-indentation))
11987 (message "Pasting interface as subprogram call \"%s\"..."
11988 (car vhdl-subprog-list))
11989 ;; paste name
11990 (insert (nth 0 vhdl-subprog-list))
11991 (if (not param-list)
11992 (insert ";")
11993 (setq start (point))
11994 ;; paste parameter list
11995 (insert " (")
11996 (unless vhdl-argument-list-indent
11997 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11998 (setq list-margin (current-column))
11999 (while param-list
12000 (setq param (car param-list))
12001 ;; paste group comment and spacing
12002 (when (eq vhdl-include-group-comments 'always)
12003 (vhdl-paste-group-comment (nth 6 param) list-margin))
12004 ;; paste formal port
12005 (insert (car (nth 0 param)) " => ")
12006 (setq param-list (cdr param-list))
12007 (insert (if param-list "," ");"))
12008 ;; paste comment
12009 (when (and vhdl-include-port-comments (nth 5 param))
12010 (vhdl-comment-insert-inline (nth 5 param)))
12011 (when param-list (insert "\n") (indent-to list-margin)))
12012 ;; align parameter list
12013 (when vhdl-auto-align
12014 (vhdl-align-region-groups start (point) 1)))
12015 (message "Pasting interface as subprogram call \"%s\"...done"
12016 (car vhdl-subprog-list))
12017 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12018
12019
12020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12021 ;;; Miscellaneous
12022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12023
12024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12025 ;; Hippie expand customization
12026
12027 (defvar vhdl-expand-upper-case nil)
12028
12029 (defun vhdl-try-expand-abbrev (old)
12030 "Try expanding abbreviations from `vhdl-abbrev-list'."
12031 (unless old
12032 (he-init-string (he-dabbrev-beg) (point))
12033 (setq he-expand-list
12034 (let ((abbrev-list vhdl-abbrev-list)
12035 (sel-abbrev-list '()))
12036 (while abbrev-list
12037 (when (or (not (stringp (car abbrev-list)))
12038 (string-match
12039 (concat "^" he-search-string) (car abbrev-list)))
12040 (setq sel-abbrev-list
12041 (cons (car abbrev-list) sel-abbrev-list)))
12042 (setq abbrev-list (cdr abbrev-list)))
12043 (nreverse sel-abbrev-list))))
12044 (while (and he-expand-list
12045 (or (not (stringp (car he-expand-list)))
12046 (he-string-member (car he-expand-list) he-tried-table t)))
12047 ; (equal (car he-expand-list) he-search-string)))
12048 (unless (stringp (car he-expand-list))
12049 (setq vhdl-expand-upper-case (car he-expand-list)))
12050 (setq he-expand-list (cdr he-expand-list)))
12051 (if (null he-expand-list)
12052 (progn (when old (he-reset-string))
12053 nil)
12054 (he-substitute-string
12055 (if vhdl-expand-upper-case
12056 (upcase (car he-expand-list))
12057 (car he-expand-list))
12058 t)
12059 (setq he-expand-list (cdr he-expand-list))
12060 t))
12061
12062 (defun vhdl-he-list-beg ()
12063 "Also looks at the word before `(' in order to better match parenthesized
12064 expressions (e.g. for index ranges of types and signals)."
12065 (save-excursion
12066 (condition-case ()
12067 (progn (backward-up-list 1)
12068 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12069 (error ()))
12070 (point)))
12071
12072 ;; override `he-list-beg' from `hippie-exp'
12073 (unless (and (boundp 'viper-mode) viper-mode)
12074 (defalias 'he-list-beg 'vhdl-he-list-beg))
12075
12076 ;; function for expanding abbrevs and dabbrevs
12077 (defun vhdl-expand-abbrev (arg))
12078 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12079 '(try-expand-dabbrev
12080 try-expand-dabbrev-all-buffers
12081 vhdl-try-expand-abbrev)))
12082
12083 ;; function for expanding parenthesis
12084 (defun vhdl-expand-paren (arg))
12085 (fset 'vhdl-expand-paren (make-hippie-expand-function
12086 '(try-expand-list
12087 try-expand-list-all-buffers)))
12088
12089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12090 ;; Case fixing
12091
12092 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12093 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12094 depending on parameter UPPER-CASE."
12095 (let ((case-replace nil)
12096 (last-update 0))
12097 (vhdl-prepare-search-2
12098 (save-excursion
12099 (goto-char end)
12100 (setq end (point-marker))
12101 (goto-char beg)
12102 (while (re-search-forward word-regexp end t)
12103 (or (vhdl-in-literal)
12104 (if upper-case
12105 (upcase-word -1)
12106 (downcase-word -1)))
12107 (when (and count vhdl-progress-interval (not noninteractive)
12108 (< vhdl-progress-interval
12109 (- (nth 1 (current-time)) last-update)))
12110 (message "Fixing case... (%2d%s)"
12111 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12112 "%")
12113 (setq last-update (nth 1 (current-time)))))
12114 (goto-char end)))))
12115
12116 (defun vhdl-fix-case-region (beg end &optional arg)
12117 "Convert all VHDL words in region to lower or upper case, depending on
12118 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12119 (interactive "r\nP")
12120 (vhdl-fix-case-region-1
12121 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12122 (vhdl-fix-case-region-1
12123 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12124 (vhdl-fix-case-region-1
12125 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12126 (vhdl-fix-case-region-1
12127 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12128 (when vhdl-progress-interval (message "Fixing case...done")))
12129
12130 (defun vhdl-fix-case-buffer ()
12131 "Convert all VHDL words in buffer to lower or upper case, depending on
12132 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12133 (interactive)
12134 (vhdl-fix-case-region (point-min) (point-max)))
12135
12136 (defun vhdl-fix-case-word (&optional arg)
12137 "Convert word after cursor to upper case if necessary."
12138 (interactive "p")
12139 (save-excursion
12140 (when arg (backward-word 1))
12141 (vhdl-prepare-search-1
12142 (when (and vhdl-upper-case-keywords
12143 (looking-at vhdl-keywords-regexp))
12144 (upcase-word 1))
12145 (when (and vhdl-upper-case-types
12146 (looking-at vhdl-types-regexp))
12147 (upcase-word 1))
12148 (when (and vhdl-upper-case-attributes
12149 (looking-at vhdl-attributes-regexp))
12150 (upcase-word 1))
12151 (when (and vhdl-upper-case-enum-values
12152 (looking-at vhdl-enum-values-regexp))
12153 (upcase-word 1)))))
12154
12155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12156 ;; Line handling functions
12157
12158 (defun vhdl-current-line ()
12159 "Return the line number of the line containing point."
12160 (save-restriction
12161 (widen)
12162 (save-excursion
12163 (beginning-of-line)
12164 (1+ (count-lines 1 (point))))))
12165
12166 (defun vhdl-line-kill-entire (&optional arg)
12167 "Delete entire line."
12168 (interactive "p")
12169 (beginning-of-line)
12170 (kill-line (or arg 1)))
12171
12172 (defun vhdl-line-kill (&optional arg)
12173 "Kill current line."
12174 (interactive "p")
12175 (vhdl-line-kill-entire arg))
12176
12177 (defun vhdl-line-copy (&optional arg)
12178 "Copy current line."
12179 (interactive "p")
12180 (save-excursion
12181 (beginning-of-line)
12182 (let ((position (point)))
12183 (forward-line (or arg 1))
12184 (copy-region-as-kill position (point)))))
12185
12186 (defun vhdl-line-yank ()
12187 "Yank entire line."
12188 (interactive)
12189 (beginning-of-line)
12190 (yank))
12191
12192 (defun vhdl-line-expand (&optional prefix-arg)
12193 "Hippie-expand current line."
12194 (interactive "P")
12195 (let ((case-fold-search t) (case-replace nil)
12196 (hippie-expand-try-functions-list
12197 '(try-expand-line try-expand-line-all-buffers)))
12198 (hippie-expand prefix-arg)))
12199
12200 (defun vhdl-line-transpose-next (&optional arg)
12201 "Interchange this line with next line."
12202 (interactive "p")
12203 (forward-line 1)
12204 (transpose-lines (or arg 1))
12205 (forward-line -1))
12206
12207 (defun vhdl-line-transpose-previous (&optional arg)
12208 "Interchange this line with previous line."
12209 (interactive "p")
12210 (forward-line 1)
12211 (transpose-lines (- 0 (or arg 0)))
12212 (forward-line -1))
12213
12214 (defun vhdl-line-open ()
12215 "Open a new line and indent."
12216 (interactive)
12217 (end-of-line -0)
12218 (newline-and-indent))
12219
12220 (defun vhdl-delete-indentation ()
12221 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12222 it works within comments too."
12223 (interactive)
12224 (let ((fill-prefix "-- "))
12225 (delete-indentation)))
12226
12227 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12228 ;; Move functions
12229
12230 (defun vhdl-forward-same-indent ()
12231 "Move forward to next line with same indent."
12232 (interactive)
12233 (let ((pos (point))
12234 (indent (current-indentation)))
12235 (beginning-of-line 2)
12236 (while (and (not (eobp))
12237 (or (looking-at "^\\s-*\\(--.*\\)?$")
12238 (> (current-indentation) indent)))
12239 (beginning-of-line 2))
12240 (if (= (current-indentation) indent)
12241 (back-to-indentation)
12242 (message "No following line with same indent found in this block")
12243 (goto-char pos)
12244 nil)))
12245
12246 (defun vhdl-backward-same-indent ()
12247 "Move backward to previous line with same indent."
12248 (interactive)
12249 (let ((pos (point))
12250 (indent (current-indentation)))
12251 (beginning-of-line -0)
12252 (while (and (not (bobp))
12253 (or (looking-at "^\\s-*\\(--.*\\)?$")
12254 (> (current-indentation) indent)))
12255 (beginning-of-line -0))
12256 (if (= (current-indentation) indent)
12257 (back-to-indentation)
12258 (message "No preceding line with same indent found in this block")
12259 (goto-char pos)
12260 nil)))
12261
12262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12263 ;; Statistics
12264
12265 (defun vhdl-statistics-buffer ()
12266 "Get some file statistics."
12267 (interactive)
12268 (let ((no-stats 0)
12269 (no-code-lines 0)
12270 (no-lines (count-lines (point-min) (point-max))))
12271 (save-excursion
12272 ;; count statements
12273 (goto-char (point-min))
12274 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12275 (if (match-string 1)
12276 (goto-char (match-end 1))
12277 (setq no-stats (1+ no-stats))))
12278 ;; count code lines
12279 (goto-char (point-min))
12280 (while (not (eobp))
12281 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12282 (setq no-code-lines (1+ no-code-lines)))
12283 (beginning-of-line 2)))
12284 ;; print results
12285 (message "\n\
12286 File statistics: \"%s\"\n\
12287 ---------------------\n\
12288 # statements : %5d\n\
12289 # code lines : %5d\n\
12290 # total lines : %5d\n\ "
12291 (buffer-file-name) no-stats no-code-lines no-lines)
12292 (unless vhdl-emacs-21 (vhdl-show-messages))))
12293
12294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12295 ;; Help functions
12296
12297 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12298 "Like `re-search-forward', but does not match within literals."
12299 (let (pos)
12300 (save-excursion
12301 (while (and (setq pos (re-search-forward regexp bound noerror count))
12302 (vhdl-in-literal))))
12303 (when pos (goto-char pos))
12304 pos))
12305
12306 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12307 "Like `re-search-backward', but does not match within literals."
12308 (let (pos)
12309 (save-excursion
12310 (while (and (setq pos (re-search-backward regexp bound noerror count))
12311 (vhdl-in-literal))))
12312 (when pos (goto-char pos))
12313 pos))
12314
12315
12316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12317 ;;; Project
12318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12319
12320 (defun vhdl-set-project (name)
12321 "Set current project to NAME."
12322 (interactive
12323 (list (let ((completion-ignore-case t))
12324 (completing-read "Project name: " vhdl-project-alist nil t))))
12325 (cond ((equal name "")
12326 (setq vhdl-project nil)
12327 (message "Current VHDL project: None"))
12328 ((assoc name vhdl-project-alist)
12329 (setq vhdl-project name)
12330 (message "Current VHDL project: \"%s\"" name))
12331 (t
12332 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12333 (vhdl-speedbar-update-current-project))
12334
12335 (defun vhdl-set-default-project ()
12336 "Set current project as default on startup."
12337 (interactive)
12338 (customize-set-variable 'vhdl-project vhdl-project)
12339 (customize-save-customized))
12340
12341 (defun vhdl-toggle-project (name token indent)
12342 "Set current project to NAME or unset if NAME is current project."
12343 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12344
12345 (defun vhdl-export-project (file-name)
12346 "Write project setup for current project."
12347 (interactive
12348 (let ((name (vhdl-resolve-env-variable
12349 (vhdl-replace-string
12350 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12351 (concat (subst-char-in-string
12352 ? ?_ (or (vhdl-project-p)
12353 (error "ERROR: No current project")))
12354 " " (user-login-name))))))
12355 (list (read-file-name
12356 "Write project file: "
12357 (when (file-name-absolute-p name) "") nil nil name))))
12358 (setq file-name (abbreviate-file-name file-name))
12359 (let ((orig-buffer (current-buffer)))
12360 (unless (file-exists-p (file-name-directory file-name))
12361 (make-directory (file-name-directory file-name) t))
12362 (if (not (file-writable-p file-name))
12363 (error "ERROR: File not writable: \"%s\"" file-name)
12364 (set-buffer (find-file-noselect file-name t t))
12365 (erase-buffer)
12366 (insert ";; -*- Emacs-Lisp -*-\n\n"
12367 ";;; " (file-name-nondirectory file-name)
12368 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12369 ";; Project : " vhdl-project "\n"
12370 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12371 (user-login-name) "\n\n\n"
12372 ";; project name\n"
12373 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12374 ";; project setup\n"
12375 "(aput 'vhdl-project-alist vhdl-project\n'")
12376 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12377 (insert ")\n")
12378 (save-buffer)
12379 (kill-buffer (current-buffer))
12380 (set-buffer orig-buffer))))
12381
12382 (defun vhdl-import-project (file-name &optional auto not-make-current)
12383 "Read project setup and set current project."
12384 (interactive
12385 (let ((name (vhdl-resolve-env-variable
12386 (vhdl-replace-string
12387 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12388 (concat "" " " (user-login-name))))))
12389 (list (read-file-name
12390 "Read project file: " (when (file-name-absolute-p name) "") nil t
12391 (file-name-directory name)))))
12392 (when (file-exists-p file-name)
12393 (condition-case ()
12394 (let ((current-project vhdl-project))
12395 (load-file file-name)
12396 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12397 (adelete 'vhdl-project-alist vhdl-project)
12398 (error ""))
12399 (when not-make-current
12400 (setq vhdl-project current-project))
12401 (vhdl-update-mode-menu)
12402 (vhdl-speedbar-refresh)
12403 (unless not-make-current
12404 (message "Current VHDL project: \"%s\"%s"
12405 vhdl-project (if auto " (auto-loaded)" ""))))
12406 (error (vhdl-warning
12407 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12408
12409 (defun vhdl-duplicate-project ()
12410 "Duplicate setup of current project."
12411 (interactive)
12412 (let ((new-name (read-from-minibuffer "New project name: "))
12413 (project-entry (aget vhdl-project-alist vhdl-project t)))
12414 (setq vhdl-project-alist
12415 (append vhdl-project-alist
12416 (list (cons new-name project-entry))))
12417 (vhdl-update-mode-menu)))
12418
12419 (defun vhdl-auto-load-project ()
12420 "Automatically load project setup at startup."
12421 (let ((file-name-list vhdl-project-file-name)
12422 file-list list-length)
12423 (while file-name-list
12424 (setq file-list
12425 (append file-list
12426 (file-expand-wildcards
12427 (vhdl-resolve-env-variable
12428 (vhdl-replace-string
12429 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12430 (concat "\*" " " (user-login-name)))))))
12431 (setq list-length (or list-length (length file-list)))
12432 (setq file-name-list (cdr file-name-list)))
12433 (while file-list
12434 (vhdl-import-project (expand-file-name (car file-list)) t
12435 (not (> list-length 0)))
12436 (setq list-length (1- list-length))
12437 (setq file-list (cdr file-list)))))
12438
12439 ;; automatically load project setup when idle after startup
12440 (when (memq 'startup vhdl-project-auto-load)
12441 (if noninteractive
12442 (vhdl-auto-load-project)
12443 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12444
12445
12446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12447 ;;; Hideshow
12448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12449 ;; (using `hideshow.el')
12450
12451 (defconst vhdl-hs-start-regexp
12452 (concat
12453 "\\(^\\)\\s-*\\("
12454 ;; generic/port clause
12455 "\\(generic\\|port\\)[ \t\n]*(\\|"
12456 ;; component
12457 "component\\>\\|"
12458 ;; component instantiation
12459 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12460 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12461 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12462 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12463 ;; subprogram
12464 "\\(function\\|procedure\\)\\>\\|"
12465 ;; process, block
12466 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12467 ;; configuration declaration
12468 "configuration\\>"
12469 "\\)")
12470 "Regexp to match start of construct to hide.")
12471
12472 (defun vhdl-hs-forward-sexp-func (count)
12473 "Find end of construct to hide (for hideshow). Only searches forward."
12474 (let ((pos (point)))
12475 (vhdl-prepare-search-2
12476 (beginning-of-line)
12477 (cond
12478 ;; generic/port clause
12479 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12480 (goto-char (match-end 0))
12481 (backward-char)
12482 (forward-sexp))
12483 ;; component declaration
12484 ((looking-at "^\\s-*component\\>")
12485 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12486 ;; component instantiation
12487 ((looking-at
12488 (concat
12489 "^\\s-*\\w+\\s-*:[ \t\n]*"
12490 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12491 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12492 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12493 (goto-char (match-end 0))
12494 (backward-char)
12495 (forward-sexp)
12496 (setq pos (point))
12497 (vhdl-forward-syntactic-ws)
12498 (when (looking-at "port\\s-+map[ \t\n]*(")
12499 (goto-char (match-end 0))
12500 (backward-char)
12501 (forward-sexp)
12502 (setq pos (point)))
12503 (goto-char pos))
12504 ;; subprogram declaration/body
12505 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12506 (goto-char (match-end 0))
12507 (vhdl-forward-syntactic-ws)
12508 (when (looking-at "(")
12509 (forward-sexp))
12510 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12511 (vhdl-in-literal)))
12512 ;; subprogram body
12513 (when (match-string 2)
12514 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12515 (backward-word 1)
12516 (vhdl-forward-sexp)))
12517 ;; block (recursive)
12518 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12519 (goto-char (match-end 0))
12520 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12521 (match-beginning 2))
12522 (vhdl-hs-forward-sexp-func count)))
12523 ;; process
12524 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12525 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12526 ;; configuration declaration
12527 ((looking-at "^\\s-*configuration\\>")
12528 (forward-word 4)
12529 (vhdl-forward-sexp))
12530 (t (goto-char pos))))))
12531
12532 (defun vhdl-hideshow-init ()
12533 "Initialize `hideshow'."
12534 (when vhdl-hideshow-menu
12535 (vhdl-hs-minor-mode 1)))
12536
12537 (defun vhdl-hs-minor-mode (&optional arg)
12538 "Toggle hideshow minor mode and update menu bar."
12539 (interactive "P")
12540 (require 'hideshow)
12541 ;; check for hideshow version 5.x
12542 (if (not (boundp 'hs-block-start-mdata-select))
12543 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12544 ;; initialize hideshow
12545 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12546 (setq hs-special-modes-alist
12547 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12548 'vhdl-hs-forward-sexp-func nil)
12549 hs-special-modes-alist)))
12550 (make-local-variable 'hs-minor-mode-hook)
12551 (if vhdl-hide-all-init
12552 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12553 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12554 (hs-minor-mode arg)
12555 (vhdl-mode-line-update))) ; hack to update menu bar
12556
12557
12558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12559 ;;; Font locking
12560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12561 ;; (using `font-lock.el')
12562
12563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12564 ;; Help functions
12565
12566 (defun vhdl-within-translate-off ()
12567 "Return point if within translate-off region, else nil."
12568 (and (save-excursion
12569 (re-search-backward
12570 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12571 (equal "off" (match-string 1))
12572 (point)))
12573
12574 (defun vhdl-start-translate-off (limit)
12575 "Return point before translate-off pragma if before LIMIT, else nil."
12576 (when (re-search-forward
12577 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12578 (match-beginning 0)))
12579
12580 (defun vhdl-end-translate-off (limit)
12581 "Return point after translate-on pragma if before LIMIT, else nil."
12582 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12583
12584 (defun vhdl-match-translate-off (limit)
12585 "Match a translate-off block, setting match-data and returning t, else nil."
12586 (when (< (point) limit)
12587 (let ((start (or (vhdl-within-translate-off)
12588 (vhdl-start-translate-off limit)))
12589 (case-fold-search t))
12590 (when start
12591 (let ((end (or (vhdl-end-translate-off limit) limit)))
12592 (set-match-data (list start end))
12593 (goto-char end))))))
12594
12595 (defun vhdl-font-lock-match-item (limit)
12596 "Match, and move over, any declaration item after point. Adapted from
12597 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12598 (condition-case nil
12599 (save-restriction
12600 (narrow-to-region (point-min) limit)
12601 ;; match item
12602 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12603 (save-match-data
12604 (goto-char (match-end 1))
12605 ;; move to next item
12606 (if (looking-at "\\(\\s-*,\\)")
12607 (goto-char (match-end 1))
12608 (end-of-line) t))))
12609 (error t)))
12610
12611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12612 ;; Syntax definitions
12613
12614 (defconst vhdl-font-lock-syntactic-keywords
12615 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12616 "Mark single quotes as having string quote syntax in 'c' instances.")
12617
12618 (defvar vhdl-font-lock-keywords nil
12619 "Regular expressions to highlight in VHDL Mode.")
12620
12621 (defvar vhdl-font-lock-keywords-0
12622 ;; set in `vhdl-font-lock-init' because dependent on user options
12623 "For consideration as a value of `vhdl-font-lock-keywords'.
12624 This does highlighting of template prompts and directives (pragmas).")
12625
12626 (defvar vhdl-font-lock-keywords-1 nil
12627 ;; set in `vhdl-font-lock-init' because dependent on user options
12628 "For consideration as a value of `vhdl-font-lock-keywords'.
12629 This does highlighting of keywords and standard identifiers.")
12630
12631 (defconst vhdl-font-lock-keywords-2
12632 (list
12633 ;; highlight names of units, subprograms, and components when declared
12634 (list
12635 (concat
12636 "^\\s-*\\("
12637 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12638 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12639 "\\)\\s-+\\(\\w+\\)")
12640 5 'font-lock-function-name-face)
12641
12642 ;; highlight entity names of architectures and configurations
12643 (list
12644 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12645 2 'font-lock-function-name-face)
12646
12647 ;; highlight labels of common constructs
12648 (list
12649 (concat
12650 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12651 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12652 "postponed\\|process\\|"
12653 (when (vhdl-standard-p 'ams) "procedural\\|")
12654 "with\\|while"
12655 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12656 1 'font-lock-function-name-face)
12657
12658 ;; highlight label and component name of component instantiations
12659 (list
12660 (concat
12661 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12662 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12663 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12664
12665 ;; highlight label and instantiated unit of component instantiations
12666 (list
12667 (concat
12668 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12669 "\\(component\\|configuration\\|entity\\)\\s-+"
12670 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12671 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12672 '(5 font-lock-function-name-face nil t)
12673 '(7 font-lock-function-name-face nil t))
12674
12675 ;; highlight names and labels at end of constructs
12676 (list
12677 (concat
12678 "^\\s-*end\\s-+\\(\\("
12679 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12680 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12681 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12682 (when (vhdl-standard-p 'ams) "procedural\\|")
12683 "units"
12684 "\\)\\s-+\\)?\\(\\w*\\)")
12685 5 'font-lock-function-name-face)
12686
12687 ;; highlight labels in exit and next statements
12688 (list
12689 (concat
12690 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12691 3 'font-lock-function-name-face)
12692
12693 ;; highlight entity name in attribute specifications
12694 (list
12695 (concat
12696 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12697 1 'font-lock-function-name-face)
12698
12699 ;; highlight labels in block and component specifications
12700 (list
12701 (concat
12702 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12703 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12704 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12705
12706 ;; highlight names in library clauses
12707 (list "^\\s-*library\\>"
12708 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12709
12710 ;; highlight names in use clauses
12711 (list
12712 (concat
12713 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12714 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12715 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12716 '(7 font-lock-function-name-face nil t))
12717
12718 ;; highlight attribute name in attribute declarations/specifications
12719 (list
12720 (concat
12721 "^\\s-*attribute\\s-+\\(\\w+\\)")
12722 1 'vhdl-font-lock-attribute-face)
12723
12724 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12725 (list
12726 (concat
12727 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12728 3 'font-lock-type-face)
12729
12730 ;; highlight signal/variable/constant declaration names
12731 (list "\\(:[^=]\\)"
12732 '(vhdl-font-lock-match-item
12733 (progn (goto-char (match-beginning 1))
12734 (skip-syntax-backward " ")
12735 (skip-syntax-backward "w_")
12736 (skip-syntax-backward " ")
12737 (while (= (preceding-char) ?,)
12738 (backward-char 1)
12739 (skip-syntax-backward " ")
12740 (skip-syntax-backward "w_")
12741 (skip-syntax-backward " ")))
12742 ; (skip-chars-backward "^-(\n\";")
12743 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12744
12745 ;; highlight formal parameters in component instantiations and subprogram
12746 ;; calls
12747 (list "\\(=>\\)"
12748 '(vhdl-font-lock-match-item
12749 (progn (goto-char (match-beginning 1))
12750 (skip-syntax-backward " ")
12751 (while (= (preceding-char) ?\)) (backward-sexp))
12752 (skip-syntax-backward "w_")
12753 (skip-syntax-backward " ")
12754 (when (memq (preceding-char) '(?n ?N ?|))
12755 (goto-char (point-max))))
12756 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12757
12758 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12759 ;; variables
12760 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12761 '(vhdl-font-lock-match-item
12762 (progn (goto-char (match-end 1)) (match-beginning 2))
12763 nil (1 font-lock-variable-name-face)))
12764 )
12765 "For consideration as a value of `vhdl-font-lock-keywords'.
12766 This does context sensitive highlighting of names and labels.")
12767
12768 (defvar vhdl-font-lock-keywords-3 nil
12769 ;; set in `vhdl-font-lock-init' because dependent on user options
12770 "For consideration as a value of `vhdl-font-lock-keywords'.
12771 This does highlighting of words with special syntax.")
12772
12773 (defvar vhdl-font-lock-keywords-4 nil
12774 ;; set in `vhdl-font-lock-init' because dependent on user options
12775 "For consideration as a value of `vhdl-font-lock-keywords'.
12776 This does highlighting of additional reserved words.")
12777
12778 (defconst vhdl-font-lock-keywords-5
12779 ;; background highlight translate-off regions
12780 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12781 "For consideration as a value of `vhdl-font-lock-keywords'.
12782 This does background highlighting of translate-off regions.")
12783
12784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12785 ;; Font and color definitions
12786
12787 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12788 "Face name to use for prompts.")
12789
12790 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12791 "Face name to use for standardized attributes.")
12792
12793 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12794 "Face name to use for standardized enumeration values.")
12795
12796 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12797 "Face name to use for standardized functions and packages.")
12798
12799 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12800 "Face name to use for directives.")
12801
12802 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12803 "Face name to use for additional reserved words.")
12804
12805 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12806 "Face name to use for translate-off regions.")
12807
12808 ;; face names to use for words with special syntax.
12809 (let ((syntax-alist vhdl-special-syntax-alist)
12810 name)
12811 (while syntax-alist
12812 (setq name (vhdl-function-name
12813 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12814 (eval `(defvar ,name ',name
12815 ,(concat "Face name to use for "
12816 (nth 0 (car syntax-alist)) ".")))
12817 (setq syntax-alist (cdr syntax-alist))))
12818
12819 (defgroup vhdl-highlight-faces nil
12820 "Faces for highlighting."
12821 :group 'vhdl-highlight)
12822
12823 ;; add faces used from `font-lock'
12824 (custom-add-to-group
12825 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12826 (custom-add-to-group
12827 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12828 (custom-add-to-group
12829 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12830 (custom-add-to-group
12831 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12832 (custom-add-to-group
12833 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12834 (custom-add-to-group
12835 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12836
12837 (defface vhdl-font-lock-prompt-face
12838 '((((min-colors 88) (class color) (background light))
12839 (:foreground "Red1" :bold t))
12840 (((class color) (background light)) (:foreground "Red" :bold t))
12841 (((class color) (background dark)) (:foreground "Pink" :bold t))
12842 (t (:inverse-video t)))
12843 "Font lock mode face used to highlight prompts."
12844 :group 'vhdl-highlight-faces)
12845
12846 (defface vhdl-font-lock-attribute-face
12847 '((((class color) (background light)) (:foreground "Orchid"))
12848 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12849 (t (:italic t :bold t)))
12850 "Font lock mode face used to highlight standardized attributes."
12851 :group 'vhdl-highlight-faces)
12852
12853 (defface vhdl-font-lock-enumvalue-face
12854 '((((class color) (background light)) (:foreground "SaddleBrown"))
12855 (((class color) (background dark)) (:foreground "BurlyWood"))
12856 (t (:italic t :bold t)))
12857 "Font lock mode face used to highlight standardized enumeration values."
12858 :group 'vhdl-highlight-faces)
12859
12860 (defface vhdl-font-lock-function-face
12861 '((((class color) (background light)) (:foreground "Cyan4"))
12862 (((class color) (background dark)) (:foreground "Orchid1"))
12863 (t (:italic t :bold t)))
12864 "Font lock mode face used to highlight standardized functions and packages."
12865 :group 'vhdl-highlight-faces)
12866
12867 (defface vhdl-font-lock-directive-face
12868 '((((class color) (background light)) (:foreground "CadetBlue"))
12869 (((class color) (background dark)) (:foreground "Aquamarine"))
12870 (t (:italic t :bold t)))
12871 "Font lock mode face used to highlight directives."
12872 :group 'vhdl-highlight-faces)
12873
12874 (defface vhdl-font-lock-reserved-words-face
12875 '((((class color) (background light)) (:foreground "Orange" :bold t))
12876 (((min-colors 88) (class color) (background dark))
12877 (:foreground "Yellow1" :bold t))
12878 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12879 (t ()))
12880 "Font lock mode face used to highlight additional reserved words."
12881 :group 'vhdl-highlight-faces)
12882
12883 (defface vhdl-font-lock-translate-off-face
12884 '((((class color) (background light)) (:background "LightGray"))
12885 (((class color) (background dark)) (:background "DimGray"))
12886 (t ()))
12887 "Font lock mode face used to background highlight translate-off regions."
12888 :group 'vhdl-highlight-faces)
12889
12890 ;; font lock mode faces used to highlight words with special syntax.
12891 (let ((syntax-alist vhdl-special-syntax-alist))
12892 (while syntax-alist
12893 (eval `(defface ,(vhdl-function-name
12894 "vhdl-font-lock" (caar syntax-alist) "face")
12895 '((((class color) (background light))
12896 (:foreground ,(nth 2 (car syntax-alist))))
12897 (((class color) (background dark))
12898 (:foreground ,(nth 3 (car syntax-alist))))
12899 (t ()))
12900 ,(concat "Font lock mode face used to highlight "
12901 (nth 0 (car syntax-alist)) ".")
12902 :group 'vhdl-highlight-faces))
12903 (setq syntax-alist (cdr syntax-alist))))
12904
12905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12906 ;; Font lock initialization
12907
12908 (defun vhdl-font-lock-init ()
12909 "Initialize fontification."
12910 ;; highlight template prompts and directives
12911 (setq vhdl-font-lock-keywords-0
12912 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12913 vhdl-template-prompt-syntax ">\\)")
12914 2 'vhdl-font-lock-prompt-face t)
12915 (list (concat "--\\s-*"
12916 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12917 2 'vhdl-font-lock-directive-face t)
12918 ;; highlight c-preprocessor directives
12919 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12920 '(1 font-lock-builtin-face)
12921 '(3 font-lock-variable-name-face nil t))))
12922 ;; highlight keywords and standardized types, attributes, enumeration
12923 ;; values, and subprograms
12924 (setq vhdl-font-lock-keywords-1
12925 (list
12926 (list (concat "'" vhdl-attributes-regexp)
12927 1 'vhdl-font-lock-attribute-face)
12928 (list vhdl-types-regexp 1 'font-lock-type-face)
12929 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12930 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12931 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12932 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12933 ;; highlight words with special syntax.
12934 (setq vhdl-font-lock-keywords-3
12935 (let ((syntax-alist vhdl-special-syntax-alist)
12936 keywords)
12937 (while syntax-alist
12938 (setq keywords
12939 (cons
12940 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12941 (vhdl-function-name
12942 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12943 keywords))
12944 (setq syntax-alist (cdr syntax-alist)))
12945 keywords))
12946 ;; highlight additional reserved words
12947 (setq vhdl-font-lock-keywords-4
12948 (list (list vhdl-reserved-words-regexp 1
12949 'vhdl-font-lock-reserved-words-face)))
12950 ;; highlight everything together
12951 (setq vhdl-font-lock-keywords
12952 (append
12953 vhdl-font-lock-keywords-0
12954 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12955 (when (or vhdl-highlight-forbidden-words
12956 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12957 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12958 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12959 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12960
12961 ;; initialize fontification for VHDL Mode
12962 (vhdl-font-lock-init)
12963
12964 (defun vhdl-fontify-buffer ()
12965 "Re-initialize fontification and fontify buffer."
12966 (interactive)
12967 (setq font-lock-defaults
12968 (list
12969 'vhdl-font-lock-keywords nil
12970 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12971 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12972 (when (fboundp 'font-lock-unset-defaults)
12973 (font-lock-unset-defaults)) ; not implemented in XEmacs
12974 (font-lock-set-defaults)
12975 (font-lock-mode nil)
12976 (font-lock-mode t))
12977
12978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12979 ;; Initialization for postscript printing
12980
12981 (defun vhdl-ps-print-settings ()
12982 "Initialize custom face and page settings for postscript printing."
12983 ;; define custom face settings
12984 (unless (or (not vhdl-print-customize-faces)
12985 ps-print-color-p)
12986 (set (make-local-variable 'ps-bold-faces)
12987 '(font-lock-keyword-face
12988 font-lock-type-face
12989 vhdl-font-lock-attribute-face
12990 vhdl-font-lock-enumvalue-face
12991 vhdl-font-lock-directive-face))
12992 (set (make-local-variable 'ps-italic-faces)
12993 '(font-lock-comment-face
12994 font-lock-function-name-face
12995 font-lock-type-face
12996 vhdl-font-lock-attribute-face
12997 vhdl-font-lock-enumvalue-face
12998 vhdl-font-lock-directive-face))
12999 (set (make-local-variable 'ps-underlined-faces)
13000 '(font-lock-string-face))
13001 (setq ps-always-build-face-reference t))
13002 ;; define page settings, so that a line containing 79 characters (default)
13003 ;; fits into one column
13004 (when vhdl-print-two-column
13005 (set (make-local-variable 'ps-landscape-mode) t)
13006 (set (make-local-variable 'ps-number-of-columns) 2)
13007 (set (make-local-variable 'ps-font-size) 7.0)
13008 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13009 (set (make-local-variable 'ps-header-font-size) 9.0)
13010 (set (make-local-variable 'ps-header-offset) 12.0)
13011 (when (eq ps-paper-type 'letter)
13012 (set (make-local-variable 'ps-inter-column) 40.0)
13013 (set (make-local-variable 'ps-left-margin) 40.0)
13014 (set (make-local-variable 'ps-right-margin) 40.0))))
13015
13016 (defun vhdl-ps-print-init ()
13017 "Initialize postscript printing."
13018 (if (featurep 'xemacs)
13019 (when (boundp 'ps-print-color-p)
13020 (vhdl-ps-print-settings))
13021 (make-local-variable 'ps-print-hook)
13022 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13023
13024
13025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13026 ;;; Hierarchy browser (using `speedbar.el')
13027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13028 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13029 ;; directory by using the speedbar.
13030
13031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13032 ;; Variables
13033
13034 (defvar vhdl-entity-alist nil
13035 "Cache with entities and corresponding architectures for each
13036 project/directory.")
13037 ;; structure: (parenthesised expression means list of such entries)
13038 ;; (cache-key
13039 ;; (ent-key ent-name ent-file ent-line
13040 ;; (arch-key arch-name arch-file arch-line
13041 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13042 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13043 ;; (lib-name pack-key))
13044 ;; mra-key (lib-name pack-key))
13045
13046 (defvar vhdl-config-alist nil
13047 "Cache with configurations for each project/directory.")
13048 ;; structure: (parenthesised expression means list of such entries)
13049 ;; (cache-key
13050 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13051 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13052 ;; inst-conf-key inst-lib-key)
13053 ;; (lib-name pack-key)))
13054
13055 (defvar vhdl-package-alist nil
13056 "Cache with packages for each project/directory.")
13057 ;; structure: (parenthesised expression means list of such entries)
13058 ;; (cache-key
13059 ;; (pack-key pack-name pack-file pack-line
13060 ;; (comp-key comp-name comp-file comp-line)
13061 ;; (func-key func-name func-file func-line)
13062 ;; (lib-name pack-key)
13063 ;; pack-body-file pack-body-line
13064 ;; (func-key func-name func-body-file func-body-line)
13065 ;; (lib-name pack-key)))
13066
13067 (defvar vhdl-ent-inst-alist nil
13068 "Cache with instantiated entities for each project/directory.")
13069 ;; structure: (parenthesised expression means list of such entries)
13070 ;; (cache-key (inst-ent-key))
13071
13072 (defvar vhdl-file-alist nil
13073 "Cache with design units in each file for each project/directory.")
13074 ;; structure: (parenthesised expression means list of such entries)
13075 ;; (cache-key
13076 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13077 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13078
13079 (defvar vhdl-directory-alist nil
13080 "Cache with source directories for each project.")
13081 ;; structure: (parenthesised expression means list of such entries)
13082 ;; (cache-key (directory))
13083
13084 (defvar vhdl-speedbar-shown-unit-alist nil
13085 "Alist of design units simultaneously open in the current speedbar for each
13086 directory and project.")
13087
13088 (defvar vhdl-speedbar-shown-project-list nil
13089 "List of projects simultaneously open in the current speedbar.")
13090
13091 (defvar vhdl-updated-project-list nil
13092 "List of projects and directories with updated files.")
13093
13094 (defvar vhdl-modified-file-list nil
13095 "List of modified files to be rescanned for hierarchy updating.")
13096
13097 (defvar vhdl-speedbar-hierarchy-depth 0
13098 "Depth of instantiation hierarchy to display.")
13099
13100 (defvar vhdl-speedbar-show-projects nil
13101 "Non-nil means project hierarchy is displayed in speedbar, directory
13102 hierarchy otherwise.")
13103
13104 (defun vhdl-get-end-of-unit ()
13105 "Return position of end of current unit."
13106 (let ((pos (point)))
13107 (save-excursion
13108 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13109 (save-excursion
13110 (goto-char (match-beginning 0))
13111 (vhdl-backward-syntactic-ws)
13112 (and (/= (preceding-char) ?\;) (not (bobp))))))
13113 (re-search-backward "^[ \t]*end\\>" pos 1)
13114 (point))))
13115
13116 (defun vhdl-match-string-downcase (num &optional string)
13117 "Like `match-string-no-properties' with down-casing."
13118 (let ((match (match-string-no-properties num string)))
13119 (and match (downcase match))))
13120
13121
13122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13123 ;; Scan functions
13124
13125 (defun vhdl-scan-context-clause ()
13126 "Scan the context clause that preceeds a design unit."
13127 (let (lib-alist)
13128 (save-excursion
13129 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13130 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13131 (equal "USE" (upcase (match-string 1))))
13132 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13133 (setq lib-alist (cons (cons (match-string-no-properties 1)
13134 (vhdl-match-string-downcase 2))
13135 lib-alist))))))
13136 lib-alist))
13137
13138 (defun vhdl-scan-directory-contents (name &optional project update num-string
13139 non-final)
13140 "Scan contents of VHDL files in directory or file pattern NAME."
13141 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13142 ; (unless (file-directory-p (match-string 1 name))
13143 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13144 (let* ((dir-name (match-string 1 name))
13145 (file-pattern (match-string 2 name))
13146 (is-directory (= 0 (length file-pattern)))
13147 (file-list
13148 (if update
13149 (list name)
13150 (if is-directory
13151 (vhdl-get-source-files t dir-name)
13152 (vhdl-directory-files
13153 dir-name t (wildcard-to-regexp file-pattern)))))
13154 (key (or project dir-name))
13155 (file-exclude-regexp
13156 (or (nth 3 (aget vhdl-project-alist project)) ""))
13157 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13158 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13159 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13160 ent-alist conf-alist pack-alist ent-inst-list file-alist
13161 tmp-list tmp-entry no-files files-exist big-files)
13162 (when (or project update)
13163 (setq ent-alist (aget vhdl-entity-alist key t)
13164 conf-alist (aget vhdl-config-alist key t)
13165 pack-alist (aget vhdl-package-alist key t)
13166 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13167 file-alist (aget vhdl-file-alist key t)))
13168 (when (and (not is-directory) (null file-list))
13169 (message "No such file: \"%s\"" name))
13170 (setq files-exist file-list)
13171 (when file-list
13172 (setq no-files (length file-list))
13173 (message "Scanning %s %s\"%s\"..."
13174 (if is-directory "directory" "files") (or num-string "") name)
13175 ;; exclude files
13176 (unless (equal file-exclude-regexp "")
13177 (let ((case-fold-search nil)
13178 file-tmp-list)
13179 (while file-list
13180 (unless (string-match file-exclude-regexp (car file-list))
13181 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13182 (setq file-list (cdr file-list)))
13183 (setq file-list (nreverse file-tmp-list))))
13184 ;; do for all files
13185 (while file-list
13186 (unless noninteractive
13187 (message "Scanning %s %s\"%s\"... (%2d%s)"
13188 (if is-directory "directory" "files")
13189 (or num-string "") name
13190 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13191 (let ((file-name (abbreviate-file-name (car file-list)))
13192 ent-list arch-list arch-ent-list conf-list
13193 pack-list pack-body-list inst-list inst-ent-list)
13194 ;; scan file
13195 (vhdl-visit-file
13196 file-name nil
13197 (vhdl-prepare-search-2
13198 (save-excursion
13199 ;; scan for design units
13200 (if (and limit-design-file-size
13201 (< limit-design-file-size (buffer-size)))
13202 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13203 (setq big-files t))
13204 ;; scan for entities
13205 (goto-char (point-min))
13206 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13207 (let* ((ent-name (match-string-no-properties 1))
13208 (ent-key (downcase ent-name))
13209 (ent-entry (aget ent-alist ent-key t))
13210 (lib-alist (vhdl-scan-context-clause)))
13211 (if (nth 1 ent-entry)
13212 (vhdl-warning-when-idle
13213 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13214 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13215 file-name (vhdl-current-line))
13216 (setq ent-list (cons ent-key ent-list))
13217 (aput 'ent-alist ent-key
13218 (list ent-name file-name (vhdl-current-line)
13219 (nth 3 ent-entry) (nth 4 ent-entry)
13220 lib-alist)))))
13221 ;; scan for architectures
13222 (goto-char (point-min))
13223 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13224 (let* ((arch-name (match-string-no-properties 1))
13225 (arch-key (downcase arch-name))
13226 (ent-name (match-string-no-properties 2))
13227 (ent-key (downcase ent-name))
13228 (ent-entry (aget ent-alist ent-key t))
13229 (arch-alist (nth 3 ent-entry))
13230 (arch-entry (aget arch-alist arch-key t))
13231 (lib-arch-alist (vhdl-scan-context-clause)))
13232 (if arch-entry
13233 (vhdl-warning-when-idle
13234 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13235 arch-name ent-name (nth 1 arch-entry)
13236 (nth 2 arch-entry) file-name (vhdl-current-line))
13237 (setq arch-list (cons arch-key arch-list)
13238 arch-ent-list (cons ent-key arch-ent-list))
13239 (aput 'arch-alist arch-key
13240 (list arch-name file-name (vhdl-current-line) nil
13241 lib-arch-alist))
13242 (aput 'ent-alist ent-key
13243 (list (or (nth 0 ent-entry) ent-name)
13244 (nth 1 ent-entry) (nth 2 ent-entry)
13245 (vhdl-sort-alist arch-alist)
13246 arch-key (nth 5 ent-entry))))))
13247 ;; scan for configurations
13248 (goto-char (point-min))
13249 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13250 (let* ((conf-name (match-string-no-properties 1))
13251 (conf-key (downcase conf-name))
13252 (conf-entry (aget conf-alist conf-key t))
13253 (ent-name (match-string-no-properties 2))
13254 (ent-key (downcase ent-name))
13255 (lib-alist (vhdl-scan-context-clause))
13256 (conf-line (vhdl-current-line))
13257 (end-of-unit (vhdl-get-end-of-unit))
13258 arch-key comp-conf-list inst-key-list
13259 inst-comp-key inst-ent-key inst-arch-key
13260 inst-conf-key inst-lib-key)
13261 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13262 (setq arch-key (vhdl-match-string-downcase 1)))
13263 (if conf-entry
13264 (vhdl-warning-when-idle
13265 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13266 conf-name ent-name (nth 1 conf-entry)
13267 (nth 2 conf-entry) file-name conf-line)
13268 (setq conf-list (cons conf-key conf-list))
13269 ;; scan for subconfigurations and subentities
13270 (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)
13271 (setq inst-comp-key (vhdl-match-string-downcase 3)
13272 inst-key-list (split-string
13273 (vhdl-match-string-downcase 1)
13274 "[ \t\n]*,[ \t\n]*"))
13275 (vhdl-forward-syntactic-ws)
13276 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13277 (setq
13278 inst-lib-key (vhdl-match-string-downcase 3)
13279 inst-ent-key (and (match-string 2)
13280 (vhdl-match-string-downcase 4))
13281 inst-arch-key (and (match-string 2)
13282 (vhdl-match-string-downcase 6))
13283 inst-conf-key (and (not (match-string 2))
13284 (vhdl-match-string-downcase 4)))
13285 (while inst-key-list
13286 (setq comp-conf-list
13287 (cons (list (car inst-key-list)
13288 inst-comp-key inst-ent-key
13289 inst-arch-key inst-conf-key
13290 inst-lib-key)
13291 comp-conf-list))
13292 (setq inst-key-list (cdr inst-key-list)))))
13293 (aput 'conf-alist conf-key
13294 (list conf-name file-name conf-line ent-key
13295 arch-key comp-conf-list lib-alist)))))
13296 ;; scan for packages
13297 (goto-char (point-min))
13298 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13299 (let* ((pack-name (match-string-no-properties 2))
13300 (pack-key (downcase pack-name))
13301 (is-body (match-string-no-properties 1))
13302 (pack-entry (aget pack-alist pack-key t))
13303 (pack-line (vhdl-current-line))
13304 (end-of-unit (vhdl-get-end-of-unit))
13305 comp-name func-name comp-alist func-alist lib-alist)
13306 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13307 (vhdl-warning-when-idle
13308 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13309 (if is-body " body" "") pack-name
13310 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13311 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13312 file-name (vhdl-current-line))
13313 ;; scan for context clauses
13314 (setq lib-alist (vhdl-scan-context-clause))
13315 ;; scan for component and subprogram declarations/bodies
13316 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13317 (if (equal (upcase (match-string 1)) "COMPONENT")
13318 (setq comp-name (match-string-no-properties 2)
13319 comp-alist
13320 (cons (list (downcase comp-name) comp-name
13321 file-name (vhdl-current-line))
13322 comp-alist))
13323 (setq func-name (match-string-no-properties 2)
13324 func-alist
13325 (cons (list (downcase func-name) func-name
13326 file-name (vhdl-current-line))
13327 func-alist))))
13328 (setq func-alist (nreverse func-alist))
13329 (setq comp-alist (nreverse comp-alist))
13330 (if is-body
13331 (setq pack-body-list (cons pack-key pack-body-list))
13332 (setq pack-list (cons pack-key pack-list)))
13333 (aput
13334 'pack-alist pack-key
13335 (if is-body
13336 (list (or (nth 0 pack-entry) pack-name)
13337 (nth 1 pack-entry) (nth 2 pack-entry)
13338 (nth 3 pack-entry) (nth 4 pack-entry)
13339 (nth 5 pack-entry)
13340 file-name pack-line func-alist lib-alist)
13341 (list pack-name file-name pack-line
13342 comp-alist func-alist lib-alist
13343 (nth 6 pack-entry) (nth 7 pack-entry)
13344 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13345 ;; scan for hierarchy
13346 (if (and limit-hier-file-size
13347 (< limit-hier-file-size (buffer-size)))
13348 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13349 (setq big-files t))
13350 ;; scan for architectures
13351 (goto-char (point-min))
13352 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13353 (let* ((ent-name (match-string-no-properties 2))
13354 (ent-key (downcase ent-name))
13355 (arch-name (match-string-no-properties 1))
13356 (arch-key (downcase arch-name))
13357 (ent-entry (aget ent-alist ent-key t))
13358 (arch-alist (nth 3 ent-entry))
13359 (arch-entry (aget arch-alist arch-key t))
13360 (beg-of-unit (point))
13361 (end-of-unit (vhdl-get-end-of-unit))
13362 (inst-no 0)
13363 inst-alist inst-path)
13364 ;; scan for contained instantiations
13365 (while (and (re-search-forward
13366 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13367 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13368 "component[ \t\n]+\\(\\w+\\)\\|"
13369 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13370 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13371 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13372 (or (not limit-hier-inst-no)
13373 (<= (setq inst-no (1+ inst-no))
13374 limit-hier-inst-no)))
13375 (cond
13376 ;; block/generate beginning found
13377 ((match-string 14)
13378 (setq inst-path
13379 (cons (match-string-no-properties 1) inst-path)))
13380 ;; block/generate end found
13381 ((match-string 16)
13382 (setq inst-path (cdr inst-path)))
13383 ;; instantiation found
13384 (t
13385 (let* ((inst-name (match-string-no-properties 1))
13386 (inst-key (downcase inst-name))
13387 (inst-comp-name
13388 (or (match-string-no-properties 3)
13389 (match-string-no-properties 6)))
13390 (inst-ent-key
13391 (or (and (match-string 8)
13392 (vhdl-match-string-downcase 11))
13393 (and inst-comp-name
13394 (downcase inst-comp-name))))
13395 (inst-arch-key (vhdl-match-string-downcase 13))
13396 (inst-conf-key
13397 (and (not (match-string 8))
13398 (vhdl-match-string-downcase 11)))
13399 (inst-lib-key (vhdl-match-string-downcase 10)))
13400 (goto-char (match-end 1))
13401 (setq inst-list (cons inst-key inst-list)
13402 inst-ent-list
13403 (cons inst-ent-key inst-ent-list))
13404 (setq inst-alist
13405 (append
13406 inst-alist
13407 (list (list inst-key inst-name file-name
13408 (vhdl-current-line) inst-comp-name
13409 inst-ent-key inst-arch-key
13410 inst-conf-key inst-lib-key
13411 (reverse inst-path)))))))))
13412 ;; scan for contained configuration specifications
13413 (goto-char beg-of-unit)
13414 (while (re-search-forward
13415 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13416 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13417 (let* ((inst-comp-name (match-string-no-properties 3))
13418 (inst-ent-key
13419 (and (match-string 6)
13420 (vhdl-match-string-downcase 9)))
13421 (inst-arch-key (vhdl-match-string-downcase 11))
13422 (inst-conf-key
13423 (and (not (match-string 6))
13424 (vhdl-match-string-downcase 9)))
13425 (inst-lib-key (vhdl-match-string-downcase 8))
13426 (inst-key-list
13427 (split-string (vhdl-match-string-downcase 1)
13428 "[ \t\n]*,[ \t\n]*"))
13429 (tmp-inst-alist inst-alist)
13430 inst-entry)
13431 (while tmp-inst-alist
13432 (when (and (or (equal "all" (car inst-key-list))
13433 (member (nth 0 (car tmp-inst-alist))
13434 inst-key-list))
13435 (equal
13436 (downcase
13437 (or (nth 4 (car tmp-inst-alist)) ""))
13438 (downcase inst-comp-name)))
13439 (setq inst-entry (car tmp-inst-alist))
13440 (setq inst-ent-list
13441 (cons (or inst-ent-key (nth 5 inst-entry))
13442 (vhdl-delete
13443 (nth 5 inst-entry) inst-ent-list)))
13444 (setq inst-entry
13445 (list (nth 0 inst-entry) (nth 1 inst-entry)
13446 (nth 2 inst-entry) (nth 3 inst-entry)
13447 (nth 4 inst-entry)
13448 (or inst-ent-key (nth 5 inst-entry))
13449 (or inst-arch-key (nth 6 inst-entry))
13450 inst-conf-key inst-lib-key))
13451 (setcar tmp-inst-alist inst-entry))
13452 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13453 ;; save in cache
13454 (aput 'arch-alist arch-key
13455 (list (nth 0 arch-entry) (nth 1 arch-entry)
13456 (nth 2 arch-entry) inst-alist
13457 (nth 4 arch-entry)))
13458 (aput 'ent-alist ent-key
13459 (list (nth 0 ent-entry) (nth 1 ent-entry)
13460 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13461 (nth 4 ent-entry) (nth 5 ent-entry)))
13462 (when (and limit-hier-inst-no
13463 (> inst-no limit-hier-inst-no))
13464 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13465 (setq big-files t))
13466 (goto-char end-of-unit))))
13467 ;; remember design units for this file
13468 (aput 'file-alist file-name
13469 (list ent-list arch-list arch-ent-list conf-list
13470 pack-list pack-body-list inst-list inst-ent-list))
13471 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13472 (setq file-list (cdr file-list))))
13473 (when (or (and (not project) files-exist)
13474 (and project (not non-final)))
13475 ;; consistency checks:
13476 ;; check whether each architecture has a corresponding entity
13477 (setq tmp-list ent-alist)
13478 (while tmp-list
13479 (when (null (nth 2 (car tmp-list)))
13480 (setq tmp-entry (car (nth 4 (car tmp-list))))
13481 (vhdl-warning-when-idle
13482 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13483 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13484 (nth 3 tmp-entry)))
13485 (setq tmp-list (cdr tmp-list)))
13486 ;; check whether configuration has a corresponding entity/architecture
13487 (setq tmp-list conf-alist)
13488 (while tmp-list
13489 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13490 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13491 (setq tmp-entry (car tmp-list))
13492 (vhdl-warning-when-idle
13493 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13494 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13495 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13496 (setq tmp-entry (car tmp-list))
13497 (vhdl-warning-when-idle
13498 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13499 (nth 1 tmp-entry) (nth 4 tmp-entry)
13500 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13501 (setq tmp-list (cdr tmp-list)))
13502 ;; check whether each package body has a package declaration
13503 (setq tmp-list pack-alist)
13504 (while tmp-list
13505 (when (null (nth 2 (car tmp-list)))
13506 (setq tmp-entry (car tmp-list))
13507 (vhdl-warning-when-idle
13508 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13509 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13510 (setq tmp-list (cdr tmp-list)))
13511 ;; sort lists
13512 (setq ent-alist (vhdl-sort-alist ent-alist))
13513 (setq conf-alist (vhdl-sort-alist conf-alist))
13514 (setq pack-alist (vhdl-sort-alist pack-alist))
13515 ;; remember updated directory/project
13516 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13517 ;; clear directory alists
13518 (unless project
13519 (adelete 'vhdl-entity-alist key)
13520 (adelete 'vhdl-config-alist key)
13521 (adelete 'vhdl-package-alist key)
13522 (adelete 'vhdl-ent-inst-alist key)
13523 (adelete 'vhdl-file-alist key))
13524 ;; put directory contents into cache
13525 (aput 'vhdl-entity-alist key ent-alist)
13526 (aput 'vhdl-config-alist key conf-alist)
13527 (aput 'vhdl-package-alist key pack-alist)
13528 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13529 (aput 'vhdl-file-alist key file-alist)
13530 ;; final messages
13531 (message "Scanning %s %s\"%s\"...done"
13532 (if is-directory "directory" "files") (or num-string "") name)
13533 (unless project (message "Scanning directory...done"))
13534 (when big-files
13535 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13536 ;; save cache when scanned non-interactively
13537 (when (or (not project) (not non-final))
13538 (when (and noninteractive vhdl-speedbar-save-cache)
13539 (vhdl-save-cache key)))
13540 t))
13541
13542 (defun vhdl-scan-project-contents (project)
13543 "Scan the contents of all VHDL files found in the directories and files
13544 of PROJECT."
13545 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13546 (default-dir (vhdl-resolve-env-variable
13547 (nth 1 (aget vhdl-project-alist project))))
13548 (file-exclude-regexp
13549 (or (nth 3 (aget vhdl-project-alist project)) ""))
13550 dir-list-tmp dir dir-name num-dir act-dir recursive)
13551 ;; clear project alists
13552 (adelete 'vhdl-entity-alist project)
13553 (adelete 'vhdl-config-alist project)
13554 (adelete 'vhdl-package-alist project)
13555 (adelete 'vhdl-ent-inst-alist project)
13556 (adelete 'vhdl-file-alist project)
13557 ;; expand directory names by default-directory
13558 (message "Collecting source files...")
13559 (while dir-list
13560 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13561 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13562 (setq recursive (match-string 1 dir)
13563 dir-name (match-string 3 dir))
13564 (setq dir-list-tmp
13565 (cons (concat recursive
13566 (if (file-name-absolute-p dir-name) "" default-dir)
13567 dir-name)
13568 dir-list-tmp))
13569 (setq dir-list (cdr dir-list)))
13570 ;; resolve path wildcards
13571 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13572 ;; expand directories
13573 (while dir-list-tmp
13574 (setq dir (car dir-list-tmp))
13575 ;; get subdirectories
13576 (if (string-match "-r \\(.*[/\\]\\)" dir)
13577 (setq dir-list (append dir-list (vhdl-get-subdirs
13578 (match-string 1 dir))))
13579 (setq dir-list (append dir-list (list dir))))
13580 (setq dir-list-tmp (cdr dir-list-tmp)))
13581 ;; exclude files
13582 (unless (equal file-exclude-regexp "")
13583 (let ((case-fold-search nil))
13584 (while dir-list
13585 (unless (string-match file-exclude-regexp (car dir-list))
13586 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13587 (setq dir-list (cdr dir-list)))
13588 (setq dir-list (nreverse dir-list-tmp))))
13589 (message "Collecting source files...done")
13590 ;; scan for design units for each directory in DIR-LIST
13591 (setq dir-list-tmp nil
13592 num-dir (length dir-list)
13593 act-dir 1)
13594 (while dir-list
13595 (setq dir-name (abbreviate-file-name
13596 (expand-file-name (car dir-list))))
13597 (vhdl-scan-directory-contents dir-name project nil
13598 (format "(%s/%s) " act-dir num-dir)
13599 (cdr dir-list))
13600 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13601 (setq dir-list (cdr dir-list)
13602 act-dir (1+ act-dir)))
13603 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13604 (message "Scanning project \"%s\"...done" project)))
13605
13606 (defun vhdl-update-file-contents (file-name)
13607 "Update hierarchy information by contents of current buffer."
13608 (setq file-name (abbreviate-file-name file-name))
13609 (let* ((dir-name (file-name-directory file-name))
13610 (directory-alist vhdl-directory-alist)
13611 updated)
13612 (while directory-alist
13613 (when (member dir-name (nth 1 (car directory-alist)))
13614 (let* ((vhdl-project (nth 0 (car directory-alist)))
13615 (project (vhdl-project-p))
13616 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13617 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13618 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13619 (ent-inst-list (car (aget vhdl-ent-inst-alist
13620 (or project dir-name) t)))
13621 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13622 (file-entry (aget file-alist file-name t))
13623 (ent-list (nth 0 file-entry))
13624 (arch-list (nth 1 file-entry))
13625 (arch-ent-list (nth 2 file-entry))
13626 (conf-list (nth 3 file-entry))
13627 (pack-list (nth 4 file-entry))
13628 (pack-body-list (nth 5 file-entry))
13629 (inst-ent-list (nth 7 file-entry))
13630 (cache-key (or project dir-name))
13631 arch-alist key ent-key entry)
13632 ;; delete design units previously contained in this file:
13633 ;; entities
13634 (while ent-list
13635 (setq key (car ent-list)
13636 entry (aget ent-alist key t))
13637 (when (equal file-name (nth 1 entry))
13638 (if (nth 3 entry)
13639 (aput 'ent-alist key
13640 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13641 (adelete 'ent-alist key)))
13642 (setq ent-list (cdr ent-list)))
13643 ;; architectures
13644 (while arch-list
13645 (setq key (car arch-list)
13646 ent-key (car arch-ent-list)
13647 entry (aget ent-alist ent-key t)
13648 arch-alist (nth 3 entry))
13649 (when (equal file-name (nth 1 (aget arch-alist key t)))
13650 (adelete 'arch-alist key)
13651 (if (or (nth 1 entry) arch-alist)
13652 (aput 'ent-alist ent-key
13653 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13654 arch-alist (nth 4 entry) (nth 5 entry)))
13655 (adelete 'ent-alist ent-key)))
13656 (setq arch-list (cdr arch-list)
13657 arch-ent-list (cdr arch-ent-list)))
13658 ;; configurations
13659 (while conf-list
13660 (setq key (car conf-list))
13661 (when (equal file-name (nth 1 (aget conf-alist key t)))
13662 (adelete 'conf-alist key))
13663 (setq conf-list (cdr conf-list)))
13664 ;; package declarations
13665 (while pack-list
13666 (setq key (car pack-list)
13667 entry (aget pack-alist key t))
13668 (when (equal file-name (nth 1 entry))
13669 (if (nth 6 entry)
13670 (aput 'pack-alist key
13671 (list (nth 0 entry) nil nil nil nil nil
13672 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13673 (nth 9 entry)))
13674 (adelete 'pack-alist key)))
13675 (setq pack-list (cdr pack-list)))
13676 ;; package bodies
13677 (while pack-body-list
13678 (setq key (car pack-body-list)
13679 entry (aget pack-alist key t))
13680 (when (equal file-name (nth 6 entry))
13681 (if (nth 1 entry)
13682 (aput 'pack-alist key
13683 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13684 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13685 nil nil nil nil))
13686 (adelete 'pack-alist key)))
13687 (setq pack-body-list (cdr pack-body-list)))
13688 ;; instantiated entities
13689 (while inst-ent-list
13690 (setq ent-inst-list
13691 (vhdl-delete (car inst-ent-list) ent-inst-list))
13692 (setq inst-ent-list (cdr inst-ent-list)))
13693 ;; update caches
13694 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13695 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13696 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13697 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13698 ;; scan file
13699 (vhdl-scan-directory-contents file-name project t)
13700 (when (or (and vhdl-speedbar-show-projects project)
13701 (and (not vhdl-speedbar-show-projects) (not project)))
13702 (vhdl-speedbar-refresh project))
13703 (setq updated t)))
13704 (setq directory-alist (cdr directory-alist)))
13705 updated))
13706
13707 (defun vhdl-update-hierarchy ()
13708 "Update directory and hierarchy information in speedbar."
13709 (let ((file-list (reverse vhdl-modified-file-list))
13710 updated)
13711 (when (and vhdl-speedbar-update-on-saving file-list)
13712 (while file-list
13713 (setq updated
13714 (or (vhdl-update-file-contents (car file-list))
13715 updated))
13716 (setq file-list (cdr file-list)))
13717 (setq vhdl-modified-file-list nil)
13718 (vhdl-speedbar-update-current-unit)
13719 (when updated (message "Updating hierarchy...done")))))
13720
13721 ;; structure (parenthesised expression means list of such entries)
13722 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13723 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13724 ;; comp-lib-name level)
13725 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13726 conf-inst-alist level indent
13727 &optional include-top ent-hier)
13728 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13729 entity ENT-KEY."
13730 (let* ((ent-entry (aget ent-alist ent-key t))
13731 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13732 (cdar (last (nth 3 ent-entry)))))
13733 (inst-alist (nth 3 arch-entry))
13734 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13735 hier-list subcomp-list tmp-list inst-key inst-comp-name
13736 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13737 (when (= level 0) (message "Extract design hierarchy..."))
13738 (when include-top
13739 (setq level (1+ level)))
13740 (when (member ent-key ent-hier)
13741 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13742 ;; check configured architecture (already checked during scanning)
13743 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13744 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13745 ;; process all instances
13746 (while inst-alist
13747 (setq inst-entry (car inst-alist)
13748 inst-key (nth 0 inst-entry)
13749 inst-comp-name (nth 4 inst-entry)
13750 inst-conf-key (nth 7 inst-entry))
13751 ;; search entry in configuration's instantiations list
13752 (setq tmp-list conf-inst-alist)
13753 (while (and tmp-list
13754 (not (and (member (nth 0 (car tmp-list))
13755 (list "all" inst-key))
13756 (equal (nth 1 (car tmp-list))
13757 (downcase (or inst-comp-name ""))))))
13758 (setq tmp-list (cdr tmp-list)))
13759 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13760 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13761 (when (and inst-conf-key (not inst-conf-entry))
13762 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13763 ;; determine entity
13764 (setq inst-ent-key
13765 (or (nth 2 (car tmp-list)) ; from configuration
13766 (nth 3 inst-conf-entry) ; from subconfiguration
13767 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13768 ; from configuration spec.
13769 (nth 5 inst-entry))) ; from direct instantiation
13770 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13771 ;; determine architecture
13772 (setq inst-arch-key
13773 (or (nth 3 (car tmp-list)) ; from configuration
13774 (nth 4 inst-conf-entry) ; from subconfiguration
13775 (nth 6 inst-entry) ; from direct instantiation
13776 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13777 ; from configuration spec.
13778 (nth 4 inst-ent-entry) ; MRA
13779 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13780 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13781 ;; set library
13782 (setq inst-lib-key
13783 (or (nth 5 (car tmp-list)) ; from configuration
13784 (nth 8 inst-entry))) ; from direct instantiation
13785 ;; gather information for this instance
13786 (setq comp-entry
13787 (list (nth 1 inst-entry)
13788 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13789 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13790 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13791 (or (nth 0 inst-arch-entry) inst-arch-key)
13792 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13793 (or (nth 0 inst-conf-entry) inst-conf-key)
13794 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13795 inst-lib-key level))
13796 ;; get subcomponent hierarchy
13797 (setq subcomp-list (vhdl-get-hierarchy
13798 ent-alist conf-alist
13799 inst-ent-key inst-arch-key inst-conf-key
13800 (nth 5 inst-conf-entry)
13801 (1+ level) indent nil (cons ent-key ent-hier)))
13802 ;; add to list
13803 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13804 (setq inst-alist (cdr inst-alist)))
13805 (when include-top
13806 (setq hier-list
13807 (cons (list nil nil (nth 0 ent-entry)
13808 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13809 (nth 0 arch-entry)
13810 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13811 nil nil
13812 nil (1- level))
13813 hier-list)))
13814 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13815 hier-list))
13816
13817 (defun vhdl-get-instantiations (ent-key indent)
13818 "Get all instantiations of entity ENT-KEY."
13819 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13820 arch-alist inst-alist ent-inst-list
13821 ent-entry arch-entry inst-entry)
13822 (while ent-alist
13823 (setq ent-entry (car ent-alist))
13824 (setq arch-alist (nth 4 ent-entry))
13825 (while arch-alist
13826 (setq arch-entry (car arch-alist))
13827 (setq inst-alist (nth 4 arch-entry))
13828 (while inst-alist
13829 (setq inst-entry (car inst-alist))
13830 (when (equal ent-key (nth 5 inst-entry))
13831 (setq ent-inst-list
13832 (cons (list (nth 1 inst-entry)
13833 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13834 (nth 1 ent-entry)
13835 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13836 (nth 1 arch-entry)
13837 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13838 ent-inst-list)))
13839 (setq inst-alist (cdr inst-alist)))
13840 (setq arch-alist (cdr arch-alist)))
13841 (setq ent-alist (cdr ent-alist)))
13842 (nreverse ent-inst-list)))
13843
13844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13845 ;; Caching in file
13846
13847 (defun vhdl-save-caches ()
13848 "Save all updated hierarchy caches to file."
13849 (interactive)
13850 (condition-case nil
13851 (when vhdl-speedbar-save-cache
13852 ;; update hierarchy
13853 (vhdl-update-hierarchy)
13854 (let ((project-list vhdl-updated-project-list))
13855 (message "Saving hierarchy caches...")
13856 ;; write updated project caches
13857 (while project-list
13858 (vhdl-save-cache (car project-list))
13859 (setq project-list (cdr project-list)))
13860 (message "Saving hierarchy caches...done")))
13861 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13862 (sit-for 2)))))
13863
13864 (defun vhdl-save-cache (key)
13865 "Save current hierarchy cache to file."
13866 (let* ((orig-buffer (current-buffer))
13867 (vhdl-project key)
13868 (project (vhdl-project-p))
13869 (default-directory key)
13870 (directory (abbreviate-file-name (vhdl-default-directory)))
13871 (file-name (vhdl-resolve-env-variable
13872 (vhdl-replace-string
13873 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13874 (concat
13875 (subst-char-in-string ? ?_ (or project "dir"))
13876 " " (user-login-name)))))
13877 (file-dir-name (expand-file-name file-name directory))
13878 (cache-key (or project directory))
13879 (key (if project "project" "directory")))
13880 (unless (file-exists-p (file-name-directory file-dir-name))
13881 (make-directory (file-name-directory file-dir-name) t))
13882 (if (not (file-writable-p file-dir-name))
13883 (progn (vhdl-warning (format "File not writable: \"%s\""
13884 (abbreviate-file-name file-dir-name)))
13885 (sit-for 2))
13886 (message "Saving cache: \"%s\"" file-dir-name)
13887 (set-buffer (find-file-noselect file-dir-name t t))
13888 (erase-buffer)
13889 (insert ";; -*- Emacs-Lisp -*-\n\n"
13890 ";;; " (file-name-nondirectory file-name)
13891 " - design hierarchy cache file for Emacs VHDL Mode "
13892 vhdl-version "\n")
13893 (insert "\n;; " (if project "Project " "Directory") " : ")
13894 (if project (insert project) (prin1 directory (current-buffer)))
13895 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13896 (user-login-name) "\n\n"
13897 "\n;; version number\n"
13898 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13899 "\n;; " (if project "project" "directory") " name"
13900 "\n(setq " key " ")
13901 (prin1 (or project directory) (current-buffer))
13902 (insert ")\n")
13903 (when (member 'hierarchy vhdl-speedbar-save-cache)
13904 (insert "\n;; entity and architecture cache\n"
13905 "(aput 'vhdl-entity-alist " key " '")
13906 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13907 (insert ")\n\n;; configuration cache\n"
13908 "(aput 'vhdl-config-alist " key " '")
13909 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13910 (insert ")\n\n;; package cache\n"
13911 "(aput 'vhdl-package-alist " key " '")
13912 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13913 (insert ")\n\n;; instantiated entities cache\n"
13914 "(aput 'vhdl-ent-inst-alist " key " '")
13915 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13916 (insert ")\n\n;; design units per file cache\n"
13917 "(aput 'vhdl-file-alist " key " '")
13918 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13919 (when project
13920 (insert ")\n\n;; source directories in project cache\n"
13921 "(aput 'vhdl-directory-alist " key " '")
13922 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13923 (insert ")\n"))
13924 (when (member 'display vhdl-speedbar-save-cache)
13925 (insert "\n;; shown design units cache\n"
13926 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13927 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13928 (current-buffer))
13929 (insert ")\n"))
13930 (setq vhdl-updated-project-list
13931 (delete cache-key vhdl-updated-project-list))
13932 (save-buffer)
13933 (kill-buffer (current-buffer))
13934 (set-buffer orig-buffer))))
13935
13936 (defun vhdl-load-cache (key)
13937 "Load hierarchy cache information from file."
13938 (let* ((vhdl-project key)
13939 (default-directory key)
13940 (directory (vhdl-default-directory))
13941 (file-name (vhdl-resolve-env-variable
13942 (vhdl-replace-string
13943 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13944 (concat
13945 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13946 " " (user-login-name)))))
13947 (file-dir-name (expand-file-name file-name directory))
13948 vhdl-cache-version)
13949 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13950 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13951 (when (file-exists-p file-dir-name)
13952 (condition-case ()
13953 (progn (load-file file-dir-name)
13954 (string< (mapconcat
13955 (lambda (a) (format "%3d" (string-to-number a)))
13956 (split-string "3.33" "\\.") "")
13957 (mapconcat
13958 (lambda (a) (format "%3d" (string-to-number a)))
13959 (split-string vhdl-cache-version "\\.") "")))
13960 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13961 nil))))))
13962
13963 (defun vhdl-require-hierarchy-info ()
13964 "Make sure that hierarchy information is available. Load cache or scan files
13965 if required."
13966 (if (vhdl-project-p)
13967 (unless (or (assoc vhdl-project vhdl-file-alist)
13968 (vhdl-load-cache vhdl-project))
13969 (vhdl-scan-project-contents vhdl-project))
13970 (let ((directory (abbreviate-file-name default-directory)))
13971 (unless (or (assoc directory vhdl-file-alist)
13972 (vhdl-load-cache directory))
13973 (vhdl-scan-directory-contents directory)))))
13974
13975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13976 ;; Add hierarchy browser functionality to speedbar
13977
13978 (defvar vhdl-speedbar-key-map nil
13979 "Keymap used when in the VHDL hierarchy browser mode.")
13980
13981 (defvar vhdl-speedbar-menu-items nil
13982 "Additional menu-items to add to speedbar frame.")
13983
13984 (defun vhdl-speedbar-initialize ()
13985 "Initialize speedbar."
13986 ;; general settings
13987 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13988 ;; VHDL file extensions (extracted from `auto-mode-alist')
13989 (let ((mode-alist auto-mode-alist))
13990 (while mode-alist
13991 (when (eq (cdar mode-alist) 'vhdl-mode)
13992 (speedbar-add-supported-extension (caar mode-alist)))
13993 (setq mode-alist (cdr mode-alist))))
13994 ;; hierarchy browser settings
13995 (when (boundp 'speedbar-mode-functions-list)
13996 ;; special functions
13997 (speedbar-add-mode-functions-list
13998 '("vhdl directory"
13999 (speedbar-item-info . vhdl-speedbar-item-info)
14000 (speedbar-line-directory . speedbar-files-line-path)))
14001 (speedbar-add-mode-functions-list
14002 '("vhdl project"
14003 (speedbar-item-info . vhdl-speedbar-item-info)
14004 (speedbar-line-directory . vhdl-speedbar-line-project)))
14005 ;; keymap
14006 (unless vhdl-speedbar-key-map
14007 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14008 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14009 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14010 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14011 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14012 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14013 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14014 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14015 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14016 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14017 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14018 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14019 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14020 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14021 (let ((key 0))
14022 (while (<= key 9)
14023 (define-key vhdl-speedbar-key-map (int-to-string key)
14024 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14025 (setq key (1+ key)))))
14026 (define-key speedbar-key-map "h"
14027 (lambda () (interactive)
14028 (speedbar-change-initial-expansion-list "vhdl directory")))
14029 (define-key speedbar-key-map "H"
14030 (lambda () (interactive)
14031 (speedbar-change-initial-expansion-list "vhdl project")))
14032 ;; menu
14033 (unless vhdl-speedbar-menu-items
14034 (setq
14035 vhdl-speedbar-menu-items
14036 `(["Edit" speedbar-edit-line t]
14037 ["Expand" speedbar-expand-line
14038 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14039 ["Contract" vhdl-speedbar-contract-level t]
14040 ["Expand All" vhdl-speedbar-expand-all t]
14041 ["Contract All" vhdl-speedbar-contract-all t]
14042 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14043 (while (<= key 9)
14044 (setq menu-list
14045 (cons `[,(if (= key 0) "All" (int-to-string key))
14046 (vhdl-speedbar-set-depth ,key)
14047 :style radio
14048 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14049 :keys ,(int-to-string key)]
14050 menu-list))
14051 (setq key (1+ key)))
14052 (nreverse menu-list))
14053 "--"
14054 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14055 (or (vhdl-speedbar-check-unit 'entity)
14056 (vhdl-speedbar-check-unit 'subprogram))]
14057 ["Place Component" vhdl-speedbar-place-component
14058 (vhdl-speedbar-check-unit 'entity)]
14059 ["Generate Configuration" vhdl-speedbar-configuration
14060 (vhdl-speedbar-check-unit 'architecture)]
14061 ["Select as MRA" vhdl-speedbar-select-mra
14062 (vhdl-speedbar-check-unit 'architecture)]
14063 ["Make" vhdl-speedbar-make-design
14064 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14065 ["Generate Makefile" vhdl-speedbar-generate-makefile
14066 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14067 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14068 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14069 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14070 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14071 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14072 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14073 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14074 ;; hook-ups
14075 (speedbar-add-expansion-list
14076 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14077 vhdl-speedbar-display-directory))
14078 (speedbar-add-expansion-list
14079 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14080 vhdl-speedbar-display-projects))
14081 (setq speedbar-stealthy-function-list
14082 (append
14083 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14084 ("vhdl project" vhdl-speedbar-update-current-project
14085 vhdl-speedbar-update-current-unit)
14086 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14087 ; (speedbar-extension-list-to-regex
14088 ; speedbar-ignored-path-expressions))))
14089 )
14090 speedbar-stealthy-function-list))
14091 (when (eq vhdl-speedbar-display-mode 'directory)
14092 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14093 (when (eq vhdl-speedbar-display-mode 'project)
14094 (setq speedbar-initial-expansion-list-name "vhdl project"))
14095 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14096
14097 (defun vhdl-speedbar (&optional arg)
14098 "Open/close speedbar."
14099 (interactive)
14100 (if (not (fboundp 'speedbar))
14101 (error "WARNING: Speedbar is not available or not installed")
14102 (condition-case ()
14103 (speedbar-frame-mode arg)
14104 (error (error "WARNING: An error occurred while opening speedbar")))))
14105
14106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14107 ;; Display functions
14108
14109 (defvar vhdl-speedbar-last-selected-project nil
14110 "Name of last selected project.")
14111
14112 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14113 (defmacro speedbar-with-writable (&rest forms)
14114 "Allow the buffer to be writable and evaluate FORMS."
14115 (list 'let '((inhibit-read-only t))
14116 (cons 'progn forms)))
14117 (put 'speedbar-with-writable 'lisp-indent-function 0)
14118
14119 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14120 "Display directory and hierarchy information in speedbar."
14121 (setq vhdl-speedbar-show-projects nil)
14122 (setq speedbar-ignored-directory-regexp
14123 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14124 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14125 (setq speedbar-last-selected-file nil)
14126 (speedbar-with-writable
14127 (condition-case nil
14128 (progn
14129 ;; insert directory path
14130 (speedbar-directory-buttons directory depth)
14131 ;; insert subdirectories
14132 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14133 ;; scan and insert hierarchy of current directory
14134 (vhdl-speedbar-insert-dir-hierarchy directory depth
14135 speedbar-power-click)
14136 ;; expand subdirectories
14137 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14138 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14139
14140 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14141 "Display projects and hierarchy information in speedbar."
14142 (setq vhdl-speedbar-show-projects t)
14143 (setq speedbar-ignored-directory-regexp ".")
14144 (setq speedbar-last-selected-file nil)
14145 (setq vhdl-speedbar-last-selected-project nil)
14146 (speedbar-with-writable
14147 (condition-case nil
14148 ;; insert projects
14149 (vhdl-speedbar-insert-projects)
14150 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14151 (setq speedbar-full-text-cache nil)) ; prevent caching
14152
14153 (defun vhdl-speedbar-insert-projects ()
14154 "Insert all projects in speedbar."
14155 (vhdl-speedbar-make-title-line "Projects:")
14156 (let ((project-alist (if vhdl-project-sort
14157 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14158 vhdl-project-alist))
14159 (vhdl-speedbar-update-current-unit nil))
14160 ;; insert projects
14161 (while project-alist
14162 (speedbar-make-tag-line
14163 'angle ?+ 'vhdl-speedbar-expand-project
14164 (caar project-alist) (caar project-alist)
14165 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14166 (setq project-alist (cdr project-alist)))
14167 (setq project-alist vhdl-project-alist)
14168 ;; expand projects
14169 (while project-alist
14170 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14171 (goto-char (point-min))
14172 (when (re-search-forward
14173 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14174 (goto-char (match-end 1))
14175 (speedbar-do-function-pointer)))
14176 (setq project-alist (cdr project-alist))))
14177 ; (vhdl-speedbar-update-current-project)
14178 ; (vhdl-speedbar-update-current-unit nil t)
14179 )
14180
14181 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14182 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14183 otherwise use cached data."
14184 (when (or rescan (and (not (assoc project vhdl-file-alist))
14185 (not (vhdl-load-cache project))))
14186 (vhdl-scan-project-contents project))
14187 ;; insert design hierarchy
14188 (vhdl-speedbar-insert-hierarchy
14189 (aget vhdl-entity-alist project t)
14190 (aget vhdl-config-alist project t)
14191 (aget vhdl-package-alist project t)
14192 (car (aget vhdl-ent-inst-alist project t)) indent)
14193 (insert (int-to-string indent) ":\n")
14194 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14195 (put-text-property (1- (point)) (point) 'invisible nil)
14196 ;; expand design units
14197 (vhdl-speedbar-expand-units project))
14198
14199 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14200 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14201 otherwise use cached data."
14202 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14203 (not (vhdl-load-cache directory))))
14204 (vhdl-scan-directory-contents directory))
14205 ;; insert design hierarchy
14206 (vhdl-speedbar-insert-hierarchy
14207 (aget vhdl-entity-alist directory t)
14208 (aget vhdl-config-alist directory t)
14209 (aget vhdl-package-alist directory t)
14210 (car (aget vhdl-ent-inst-alist directory t)) depth)
14211 ;; expand design units
14212 (vhdl-speedbar-expand-units directory)
14213 (aput 'vhdl-directory-alist directory (list (list directory))))
14214
14215 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14216 ent-inst-list depth)
14217 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14218 (if (not (or ent-alist conf-alist pack-alist))
14219 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14220 (let (ent-entry conf-entry pack-entry)
14221 ;; insert entities
14222 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14223 (while ent-alist
14224 (setq ent-entry (car ent-alist))
14225 (speedbar-make-tag-line
14226 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14227 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14228 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14229 'vhdl-speedbar-entity-face depth)
14230 (unless (nth 2 ent-entry)
14231 (end-of-line 0) (insert "!") (forward-char 1))
14232 (unless (member (nth 0 ent-entry) ent-inst-list)
14233 (end-of-line 0) (insert " (top)") (forward-char 1))
14234 (setq ent-alist (cdr ent-alist)))
14235 ;; insert configurations
14236 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14237 (while conf-alist
14238 (setq conf-entry (car conf-alist))
14239 (speedbar-make-tag-line
14240 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14241 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14242 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14243 'vhdl-speedbar-configuration-face depth)
14244 (setq conf-alist (cdr conf-alist)))
14245 ;; insert packages
14246 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14247 (while pack-alist
14248 (setq pack-entry (car pack-alist))
14249 (vhdl-speedbar-make-pack-line
14250 (nth 0 pack-entry) (nth 1 pack-entry)
14251 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14252 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14253 depth)
14254 (setq pack-alist (cdr pack-alist))))))
14255
14256 (defun vhdl-speedbar-rescan-hierarchy ()
14257 "Rescan hierarchy for the directory or project under the cursor."
14258 (interactive)
14259 (let (key path)
14260 (cond
14261 ;; current project
14262 (vhdl-speedbar-show-projects
14263 (setq key (vhdl-speedbar-line-project))
14264 (vhdl-scan-project-contents key))
14265 ;; top-level directory
14266 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14267 (re-search-forward "[0-9]+:" nil t)
14268 (vhdl-scan-directory-contents
14269 (abbreviate-file-name (speedbar-line-directory))))
14270 ;; current directory
14271 (t (setq path (speedbar-line-directory))
14272 (string-match "^\\(.+[/\\]\\)" path)
14273 (vhdl-scan-directory-contents
14274 (abbreviate-file-name (match-string 1 path)))))
14275 (vhdl-speedbar-refresh key)))
14276
14277 (defun vhdl-speedbar-expand-dirs (directory)
14278 "Expand subdirectories in DIRECTORY according to
14279 `speedbar-shown-directories'."
14280 ;; (nicked from `speedbar-default-directory-list')
14281 (let ((sf (cdr (reverse speedbar-shown-directories)))
14282 (vhdl-speedbar-update-current-unit nil))
14283 (setq speedbar-shown-directories
14284 (list (expand-file-name default-directory)))
14285 (while sf
14286 (when (speedbar-goto-this-file (car sf))
14287 (beginning-of-line)
14288 (when (looking-at "[0-9]+:\\s-*<")
14289 (goto-char (match-end 0))
14290 (speedbar-do-function-pointer)))
14291 (setq sf (cdr sf))))
14292 (vhdl-speedbar-update-current-unit nil t))
14293
14294 (defun vhdl-speedbar-expand-units (key)
14295 "Expand design units in directory/project KEY according to
14296 `vhdl-speedbar-shown-unit-alist'."
14297 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14298 (vhdl-speedbar-update-current-unit nil)
14299 vhdl-updated-project-list)
14300 (adelete 'vhdl-speedbar-shown-unit-alist key)
14301 (vhdl-prepare-search-1
14302 (while unit-alist ; expand units
14303 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14304 (beginning-of-line)
14305 (let ((arch-alist (nth 1 (car unit-alist)))
14306 position)
14307 (when (looking-at "^[0-9]+:\\s-*\\[")
14308 (goto-char (match-end 0))
14309 (setq position (point))
14310 (speedbar-do-function-pointer)
14311 (select-frame speedbar-frame)
14312 (while arch-alist ; expand architectures
14313 (goto-char position)
14314 (when (re-search-forward
14315 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14316 (car arch-alist) "\\>\\)") nil t)
14317 (beginning-of-line)
14318 (when (looking-at "^[0-9]+:\\s-*{")
14319 (goto-char (match-end 0))
14320 (speedbar-do-function-pointer)
14321 (select-frame speedbar-frame)))
14322 (setq arch-alist (cdr arch-alist))))
14323 (setq unit-alist (cdr unit-alist))))))
14324 (vhdl-speedbar-update-current-unit nil t))
14325
14326 (defun vhdl-speedbar-contract-level ()
14327 "Contract current level in current directory/project."
14328 (interactive)
14329 (when (or (save-excursion
14330 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14331 (and (save-excursion
14332 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14333 (re-search-backward
14334 (format "^[0-%d]:\\s-*[[{<]-"
14335 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14336 (goto-char (match-end 0))
14337 (speedbar-do-function-pointer)
14338 (speedbar-center-buffer-smartly)))
14339
14340 (defun vhdl-speedbar-contract-all ()
14341 "Contract all expanded design units in current directory/project."
14342 (interactive)
14343 (if (and vhdl-speedbar-show-projects
14344 (save-excursion (beginning-of-line) (looking-at "^0:")))
14345 (progn (setq vhdl-speedbar-shown-project-list nil)
14346 (vhdl-speedbar-refresh))
14347 (let ((key (vhdl-speedbar-line-key)))
14348 (adelete 'vhdl-speedbar-shown-unit-alist key)
14349 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14350 (when (memq 'display vhdl-speedbar-save-cache)
14351 (add-to-list 'vhdl-updated-project-list key)))))
14352
14353 (defun vhdl-speedbar-expand-all ()
14354 "Expand all design units in current directory/project."
14355 (interactive)
14356 (let* ((key (vhdl-speedbar-line-key))
14357 (ent-alist (aget vhdl-entity-alist key t))
14358 (conf-alist (aget vhdl-config-alist key t))
14359 (pack-alist (aget vhdl-package-alist key t))
14360 arch-alist unit-alist subunit-alist)
14361 (add-to-list 'vhdl-speedbar-shown-project-list key)
14362 (while ent-alist
14363 (setq arch-alist (nth 4 (car ent-alist)))
14364 (setq subunit-alist nil)
14365 (while arch-alist
14366 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14367 (setq arch-alist (cdr arch-alist)))
14368 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14369 (setq ent-alist (cdr ent-alist)))
14370 (while conf-alist
14371 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14372 (setq conf-alist (cdr conf-alist)))
14373 (while pack-alist
14374 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14375 (setq pack-alist (cdr pack-alist)))
14376 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14377 (vhdl-speedbar-refresh)
14378 (when (memq 'display vhdl-speedbar-save-cache)
14379 (add-to-list 'vhdl-updated-project-list key))))
14380
14381 (defun vhdl-speedbar-expand-project (text token indent)
14382 "Expand/contract the project under the cursor."
14383 (cond
14384 ((string-match "+" text) ; expand project
14385 (speedbar-change-expand-button-char ?-)
14386 (unless (member token vhdl-speedbar-shown-project-list)
14387 (setq vhdl-speedbar-shown-project-list
14388 (cons token vhdl-speedbar-shown-project-list)))
14389 (speedbar-with-writable
14390 (save-excursion
14391 (end-of-line) (forward-char 1)
14392 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14393 speedbar-power-click))))
14394 ((string-match "-" text) ; contract project
14395 (speedbar-change-expand-button-char ?+)
14396 (setq vhdl-speedbar-shown-project-list
14397 (delete token vhdl-speedbar-shown-project-list))
14398 (speedbar-delete-subblock indent))
14399 (t (error "Nothing to display")))
14400 (when (equal (selected-frame) speedbar-frame)
14401 (speedbar-center-buffer-smartly)))
14402
14403 (defun vhdl-speedbar-expand-entity (text token indent)
14404 "Expand/contract the entity under the cursor."
14405 (cond
14406 ((string-match "+" text) ; expand entity
14407 (let* ((key (vhdl-speedbar-line-key indent))
14408 (ent-alist (aget vhdl-entity-alist key t))
14409 (ent-entry (aget ent-alist token t))
14410 (arch-alist (nth 3 ent-entry))
14411 (inst-alist (vhdl-get-instantiations token indent))
14412 (subpack-alist (nth 5 ent-entry))
14413 (multiple-arch (> (length arch-alist) 1))
14414 arch-entry inst-entry)
14415 (if (not (or arch-alist inst-alist subpack-alist))
14416 (speedbar-change-expand-button-char ??)
14417 (speedbar-change-expand-button-char ?-)
14418 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14419 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14420 (aput 'unit-alist token nil)
14421 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14422 (speedbar-with-writable
14423 (save-excursion
14424 (end-of-line) (forward-char 1)
14425 ;; insert architectures
14426 (when arch-alist
14427 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14428 (while arch-alist
14429 (setq arch-entry (car arch-alist))
14430 (speedbar-make-tag-line
14431 'curly ?+ 'vhdl-speedbar-expand-architecture
14432 (cons token (nth 0 arch-entry))
14433 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14434 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14435 'vhdl-speedbar-architecture-face (1+ indent))
14436 (when (and multiple-arch
14437 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14438 (end-of-line 0) (insert " (mra)") (forward-char 1))
14439 (setq arch-alist (cdr arch-alist)))
14440 ;; insert instantiations
14441 (when inst-alist
14442 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14443 (while inst-alist
14444 (setq inst-entry (car inst-alist))
14445 (vhdl-speedbar-make-inst-line
14446 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14447 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14448 nil nil nil (1+ indent) 0 " in ")
14449 (setq inst-alist (cdr inst-alist)))
14450 ;; insert required packages
14451 (vhdl-speedbar-insert-subpackages
14452 subpack-alist (1+ indent) indent)))
14453 (when (memq 'display vhdl-speedbar-save-cache)
14454 (add-to-list 'vhdl-updated-project-list key))
14455 (vhdl-speedbar-update-current-unit t t))))
14456 ((string-match "-" text) ; contract entity
14457 (speedbar-change-expand-button-char ?+)
14458 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14459 (let* ((key (vhdl-speedbar-line-key indent))
14460 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14461 (adelete 'unit-alist token)
14462 (if unit-alist
14463 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14464 (adelete 'vhdl-speedbar-shown-unit-alist key))
14465 (speedbar-delete-subblock indent)
14466 (when (memq 'display vhdl-speedbar-save-cache)
14467 (add-to-list 'vhdl-updated-project-list key))))
14468 (t (error "Nothing to display")))
14469 (when (equal (selected-frame) speedbar-frame)
14470 (speedbar-center-buffer-smartly)))
14471
14472 (defun vhdl-speedbar-expand-architecture (text token indent)
14473 "Expand/contract the architecture under the cursor."
14474 (cond
14475 ((string-match "+" text) ; expand architecture
14476 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14477 (ent-alist (aget vhdl-entity-alist key t))
14478 (conf-alist (aget vhdl-config-alist key t))
14479 (hier-alist (vhdl-get-hierarchy
14480 ent-alist conf-alist (car token) (cdr token) nil nil
14481 0 (1- indent)))
14482 (ent-entry (aget ent-alist (car token) t))
14483 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14484 (subpack-alist (nth 4 arch-entry))
14485 entry)
14486 (if (not (or hier-alist subpack-alist))
14487 (speedbar-change-expand-button-char ??)
14488 (speedbar-change-expand-button-char ?-)
14489 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14490 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14491 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14492 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14493 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14494 (speedbar-with-writable
14495 (save-excursion
14496 (end-of-line) (forward-char 1)
14497 ;; insert instance hierarchy
14498 (when hier-alist
14499 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14500 (1+ indent)))
14501 (while hier-alist
14502 (setq entry (car hier-alist))
14503 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14504 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14505 (vhdl-speedbar-make-inst-line
14506 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14507 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14508 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14509 (setq hier-alist (cdr hier-alist)))
14510 ;; insert required packages
14511 (vhdl-speedbar-insert-subpackages
14512 subpack-alist (1+ indent) (1- indent))))
14513 (when (memq 'display vhdl-speedbar-save-cache)
14514 (add-to-list 'vhdl-updated-project-list key))
14515 (vhdl-speedbar-update-current-unit t t))))
14516 ((string-match "-" text) ; contract architecture
14517 (speedbar-change-expand-button-char ?+)
14518 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14519 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14520 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14521 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14522 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14523 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14524 (speedbar-delete-subblock indent)
14525 (when (memq 'display vhdl-speedbar-save-cache)
14526 (add-to-list 'vhdl-updated-project-list key))))
14527 (t (error "Nothing to display")))
14528 (when (equal (selected-frame) speedbar-frame)
14529 (speedbar-center-buffer-smartly)))
14530
14531 (defun vhdl-speedbar-expand-config (text token indent)
14532 "Expand/contract the configuration under the cursor."
14533 (cond
14534 ((string-match "+" text) ; expand configuration
14535 (let* ((key (vhdl-speedbar-line-key indent))
14536 (conf-alist (aget vhdl-config-alist key t))
14537 (conf-entry (aget conf-alist token))
14538 (ent-alist (aget vhdl-entity-alist key t))
14539 (hier-alist (vhdl-get-hierarchy
14540 ent-alist conf-alist (nth 3 conf-entry)
14541 (nth 4 conf-entry) token (nth 5 conf-entry)
14542 0 indent t))
14543 (subpack-alist (nth 6 conf-entry))
14544 entry)
14545 (if (not (or hier-alist subpack-alist))
14546 (speedbar-change-expand-button-char ??)
14547 (speedbar-change-expand-button-char ?-)
14548 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14549 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14550 (aput 'unit-alist token nil)
14551 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14552 (speedbar-with-writable
14553 (save-excursion
14554 (end-of-line) (forward-char 1)
14555 ;; insert instance hierarchy
14556 (when hier-alist
14557 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14558 (while hier-alist
14559 (setq entry (car hier-alist))
14560 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14561 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14562 (vhdl-speedbar-make-inst-line
14563 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14564 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14565 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14566 (setq hier-alist (cdr hier-alist)))
14567 ;; insert required packages
14568 (vhdl-speedbar-insert-subpackages
14569 subpack-alist (1+ indent) indent)))
14570 (when (memq 'display vhdl-speedbar-save-cache)
14571 (add-to-list 'vhdl-updated-project-list key))
14572 (vhdl-speedbar-update-current-unit t t))))
14573 ((string-match "-" text) ; contract configuration
14574 (speedbar-change-expand-button-char ?+)
14575 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14576 (let* ((key (vhdl-speedbar-line-key indent))
14577 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14578 (adelete 'unit-alist token)
14579 (if unit-alist
14580 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14581 (adelete 'vhdl-speedbar-shown-unit-alist key))
14582 (speedbar-delete-subblock indent)
14583 (when (memq 'display vhdl-speedbar-save-cache)
14584 (add-to-list 'vhdl-updated-project-list key))))
14585 (t (error "Nothing to display")))
14586 (when (equal (selected-frame) speedbar-frame)
14587 (speedbar-center-buffer-smartly)))
14588
14589 (defun vhdl-speedbar-expand-package (text token indent)
14590 "Expand/contract the package under the cursor."
14591 (cond
14592 ((string-match "+" text) ; expand package
14593 (let* ((key (vhdl-speedbar-line-key indent))
14594 (pack-alist (aget vhdl-package-alist key t))
14595 (pack-entry (aget pack-alist token t))
14596 (comp-alist (nth 3 pack-entry))
14597 (func-alist (nth 4 pack-entry))
14598 (func-body-alist (nth 8 pack-entry))
14599 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14600 comp-entry func-entry func-body-entry)
14601 (if (not (or comp-alist func-alist subpack-alist))
14602 (speedbar-change-expand-button-char ??)
14603 (speedbar-change-expand-button-char ?-)
14604 ;; add package to `vhdl-speedbar-shown-unit-alist'
14605 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14606 (aput 'unit-alist token nil)
14607 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14608 (speedbar-with-writable
14609 (save-excursion
14610 (end-of-line) (forward-char 1)
14611 ;; insert components
14612 (when comp-alist
14613 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14614 (while comp-alist
14615 (setq comp-entry (car comp-alist))
14616 (speedbar-make-tag-line
14617 nil nil nil
14618 (cons token (nth 0 comp-entry))
14619 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14620 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14621 'vhdl-speedbar-entity-face (1+ indent))
14622 (setq comp-alist (cdr comp-alist)))
14623 ;; insert subprograms
14624 (when func-alist
14625 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14626 (while func-alist
14627 (setq func-entry (car func-alist)
14628 func-body-entry (aget func-body-alist (car func-entry) t))
14629 (when (nth 2 func-entry)
14630 (vhdl-speedbar-make-subprogram-line
14631 (nth 1 func-entry)
14632 (cons (nth 2 func-entry) (nth 3 func-entry))
14633 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14634 (1+ indent)))
14635 (setq func-alist (cdr func-alist)))
14636 ;; insert required packages
14637 (vhdl-speedbar-insert-subpackages
14638 subpack-alist (1+ indent) indent)))
14639 (when (memq 'display vhdl-speedbar-save-cache)
14640 (add-to-list 'vhdl-updated-project-list key))
14641 (vhdl-speedbar-update-current-unit t t))))
14642 ((string-match "-" text) ; contract package
14643 (speedbar-change-expand-button-char ?+)
14644 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14645 (let* ((key (vhdl-speedbar-line-key indent))
14646 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14647 (adelete 'unit-alist token)
14648 (if unit-alist
14649 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14650 (adelete 'vhdl-speedbar-shown-unit-alist key))
14651 (speedbar-delete-subblock indent)
14652 (when (memq 'display vhdl-speedbar-save-cache)
14653 (add-to-list 'vhdl-updated-project-list key))))
14654 (t (error "Nothing to display")))
14655 (when (equal (selected-frame) speedbar-frame)
14656 (speedbar-center-buffer-smartly)))
14657
14658 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14659 "Insert required packages."
14660 (let* ((pack-alist (aget vhdl-package-alist
14661 (vhdl-speedbar-line-key dir-indent) t))
14662 pack-key lib-name pack-entry)
14663 (when subpack-alist
14664 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14665 (while subpack-alist
14666 (setq pack-key (cdar subpack-alist)
14667 lib-name (caar subpack-alist))
14668 (setq pack-entry (aget pack-alist pack-key t))
14669 (vhdl-speedbar-make-subpack-line
14670 (or (nth 0 pack-entry) pack-key) lib-name
14671 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14672 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14673 (setq subpack-alist (cdr subpack-alist)))))
14674
14675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14676 ;; Display help functions
14677
14678 (defvar vhdl-speedbar-update-current-unit t
14679 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14680
14681 (defun vhdl-speedbar-update-current-project ()
14682 "Highlight project that is currently active."
14683 (when (and vhdl-speedbar-show-projects
14684 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14685 (and (boundp 'speedbar-frame)
14686 (frame-live-p speedbar-frame)))
14687 (let ((last-frame (selected-frame))
14688 (project-alist vhdl-project-alist)
14689 pos)
14690 (select-frame speedbar-frame)
14691 (speedbar-with-writable
14692 (save-excursion
14693 (while project-alist
14694 (goto-char (point-min))
14695 (when (re-search-forward
14696 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14697 (put-text-property (match-beginning 1) (match-end 1) 'face
14698 (if (equal (caar project-alist) vhdl-project)
14699 'speedbar-selected-face
14700 'speedbar-directory-face))
14701 (when (equal (caar project-alist) vhdl-project)
14702 (setq pos (1- (match-beginning 1)))))
14703 (setq project-alist (cdr project-alist))))
14704 (when pos (goto-char pos)))
14705 (select-frame last-frame)
14706 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14707 t)
14708
14709 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14710 "Highlight all design units that are contained in the current file.
14711 NO-POSITION non-nil means do not re-position cursor."
14712 (let ((last-frame (selected-frame))
14713 (project-list vhdl-speedbar-shown-project-list)
14714 file-alist pos file-name)
14715 ;; get current file name
14716 (if (fboundp 'speedbar-select-attached-frame)
14717 (speedbar-select-attached-frame)
14718 (select-frame speedbar-attached-frame))
14719 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14720 (when (and vhdl-speedbar-update-current-unit
14721 (or always (not (equal file-name speedbar-last-selected-file))))
14722 (if vhdl-speedbar-show-projects
14723 (while project-list
14724 (setq file-alist (append file-alist (aget vhdl-file-alist
14725 (car project-list) t)))
14726 (setq project-list (cdr project-list)))
14727 (setq file-alist (aget vhdl-file-alist
14728 (abbreviate-file-name default-directory) t)))
14729 (select-frame speedbar-frame)
14730 (set-buffer speedbar-buffer)
14731 (speedbar-with-writable
14732 (vhdl-prepare-search-1
14733 (save-excursion
14734 ;; unhighlight last units
14735 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14736 (vhdl-speedbar-update-units
14737 "\\[.\\] " (nth 0 file-entry)
14738 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14739 (vhdl-speedbar-update-units
14740 "{.} " (nth 1 file-entry)
14741 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14742 (vhdl-speedbar-update-units
14743 "\\[.\\] " (nth 3 file-entry)
14744 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14745 (vhdl-speedbar-update-units
14746 "[]>] " (nth 4 file-entry)
14747 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14748 (vhdl-speedbar-update-units
14749 "\\[.\\].+(" '("body")
14750 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14751 (vhdl-speedbar-update-units
14752 "> " (nth 6 file-entry)
14753 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14754 ;; highlight current units
14755 (let* ((file-entry (aget file-alist file-name t)))
14756 (setq
14757 pos (vhdl-speedbar-update-units
14758 "\\[.\\] " (nth 0 file-entry)
14759 file-name 'vhdl-speedbar-entity-selected-face pos)
14760 pos (vhdl-speedbar-update-units
14761 "{.} " (nth 1 file-entry)
14762 file-name 'vhdl-speedbar-architecture-selected-face pos)
14763 pos (vhdl-speedbar-update-units
14764 "\\[.\\] " (nth 3 file-entry)
14765 file-name 'vhdl-speedbar-configuration-selected-face pos)
14766 pos (vhdl-speedbar-update-units
14767 "[]>] " (nth 4 file-entry)
14768 file-name 'vhdl-speedbar-package-selected-face pos)
14769 pos (vhdl-speedbar-update-units
14770 "\\[.\\].+(" '("body")
14771 file-name 'vhdl-speedbar-package-selected-face pos)
14772 pos (vhdl-speedbar-update-units
14773 "> " (nth 6 file-entry)
14774 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14775 ;; move speedbar so the first highlighted unit is visible
14776 (when (and pos (not no-position))
14777 (goto-char pos)
14778 (speedbar-center-buffer-smartly)
14779 (speedbar-position-cursor-on-line))
14780 (setq speedbar-last-selected-file file-name))
14781 (select-frame last-frame)
14782 t))
14783
14784 (defun vhdl-speedbar-update-units (text unit-list file-name face
14785 &optional pos)
14786 "Help function to highlight design units."
14787 (while unit-list
14788 (goto-char (point-min))
14789 (while (re-search-forward
14790 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14791 (when (equal file-name (car (get-text-property
14792 (match-beginning 1) 'speedbar-token)))
14793 (setq pos (or pos (point-marker)))
14794 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14795 (setq unit-list (cdr unit-list)))
14796 pos)
14797
14798 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14799 ent-name ent-file-marker
14800 arch-name arch-file-marker
14801 conf-name conf-file-marker
14802 lib-name depth offset delimiter)
14803 "Insert instantiation entry."
14804 (let ((start (point))
14805 visible-start)
14806 (insert (int-to-string depth) ":")
14807 (put-text-property start (point) 'invisible t)
14808 (setq visible-start (point))
14809 (insert-char ? (* depth speedbar-indentation-width))
14810 (while (> offset 0)
14811 (insert "|")
14812 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14813 (setq offset (1- offset)))
14814 (put-text-property visible-start (point) 'invisible nil)
14815 (setq start (point))
14816 (insert ">")
14817 (speedbar-make-button start (point) nil nil nil)
14818 (setq visible-start (point))
14819 (insert " ")
14820 (setq start (point))
14821 (if (not inst-name)
14822 (insert "(top)")
14823 (insert inst-name)
14824 (speedbar-make-button
14825 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14826 'vhdl-speedbar-find-file inst-file-marker))
14827 (insert delimiter)
14828 (when ent-name
14829 (setq start (point))
14830 (insert ent-name)
14831 (speedbar-make-button
14832 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14833 'vhdl-speedbar-find-file ent-file-marker)
14834 (when arch-name
14835 (insert " (")
14836 (setq start (point))
14837 (insert arch-name)
14838 (speedbar-make-button
14839 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14840 'vhdl-speedbar-find-file arch-file-marker)
14841 (insert ")"))
14842 (when conf-name
14843 (insert " (")
14844 (setq start (point))
14845 (insert conf-name)
14846 (speedbar-make-button
14847 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14848 'vhdl-speedbar-find-file conf-file-marker)
14849 (insert ")")))
14850 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14851 (setq start (point))
14852 (insert " (" lib-name ")")
14853 (put-text-property (+ 2 start) (1- (point)) 'face
14854 'vhdl-speedbar-library-face))
14855 (insert-char ?\n 1)
14856 (put-text-property visible-start (point) 'invisible nil)))
14857
14858 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14859 body-file-marker depth)
14860 "Insert package entry."
14861 (let ((start (point))
14862 visible-start)
14863 (insert (int-to-string depth) ":")
14864 (put-text-property start (point) 'invisible t)
14865 (setq visible-start (point))
14866 (insert-char ? (* depth speedbar-indentation-width))
14867 (put-text-property visible-start (point) 'invisible nil)
14868 (setq start (point))
14869 (insert "[+]")
14870 (speedbar-make-button
14871 start (point) 'speedbar-button-face 'speedbar-highlight-face
14872 'vhdl-speedbar-expand-package pack-key)
14873 (setq visible-start (point))
14874 (insert-char ? 1 nil)
14875 (setq start (point))
14876 (insert pack-name)
14877 (speedbar-make-button
14878 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14879 'vhdl-speedbar-find-file pack-file-marker)
14880 (unless (car pack-file-marker)
14881 (insert "!"))
14882 (when (car body-file-marker)
14883 (insert " (")
14884 (setq start (point))
14885 (insert "body")
14886 (speedbar-make-button
14887 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14888 'vhdl-speedbar-find-file body-file-marker)
14889 (insert ")"))
14890 (insert-char ?\n 1)
14891 (put-text-property visible-start (point) 'invisible nil)))
14892
14893 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14894 pack-body-file-marker depth)
14895 "Insert used package entry."
14896 (let ((start (point))
14897 visible-start)
14898 (insert (int-to-string depth) ":")
14899 (put-text-property start (point) 'invisible t)
14900 (setq visible-start (point))
14901 (insert-char ? (* depth speedbar-indentation-width))
14902 (put-text-property visible-start (point) 'invisible nil)
14903 (setq start (point))
14904 (insert ">")
14905 (speedbar-make-button start (point) nil nil nil)
14906 (setq visible-start (point))
14907 (insert " ")
14908 (setq start (point))
14909 (insert pack-name)
14910 (speedbar-make-button
14911 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14912 'vhdl-speedbar-find-file pack-file-marker)
14913 (when (car pack-body-file-marker)
14914 (insert " (")
14915 (setq start (point))
14916 (insert "body")
14917 (speedbar-make-button
14918 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14919 'vhdl-speedbar-find-file pack-body-file-marker)
14920 (insert ")"))
14921 (setq start (point))
14922 (insert " (" lib-name ")")
14923 (put-text-property (+ 2 start) (1- (point)) 'face
14924 'vhdl-speedbar-library-face)
14925 (insert-char ?\n 1)
14926 (put-text-property visible-start (point) 'invisible nil)))
14927
14928 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14929 func-body-file-marker
14930 depth)
14931 "Insert subprogram entry."
14932 (let ((start (point))
14933 visible-start)
14934 (insert (int-to-string depth) ":")
14935 (put-text-property start (point) 'invisible t)
14936 (setq visible-start (point))
14937 (insert-char ? (* depth speedbar-indentation-width))
14938 (put-text-property visible-start (point) 'invisible nil)
14939 (setq start (point))
14940 (insert ">")
14941 (speedbar-make-button start (point) nil nil nil)
14942 (setq visible-start (point))
14943 (insert " ")
14944 (setq start (point))
14945 (insert func-name)
14946 (speedbar-make-button
14947 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14948 'vhdl-speedbar-find-file func-file-marker)
14949 (when (car func-body-file-marker)
14950 (insert " (")
14951 (setq start (point))
14952 (insert "body")
14953 (speedbar-make-button
14954 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14955 'vhdl-speedbar-find-file func-body-file-marker)
14956 (insert ")"))
14957 (insert-char ?\n 1)
14958 (put-text-property visible-start (point) 'invisible nil)))
14959
14960 (defun vhdl-speedbar-make-title-line (text &optional depth)
14961 "Insert design unit title entry."
14962 (let ((start (point))
14963 visible-start)
14964 (when depth
14965 (insert (int-to-string depth) ":")
14966 (put-text-property start (point) 'invisible t))
14967 (setq visible-start (point))
14968 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14969 (setq start (point))
14970 (insert text)
14971 (speedbar-make-button start (point) nil nil nil nil)
14972 (insert-char ?\n 1)
14973 (put-text-property visible-start (point) 'invisible nil)))
14974
14975 (defun vhdl-speedbar-insert-dirs (files level)
14976 "Insert subdirectories."
14977 (let ((dirs (car files)))
14978 (while dirs
14979 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14980 (car dirs) 'speedbar-dir-follow nil
14981 'speedbar-directory-face level)
14982 (setq dirs (cdr dirs)))))
14983
14984 (defun vhdl-speedbar-dired (text token indent)
14985 "Speedbar click handler for directory expand button in hierarchy mode."
14986 (cond ((string-match "+" text) ; we have to expand this dir
14987 (setq speedbar-shown-directories
14988 (cons (expand-file-name
14989 (concat (speedbar-line-directory indent) token "/"))
14990 speedbar-shown-directories))
14991 (speedbar-change-expand-button-char ?-)
14992 (speedbar-reset-scanners)
14993 (speedbar-with-writable
14994 (save-excursion
14995 (end-of-line) (forward-char 1)
14996 (vhdl-speedbar-insert-dirs
14997 (speedbar-file-lists
14998 (concat (speedbar-line-directory indent) token "/"))
14999 (1+ indent))
15000 (speedbar-reset-scanners)
15001 (vhdl-speedbar-insert-dir-hierarchy
15002 (abbreviate-file-name
15003 (concat (speedbar-line-directory indent) token "/"))
15004 (1+ indent) speedbar-power-click)))
15005 (vhdl-speedbar-update-current-unit t t))
15006 ((string-match "-" text) ; we have to contract this node
15007 (speedbar-reset-scanners)
15008 (let ((oldl speedbar-shown-directories)
15009 (newl nil)
15010 (td (expand-file-name
15011 (concat (speedbar-line-directory indent) token))))
15012 (while oldl
15013 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15014 (setq newl (cons (car oldl) newl)))
15015 (setq oldl (cdr oldl)))
15016 (setq speedbar-shown-directories (nreverse newl)))
15017 (speedbar-change-expand-button-char ?+)
15018 (speedbar-delete-subblock indent))
15019 (t (error "Nothing to display")))
15020 (when (equal (selected-frame) speedbar-frame)
15021 (speedbar-center-buffer-smartly)))
15022
15023 (defun vhdl-speedbar-item-info ()
15024 "Derive and display information about this line item."
15025 (save-excursion
15026 (beginning-of-line)
15027 ;; skip invisible number info
15028 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15029 (cond
15030 ;; project/directory entry
15031 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15032 (if vhdl-speedbar-show-projects
15033 (message "Project \"%s\"" (match-string-no-properties 1))
15034 (speedbar-files-item-info)))
15035 ;; design unit entry
15036 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15037 (goto-char (match-end 1))
15038 (let ((face (get-text-property (point) 'face)))
15039 (message
15040 "%s \"%s\" in \"%s\""
15041 ;; design unit kind
15042 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15043 (eq face 'vhdl-speedbar-entity-selected-face))
15044 (if (equal (match-string 2) ">") "Component" "Entity"))
15045 ((or (eq face 'vhdl-speedbar-architecture-face)
15046 (eq face 'vhdl-speedbar-architecture-selected-face))
15047 "Architecture")
15048 ((or (eq face 'vhdl-speedbar-configuration-face)
15049 (eq face 'vhdl-speedbar-configuration-selected-face))
15050 "Configuration")
15051 ((or (eq face 'vhdl-speedbar-package-face)
15052 (eq face 'vhdl-speedbar-package-selected-face))
15053 "Package")
15054 ((or (eq face 'vhdl-speedbar-instantiation-face)
15055 (eq face 'vhdl-speedbar-instantiation-selected-face))
15056 "Instantiation")
15057 ((eq face 'vhdl-speedbar-subprogram-face)
15058 "Subprogram")
15059 (t ""))
15060 ;; design unit name
15061 (buffer-substring-no-properties
15062 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15063 (match-end 1))
15064 ;; file name
15065 (file-relative-name
15066 (or (car (get-text-property (point) 'speedbar-token))
15067 "?")
15068 (vhdl-default-directory)))))
15069 (t (message "")))))
15070
15071 (defun vhdl-speedbar-line-text ()
15072 "Calls `speedbar-line-text' and removes text properties."
15073 (let ((string (speedbar-line-text)))
15074 (set-text-properties 0 (length string) nil string)
15075 string))
15076
15077 (defun vhdl-speedbar-higher-text ()
15078 "Get speedbar-line-text of higher level."
15079 (let (depth string)
15080 (save-excursion
15081 (beginning-of-line)
15082 (looking-at "^\\([0-9]+\\):")
15083 (setq depth (string-to-number (match-string 1)))
15084 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15085 (setq string (match-string 1))
15086 (set-text-properties 0 (length string) nil string)
15087 string))))
15088
15089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15090 ;; Help functions
15091
15092 (defun vhdl-speedbar-line-key (&optional indent)
15093 "Get currently displayed directory of project name."
15094 (if vhdl-speedbar-show-projects
15095 (vhdl-speedbar-line-project)
15096 (abbreviate-file-name
15097 (file-name-as-directory (speedbar-line-directory indent)))))
15098
15099 (defun vhdl-speedbar-line-project (&optional indent)
15100 "Get currently displayed project name."
15101 (and vhdl-speedbar-show-projects
15102 (save-excursion
15103 (end-of-line)
15104 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15105 (match-string-no-properties 1))))
15106
15107 (defun vhdl-add-modified-file ()
15108 "Add file to `vhdl-modified-file-list'."
15109 (when vhdl-file-alist
15110 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15111 nil)
15112
15113 (defun vhdl-resolve-paths (path-list)
15114 "Resolve path wildcards in PATH-LIST."
15115 (let (path-list-1 path-list-2 path-beg path-end dir)
15116 ;; eliminate non-existent directories
15117 (while path-list
15118 (setq dir (car path-list))
15119 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15120 (if (file-directory-p (match-string 2 dir))
15121 (setq path-list-1 (cons dir path-list-1))
15122 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15123 (setq path-list (cdr path-list)))
15124 ;; resolve path wildcards
15125 (while path-list-1
15126 (setq dir (car path-list-1))
15127 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15128 (progn
15129 (setq path-beg (match-string 1 dir)
15130 path-end (match-string 5 dir))
15131 (setq path-list-1
15132 (append
15133 (mapcar
15134 (function
15135 (lambda (var) (concat path-beg var path-end)))
15136 (let ((all-list (vhdl-directory-files
15137 (match-string 2 dir) t
15138 (concat "\\<" (wildcard-to-regexp
15139 (match-string 4 dir)))))
15140 dir-list)
15141 (while all-list
15142 (when (file-directory-p (car all-list))
15143 (setq dir-list (cons (car all-list) dir-list)))
15144 (setq all-list (cdr all-list)))
15145 dir-list))
15146 (cdr path-list-1))))
15147 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15148 (when (file-directory-p (match-string 2 dir))
15149 (setq path-list-2 (cons dir path-list-2)))
15150 (setq path-list-1 (cdr path-list-1))))
15151 (nreverse path-list-2)))
15152
15153 (defun vhdl-speedbar-goto-this-unit (directory unit)
15154 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15155 (let ((dest (point)))
15156 (if (and (if vhdl-speedbar-show-projects
15157 (progn (goto-char (point-min)) t)
15158 (speedbar-goto-this-file directory))
15159 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15160 (progn (speedbar-position-cursor-on-line)
15161 t)
15162 (goto-char dest)
15163 nil)))
15164
15165 (defun vhdl-speedbar-find-file (text token indent)
15166 "When user clicks on TEXT, load file with name and position in TOKEN.
15167 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15168 is already shown in a buffer."
15169 (if (not (car token))
15170 (error "ERROR: File cannot be found")
15171 (let ((buffer (get-file-buffer (car token))))
15172 (speedbar-find-file-in-frame (car token))
15173 (when (or vhdl-speedbar-jump-to-unit buffer)
15174 (goto-line (cdr token))
15175 (recenter))
15176 (vhdl-speedbar-update-current-unit t t)
15177 (speedbar-set-timer dframe-update-speed)
15178 (speedbar-maybee-jump-to-attached-frame))))
15179
15180 (defun vhdl-speedbar-port-copy ()
15181 "Copy the port of the entity/component or subprogram under the cursor."
15182 (interactive)
15183 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15184 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15185 (error "ERROR: No entity/component or subprogram under cursor")
15186 (beginning-of-line)
15187 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15188 (condition-case info
15189 (let ((token (get-text-property
15190 (match-beginning 3) 'speedbar-token)))
15191 (vhdl-visit-file (car token) t
15192 (progn (goto-line (cdr token))
15193 (end-of-line)
15194 (if is-entity
15195 (vhdl-port-copy)
15196 (vhdl-subprog-copy)))))
15197 (error (error "ERROR: %s not scanned successfully\n (%s)"
15198 (if is-entity "Port" "Interface") (cadr info))))
15199 (error "ERROR: No entity/component or subprogram on current line")))))
15200
15201 (defun vhdl-speedbar-place-component ()
15202 "Place the entity/component under the cursor as component."
15203 (interactive)
15204 (if (not (vhdl-speedbar-check-unit 'entity))
15205 (error "ERROR: No entity/component under cursor")
15206 (vhdl-speedbar-port-copy)
15207 (if (fboundp 'speedbar-select-attached-frame)
15208 (speedbar-select-attached-frame)
15209 (select-frame speedbar-attached-frame))
15210 (vhdl-compose-place-component)
15211 (select-frame speedbar-frame)))
15212
15213 (defun vhdl-speedbar-configuration ()
15214 "Generate configuration for the architecture under the cursor."
15215 (interactive)
15216 (if (not (vhdl-speedbar-check-unit 'architecture))
15217 (error "ERROR: No architecture under cursor")
15218 (let ((arch-name (vhdl-speedbar-line-text))
15219 (ent-name (vhdl-speedbar-higher-text)))
15220 (if (fboundp 'speedbar-select-attached-frame)
15221 (speedbar-select-attached-frame)
15222 (select-frame speedbar-attached-frame))
15223 (vhdl-compose-configuration ent-name arch-name))))
15224
15225 (defun vhdl-speedbar-select-mra ()
15226 "Select the architecture under the cursor as MRA."
15227 (interactive)
15228 (if (not (vhdl-speedbar-check-unit 'architecture))
15229 (error "ERROR: No architecture under cursor")
15230 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15231 (ent-key (downcase (vhdl-speedbar-higher-text)))
15232 (ent-alist (aget vhdl-entity-alist
15233 (or (vhdl-project-p) default-directory) t))
15234 (ent-entry (aget ent-alist ent-key t)))
15235 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15236 (speedbar-refresh))))
15237
15238 (defun vhdl-speedbar-make-design ()
15239 "Make (compile) design unit or directory/project under the cursor."
15240 (interactive)
15241 (if (not (save-excursion (beginning-of-line)
15242 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15243 (error "ERROR: No primary design unit or directory/project under cursor")
15244 (let ((is-unit (match-string 2))
15245 (unit-name (vhdl-speedbar-line-text))
15246 (vhdl-project (vhdl-speedbar-line-project))
15247 (directory (file-name-as-directory
15248 (or (speedbar-line-file) (speedbar-line-directory)))))
15249 (if (fboundp 'speedbar-select-attached-frame)
15250 (speedbar-select-attached-frame)
15251 (select-frame speedbar-attached-frame))
15252 (let ((default-directory directory))
15253 (vhdl-make (and is-unit unit-name))))))
15254
15255 (defun vhdl-speedbar-generate-makefile ()
15256 "Generate Makefile for directory/project under the cursor."
15257 (interactive)
15258 (let ((vhdl-project (vhdl-speedbar-line-project))
15259 (default-directory (file-name-as-directory
15260 (or (speedbar-line-file) (speedbar-line-directory)))))
15261 (vhdl-generate-makefile)))
15262
15263 (defun vhdl-speedbar-check-unit (design-unit)
15264 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15265 expansion function)."
15266 (save-excursion
15267 (speedbar-position-cursor-on-line)
15268 (cond ((eq design-unit 'entity)
15269 (memq (get-text-property (match-end 0) 'face)
15270 '(vhdl-speedbar-entity-face
15271 vhdl-speedbar-entity-selected-face)))
15272 ((eq design-unit 'architecture)
15273 (memq (get-text-property (match-end 0) 'face)
15274 '(vhdl-speedbar-architecture-face
15275 vhdl-speedbar-architecture-selected-face)))
15276 ((eq design-unit 'subprogram)
15277 (eq (get-text-property (match-end 0) 'face)
15278 'vhdl-speedbar-subprogram-face))
15279 (t nil))))
15280
15281 (defun vhdl-speedbar-set-depth (depth)
15282 "Set hierarchy display depth to DEPTH and refresh speedbar."
15283 (setq vhdl-speedbar-hierarchy-depth depth)
15284 (speedbar-refresh))
15285
15286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15287 ;; Fontification
15288
15289 (defface vhdl-speedbar-entity-face
15290 '((((class color) (background light)) (:foreground "ForestGreen"))
15291 (((class color) (background dark)) (:foreground "PaleGreen")))
15292 "Face used for displaying entity names."
15293 :group 'speedbar-faces)
15294
15295 (defface vhdl-speedbar-architecture-face
15296 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15297 (((class color) (background light)) (:foreground "Blue"))
15298
15299 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15300 "Face used for displaying architecture names."
15301 :group 'speedbar-faces)
15302
15303 (defface vhdl-speedbar-configuration-face
15304 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15305 (((class color) (background dark)) (:foreground "Salmon")))
15306 "Face used for displaying configuration names."
15307 :group 'speedbar-faces)
15308
15309 (defface vhdl-speedbar-package-face
15310 '((((class color) (background light)) (:foreground "Grey50"))
15311 (((class color) (background dark)) (:foreground "Grey80")))
15312 "Face used for displaying package names."
15313 :group 'speedbar-faces)
15314
15315 (defface vhdl-speedbar-library-face
15316 '((((class color) (background light)) (:foreground "Purple"))
15317 (((class color) (background dark)) (:foreground "Orchid1")))
15318 "Face used for displaying library names."
15319 :group 'speedbar-faces)
15320
15321 (defface vhdl-speedbar-instantiation-face
15322 '((((class color) (background light)) (:foreground "Brown"))
15323 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15324 (((class color) (background dark)) (:foreground "Yellow")))
15325 "Face used for displaying instantiation names."
15326 :group 'speedbar-faces)
15327
15328 (defface vhdl-speedbar-subprogram-face
15329 '((((class color) (background light)) (:foreground "Orchid4"))
15330 (((class color) (background dark)) (:foreground "BurlyWood2")))
15331 "Face used for displaying subprogram names."
15332 :group 'speedbar-faces)
15333
15334 (defface vhdl-speedbar-entity-selected-face
15335 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15336 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15337 "Face used for displaying entity names."
15338 :group 'speedbar-faces)
15339
15340 (defface vhdl-speedbar-architecture-selected-face
15341 '((((min-colors 88) (class color) (background light)) (:foreground
15342 "Blue1" :underline t))
15343 (((class color) (background light)) (:foreground "Blue" :underline t))
15344 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15345 "Face used for displaying architecture names."
15346 :group 'speedbar-faces)
15347
15348 (defface vhdl-speedbar-configuration-selected-face
15349 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15350 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15351 "Face used for displaying configuration names."
15352 :group 'speedbar-faces)
15353
15354 (defface vhdl-speedbar-package-selected-face
15355 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15356 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15357 "Face used for displaying package names."
15358 :group 'speedbar-faces)
15359
15360 (defface vhdl-speedbar-instantiation-selected-face
15361 '((((class color) (background light)) (:foreground "Brown" :underline t))
15362 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15363 "Face used for displaying instantiation names."
15364 :group 'speedbar-faces)
15365
15366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15367 ;; Initialization
15368
15369 ;; add speedbar
15370 (when (fboundp 'speedbar)
15371 (condition-case ()
15372 (when (and vhdl-speedbar-auto-open
15373 (not (and (boundp 'speedbar-frame)
15374 (frame-live-p speedbar-frame))))
15375 (speedbar-frame-mode 1)
15376 (if (fboundp 'speedbar-select-attached-frame)
15377 (speedbar-select-attached-frame)
15378 (select-frame speedbar-attached-frame)))
15379 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15380
15381 ;; initialize speedbar
15382 (if (not (boundp 'speedbar-frame))
15383 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15384 (vhdl-speedbar-initialize)
15385 (when speedbar-frame (vhdl-speedbar-refresh)))
15386
15387
15388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15389 ;;; Structural composition
15390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15391
15392 (defun vhdl-get-components-package-name ()
15393 "Return the name of the components package."
15394 (let ((project (vhdl-project-p)))
15395 (if project
15396 (vhdl-replace-string (car vhdl-components-package-name)
15397 (subst-char-in-string ? ?_ project))
15398 (cdr vhdl-components-package-name))))
15399
15400 (defun vhdl-compose-new-component ()
15401 "Create entity and architecture for new component."
15402 (interactive)
15403 (let* ((case-fold-search t)
15404 (ent-name (read-from-minibuffer "entity name: "
15405 nil vhdl-minibuffer-local-map))
15406 (arch-name
15407 (if (equal (cdr vhdl-compose-architecture-name) "")
15408 (read-from-minibuffer "architecture name: "
15409 nil vhdl-minibuffer-local-map)
15410 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15411 ent-file-name arch-file-name ent-buffer arch-buffer project)
15412 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15413 ;; open entity file
15414 (unless (eq vhdl-compose-create-files 'none)
15415 (setq ent-file-name
15416 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15417 "." (file-name-extension (buffer-file-name))))
15418 (when (and (file-exists-p ent-file-name)
15419 (not (y-or-n-p (concat "File \"" ent-file-name
15420 "\" exists; overwrite? "))))
15421 (error "ERROR: Creating component...aborted"))
15422 (find-file ent-file-name)
15423 (erase-buffer)
15424 (set-buffer-modified-p nil))
15425 ;; insert header
15426 (if vhdl-compose-include-header
15427 (progn (vhdl-template-header)
15428 (goto-char (point-max)))
15429 (vhdl-comment-display-line) (insert "\n\n"))
15430 ;; insert library clause
15431 (vhdl-template-package-std-logic-1164)
15432 (when vhdl-use-components-package
15433 (insert "\n")
15434 (vhdl-template-standard-package (vhdl-work-library)
15435 (vhdl-get-components-package-name)))
15436 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15437 ;; insert entity declaration
15438 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15439 (vhdl-insert-keyword " IS\n")
15440 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15441 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15442 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15443 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15444 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15445 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15446 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15447 (vhdl-insert-keyword "END ")
15448 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15449 (insert ent-name ";\n\n")
15450 (vhdl-comment-display-line) (insert "\n")
15451 ;; open architecture file
15452 (if (not (eq vhdl-compose-create-files 'separate))
15453 (insert "\n")
15454 (setq ent-buffer (current-buffer))
15455 (setq arch-file-name
15456 (concat (vhdl-replace-string vhdl-architecture-file-name
15457 (concat ent-name " " arch-name) t)
15458 "." (file-name-extension (buffer-file-name))))
15459 (when (and (file-exists-p arch-file-name)
15460 (not (y-or-n-p (concat "File \"" arch-file-name
15461 "\" exists; overwrite? "))))
15462 (error "ERROR: Creating component...aborted"))
15463 (find-file arch-file-name)
15464 (erase-buffer)
15465 (set-buffer-modified-p nil)
15466 ;; insert header
15467 (if vhdl-compose-include-header
15468 (progn (vhdl-template-header)
15469 (goto-char (point-max)))
15470 (vhdl-comment-display-line) (insert "\n\n")))
15471 ;; insert architecture body
15472 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15473 (vhdl-insert-keyword " OF ") (insert ent-name)
15474 (vhdl-insert-keyword " IS\n\n")
15475 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15476 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15477 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15478 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15479 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15480 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15481 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15482 (vhdl-insert-keyword "BEGIN")
15483 (when vhdl-self-insert-comments
15484 (insert " -- ")
15485 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15486 (insert arch-name))
15487 (insert "\n\n")
15488 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15489 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15490 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15491 (vhdl-insert-keyword "END ")
15492 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15493 (insert arch-name ";\n\n")
15494 ;; insert footer and save
15495 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15496 (vhdl-template-footer)
15497 (vhdl-comment-display-line) (insert "\n"))
15498 (goto-char (point-min))
15499 (setq arch-buffer (current-buffer))
15500 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15501 (set-buffer arch-buffer) (save-buffer)
15502 (message "%s"
15503 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15504 (and ent-file-name
15505 (format "\n File created: \"%s\"" ent-file-name))
15506 (and arch-file-name
15507 (format "\n File created: \"%s\"" arch-file-name))))))
15508
15509 (defun vhdl-compose-place-component ()
15510 "Place new component by pasting current port as component declaration and
15511 component instantiation."
15512 (interactive)
15513 (if (not vhdl-port-list)
15514 (error "ERROR: No port has been read")
15515 (save-excursion
15516 (vhdl-prepare-search-2
15517 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15518 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15519 (error "ERROR: No architecture found"))
15520 (let* ((ent-name (match-string 1))
15521 (ent-file-name
15522 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15523 "." (file-name-extension (buffer-file-name))))
15524 (orig-buffer (current-buffer)))
15525 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15526 ;; place component declaration
15527 (unless (or vhdl-use-components-package
15528 (vhdl-use-direct-instantiation)
15529 (save-excursion
15530 (re-search-forward
15531 (concat "^\\s-*component\\s-+"
15532 (car vhdl-port-list) "\\>") nil t)))
15533 (re-search-forward "^begin\\>" nil)
15534 (beginning-of-line)
15535 (skip-chars-backward " \t\n")
15536 (insert "\n\n") (indent-to vhdl-basic-offset)
15537 (vhdl-port-paste-component t))
15538 ;; place component instantiation
15539 (re-search-forward "^end\\>" nil)
15540 (beginning-of-line)
15541 (skip-chars-backward " \t\n")
15542 (insert "\n\n") (indent-to vhdl-basic-offset)
15543 (vhdl-port-paste-instance nil t t)
15544 ;; place use clause for used packages
15545 (when (nth 3 vhdl-port-list)
15546 ;; open entity file
15547 (when (file-exists-p ent-file-name)
15548 (find-file ent-file-name))
15549 (goto-char (point-min))
15550 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15551 (error "ERROR: Entity not found: \"%s\"" ent-name))
15552 (goto-char (match-beginning 0))
15553 (if (and (save-excursion
15554 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15555 (match-string 1))
15556 (progn (goto-char (match-end 0))
15557 (beginning-of-line 2))
15558 (insert "\n")
15559 (backward-char))
15560 (vhdl-port-paste-context-clause)
15561 (switch-to-buffer orig-buffer))
15562 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15563
15564 (defun vhdl-compose-wire-components ()
15565 "Connect components."
15566 (interactive)
15567 (save-excursion
15568 (vhdl-prepare-search-2
15569 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15570 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15571 (error "ERROR: No architecture found"))
15572 (let* ((ent-name (match-string 1))
15573 (ent-file-name
15574 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15575 "." (file-name-extension (buffer-file-name))))
15576 (arch-decl-pos (point-marker))
15577 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15578 (arch-end-pos (re-search-forward "^end\\>" nil))
15579 (pack-name (vhdl-get-components-package-name))
15580 (pack-file-name
15581 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15582 "." (file-name-extension (buffer-file-name))))
15583 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15584 port-alist generic-alist inst-alist
15585 signal-name signal-entry signal-alist local-list written-list
15586 single-in-list multi-in-list single-out-list multi-out-list
15587 constant-name constant-entry constant-alist single-list multi-list
15588 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15589 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15590 signal-beg-pos signal-pos
15591 constant-temp-pos port-temp-pos signal-temp-pos)
15592 (message "Wiring components...")
15593 ;; process all instances
15594 (goto-char arch-stat-pos)
15595 (while (re-search-forward
15596 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15597 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15598 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15599 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15600 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15601 (setq inst-name (match-string-no-properties 1)
15602 comp-name (match-string-no-properties 4)
15603 comp-ent-name (match-string-no-properties 12)
15604 has-generic (or (match-string 7) (match-string 17)))
15605 ;; get port ...
15606 (if comp-name
15607 ;; ... from component declaration
15608 (vhdl-visit-file
15609 (when vhdl-use-components-package pack-file-name) t
15610 (save-excursion
15611 (goto-char (point-min))
15612 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15613 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15614 (vhdl-port-copy)))
15615 ;; ... from entity declaration (direct instantiation)
15616 (setq comp-ent-file-name
15617 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15618 "." (file-name-extension (buffer-file-name))))
15619 (vhdl-visit-file
15620 comp-ent-file-name t
15621 (save-excursion
15622 (goto-char (point-min))
15623 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15624 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15625 (vhdl-port-copy))))
15626 (vhdl-port-flatten t)
15627 (setq generic-alist (nth 1 vhdl-port-list)
15628 port-alist (nth 2 vhdl-port-list)
15629 vhdl-port-list nil)
15630 (setq constant-alist nil
15631 signal-alist nil)
15632 (when has-generic
15633 ;; process all constants in generic map
15634 (vhdl-forward-syntactic-ws)
15635 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15636 (setq constant-name (match-string-no-properties 3))
15637 (setq constant-entry
15638 (cons constant-name
15639 (if (match-string 1)
15640 (or (aget generic-alist (match-string 2) t)
15641 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15642 (cdar generic-alist))))
15643 (setq constant-alist (cons constant-entry constant-alist))
15644 (setq constant-name (downcase constant-name))
15645 (if (or (member constant-name single-list)
15646 (member constant-name multi-list))
15647 (progn (setq single-list (delete constant-name single-list))
15648 (add-to-list 'multi-list constant-name))
15649 (add-to-list 'single-list constant-name))
15650 (unless (match-string 1)
15651 (setq generic-alist (cdr generic-alist)))
15652 (vhdl-forward-syntactic-ws))
15653 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15654 ;; process all signals in port map
15655 (vhdl-forward-syntactic-ws)
15656 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15657 (setq signal-name (match-string-no-properties 3))
15658 (setq signal-entry (cons signal-name
15659 (if (match-string 1)
15660 (or (aget port-alist (match-string 2) t)
15661 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15662 (cdar port-alist))))
15663 (setq signal-alist (cons signal-entry signal-alist))
15664 (setq signal-name (downcase signal-name))
15665 (if (equal (upcase (nth 2 signal-entry)) "IN")
15666 ;; input signal
15667 (cond
15668 ((member signal-name local-list)
15669 nil)
15670 ((or (member signal-name single-out-list)
15671 (member signal-name multi-out-list))
15672 (setq single-out-list (delete signal-name single-out-list))
15673 (setq multi-out-list (delete signal-name multi-out-list))
15674 (add-to-list 'local-list signal-name))
15675 ((member signal-name single-in-list)
15676 (setq single-in-list (delete signal-name single-in-list))
15677 (add-to-list 'multi-in-list signal-name))
15678 ((not (member signal-name multi-in-list))
15679 (add-to-list 'single-in-list signal-name)))
15680 ;; output signal
15681 (cond
15682 ((member signal-name local-list)
15683 nil)
15684 ((or (member signal-name single-in-list)
15685 (member signal-name multi-in-list))
15686 (setq single-in-list (delete signal-name single-in-list))
15687 (setq multi-in-list (delete signal-name multi-in-list))
15688 (add-to-list 'local-list signal-name))
15689 ((member signal-name single-out-list)
15690 (setq single-out-list (delete signal-name single-out-list))
15691 (add-to-list 'multi-out-list signal-name))
15692 ((not (member signal-name multi-out-list))
15693 (add-to-list 'single-out-list signal-name))))
15694 (unless (match-string 1)
15695 (setq port-alist (cdr port-alist)))
15696 (vhdl-forward-syntactic-ws))
15697 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15698 (nreverse signal-alist)) inst-alist)))
15699 ;; prepare signal insertion
15700 (vhdl-goto-marker arch-decl-pos)
15701 (forward-line 1)
15702 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15703 (setq signal-pos (point-marker))
15704 (while (progn (vhdl-forward-syntactic-ws)
15705 (looking-at "signal\\>"))
15706 (beginning-of-line 2)
15707 (delete-region signal-pos (point)))
15708 (setq signal-beg-pos signal-pos)
15709 ;; open entity file
15710 (when (file-exists-p ent-file-name)
15711 (find-file ent-file-name))
15712 (goto-char (point-min))
15713 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15714 (error "ERROR: Entity not found: \"%s\"" ent-name))
15715 ;; prepare generic clause insertion
15716 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15717 (match-string 1))
15718 (goto-char (match-beginning 0))
15719 (indent-to vhdl-basic-offset)
15720 (insert "generic ();\n\n")
15721 (backward-char 4))
15722 (backward-char)
15723 (setq generic-pos (point-marker))
15724 (forward-sexp) (end-of-line)
15725 (delete-region generic-pos (point)) (delete-char 1)
15726 (insert "(\n")
15727 (when multi-list
15728 (insert "\n")
15729 (indent-to (* 2 vhdl-basic-offset))
15730 (insert "-- global generics\n"))
15731 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15732 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15733 ;; prepare port clause insertion
15734 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15735 (match-string 1))
15736 (goto-char (match-beginning 0))
15737 (indent-to vhdl-basic-offset)
15738 (insert "port ();\n\n")
15739 (backward-char 4))
15740 (backward-char)
15741 (setq port-in-pos (point-marker))
15742 (forward-sexp) (end-of-line)
15743 (delete-region port-in-pos (point)) (delete-char 1)
15744 (insert "(\n")
15745 (when (or multi-in-list multi-out-list)
15746 (insert "\n")
15747 (indent-to (* 2 vhdl-basic-offset))
15748 (insert "-- global ports\n"))
15749 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15750 port-out-pos (point-marker) port-inst-pos (point-marker)
15751 port-end-pos (point-marker))
15752 ;; insert generics, ports and signals
15753 (setq inst-alist (nreverse inst-alist))
15754 (while inst-alist
15755 (setq inst-name (nth 0 (car inst-alist))
15756 constant-alist (nth 1 (car inst-alist))
15757 signal-alist (nth 2 (car inst-alist))
15758 constant-temp-pos generic-inst-pos
15759 port-temp-pos port-inst-pos
15760 signal-temp-pos signal-pos)
15761 ;; generics
15762 (while constant-alist
15763 (setq constant-name (downcase (caar constant-alist))
15764 constant-entry (car constant-alist))
15765 (cond ((member constant-name written-list)
15766 nil)
15767 ((member constant-name multi-list)
15768 (vhdl-goto-marker generic-pos)
15769 (setq generic-end-pos
15770 (vhdl-max-marker
15771 generic-end-pos
15772 (vhdl-compose-insert-generic constant-entry)))
15773 (setq generic-pos (point-marker))
15774 (add-to-list 'written-list constant-name))
15775 (t
15776 (vhdl-goto-marker
15777 (vhdl-max-marker generic-inst-pos generic-pos))
15778 (setq generic-end-pos
15779 (vhdl-compose-insert-generic constant-entry))
15780 (setq generic-inst-pos (point-marker))
15781 (add-to-list 'written-list constant-name)))
15782 (setq constant-alist (cdr constant-alist)))
15783 (when (/= constant-temp-pos generic-inst-pos)
15784 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15785 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15786 (insert "-- generics for \"" inst-name "\"\n")
15787 (vhdl-goto-marker generic-inst-pos))
15788 ;; ports and signals
15789 (while signal-alist
15790 (setq signal-name (downcase (caar signal-alist))
15791 signal-entry (car signal-alist))
15792 (cond ((member signal-name written-list)
15793 nil)
15794 ((member signal-name multi-in-list)
15795 (vhdl-goto-marker port-in-pos)
15796 (setq port-end-pos
15797 (vhdl-max-marker
15798 port-end-pos (vhdl-compose-insert-port signal-entry)))
15799 (setq port-in-pos (point-marker))
15800 (add-to-list 'written-list signal-name))
15801 ((member signal-name multi-out-list)
15802 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15803 (setq port-end-pos
15804 (vhdl-max-marker
15805 port-end-pos (vhdl-compose-insert-port signal-entry)))
15806 (setq port-out-pos (point-marker))
15807 (add-to-list 'written-list signal-name))
15808 ((or (member signal-name single-in-list)
15809 (member signal-name single-out-list))
15810 (vhdl-goto-marker
15811 (vhdl-max-marker
15812 port-inst-pos
15813 (vhdl-max-marker port-out-pos port-in-pos)))
15814 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15815 (setq port-inst-pos (point-marker))
15816 (add-to-list 'written-list signal-name))
15817 ((equal (upcase (nth 2 signal-entry)) "OUT")
15818 (vhdl-goto-marker signal-pos)
15819 (vhdl-compose-insert-signal signal-entry)
15820 (setq signal-pos (point-marker))
15821 (add-to-list 'written-list signal-name)))
15822 (setq signal-alist (cdr signal-alist)))
15823 (when (/= port-temp-pos port-inst-pos)
15824 (vhdl-goto-marker
15825 (vhdl-max-marker port-temp-pos
15826 (vhdl-max-marker port-in-pos port-out-pos)))
15827 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15828 (insert "-- ports to \"" inst-name "\"\n")
15829 (vhdl-goto-marker port-inst-pos))
15830 (when (/= signal-temp-pos signal-pos)
15831 (vhdl-goto-marker signal-temp-pos)
15832 (insert "\n") (indent-to vhdl-basic-offset)
15833 (insert "-- outputs of \"" inst-name "\"\n")
15834 (vhdl-goto-marker signal-pos))
15835 (setq inst-alist (cdr inst-alist)))
15836 ;; finalize generic/port clause
15837 (vhdl-goto-marker generic-end-pos) (backward-char)
15838 (when (= generic-beg-pos generic-end-pos)
15839 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15840 (insert ";") (backward-char))
15841 (insert ")")
15842 (vhdl-goto-marker port-end-pos) (backward-char)
15843 (when (= port-beg-pos port-end-pos)
15844 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15845 (insert ";") (backward-char))
15846 (insert ")")
15847 ;; align everything
15848 (when vhdl-auto-align
15849 (vhdl-goto-marker generic-beg-pos)
15850 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15851 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15852 (vhdl-goto-marker signal-beg-pos)
15853 (vhdl-align-region-groups signal-beg-pos signal-pos))
15854 (switch-to-buffer (marker-buffer signal-beg-pos))
15855 (message "Wiring components...done")))))
15856
15857 (defun vhdl-compose-insert-generic (entry)
15858 "Insert ENTRY as generic declaration."
15859 (let (pos)
15860 (indent-to (* 2 vhdl-basic-offset))
15861 (insert (nth 0 entry) " : " (nth 1 entry))
15862 (when (nth 2 entry)
15863 (insert " := " (nth 2 entry)))
15864 (insert ";")
15865 (setq pos (point-marker))
15866 (when (and vhdl-include-port-comments (nth 3 entry))
15867 (vhdl-comment-insert-inline (nth 3 entry) t))
15868 (insert "\n")
15869 pos))
15870
15871 (defun vhdl-compose-insert-port (entry)
15872 "Insert ENTRY as port declaration."
15873 (let (pos)
15874 (indent-to (* 2 vhdl-basic-offset))
15875 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15876 (setq pos (point-marker))
15877 (when (and vhdl-include-port-comments (nth 4 entry))
15878 (vhdl-comment-insert-inline (nth 4 entry) t))
15879 (insert "\n")
15880 pos))
15881
15882 (defun vhdl-compose-insert-signal (entry)
15883 "Insert ENTRY as signal declaration."
15884 (indent-to vhdl-basic-offset)
15885 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15886 (when (and vhdl-include-port-comments (nth 4 entry))
15887 (vhdl-comment-insert-inline (nth 4 entry) t))
15888 (insert "\n"))
15889
15890 (defun vhdl-compose-components-package ()
15891 "Generate a package containing component declarations for all entities in the
15892 current project/directory."
15893 (interactive)
15894 (vhdl-require-hierarchy-info)
15895 (let* ((project (vhdl-project-p))
15896 (pack-name (vhdl-get-components-package-name))
15897 (pack-file-name
15898 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15899 "." (file-name-extension (buffer-file-name))))
15900 (ent-alist (aget vhdl-entity-alist
15901 (or project default-directory) t))
15902 (lazy-lock-minimum-size 0)
15903 clause-pos component-pos)
15904 (message "Generating components package \"%s\"..." pack-name)
15905 ;; open package file
15906 (when (and (file-exists-p pack-file-name)
15907 (not (y-or-n-p (concat "File \"" pack-file-name
15908 "\" exists; overwrite? "))))
15909 (error "ERROR: Generating components package...aborted"))
15910 (find-file pack-file-name)
15911 (erase-buffer)
15912 ;; insert header
15913 (if vhdl-compose-include-header
15914 (progn (vhdl-template-header
15915 (concat "Components package (generated by Emacs VHDL Mode "
15916 vhdl-version ")"))
15917 (goto-char (point-max)))
15918 (vhdl-comment-display-line) (insert "\n\n"))
15919 ;; insert std_logic_1164 package
15920 (vhdl-template-package-std-logic-1164)
15921 (insert "\n") (setq clause-pos (point-marker))
15922 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15923 ;; insert package declaration
15924 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15925 (vhdl-insert-keyword " IS\n\n")
15926 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15927 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15928 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15929 (indent-to vhdl-basic-offset)
15930 (setq component-pos (point-marker))
15931 (insert "\n\n") (vhdl-insert-keyword "END ")
15932 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15933 (insert pack-name ";\n\n")
15934 ;; insert footer
15935 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15936 (vhdl-template-footer)
15937 (vhdl-comment-display-line) (insert "\n"))
15938 ;; insert component declarations
15939 (while ent-alist
15940 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15941 (progn (goto-line (nth 3 (car ent-alist)))
15942 (end-of-line)
15943 (vhdl-port-copy)))
15944 (goto-char component-pos)
15945 (vhdl-port-paste-component t)
15946 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15947 (setq component-pos (point-marker))
15948 (goto-char clause-pos)
15949 (vhdl-port-paste-context-clause pack-name)
15950 (setq clause-pos (point-marker))
15951 (setq ent-alist (cdr ent-alist)))
15952 (goto-char (point-min))
15953 (save-buffer)
15954 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15955 pack-name pack-file-name)))
15956
15957 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15958 &optional insert-conf)
15959 "Generate block configuration for architecture."
15960 (let ((margin (current-indentation))
15961 (beg (save-excursion (beginning-of-line) (point)))
15962 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15963 ;; insert block configuration (for architecture)
15964 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15965 (setq margin (+ margin vhdl-basic-offset))
15966 ;; process all instances
15967 (while inst-alist
15968 (setq inst-entry (car inst-alist))
15969 ;; is component?
15970 (when (nth 4 inst-entry)
15971 (setq insert-conf t)
15972 (setq inst-path (nth 9 inst-entry))
15973 ;; skip common path with previous instance
15974 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15975 (setq inst-path (cdr inst-path)
15976 inst-prev-path (cdr inst-prev-path)))
15977 ;; insert block configuration end (for previous block/generate)
15978 (while inst-prev-path
15979 (setq margin (- margin vhdl-basic-offset))
15980 (indent-to margin)
15981 (vhdl-insert-keyword "END FOR;\n")
15982 (setq inst-prev-path (cdr inst-prev-path)))
15983 ;; insert block configuration beginning (for current block/generate)
15984 (indent-to margin)
15985 (while inst-path
15986 (setq margin (+ margin vhdl-basic-offset))
15987 (vhdl-insert-keyword "FOR ")
15988 (insert (car inst-path) "\n")
15989 (indent-to margin)
15990 (setq inst-path (cdr inst-path)))
15991 ;; insert component configuration beginning
15992 (vhdl-insert-keyword "FOR ")
15993 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15994 ;; find subconfiguration
15995 (setq conf-key (nth 7 inst-entry))
15996 (setq tmp-alist conf-alist)
15997 ;; use first configuration found for instance's entity
15998 (while (and tmp-alist (null conf-key))
15999 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16000 (setq conf-key (nth 0 (car tmp-alist))))
16001 (setq tmp-alist (cdr tmp-alist)))
16002 (setq conf-entry (aget conf-alist conf-key t))
16003 ;; insert binding indication ...
16004 ;; ... with subconfiguration (if exists)
16005 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16006 (progn
16007 (indent-to (+ margin vhdl-basic-offset))
16008 (vhdl-insert-keyword "USE CONFIGURATION ")
16009 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16010 (insert ";\n"))
16011 ;; ... with entity (if exists)
16012 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16013 (when ent-entry
16014 (indent-to (+ margin vhdl-basic-offset))
16015 (vhdl-insert-keyword "USE ENTITY ")
16016 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16017 ;; insert architecture name (if architecture exists)
16018 (when (nth 3 ent-entry)
16019 (setq arch-name
16020 ;; choose architecture name a) from configuration,
16021 ;; b) from mra, or c) from first architecture
16022 (or (nth 0 (aget (nth 3 ent-entry)
16023 (or (nth 6 inst-entry)
16024 (nth 4 ent-entry)) t))
16025 (nth 1 (car (nth 3 ent-entry)))))
16026 (insert "(" arch-name ")"))
16027 (insert ";\n")
16028 ;; insert block configuration (for architecture of subcomponent)
16029 (when (and vhdl-compose-configuration-hierarchical
16030 (nth 3 ent-entry))
16031 (indent-to (+ margin vhdl-basic-offset))
16032 (vhdl-compose-configuration-architecture
16033 (nth 0 ent-entry) arch-name
16034 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16035 ;; insert component configuration end
16036 (indent-to margin)
16037 (vhdl-insert-keyword "END FOR;\n")
16038 (setq inst-prev-path (nth 9 inst-entry)))
16039 (setq inst-alist (cdr inst-alist)))
16040 ;; insert block configuration end (for block/generate)
16041 (while inst-prev-path
16042 (setq margin (- margin vhdl-basic-offset))
16043 (indent-to margin)
16044 (vhdl-insert-keyword "END FOR;\n")
16045 (setq inst-prev-path (cdr inst-prev-path)))
16046 (indent-to (- margin vhdl-basic-offset))
16047 ;; insert block configuration end or remove beginning (for architecture)
16048 (if insert-conf
16049 (vhdl-insert-keyword "END FOR;\n")
16050 (delete-region beg (point)))))
16051
16052 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16053 "Generate configuration declaration."
16054 (interactive)
16055 (vhdl-require-hierarchy-info)
16056 (let ((ent-alist (aget vhdl-entity-alist
16057 (or (vhdl-project-p) default-directory) t))
16058 (conf-alist (aget vhdl-config-alist
16059 (or (vhdl-project-p) default-directory) t))
16060 (from-speedbar ent-name)
16061 inst-alist conf-name conf-file-name pos)
16062 (vhdl-prepare-search-2
16063 ;; get entity and architecture name
16064 (unless ent-name
16065 (save-excursion
16066 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16067 (not (equal "END" (upcase (match-string 1))))
16068 (setq ent-name (match-string-no-properties 3))
16069 (setq arch-name (match-string-no-properties 2)))
16070 (error "ERROR: Not within an architecture"))))
16071 (setq conf-name (vhdl-replace-string
16072 vhdl-compose-configuration-name
16073 (concat ent-name " " arch-name)))
16074 (setq inst-alist
16075 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16076 (downcase arch-name) t))))
16077 (message "Generating configuration \"%s\"..." conf-name)
16078 (if vhdl-compose-configuration-create-file
16079 ;; open configuration file
16080 (progn
16081 (setq conf-file-name
16082 (concat (vhdl-replace-string vhdl-configuration-file-name
16083 conf-name t)
16084 "." (file-name-extension (buffer-file-name))))
16085 (when (and (file-exists-p conf-file-name)
16086 (not (y-or-n-p (concat "File \"" conf-file-name
16087 "\" exists; overwrite? "))))
16088 (error "ERROR: Creating configuration...aborted"))
16089 (find-file conf-file-name)
16090 (erase-buffer)
16091 (set-buffer-modified-p nil)
16092 ;; insert header
16093 (if vhdl-compose-include-header
16094 (progn (vhdl-template-header
16095 (concat "Configuration declaration for design \""
16096 ent-name "(" arch-name ")\""))
16097 (goto-char (point-max)))
16098 (vhdl-comment-display-line) (insert "\n\n")))
16099 ;; goto end of architecture
16100 (unless from-speedbar
16101 (re-search-forward "^end\\>" nil)
16102 (end-of-line) (insert "\n\n")
16103 (vhdl-comment-display-line) (insert "\n\n")))
16104 ;; insert library clause
16105 (setq pos (point))
16106 (vhdl-template-standard-package (vhdl-work-library) nil)
16107 (when (/= pos (point))
16108 (insert "\n\n"))
16109 ;; insert configuration
16110 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16111 (vhdl-insert-keyword " OF ") (insert ent-name)
16112 (vhdl-insert-keyword " IS\n")
16113 (indent-to vhdl-basic-offset)
16114 ;; insert block configuration (for architecture)
16115 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16116 (vhdl-insert-keyword "END ") (insert conf-name ";")
16117 (when conf-file-name
16118 ;; insert footer and save
16119 (insert "\n\n")
16120 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16121 (vhdl-template-footer)
16122 (vhdl-comment-display-line) (insert "\n"))
16123 (save-buffer))
16124 (message "%s"
16125 (concat (format "Generating configuration \"%s\"...done" conf-name)
16126 (and conf-file-name
16127 (format "\n File created: \"%s\"" conf-file-name))))))
16128
16129
16130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16131 ;;; Compilation / Makefile generation
16132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16133 ;; (using `compile.el')
16134
16135 (defun vhdl-makefile-name ()
16136 "Return the Makefile name of the current project or the current compiler if
16137 no project is defined."
16138 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16139 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16140 (vhdl-replace-string
16141 (cons "\\(.*\\)\n\\(.*\\)"
16142 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16143 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16144
16145 (defun vhdl-compile-directory ()
16146 "Return the directory where compilation/make should be run."
16147 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16148 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16149 (directory (vhdl-resolve-env-variable
16150 (if project
16151 (vhdl-replace-string
16152 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16153 (nth 6 compiler)))))
16154 (file-name-as-directory
16155 (if (file-name-absolute-p directory)
16156 directory
16157 (expand-file-name directory (vhdl-default-directory))))))
16158
16159 (defun vhdl-uniquify (in-list)
16160 "Remove duplicate elements from IN-LIST."
16161 (let (out-list)
16162 (while in-list
16163 (add-to-list 'out-list (car in-list))
16164 (setq in-list (cdr in-list)))
16165 out-list))
16166
16167 (defun vhdl-set-compiler (name)
16168 "Set current compiler to NAME."
16169 (interactive
16170 (list (let ((completion-ignore-case t))
16171 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16172 (if (assoc name vhdl-compiler-alist)
16173 (progn (setq vhdl-compiler name)
16174 (message "Current compiler: \"%s\"" vhdl-compiler))
16175 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16176
16177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16178 ;; Compilation
16179
16180 (defun vhdl-compile-init ()
16181 "Initialize for compilation."
16182 (when (or (null compilation-error-regexp-alist)
16183 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16184 compilation-error-regexp-alist)))
16185 ;; `compilation-error-regexp-alist'
16186 (let ((commands-alist vhdl-compiler-alist)
16187 regexp-alist sublist)
16188 (while commands-alist
16189 (setq sublist (nth 11 (car commands-alist)))
16190 (unless (or (equal "" (car sublist))
16191 (assoc (car sublist) regexp-alist))
16192 (setq regexp-alist (cons (list (nth 0 sublist)
16193 (if (= 0 (nth 1 sublist))
16194 (if (featurep 'xemacs) 9 nil)
16195 (nth 1 sublist))
16196 (nth 2 sublist) (nth 3 sublist))
16197 regexp-alist)))
16198 (setq commands-alist (cdr commands-alist)))
16199 (setq compilation-error-regexp-alist
16200 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16201 ;; `compilation-file-regexp-alist'
16202 (let ((commands-alist vhdl-compiler-alist)
16203 regexp-alist sublist)
16204 ;; matches vhdl-mode file name output
16205 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16206 (while commands-alist
16207 (setq sublist (nth 12 (car commands-alist)))
16208 (unless (or (equal "" (car sublist))
16209 (assoc (car sublist) regexp-alist))
16210 (setq regexp-alist (cons sublist regexp-alist)))
16211 (setq commands-alist (cdr commands-alist)))
16212 (setq compilation-file-regexp-alist
16213 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16214
16215 (defvar vhdl-compile-file-name nil
16216 "Name of file to be compiled.")
16217
16218 (defun vhdl-compile-print-file-name ()
16219 "Function called within `compile' to print out file name for compilers that
16220 do not print any file names."
16221 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16222
16223 (defun vhdl-get-compile-options (project compiler file-name
16224 &optional file-options-only)
16225 "Get compiler options. Returning nil means do not compile this file."
16226 (let* ((compiler-options (nth 1 compiler))
16227 (project-entry (aget (nth 4 project) vhdl-compiler))
16228 (project-options (nth 0 project-entry))
16229 (exception-list (and file-name (nth 2 project-entry)))
16230 (work-library (vhdl-work-library))
16231 (case-fold-search nil)
16232 file-options)
16233 (while (and exception-list
16234 (not (string-match (caar exception-list) file-name)))
16235 (setq exception-list (cdr exception-list)))
16236 (if (and exception-list (not (cdar exception-list)))
16237 nil
16238 (if (and file-options-only (not exception-list))
16239 'default
16240 (setq file-options (cdar exception-list))
16241 ;; insert library name in compiler-specific options
16242 (setq compiler-options
16243 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16244 work-library))
16245 ;; insert compiler-specific options in project-specific options
16246 (when project-options
16247 (setq project-options
16248 (vhdl-replace-string
16249 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16250 (concat work-library "\n" compiler-options))))
16251 ;; insert project-specific options in file-specific options
16252 (when file-options
16253 (setq file-options
16254 (vhdl-replace-string
16255 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16256 (concat work-library "\n" compiler-options "\n"
16257 project-options))))
16258 ;; return options
16259 (or file-options project-options compiler-options)))))
16260
16261 (defun vhdl-get-make-options (project compiler)
16262 "Get make options."
16263 (let* ((compiler-options (nth 3 compiler))
16264 (project-entry (aget (nth 4 project) vhdl-compiler))
16265 (project-options (nth 1 project-entry))
16266 (makefile-name (vhdl-makefile-name)))
16267 ;; insert Makefile name in compiler-specific options
16268 (setq compiler-options
16269 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16270 makefile-name))
16271 ;; insert compiler-specific options in project-specific options
16272 (when project-options
16273 (setq project-options
16274 (vhdl-replace-string
16275 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16276 (concat makefile-name "\n" compiler-options))))
16277 ;; return options
16278 (or project-options compiler-options)))
16279
16280 (defun vhdl-compile ()
16281 "Compile current buffer using the VHDL compiler specified in
16282 `vhdl-compiler'."
16283 (interactive)
16284 (vhdl-compile-init)
16285 (let* ((project (aget vhdl-project-alist vhdl-project))
16286 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16287 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16288 (command (nth 0 compiler))
16289 (file-name (buffer-file-name))
16290 (options (vhdl-get-compile-options project compiler file-name))
16291 (default-directory (vhdl-compile-directory))
16292 compilation-process-setup-function)
16293 (unless (file-directory-p default-directory)
16294 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16295 ;; put file name into quotes if it contains spaces
16296 (when (string-match " " file-name)
16297 (setq file-name (concat "\"" file-name "\"")))
16298 ;; print out file name if compiler does not
16299 (setq vhdl-compile-file-name (buffer-file-name))
16300 (when (and (= 0 (nth 1 (nth 10 compiler)))
16301 (= 0 (nth 1 (nth 11 compiler))))
16302 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16303 ;; run compilation
16304 (if options
16305 (when command
16306 (compile (concat command " " options " " file-name)))
16307 (vhdl-warning "Your project settings tell me not to compile this file"))))
16308
16309 (defvar vhdl-make-target "all"
16310 "Default target for `vhdl-make' command.")
16311
16312 (defun vhdl-make (&optional target)
16313 "Call make command for compilation of all updated source files (requires
16314 `Makefile'). Optional argument TARGET allows to compile the design
16315 specified by a target."
16316 (interactive)
16317 (setq vhdl-make-target
16318 (or target (read-from-minibuffer "Target: " vhdl-make-target
16319 vhdl-minibuffer-local-map)))
16320 (vhdl-compile-init)
16321 (let* ((project (aget vhdl-project-alist vhdl-project))
16322 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16323 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16324 (command (nth 2 compiler))
16325 (options (vhdl-get-make-options project compiler))
16326 (default-directory (vhdl-compile-directory)))
16327 (unless (file-directory-p default-directory)
16328 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16329 ;; run make
16330 (compile (concat (if (equal command "") "make" command)
16331 " " options " " vhdl-make-target))))
16332
16333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16334 ;; Makefile generation
16335
16336 (defun vhdl-generate-makefile ()
16337 "Generate `Makefile'."
16338 (interactive)
16339 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16340 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16341 (command (nth 4 compiler)))
16342 ;; generate makefile
16343 (if command
16344 (let ((default-directory (vhdl-compile-directory)))
16345 (compile (vhdl-replace-string
16346 (cons "\\(.*\\) \\(.*\\)" command)
16347 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16348 (vhdl-generate-makefile-1))))
16349
16350 (defun vhdl-get-packages (lib-alist work-library)
16351 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16352 (let (pack-list)
16353 (while lib-alist
16354 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16355 (setq pack-list (cons (cdar lib-alist) pack-list)))
16356 (setq lib-alist (cdr lib-alist)))
16357 pack-list))
16358
16359 (defun vhdl-generate-makefile-1 ()
16360 "Generate Makefile for current project or directory."
16361 ;; scan hierarchy if required
16362 (if (vhdl-project-p)
16363 (unless (or (assoc vhdl-project vhdl-file-alist)
16364 (vhdl-load-cache vhdl-project))
16365 (vhdl-scan-project-contents vhdl-project))
16366 (let ((directory (abbreviate-file-name default-directory)))
16367 (unless (or (assoc directory vhdl-file-alist)
16368 (vhdl-load-cache directory))
16369 (vhdl-scan-directory-contents directory))))
16370 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16371 (project (vhdl-project-p))
16372 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16373 (conf-alist (aget vhdl-config-alist (or project directory) t))
16374 (pack-alist (aget vhdl-package-alist (or project directory) t))
16375 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16376 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16377 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16378 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16379 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16380 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16381 (adjust-case (nth 5 regexp-list))
16382 (work-library (downcase (vhdl-work-library)))
16383 (compile-directory (expand-file-name (vhdl-compile-directory)
16384 default-directory))
16385 (makefile-name (vhdl-makefile-name))
16386 rule-alist arch-alist inst-alist
16387 target-list depend-list unit-list prim-list second-list subcomp-list
16388 lib-alist lib-body-alist pack-list all-pack-list
16389 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16390 conf-key conf-file-name pack-key pack-file-name
16391 ent-entry arch-entry conf-entry pack-entry inst-entry
16392 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16393 tmp-key tmp-list rule)
16394 ;; check prerequisites
16395 (unless (file-exists-p compile-directory)
16396 (make-directory compile-directory t))
16397 (unless regexp-list
16398 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16399 vhdl-compiler))
16400 (message "Generating makefile \"%s\"..." makefile-name)
16401 ;; rules for all entities
16402 (setq tmp-list ent-alist)
16403 (while ent-alist
16404 (setq ent-entry (car ent-alist)
16405 ent-key (nth 0 ent-entry))
16406 (when (nth 2 ent-entry)
16407 (setq ent-file-name (file-relative-name
16408 (nth 2 ent-entry) compile-directory)
16409 arch-alist (nth 4 ent-entry)
16410 lib-alist (nth 6 ent-entry)
16411 rule (aget rule-alist ent-file-name)
16412 target-list (nth 0 rule)
16413 depend-list (nth 1 rule)
16414 second-list nil
16415 subcomp-list nil)
16416 (setq tmp-key (vhdl-replace-string
16417 ent-regexp (funcall adjust-case ent-key)))
16418 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16419 ;; rule target for this entity
16420 (setq target-list (cons ent-key target-list))
16421 ;; rule dependencies for all used packages
16422 (setq pack-list (vhdl-get-packages lib-alist work-library))
16423 (setq depend-list (append depend-list pack-list))
16424 (setq all-pack-list pack-list)
16425 ;; add rule
16426 (aput 'rule-alist ent-file-name (list target-list depend-list))
16427 ;; rules for all corresponding architectures
16428 (while arch-alist
16429 (setq arch-entry (car arch-alist)
16430 arch-key (nth 0 arch-entry)
16431 ent-arch-key (concat ent-key "-" arch-key)
16432 arch-file-name (file-relative-name (nth 2 arch-entry)
16433 compile-directory)
16434 inst-alist (nth 4 arch-entry)
16435 lib-alist (nth 5 arch-entry)
16436 rule (aget rule-alist arch-file-name)
16437 target-list (nth 0 rule)
16438 depend-list (nth 1 rule))
16439 (setq tmp-key (vhdl-replace-string
16440 arch-regexp
16441 (funcall adjust-case (concat arch-key " " ent-key))))
16442 (setq unit-list
16443 (cons (cons ent-arch-key tmp-key) unit-list))
16444 (setq second-list (cons ent-arch-key second-list))
16445 ;; rule target for this architecture
16446 (setq target-list (cons ent-arch-key target-list))
16447 ;; rule dependency for corresponding entity
16448 (setq depend-list (cons ent-key depend-list))
16449 ;; rule dependencies for contained component instantiations
16450 (while inst-alist
16451 (setq inst-entry (car inst-alist))
16452 (when (or (null (nth 8 inst-entry))
16453 (equal (downcase (nth 8 inst-entry)) work-library))
16454 (setq inst-ent-key (or (nth 7 inst-entry)
16455 (nth 5 inst-entry)))
16456 (setq depend-list (cons inst-ent-key depend-list)
16457 subcomp-list (cons inst-ent-key subcomp-list)))
16458 (setq inst-alist (cdr inst-alist)))
16459 ;; rule dependencies for all used packages
16460 (setq pack-list (vhdl-get-packages lib-alist work-library))
16461 (setq depend-list (append depend-list pack-list))
16462 (setq all-pack-list (append all-pack-list pack-list))
16463 ;; add rule
16464 (aput 'rule-alist arch-file-name (list target-list depend-list))
16465 (setq arch-alist (cdr arch-alist)))
16466 (setq prim-list (cons (list ent-key second-list
16467 (append subcomp-list all-pack-list))
16468 prim-list)))
16469 (setq ent-alist (cdr ent-alist)))
16470 (setq ent-alist tmp-list)
16471 ;; rules for all configurations
16472 (setq tmp-list conf-alist)
16473 (while conf-alist
16474 (setq conf-entry (car conf-alist)
16475 conf-key (nth 0 conf-entry)
16476 conf-file-name (file-relative-name
16477 (nth 2 conf-entry) compile-directory)
16478 ent-key (nth 4 conf-entry)
16479 arch-key (nth 5 conf-entry)
16480 inst-alist (nth 6 conf-entry)
16481 lib-alist (nth 7 conf-entry)
16482 rule (aget rule-alist conf-file-name)
16483 target-list (nth 0 rule)
16484 depend-list (nth 1 rule)
16485 subcomp-list (list ent-key))
16486 (setq tmp-key (vhdl-replace-string
16487 conf-regexp (funcall adjust-case conf-key)))
16488 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16489 ;; rule target for this configuration
16490 (setq target-list (cons conf-key target-list))
16491 ;; rule dependency for corresponding entity and architecture
16492 (setq depend-list
16493 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16494 ;; rule dependencies for used packages
16495 (setq pack-list (vhdl-get-packages lib-alist work-library))
16496 (setq depend-list (append depend-list pack-list))
16497 ;; rule dependencies for contained component configurations
16498 (while inst-alist
16499 (setq inst-entry (car inst-alist))
16500 (setq inst-ent-key (nth 2 inst-entry)
16501 ; comp-arch-key (nth 2 inst-entry))
16502 inst-conf-key (nth 4 inst-entry))
16503 (when (equal (downcase (nth 5 inst-entry)) work-library)
16504 (when inst-ent-key
16505 (setq depend-list (cons inst-ent-key depend-list)
16506 subcomp-list (cons inst-ent-key subcomp-list)))
16507 ; (when comp-arch-key
16508 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16509 ; depend-list)))
16510 (when inst-conf-key
16511 (setq depend-list (cons inst-conf-key depend-list)
16512 subcomp-list (cons inst-conf-key subcomp-list))))
16513 (setq inst-alist (cdr inst-alist)))
16514 ;; add rule
16515 (aput 'rule-alist conf-file-name (list target-list depend-list))
16516 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16517 prim-list))
16518 (setq conf-alist (cdr conf-alist)))
16519 (setq conf-alist tmp-list)
16520 ;; rules for all packages
16521 (setq tmp-list pack-alist)
16522 (while pack-alist
16523 (setq pack-entry (car pack-alist)
16524 pack-key (nth 0 pack-entry)
16525 pack-body-key nil)
16526 (when (nth 2 pack-entry)
16527 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16528 compile-directory)
16529 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16530 rule (aget rule-alist pack-file-name)
16531 target-list (nth 0 rule) depend-list (nth 1 rule))
16532 (setq tmp-key (vhdl-replace-string
16533 pack-regexp (funcall adjust-case pack-key)))
16534 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16535 ;; rule target for this package
16536 (setq target-list (cons pack-key target-list))
16537 ;; rule dependencies for all used packages
16538 (setq pack-list (vhdl-get-packages lib-alist work-library))
16539 (setq depend-list (append depend-list pack-list))
16540 (setq all-pack-list pack-list)
16541 ;; add rule
16542 (aput 'rule-alist pack-file-name (list target-list depend-list))
16543 ;; rules for this package's body
16544 (when (nth 7 pack-entry)
16545 (setq pack-body-key (concat pack-key "-body")
16546 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16547 compile-directory)
16548 rule (aget rule-alist pack-body-file-name)
16549 target-list (nth 0 rule)
16550 depend-list (nth 1 rule))
16551 (setq tmp-key (vhdl-replace-string
16552 pack-body-regexp (funcall adjust-case pack-key)))
16553 (setq unit-list
16554 (cons (cons pack-body-key tmp-key) unit-list))
16555 ;; rule target for this package's body
16556 (setq target-list (cons pack-body-key target-list))
16557 ;; rule dependency for corresponding package declaration
16558 (setq depend-list (cons pack-key depend-list))
16559 ;; rule dependencies for all used packages
16560 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16561 (setq depend-list (append depend-list pack-list))
16562 (setq all-pack-list (append all-pack-list pack-list))
16563 ;; add rule
16564 (aput 'rule-alist pack-body-file-name
16565 (list target-list depend-list)))
16566 (setq prim-list
16567 (cons (list pack-key (when pack-body-key (list pack-body-key))
16568 all-pack-list)
16569 prim-list)))
16570 (setq pack-alist (cdr pack-alist)))
16571 (setq pack-alist tmp-list)
16572 ;; generate Makefile
16573 (let* ((project (aget vhdl-project-alist project))
16574 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16575 (compiler-id (nth 9 compiler))
16576 (library-directory
16577 (vhdl-resolve-env-variable
16578 (vhdl-replace-string
16579 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16580 compiler-id)))
16581 (makefile-path-name (expand-file-name
16582 makefile-name compile-directory))
16583 (orig-buffer (current-buffer))
16584 cell second-list subcomp-list options unit-key unit-name)
16585 ;; sort lists
16586 (setq unit-list (vhdl-sort-alist unit-list))
16587 (setq prim-list (vhdl-sort-alist prim-list))
16588 (setq tmp-list rule-alist)
16589 (while tmp-list ; pre-sort rule targets
16590 (setq cell (cdar tmp-list))
16591 (setcar cell (sort (car cell) 'string<))
16592 (setq tmp-list (cdr tmp-list)))
16593 (setq rule-alist ; sort by first rule target
16594 (sort rule-alist
16595 (function (lambda (a b)
16596 (string< (car (cadr a)) (car (cadr b)))))))
16597 ;; open and clear Makefile
16598 (set-buffer (find-file-noselect makefile-path-name t t))
16599 (erase-buffer)
16600 (insert "# -*- Makefile -*-\n"
16601 "### " (file-name-nondirectory makefile-name)
16602 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16603 "\n")
16604 (if project
16605 (insert "\n# Project : " (nth 0 project))
16606 (insert "\n# Directory : \"" directory "\""))
16607 (insert "\n# Platform : " vhdl-compiler
16608 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16609 (user-login-name) "\n")
16610 ;; insert compile and option variable settings
16611 (insert "\n\n# Define compilation command and options\n"
16612 "\nCOMPILE = " (nth 0 compiler)
16613 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16614 "\n")
16615 ;; insert library paths
16616 (setq library-directory
16617 (directory-file-name
16618 (if (file-name-absolute-p library-directory)
16619 library-directory
16620 (file-relative-name
16621 (expand-file-name library-directory directory)
16622 compile-directory))))
16623 (insert "\n\n# Define library paths\n"
16624 "\nLIBRARY-" work-library " = " library-directory "\n")
16625 ;; insert variable definitions for all library unit files
16626 (insert "\n\n# Define library unit files\n")
16627 (setq tmp-list unit-list)
16628 (while unit-list
16629 (insert "\nUNIT-" work-library "-" (caar unit-list)
16630 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16631 (setq unit-list (cdr unit-list)))
16632 ;; insert variable definition for list of all library unit files
16633 (insert "\n\n\n# Define list of all library unit files\n"
16634 "\nALL_UNITS =")
16635 (setq unit-list tmp-list)
16636 (while unit-list
16637 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16638 (setq unit-list (cdr unit-list)))
16639 (insert "\n")
16640 (setq unit-list tmp-list)
16641 ;; insert `make all' rule
16642 (insert "\n\n\n# Rule for compiling entire design\n"
16643 "\nall :"
16644 " \\\n\t\tlibrary"
16645 " \\\n\t\t$(ALL_UNITS)\n")
16646 ;; insert `make clean' rule
16647 (insert "\n\n# Rule for cleaning entire design\n"
16648 "\nclean : "
16649 "\n\t-rm -f $(ALL_UNITS)\n")
16650 ;; insert `make library' rule
16651 (insert "\n\n# Rule for creating library directory\n"
16652 "\nlibrary :"
16653 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16654 "\n$(LIBRARY-" work-library ") :"
16655 "\n\t"
16656 (vhdl-replace-string
16657 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16658 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16659 "\n")
16660 ;; insert rule for each library unit
16661 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16662 (while prim-list
16663 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16664 (setq subcomp-list
16665 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16666 (setq unit-key (caar prim-list)
16667 unit-name (or (nth 0 (aget ent-alist unit-key t))
16668 (nth 0 (aget conf-alist unit-key t))
16669 (nth 0 (aget pack-alist unit-key t))))
16670 (insert "\n" unit-key)
16671 (unless (equal unit-key unit-name)
16672 (insert " \\\n" unit-name))
16673 (insert " :"
16674 " \\\n\t\tlibrary"
16675 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16676 (while second-list
16677 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16678 (setq second-list (cdr second-list)))
16679 (while subcomp-list
16680 (when (and (assoc (car subcomp-list) unit-list)
16681 (not (equal unit-key (car subcomp-list))))
16682 (insert " \\\n\t\t" (car subcomp-list)))
16683 (setq subcomp-list (cdr subcomp-list)))
16684 (insert "\n")
16685 (setq prim-list (cdr prim-list)))
16686 ;; insert rule for each library unit file
16687 (insert "\n\n# Rules for compiling single library unit files\n")
16688 (while rule-alist
16689 (setq rule (car rule-alist))
16690 ;; get compiler options for this file
16691 (setq options
16692 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16693 ;; insert rule if file is supposed to be compiled
16694 (setq target-list (nth 1 rule)
16695 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16696 ;; insert targets
16697 (setq tmp-list target-list)
16698 (while target-list
16699 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16700 (if (cdr target-list) " \\" " :"))
16701 (setq target-list (cdr target-list)))
16702 (setq target-list tmp-list)
16703 ;; insert file name as first dependency
16704 (insert " \\\n\t\t" (nth 0 rule))
16705 ;; insert dependencies (except if also target or unit does not exist)
16706 (while depend-list
16707 (when (and (not (member (car depend-list) target-list))
16708 (assoc (car depend-list) unit-list))
16709 (insert " \\\n\t\t"
16710 "$(UNIT-" work-library "-" (car depend-list) ")"))
16711 (setq depend-list (cdr depend-list)))
16712 ;; insert compile command
16713 (if options
16714 (insert "\n\t$(COMPILE) "
16715 (if (eq options 'default) "$(OPTIONS)" options) " "
16716 (nth 0 rule) "\n")
16717 (setq tmp-list target-list)
16718 (while target-list
16719 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16720 (if (cdr target-list) " \\" "\n"))
16721 (setq target-list (cdr target-list)))
16722 (setq target-list tmp-list))
16723 (setq rule-alist (cdr rule-alist)))
16724 (insert "\n\n### " makefile-name " ends here\n")
16725 ;; run Makefile generation hook
16726 (run-hooks 'vhdl-makefile-generation-hook)
16727 (message "Generating makefile \"%s\"...done" makefile-name)
16728 ;; save and close file
16729 (if (file-writable-p makefile-path-name)
16730 (progn (save-buffer)
16731 (kill-buffer (current-buffer))
16732 (set-buffer orig-buffer)
16733 (add-to-history 'file-name-history makefile-path-name))
16734 (vhdl-warning-when-idle
16735 (format "File not writable: \"%s\""
16736 (abbreviate-file-name makefile-path-name)))
16737 (switch-to-buffer (current-buffer))))))
16738
16739
16740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16741 ;;; Bug reports
16742 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16743 ;; (using `reporter.el')
16744
16745 (defconst vhdl-mode-help-address
16746 "Reto Zimmermann <reto@gnu.org>"
16747 "Address for VHDL Mode bug reports.")
16748
16749 (defun vhdl-submit-bug-report ()
16750 "Submit via mail a bug report on VHDL Mode."
16751 (interactive)
16752 ;; load in reporter
16753 (and
16754 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16755 (let ((reporter-prompt-for-summary-p t))
16756 (reporter-submit-bug-report
16757 vhdl-mode-help-address
16758 (concat "VHDL Mode " vhdl-version)
16759 (list
16760 ;; report all important user options
16761 'vhdl-offsets-alist
16762 'vhdl-comment-only-line-offset
16763 'tab-width
16764 'vhdl-electric-mode
16765 'vhdl-stutter-mode
16766 'vhdl-indent-tabs-mode
16767 'vhdl-project-alist
16768 'vhdl-project
16769 'vhdl-project-file-name
16770 'vhdl-project-auto-load
16771 'vhdl-project-sort
16772 'vhdl-compiler-alist
16773 'vhdl-compiler
16774 'vhdl-compile-use-local-error-regexp
16775 'vhdl-makefile-generation-hook
16776 'vhdl-default-library
16777 'vhdl-standard
16778 'vhdl-basic-offset
16779 'vhdl-upper-case-keywords
16780 'vhdl-upper-case-types
16781 'vhdl-upper-case-attributes
16782 'vhdl-upper-case-enum-values
16783 'vhdl-upper-case-constants
16784 'vhdl-use-direct-instantiation
16785 'vhdl-compose-configuration-name
16786 'vhdl-entity-file-name
16787 'vhdl-architecture-file-name
16788 'vhdl-configuration-file-name
16789 'vhdl-package-file-name
16790 'vhdl-file-name-case
16791 'vhdl-electric-keywords
16792 'vhdl-optional-labels
16793 'vhdl-insert-empty-lines
16794 'vhdl-argument-list-indent
16795 'vhdl-association-list-with-formals
16796 'vhdl-conditions-in-parenthesis
16797 'vhdl-zero-string
16798 'vhdl-one-string
16799 'vhdl-file-header
16800 'vhdl-file-footer
16801 'vhdl-company-name
16802 'vhdl-copyright-string
16803 'vhdl-platform-spec
16804 'vhdl-date-format
16805 'vhdl-modify-date-prefix-string
16806 'vhdl-modify-date-on-saving
16807 'vhdl-reset-kind
16808 'vhdl-reset-active-high
16809 'vhdl-clock-rising-edge
16810 'vhdl-clock-edge-condition
16811 'vhdl-clock-name
16812 'vhdl-reset-name
16813 'vhdl-model-alist
16814 'vhdl-include-port-comments
16815 'vhdl-include-direction-comments
16816 'vhdl-include-type-comments
16817 'vhdl-include-group-comments
16818 'vhdl-actual-port-name
16819 'vhdl-instance-name
16820 'vhdl-testbench-entity-name
16821 'vhdl-testbench-architecture-name
16822 'vhdl-testbench-configuration-name
16823 'vhdl-testbench-dut-name
16824 'vhdl-testbench-include-header
16825 'vhdl-testbench-declarations
16826 'vhdl-testbench-statements
16827 'vhdl-testbench-initialize-signals
16828 'vhdl-testbench-include-library
16829 'vhdl-testbench-include-configuration
16830 'vhdl-testbench-create-files
16831 'vhdl-testbench-entity-file-name
16832 'vhdl-testbench-architecture-file-name
16833 'vhdl-compose-create-files
16834 'vhdl-compose-configuration-create-file
16835 'vhdl-compose-configuration-hierarchical
16836 'vhdl-compose-configuration-use-subconfiguration
16837 'vhdl-compose-include-header
16838 'vhdl-compose-architecture-name
16839 'vhdl-components-package-name
16840 'vhdl-use-components-package
16841 'vhdl-self-insert-comments
16842 'vhdl-prompt-for-comments
16843 'vhdl-inline-comment-column
16844 'vhdl-end-comment-column
16845 'vhdl-auto-align
16846 'vhdl-align-groups
16847 'vhdl-align-group-separate
16848 'vhdl-align-same-indent
16849 'vhdl-highlight-keywords
16850 'vhdl-highlight-names
16851 'vhdl-highlight-special-words
16852 'vhdl-highlight-forbidden-words
16853 'vhdl-highlight-verilog-keywords
16854 'vhdl-highlight-translate-off
16855 'vhdl-highlight-case-sensitive
16856 'vhdl-special-syntax-alist
16857 'vhdl-forbidden-words
16858 'vhdl-forbidden-syntax
16859 'vhdl-directive-keywords
16860 'vhdl-speedbar-auto-open
16861 'vhdl-speedbar-display-mode
16862 'vhdl-speedbar-scan-limit
16863 'vhdl-speedbar-jump-to-unit
16864 'vhdl-speedbar-update-on-saving
16865 'vhdl-speedbar-save-cache
16866 'vhdl-speedbar-cache-file-name
16867 'vhdl-index-menu
16868 'vhdl-source-file-menu
16869 'vhdl-hideshow-menu
16870 'vhdl-hide-all-init
16871 'vhdl-print-two-column
16872 'vhdl-print-customize-faces
16873 'vhdl-intelligent-tab
16874 'vhdl-indent-syntax-based
16875 'vhdl-word-completion-case-sensitive
16876 'vhdl-word-completion-in-minibuffer
16877 'vhdl-underscore-is-part-of-word
16878 'vhdl-mode-hook)
16879 (function
16880 (lambda ()
16881 (insert
16882 (if vhdl-special-indent-hook
16883 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16884 "vhdl-special-indent-hook is set to '"
16885 (format "%s" vhdl-special-indent-hook)
16886 ".\nPerhaps this is your problem?\n"
16887 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16888 "\n"))))
16889 nil
16890 "Hi Reto,"))))
16891
16892
16893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16894 ;;; Documentation
16895 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16896
16897 (defconst vhdl-doc-release-notes nil
16898 "\
16899 Release Notes for VHDL Mode 3.33
16900 ================================
16901
16902 - New Features
16903 - User Options
16904
16905
16906 New Features
16907 ------------
16908
16909 CONFIGURATION DECLARATION GENERATION:
16910 - Automatic generation of a configuration declaration for a design.
16911 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16912
16913
16914 User Options
16915 ------------
16916
16917 `vhdl-configuration-file-name': (new)
16918 Specify how the configuration file name is obtained.
16919 `vhdl-compose-configuration-name': (new)
16920 Specify how the configuration name is optained.
16921 `vhdl-compose-configuration-create-file': (new)
16922 Specify whether a new file should be created for a configuration.
16923 `vhdl-compose-configuration-hierarchical': (new)
16924 Specify whether hierarchical configurations should be created.
16925 `vhdl-compose-configuration-use-subconfiguration': (new)
16926 Specify whether subconfigurations should be used inside configurations.
16927 ")
16928
16929
16930 (defconst vhdl-doc-keywords nil
16931 "\
16932 Reserved words in VHDL
16933 ----------------------
16934
16935 VHDL'93 (IEEE Std 1076-1993):
16936 `vhdl-93-keywords' : keywords
16937 `vhdl-93-types' : standardized types
16938 `vhdl-93-attributes' : standardized attributes
16939 `vhdl-93-enum-values' : standardized enumeration values
16940 `vhdl-93-functions' : standardized functions
16941 `vhdl-93-packages' : standardized packages and libraries
16942
16943 VHDL-AMS (IEEE Std 1076.1):
16944 `vhdl-ams-keywords' : keywords
16945 `vhdl-ams-types' : standardized types
16946 `vhdl-ams-attributes' : standardized attributes
16947 `vhdl-ams-enum-values' : standardized enumeration values
16948 `vhdl-ams-functions' : standardized functions
16949
16950 Math Packages (IEEE Std 1076.2):
16951 `vhdl-math-types' : standardized types
16952 `vhdl-math-constants' : standardized constants
16953 `vhdl-math-functions' : standardized functions
16954 `vhdl-math-packages' : standardized packages
16955
16956 Forbidden words:
16957 `vhdl-verilog-keywords' : Verilog reserved words
16958
16959 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16960
16961
16962 (defconst vhdl-doc-coding-style nil
16963 "\
16964 For VHDL coding style and naming convention guidelines, see the following
16965 references:
16966
16967 \[1] Ben Cohen.
16968 \"VHDL Coding Styles and Methodologies\".
16969 Kluwer Academic Publishers, 1999.
16970 http://members.aol.com/vhdlcohen/vhdl/
16971
16972 \[2] Michael Keating and Pierre Bricaud.
16973 \"Reuse Methodology Manual, Second Edition\".
16974 Kluwer Academic Publishers, 1999.
16975 http://www.openmore.com/openmore/rmm2.html
16976
16977 \[3] European Space Agency.
16978 \"VHDL Modelling Guidelines\".
16979 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16980
16981 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16982 to visually support naming conventions.")
16983
16984
16985 (defun vhdl-version ()
16986 "Echo the current version of VHDL Mode in the minibuffer."
16987 (interactive)
16988 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16989 (vhdl-keep-region-active))
16990
16991 (defun vhdl-doc-variable (variable)
16992 "Display VARIABLE's documentation in *Help* buffer."
16993 (interactive)
16994 (unless (featurep 'xemacs)
16995 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16996 (with-output-to-temp-buffer
16997 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16998 (princ (documentation-property variable 'variable-documentation))
16999 (with-current-buffer standard-output
17000 (help-mode))
17001 (print-help-return-message)))
17002
17003 (defun vhdl-doc-mode ()
17004 "Display VHDL Mode documentation in *Help* buffer."
17005 (interactive)
17006 (unless (featurep 'xemacs)
17007 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17008 (with-output-to-temp-buffer
17009 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17010 (princ mode-name)
17011 (princ " mode:\n")
17012 (princ (documentation 'vhdl-mode))
17013 (with-current-buffer standard-output
17014 (help-mode))
17015 (print-help-return-message)))
17016
17017
17018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17019
17020 (provide 'vhdl-mode)
17021
17022 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17023 ;;; vhdl-mode.el ends here