Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992-2011
4 ;; Free Software Foundation, Inc.
5
6 ;; Authors: Reto Zimmermann <reto@gnu.org>
7 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
8 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
9 ;; Keywords: languages vhdl
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
11
12 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
13 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
14 ;; filed in the Emacs bug reporting system against this file, a copy
15 ;; of the bug report be sent to the maintainer's email address.
16
17 (defconst vhdl-version "3.33.6"
18 "VHDL Mode version number.")
19
20 (defconst vhdl-time-stamp "2005-08-30"
21 "VHDL Mode time stamp for last update.")
22
23 ;; This file is part of GNU Emacs.
24
25 ;; GNU Emacs is free software: you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation, either version 3 of the License, or
28 ;; (at your option) any later version.
29
30 ;; GNU Emacs is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
34
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;; Commentary:
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
42 ;; This package provides an Emacs major mode for editing VHDL code.
43 ;; It includes the following features:
44
45 ;; - Syntax highlighting
46 ;; - Indentation
47 ;; - Template insertion (electrification)
48 ;; - Insertion of file headers
49 ;; - Insertion of user-specified models
50 ;; - Port translation / testbench generation
51 ;; - Structural composition
52 ;; - Configuration generation
53 ;; - Sensitivity list updating
54 ;; - File browser
55 ;; - Design hierarchy browser
56 ;; - Source file compilation (syntax analysis)
57 ;; - Makefile generation
58 ;; - Code hiding
59 ;; - Word/keyword completion
60 ;; - Block commenting
61 ;; - Code fixing/alignment/beautification
62 ;; - Postscript printing
63 ;; - VHDL'87/'93 and VHDL-AMS supported
64 ;; - Comprehensive menu
65 ;; - Fully customizable
66 ;; - Works under GNU Emacs (recommended) and XEmacs
67
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69 ;; Documentation
70
71 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 ;; Emacs Versions
75
76 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
77 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
78
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 ;; Installation
81
82 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
83
84 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
85 ;; or into an arbitrary directory that is added to the load path by the
86 ;; following line in your Emacs start-up file `.emacs':
87
88 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
89
90 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
91 ;; directory. Otherwise, byte-compile the source file:
92 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
93 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
94
95 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
96 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
97 ;; (not required in Emacs 20.X):
98
99 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
100 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
101
102 ;; More detailed installation instructions are included in the official
103 ;; VHDL Mode distribution.
104
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 ;; Acknowledgements
107
108 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
109 ;; and Steve Grout.
110
111 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
112 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
113
114 ;; Many thanks to all the users who sent me bug reports and enhancement
115 ;; requests.
116 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
117 ;; enhancement suggestions and the fruitful discussions.
118 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
119 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
120
121 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
122 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
123 ;; giving me the opportunity to develop this code.
124 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
125 ;; of the Swiss Government.
126
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128
129 ;;; Code:
130
131 ;; Emacs 21+ handling
132 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
133 "Non-nil if GNU Emacs 21, 22, ... is used.")
134 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
135 "Non-nil if GNU Emacs 22, ... is used.")
136
137 (defvar compilation-file-regexp-alist)
138 (defvar conf-alist)
139 (defvar conf-entry)
140 (defvar conf-key)
141 (defvar ent-alist)
142 (defvar itimer-version)
143 (defvar lazy-lock-defer-contextually)
144 (defvar lazy-lock-defer-on-scrolling)
145 (defvar lazy-lock-defer-on-the-fly)
146 (defvar speedbar-attached-frame)
147
148
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;;; Variables
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152
153 ;; help function for user options
154 (defun vhdl-custom-set (variable value &rest functions)
155 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
156 (if (fboundp 'custom-set-default)
157 (custom-set-default variable value)
158 (set-default variable value))
159 (while functions
160 (when (fboundp (car functions)) (funcall (car functions)))
161 (setq functions (cdr functions))))
162
163 (defun vhdl-widget-directory-validate (widget)
164 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
165 '/' or is empty)."
166 (let ((val (widget-value widget)))
167 (unless (string-match "^\\(\\|.*/\\)$" val)
168 (widget-put widget :error "Invalid directory entry: must end with '/'")
169 widget)))
170
171 ;; help string for user options
172 (defconst vhdl-name-doc-string "
173
174 FROM REGEXP is a regular expression matching the original name:
175 \".*\" matches the entire string
176 \"\\(...\\)\" matches a substring
177 TO STRING specifies the string to be inserted as new name:
178 \"\\&\" means substitute entire matched text
179 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
180 Examples:
181 \".*\" \"\\&\" inserts original string
182 \".*\" \"\\&_i\" attaches \"_i\" to original string
183 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
184 \".*\" \"foo\" inserts constant string \"foo\"
185 \".*\" \"\" inserts empty string")
186
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 ;; User variables
189
190 (defgroup vhdl nil
191 "Customizations for VHDL Mode."
192 :prefix "vhdl-"
193 :group 'languages
194 ; :version "21.2" ; comment out for XEmacs
195 )
196
197 (defgroup vhdl-mode nil
198 "Customizations for modes."
199 :group 'vhdl)
200
201 (defcustom vhdl-indent-tabs-mode nil
202 "*Non-nil means indentation can insert tabs.
203 Overrides local variable `indent-tabs-mode'."
204 :type 'boolean
205 :group 'vhdl-mode)
206
207
208 (defgroup vhdl-compile nil
209 "Customizations for compilation."
210 :group 'vhdl)
211
212 (defcustom vhdl-compiler-alist
213 '(
214 ;; Cadence Leapfrog: cv -file test.vhd
215 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
216 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
217 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
218 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
219 ("\\1/entity" "\\2/\\1" "\\1/configuration"
220 "\\1/package" "\\1/body" downcase))
221 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
222 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
223 ;; (PLL_400X_TOP) is not declared [10.3].
224 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
225 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
226 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
227 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
228 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
229 ;; Ikos Voyager: analyze test.vhd
230 ;; analyze test.vhd
231 ;; E L4/C5: this library unit is inaccessible
232 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
233 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
234 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
235 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
236 nil)
237 ;; ModelSim, Model Technology: vcom test.vhd
238 ;; ERROR: test.vhd(14): Unknown identifier: positiv
239 ;; WARNING[2]: test.vhd(85): Possible infinite loop
240 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
241 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
242 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
243 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
244 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
245 "\\1/_primary.dat" "\\1/body.dat" downcase))
246 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
247 ;; test.vhd:34: error message
248 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
249 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
250 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
251 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
252 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
253 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
254 ;; ERROR: test.vhd(24): near "dnd": expecting: END
255 ;; WARNING[4]: test.vhd(30): A space is required between ...
256 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
257 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
258 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
259 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
260 "\\1/_primary.dat" "\\1/body.dat" downcase))
261 ;; Savant: scram -publish-cc test.vhd
262 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
263 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
264 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
265 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
266 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
267 "\\1_config.vhdl" "\\1_package.vhdl"
268 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
269 ;; Simili: vhdlp -work test.vhd
270 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
271 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
272 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
273 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
274 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
275 "\\1/prim.var" "\\1/_body.var" downcase))
276 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
277 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
278 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
279 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
280 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
281 nil)
282 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
283 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
284 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
285 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
286 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
287 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
288 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
289 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
290 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
291 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
292 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
293 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
294 ;; Synplify:
295 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
296 ("Synplify" "n/a" "n/a" "make" "-f \\1"
297 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
298 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
299 nil)
300 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
301 ;; Compiling "test.vhd" line 1...
302 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
303 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
304 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
305 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
306 ("^ *Compiling \"\\(.+\\)\" " 1)
307 nil)
308 ;; VeriBest: vc vhdl test.vhd
309 ;; (no file name printed out!)
310 ;; 32: Z <= A and BitA ;
311 ;; ^^^^
312 ;; [Error] Name BITA is unknown
313 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
314 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
315 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
316 nil)
317 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
318 ;; Compiling "test.vhd" line 1...
319 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
320 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
321 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
322 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
323 ("^ *Compiling \"\\(.+\\)\" " 1)
324 nil)
325 )
326 "*List of available VHDL compilers and their properties.
327 Each list entry specifies the following items for a compiler:
328 Compiler:
329 Compiler name : name used in option `vhdl-compiler' to choose compiler
330 Compile command : command used for source file compilation
331 Compile options : compile options (\"\\1\" inserts library name)
332 Make command : command used for compilation using a Makefile
333 Make options : make options (\"\\1\" inserts Makefile name)
334 Generate Makefile: use built-in function or command to generate a Makefile
335 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
336 Library command : command to create library directory \(\"\\1\" inserts
337 library directory, \"\\2\" inserts library name)
338 Compile directory: where compilation is run and the Makefile is placed
339 Library directory: directory of default library
340 Makefile name : name of Makefile (default is \"Makefile\")
341 ID string : compiler identification string (see `vhdl-project-alist')
342 Error message:
343 Regexp : regular expression to match error messages (*)
344 File subexp index: index of subexpression that matches the file name
345 Line subexp index: index of subexpression that matches the line number
346 Column subexp idx: index of subexpression that matches the column number
347 File message:
348 Regexp : regular expression to match a file name message
349 File subexp index: index of subexpression that matches the file name
350 Unit-to-file name mapping: mapping of library unit names to names of files
351 generated by the compiler (used for Makefile generation)
352 To string : string a name is mapped to (\"\\1\" inserts the unit name,
353 \"\\2\" inserts the entity name for architectures)
354 Case adjustment : adjust case of inserted unit names
355
356 \(*) The regular expression must match the error message starting from the
357 beginning of the line (but not necessarily to the end of the line).
358
359 Compile options allows insertion of the library name (see `vhdl-project-alist')
360 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
361
362 For Makefile generation, the built-in function can be used (requires
363 specification of the unit-to-file name mapping). Alternatively, an
364 external command can be specified. Work directory allows specification of
365 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
366 used for Makefile generation). To use another library name than \"work\",
367 customize `vhdl-project-alist'. The library command is inserted in Makefiles
368 to automatically create the library directory if not existent.
369
370 Compile options, compile directory, library directory, and Makefile name are
371 overwritten by the project settings if a project is defined (see
372 `vhdl-project-alist'). Directory paths are relative to the source file
373 directory.
374
375 Some compilers do not include the file name in the error message, but print
376 out a file name message in advance. In this case, set \"File Subexp Index\"
377 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
378 If no file name at all is printed out, set both \"File Message\" entries to 0
379 \(a default file name message will be printed out instead, does not work in
380 XEmacs).
381
382 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
383 assigning its name to option `vhdl-compiler'.
384
385 Please send any missing or erroneous compiler properties to the maintainer for
386 updating.
387
388 NOTE: Activate new error and file message regexps and reflect the new setting
389 in the choice list of option `vhdl-compiler' by restarting Emacs."
390 :type '(repeat
391 (list :tag "Compiler" :indent 2
392 (string :tag "Compiler name ")
393 (string :tag "Compile command ")
394 (string :tag "Compile options " "-work \\1")
395 (string :tag "Make command " "make")
396 (string :tag "Make options " "-f \\1")
397 (choice :tag "Generate Makefile "
398 (const :tag "Built-in function" nil)
399 (string :tag "Command" "vmake \\2 > \\1"))
400 (string :tag "Library command " "mkdir \\1")
401 (directory :tag "Compile directory "
402 :validate vhdl-widget-directory-validate "./")
403 (directory :tag "Library directory "
404 :validate vhdl-widget-directory-validate "work/")
405 (file :tag "Makefile name " "Makefile")
406 (string :tag "ID string ")
407 (list :tag "Error message" :indent 4
408 (regexp :tag "Regexp ")
409 (integer :tag "File subexp index")
410 (integer :tag "Line subexp index")
411 (integer :tag "Column subexp idx"))
412 (list :tag "File message" :indent 4
413 (regexp :tag "Regexp ")
414 (integer :tag "File subexp index"))
415 (choice :tag "Unit-to-file name mapping"
416 :format "%t: %[Value Menu%] %v\n"
417 (const :tag "Not defined" nil)
418 (list :tag "To string" :indent 4
419 (string :tag "Entity " "\\1.vhd")
420 (string :tag "Architecture " "\\2_\\1.vhd")
421 (string :tag "Configuration " "\\1.vhd")
422 (string :tag "Package " "\\1.vhd")
423 (string :tag "Package Body " "\\1_body.vhd")
424 (choice :tag "Case adjustment "
425 (const :tag "None" identity)
426 (const :tag "Upcase" upcase)
427 (const :tag "Downcase" downcase))))))
428 :set (lambda (variable value)
429 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
430 :group 'vhdl-compile)
431
432 (defcustom vhdl-compiler "ModelSim"
433 "*Specifies the VHDL compiler to be used for syntax analysis.
434 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
435 :type (let ((alist vhdl-compiler-alist) list)
436 (while alist
437 (setq list (cons (list 'const (caar alist)) list))
438 (setq alist (cdr alist)))
439 (append '(choice) (nreverse list)))
440 :group 'vhdl-compile)
441
442 (defcustom vhdl-compile-use-local-error-regexp t
443 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
444 In this case, only error message regexps for VHDL compilers are active if
445 compilation is started from a VHDL buffer. Otherwise, the error message
446 regexps are appended to the predefined global regexps, and all regexps are
447 active all the time. Note that by doing that, the predefined global regexps
448 might result in erroneous parsing of error messages for some VHDL compilers.
449
450 NOTE: Activate the new setting by restarting Emacs."
451 :type 'boolean
452 :group 'vhdl-compile)
453
454 (defcustom vhdl-makefile-generation-hook nil
455 "*Functions to run at the end of Makefile generation.
456 Allows to insert user specific parts into a Makefile.
457
458 Example:
459 \(lambda nil
460 \(re-search-backward \"^# Rule for compiling entire design\")
461 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
462 :type 'hook
463 :group 'vhdl-compile)
464
465 (defcustom vhdl-default-library "work"
466 "*Name of default library.
467 Is overwritten by project settings if a project is active."
468 :type 'string
469 :group 'vhdl-compile)
470
471
472 (defgroup vhdl-project nil
473 "Customizations for projects."
474 :group 'vhdl)
475
476 (defcustom vhdl-project-alist
477 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
478 "~/example1/" ("src/system/" "src/components/") ""
479 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
480 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
481 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
482 ("Example 2" "Individual source files, multiple compilers in different directories"
483 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
484 nil "\\1/" "work" "\\1/work/" "Makefile" "")
485 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
486 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
487 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
488 -------------------------------------------------------------------------------
489 -- This is a multi-line project description
490 -- that can be used as a project dependent part of the file header.
491 "))
492 "*List of projects and their properties.
493 Name : name used in option `vhdl-project' to choose project
494 Title : title of project (single-line string)
495 Default directory: default project directory (absolute path)
496 Sources : a) source files : path + \"/\" + file name
497 b) directory : path + \"/\"
498 c) directory tree: \"-r \" + path + \"/\"
499 Exclude regexp : matches file/directory names to be excluded as sources
500 Compile options : project-specific options for each compiler
501 Compiler name : name of compiler for which these options are valid
502 Compile options: project-specific compiler options
503 (\"\\1\" inserts library name, \"\\2\" default options)
504 Make options: project-specific make options
505 (\"\\1\" inserts Makefile name, \"\\2\" default options)
506 Exceptions : file-specific exceptions
507 File name regexp: matches file names for which exceptions are valid
508 - Options : file-specific compiler options string
509 (\"\\1\" inserts library name, \"\\2\" default options,
510 \"\\3\" project-specific options)
511 - Do not compile: do not compile this file (in Makefile)
512 Compile directory: where compilation is run and the Makefile is placed
513 \(\"\\1\" inserts compiler ID string)
514 Library name : name of library (default is \"work\")
515 Library directory: path to library (\"\\1\" inserts compiler ID string)
516 Makefile name : name of Makefile
517 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
518 Description : description of project (multi-line string)
519
520 Project title and description are used to insert into the file header (see
521 option `vhdl-file-header').
522
523 The default directory must have an absolute path (use `M-TAB' for completion).
524 All other paths can be absolute or relative to the default directory. All
525 paths must end with '/'.
526
527 The design units found in the sources (files and directories) are shown in the
528 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
529 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
530 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
531 specified, the default directory is taken as source directory. Otherwise,
532 the default directory is only taken as source directory if there is a sources
533 entry with the empty string or \"./\". Exclude regexp allows to filter out
534 specific file and directory names from the list of sources (e.g. CVS
535 directories).
536
537 Files are compiled in the compile directory. Makefiles are also placed into
538 the compile directory. Library directory specifies which directory the
539 compiler compiles into (used to generate the Makefile).
540
541 Since different compile/library directories and Makefiles may exist for
542 different compilers within one project, these paths and names allow the
543 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
544 Compile options, compile directory, library directory, and Makefile name
545 overwrite the settings of the current compiler.
546
547 File-specific compiler options (highest priority) overwrite project-specific
548 options which overwrite default options (lowest priority). Lower priority
549 options can be inserted in higher priority options. This allows to reuse
550 default options (e.g. \"-file\") in project- or file-specific options (e.g.
551 \"-93 -file\").
552
553 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
554 by restarting Emacs."
555 :type `(repeat
556 (list :tag "Project" :indent 2
557 (string :tag "Name ")
558 (string :tag "Title ")
559 (directory :tag "Default directory"
560 :validate vhdl-widget-directory-validate
561 ,(abbreviate-file-name default-directory))
562 (repeat :tag "Sources " :indent 4
563 (directory :format " %v" "./"))
564 (regexp :tag "Exclude regexp ")
565 (repeat
566 :tag "Compile options " :indent 4
567 (list :tag "Compiler" :indent 6
568 ,(let ((alist vhdl-compiler-alist) list)
569 (while alist
570 (setq list (cons (list 'const (caar alist)) list))
571 (setq alist (cdr alist)))
572 (append '(choice :tag "Compiler name")
573 (nreverse list)))
574 (string :tag "Compile options" "\\2")
575 (string :tag "Make options " "\\2")
576 (repeat
577 :tag "Exceptions " :indent 8
578 (cons :format "%v"
579 (regexp :tag "File name regexp ")
580 (choice :format "%[Value Menu%] %v"
581 (string :tag "Options" "\\3")
582 (const :tag "Do not compile" nil))))))
583 (directory :tag "Compile directory"
584 :validate vhdl-widget-directory-validate "./")
585 (string :tag "Library name " "work")
586 (directory :tag "Library directory"
587 :validate vhdl-widget-directory-validate "work/")
588 (file :tag "Makefile name " "Makefile")
589 (string :tag "Description: (type `C-j' for newline)"
590 :format "%t\n%v\n")))
591 :set (lambda (variable value)
592 (vhdl-custom-set variable value
593 'vhdl-update-mode-menu
594 'vhdl-speedbar-refresh))
595 :group 'vhdl-project)
596
597 (defcustom vhdl-project nil
598 "*Specifies the default for the current project.
599 Select a project name from the ones defined in option `vhdl-project-alist'.
600 Is used to determine the project title and description to be inserted in file
601 headers and the source files/directories to be scanned in the hierarchy
602 browser. The current project can also be changed temporarily in the menu."
603 :type (let ((alist vhdl-project-alist) list)
604 (while alist
605 (setq list (cons (list 'const (caar alist)) list))
606 (setq alist (cdr alist)))
607 (append '(choice (const :tag "None" nil) (const :tag "--"))
608 (nreverse list)))
609 :group 'vhdl-project)
610
611 (defcustom vhdl-project-file-name '("\\1.prj")
612 "*List of file names/paths for importing/exporting project setups.
613 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
614 replaced by the user name (allows to have user-specific project setups).
615 The first entry is used as file name to import/export individual project
616 setups. All entries are used to automatically import project setups at
617 startup (see option `vhdl-project-auto-load'). Projects loaded from the
618 first entry are automatically made current. Hint: specify local project
619 setups in first entry, global setups in following entries; loading a local
620 project setup will make it current, while loading the global setups
621 is done without changing the current project.
622 Names can also have an absolute path (i.e. project setups can be stored
623 in global directories)."
624 :type '(repeat (string :tag "File name" "\\1.prj"))
625 :group 'vhdl-project)
626
627 (defcustom vhdl-project-auto-load '(startup)
628 "*Automatically load project setups from files.
629 All project setup files that match the file names specified in option
630 `vhdl-project-file-name' are automatically loaded. The project of the
631 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
632 entry is activated.
633 A project setup file can be obtained by exporting a project (see menu).
634 At startup: project setup file is loaded at Emacs startup"
635 :type '(set (const :tag "At startup" startup))
636 :group 'vhdl-project)
637
638 (defcustom vhdl-project-sort t
639 "*Non-nil means projects are displayed in alphabetical order."
640 :type 'boolean
641 :group 'vhdl-project)
642
643
644 (defgroup vhdl-style nil
645 "Customizations for coding styles."
646 :group 'vhdl
647 :group 'vhdl-template
648 :group 'vhdl-port
649 :group 'vhdl-compose)
650
651 (defcustom vhdl-standard '(87 nil)
652 "*VHDL standards used.
653 Basic standard:
654 VHDL'87 : IEEE Std 1076-1987
655 VHDL'93 : IEEE Std 1076-1993
656 Additional standards:
657 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
658 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
659
660 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
661 \"Activate Options\"."
662 :type '(list (choice :tag "Basic standard"
663 (const :tag "VHDL'87" 87)
664 (const :tag "VHDL'93" 93))
665 (set :tag "Additional standards" :indent 2
666 (const :tag "VHDL-AMS" ams)
667 (const :tag "Math packages" math)))
668 :set (lambda (variable value)
669 (vhdl-custom-set variable value
670 'vhdl-template-map-init
671 'vhdl-mode-abbrev-table-init
672 'vhdl-template-construct-alist-init
673 'vhdl-template-package-alist-init
674 'vhdl-update-mode-menu
675 'vhdl-words-init 'vhdl-font-lock-init))
676 :group 'vhdl-style)
677
678 (defcustom vhdl-basic-offset 2
679 "*Amount of basic offset used for indentation.
680 This value is used by + and - symbols in `vhdl-offsets-alist'."
681 :type 'integer
682 :group 'vhdl-style)
683
684 (defcustom vhdl-upper-case-keywords nil
685 "*Non-nil means convert keywords to upper case.
686 This is done when typed or expanded or by the fix case functions."
687 :type 'boolean
688 :set (lambda (variable value)
689 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
690 :group 'vhdl-style)
691
692 (defcustom vhdl-upper-case-types nil
693 "*Non-nil means convert standardized types to upper case.
694 This is done when expanded or by the fix case functions."
695 :type 'boolean
696 :set (lambda (variable value)
697 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
698 :group 'vhdl-style)
699
700 (defcustom vhdl-upper-case-attributes nil
701 "*Non-nil means convert standardized attributes to upper case.
702 This is done when 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-enum-values nil
709 "*Non-nil means convert standardized enumeration values 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-constants t
717 "*Non-nil means convert standardized constants to upper case.
718 This is done when expanded."
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-use-direct-instantiation 'standard
725 "*Non-nil means use VHDL'93 direct component instantiation.
726 Never : never
727 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
728 Always : always"
729 :type '(choice (const :tag "Never" never)
730 (const :tag "Standard" standard)
731 (const :tag "Always" always))
732 :group 'vhdl-style)
733
734
735 (defgroup vhdl-naming nil
736 "Customizations for naming conventions."
737 :group 'vhdl)
738
739 (defcustom vhdl-entity-file-name '(".*" . "\\&")
740 (concat
741 "*Specifies how the entity file name is obtained.
742 The entity file name can be obtained by modifying the entity name (e.g.
743 attaching or stripping off a substring). The file extension is automatically
744 taken from the file name of the current buffer."
745 vhdl-name-doc-string)
746 :type '(cons (regexp :tag "From regexp")
747 (string :tag "To string "))
748 :group 'vhdl-naming
749 :group 'vhdl-compose)
750
751 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
752 (concat
753 "*Specifies how the architecture file name is obtained.
754 The architecture file name can be obtained by modifying the entity
755 and/or architecture name (e.g. attaching or stripping off a substring). The
756 file extension is automatically taken from the file name of the current
757 buffer. The string that is matched against the regexp is the concatenation
758 of the entity and the architecture name separated by a space. This gives
759 access to both names (see default setting as example)."
760 vhdl-name-doc-string)
761 :type '(cons (regexp :tag "From regexp")
762 (string :tag "To string "))
763 :group 'vhdl-naming
764 :group 'vhdl-compose)
765
766 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
767 (concat
768 "*Specifies how the configuration file name is obtained.
769 The configuration file name can be obtained by modifying the configuration
770 name (e.g. attaching or stripping off a substring). The file extension is
771 automatically taken from the file name of the current buffer."
772 vhdl-name-doc-string)
773 :type '(cons (regexp :tag "From regexp")
774 (string :tag "To string "))
775 :group 'vhdl-naming
776 :group 'vhdl-compose)
777
778 (defcustom vhdl-package-file-name '(".*" . "\\&")
779 (concat
780 "*Specifies how the package file name is obtained.
781 The package file name can be obtained by modifying the package name (e.g.
782 attaching or stripping off a substring). The file extension is automatically
783 taken from the file name of the current buffer. Package files can be created
784 in a different directory by prepending a relative or absolute path to the
785 file name."
786 vhdl-name-doc-string)
787 :type '(cons (regexp :tag "From regexp")
788 (string :tag "To string "))
789 :group 'vhdl-naming
790 :group 'vhdl-compose)
791
792 (defcustom vhdl-file-name-case 'identity
793 "*Specifies how to change case for obtaining file names.
794 When deriving a file name from a VHDL unit name, case can be changed as
795 follows:
796 As Is: case is not changed (taken as is)
797 Lower Case: whole name is changed to lower case
798 Upper Case: whole name is changed to upper case
799 Capitalize: first letter of each word in name is capitalized"
800 :type '(choice (const :tag "As Is" identity)
801 (const :tag "Lower Case" downcase)
802 (const :tag "Upper Case" upcase)
803 (const :tag "Capitalize" capitalize))
804 :group 'vhdl-naming
805 :group 'vhdl-compose)
806
807
808 (defgroup vhdl-template nil
809 "Customizations for electrification."
810 :group 'vhdl)
811
812 (defcustom vhdl-electric-keywords '(vhdl user)
813 "*Type of keywords for which electrification is enabled.
814 VHDL keywords: invoke built-in templates
815 User keywords: invoke user models (see option `vhdl-model-alist')"
816 :type '(set (const :tag "VHDL keywords" vhdl)
817 (const :tag "User model keywords" user))
818 :set (lambda (variable value)
819 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
820 :group 'vhdl-template)
821
822 (defcustom vhdl-optional-labels 'process
823 "*Constructs for which labels are to be queried.
824 Template generators prompt for optional labels for:
825 None : no constructs
826 Processes only: processes only (also procedurals in VHDL-AMS)
827 All constructs: all constructs with optional labels and keyword END"
828 :type '(choice (const :tag "None" none)
829 (const :tag "Processes only" process)
830 (const :tag "All constructs" all))
831 :group 'vhdl-template)
832
833 (defcustom vhdl-insert-empty-lines 'unit
834 "*Specifies whether to insert empty lines in some templates.
835 This improves readability of code. Empty lines are inserted in:
836 None : no constructs
837 Design units only: entities, architectures, configurations, packages only
838 All constructs : also all constructs with BEGIN...END parts
839
840 Replaces option `vhdl-additional-empty-lines'."
841 :type '(choice (const :tag "None" none)
842 (const :tag "Design units only" unit)
843 (const :tag "All constructs" all))
844 :group 'vhdl-template
845 :group 'vhdl-port
846 :group 'vhdl-compose)
847
848 (defcustom vhdl-argument-list-indent nil
849 "*Non-nil means indent argument lists relative to opening parenthesis.
850 That is, argument, association, and port lists start on the same line as the
851 opening parenthesis and subsequent lines are indented accordingly.
852 Otherwise, lists start on a new line and are indented as normal code."
853 :type 'boolean
854 :group 'vhdl-template
855 :group 'vhdl-port
856 :group 'vhdl-compose)
857
858 (defcustom vhdl-association-list-with-formals t
859 "*Non-nil means write association lists with formal parameters.
860 Templates prompt for formal and actual parameters (ports/generics).
861 When pasting component instantiations, formals are included.
862 If nil, only a list of actual parameters is entered."
863 :type 'boolean
864 :group 'vhdl-template
865 :group 'vhdl-port
866 :group 'vhdl-compose)
867
868 (defcustom vhdl-conditions-in-parenthesis nil
869 "*Non-nil means place parenthesis around condition expressions."
870 :type 'boolean
871 :group 'vhdl-template)
872
873 (defcustom vhdl-zero-string "'0'"
874 "*String to use for a logic zero."
875 :type 'string
876 :group 'vhdl-template)
877
878 (defcustom vhdl-one-string "'1'"
879 "*String to use for a logic one."
880 :type 'string
881 :group 'vhdl-template)
882
883
884 (defgroup vhdl-header nil
885 "Customizations for file header."
886 :group 'vhdl-template
887 :group 'vhdl-compose)
888
889 (defcustom vhdl-file-header "\
890 -------------------------------------------------------------------------------
891 -- Title : <title string>
892 -- Project : <project>
893 -------------------------------------------------------------------------------
894 -- File : <filename>
895 -- Author : <author>
896 -- Company : <company>
897 -- Created : <date>
898 -- Last update: <date>
899 -- Platform : <platform>
900 -- Standard : <standard>
901 <projectdesc>-------------------------------------------------------------------------------
902 -- Description: <cursor>
903 <copyright>-------------------------------------------------------------------------------
904 -- Revisions :
905 -- Date Version Author Description
906 -- <date> 1.0 <login>\tCreated
907 -------------------------------------------------------------------------------
908
909 "
910 "*String or file to insert as file header.
911 If the string specifies an existing file name, the contents of the file is
912 inserted, otherwise the string itself is inserted as file header.
913 Type `C-j' for newlines.
914 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
915 if the header needs to be version controlled.
916
917 The following keywords for template generation are supported:
918 <filename> : replaced by the name of the buffer
919 <author> : replaced by the user name and email address
920 \(`user-full-name', `mail-host-address', `user-mail-address')
921 <login> : replaced by user login name (`user-login-name')
922 <company> : replaced by contents of option `vhdl-company-name'
923 <date> : replaced by the current date
924 <year> : replaced by the current year
925 <project> : replaced by title of current project (`vhdl-project')
926 <projectdesc> : replaced by description of current project (`vhdl-project')
927 <copyright> : replaced by copyright string (`vhdl-copyright-string')
928 <platform> : replaced by contents of option `vhdl-platform-spec'
929 <standard> : replaced by the VHDL language standard(s) used
930 <... string> : replaced by a queried string (\"...\" is the prompt word)
931 <title string>: replaced by file title in automatically generated files
932 <cursor> : final cursor position
933
934 The (multi-line) project description <projectdesc> can be used as a project
935 dependent part of the file header and can also contain the above keywords."
936 :type 'string
937 :group 'vhdl-header)
938
939 (defcustom vhdl-file-footer ""
940 "*String or file to insert as file footer.
941 If the string specifies an existing file name, the contents of the file is
942 inserted, otherwise the string itself is inserted as file footer (i.e. at
943 the end of the file).
944 Type `C-j' for newlines.
945 The same keywords as in option `vhdl-file-header' can be used."
946 :type 'string
947 :group 'vhdl-header)
948
949 (defcustom vhdl-company-name ""
950 "*Name of company to insert in file header.
951 See option `vhdl-file-header'."
952 :type 'string
953 :group 'vhdl-header)
954
955 (defcustom vhdl-copyright-string "\
956 -------------------------------------------------------------------------------
957 -- Copyright (c) <year> <company>
958 "
959 "*Copyright string to insert in file header.
960 Can be multi-line string (type `C-j' for newline) and contain other file
961 header keywords (see option `vhdl-file-header')."
962 :type 'string
963 :group 'vhdl-header)
964
965 (defcustom vhdl-platform-spec ""
966 "*Specification of VHDL platform to insert in file header.
967 The platform specification should contain names and versions of the
968 simulation and synthesis tools used.
969 See option `vhdl-file-header'."
970 :type 'string
971 :group 'vhdl-header)
972
973 (defcustom vhdl-date-format "%Y-%m-%d"
974 "*Specifies the date format to use in the header.
975 This string is passed as argument to the command `format-time-string'.
976 For more information on format strings, see the documentation for the
977 `format-time-string' command (C-h f `format-time-string')."
978 :type 'string
979 :group 'vhdl-header)
980
981 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
982 "*Prefix string of modification date in VHDL file header.
983 If actualization of the modification date is called (menu,
984 `\\[vhdl-template-modify]'), this string is searched and the rest
985 of the line replaced by the current date."
986 :type 'string
987 :group 'vhdl-header)
988
989 (defcustom vhdl-modify-date-on-saving t
990 "*Non-nil means update the modification date when the buffer is saved.
991 Calls function `\\[vhdl-template-modify]').
992
993 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
994 \"Activate Options\"."
995 :type 'boolean
996 :group 'vhdl-header)
997
998
999 (defgroup vhdl-sequential-process nil
1000 "Customizations for sequential processes."
1001 :group 'vhdl-template)
1002
1003 (defcustom vhdl-reset-kind 'async
1004 "*Specifies which kind of reset to use in sequential processes."
1005 :type '(choice (const :tag "None" none)
1006 (const :tag "Synchronous" sync)
1007 (const :tag "Asynchronous" async))
1008 :group 'vhdl-sequential-process)
1009
1010 (defcustom vhdl-reset-active-high nil
1011 "*Non-nil means reset in sequential processes is active high.
1012 Otherwise, reset is active low."
1013 :type 'boolean
1014 :group 'vhdl-sequential-process)
1015
1016 (defcustom vhdl-clock-rising-edge t
1017 "*Non-nil means rising edge of clock triggers sequential processes.
1018 Otherwise, falling edge triggers."
1019 :type 'boolean
1020 :group 'vhdl-sequential-process)
1021
1022 (defcustom vhdl-clock-edge-condition 'standard
1023 "*Syntax of the clock edge condition.
1024 Standard: \"clk'event and clk = '1'\"
1025 Function: \"rising_edge(clk)\""
1026 :type '(choice (const :tag "Standard" standard)
1027 (const :tag "Function" function))
1028 :group 'vhdl-sequential-process)
1029
1030 (defcustom vhdl-clock-name ""
1031 "*Name of clock signal to use in templates."
1032 :type 'string
1033 :group 'vhdl-sequential-process)
1034
1035 (defcustom vhdl-reset-name ""
1036 "*Name of reset signal to use in templates."
1037 :type 'string
1038 :group 'vhdl-sequential-process)
1039
1040
1041 (defgroup vhdl-model nil
1042 "Customizations for user models."
1043 :group 'vhdl)
1044
1045 (defcustom vhdl-model-alist
1046 '(("Example Model"
1047 "<label> : process (<clock>, <reset>)
1048 begin -- process <label>
1049 if <reset> = '0' then -- asynchronous reset (active low)
1050 <cursor>
1051 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1052 if <enable> = '1' then -- synchronous load
1053
1054 end if;
1055 end if;
1056 end process <label>;"
1057 "e" ""))
1058 "*List of user models.
1059 VHDL models (templates) can be specified by the user in this list. They can be
1060 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1061 electrification (i.e. overriding existing or creating new keywords, see
1062 option `vhdl-electric-keywords').
1063 Name : name of model (string of words and spaces)
1064 String : string or name of file to be inserted as model (newline: `C-j')
1065 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1066 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1067 Keyword : keyword to invoke model
1068
1069 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1070 A prompt that appears several times is queried once and replaced throughout
1071 the model. Special prompts are:
1072 <clock> : name specified in `vhdl-clock-name' (if not empty)
1073 <reset> : name specified in `vhdl-reset-name' (if not empty)
1074 <cursor>: final cursor position
1075 File header prompts (see variable `vhdl-file-header') are automatically
1076 replaced, so that user models can also be used to insert different types of
1077 headers.
1078
1079 If the string specifies an existing file name, the contents of the file is
1080 inserted, otherwise the string itself is inserted.
1081 The code within the models should be correctly indented.
1082 Type `C-j' for newlines.
1083
1084 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1085 \"Activate Options\"."
1086 :type '(repeat (list :tag "Model" :indent 2
1087 (string :tag "Name ")
1088 (string :tag "String : (type `C-j' for newline)"
1089 :format "%t\n%v")
1090 (sexp :tag "Key binding" x)
1091 (string :tag "Keyword " :format "%t: %v\n")))
1092 :set (lambda (variable value)
1093 (vhdl-custom-set variable value
1094 'vhdl-model-map-init
1095 'vhdl-model-defun
1096 'vhdl-mode-abbrev-table-init
1097 'vhdl-update-mode-menu))
1098 :group 'vhdl-model)
1099
1100
1101 (defgroup vhdl-compose nil
1102 "Customizations for structural composition."
1103 :group 'vhdl)
1104
1105 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1106 (concat
1107 "*Specifies how the component architecture name is obtained.
1108 The component architecture name can be obtained by modifying the entity name
1109 \(e.g. attaching or stripping off a substring).
1110 If TO STRING is empty, the architecture name is queried."
1111 vhdl-name-doc-string)
1112 :type '(cons (regexp :tag "From regexp")
1113 (string :tag "To string "))
1114 :group 'vhdl-compose)
1115
1116 (defcustom vhdl-compose-configuration-name
1117 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1118 (concat
1119 "*Specifies how the configuration name is obtained.
1120 The configuration name can be obtained by modifying the entity and/or
1121 architecture name (e.g. attaching or stripping off a substring). The string
1122 that is matched against the regexp is the concatenation of the entity and the
1123 architecture name separated by a space. This gives access to both names (see
1124 default setting as example)."
1125 vhdl-name-doc-string)
1126 :type '(cons (regexp :tag "From regexp")
1127 (string :tag "To string "))
1128 :group 'vhdl-compose)
1129
1130 (defcustom vhdl-components-package-name
1131 '((".*" . "\\&_components") . "components")
1132 (concat
1133 "*Specifies how the name for the components package is obtained.
1134 The components package is a package containing all component declarations for
1135 the current design. Its name can be obtained by modifying the project name
1136 \(e.g. attaching or stripping off a substring). If no project is defined, the
1137 DIRECTORY entry is chosen."
1138 vhdl-name-doc-string)
1139 :type '(cons (cons :tag "Project" :indent 2
1140 (regexp :tag "From regexp")
1141 (string :tag "To string "))
1142 (string :tag "Directory:\n String "))
1143 :group 'vhdl-compose)
1144
1145 (defcustom vhdl-use-components-package nil
1146 "*Non-nil means use a separate components package for component declarations.
1147 Otherwise, component declarations are inserted and searched for in the
1148 architecture declarative parts."
1149 :type 'boolean
1150 :group 'vhdl-compose)
1151
1152 (defcustom vhdl-compose-include-header t
1153 "*Non-nil means include a header in automatically generated files."
1154 :type 'boolean
1155 :group 'vhdl-compose)
1156
1157 (defcustom vhdl-compose-create-files 'single
1158 "*Specifies whether new files should be created for the new component.
1159 The component's entity and architecture are inserted:
1160 None : in current buffer
1161 Single file : in new single file
1162 Separate files: in two separate files
1163 The file names are obtained from variables `vhdl-entity-file-name' and
1164 `vhdl-architecture-file-name'."
1165 :type '(choice (const :tag "None" none)
1166 (const :tag "Single file" single)
1167 (const :tag "Separate files" separate))
1168 :group 'vhdl-compose)
1169
1170 (defcustom vhdl-compose-configuration-create-file nil
1171 "*Specifies whether a new file should be created for the configuration.
1172 If non-nil, a new file is created for the configuration.
1173 The file name is obtained from variable `vhdl-configuration-file-name'."
1174 :type 'boolean
1175 :group 'vhdl-compose)
1176
1177 (defcustom vhdl-compose-configuration-hierarchical t
1178 "*Specifies whether hierarchical configurations should be created.
1179 If non-nil, automatically created configurations are hierarchical and include
1180 the whole hierarchy of subcomponents. Otherwise the configuration only
1181 includes one level of subcomponents."
1182 :type 'boolean
1183 :group 'vhdl-compose)
1184
1185 (defcustom vhdl-compose-configuration-use-subconfiguration t
1186 "*Specifies whether subconfigurations should be used inside configurations.
1187 If non-nil, automatically created configurations use configurations in binding
1188 indications for subcomponents, if such configurations exist. Otherwise,
1189 entities are used in binding indications for subcomponents."
1190 :type 'boolean
1191 :group 'vhdl-compose)
1192
1193
1194 (defgroup vhdl-port nil
1195 "Customizations for port translation functions."
1196 :group 'vhdl
1197 :group 'vhdl-compose)
1198
1199 (defcustom vhdl-include-port-comments nil
1200 "*Non-nil means include port comments when a port is pasted."
1201 :type 'boolean
1202 :group 'vhdl-port)
1203
1204 (defcustom vhdl-include-direction-comments nil
1205 "*Non-nil means include port direction in instantiations as comments."
1206 :type 'boolean
1207 :group 'vhdl-port)
1208
1209 (defcustom vhdl-include-type-comments nil
1210 "*Non-nil means include generic/port type in instantiations as comments."
1211 :type 'boolean
1212 :group 'vhdl-port)
1213
1214 (defcustom vhdl-include-group-comments 'never
1215 "*Specifies whether to include group comments and spacings.
1216 The comments and empty lines between groups of ports are pasted:
1217 Never : never
1218 Declarations: in entity/component/constant/signal declarations only
1219 Always : also in generic/port maps"
1220 :type '(choice (const :tag "Never" never)
1221 (const :tag "Declarations" decl)
1222 (const :tag "Always" always))
1223 :group 'vhdl-port)
1224
1225 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1226 (concat
1227 "*Specifies how actual port names are obtained from formal port names.
1228 In a component instantiation, an actual port name can be obtained by
1229 modifying the formal port name (e.g. attaching or stripping off a substring)."
1230 vhdl-name-doc-string)
1231 :type '(cons (regexp :tag "From regexp")
1232 (string :tag "To string "))
1233 :group 'vhdl-port)
1234
1235 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1236 (concat
1237 "*Specifies how an instance name is obtained.
1238 The instance name can be obtained by modifying the name of the component to be
1239 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1240 by a unique number (starting with 1).
1241 If TO STRING is empty, the instance name is queried."
1242 vhdl-name-doc-string)
1243 :type '(cons (regexp :tag "From regexp")
1244 (string :tag "To string "))
1245 :group 'vhdl-port)
1246
1247
1248 (defgroup vhdl-testbench nil
1249 "Customizations for testbench generation."
1250 :group 'vhdl-port)
1251
1252 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1253 (concat
1254 "*Specifies how the testbench entity name is obtained.
1255 The entity name of a testbench can be obtained by modifying the name of
1256 the component to be tested (e.g. attaching or stripping off a substring)."
1257 vhdl-name-doc-string)
1258 :type '(cons (regexp :tag "From regexp")
1259 (string :tag "To string "))
1260 :group 'vhdl-testbench)
1261
1262 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1263 (concat
1264 "*Specifies how the testbench architecture name is obtained.
1265 The testbench architecture name can be obtained by modifying the name of
1266 the component to be tested (e.g. attaching or stripping off a substring).
1267 If TO STRING is empty, the architecture name is queried."
1268 vhdl-name-doc-string)
1269 :type '(cons (regexp :tag "From regexp")
1270 (string :tag "To string "))
1271 :group 'vhdl-testbench)
1272
1273 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1274 (concat
1275 "*Specifies how the testbench configuration name is obtained.
1276 The configuration name of a testbench can be obtained by modifying the entity
1277 and/or architecture name (e.g. attaching or stripping off a substring). The
1278 string that is matched against the regexp is the concatenation of the entity
1279 and the architecture name separated by a space. This gives access to both
1280 names (see default setting as example)."
1281 vhdl-name-doc-string)
1282 :type '(cons (regexp :tag "From regexp")
1283 (string :tag "To string "))
1284 :group 'vhdl-testbench)
1285
1286 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1287 (concat
1288 "*Specifies how a DUT instance name is obtained.
1289 The design-under-test instance name (i.e. the component instantiated in the
1290 testbench) can be obtained by modifying the component name (e.g. attaching
1291 or stripping off a substring)."
1292 vhdl-name-doc-string)
1293 :type '(cons (regexp :tag "From regexp")
1294 (string :tag "To string "))
1295 :group 'vhdl-testbench)
1296
1297 (defcustom vhdl-testbench-include-header t
1298 "*Non-nil means include a header in automatically generated files."
1299 :type 'boolean
1300 :group 'vhdl-testbench)
1301
1302 (defcustom vhdl-testbench-declarations "\
1303 -- clock
1304 signal Clk : std_logic := '1';
1305 "
1306 "*String or file to be inserted in the testbench declarative part.
1307 If the string specifies an existing file name, the contents of the file is
1308 inserted, otherwise the string itself is inserted in the testbench
1309 architecture before the BEGIN keyword.
1310 Type `C-j' for newlines."
1311 :type 'string
1312 :group 'vhdl-testbench)
1313
1314 (defcustom vhdl-testbench-statements "\
1315 -- clock generation
1316 Clk <= not Clk after 10 ns;
1317
1318 -- waveform generation
1319 WaveGen_Proc: process
1320 begin
1321 -- insert signal assignments here
1322
1323 wait until Clk = '1';
1324 end process WaveGen_Proc;
1325 "
1326 "*String or file to be inserted in the testbench statement part.
1327 If the string specifies an existing file name, the contents of the file is
1328 inserted, otherwise the string itself is inserted in the testbench
1329 architecture before the END keyword.
1330 Type `C-j' for newlines."
1331 :type 'string
1332 :group 'vhdl-testbench)
1333
1334 (defcustom vhdl-testbench-initialize-signals nil
1335 "*Non-nil means initialize signals with `0' when declared in testbench."
1336 :type 'boolean
1337 :group 'vhdl-testbench)
1338
1339 (defcustom vhdl-testbench-include-library t
1340 "*Non-nil means a library/use clause for std_logic_1164 is included."
1341 :type 'boolean
1342 :group 'vhdl-testbench)
1343
1344 (defcustom vhdl-testbench-include-configuration t
1345 "*Non-nil means a testbench configuration is attached at the end."
1346 :type 'boolean
1347 :group 'vhdl-testbench)
1348
1349 (defcustom vhdl-testbench-create-files 'single
1350 "*Specifies whether new files should be created for the testbench.
1351 testbench entity and architecture are inserted:
1352 None : in current buffer
1353 Single file : in new single file
1354 Separate files: in two separate files
1355 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1356 and `vhdl-testbench-architecture-file-name'."
1357 :type '(choice (const :tag "None" none)
1358 (const :tag "Single file" single)
1359 (const :tag "Separate files" separate))
1360 :group 'vhdl-testbench)
1361
1362 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1363 (concat
1364 "*Specifies how the testbench entity file name is obtained.
1365 The entity file name can be obtained by modifying the testbench entity name
1366 \(e.g. attaching or stripping off a substring). The file extension is
1367 automatically taken from the file name of the current buffer. Testbench
1368 files can be created in a different directory by prepending a relative or
1369 absolute path to the file name."
1370 vhdl-name-doc-string)
1371 :type '(cons (regexp :tag "From regexp")
1372 (string :tag "To string "))
1373 :group 'vhdl-testbench)
1374
1375 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1376 (concat
1377 "*Specifies how the testbench architecture file name is obtained.
1378 The architecture file name can be obtained by modifying the testbench entity
1379 and/or architecture name (e.g. attaching or stripping off a substring). The
1380 string that is matched against the regexp is the concatenation of the entity
1381 and the architecture name separated by a space. This gives access to both
1382 names (see default setting as example). Testbench files can be created in
1383 a different directory by prepending a relative or absolute path to the file
1384 name."
1385 vhdl-name-doc-string)
1386 :type '(cons (regexp :tag "From regexp")
1387 (string :tag "To string "))
1388 :group 'vhdl-testbench)
1389
1390
1391 (defgroup vhdl-comment nil
1392 "Customizations for comments."
1393 :group 'vhdl)
1394
1395 (defcustom vhdl-self-insert-comments t
1396 "*Non-nil means various templates automatically insert help comments."
1397 :type 'boolean
1398 :group 'vhdl-comment)
1399
1400 (defcustom vhdl-prompt-for-comments t
1401 "*Non-nil means various templates prompt for user definable comments."
1402 :type 'boolean
1403 :group 'vhdl-comment)
1404
1405 (defcustom vhdl-inline-comment-column 40
1406 "*Column to indent and align inline comments to.
1407 Overrides local option `comment-column'.
1408
1409 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1410 \"Activate Options\"."
1411 :type 'integer
1412 :group 'vhdl-comment)
1413
1414 (defcustom vhdl-end-comment-column 79
1415 "*End of comment column.
1416 Comments that exceed this column number are wrapped.
1417
1418 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1419 \"Activate Options\"."
1420 :type 'integer
1421 :group 'vhdl-comment)
1422
1423 (defvar end-comment-column)
1424
1425
1426 (defgroup vhdl-align nil
1427 "Customizations for alignment."
1428 :group 'vhdl)
1429
1430 (defcustom vhdl-auto-align t
1431 "*Non-nil means align some templates automatically after generation."
1432 :type 'boolean
1433 :group 'vhdl-align)
1434
1435 (defcustom vhdl-align-groups t
1436 "*Non-nil means align groups of code lines separately.
1437 A group of code lines is a region of consecutive lines between two lines that
1438 match the regexp in option `vhdl-align-group-separate'."
1439 :type 'boolean
1440 :group 'vhdl-align)
1441
1442 (defcustom vhdl-align-group-separate "^\\s-*$"
1443 "*Regexp for matching a line that separates groups of lines for alignment.
1444 Examples:
1445 \"^\\s-*$\": matches an empty line
1446 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1447 :type 'regexp
1448 :group 'vhdl-align)
1449
1450 (defcustom vhdl-align-same-indent t
1451 "*Non-nil means align blocks with same indent separately.
1452 When a region or the entire buffer is aligned, the code is divided into
1453 blocks of same indent which are aligned separately (except for argument/port
1454 lists). This gives nicer alignment in most cases.
1455 Option `vhdl-align-groups' still applies within these blocks."
1456 :type 'boolean
1457 :group 'vhdl-align)
1458
1459
1460 (defgroup vhdl-highlight nil
1461 "Customizations for highlighting."
1462 :group 'vhdl)
1463
1464 (defcustom vhdl-highlight-keywords t
1465 "*Non-nil means highlight VHDL keywords and other standardized words.
1466 The following faces are used:
1467 `font-lock-keyword-face' : keywords
1468 `font-lock-type-face' : standardized types
1469 `vhdl-font-lock-attribute-face': standardized attributes
1470 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1471 `vhdl-font-lock-function-face' : standardized function and package names
1472
1473 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1474 entry \"Fontify Buffer\")."
1475 :type 'boolean
1476 :set (lambda (variable value)
1477 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1478 :group 'vhdl-highlight)
1479
1480 (defcustom vhdl-highlight-names t
1481 "*Non-nil means highlight declaration names and construct labels.
1482 The following faces are used:
1483 `font-lock-function-name-face' : names in declarations of units,
1484 subprograms, components, as well as labels of VHDL constructs
1485 `font-lock-type-face' : names in type/nature declarations
1486 `vhdl-font-lock-attribute-face': names in attribute declarations
1487 `font-lock-variable-name-face' : names in declarations of signals,
1488 variables, constants, subprogram parameters, generics, and ports
1489
1490 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1491 entry \"Fontify Buffer\")."
1492 :type 'boolean
1493 :set (lambda (variable value)
1494 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1495 :group 'vhdl-highlight)
1496
1497 (defcustom vhdl-highlight-special-words nil
1498 "*Non-nil means highlight words with special syntax.
1499 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1500 are highlighted accordingly.
1501 Can be used for visual support of naming conventions.
1502
1503 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1504 entry \"Fontify Buffer\")."
1505 :type 'boolean
1506 :set (lambda (variable value)
1507 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1508 :group 'vhdl-highlight)
1509
1510 (defcustom vhdl-highlight-forbidden-words nil
1511 "*Non-nil means highlight forbidden words.
1512 The reserved words specified in option `vhdl-forbidden-words' or having the
1513 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1514 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1515 use them.
1516
1517 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1518 entry \"Fontify Buffer\")."
1519 :type 'boolean
1520 :set (lambda (variable value)
1521 (vhdl-custom-set variable value
1522 'vhdl-words-init 'vhdl-font-lock-init))
1523 :group 'vhdl-highlight)
1524
1525 (defcustom vhdl-highlight-verilog-keywords nil
1526 "*Non-nil means highlight Verilog keywords as reserved words.
1527 Verilog keywords are highlighted in a warning color (face
1528 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1529
1530 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1531 entry \"Fontify Buffer\")."
1532 :type 'boolean
1533 :set (lambda (variable value)
1534 (vhdl-custom-set variable value
1535 'vhdl-words-init 'vhdl-font-lock-init))
1536 :group 'vhdl-highlight)
1537
1538 (defcustom vhdl-highlight-translate-off nil
1539 "*Non-nil means background-highlight code excluded from translation.
1540 That is, all code between \"-- pragma translate_off\" and
1541 \"-- pragma translate_on\" is highlighted using a different background color
1542 \(face `vhdl-font-lock-translate-off-face').
1543 Note: this might slow down on-the-fly fontification (and thus editing).
1544
1545 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1546 entry \"Fontify Buffer\")."
1547 :type 'boolean
1548 :set (lambda (variable value)
1549 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1550 :group 'vhdl-highlight)
1551
1552 (defcustom vhdl-highlight-case-sensitive nil
1553 "*Non-nil means consider case for highlighting.
1554 Possible trade-off:
1555 non-nil also upper-case VHDL words are highlighted, but case of words with
1556 special syntax is not considered
1557 nil only lower-case VHDL words are highlighted, but case of words with
1558 special syntax is considered
1559 Overrides local option `font-lock-keywords-case-fold-search'.
1560
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1563 :type 'boolean
1564 :group 'vhdl-highlight)
1565
1566 (defcustom vhdl-special-syntax-alist
1567 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1568 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1569 ("variable" "\\w+_v" "Grey50" "Grey80"))
1570 "*List of special syntax to be highlighted.
1571 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1572 syntax (as regular expression) are highlighted in the corresponding color.
1573
1574 Name : string of words and spaces
1575 Regexp : regular expression describing word syntax
1576 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1577 Color (light): foreground color for light background
1578 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1579 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1580 Color (dark) : foreground color for dark background
1581 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1582 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1583
1584 Can be used for visual support of naming conventions, such as highlighting
1585 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1586 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1587 common substrings or name suffices.
1588 For each entry, a new face is generated with the specified colors and name
1589 \"vhdl-font-lock-\" + name + \"-face\".
1590
1591 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1592 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1593 :type '(repeat (list :tag "Face" :indent 2
1594 (string :tag "Name ")
1595 (regexp :tag "Regexp " "\\w+_")
1596 (string :tag "Color (light)")
1597 (string :tag "Color (dark) ")))
1598 :set (lambda (variable value)
1599 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1600 :group 'vhdl-highlight)
1601
1602 (defcustom vhdl-forbidden-words '()
1603 "*List of forbidden words to be highlighted.
1604 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1605 words are highlighted in a warning color to indicate not to use them.
1606
1607 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1608 entry \"Fontify Buffer\")."
1609 :type '(repeat (string :format "%v"))
1610 :set (lambda (variable value)
1611 (vhdl-custom-set variable value
1612 'vhdl-words-init 'vhdl-font-lock-init))
1613 :group 'vhdl-highlight)
1614
1615 (defcustom vhdl-forbidden-syntax ""
1616 "*Syntax of forbidden words to be highlighted.
1617 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1618 syntax are highlighted in a warning color to indicate not to use them.
1619 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1620 highlights identifiers with 10 or more characters).
1621
1622 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1623 entry \"Fontify Buffer\")."
1624 :type 'regexp
1625 :set (lambda (variable value)
1626 (vhdl-custom-set variable value
1627 'vhdl-words-init 'vhdl-font-lock-init))
1628 :group 'vhdl-highlight)
1629
1630 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1631 "*List of compiler directive keywords recognized for highlighting.
1632
1633 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1634 entry \"Fontify Buffer\")."
1635 :type '(repeat (string :format "%v"))
1636 :set (lambda (variable value)
1637 (vhdl-custom-set variable value
1638 'vhdl-words-init 'vhdl-font-lock-init))
1639 :group 'vhdl-highlight)
1640
1641
1642 (defgroup vhdl-speedbar nil
1643 "Customizations for speedbar."
1644 :group 'vhdl)
1645
1646 (defcustom vhdl-speedbar-auto-open nil
1647 "*Non-nil means automatically open speedbar at startup.
1648 Alternatively, the speedbar can be opened from the VHDL menu."
1649 :type 'boolean
1650 :group 'vhdl-speedbar)
1651
1652 (defcustom vhdl-speedbar-display-mode 'files
1653 "*Specifies the default displaying mode when opening speedbar.
1654 Alternatively, the displaying mode can be selected from the speedbar menu or
1655 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1656 :type '(choice (const :tag "Files" files)
1657 (const :tag "Directory hierarchy" directory)
1658 (const :tag "Project hierarchy" project))
1659 :group 'vhdl-speedbar)
1660
1661 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1662 "*Limits scanning of large files and netlists.
1663 Design units: maximum file size to scan for design units
1664 Hierarchy (instances of subcomponents):
1665 File size: maximum file size to scan for instances (in bytes)
1666 Instances per arch: maximum number of instances to scan per architecture
1667
1668 \"None\" always means that there is no limit.
1669 In case of files not or incompletely scanned, a warning message and the file
1670 names are printed out.
1671 Background: scanning for instances is considerably slower than scanning for
1672 design units, especially when there are many instances. These limits should
1673 prevent the scanning of large netlists."
1674 :type '(list (choice :tag "Design units"
1675 :format "%t : %[Value Menu%] %v"
1676 (const :tag "None" nil)
1677 (integer :tag "File size"))
1678 (list :tag "Hierarchy" :indent 2
1679 (choice :tag "File size"
1680 :format "%t : %[Value Menu%] %v"
1681 (const :tag "None" nil)
1682 (integer :tag "Size "))
1683 (choice :tag "Instances per arch"
1684 (const :tag "None" nil)
1685 (integer :tag "Number "))))
1686 :group 'vhdl-speedbar)
1687
1688 (defcustom vhdl-speedbar-jump-to-unit t
1689 "*Non-nil means jump to the design unit code when opened in a buffer.
1690 The buffer cursor position is left unchanged otherwise."
1691 :type 'boolean
1692 :group 'vhdl-speedbar)
1693
1694 (defcustom vhdl-speedbar-update-on-saving t
1695 "*Automatically update design hierarchy when buffer is saved."
1696 :type 'boolean
1697 :group 'vhdl-speedbar)
1698
1699 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1700 "*Automatically save modified hierarchy caches when exiting Emacs.
1701 Hierarchy: design hierarchy information
1702 Display: displaying information (which design units to expand)"
1703 :type '(set (const :tag "Hierarchy" hierarchy)
1704 (const :tag "Display" display))
1705 :group 'vhdl-speedbar)
1706
1707 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1708 "*Name of file for saving hierarchy cache.
1709 \"\\1\" is replaced by the project name if a project is specified,
1710 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1711 different users to have cache files in the same directory). Can also have
1712 an absolute path (i.e. all caches can be stored in one global directory)."
1713 :type 'string
1714 :group 'vhdl-speedbar)
1715
1716
1717 (defgroup vhdl-menu nil
1718 "Customizations for menues."
1719 :group 'vhdl)
1720
1721 (defcustom vhdl-index-menu nil
1722 "*Non-nil means add an index menu for a source file when loading.
1723 Alternatively, the speedbar can be used. Note that the index menu scans a file
1724 when it is opened, while speedbar only scans the file upon request."
1725 :type 'boolean
1726 :group 'vhdl-menu)
1727
1728 (defcustom vhdl-source-file-menu nil
1729 "*Non-nil means add a menu of all source files in current directory.
1730 Alternatively, the speedbar can be used."
1731 :type 'boolean
1732 :group 'vhdl-menu)
1733
1734 (defcustom vhdl-hideshow-menu nil
1735 "*Non-nil means add hideshow menu and functionality at startup.
1736 Hideshow can also be enabled from the VHDL Mode menu.
1737 Hideshow allows hiding code of various VHDL constructs.
1738
1739 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1740 \"Activate Options\"."
1741 :type 'boolean
1742 :group 'vhdl-menu)
1743
1744 (defcustom vhdl-hide-all-init nil
1745 "*Non-nil means hide all design units initially after a file is loaded."
1746 :type 'boolean
1747 :group 'vhdl-menu)
1748
1749
1750 (defgroup vhdl-print nil
1751 "Customizations for printing."
1752 :group 'vhdl)
1753
1754 (defcustom vhdl-print-two-column t
1755 "*Non-nil means print code in two columns and landscape format.
1756 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1757 prints VHDL files in a nice two-column landscape style.
1758
1759 NOTE: Activate the new setting by restarting Emacs.
1760 Overrides `ps-print' settings locally."
1761 :type 'boolean
1762 :group 'vhdl-print)
1763
1764 (defcustom vhdl-print-customize-faces t
1765 "*Non-nil means use an optimized set of faces for postscript printing.
1766
1767 NOTE: Activate the new setting by restarting Emacs.
1768 Overrides `ps-print' settings locally."
1769 :type 'boolean
1770 :group 'vhdl-print)
1771
1772
1773 (defgroup vhdl-misc nil
1774 "Miscellaneous customizations."
1775 :group 'vhdl)
1776
1777 (defcustom vhdl-intelligent-tab t
1778 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1779 That is, if preceeding character is part of a word then complete word,
1780 else if not at beginning of line then insert tab,
1781 else if last command was a `TAB' or `RET' then dedent one step,
1782 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1783 If nil, TAB always indents current line (i.e. `TAB' is bound to
1784 `indent-according-to-mode').
1785
1786 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1787 \"Activate Options\"."
1788 :type 'boolean
1789 :group 'vhdl-misc)
1790
1791 (defcustom vhdl-indent-syntax-based t
1792 "*Non-nil means indent lines of code based on their syntactic context.
1793 Otherwise, a line is indented like the previous nonblank line. This can be
1794 useful in large files where syntax-based indentation gets very slow."
1795 :type 'boolean
1796 :group 'vhdl-misc)
1797
1798 (defcustom vhdl-word-completion-case-sensitive nil
1799 "*Non-nil means word completion using `TAB' is case sensitive.
1800 That is, `TAB' completes words that start with the same letters and case.
1801 Otherwise, case is ignored."
1802 :type 'boolean
1803 :group 'vhdl-misc)
1804
1805 (defcustom vhdl-word-completion-in-minibuffer t
1806 "*Non-nil enables word completion in minibuffer (for template prompts).
1807
1808 NOTE: Activate the new setting by restarting Emacs."
1809 :type 'boolean
1810 :group 'vhdl-misc)
1811
1812 (defcustom vhdl-underscore-is-part-of-word nil
1813 "*Non-nil means consider the underscore character `_' as part of word.
1814 An identifier containing underscores is then treated as a single word in
1815 select and move operations. All parts of an identifier separated by underscore
1816 are treated as single words otherwise.
1817
1818 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1819 \"Activate Options\"."
1820 :type 'boolean
1821 :set (lambda (variable value)
1822 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1823 :group 'vhdl-misc)
1824
1825
1826 (defgroup vhdl-related nil
1827 "Related general customizations."
1828 :group 'vhdl)
1829
1830 ;; add related general customizations
1831 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1832 (if (featurep 'xemacs)
1833 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1834 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1835 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1836 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1837 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1838 (unless (featurep 'xemacs)
1839 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1840 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1841 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1842 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1843
1844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1845 ;; Internal variables
1846
1847 (defvar vhdl-menu-max-size 20
1848 "*Specifies the maximum size of a menu before splitting it into submenues.")
1849
1850 (defvar vhdl-progress-interval 1
1851 "*Interval used to update progress status during long operations.
1852 If a number, percentage complete gets updated after each interval of
1853 that many seconds. To inhibit all messages, set this option to nil.")
1854
1855 (defvar vhdl-inhibit-startup-warnings-p nil
1856 "*If non-nil, inhibits start up compatibility warnings.")
1857
1858 (defvar vhdl-strict-syntax-p nil
1859 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1860 If the syntactic symbol for a particular line does not match a symbol
1861 in the offsets alist, an error is generated, otherwise no error is
1862 reported and the syntactic symbol is ignored.")
1863
1864 (defvar vhdl-echo-syntactic-information-p nil
1865 "*If non-nil, syntactic info is echoed when the line is indented.")
1866
1867 (defconst vhdl-offsets-alist-default
1868 '((string . -1000)
1869 (cpp-macro . -1000)
1870 (block-open . 0)
1871 (block-close . 0)
1872 (statement . 0)
1873 (statement-cont . vhdl-lineup-statement-cont)
1874 (statement-block-intro . +)
1875 (statement-case-intro . +)
1876 (case-alternative . +)
1877 (comment . vhdl-lineup-comment)
1878 (arglist-intro . +)
1879 (arglist-cont . 0)
1880 (arglist-cont-nonempty . vhdl-lineup-arglist)
1881 (arglist-close . vhdl-lineup-arglist)
1882 (entity . 0)
1883 (configuration . 0)
1884 (package . 0)
1885 (architecture . 0)
1886 (package-body . 0)
1887 )
1888 "Default settings for offsets of syntactic elements.
1889 Do not change this constant! See the variable `vhdl-offsets-alist' for
1890 more information.")
1891
1892 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1893 "*Association list of syntactic element symbols and indentation offsets.
1894 As described below, each cons cell in this list has the form:
1895
1896 (SYNTACTIC-SYMBOL . OFFSET)
1897
1898 When a line is indented, `vhdl-mode' first determines the syntactic
1899 context of the line by generating a list of symbols called syntactic
1900 elements. This list can contain more than one syntactic element and
1901 the global variable `vhdl-syntactic-context' contains the context list
1902 for the line being indented. Each element in this list is actually a
1903 cons cell of the syntactic symbol and a buffer position. This buffer
1904 position is call the relative indent point for the line. Some
1905 syntactic symbols may not have a relative indent point associated with
1906 them.
1907
1908 After the syntactic context list for a line is generated, `vhdl-mode'
1909 calculates the absolute indentation for the line by looking at each
1910 syntactic element in the list. First, it compares the syntactic
1911 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1912 finds a match, it adds the OFFSET to the column of the relative indent
1913 point. The sum of this calculation for each element in the syntactic
1914 list is the absolute offset for line being indented.
1915
1916 If the syntactic element does not match any in the `vhdl-offsets-alist',
1917 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1918 the element is ignored.
1919
1920 Actually, OFFSET can be an integer, a function, a variable, or one of
1921 the following symbols: `+', `-', `++', or `--'. These latter
1922 designate positive or negative multiples of `vhdl-basic-offset',
1923 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1924 called with a single argument containing the cons of the syntactic
1925 element symbol and the relative indent point. The function should
1926 return an integer offset.
1927
1928 Here is the current list of valid syntactic element symbols:
1929
1930 string -- inside multi-line string
1931 block-open -- statement block open
1932 block-close -- statement block close
1933 statement -- a VHDL statement
1934 statement-cont -- a continuation of a VHDL statement
1935 statement-block-intro -- the first line in a new statement block
1936 statement-case-intro -- the first line in a case alternative block
1937 case-alternative -- a case statement alternative clause
1938 comment -- a line containing only a comment
1939 arglist-intro -- the first line in an argument list
1940 arglist-cont -- subsequent argument list lines when no
1941 arguments follow on the same line as the
1942 the arglist opening paren
1943 arglist-cont-nonempty -- subsequent argument list lines when at
1944 least one argument follows on the same
1945 line as the arglist opening paren
1946 arglist-close -- the solo close paren of an argument list
1947 entity -- inside an entity declaration
1948 configuration -- inside a configuration declaration
1949 package -- inside a package declaration
1950 architecture -- inside an architecture body
1951 package-body -- inside a package body")
1952
1953 (defvar vhdl-comment-only-line-offset 0
1954 "*Extra offset for line which contains only the start of a comment.
1955 Can contain an integer or a cons cell of the form:
1956
1957 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1958
1959 Where NON-ANCHORED-OFFSET is the amount of offset given to
1960 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1961 the amount of offset to give column-zero anchored comment-only lines.
1962 Just an integer as value is equivalent to (<val> . 0)")
1963
1964 (defvar vhdl-special-indent-hook nil
1965 "*Hook for user defined special indentation adjustments.
1966 This hook gets called after a line is indented by the mode.")
1967
1968 (defvar vhdl-style-alist
1969 '(("IEEE"
1970 (vhdl-basic-offset . 4)
1971 (vhdl-offsets-alist . ())))
1972 "Styles of Indentation.
1973 Elements of this alist are of the form:
1974
1975 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1976
1977 where STYLE-STRING is a short descriptive string used to select a
1978 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1979 value for that variable when using the selected style.
1980
1981 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1982 case, the VALUE is a list containing elements of the form:
1983
1984 (SYNTACTIC-SYMBOL . VALUE)
1985
1986 as described in `vhdl-offsets-alist'. These are passed directly to
1987 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1988 your style, only those that are different from the default.")
1989
1990 ;; dynamically append the default value of most variables
1991 (or (assoc "Default" vhdl-style-alist)
1992 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1993 vhdl-strict-syntax-p
1994 vhdl-echo-syntactic-information-p
1995 vhdl-basic-offset
1996 vhdl-offsets-alist
1997 vhdl-comment-only-line-offset))
1998 (default (cons "Default"
1999 (mapcar
2000 (function
2001 (lambda (var)
2002 (cons var (symbol-value var))))
2003 varlist))))
2004 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2005
2006 (defvar vhdl-mode-hook nil
2007 "*Hook called by `vhdl-mode'.")
2008
2009
2010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2011 ;;; Required packages
2012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2013
2014 ;; mandatory
2015 (require 'assoc)
2016 (require 'compile) ; XEmacs
2017 (require 'easymenu)
2018 (require 'hippie-exp)
2019
2020 ;; optional (minimize warning messages during compile)
2021 (eval-when-compile
2022 (require 'font-lock)
2023 (require 'ps-print)
2024 (require 'speedbar))
2025
2026
2027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2028 ;;; Compatibility
2029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032 ;; XEmacs compatibility
2033
2034 ;; active regions
2035 (defun vhdl-keep-region-active ()
2036 "Do whatever is necessary to keep the region active in XEmacs.
2037 Ignore byte-compiler warnings you might see."
2038 (and (featurep 'xemacs)
2039 (setq zmacs-region-stays t)))
2040
2041 ;; `wildcard-to-regexp' is included only in XEmacs 21
2042 (unless (fboundp 'wildcard-to-regexp)
2043 (defun wildcard-to-regexp (wildcard)
2044 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2045 (let* ((i (string-match "[*?]" wildcard))
2046 (result (substring wildcard 0 i))
2047 (len (length wildcard)))
2048 (when i
2049 (while (< i len)
2050 (let ((ch (aref wildcard i)))
2051 (setq result (concat result
2052 (cond ((eq ch ?*) "[^\000]*")
2053 ((eq ch ??) "[^\000]")
2054 (t (char-to-string ch)))))
2055 (setq i (1+ i)))))
2056 (concat "\\`" result "\\'"))))
2057
2058 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2059 ;; `regexp-opt' accelerates fontification by 10-20%
2060 (unless (fboundp 'regexp-opt)
2061 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2062 (defun regexp-opt (strings &optional paren)
2063 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2064 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2065
2066 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2067 (unless (fboundp 'match-string-no-properties)
2068 (defalias 'match-string-no-properties 'match-string))
2069
2070 ;; `subst-char-in-string' undefined (XEmacs)
2071 (unless (fboundp 'subst-char-in-string)
2072 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2073 (let ((i (length string))
2074 (newstr (if inplace string (copy-sequence string))))
2075 (while (> i 0)
2076 (setq i (1- i))
2077 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2078 newstr)))
2079
2080 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2081 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2082 (not noninteractive))
2083 (load "itimer")
2084 (when (string< itimer-version "1.09")
2085 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2086 (beep) (sit-for 5)))
2087
2088 ;; `file-expand-wildcards' undefined (XEmacs)
2089 (unless (fboundp 'file-expand-wildcards)
2090 (defun file-expand-wildcards (pattern &optional full)
2091 "Taken from Emacs' `files.el'."
2092 (let* ((nondir (file-name-nondirectory pattern))
2093 (dirpart (file-name-directory pattern))
2094 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2095 (mapcar 'file-name-as-directory
2096 (file-expand-wildcards (directory-file-name dirpart)))
2097 (list dirpart)))
2098 contents)
2099 (while dirs
2100 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2101 (file-directory-p (directory-file-name (car dirs))))
2102 (let ((this-dir-contents
2103 (delq nil
2104 (mapcar #'(lambda (name)
2105 (unless (string-match "\\`\\.\\.?\\'"
2106 (file-name-nondirectory name))
2107 name))
2108 (directory-files (or (car dirs) ".") full
2109 (wildcard-to-regexp nondir))))))
2110 (setq contents
2111 (nconc
2112 (if (and (car dirs) (not full))
2113 (mapcar (function (lambda (name) (concat (car dirs) name)))
2114 this-dir-contents)
2115 this-dir-contents)
2116 contents))))
2117 (setq dirs (cdr dirs)))
2118 contents)))
2119
2120 ;; `member-ignore-case' undefined (XEmacs)
2121 (unless (fboundp 'member-ignore-case)
2122 (defalias 'member-ignore-case 'member))
2123
2124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2125 ;; Compatibility with older VHDL Mode versions
2126
2127 (defvar vhdl-warnings nil
2128 "Warnings to tell the user during start up.")
2129
2130 (defun vhdl-run-when-idle (secs repeat function)
2131 "Wait until idle, then run FUNCTION."
2132 (if (fboundp 'start-itimer)
2133 (start-itimer "vhdl-mode" function secs repeat t)
2134 ; (run-with-idle-timer secs repeat function)))
2135 ;; explicitely activate timer (necessary when Emacs is already idle)
2136 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2137
2138 (defun vhdl-warning-when-idle (&rest args)
2139 "Wait until idle, then print out warning STRING and beep."
2140 (if noninteractive
2141 (vhdl-warning (apply 'format args) t)
2142 (unless vhdl-warnings
2143 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2144 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2145
2146 (defun vhdl-warning (string &optional nobeep)
2147 "Print out warning STRING and beep."
2148 (message "WARNING: %s" string)
2149 (unless (or nobeep noninteractive) (beep)))
2150
2151 (defun vhdl-print-warnings ()
2152 "Print out messages in variable `vhdl-warnings'."
2153 (let ((no-warnings (length vhdl-warnings)))
2154 (setq vhdl-warnings (nreverse vhdl-warnings))
2155 (while vhdl-warnings
2156 (message "WARNING: %s" (car vhdl-warnings))
2157 (setq vhdl-warnings (cdr vhdl-warnings)))
2158 (beep)
2159 (when (> no-warnings 1)
2160 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2161
2162 ;; Backward compatibility checks and fixes
2163 ;; option `vhdl-compiler' changed format
2164 (unless (stringp vhdl-compiler)
2165 (setq vhdl-compiler "ModelSim")
2166 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2167
2168 ;; option `vhdl-standard' changed format
2169 (unless (listp vhdl-standard)
2170 (setq vhdl-standard '(87 nil))
2171 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2172
2173 ;; option `vhdl-model-alist' changed format
2174 (when (= (length (car vhdl-model-alist)) 3)
2175 (let ((old-alist vhdl-model-alist)
2176 new-alist)
2177 (while old-alist
2178 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2179 (setq old-alist (cdr old-alist)))
2180 (setq vhdl-model-alist (nreverse new-alist)))
2181 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2182
2183 ;; option `vhdl-project-alist' changed format
2184 (when (= (length (car vhdl-project-alist)) 3)
2185 (let ((old-alist vhdl-project-alist)
2186 new-alist)
2187 (while old-alist
2188 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2189 (setq old-alist (cdr old-alist)))
2190 (setq vhdl-project-alist (nreverse new-alist)))
2191 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2192
2193 ;; option `vhdl-project-alist' changed format (3.31.1)
2194 (when (= (length (car vhdl-project-alist)) 4)
2195 (let ((old-alist vhdl-project-alist)
2196 new-alist elem)
2197 (while old-alist
2198 (setq elem (car old-alist))
2199 (setq new-alist
2200 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2201 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2202 new-alist))
2203 (setq old-alist (cdr old-alist)))
2204 (setq vhdl-project-alist (nreverse new-alist)))
2205 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2206
2207 ;; option `vhdl-project-alist' changed format (3.31.12)
2208 (when (= (length (car vhdl-project-alist)) 10)
2209 (let ((tmp-alist vhdl-project-alist))
2210 (while tmp-alist
2211 (setcdr (nthcdr 3 (car tmp-alist))
2212 (cons "" (nthcdr 4 (car tmp-alist))))
2213 (setq tmp-alist (cdr tmp-alist))))
2214 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2215
2216 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2217 (when (= (length (car vhdl-compiler-alist)) 7)
2218 (let ((old-alist vhdl-compiler-alist)
2219 new-alist elem)
2220 (while old-alist
2221 (setq elem (car old-alist))
2222 (setq new-alist
2223 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2224 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2225 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2226 (nth 5 elem) (nth 6 elem) nil)
2227 new-alist))
2228 (setq old-alist (cdr old-alist)))
2229 (setq vhdl-compiler-alist (nreverse new-alist)))
2230 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2231
2232 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2233 (when (= (length (car vhdl-compiler-alist)) 12)
2234 (let ((tmp-alist vhdl-compiler-alist))
2235 (while tmp-alist
2236 (setcdr (nthcdr 4 (car tmp-alist))
2237 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2238 (setq tmp-alist (cdr tmp-alist))))
2239 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2240
2241 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2242 (when (= (length (car vhdl-compiler-alist)) 13)
2243 (let ((tmp-alist vhdl-compiler-alist))
2244 (while tmp-alist
2245 (setcdr (nthcdr 3 (car tmp-alist))
2246 (cons "" (nthcdr 4 (car tmp-alist))))
2247 (setq tmp-alist (cdr tmp-alist))))
2248 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2249
2250 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2251 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2252 (let ((tmp-alist vhdl-compiler-alist))
2253 (while tmp-alist
2254 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2255 '(0 . nil))
2256 (setq tmp-alist (cdr tmp-alist))))
2257 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2258
2259 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2260 (when (equal vhdl-project "")
2261 (setq vhdl-project nil)
2262 (customize-save-variable 'vhdl-project vhdl-project))
2263
2264 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2265 (when (stringp vhdl-project-file-name)
2266 (setq vhdl-project-file-name (list vhdl-project-file-name))
2267 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2268
2269 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2270 (if (not (boundp 'speedbar-indentation-width))
2271 (defvar speedbar-indentation-width 2)
2272 ;; set default to 2 if not already customized
2273 (unless (get 'speedbar-indentation-width 'saved-value)
2274 (setq speedbar-indentation-width 2)))
2275
2276
2277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2278 ;;; Help functions / inline substitutions / macros
2279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2280
2281 (defun vhdl-standard-p (standard)
2282 "Check if STANDARD is specified as used standard."
2283 (or (eq standard (car vhdl-standard))
2284 (memq standard (cadr vhdl-standard))))
2285
2286 (defun vhdl-project-p (&optional warning)
2287 "Return non-nil if a project is displayed, i.e. directories or files are
2288 specified."
2289 (if (assoc vhdl-project vhdl-project-alist)
2290 vhdl-project
2291 (when (and vhdl-project warning)
2292 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2293 nil))
2294
2295 (defun vhdl-resolve-env-variable (string)
2296 "Resolve environment variables in STRING."
2297 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2298 (setq string (concat (match-string 1 string)
2299 (getenv (match-string 2 string))
2300 (match-string 4 string))))
2301 string)
2302
2303 (defun vhdl-default-directory ()
2304 "Return the default directory of the current project or the directory of the
2305 current buffer if no project is defined."
2306 (if (vhdl-project-p)
2307 (expand-file-name (vhdl-resolve-env-variable
2308 (nth 1 (aget vhdl-project-alist vhdl-project))))
2309 default-directory))
2310
2311 (defmacro vhdl-prepare-search-1 (&rest body)
2312 "Enable case insensitive search and switch to syntax table that includes '_',
2313 then execute BODY, and finally restore the old environment. Used for
2314 consistent searching."
2315 `(let ((case-fold-search t)) ; case insensitive search
2316 ;; use extended syntax table
2317 (with-syntax-table vhdl-mode-ext-syntax-table
2318 ,@body)))
2319
2320 (defmacro vhdl-prepare-search-2 (&rest body)
2321 "Enable case insensitive search, switch to syntax table that includes '_',
2322 and remove `intangible' overlays, then execute BODY, and finally restore the
2323 old environment. Used for consistent searching."
2324 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2325 `(let ((case-fold-search t) ; case insensitive search
2326 (current-syntax-table (syntax-table))
2327 overlay-all-list overlay-intangible-list overlay)
2328 ;; use extended syntax table
2329 (set-syntax-table vhdl-mode-ext-syntax-table)
2330 ;; remove `intangible' overlays
2331 (when (fboundp 'overlay-lists)
2332 (setq overlay-all-list (overlay-lists))
2333 (setq overlay-all-list
2334 (append (car overlay-all-list) (cdr overlay-all-list)))
2335 (while overlay-all-list
2336 (setq overlay (car overlay-all-list))
2337 (when (memq 'intangible (overlay-properties overlay))
2338 (setq overlay-intangible-list
2339 (cons overlay overlay-intangible-list))
2340 (overlay-put overlay 'intangible nil))
2341 (setq overlay-all-list (cdr overlay-all-list))))
2342 ;; execute BODY safely
2343 (unwind-protect
2344 (progn ,@body)
2345 ;; restore syntax table
2346 (set-syntax-table current-syntax-table)
2347 ;; restore `intangible' overlays
2348 (when (fboundp 'overlay-lists)
2349 (while overlay-intangible-list
2350 (overlay-put (car overlay-intangible-list) 'intangible t)
2351 (setq overlay-intangible-list
2352 (cdr overlay-intangible-list)))))))
2353
2354 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2355 "Visit file FILE-NAME and execute BODY."
2356 `(if (null ,file-name)
2357 (progn ,@body)
2358 (unless (file-directory-p ,file-name)
2359 (let ((source-buffer (current-buffer))
2360 (visiting-buffer (find-buffer-visiting ,file-name))
2361 file-opened)
2362 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2363 (condition-case ()
2364 (progn (set-buffer (create-file-buffer ,file-name))
2365 (setq file-opened t)
2366 (vhdl-insert-file-contents ,file-name)
2367 (modify-syntax-entry ?\- ". 12" (syntax-table))
2368 (modify-syntax-entry ?\n ">" (syntax-table))
2369 (modify-syntax-entry ?\^M ">" (syntax-table))
2370 (modify-syntax-entry ?_ "w" (syntax-table))
2371 t)
2372 (error
2373 (if ,issue-error
2374 (progn
2375 (when file-opened (kill-buffer (current-buffer)))
2376 (set-buffer source-buffer)
2377 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2378 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2379 nil))))
2380 (condition-case info
2381 (progn ,@body)
2382 (error
2383 (if ,issue-error
2384 (progn
2385 (when file-opened (kill-buffer (current-buffer)))
2386 (set-buffer source-buffer)
2387 (error (cadr info)))
2388 (vhdl-warning (cadr info))))))
2389 (when file-opened (kill-buffer (current-buffer)))
2390 (set-buffer source-buffer)))))
2391
2392 (defun vhdl-insert-file-contents (filename)
2393 "Nicked from `insert-file-contents-literally', but allow coding system
2394 conversion."
2395 (let ((format-alist nil)
2396 (after-insert-file-functions nil)
2397 (jka-compr-compression-info-list nil))
2398 (insert-file-contents filename t)))
2399
2400 (defun vhdl-sort-alist (alist)
2401 "Sort ALIST."
2402 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2403
2404 (defun vhdl-get-subdirs (directory)
2405 "Recursively get subdirectories of DIRECTORY."
2406 (let ((dir-list (list (file-name-as-directory directory)))
2407 file-list)
2408 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2409 (while file-list
2410 (when (file-directory-p (car file-list))
2411 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2412 (setq file-list (cdr file-list)))
2413 dir-list))
2414
2415 (defun vhdl-aput (alist-symbol key &optional value)
2416 "As `aput', but delete key-value pair if VALUE is nil."
2417 (if value
2418 (aput alist-symbol key value)
2419 (adelete alist-symbol key)))
2420
2421 (defun vhdl-delete (elt list)
2422 "Delete by side effect the first occurrence of ELT as a member of LIST."
2423 (setq list (cons nil list))
2424 (let ((list1 list))
2425 (while (and (cdr list1) (not (equal elt (cadr list1))))
2426 (setq list1 (cdr list1)))
2427 (when list
2428 (setcdr list1 (cddr list1))))
2429 (cdr list))
2430
2431 (defun vhdl-speedbar-refresh (&optional key)
2432 "Refresh directory or project with name KEY."
2433 (when (and (boundp 'speedbar-frame)
2434 (frame-live-p speedbar-frame))
2435 (let ((pos (point))
2436 (last-frame (selected-frame)))
2437 (if (null key)
2438 (speedbar-refresh)
2439 (select-frame speedbar-frame)
2440 (when (save-excursion
2441 (goto-char (point-min))
2442 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2443 (goto-char (match-end 1))
2444 (speedbar-do-function-pointer)
2445 (backward-char 2)
2446 (speedbar-do-function-pointer)
2447 (message "Refreshing speedbar...done"))
2448 (select-frame last-frame)))))
2449
2450 (defun vhdl-show-messages ()
2451 "Get *Messages* buffer to show recent messages."
2452 (interactive)
2453 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2454
2455 (defun vhdl-use-direct-instantiation ()
2456 "Return whether direct instantiation is used."
2457 (or (eq vhdl-use-direct-instantiation 'always)
2458 (and (eq vhdl-use-direct-instantiation 'standard)
2459 (not (vhdl-standard-p '87)))))
2460
2461 (defun vhdl-max-marker (marker1 marker2)
2462 "Return larger marker."
2463 (if (> marker1 marker2) marker1 marker2))
2464
2465 (defun vhdl-goto-marker (marker)
2466 "Goto marker in appropriate buffer."
2467 (when (markerp marker)
2468 (set-buffer (marker-buffer marker)))
2469 (goto-char marker))
2470
2471 (defun vhdl-menu-split (list title)
2472 "Split menu LIST into several submenues, if number of
2473 elements > `vhdl-menu-max-size'."
2474 (if (> (length list) vhdl-menu-max-size)
2475 (let ((remain list)
2476 (result '())
2477 (sublist '())
2478 (menuno 1)
2479 (i 0))
2480 (while remain
2481 (setq sublist (cons (car remain) sublist))
2482 (setq remain (cdr remain))
2483 (setq i (+ i 1))
2484 (if (= i vhdl-menu-max-size)
2485 (progn
2486 (setq result (cons (cons (format "%s %s" title menuno)
2487 (nreverse sublist)) result))
2488 (setq i 0)
2489 (setq menuno (+ menuno 1))
2490 (setq sublist '()))))
2491 (and sublist
2492 (setq result (cons (cons (format "%s %s" title menuno)
2493 (nreverse sublist)) result)))
2494 (nreverse result))
2495 list))
2496
2497
2498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2499 ;;; Bindings
2500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2501
2502 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2503 ;; Key bindings
2504
2505 (defvar vhdl-template-map nil
2506 "Keymap for VHDL templates.")
2507
2508 (defun vhdl-template-map-init ()
2509 "Initialize `vhdl-template-map'."
2510 (setq vhdl-template-map (make-sparse-keymap))
2511 ;; key bindings for VHDL templates
2512 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2513 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2514 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2515 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2516 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2517 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2518 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2519 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2520 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2521 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2522 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2523 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2524 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2525 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2526 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2527 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2528 (define-key vhdl-template-map "el" 'vhdl-template-else)
2529 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2530 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2531 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2532 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2533 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2534 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2535 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2536 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2537 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2538 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2539 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2540 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2541 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2542 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2543 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2544 (define-key vhdl-template-map "li" 'vhdl-template-library)
2545 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2546 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2547 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2548 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2549 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2550 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2551 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2552 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2553 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2554 (define-key vhdl-template-map "po" 'vhdl-template-port)
2555 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2556 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2557 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2558 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2559 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2560 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2561 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2562 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2563 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2564 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2565 (define-key vhdl-template-map "us" 'vhdl-template-use)
2566 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2567 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2568 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2569 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2570 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2571 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2572 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2573 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2574 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2575 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2576 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2577 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2578 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2579 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2580 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2581 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2582 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2583 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2584 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2585 (when (vhdl-standard-p 'ams)
2586 (define-key vhdl-template-map "br" 'vhdl-template-break)
2587 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2588 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2589 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2590 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2591 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2592 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2593 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2594 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2595 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2596 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2597 )
2598 (when (vhdl-standard-p 'math)
2599 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2600 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2601 ))
2602
2603 ;; initialize template map for VHDL Mode
2604 (vhdl-template-map-init)
2605
2606 (defun vhdl-function-name (prefix string &optional postfix)
2607 "Generate a Lisp function name.
2608 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2609 STRING are replaced by `-' and substrings are converted to lower case."
2610 (let ((name prefix))
2611 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2612 (setq name
2613 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2614 (setq string (substring string (match-beginning 2))))
2615 (when postfix (setq name (concat name "-" postfix)))
2616 (intern name)))
2617
2618 (defvar vhdl-model-map nil
2619 "Keymap for VHDL models.")
2620
2621 (defun vhdl-model-map-init ()
2622 "Initialize `vhdl-model-map'."
2623 (setq vhdl-model-map (make-sparse-keymap))
2624 ;; key bindings for VHDL models
2625 (let ((model-alist vhdl-model-alist) model)
2626 (while model-alist
2627 (setq model (car model-alist))
2628 (define-key vhdl-model-map (nth 2 model)
2629 (vhdl-function-name "vhdl-model" (nth 0 model)))
2630 (setq model-alist (cdr model-alist)))))
2631
2632 ;; initialize user model map for VHDL Mode
2633 (vhdl-model-map-init)
2634
2635 (defvar vhdl-mode-map nil
2636 "Keymap for VHDL Mode.")
2637
2638 (defun vhdl-mode-map-init ()
2639 "Initialize `vhdl-mode-map'."
2640 (setq vhdl-mode-map (make-sparse-keymap))
2641 ;; template key bindings
2642 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2643 ;; model key bindings
2644 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2645 ;; standard key bindings
2646 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2647 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2648 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2649 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2650 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2651 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2652 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2653 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2654 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2655 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2656 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2657 ;; backspace/delete key bindings
2658 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2659 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2660 (define-key vhdl-mode-map [delete] 'delete-char)
2661 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2662 ;; mode specific key bindings
2663 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2664 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2665 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2666 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2668 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2669 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2670 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2671 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2672 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2673 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2674 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2675 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2678 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2679 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2680 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2681 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2682 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2683 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2684 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2685 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2686 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2687 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2688 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2689 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2692 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2693 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2694 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2698 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2699 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2700 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2701 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2702 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2703 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2704 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2705 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2709 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2710 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2711 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2712 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2713 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2714 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2717 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2718 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2719 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2720 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2721 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2722 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2723 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2727 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2728 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2729 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2730 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2731 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2732 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2733 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2734 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2735 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2736 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2737 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2739 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2740 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2741 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2742 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2743 ;; insert commands bindings
2744 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2745 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2746 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2747 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2748 ;; electric key bindings
2749 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2750 (when vhdl-intelligent-tab
2751 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2752 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2753 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2754 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2755 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2756 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2757 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2758 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2759 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2760 (when (vhdl-standard-p 'ams)
2761 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2762
2763 ;; initialize mode map for VHDL Mode
2764 (vhdl-mode-map-init)
2765
2766 ;; define special minibuffer keymap for enabling word completion in minibuffer
2767 ;; (useful in template generator prompts)
2768 (defvar vhdl-minibuffer-local-map
2769 (let ((map (make-sparse-keymap)))
2770 (set-keymap-parent map minibuffer-local-map)
2771 (when vhdl-word-completion-in-minibuffer
2772 (define-key map "\t" 'vhdl-minibuffer-tab))
2773 map)
2774 "Keymap for minibuffer used in VHDL Mode.")
2775
2776 ;; set up electric character functions to work with
2777 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2778 (mapc
2779 (function
2780 (lambda (sym)
2781 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2782 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2783 '(vhdl-electric-space
2784 vhdl-electric-tab
2785 vhdl-electric-return
2786 vhdl-electric-dash
2787 vhdl-electric-open-bracket
2788 vhdl-electric-close-bracket
2789 vhdl-electric-quote
2790 vhdl-electric-semicolon
2791 vhdl-electric-comma
2792 vhdl-electric-period
2793 vhdl-electric-equal))
2794
2795 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2796 ;; Syntax table
2797
2798 (defvar vhdl-mode-syntax-table nil
2799 "Syntax table used in `vhdl-mode' buffers.")
2800
2801 (defvar vhdl-mode-ext-syntax-table nil
2802 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2803
2804 (defun vhdl-mode-syntax-table-init ()
2805 "Initialize `vhdl-mode-syntax-table'."
2806 (setq vhdl-mode-syntax-table (make-syntax-table))
2807 ;; define punctuation
2808 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2809 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2810 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2811 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2812 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2813 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2814 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2815 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2816 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2817 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2818 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2819 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2820 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2821 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2822 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2823 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2824 ;; define string
2825 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2826 ;; define underscore
2827 (when vhdl-underscore-is-part-of-word
2828 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2829 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2830 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2831 ;; and \n and \^M end a comment
2832 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2833 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2834 ;; define parentheses to match
2835 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2836 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2839 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2840 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2841 ;; extended syntax table including '_' (for simpler search regexps)
2842 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2843 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2844
2845 ;; initialize syntax table for VHDL Mode
2846 (vhdl-mode-syntax-table-init)
2847
2848 (defvar vhdl-syntactic-context nil
2849 "Buffer local variable containing syntactic analysis list.")
2850 (make-variable-buffer-local 'vhdl-syntactic-context)
2851
2852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2853 ;; Abbrev ook bindings
2854
2855 (defvar vhdl-mode-abbrev-table nil
2856 "Abbrev table to use in `vhdl-mode' buffers.")
2857
2858 (defun vhdl-mode-abbrev-table-init ()
2859 "Initialize `vhdl-mode-abbrev-table'."
2860 (define-abbrev-table 'vhdl-mode-abbrev-table
2861 (append
2862 (when (memq 'vhdl vhdl-electric-keywords)
2863 ;; VHDL'93 keywords
2864 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2865 '(
2866 ("--" . vhdl-template-display-comment-hook)
2867 ("abs" . vhdl-template-default-hook)
2868 ("access" . vhdl-template-default-hook)
2869 ("after" . vhdl-template-default-hook)
2870 ("alias" . vhdl-template-alias-hook)
2871 ("all" . vhdl-template-default-hook)
2872 ("and" . vhdl-template-default-hook)
2873 ("arch" . vhdl-template-architecture-hook)
2874 ("architecture" . vhdl-template-architecture-hook)
2875 ("array" . vhdl-template-default-hook)
2876 ("assert" . vhdl-template-assert-hook)
2877 ("attr" . vhdl-template-attribute-hook)
2878 ("attribute" . vhdl-template-attribute-hook)
2879 ("begin" . vhdl-template-default-indent-hook)
2880 ("block" . vhdl-template-block-hook)
2881 ("body" . vhdl-template-default-hook)
2882 ("buffer" . vhdl-template-default-hook)
2883 ("bus" . vhdl-template-default-hook)
2884 ("case" . vhdl-template-case-hook)
2885 ("comp" . vhdl-template-component-hook)
2886 ("component" . vhdl-template-component-hook)
2887 ("cond" . vhdl-template-conditional-signal-asst-hook)
2888 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2889 ("conf" . vhdl-template-configuration-hook)
2890 ("configuration" . vhdl-template-configuration-hook)
2891 ("cons" . vhdl-template-constant-hook)
2892 ("constant" . vhdl-template-constant-hook)
2893 ("disconnect" . vhdl-template-disconnect-hook)
2894 ("downto" . vhdl-template-default-hook)
2895 ("else" . vhdl-template-else-hook)
2896 ("elseif" . vhdl-template-elsif-hook)
2897 ("elsif" . vhdl-template-elsif-hook)
2898 ("end" . vhdl-template-default-indent-hook)
2899 ("entity" . vhdl-template-entity-hook)
2900 ("exit" . vhdl-template-exit-hook)
2901 ("file" . vhdl-template-file-hook)
2902 ("for" . vhdl-template-for-hook)
2903 ("func" . vhdl-template-function-hook)
2904 ("function" . vhdl-template-function-hook)
2905 ("generic" . vhdl-template-generic-hook)
2906 ("group" . vhdl-template-group-hook)
2907 ("guarded" . vhdl-template-default-hook)
2908 ("if" . vhdl-template-if-hook)
2909 ("impure" . vhdl-template-default-hook)
2910 ("in" . vhdl-template-default-hook)
2911 ("inertial" . vhdl-template-default-hook)
2912 ("inout" . vhdl-template-default-hook)
2913 ("inst" . vhdl-template-instance-hook)
2914 ("instance" . vhdl-template-instance-hook)
2915 ("is" . vhdl-template-default-hook)
2916 ("label" . vhdl-template-default-hook)
2917 ("library" . vhdl-template-library-hook)
2918 ("linkage" . vhdl-template-default-hook)
2919 ("literal" . vhdl-template-default-hook)
2920 ("loop" . vhdl-template-bare-loop-hook)
2921 ("map" . vhdl-template-map-hook)
2922 ("mod" . vhdl-template-default-hook)
2923 ("nand" . vhdl-template-default-hook)
2924 ("new" . vhdl-template-default-hook)
2925 ("next" . vhdl-template-next-hook)
2926 ("nor" . vhdl-template-default-hook)
2927 ("not" . vhdl-template-default-hook)
2928 ("null" . vhdl-template-default-hook)
2929 ("of" . vhdl-template-default-hook)
2930 ("on" . vhdl-template-default-hook)
2931 ("open" . vhdl-template-default-hook)
2932 ("or" . vhdl-template-default-hook)
2933 ("others" . vhdl-template-others-hook)
2934 ("out" . vhdl-template-default-hook)
2935 ("pack" . vhdl-template-package-hook)
2936 ("package" . vhdl-template-package-hook)
2937 ("port" . vhdl-template-port-hook)
2938 ("postponed" . vhdl-template-default-hook)
2939 ("procedure" . vhdl-template-procedure-hook)
2940 ("process" . vhdl-template-process-hook)
2941 ("pure" . vhdl-template-default-hook)
2942 ("range" . vhdl-template-default-hook)
2943 ("record" . vhdl-template-default-hook)
2944 ("register" . vhdl-template-default-hook)
2945 ("reject" . vhdl-template-default-hook)
2946 ("rem" . vhdl-template-default-hook)
2947 ("report" . vhdl-template-report-hook)
2948 ("return" . vhdl-template-return-hook)
2949 ("rol" . vhdl-template-default-hook)
2950 ("ror" . vhdl-template-default-hook)
2951 ("select" . vhdl-template-selected-signal-asst-hook)
2952 ("severity" . vhdl-template-default-hook)
2953 ("shared" . vhdl-template-default-hook)
2954 ("sig" . vhdl-template-signal-hook)
2955 ("signal" . vhdl-template-signal-hook)
2956 ("sla" . vhdl-template-default-hook)
2957 ("sll" . vhdl-template-default-hook)
2958 ("sra" . vhdl-template-default-hook)
2959 ("srl" . vhdl-template-default-hook)
2960 ("subtype" . vhdl-template-subtype-hook)
2961 ("then" . vhdl-template-default-hook)
2962 ("to" . vhdl-template-default-hook)
2963 ("transport" . vhdl-template-default-hook)
2964 ("type" . vhdl-template-type-hook)
2965 ("unaffected" . vhdl-template-default-hook)
2966 ("units" . vhdl-template-default-hook)
2967 ("until" . vhdl-template-default-hook)
2968 ("use" . vhdl-template-use-hook)
2969 ("var" . vhdl-template-variable-hook)
2970 ("variable" . vhdl-template-variable-hook)
2971 ("wait" . vhdl-template-wait-hook)
2972 ("when" . vhdl-template-when-hook)
2973 ("while" . vhdl-template-while-loop-hook)
2974 ("with" . vhdl-template-with-hook)
2975 ("xnor" . vhdl-template-default-hook)
2976 ("xor" . vhdl-template-default-hook)
2977 )))
2978 ;; VHDL-AMS keywords
2979 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2980 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2981 '(
2982 ("across" . vhdl-template-default-hook)
2983 ("break" . vhdl-template-break-hook)
2984 ("limit" . vhdl-template-limit-hook)
2985 ("nature" . vhdl-template-nature-hook)
2986 ("noise" . vhdl-template-default-hook)
2987 ("procedural" . vhdl-template-procedural-hook)
2988 ("quantity" . vhdl-template-quantity-hook)
2989 ("reference" . vhdl-template-default-hook)
2990 ("spectrum" . vhdl-template-default-hook)
2991 ("subnature" . vhdl-template-subnature-hook)
2992 ("terminal" . vhdl-template-terminal-hook)
2993 ("through" . vhdl-template-default-hook)
2994 ("tolerance" . vhdl-template-default-hook)
2995 )))
2996 ;; user model keywords
2997 (when (memq 'user vhdl-electric-keywords)
2998 (let (abbrev-list keyword)
2999 (dolist (elem vhdl-model-alist)
3000 (setq keyword (nth 3 elem))
3001 (unless (equal keyword "")
3002 (push (list keyword ""
3003 (vhdl-function-name
3004 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3005 abbrev-list)))
3006 abbrev-list)))))
3007
3008 ;; initialize abbrev table for VHDL Mode
3009 (vhdl-mode-abbrev-table-init)
3010
3011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3012 ;; Template completion lists
3013
3014 (defvar vhdl-template-construct-alist nil
3015 "List of built-in construct templates.")
3016
3017 (defun vhdl-template-construct-alist-init ()
3018 "Initialize `vhdl-template-construct-alist'."
3019 (setq
3020 vhdl-template-construct-alist
3021 (append
3022 '(
3023 ("alias declaration" vhdl-template-alias)
3024 ("architecture body" vhdl-template-architecture)
3025 ("assertion" vhdl-template-assert)
3026 ("attribute declaration" vhdl-template-attribute-decl)
3027 ("attribute specification" vhdl-template-attribute-spec)
3028 ("block configuration" vhdl-template-block-configuration)
3029 ("block statement" vhdl-template-block)
3030 ("case statement" vhdl-template-case-is)
3031 ("component configuration" vhdl-template-component-conf)
3032 ("component declaration" vhdl-template-component-decl)
3033 ("component instantiation statement" vhdl-template-component-inst)
3034 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3035 ("configuration declaration" vhdl-template-configuration-decl)
3036 ("configuration specification" vhdl-template-configuration-spec)
3037 ("constant declaration" vhdl-template-constant)
3038 ("disconnection specification" vhdl-template-disconnect)
3039 ("entity declaration" vhdl-template-entity)
3040 ("exit statement" vhdl-template-exit)
3041 ("file declaration" vhdl-template-file)
3042 ("generate statement" vhdl-template-generate)
3043 ("generic clause" vhdl-template-generic)
3044 ("group declaration" vhdl-template-group-decl)
3045 ("group template declaration" vhdl-template-group-template)
3046 ("if statement" vhdl-template-if-then)
3047 ("library clause" vhdl-template-library)
3048 ("loop statement" vhdl-template-loop)
3049 ("next statement" vhdl-template-next)
3050 ("package declaration" vhdl-template-package-decl)
3051 ("package body" vhdl-template-package-body)
3052 ("port clause" vhdl-template-port)
3053 ("process statement" vhdl-template-process)
3054 ("report statement" vhdl-template-report)
3055 ("return statement" vhdl-template-return)
3056 ("selected signal assignment" vhdl-template-selected-signal-asst)
3057 ("signal declaration" vhdl-template-signal)
3058 ("subprogram declaration" vhdl-template-subprogram-decl)
3059 ("subprogram body" vhdl-template-subprogram-body)
3060 ("subtype declaration" vhdl-template-subtype)
3061 ("type declaration" vhdl-template-type)
3062 ("use clause" vhdl-template-use)
3063 ("variable declaration" vhdl-template-variable)
3064 ("wait statement" vhdl-template-wait)
3065 )
3066 (when (vhdl-standard-p 'ams)
3067 '(
3068 ("break statement" vhdl-template-break)
3069 ("nature declaration" vhdl-template-nature)
3070 ("quantity declaration" vhdl-template-quantity)
3071 ("simultaneous case statement" vhdl-template-case-use)
3072 ("simultaneous if statement" vhdl-template-if-use)
3073 ("simultaneous procedural statement" vhdl-template-procedural)
3074 ("step limit specification" vhdl-template-limit)
3075 ("subnature declaration" vhdl-template-subnature)
3076 ("terminal declaration" vhdl-template-terminal)
3077 )))))
3078
3079 ;; initialize for VHDL Mode
3080 (vhdl-template-construct-alist-init)
3081
3082 (defvar vhdl-template-package-alist nil
3083 "List of built-in package templates.")
3084
3085 (defun vhdl-template-package-alist-init ()
3086 "Initialize `vhdl-template-package-alist'."
3087 (setq
3088 vhdl-template-package-alist
3089 (append
3090 '(
3091 ("numeric_bit" vhdl-template-package-numeric-bit)
3092 ("numeric_std" vhdl-template-package-numeric-std)
3093 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3094 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3095 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3096 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3097 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3098 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3099 ("textio" vhdl-template-package-textio)
3100 )
3101 (when (vhdl-standard-p 'math)
3102 '(
3103 ("math_complex" vhdl-template-package-math-complex)
3104 ("math_real" vhdl-template-package-math-real)
3105 )))))
3106
3107 ;; initialize for VHDL Mode
3108 (vhdl-template-package-alist-init)
3109
3110 (defvar vhdl-template-directive-alist
3111 '(
3112 ("translate_on" vhdl-template-directive-translate-on)
3113 ("translate_off" vhdl-template-directive-translate-off)
3114 ("synthesis_on" vhdl-template-directive-synthesis-on)
3115 ("synthesis_off" vhdl-template-directive-synthesis-off)
3116 )
3117 "List of built-in directive templates.")
3118
3119
3120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3121 ;;; Menues
3122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3123
3124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3125 ;; VHDL menu (using `easy-menu.el')
3126
3127 (defun vhdl-customize ()
3128 "Call the customize function with `vhdl' as argument."
3129 (interactive)
3130 (customize-browse 'vhdl))
3131
3132 (defun vhdl-create-mode-menu ()
3133 "Create VHDL Mode menu."
3134 `("VHDL"
3135 ,(append
3136 '("Project"
3137 ["None" (vhdl-set-project "")
3138 :style radio :selected (null vhdl-project)]
3139 "--")
3140 ;; add menu entries for defined projects
3141 (let ((project-alist vhdl-project-alist) menu-list name)
3142 (while project-alist
3143 (setq name (caar project-alist))
3144 (setq menu-list
3145 (cons `[,name (vhdl-set-project ,name)
3146 :style radio :selected (equal ,name vhdl-project)]
3147 menu-list))
3148 (setq project-alist (cdr project-alist)))
3149 (setq menu-list
3150 (if vhdl-project-sort
3151 (sort menu-list
3152 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3153 (nreverse menu-list)))
3154 (vhdl-menu-split menu-list "Project"))
3155 '("--" "--"
3156 ["Select Project..." vhdl-set-project t]
3157 ["Set As Default Project" vhdl-set-default-project t]
3158 "--"
3159 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3160 ["Import Project..." vhdl-import-project
3161 :keys "C-c C-p C-m" :active t]
3162 ["Export Project" vhdl-export-project vhdl-project]
3163 "--"
3164 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3165 "--"
3166 ("Compile"
3167 ["Compile Buffer" vhdl-compile t]
3168 ["Stop Compilation" kill-compilation t]
3169 "--"
3170 ["Make" vhdl-make t]
3171 ["Generate Makefile" vhdl-generate-makefile t]
3172 "--"
3173 ["Next Error" next-error t]
3174 ["Previous Error" previous-error t]
3175 ["First Error" first-error t]
3176 "--"
3177 ,(append
3178 '("Compiler")
3179 ;; add menu entries for defined compilers
3180 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3181 (while comp-alist
3182 (setq name (caar comp-alist))
3183 (setq menu-list
3184 (cons `[,name (setq vhdl-compiler ,name)
3185 :style radio :selected (equal ,name vhdl-compiler)]
3186 menu-list))
3187 (setq comp-alist (cdr comp-alist)))
3188 (setq menu-list (nreverse menu-list))
3189 (vhdl-menu-split menu-list "Compiler"))
3190 '("--" "--"
3191 ["Select Compiler..." vhdl-set-compiler t]
3192 "--"
3193 ["Customize Compiler..."
3194 (customize-option 'vhdl-compiler-alist) t])))
3195 "--"
3196 ,(append
3197 '("Template"
3198 ("VHDL Construct 1"
3199 ["Alias" vhdl-template-alias t]
3200 ["Architecture" vhdl-template-architecture t]
3201 ["Assert" vhdl-template-assert t]
3202 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3203 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3204 ["Block" vhdl-template-block t]
3205 ["Case" vhdl-template-case-is t]
3206 ["Component (Decl)" vhdl-template-component-decl t]
3207 ["(Component) Instance" vhdl-template-component-inst t]
3208 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3209 ["Configuration (Block)" vhdl-template-block-configuration t]
3210 ["Configuration (Comp)" vhdl-template-component-conf t]
3211 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3212 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3213 ["Constant" vhdl-template-constant t]
3214 ["Disconnect" vhdl-template-disconnect t]
3215 ["Else" vhdl-template-else t]
3216 ["Elsif" vhdl-template-elsif t]
3217 ["Entity" vhdl-template-entity t]
3218 ["Exit" vhdl-template-exit t]
3219 ["File" vhdl-template-file t]
3220 ["For (Generate)" vhdl-template-for-generate t]
3221 ["For (Loop)" vhdl-template-for-loop t]
3222 ["Function (Body)" vhdl-template-function-body t]
3223 ["Function (Decl)" vhdl-template-function-decl t]
3224 ["Generic" vhdl-template-generic t]
3225 ["Group (Decl)" vhdl-template-group-decl t]
3226 ["Group (Template)" vhdl-template-group-template t])
3227 ("VHDL Construct 2"
3228 ["If (Generate)" vhdl-template-if-generate t]
3229 ["If (Then)" vhdl-template-if-then t]
3230 ["Library" vhdl-template-library t]
3231 ["Loop" vhdl-template-bare-loop t]
3232 ["Map" vhdl-template-map t]
3233 ["Next" vhdl-template-next t]
3234 ["Others (Aggregate)" vhdl-template-others t]
3235 ["Package (Decl)" vhdl-template-package-decl t]
3236 ["Package (Body)" vhdl-template-package-body t]
3237 ["Port" vhdl-template-port t]
3238 ["Procedure (Body)" vhdl-template-procedure-body t]
3239 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3240 ["Process (Comb)" vhdl-template-process-comb t]
3241 ["Process (Seq)" vhdl-template-process-seq t]
3242 ["Report" vhdl-template-report t]
3243 ["Return" vhdl-template-return t]
3244 ["Select" vhdl-template-selected-signal-asst t]
3245 ["Signal" vhdl-template-signal t]
3246 ["Subtype" vhdl-template-subtype t]
3247 ["Type" vhdl-template-type t]
3248 ["Use" vhdl-template-use t]
3249 ["Variable" vhdl-template-variable t]
3250 ["Wait" vhdl-template-wait t]
3251 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3252 ["When" vhdl-template-when t]
3253 ["While (Loop)" vhdl-template-while-loop t]
3254 ["With" vhdl-template-with t]))
3255 (when (vhdl-standard-p 'ams)
3256 '(("VHDL-AMS Construct"
3257 ["Break" vhdl-template-break t]
3258 ["Case (Use)" vhdl-template-case-use t]
3259 ["If (Use)" vhdl-template-if-use t]
3260 ["Limit" vhdl-template-limit t]
3261 ["Nature" vhdl-template-nature t]
3262 ["Procedural" vhdl-template-procedural t]
3263 ["Quantity (Free)" vhdl-template-quantity-free t]
3264 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3265 ["Quantity (Source)" vhdl-template-quantity-source t]
3266 ["Subnature" vhdl-template-subnature t]
3267 ["Terminal" vhdl-template-terminal t])))
3268 '(["Insert Construct..." vhdl-template-insert-construct
3269 :keys "C-c C-i C-t"]
3270 "--")
3271 (list
3272 (append
3273 '("Package")
3274 (when (vhdl-standard-p 'math)
3275 '(["math_complex" vhdl-template-package-math-complex t]
3276 ["math_real" vhdl-template-package-math-real t]))
3277 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3278 ["numeric_std" vhdl-template-package-numeric-std t]
3279 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3280 ["textio" vhdl-template-package-textio t]
3281 "--"
3282 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3283 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3284 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3285 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3286 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3287 "--"
3288 ["Insert Package..." vhdl-template-insert-package
3289 :keys "C-c C-i C-p"])))
3290 '(("Directive"
3291 ["translate_on" vhdl-template-directive-translate-on t]
3292 ["translate_off" vhdl-template-directive-translate-off t]
3293 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3294 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3295 "--"
3296 ["Insert Directive..." vhdl-template-insert-directive
3297 :keys "C-c C-i C-d"])
3298 "--"
3299 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3300 ["Insert Footer" vhdl-template-footer t]
3301 ["Insert Date" vhdl-template-insert-date t]
3302 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3303 "--"
3304 ["Query Next Prompt" vhdl-template-search-prompt t]))
3305 ,(append
3306 '("Model")
3307 ;; add menu entries for defined models
3308 (let ((model-alist vhdl-model-alist) menu-list model)
3309 (while model-alist
3310 (setq model (car model-alist))
3311 (setq menu-list
3312 (cons
3313 (vector
3314 (nth 0 model)
3315 (vhdl-function-name "vhdl-model" (nth 0 model))
3316 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3317 menu-list))
3318 (setq model-alist (cdr model-alist)))
3319 (setq menu-list (nreverse menu-list))
3320 (vhdl-menu-split menu-list "Model"))
3321 '("--" "--"
3322 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3323 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3324 ("Port"
3325 ["Copy" vhdl-port-copy t]
3326 "--"
3327 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3328 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3329 ["Paste As Instance" vhdl-port-paste-instance
3330 :keys "C-c C-p C-i" :active vhdl-port-list]
3331 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3332 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3333 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3334 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3335 "--"
3336 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3337 "--"
3338 ["Flatten" vhdl-port-flatten
3339 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3340 ["Reverse Direction" vhdl-port-reverse-direction
3341 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3342 ("Compose"
3343 ["New Component" vhdl-compose-new-component t]
3344 ["Copy Component" vhdl-port-copy t]
3345 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3346 ["Wire Components" vhdl-compose-wire-components t]
3347 "--"
3348 ["Generate Configuration" vhdl-compose-configuration t]
3349 ["Generate Components Package" vhdl-compose-components-package t])
3350 ("Subprogram"
3351 ["Copy" vhdl-subprog-copy t]
3352 "--"
3353 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3354 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3355 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3356 "--"
3357 ["Flatten" vhdl-subprog-flatten
3358 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3359 "--"
3360 ("Comment"
3361 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3362 "--"
3363 ["Insert Inline Comment" vhdl-comment-append-inline t]
3364 ["Insert Horizontal Line" vhdl-comment-display-line t]
3365 ["Insert Display Comment" vhdl-comment-display t]
3366 "--"
3367 ["Fill Comment" fill-paragraph t]
3368 ["Fill Comment Region" fill-region (mark)]
3369 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3370 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3371 ("Line"
3372 ["Kill" vhdl-line-kill t]
3373 ["Copy" vhdl-line-copy t]
3374 ["Yank" vhdl-line-yank t]
3375 ["Expand" vhdl-line-expand t]
3376 "--"
3377 ["Transpose Next" vhdl-line-transpose-next t]
3378 ["Transpose Prev" vhdl-line-transpose-previous t]
3379 ["Open" vhdl-line-open t]
3380 ["Join" vhdl-delete-indentation t]
3381 "--"
3382 ["Goto" goto-line t]
3383 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3384 ("Move"
3385 ["Forward Statement" vhdl-end-of-statement t]
3386 ["Backward Statement" vhdl-beginning-of-statement t]
3387 ["Forward Expression" vhdl-forward-sexp t]
3388 ["Backward Expression" vhdl-backward-sexp t]
3389 ["Forward Same Indent" vhdl-forward-same-indent t]
3390 ["Backward Same Indent" vhdl-backward-same-indent t]
3391 ["Forward Function" vhdl-end-of-defun t]
3392 ["Backward Function" vhdl-beginning-of-defun t]
3393 ["Mark Function" vhdl-mark-defun t])
3394 "--"
3395 ("Indent"
3396 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3397 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3398 ["Region" vhdl-indent-region (mark)]
3399 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3400 ("Align"
3401 ["Group" vhdl-align-group t]
3402 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3403 ["List" vhdl-align-list t]
3404 ["Declarations" vhdl-align-declarations t]
3405 ["Region" vhdl-align-region (mark)]
3406 ["Buffer" vhdl-align-buffer t]
3407 "--"
3408 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3409 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3410 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3411 ("Fill"
3412 ["List" vhdl-fill-list t]
3413 ["Group" vhdl-fill-group t]
3414 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3415 ["Region" vhdl-fill-region (mark)])
3416 ("Beautify"
3417 ["Region" vhdl-beautify-region (mark)]
3418 ["Buffer" vhdl-beautify-buffer t])
3419 ("Fix"
3420 ["Generic/Port Clause" vhdl-fix-clause t]
3421 "--"
3422 ["Case Region" vhdl-fix-case-region (mark)]
3423 ["Case Buffer" vhdl-fix-case-buffer t]
3424 "--"
3425 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3426 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3427 "--"
3428 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3429 ("Update"
3430 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3431 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3432 "--"
3433 ["Fontify Buffer" vhdl-fontify-buffer t]
3434 ["Statistics Buffer" vhdl-statistics-buffer t]
3435 ["Show Messages" vhdl-show-messages t]
3436 ["Syntactic Info" vhdl-show-syntactic-information t]
3437 "--"
3438 ["Speedbar" vhdl-speedbar t]
3439 ["Hide/Show" vhdl-hs-minor-mode t]
3440 "--"
3441 ("Documentation"
3442 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3443 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3444 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3445 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3446 ["Version" vhdl-version t]
3447 ["Bug Report..." vhdl-submit-bug-report t]
3448 "--"
3449 ("Options"
3450 ("Mode"
3451 ["Electric Mode"
3452 (progn (customize-set-variable 'vhdl-electric-mode
3453 (not vhdl-electric-mode)))
3454 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3455 ["Stutter Mode"
3456 (progn (customize-set-variable 'vhdl-stutter-mode
3457 (not vhdl-stutter-mode)))
3458 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3459 ["Indent Tabs Mode"
3460 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3461 (not vhdl-indent-tabs-mode))
3462 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3463 :style toggle :selected vhdl-indent-tabs-mode]
3464 "--"
3465 ["Customize Group..." (customize-group 'vhdl-mode) t])
3466 ("Project"
3467 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3468 ,(append
3469 '("Selected Project at Startup"
3470 ["None" (progn (customize-set-variable 'vhdl-project nil)
3471 (vhdl-set-project ""))
3472 :style radio :selected (null vhdl-project)]
3473 "--")
3474 ;; add menu entries for defined projects
3475 (let ((project-alist vhdl-project-alist) menu-list name)
3476 (while project-alist
3477 (setq name (caar project-alist))
3478 (setq menu-list
3479 (cons `[,name (progn (customize-set-variable
3480 'vhdl-project ,name)
3481 (vhdl-set-project ,name))
3482 :style radio :selected (equal ,name vhdl-project)]
3483 menu-list))
3484 (setq project-alist (cdr project-alist)))
3485 (setq menu-list (nreverse menu-list))
3486 (vhdl-menu-split menu-list "Project")))
3487 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3488 ("Auto Load Setup File"
3489 ["At Startup"
3490 (customize-set-variable 'vhdl-project-auto-load
3491 (if (memq 'startup vhdl-project-auto-load)
3492 (delq 'startup vhdl-project-auto-load)
3493 (cons 'startup vhdl-project-auto-load)))
3494 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3495 ["Sort Projects"
3496 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3497 :style toggle :selected vhdl-project-sort]
3498 "--"
3499 ["Customize Group..." (customize-group 'vhdl-project) t])
3500 ("Compiler"
3501 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3502 ,(append
3503 '("Selected Compiler at Startup")
3504 ;; add menu entries for defined compilers
3505 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3506 (while comp-alist
3507 (setq name (caar comp-alist))
3508 (setq menu-list
3509 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3510 :style radio :selected (equal ,name vhdl-compiler)]
3511 menu-list))
3512 (setq comp-alist (cdr comp-alist)))
3513 (setq menu-list (nreverse menu-list))
3514 (vhdl-menu-split menu-list "Compler")))
3515 ["Use Local Error Regexp"
3516 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3517 (not vhdl-compile-use-local-error-regexp))
3518 :style toggle :selected vhdl-compile-use-local-error-regexp]
3519 ["Makefile Generation Hook..."
3520 (customize-option 'vhdl-makefile-generation-hook) t]
3521 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3522 "--"
3523 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3524 ("Style"
3525 ("VHDL Standard"
3526 ["VHDL'87"
3527 (progn (customize-set-variable 'vhdl-standard
3528 (list '87 (cadr vhdl-standard)))
3529 (vhdl-activate-customizations))
3530 :style radio :selected (eq '87 (car vhdl-standard))]
3531 ["VHDL'93"
3532 (progn (customize-set-variable 'vhdl-standard
3533 (list '93 (cadr vhdl-standard)))
3534 (vhdl-activate-customizations))
3535 :style radio :selected (eq '93 (car vhdl-standard))]
3536 "--"
3537 ["VHDL-AMS"
3538 (progn (customize-set-variable
3539 'vhdl-standard (list (car vhdl-standard)
3540 (if (memq 'ams (cadr vhdl-standard))
3541 (delq 'ams (cadr vhdl-standard))
3542 (cons 'ams (cadr vhdl-standard)))))
3543 (vhdl-activate-customizations))
3544 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3545 ["Math Packages"
3546 (progn (customize-set-variable
3547 'vhdl-standard (list (car vhdl-standard)
3548 (if (memq 'math (cadr vhdl-standard))
3549 (delq 'math (cadr vhdl-standard))
3550 (cons 'math (cadr vhdl-standard)))))
3551 (vhdl-activate-customizations))
3552 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3553 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3554 ["Upper Case Keywords"
3555 (customize-set-variable 'vhdl-upper-case-keywords
3556 (not vhdl-upper-case-keywords))
3557 :style toggle :selected vhdl-upper-case-keywords]
3558 ["Upper Case Types"
3559 (customize-set-variable 'vhdl-upper-case-types
3560 (not vhdl-upper-case-types))
3561 :style toggle :selected vhdl-upper-case-types]
3562 ["Upper Case Attributes"
3563 (customize-set-variable 'vhdl-upper-case-attributes
3564 (not vhdl-upper-case-attributes))
3565 :style toggle :selected vhdl-upper-case-attributes]
3566 ["Upper Case Enumeration Values"
3567 (customize-set-variable 'vhdl-upper-case-enum-values
3568 (not vhdl-upper-case-enum-values))
3569 :style toggle :selected vhdl-upper-case-enum-values]
3570 ["Upper Case Constants"
3571 (customize-set-variable 'vhdl-upper-case-constants
3572 (not vhdl-upper-case-constants))
3573 :style toggle :selected vhdl-upper-case-constants]
3574 ("Use Direct Instantiation"
3575 ["Never"
3576 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3577 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3578 ["Standard"
3579 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3580 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3581 ["Always"
3582 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3583 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3584 "--"
3585 ["Customize Group..." (customize-group 'vhdl-style) t])
3586 ("Naming"
3587 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3588 ["Architecture File Name..."
3589 (customize-option 'vhdl-architecture-file-name) t]
3590 ["Configuration File Name..."
3591 (customize-option 'vhdl-configuration-file-name) t]
3592 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3593 ("File Name Case"
3594 ["As Is"
3595 (customize-set-variable 'vhdl-file-name-case 'identity)
3596 :style radio :selected (eq 'identity vhdl-file-name-case)]
3597 ["Lower Case"
3598 (customize-set-variable 'vhdl-file-name-case 'downcase)
3599 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3600 ["Upper Case"
3601 (customize-set-variable 'vhdl-file-name-case 'upcase)
3602 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3603 ["Capitalize"
3604 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3605 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3606 "--"
3607 ["Customize Group..." (customize-group 'vhdl-naming) t])
3608 ("Template"
3609 ("Electric Keywords"
3610 ["VHDL Keywords"
3611 (customize-set-variable 'vhdl-electric-keywords
3612 (if (memq 'vhdl vhdl-electric-keywords)
3613 (delq 'vhdl vhdl-electric-keywords)
3614 (cons 'vhdl vhdl-electric-keywords)))
3615 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3616 ["User Model Keywords"
3617 (customize-set-variable 'vhdl-electric-keywords
3618 (if (memq 'user vhdl-electric-keywords)
3619 (delq 'user vhdl-electric-keywords)
3620 (cons 'user vhdl-electric-keywords)))
3621 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3622 ("Insert Optional Labels"
3623 ["None"
3624 (customize-set-variable 'vhdl-optional-labels 'none)
3625 :style radio :selected (eq 'none vhdl-optional-labels)]
3626 ["Processes Only"
3627 (customize-set-variable 'vhdl-optional-labels 'process)
3628 :style radio :selected (eq 'process vhdl-optional-labels)]
3629 ["All Constructs"
3630 (customize-set-variable 'vhdl-optional-labels 'all)
3631 :style radio :selected (eq 'all vhdl-optional-labels)])
3632 ("Insert Empty Lines"
3633 ["None"
3634 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3635 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3636 ["Design Units Only"
3637 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3638 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3639 ["All Constructs"
3640 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3641 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3642 ["Argument List Indent"
3643 (customize-set-variable 'vhdl-argument-list-indent
3644 (not vhdl-argument-list-indent))
3645 :style toggle :selected vhdl-argument-list-indent]
3646 ["Association List with Formals"
3647 (customize-set-variable 'vhdl-association-list-with-formals
3648 (not vhdl-association-list-with-formals))
3649 :style toggle :selected vhdl-association-list-with-formals]
3650 ["Conditions in Parenthesis"
3651 (customize-set-variable 'vhdl-conditions-in-parenthesis
3652 (not vhdl-conditions-in-parenthesis))
3653 :style toggle :selected vhdl-conditions-in-parenthesis]
3654 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3655 ["One String..." (customize-option 'vhdl-one-string) t]
3656 ("File Header"
3657 ["Header String..." (customize-option 'vhdl-file-header) t]
3658 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3659 ["Company Name..." (customize-option 'vhdl-company-name) t]
3660 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3661 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3662 ["Date Format..." (customize-option 'vhdl-date-format) t]
3663 ["Modify Date Prefix String..."
3664 (customize-option 'vhdl-modify-date-prefix-string) t]
3665 ["Modify Date on Saving"
3666 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3667 (not vhdl-modify-date-on-saving))
3668 (vhdl-activate-customizations))
3669 :style toggle :selected vhdl-modify-date-on-saving])
3670 ("Sequential Process"
3671 ("Kind of Reset"
3672 ["None"
3673 (customize-set-variable 'vhdl-reset-kind 'none)
3674 :style radio :selected (eq 'none vhdl-reset-kind)]
3675 ["Synchronous"
3676 (customize-set-variable 'vhdl-reset-kind 'sync)
3677 :style radio :selected (eq 'sync vhdl-reset-kind)]
3678 ["Asynchronous"
3679 (customize-set-variable 'vhdl-reset-kind 'async)
3680 :style radio :selected (eq 'async vhdl-reset-kind)])
3681 ["Reset is Active High"
3682 (customize-set-variable 'vhdl-reset-active-high
3683 (not vhdl-reset-active-high))
3684 :style toggle :selected vhdl-reset-active-high]
3685 ["Use Rising Clock Edge"
3686 (customize-set-variable 'vhdl-clock-rising-edge
3687 (not vhdl-clock-rising-edge))
3688 :style toggle :selected vhdl-clock-rising-edge]
3689 ("Clock Edge Condition"
3690 ["Standard"
3691 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3692 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3693 ["Function \"rising_edge\""
3694 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3695 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3696 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3697 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3698 "--"
3699 ["Customize Group..." (customize-group 'vhdl-template) t])
3700 ("Model"
3701 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3702 ("Port"
3703 ["Include Port Comments"
3704 (customize-set-variable 'vhdl-include-port-comments
3705 (not vhdl-include-port-comments))
3706 :style toggle :selected vhdl-include-port-comments]
3707 ["Include Direction Comments"
3708 (customize-set-variable 'vhdl-include-direction-comments
3709 (not vhdl-include-direction-comments))
3710 :style toggle :selected vhdl-include-direction-comments]
3711 ["Include Type Comments"
3712 (customize-set-variable 'vhdl-include-type-comments
3713 (not vhdl-include-type-comments))
3714 :style toggle :selected vhdl-include-type-comments]
3715 ("Include Group Comments"
3716 ["Never"
3717 (customize-set-variable 'vhdl-include-group-comments 'never)
3718 :style radio :selected (eq 'never vhdl-include-group-comments)]
3719 ["Declarations"
3720 (customize-set-variable 'vhdl-include-group-comments 'decl)
3721 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3722 ["Always"
3723 (customize-set-variable 'vhdl-include-group-comments 'always)
3724 :style radio :selected (eq 'always vhdl-include-group-comments)])
3725 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3726 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3727 ("Testbench"
3728 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3729 ["Architecture Name..."
3730 (customize-option 'vhdl-testbench-architecture-name) t]
3731 ["Configuration Name..."
3732 (customize-option 'vhdl-testbench-configuration-name) t]
3733 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3734 ["Include Header"
3735 (customize-set-variable 'vhdl-testbench-include-header
3736 (not vhdl-testbench-include-header))
3737 :style toggle :selected vhdl-testbench-include-header]
3738 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3739 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3740 ["Initialize Signals"
3741 (customize-set-variable 'vhdl-testbench-initialize-signals
3742 (not vhdl-testbench-initialize-signals))
3743 :style toggle :selected vhdl-testbench-initialize-signals]
3744 ["Include Library Clause"
3745 (customize-set-variable 'vhdl-testbench-include-library
3746 (not vhdl-testbench-include-library))
3747 :style toggle :selected vhdl-testbench-include-library]
3748 ["Include Configuration"
3749 (customize-set-variable 'vhdl-testbench-include-configuration
3750 (not vhdl-testbench-include-configuration))
3751 :style toggle :selected vhdl-testbench-include-configuration]
3752 ("Create Files"
3753 ["None"
3754 (customize-set-variable 'vhdl-testbench-create-files 'none)
3755 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3756 ["Single"
3757 (customize-set-variable 'vhdl-testbench-create-files 'single)
3758 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3759 ["Separate"
3760 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3761 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3762 ["Testbench Entity File Name..."
3763 (customize-option 'vhdl-testbench-entity-file-name) t]
3764 ["Testbench Architecture File Name..."
3765 (customize-option 'vhdl-testbench-architecture-file-name) t])
3766 "--"
3767 ["Customize Group..." (customize-group 'vhdl-port) t])
3768 ("Compose"
3769 ["Architecture Name..."
3770 (customize-option 'vhdl-compose-architecture-name) t]
3771 ["Configuration Name..."
3772 (customize-option 'vhdl-compose-configuration-name) t]
3773 ["Components Package Name..."
3774 (customize-option 'vhdl-components-package-name) t]
3775 ["Use Components Package"
3776 (customize-set-variable 'vhdl-use-components-package
3777 (not vhdl-use-components-package))
3778 :style toggle :selected vhdl-use-components-package]
3779 ["Include Header"
3780 (customize-set-variable 'vhdl-compose-include-header
3781 (not vhdl-compose-include-header))
3782 :style toggle :selected vhdl-compose-include-header]
3783 ("Create Entity/Architecture Files"
3784 ["None"
3785 (customize-set-variable 'vhdl-compose-create-files 'none)
3786 :style radio :selected (eq 'none vhdl-compose-create-files)]
3787 ["Single"
3788 (customize-set-variable 'vhdl-compose-create-files 'single)
3789 :style radio :selected (eq 'single vhdl-compose-create-files)]
3790 ["Separate"
3791 (customize-set-variable 'vhdl-compose-create-files 'separate)
3792 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3793 ["Create Configuration File"
3794 (customize-set-variable 'vhdl-compose-configuration-create-file
3795 (not vhdl-compose-configuration-create-file))
3796 :style toggle :selected vhdl-compose-configuration-create-file]
3797 ["Hierarchical Configuration"
3798 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3799 (not vhdl-compose-configuration-hierarchical))
3800 :style toggle :selected vhdl-compose-configuration-hierarchical]
3801 ["Use Subconfiguration"
3802 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3803 (not vhdl-compose-configuration-use-subconfiguration))
3804 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3805 "--"
3806 ["Customize Group..." (customize-group 'vhdl-compose) t])
3807 ("Comment"
3808 ["Self Insert Comments"
3809 (customize-set-variable 'vhdl-self-insert-comments
3810 (not vhdl-self-insert-comments))
3811 :style toggle :selected vhdl-self-insert-comments]
3812 ["Prompt for Comments"
3813 (customize-set-variable 'vhdl-prompt-for-comments
3814 (not vhdl-prompt-for-comments))
3815 :style toggle :selected vhdl-prompt-for-comments]
3816 ["Inline Comment Column..."
3817 (customize-option 'vhdl-inline-comment-column) t]
3818 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3819 "--"
3820 ["Customize Group..." (customize-group 'vhdl-comment) t])
3821 ("Align"
3822 ["Auto Align Templates"
3823 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3824 :style toggle :selected vhdl-auto-align]
3825 ["Align Line Groups"
3826 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3827 :style toggle :selected vhdl-align-groups]
3828 ["Group Separation String..."
3829 (customize-set-variable 'vhdl-align-group-separate) t]
3830 ["Align Lines with Same Indent"
3831 (customize-set-variable 'vhdl-align-same-indent
3832 (not vhdl-align-same-indent))
3833 :style toggle :selected vhdl-align-same-indent]
3834 "--"
3835 ["Customize Group..." (customize-group 'vhdl-align) t])
3836 ("Highlight"
3837 ["Highlighting On/Off..."
3838 (customize-option
3839 (if (fboundp 'global-font-lock-mode)
3840 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3841 ["Highlight Keywords"
3842 (progn (customize-set-variable 'vhdl-highlight-keywords
3843 (not vhdl-highlight-keywords))
3844 (vhdl-fontify-buffer))
3845 :style toggle :selected vhdl-highlight-keywords]
3846 ["Highlight Names"
3847 (progn (customize-set-variable 'vhdl-highlight-names
3848 (not vhdl-highlight-names))
3849 (vhdl-fontify-buffer))
3850 :style toggle :selected vhdl-highlight-names]
3851 ["Highlight Special Words"
3852 (progn (customize-set-variable 'vhdl-highlight-special-words
3853 (not vhdl-highlight-special-words))
3854 (vhdl-fontify-buffer))
3855 :style toggle :selected vhdl-highlight-special-words]
3856 ["Highlight Forbidden Words"
3857 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3858 (not vhdl-highlight-forbidden-words))
3859 (vhdl-fontify-buffer))
3860 :style toggle :selected vhdl-highlight-forbidden-words]
3861 ["Highlight Verilog Keywords"
3862 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3863 (not vhdl-highlight-verilog-keywords))
3864 (vhdl-fontify-buffer))
3865 :style toggle :selected vhdl-highlight-verilog-keywords]
3866 ["Highlight \"translate_off\""
3867 (progn (customize-set-variable 'vhdl-highlight-translate-off
3868 (not vhdl-highlight-translate-off))
3869 (vhdl-fontify-buffer))
3870 :style toggle :selected vhdl-highlight-translate-off]
3871 ["Case Sensitive Highlighting"
3872 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3873 (not vhdl-highlight-case-sensitive))
3874 (vhdl-fontify-buffer))
3875 :style toggle :selected vhdl-highlight-case-sensitive]
3876 ["Special Syntax Definition..."
3877 (customize-option 'vhdl-special-syntax-alist) t]
3878 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3879 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3880 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3881 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3882 "--"
3883 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3884 ("Speedbar"
3885 ["Auto Open at Startup"
3886 (customize-set-variable 'vhdl-speedbar-auto-open
3887 (not vhdl-speedbar-auto-open))
3888 :style toggle :selected vhdl-speedbar-auto-open]
3889 ("Default Displaying Mode"
3890 ["Files"
3891 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3892 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3893 ["Directory Hierarchy"
3894 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3895 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3896 ["Project Hierarchy"
3897 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3898 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3899 ["Indentation Offset..."
3900 (customize-option 'speedbar-indentation-width) t]
3901 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3902 ["Jump to Unit when Opening"
3903 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3904 (not vhdl-speedbar-jump-to-unit))
3905 :style toggle :selected vhdl-speedbar-jump-to-unit]
3906 ["Update Hierarchy on File Saving"
3907 (customize-set-variable 'vhdl-speedbar-update-on-saving
3908 (not vhdl-speedbar-update-on-saving))
3909 :style toggle :selected vhdl-speedbar-update-on-saving]
3910 ("Save in Cache File"
3911 ["Hierarchy Information"
3912 (customize-set-variable 'vhdl-speedbar-save-cache
3913 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3914 (delq 'hierarchy vhdl-speedbar-save-cache)
3915 (cons 'hierarchy vhdl-speedbar-save-cache)))
3916 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3917 ["Displaying Status"
3918 (customize-set-variable 'vhdl-speedbar-save-cache
3919 (if (memq 'display vhdl-speedbar-save-cache)
3920 (delq 'display vhdl-speedbar-save-cache)
3921 (cons 'display vhdl-speedbar-save-cache)))
3922 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3923 ["Cache File Name..."
3924 (customize-option 'vhdl-speedbar-cache-file-name) t]
3925 "--"
3926 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3927 ("Menu"
3928 ["Add Index Menu when Loading File"
3929 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3930 (vhdl-index-menu-init))
3931 :style toggle :selected vhdl-index-menu]
3932 ["Add Source File Menu when Loading File"
3933 (progn (customize-set-variable 'vhdl-source-file-menu
3934 (not vhdl-source-file-menu))
3935 (vhdl-add-source-files-menu))
3936 :style toggle :selected vhdl-source-file-menu]
3937 ["Add Hideshow Menu at Startup"
3938 (progn (customize-set-variable 'vhdl-hideshow-menu
3939 (not vhdl-hideshow-menu))
3940 (vhdl-activate-customizations))
3941 :style toggle :selected vhdl-hideshow-menu]
3942 ["Hide Everything Initially"
3943 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3944 :style toggle :selected vhdl-hide-all-init]
3945 "--"
3946 ["Customize Group..." (customize-group 'vhdl-menu) t])
3947 ("Print"
3948 ["In Two Column Format"
3949 (progn (customize-set-variable 'vhdl-print-two-column
3950 (not vhdl-print-two-column))
3951 (message "Activate new setting by saving options and restarting Emacs"))
3952 :style toggle :selected vhdl-print-two-column]
3953 ["Use Customized Faces"
3954 (progn (customize-set-variable 'vhdl-print-customize-faces
3955 (not vhdl-print-customize-faces))
3956 (message "Activate new setting by saving options and restarting Emacs"))
3957 :style toggle :selected vhdl-print-customize-faces]
3958 "--"
3959 ["Customize Group..." (customize-group 'vhdl-print) t])
3960 ("Miscellaneous"
3961 ["Use Intelligent Tab"
3962 (progn (customize-set-variable 'vhdl-intelligent-tab
3963 (not vhdl-intelligent-tab))
3964 (vhdl-activate-customizations))
3965 :style toggle :selected vhdl-intelligent-tab]
3966 ["Indent Syntax-Based"
3967 (customize-set-variable 'vhdl-indent-syntax-based
3968 (not vhdl-indent-syntax-based))
3969 :style toggle :selected vhdl-indent-syntax-based]
3970 ["Word Completion is Case Sensitive"
3971 (customize-set-variable 'vhdl-word-completion-case-sensitive
3972 (not vhdl-word-completion-case-sensitive))
3973 :style toggle :selected vhdl-word-completion-case-sensitive]
3974 ["Word Completion in Minibuffer"
3975 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3976 (not vhdl-word-completion-in-minibuffer))
3977 (message "Activate new setting by saving options and restarting Emacs"))
3978 :style toggle :selected vhdl-word-completion-in-minibuffer]
3979 ["Underscore is Part of Word"
3980 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3981 (not vhdl-underscore-is-part-of-word))
3982 (vhdl-activate-customizations))
3983 :style toggle :selected vhdl-underscore-is-part-of-word]
3984 "--"
3985 ["Customize Group..." (customize-group 'vhdl-misc) t])
3986 ["Related..." (customize-browse 'vhdl-related) t]
3987 "--"
3988 ["Save Options" customize-save-customized t]
3989 ["Activate Options" vhdl-activate-customizations t]
3990 ["Browse Options..." vhdl-customize t])))
3991
3992 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3993 "VHDL Mode menu.")
3994
3995 (defun vhdl-update-mode-menu ()
3996 "Update VHDL Mode menu."
3997 (interactive)
3998 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3999 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4000 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4001 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4002 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4003
4004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4005 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4006
4007 (defconst vhdl-imenu-generic-expression
4008 '(
4009 ("Subprogram"
4010 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4011 4)
4012 ("Instance"
4013 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4014 1)
4015 ("Component"
4016 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4017 2)
4018 ("Procedural"
4019 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4020 1)
4021 ("Process"
4022 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4023 1)
4024 ("Block"
4025 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4026 1)
4027 ("Package"
4028 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4029 3)
4030 ("Configuration"
4031 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4032 2)
4033 ("Architecture"
4034 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4035 2)
4036 ("Entity"
4037 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4038 2)
4039 )
4040 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4041
4042 (defun vhdl-index-menu-init ()
4043 "Initialize index menu."
4044 (set (make-local-variable 'imenu-case-fold-search) t)
4045 (set (make-local-variable 'imenu-generic-expression)
4046 vhdl-imenu-generic-expression)
4047 (when (and vhdl-index-menu (fboundp 'imenu))
4048 (if (or (not (boundp 'font-lock-maximum-size))
4049 (> font-lock-maximum-size (buffer-size)))
4050 (imenu-add-to-menubar "Index")
4051 (message "Scanning buffer for index...buffer too big"))))
4052
4053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4054 ;; Source file menu (using `easy-menu.el')
4055
4056 (defvar vhdl-sources-menu nil)
4057
4058 (defun vhdl-directory-files (directory &optional full match)
4059 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4060 message."
4061 (if (not (file-directory-p directory))
4062 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4063 (let ((dir (directory-files directory full match)))
4064 (setq dir (delete "." dir))
4065 (setq dir (delete ".." dir))
4066 dir)))
4067
4068 (defun vhdl-get-source-files (&optional full directory)
4069 "Get list of VHDL source files in DIRECTORY or current directory."
4070 (let ((mode-alist auto-mode-alist)
4071 filename-regexp)
4072 ;; create regular expressions for matching file names
4073 (setq filename-regexp "\\`[^.].*\\(")
4074 (while mode-alist
4075 (when (eq (cdar mode-alist) 'vhdl-mode)
4076 (setq filename-regexp
4077 (concat filename-regexp (caar mode-alist) "\\|")))
4078 (setq mode-alist (cdr mode-alist)))
4079 (setq filename-regexp
4080 (concat (substring filename-regexp 0
4081 (string-match "\\\\|$" filename-regexp)) "\\)"))
4082 ;; find files
4083 (vhdl-directory-files
4084 (or directory default-directory) full filename-regexp)))
4085
4086 (defun vhdl-add-source-files-menu ()
4087 "Scan directory for all VHDL source files and generate menu.
4088 The directory of the current source file is scanned."
4089 (interactive)
4090 (message "Scanning directory for source files ...")
4091 (let ((newmap (current-local-map))
4092 (file-list (vhdl-get-source-files))
4093 menu-list found)
4094 ;; Create list for menu
4095 (setq found nil)
4096 (while file-list
4097 (setq found t)
4098 (setq menu-list (cons (vector (car file-list)
4099 (list 'find-file (car file-list)) t)
4100 menu-list))
4101 (setq file-list (cdr file-list)))
4102 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4103 (when found (setq menu-list (cons "--" menu-list)))
4104 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4105 (setq menu-list (cons "Sources" menu-list))
4106 ;; Create menu
4107 (easy-menu-add menu-list)
4108 (easy-menu-define vhdl-sources-menu newmap
4109 "VHDL source files menu" menu-list))
4110 (message ""))
4111
4112
4113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4114 ;;; Mode definition
4115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4116 ;; performs all buffer local initializations
4117
4118 ;;;###autoload
4119 (define-derived-mode vhdl-mode prog-mode
4120 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4121 (vhdl-electric-mode "e")
4122 (vhdl-stutter-mode "s"))
4123 "Major mode for editing VHDL code.
4124
4125 Usage:
4126 ------
4127
4128 TEMPLATE INSERTION (electrification):
4129 After typing a VHDL keyword and entering `SPC', you are prompted for
4130 arguments while a template is generated for that VHDL construct. Typing
4131 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4132 template generation. Optional arguments are indicated by square
4133 brackets and removed if the queried string is left empty. Prompts for
4134 mandatory arguments remain in the code if the queried string is left
4135 empty. They can be queried again by `C-c C-t C-q'. Enabled
4136 electrification is indicated by `/e' in the modeline.
4137
4138 Typing `M-SPC' after a keyword inserts a space without calling the
4139 template generator. Automatic template generation (i.e.
4140 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4141 setting option `vhdl-electric-mode' (see OPTIONS).
4142
4143 Template generators can be invoked from the VHDL menu, by key
4144 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4145 the keyword (i.e. first word of menu entry not in parenthesis) and
4146 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4147 conf, comp, cons, func, inst, pack, sig, var.
4148
4149 Template styles can be customized in customization group
4150 `vhdl-template' \(see OPTIONS).
4151
4152
4153 HEADER INSERTION:
4154 A file header can be inserted by `C-c C-t C-h'. A file footer
4155 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4156 See customization group `vhdl-header'.
4157
4158
4159 STUTTERING:
4160 Double striking of some keys inserts cumbersome VHDL syntax elements.
4161 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4162 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4163 the modeline. The stuttering keys and their effects are:
4164
4165 ;; --> \" : \" [ --> ( -- --> comment
4166 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4167 .. --> \" => \" ] --> ) --- --> horizontal line
4168 ,, --> \" <= \" ]] --> ] ---- --> display comment
4169 == --> \" == \" '' --> \\\"
4170
4171
4172 WORD COMPLETION:
4173 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4174 word in the buffer that starts alike, inserts it and adjusts case.
4175 Re-typing `TAB' toggles through alternative word completions. This also
4176 works in the minibuffer (i.e. in template generator prompts).
4177
4178 Typing `TAB' after `(' looks for and inserts complete parenthesized
4179 expressions (e.g. for array index ranges). All keywords as well as
4180 standard types and subprograms of VHDL have predefined abbreviations
4181 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4182 beginning with \"std\").
4183
4184 Typing `TAB' after a non-word character indents the line if at the
4185 beginning of a line (i.e. no preceding non-blank characters), and
4186 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4187 stop.
4188
4189
4190 COMMENTS:
4191 `--' puts a single comment.
4192 `---' draws a horizontal line for separating code segments.
4193 `----' inserts a display comment, i.e. two horizontal lines
4194 with a comment in between.
4195 `--CR' comments out code on that line. Re-hitting CR comments
4196 out following lines.
4197 `C-c c' comments out a region if not commented out,
4198 uncomments a region if already commented out.
4199
4200 You are prompted for comments after object definitions (i.e. signals,
4201 variables, constants, ports) and after subprogram and process
4202 specifications if option `vhdl-prompt-for-comments' is non-nil.
4203 Comments are automatically inserted as additional labels (e.g. after
4204 begin statements) and as help comments if `vhdl-self-insert-comments' is
4205 non-nil.
4206
4207 Inline comments (i.e. comments after a piece of code on the same line)
4208 are indented at least to `vhdl-inline-comment-column'. Comments go at
4209 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4210 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4211 in a comment automatically opens a new comment line. `M-q' re-fills
4212 multi-line comments.
4213
4214
4215 INDENTATION:
4216 `TAB' indents a line if at the beginning of the line. The amount of
4217 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4218 always indents the current line (is bound to `TAB' if option
4219 `vhdl-intelligent-tab' is nil).
4220
4221 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4222 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4223 indented normally (nil) or relative to the opening parenthesis (non-nil)
4224 according to option `vhdl-argument-list-indent'.
4225
4226 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4227 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4228 and vice versa.
4229
4230 Syntax-based indentation can be very slow in large files. Option
4231 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4232
4233
4234 ALIGNMENT:
4235 The alignment functions align operators, keywords, and inline comments
4236 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4237 separated by blank lines, `C-c C-a C-i' a block of lines with same
4238 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4239 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4240 C-a C-d' all lines within the declarative part of a design unit. `C-c
4241 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4242 for a group of lines, and `C-c C-a M-c' for a region.
4243
4244 If option `vhdl-align-groups' is non-nil, groups of code lines
4245 separated by special lines (see option `vhdl-align-group-separate') are
4246 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4247 blocks of lines with same indent are aligned separately. Some templates
4248 are automatically aligned after generation if option `vhdl-auto-align'
4249 is non-nil.
4250
4251 Alignment tries to align inline comments at
4252 `vhdl-inline-comment-column' and tries inline comment not to exceed
4253 `vhdl-end-comment-column'.
4254
4255 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4256 symbols are surrounded by one space, and multiple spaces are eliminated.
4257
4258
4259 CODE FILLING:
4260 Code filling allows to condense code (e.g. sensitivity lists or port
4261 maps) by removing comments and newlines and re-wrapping so that all
4262 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4263 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4264 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4265 `C-c C-f M-f' an entire region.
4266
4267
4268 CODE BEAUTIFICATION:
4269 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4270 buffer respectively. This inludes indentation, alignment, and case
4271 fixing. Code beautification can also be run non-interactively using the
4272 command:
4273
4274 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4275
4276
4277 PORT TRANSLATION:
4278 Generic and port clauses from entity or component declarations can be
4279 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4280 as component instantiations and corresponding internal constants and
4281 signals, as a generic map with constants as actual generics, and as
4282 internal signal initializations (menu).
4283
4284 To include formals in component instantiations, see option
4285 `vhdl-association-list-with-formals'. To include comments in pasting,
4286 see options `vhdl-include-...-comments'.
4287
4288 A clause with several generic/port names on the same line can be
4289 flattened (`C-c C-p C-f') so that only one name per line exists. The
4290 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4291 outputs and vice versa, which can be useful in testbenches. (This
4292 reversion is done on the internal data structure and is only reflected
4293 in subsequent paste operations.)
4294
4295 Names for actual ports, instances, testbenches, and
4296 design-under-test instances can be derived from existing names according
4297 to options `vhdl-...-name'. See customization group `vhdl-port'.
4298
4299
4300 SUBPROGRAM TRANSLATION:
4301 Similar functionality exists for copying/pasting the interface of
4302 subprograms (function/procedure). A subprogram interface can be copied
4303 and then pasted as a subprogram declaration, body or call (uses
4304 association list with formals).
4305
4306
4307 TESTBENCH GENERATION:
4308 A copied port can also be pasted as a testbench. The generated
4309 testbench includes an entity, an architecture, and an optional
4310 configuration. The architecture contains the component declaration and
4311 instantiation of the DUT as well as internal constant and signal
4312 declarations. Additional user-defined templates can be inserted. The
4313 names used for entity/architecture/configuration/DUT as well as the file
4314 structure to be generated can be customized. See customization group
4315 `vhdl-testbench'.
4316
4317
4318 KEY BINDINGS:
4319 Key bindings (`C-c ...') exist for most commands (see in menu).
4320
4321
4322 VHDL MENU:
4323 All commands can be found in the VHDL menu including their key bindings.
4324
4325
4326 FILE BROWSER:
4327 The speedbar allows browsing of directories and file contents. It can
4328 be accessed from the VHDL menu and is automatically opened if option
4329 `vhdl-speedbar-auto-open' is non-nil.
4330
4331 In speedbar, open files and directories with `mouse-2' on the name and
4332 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4333
4334
4335 DESIGN HIERARCHY BROWSER:
4336 The speedbar can also be used for browsing the hierarchy of design units
4337 contained in the source files of the current directory or the specified
4338 projects (see option `vhdl-project-alist').
4339
4340 The speedbar can be switched between file, directory hierarchy and
4341 project hierarchy browsing mode in the speedbar menu or by typing `f',
4342 `h' or `H' in speedbar.
4343
4344 In speedbar, open design units with `mouse-2' on the name and browse
4345 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4346 from entities and components (in packages). Individual design units and
4347 complete designs can directly be compiled (\"Make\" menu entry).
4348
4349 The hierarchy is automatically updated upon saving a modified source
4350 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4351 hierarchy is only updated for projects that have been opened once in the
4352 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4353 options in group `vhdl-speedbar').
4354
4355 Simple design consistency checks are done during scanning, such as
4356 multiple declarations of the same unit or missing primary units that are
4357 required by secondary units.
4358
4359
4360 STRUCTURAL COMPOSITION:
4361 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4362 for a new component. Subcomponents (i.e. component declaration and
4363 instantiation) can be automatically placed from a previously read port
4364 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4365 all subcomponents can be automatically connected using internal signals
4366 and ports (`C-c C-c C-w') following these rules:
4367 - subcomponent actual ports with same name are considered to be
4368 connected by a signal (internal signal or port)
4369 - signals that are only inputs to subcomponents are considered as
4370 inputs to this component -> input port created
4371 - signals that are only outputs from subcomponents are considered as
4372 outputs from this component -> output port created
4373 - signals that are inputs to AND outputs from subcomponents are
4374 considered as internal connections -> internal signal created
4375
4376 Purpose: With appropriate naming conventions it is possible to
4377 create higher design levels with only a few mouse clicks or key
4378 strokes. A new design level can be created by simply generating a new
4379 component, placing the required subcomponents from the hierarchy
4380 browser, and wiring everything automatically.
4381
4382 Note: Automatic wiring only works reliably on templates of new
4383 components and component instantiations that were created by VHDL mode.
4384
4385 Component declarations can be placed in a components package (option
4386 `vhdl-use-components-package') which can be automatically generated for
4387 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4388 component instantiation is also supported (option
4389 `vhdl-use-direct-instantiation').
4390
4391 | Configuration declarations can automatically be generated either from
4392 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4393 | the speedbar menu (for the architecture under the cursor). The
4394 | configurations can optionally be hierarchical (i.e. include all
4395 | component levels of a hierarchical design, option
4396 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4397 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4398 | subcomponents in hierarchical configurations, the most-recently-analyzed
4399 | (mra) architecture is selected. If another architecture is desired, it
4400 | can be marked as most-recently-analyzed (speedbar menu) before
4401 | generating the configuration.
4402 |
4403 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4404 | declarations) are currently not considered when displaying
4405 | configurations in speedbar.
4406
4407 See the options group `vhdl-compose' for all relevant user options.
4408
4409
4410 SOURCE FILE COMPILATION:
4411 The syntax of the current buffer can be analyzed by calling a VHDL
4412 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4413 option `vhdl-compiler'. The available compilers are listed in option
4414 `vhdl-compiler-alist' including all required compilation command,
4415 command options, compilation directory, and error message syntax
4416 information. New compilers can be added.
4417
4418 All the source files of an entire design can be compiled by the `make'
4419 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4420
4421
4422 MAKEFILE GENERATION:
4423 Makefiles can be generated automatically by an internal generation
4424 routine (`C-c M-k'). The library unit dependency information is
4425 obtained from the hierarchy browser. Makefile generation can be
4426 customized for each compiler in option `vhdl-compiler-alist'.
4427
4428 Makefile generation can also be run non-interactively using the
4429 command:
4430
4431 emacs -batch -l ~/.emacs -l vhdl-mode
4432 [-compiler compilername] [-project projectname]
4433 -f vhdl-generate-makefile
4434
4435 The Makefile's default target \"all\" compiles the entire design, the
4436 target \"clean\" removes it and the target \"library\" creates the
4437 library directory if not existent. The Makefile also includes a target
4438 for each primary library unit which allows selective compilation of this
4439 unit, its secondary units and its subhierarchy (example: compilation of
4440 a design specified by a configuration). User specific parts can be
4441 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4442
4443 Limitations:
4444 - Only library units and dependencies within the current library are
4445 considered. Makefiles for designs that span multiple libraries are
4446 not (yet) supported.
4447 - Only one-level configurations are supported (also hierarchical),
4448 but configurations that go down several levels are not.
4449 - The \"others\" keyword in configurations is not supported.
4450
4451
4452 PROJECTS:
4453 Projects can be defined in option `vhdl-project-alist' and a current
4454 project be selected using option `vhdl-project' (permanently) or from
4455 the menu or speedbar (temporarily). For each project, title and
4456 description strings (for the file headers), source files/directories
4457 (for the hierarchy browser and Makefile generation), library name, and
4458 compiler-dependent options, exceptions and compilation directory can be
4459 specified. Compilation settings overwrite the settings of option
4460 `vhdl-compiler-alist'.
4461
4462 Project setups can be exported (i.e. written to a file) and imported.
4463 Imported setups are not automatically saved in `vhdl-project-alist' but
4464 can be saved afterwards in its customization buffer. When starting
4465 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4466 vhdl-mode\") in a directory with an existing project setup file, it is
4467 automatically loaded and its project activated if option
4468 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4469 files can be specified in option `vhdl-project-file-name'. Multiple
4470 project setups can be automatically loaded from global directories.
4471 This is an alternative to specifying project setups with option
4472 `vhdl-project-alist'.
4473
4474
4475 SPECIAL MENUES:
4476 As an alternative to the speedbar, an index menu can be added (set
4477 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4478 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4479 file) for browsing the file contents (is not populated if buffer is
4480 larger than `font-lock-maximum-size'). Also, a source file menu can be
4481 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4482 current directory for VHDL source files.
4483
4484
4485 VHDL STANDARDS:
4486 The VHDL standards to be used are specified in option `vhdl-standard'.
4487 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4488
4489
4490 KEYWORD CASE:
4491 Lower and upper case for keywords and standardized types, attributes,
4492 and enumeration values is supported. If the option
4493 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4494 lower case and are converted into upper case automatically (not for
4495 types, attributes, and enumeration values). The case of keywords,
4496 types, attributes,and enumeration values can be fixed for an entire
4497 region (menu) or buffer (`C-c C-x C-c') according to the options
4498 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4499
4500
4501 HIGHLIGHTING (fontification):
4502 Keywords and standardized types, attributes, enumeration values, and
4503 function names (controlled by option `vhdl-highlight-keywords'), as well
4504 as comments, strings, and template prompts are highlighted using
4505 different colors. Unit, subprogram, signal, variable, constant,
4506 parameter and generic/port names in declarations as well as labels are
4507 highlighted if option `vhdl-highlight-names' is non-nil.
4508
4509 Additional reserved words or words with a forbidden syntax (e.g. words
4510 that should be avoided) can be specified in option
4511 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4512 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4513 keywords are highlighted as forbidden words if option
4514 `vhdl-highlight-verilog-keywords' is non-nil.
4515
4516 Words with special syntax can be highlighted by specifying their
4517 syntax and color in option `vhdl-special-syntax-alist' and by setting
4518 option `vhdl-highlight-special-words' to non-nil. This allows to
4519 establish some naming conventions (e.g. to distinguish different kinds
4520 of signals or other objects by using name suffices) and to support them
4521 visually.
4522
4523 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4524 to support case-sensitive highlighting. However, keywords are then only
4525 highlighted if written in lower case.
4526
4527 Code between \"translate_off\" and \"translate_on\" pragmas is
4528 highlighted using a different background color if option
4529 `vhdl-highlight-translate-off' is non-nil.
4530
4531 For documentation and customization of the used colors see
4532 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4533 highlighting of matching parenthesis, see customization group
4534 `paren-showing'. Automatic buffer highlighting is turned on/off by
4535 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4536
4537
4538 USER MODELS:
4539 VHDL models (templates) can be specified by the user and made accessible
4540 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4541 electrification. See option `vhdl-model-alist'.
4542
4543
4544 HIDE/SHOW:
4545 The code of blocks, processes, subprograms, component declarations and
4546 instantiations, generic/port clauses, and configuration declarations can
4547 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4548 the code (see customization group `vhdl-menu'). XEmacs: limited
4549 functionality due to old `hideshow.el' package.
4550
4551
4552 CODE UPDATING:
4553 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4554 current process, `C-c C-u M-s' of all processes in the current buffer.
4555 Limitations:
4556 - Only declared local signals (ports, signals declared in
4557 architecture and blocks) are automatically inserted.
4558 - Global signals declared in packages are not automatically inserted.
4559 Insert them once manually (will be kept afterwards).
4560 - Out parameters of procedures are considered to be read.
4561 Use option `vhdl-entity-file-name' to specify the entity file name
4562 \(used to obtain the port names).
4563
4564
4565 CODE FIXING:
4566 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4567 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4568
4569
4570 PRINTING:
4571 Postscript printing with different faces (an optimized set of faces is
4572 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4573 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4574 postscript printing commands. Option `vhdl-print-two-column' defines
4575 appropriate default settings for nice landscape two-column printing.
4576 The paper format can be set by option `ps-paper-type'. Do not forget to
4577 switch `ps-print-color-p' to nil for printing on black-and-white
4578 printers.
4579
4580
4581 OPTIONS:
4582 User options allow customization of VHDL Mode. All options are
4583 accessible from the \"Options\" menu entry. Simple options (switches
4584 and choices) can directly be changed, while for complex options a
4585 customization buffer is opened. Changed options can be saved for future
4586 sessions using the \"Save Options\" menu entry.
4587
4588 Options and their detailed descriptions can also be accessed by using
4589 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4590 customize-group' for groups). Some customizations only take effect
4591 after some action (read the NOTE in the option documentation).
4592 Customization can also be done globally (i.e. site-wide, read the
4593 INSTALL file).
4594
4595 Not all options are described in this documentation, so go and see
4596 what other useful user options there are (`M-x vhdl-customize' or menu)!
4597
4598
4599 FILE EXTENSIONS:
4600 As default, files with extensions \".vhd\" and \".vhdl\" are
4601 automatically recognized as VHDL source files. To add an extension
4602 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4603
4604 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4605
4606
4607 HINTS:
4608 - To start Emacs with open VHDL hierarchy browser without having to load
4609 a VHDL file first, use the command:
4610
4611 emacs -l vhdl-mode -f speedbar-frame-mode
4612
4613 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4614
4615 - Some features only work on properly indented code.
4616
4617
4618 RELEASE NOTES:
4619 See also the release notes (menu) for added features in new releases.
4620
4621
4622 Maintenance:
4623 ------------
4624
4625 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4626 Add a description of the problem and include a reproducible test case.
4627
4628 Questions and enhancement requests can be sent to <reto@gnu.org>.
4629
4630 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4631 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4632 releases. You are kindly invited to participate in beta testing. Subscribe
4633 to above mailing lists by sending an email to <reto@gnu.org>.
4634
4635 VHDL Mode is officially distributed at
4636 URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
4637 where the latest version can be found.
4638
4639
4640 Known problems:
4641 ---------------
4642
4643 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4644 - XEmacs: Incorrect start-up when automatically opening speedbar.
4645 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4646
4647
4648 The VHDL Mode Authors
4649 Reto Zimmermann and Rod Whitby
4650
4651 Key bindings:
4652 -------------
4653
4654 \\{vhdl-mode-map}"
4655 :abbrev-table vhdl-mode-abbrev-table
4656
4657 ;; set local variables
4658 (set (make-local-variable 'paragraph-start)
4659 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4660 (set (make-local-variable 'paragraph-separate) paragraph-start)
4661 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4662 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4663 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4664 (set (make-local-variable 'comment-start) "--")
4665 (set (make-local-variable 'comment-end) "")
4666 (when vhdl-emacs-21
4667 (set (make-local-variable 'comment-padding) ""))
4668 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4669 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4670 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4671 (set (make-local-variable 'comment-multi-line) nil)
4672 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4673 (set (make-local-variable 'hippie-expand-verbose) nil)
4674
4675 ;; setup the comment indent variable in a Emacs version portable way
4676 ;; ignore any byte compiler warnings you might get here
4677 (when (boundp 'comment-indent-function)
4678 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4679
4680 ;; initialize font locking
4681 (set (make-local-variable 'font-lock-defaults)
4682 (list
4683 '(nil vhdl-font-lock-keywords) nil
4684 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4685 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4686 (set (make-local-variable 'syntax-propertize-function)
4687 (syntax-propertize-rules
4688 ;; Mark single quotes as having string quote syntax in
4689 ;; 'c' instances.
4690 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4691 (set (make-local-variable 'font-lock-syntactic-keywords)
4692 vhdl-font-lock-syntactic-keywords))
4693 (unless vhdl-emacs-21
4694 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4695 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4696 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4697 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4698 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4699 ; (turn-on-font-lock)
4700
4701 ;; variables for source file compilation
4702 (when vhdl-compile-use-local-error-regexp
4703 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4704 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4705
4706 ;; add index menu
4707 (vhdl-index-menu-init)
4708 ;; add source file menu
4709 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4710 ;; add VHDL menu
4711 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4712 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4713 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4714 ;; initialize hideshow and add menu
4715 (vhdl-hideshow-init)
4716 (run-hooks 'menu-bar-update-hook)
4717
4718 ;; miscellaneous
4719 (vhdl-ps-print-init)
4720 (vhdl-write-file-hooks-init)
4721 (message "VHDL Mode %s.%s" vhdl-version
4722 (if noninteractive "" " See menu for documentation and release notes.")))
4723
4724 (defun vhdl-activate-customizations ()
4725 "Activate all customizations on local variables."
4726 (interactive)
4727 (vhdl-mode-map-init)
4728 (use-local-map vhdl-mode-map)
4729 (set-syntax-table vhdl-mode-syntax-table)
4730 (setq comment-column vhdl-inline-comment-column)
4731 (setq end-comment-column vhdl-end-comment-column)
4732 (vhdl-write-file-hooks-init)
4733 (vhdl-update-mode-menu)
4734 (vhdl-hideshow-init)
4735 (run-hooks 'menu-bar-update-hook))
4736
4737 (defun vhdl-write-file-hooks-init ()
4738 "Add/remove hooks when buffer is saved."
4739 (if vhdl-modify-date-on-saving
4740 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4741 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4742 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4743 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4744
4745 (defun vhdl-process-command-line-option (option)
4746 "Process command line options for VHDL Mode."
4747 (cond
4748 ;; set compiler
4749 ((equal option "-compiler")
4750 (vhdl-set-compiler (car command-line-args-left))
4751 (setq command-line-args-left (cdr command-line-args-left)))
4752 ;; set project
4753 ((equal option "-project")
4754 (vhdl-set-project (car command-line-args-left))
4755 (setq command-line-args-left (cdr command-line-args-left)))))
4756
4757 ;; make Emacs process VHDL Mode options
4758 (setq command-switch-alist
4759 (append command-switch-alist
4760 '(("-compiler" . vhdl-process-command-line-option)
4761 ("-project" . vhdl-process-command-line-option))))
4762
4763
4764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4765 ;;; Keywords and standardized words
4766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4767
4768 (defconst vhdl-93-keywords
4769 '(
4770 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4771 "assert" "attribute"
4772 "begin" "block" "body" "buffer" "bus"
4773 "case" "component" "configuration" "constant"
4774 "disconnect" "downto"
4775 "else" "elsif" "end" "entity" "exit"
4776 "file" "for" "function"
4777 "generate" "generic" "group" "guarded"
4778 "if" "impure" "in" "inertial" "inout" "is"
4779 "label" "library" "linkage" "literal" "loop"
4780 "map" "mod"
4781 "nand" "new" "next" "nor" "not" "null"
4782 "of" "on" "open" "or" "others" "out"
4783 "package" "port" "postponed" "procedure" "process" "pure"
4784 "range" "record" "register" "reject" "rem" "report" "return"
4785 "rol" "ror"
4786 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4787 "then" "to" "transport" "type"
4788 "unaffected" "units" "until" "use"
4789 "variable"
4790 "wait" "when" "while" "with"
4791 "xnor" "xor"
4792 )
4793 "List of VHDL'93 keywords.")
4794
4795 (defconst vhdl-ams-keywords
4796 '(
4797 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4798 "reference" "spectrum" "subnature" "terminal" "through"
4799 "tolerance"
4800 )
4801 "List of VHDL-AMS keywords.")
4802
4803 (defconst vhdl-verilog-keywords
4804 '(
4805 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4806 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4807 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4808 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4809 "endprimitive" "endspecify" "endtable" "endtask" "event"
4810 "for" "force" "forever" "fork" "function"
4811 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4812 "macromodule" "makefile" "medium" "module"
4813 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4814 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4815 "pullup"
4816 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4817 "rtranif0" "rtranif1"
4818 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4819 "strong1" "supply" "supply0" "supply1"
4820 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4821 "triand" "trior" "trireg"
4822 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4823 )
4824 "List of Verilog keywords as candidate for additional reserved words.")
4825
4826 (defconst vhdl-93-types
4827 '(
4828 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4829 "real" "time" "natural" "positive" "string" "line" "text" "side"
4830 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4831 "std_logic" "std_logic_vector"
4832 "std_ulogic" "std_ulogic_vector"
4833 )
4834 "List of VHDL'93 standardized types.")
4835
4836 (defconst vhdl-ams-types
4837 '(
4838 "domain_type" "real_vector"
4839 ;; from `nature_pkg' package
4840 "voltage" "current" "electrical" "position" "velocity" "force"
4841 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4842 "pressure" "flowrate" "fluid"
4843 )
4844 "List of VHDL-AMS standardized types.")
4845
4846 (defconst vhdl-math-types
4847 '(
4848 "complex" "complex_polar"
4849 )
4850 "List of Math Packages standardized types.")
4851
4852 (defconst vhdl-93-attributes
4853 '(
4854 "base" "left" "right" "high" "low" "pos" "val" "succ"
4855 "pred" "leftof" "rightof" "range" "reverse_range"
4856 "length" "delayed" "stable" "quiet" "transaction"
4857 "event" "active" "last_event" "last_active" "last_value"
4858 "driving" "driving_value" "ascending" "value" "image"
4859 "simple_name" "instance_name" "path_name"
4860 "foreign"
4861 )
4862 "List of VHDL'93 standardized attributes.")
4863
4864 (defconst vhdl-ams-attributes
4865 '(
4866 "across" "through"
4867 "reference" "contribution" "tolerance"
4868 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4869 "ramp" "slew"
4870 )
4871 "List of VHDL-AMS standardized attributes.")
4872
4873 (defconst vhdl-93-enum-values
4874 '(
4875 "true" "false"
4876 "note" "warning" "error" "failure"
4877 "read_mode" "write_mode" "append_mode"
4878 "open_ok" "status_error" "name_error" "mode_error"
4879 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4880 "right" "left"
4881 )
4882 "List of VHDL'93 standardized enumeration values.")
4883
4884 (defconst vhdl-ams-enum-values
4885 '(
4886 "quiescent_domain" "time_domain" "frequency_domain"
4887 ;; from `nature_pkg' package
4888 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4889 )
4890 "List of VHDL-AMS standardized enumeration values.")
4891
4892 (defconst vhdl-math-constants
4893 '(
4894 "math_e" "math_1_over_e"
4895 "math_pi" "math_two_pi" "math_1_over_pi"
4896 "math_half_pi" "math_q_pi" "math_3_half_pi"
4897 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4898 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4899 "math_deg_to_rad" "math_rad_to_deg"
4900 "cbase_1" "cbase_j" "czero"
4901 )
4902 "List of Math Packages standardized constants.")
4903
4904 (defconst vhdl-93-functions
4905 '(
4906 "now" "resolved" "rising_edge" "falling_edge"
4907 "read" "readline" "write" "writeline" "endfile"
4908 "resize" "is_X" "std_match"
4909 "shift_left" "shift_right" "rotate_left" "rotate_right"
4910 "to_unsigned" "to_signed" "to_integer"
4911 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4912 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4913 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4914 "shl" "shr" "ext" "sxt"
4915 "deallocate"
4916 )
4917 "List of VHDL'93 standardized functions.")
4918
4919 (defconst vhdl-ams-functions
4920 '(
4921 "frequency"
4922 )
4923 "List of VHDL-AMS standardized functions.")
4924
4925 (defconst vhdl-math-functions
4926 '(
4927 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4928 "sqrt" "cbrt" "exp" "log"
4929 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4930 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4931 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4932 )
4933 "List of Math Packages standardized functions.")
4934
4935 (defconst vhdl-93-packages
4936 '(
4937 "std_logic_1164" "numeric_std" "numeric_bit"
4938 "standard" "textio"
4939 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4940 "std_logic_misc" "std_logic_textio"
4941 "ieee" "std" "work"
4942 )
4943 "List of VHDL'93 standardized packages and libraries.")
4944
4945 (defconst vhdl-ams-packages
4946 '(
4947 ;; from `nature_pkg' package
4948 "nature_pkg"
4949 )
4950 "List of VHDL-AMS standardized packages and libraries.")
4951
4952 (defconst vhdl-math-packages
4953 '(
4954 "math_real" "math_complex"
4955 )
4956 "List of Math Packages standardized packages and libraries.")
4957
4958 (defvar vhdl-keywords nil
4959 "List of VHDL keywords.")
4960
4961 (defvar vhdl-types nil
4962 "List of VHDL standardized types.")
4963
4964 (defvar vhdl-attributes nil
4965 "List of VHDL standardized attributes.")
4966
4967 (defvar vhdl-enum-values nil
4968 "List of VHDL standardized enumeration values.")
4969
4970 (defvar vhdl-constants nil
4971 "List of VHDL standardized constants.")
4972
4973 (defvar vhdl-functions nil
4974 "List of VHDL standardized functions.")
4975
4976 (defvar vhdl-packages nil
4977 "List of VHDL standardized packages and libraries.")
4978
4979 (defvar vhdl-reserved-words nil
4980 "List of additional reserved words.")
4981
4982 (defvar vhdl-keywords-regexp nil
4983 "Regexp for VHDL keywords.")
4984
4985 (defvar vhdl-types-regexp nil
4986 "Regexp for VHDL standardized types.")
4987
4988 (defvar vhdl-attributes-regexp nil
4989 "Regexp for VHDL standardized attributes.")
4990
4991 (defvar vhdl-enum-values-regexp nil
4992 "Regexp for VHDL standardized enumeration values.")
4993
4994 (defvar vhdl-functions-regexp nil
4995 "Regexp for VHDL standardized functions.")
4996
4997 (defvar vhdl-packages-regexp nil
4998 "Regexp for VHDL standardized packages and libraries.")
4999
5000 (defvar vhdl-reserved-words-regexp nil
5001 "Regexp for additional reserved words.")
5002
5003 (defvar vhdl-directive-keywords-regexp nil
5004 "Regexp for compiler directive keywords.")
5005
5006 (defun vhdl-words-init ()
5007 "Initialize reserved words."
5008 (setq vhdl-keywords
5009 (append vhdl-93-keywords
5010 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5011 (setq vhdl-types
5012 (append vhdl-93-types
5013 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5014 (when (vhdl-standard-p 'math) vhdl-math-types)))
5015 (setq vhdl-attributes
5016 (append vhdl-93-attributes
5017 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5018 (setq vhdl-enum-values
5019 (append vhdl-93-enum-values
5020 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5021 (setq vhdl-constants
5022 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5023 (setq vhdl-functions
5024 (append vhdl-93-functions
5025 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5026 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5027 (setq vhdl-packages
5028 (append vhdl-93-packages
5029 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5030 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5031 (setq vhdl-reserved-words
5032 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5033 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5034 '("")))
5035 (setq vhdl-keywords-regexp
5036 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5037 (setq vhdl-types-regexp
5038 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5039 (setq vhdl-attributes-regexp
5040 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5041 (setq vhdl-enum-values-regexp
5042 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5043 (setq vhdl-functions-regexp
5044 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5045 (setq vhdl-packages-regexp
5046 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5047 (setq vhdl-reserved-words-regexp
5048 (concat "\\<\\("
5049 (unless (equal vhdl-forbidden-syntax "")
5050 (concat vhdl-forbidden-syntax "\\|"))
5051 (regexp-opt vhdl-reserved-words)
5052 "\\)\\>"))
5053 (setq vhdl-directive-keywords-regexp
5054 (concat "\\<\\(" (mapconcat 'regexp-quote
5055 vhdl-directive-keywords "\\|") "\\)\\>"))
5056 (vhdl-abbrev-list-init))
5057
5058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5059 ;; Words to expand
5060
5061 (defvar vhdl-abbrev-list nil
5062 "Predefined abbreviations for VHDL.")
5063
5064 (defun vhdl-abbrev-list-init ()
5065 (setq vhdl-abbrev-list
5066 (append
5067 (list vhdl-upper-case-keywords) vhdl-keywords
5068 (list vhdl-upper-case-types) vhdl-types
5069 (list vhdl-upper-case-attributes) vhdl-attributes
5070 (list vhdl-upper-case-enum-values) vhdl-enum-values
5071 (list vhdl-upper-case-constants) vhdl-constants
5072 (list nil) vhdl-functions
5073 (list nil) vhdl-packages)))
5074
5075 ;; initialize reserved words for VHDL Mode
5076 (vhdl-words-init)
5077
5078
5079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5080 ;;; Indentation
5081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5082
5083 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5084 ;; Syntax analysis
5085
5086 ;; constant regular expressions for looking at various constructs
5087
5088 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5089 "Regexp describing a VHDL symbol.
5090 We cannot use just `word' syntax class since `_' cannot be in word
5091 class. Putting underscore in word class breaks forward word movement
5092 behavior that users are familiar with.")
5093
5094 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5095 "Regexp describing a case statement header key.")
5096
5097 (defconst vhdl-label-key
5098 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5099 "Regexp describing a VHDL label.")
5100
5101 ;; Macro definitions:
5102
5103 (defmacro vhdl-point (position)
5104 "Return the value of point at certain commonly referenced POSITIONs.
5105 POSITION can be one of the following symbols:
5106
5107 bol -- beginning of line
5108 eol -- end of line
5109 bod -- beginning of defun
5110 boi -- back to indentation
5111 eoi -- last whitespace on line
5112 ionl -- indentation of next line
5113 iopl -- indentation of previous line
5114 bonl -- beginning of next line
5115 bopl -- beginning of previous line
5116
5117 This function does not modify point or mark."
5118 (or (and (eq 'quote (car-safe position))
5119 (null (cddr position)))
5120 (error "ERROR: Bad buffer position requested: %s" position))
5121 (setq position (nth 1 position))
5122 `(let ((here (point)))
5123 ,@(cond
5124 ((eq position 'bol) '((beginning-of-line)))
5125 ((eq position 'eol) '((end-of-line)))
5126 ((eq position 'bod) '((save-match-data
5127 (vhdl-beginning-of-defun))))
5128 ((eq position 'boi) '((back-to-indentation)))
5129 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5130 ((eq position 'bonl) '((forward-line 1)))
5131 ((eq position 'bopl) '((forward-line -1)))
5132 ((eq position 'iopl)
5133 '((forward-line -1)
5134 (back-to-indentation)))
5135 ((eq position 'ionl)
5136 '((forward-line 1)
5137 (back-to-indentation)))
5138 (t (error "ERROR: Unknown buffer position requested: %s" position))
5139 )
5140 (prog1
5141 (point)
5142 (goto-char here))
5143 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5144 ;; doesn't hurt for v19
5145 ,@nil
5146 ))
5147
5148 (defmacro vhdl-safe (&rest body)
5149 "Safely execute BODY, return nil if an error occurred."
5150 `(condition-case nil
5151 (progn ,@body)
5152 (error nil)))
5153
5154 (defmacro vhdl-add-syntax (symbol &optional relpos)
5155 "A simple macro to append the syntax in SYMBOL to the syntax list.
5156 Try to increase performance by using this macro."
5157 `(setq vhdl-syntactic-context
5158 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5159
5160 (defmacro vhdl-has-syntax (symbol)
5161 "A simple macro to return check the syntax list.
5162 Try to increase performance by using this macro."
5163 `(assoc ,symbol vhdl-syntactic-context))
5164
5165 ;; Syntactic element offset manipulation:
5166
5167 (defun vhdl-read-offset (langelem)
5168 "Read new offset value for LANGELEM from minibuffer.
5169 Return a valid value only."
5170 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5171 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5172 (prompt "Offset: ")
5173 offset input interned)
5174 (while (not offset)
5175 (setq input (read-string prompt oldoff)
5176 offset (cond ((string-equal "+" input) '+)
5177 ((string-equal "-" input) '-)
5178 ((string-equal "++" input) '++)
5179 ((string-equal "--" input) '--)
5180 ((string-match "^-?[0-9]+$" input)
5181 (string-to-number input))
5182 ((fboundp (setq interned (intern input)))
5183 interned)
5184 ((boundp interned) interned)
5185 ;; error, but don't signal one, keep trying
5186 ;; to read an input value
5187 (t (ding)
5188 (setq prompt errmsg)
5189 nil))))
5190 offset))
5191
5192 (defun vhdl-set-offset (symbol offset &optional add-p)
5193 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5194 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5195 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5196 `vhdl-offsets-alist' if it doesn't already appear there."
5197 (interactive
5198 (let* ((langelem
5199 (intern (completing-read
5200 (concat "Syntactic symbol to change"
5201 (if current-prefix-arg " or add" "")
5202 ": ")
5203 (mapcar
5204 (function
5205 (lambda (langelem)
5206 (cons (format "%s" (car langelem)) nil)))
5207 vhdl-offsets-alist)
5208 nil (not current-prefix-arg)
5209 ;; initial contents tries to be the last element
5210 ;; on the syntactic analysis list for the current
5211 ;; line
5212 (let* ((syntax (vhdl-get-syntactic-context))
5213 (len (length syntax))
5214 (ic (format "%s" (car (nth (1- len) syntax)))))
5215 ic)
5216 )))
5217 (offset (vhdl-read-offset langelem)))
5218 (list langelem offset current-prefix-arg)))
5219 ;; sanity check offset
5220 (or (eq offset '+)
5221 (eq offset '-)
5222 (eq offset '++)
5223 (eq offset '--)
5224 (integerp offset)
5225 (fboundp offset)
5226 (boundp offset)
5227 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5228 offset))
5229 (let ((entry (assq symbol vhdl-offsets-alist)))
5230 (if entry
5231 (setcdr entry offset)
5232 (if add-p
5233 (setq vhdl-offsets-alist
5234 (cons (cons symbol offset) vhdl-offsets-alist))
5235 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5236 (vhdl-keep-region-active))
5237
5238 (defun vhdl-set-style (style &optional local)
5239 "Set `vhdl-mode' variables to use one of several different indentation styles.
5240 STYLE is a string representing the desired style and optional LOCAL is
5241 a flag which, if non-nil, means to make the style variables being
5242 changed buffer local, instead of the default, which is to set the
5243 global variables. Interactively, the flag comes from the prefix
5244 argument. The styles are chosen from the `vhdl-style-alist' variable."
5245 (interactive (list (completing-read "Use which VHDL indentation style? "
5246 vhdl-style-alist nil t)
5247 current-prefix-arg))
5248 (let ((vars (cdr (assoc style vhdl-style-alist))))
5249 (or vars
5250 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5251 ;; set all the variables
5252 (mapc
5253 (function
5254 (lambda (varentry)
5255 (let ((var (car varentry))
5256 (val (cdr varentry)))
5257 ;; special case for vhdl-offsets-alist
5258 (if (not (eq var 'vhdl-offsets-alist))
5259 (set (if local (make-local-variable var) var) val)
5260 ;; reset vhdl-offsets-alist to the default value first
5261 (set (if local (make-local-variable var) var)
5262 (copy-alist vhdl-offsets-alist-default))
5263 ;; now set the langelems that are different
5264 (mapcar
5265 (function
5266 (lambda (langentry)
5267 (let ((langelem (car langentry))
5268 (offset (cdr langentry)))
5269 (vhdl-set-offset langelem offset)
5270 )))
5271 val))
5272 )))
5273 vars))
5274 (vhdl-keep-region-active))
5275
5276 (defun vhdl-get-offset (langelem)
5277 "Get offset from LANGELEM which is a cons cell of the form:
5278 \(SYMBOL . RELPOS). The symbol is matched against
5279 vhdl-offsets-alist and the offset found there is either returned,
5280 or added to the indentation at RELPOS. If RELPOS is nil, then
5281 the offset is simply returned."
5282 (let* ((symbol (car langelem))
5283 (relpos (cdr langelem))
5284 (match (assq symbol vhdl-offsets-alist))
5285 (offset (cdr-safe match)))
5286 ;; offset can be a number, a function, a variable, or one of the
5287 ;; symbols + or -
5288 (cond
5289 ((not match)
5290 (if vhdl-strict-syntax-p
5291 (error "ERROR: Don't know how to indent a %s" symbol)
5292 (setq offset 0
5293 relpos 0)))
5294 ((eq offset '+) (setq offset vhdl-basic-offset))
5295 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5296 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5297 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5298 ((and (not (numberp offset))
5299 (fboundp offset))
5300 (setq offset (funcall offset langelem)))
5301 ((not (numberp offset))
5302 (setq offset (eval offset)))
5303 )
5304 (+ (if (and relpos
5305 (< relpos (vhdl-point 'bol)))
5306 (save-excursion
5307 (goto-char relpos)
5308 (current-column))
5309 0)
5310 offset)))
5311
5312 ;; Syntactic support functions:
5313
5314 (defun vhdl-in-comment-p ()
5315 "Check if point is in a comment."
5316 (eq (vhdl-in-literal) 'comment))
5317
5318 (defun vhdl-in-string-p ()
5319 "Check if point is in a string."
5320 (eq (vhdl-in-literal) 'string))
5321
5322 (defun vhdl-in-literal ()
5323 "Determine if point is in a VHDL literal."
5324 (save-excursion
5325 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5326 (cond
5327 ((nth 3 state) 'string)
5328 ((nth 4 state) 'comment)
5329 ((vhdl-beginning-of-macro) 'pound)
5330 (t nil)))))
5331
5332 (defun vhdl-forward-comment (&optional direction)
5333 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5334 negative, skip forward otherwise."
5335 (interactive "p")
5336 (if (and direction (< direction 0))
5337 ;; skip backwards
5338 (progn
5339 (skip-chars-backward " \t\n")
5340 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5341 (goto-char (match-beginning 3))
5342 (skip-chars-backward " \t\n")))
5343 ;; skip forwards
5344 (skip-chars-forward " \t\n")
5345 (while (looking-at "--.*")
5346 (goto-char (match-end 0))
5347 (skip-chars-forward " \t\n"))))
5348
5349 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5350 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5351 (defalias 'vhdl-forward-comment 'forward-comment))
5352
5353 ;; This is the best we can do in Win-Emacs.
5354 (defun vhdl-win-il (&optional lim)
5355 "Determine if point is in a VHDL literal."
5356 (save-excursion
5357 (let* ((here (point))
5358 (state nil)
5359 (match nil)
5360 (lim (or lim (vhdl-point 'bod))))
5361 (goto-char lim )
5362 (while (< (point) here)
5363 (setq match
5364 (and (re-search-forward "--\\|[\"']"
5365 here 'move)
5366 (buffer-substring (match-beginning 0) (match-end 0))))
5367 (setq state
5368 (cond
5369 ;; no match
5370 ((null match) nil)
5371 ;; looking at the opening of a VHDL style comment
5372 ((string= "--" match)
5373 (if (<= here (progn (end-of-line) (point))) 'comment))
5374 ;; looking at the opening of a double quote string
5375 ((string= "\"" match)
5376 (if (not (save-restriction
5377 ;; this seems to be necessary since the
5378 ;; re-search-forward will not work without it
5379 (narrow-to-region (point) here)
5380 (re-search-forward
5381 ;; this regexp matches a double quote
5382 ;; which is preceded by an even number
5383 ;; of backslashes, including zero
5384 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5385 'string))
5386 ;; looking at the opening of a single quote string
5387 ((string= "'" match)
5388 (if (not (save-restriction
5389 ;; see comments from above
5390 (narrow-to-region (point) here)
5391 (re-search-forward
5392 ;; this matches a single quote which is
5393 ;; preceded by zero or two backslashes.
5394 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5395 here 'move)))
5396 'string))
5397 (t nil)))
5398 ) ; end-while
5399 state)))
5400
5401 (and (string-match "Win-Emacs" emacs-version)
5402 (fset 'vhdl-in-literal 'vhdl-win-il))
5403
5404 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5405 ;; defined as lexical whitespace or comments. Search no farther back
5406 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5407 ;; used for backward skipping, (point-max) is used for forward
5408 ;; skipping.
5409
5410 (defun vhdl-forward-syntactic-ws (&optional lim)
5411 "Forward skip of syntactic whitespace."
5412 (let* ((here (point-max))
5413 (hugenum (point-max)))
5414 (while (/= here (point))
5415 (setq here (point))
5416 (vhdl-forward-comment hugenum)
5417 ;; skip preprocessor directives
5418 (when (and (eq (char-after) ?#)
5419 (= (vhdl-point 'boi) (point)))
5420 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5421 (= (forward-line 1) 0)))
5422 (end-of-line)))
5423 (if lim (goto-char (min (point) lim)))))
5424
5425
5426 ;; This is the best we can do in Win-Emacs.
5427 (defun vhdl-win-fsws (&optional lim)
5428 "Forward skip syntactic whitespace for Win-Emacs."
5429 (let ((lim (or lim (point-max)))
5430 stop)
5431 (while (not stop)
5432 (skip-chars-forward " \t\n\r\f" lim)
5433 (cond
5434 ;; vhdl comment
5435 ((looking-at "--") (end-of-line))
5436 ;; none of the above
5437 (t (setq stop t))))))
5438
5439 (and (string-match "Win-Emacs" emacs-version)
5440 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5441
5442 (defun vhdl-beginning-of-macro (&optional lim)
5443 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5444 (let ((here (point)))
5445 (beginning-of-line)
5446 (while (eq (char-before (1- (point))) ?\\)
5447 (forward-line -1))
5448 (back-to-indentation)
5449 (if (and (<= (point) here)
5450 (eq (char-after) ?#))
5451 t
5452 (goto-char here)
5453 nil)))
5454
5455 (defun vhdl-backward-syntactic-ws (&optional lim)
5456 "Backward skip over syntactic whitespace."
5457 (let* ((here (point-min))
5458 (hugenum (- (point-max))))
5459 (while (/= here (point))
5460 (setq here (point))
5461 (vhdl-forward-comment hugenum)
5462 (vhdl-beginning-of-macro))
5463 (if lim (goto-char (max (point) lim)))))
5464
5465 ;; This is the best we can do in Win-Emacs.
5466 (defun vhdl-win-bsws (&optional lim)
5467 "Backward skip syntactic whitespace for Win-Emacs."
5468 (let ((lim (or lim (vhdl-point 'bod)))
5469 stop)
5470 (while (not stop)
5471 (skip-chars-backward " \t\n\r\f" lim)
5472 (cond
5473 ;; vhdl comment
5474 ((eq (vhdl-in-literal) 'comment)
5475 (skip-chars-backward "^-" lim)
5476 (skip-chars-backward "-" lim)
5477 (while (not (or (and (= (following-char) ?-)
5478 (= (char-after (1+ (point))) ?-))
5479 (<= (point) lim)))
5480 (skip-chars-backward "^-" lim)
5481 (skip-chars-backward "-" lim)))
5482 ;; none of the above
5483 (t (setq stop t))))))
5484
5485 (and (string-match "Win-Emacs" emacs-version)
5486 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5487
5488 ;; Functions to help finding the correct indentation column:
5489
5490 (defun vhdl-first-word (point)
5491 "If the keyword at POINT is at boi, then return (current-column) at
5492 that point, else nil."
5493 (save-excursion
5494 (and (goto-char point)
5495 (eq (point) (vhdl-point 'boi))
5496 (current-column))))
5497
5498 (defun vhdl-last-word (point)
5499 "If the keyword at POINT is at eoi, then return (current-column) at
5500 that point, else nil."
5501 (save-excursion
5502 (and (goto-char point)
5503 (save-excursion (or (eq (progn (forward-sexp) (point))
5504 (vhdl-point 'eoi))
5505 (looking-at "\\s-*\\(--\\)?")))
5506 (current-column))))
5507
5508 ;; Core syntactic evaluation functions:
5509
5510 (defconst vhdl-libunit-re
5511 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5512
5513 (defun vhdl-libunit-p ()
5514 (and
5515 (save-excursion
5516 (forward-sexp)
5517 (skip-chars-forward " \t\n")
5518 (not (looking-at "is\\b[^_]")))
5519 (save-excursion
5520 (backward-sexp)
5521 (and (not (looking-at "use\\b[^_]"))
5522 (progn
5523 (forward-sexp)
5524 (vhdl-forward-syntactic-ws)
5525 (/= (following-char) ?:))))
5526 ))
5527
5528 (defconst vhdl-defun-re
5529 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5530
5531 (defun vhdl-defun-p ()
5532 (save-excursion
5533 (if (looking-at "block\\|process\\|procedural")
5534 ;; "block", "process", "procedural":
5535 (save-excursion
5536 (backward-sexp)
5537 (not (looking-at "end\\s-+\\w")))
5538 ;; "architecture", "configuration", "entity",
5539 ;; "package", "procedure", "function":
5540 t)))
5541
5542 (defun vhdl-corresponding-defun ()
5543 "If the word at the current position corresponds to a \"defun\"
5544 keyword, then return a string that can be used to find the
5545 corresponding \"begin\" keyword, else return nil."
5546 (save-excursion
5547 (and (looking-at vhdl-defun-re)
5548 (vhdl-defun-p)
5549 (if (looking-at "block\\|process\\|procedural")
5550 ;; "block", "process". "procedural:
5551 (buffer-substring (match-beginning 0) (match-end 0))
5552 ;; "architecture", "configuration", "entity", "package",
5553 ;; "procedure", "function":
5554 "is"))))
5555
5556 (defconst vhdl-begin-fwd-re
5557 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5558 "A regular expression for searching forward that matches all known
5559 \"begin\" keywords.")
5560
5561 (defconst vhdl-begin-bwd-re
5562 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5563 "A regular expression for searching backward that matches all known
5564 \"begin\" keywords.")
5565
5566 (defun vhdl-begin-p (&optional lim)
5567 "Return t if we are looking at a real \"begin\" keyword.
5568 Assumes that the caller will make sure that we are looking at
5569 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5570 the middle of an identifier that just happens to contain a \"begin\"
5571 keyword."
5572 (cond
5573 ;; "[architecture|case|configuration|entity|package|
5574 ;; procedure|function] ... is":
5575 ((and (looking-at "i")
5576 (save-excursion
5577 ;; Skip backward over first sexp (needed to skip over a
5578 ;; procedure interface list, and is harmless in other
5579 ;; situations). Note that we need "return" in the
5580 ;; following search list so that we don't run into
5581 ;; semicolons in the function interface list.
5582 (backward-sexp)
5583 (let (foundp)
5584 (while (and (not foundp)
5585 (re-search-backward
5586 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5587 lim 'move))
5588 (if (or (= (preceding-char) ?_)
5589 (vhdl-in-literal))
5590 (backward-char)
5591 (setq foundp t))))
5592 (and (/= (following-char) ?\;)
5593 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5594 t)
5595 ;; "begin", "then":
5596 ((looking-at "be\\|t")
5597 t)
5598 ;; "else":
5599 ((and (looking-at "e")
5600 ;; make sure that the "else" isn't inside a
5601 ;; conditional signal assignment.
5602 (save-excursion
5603 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5604 (or (eq (following-char) ?\;)
5605 (eq (point) lim))))
5606 t)
5607 ;; "block", "generate", "loop", "process", "procedural",
5608 ;; "units", "record":
5609 ((and (looking-at "bl\\|[glpur]")
5610 (save-excursion
5611 (backward-sexp)
5612 (not (looking-at "end\\s-+\\w"))))
5613 t)
5614 ;; "component":
5615 ((and (looking-at "c")
5616 (save-excursion
5617 (backward-sexp)
5618 (not (looking-at "end\\s-+\\w")))
5619 ;; look out for the dreaded entity class in an attribute
5620 (save-excursion
5621 (vhdl-backward-syntactic-ws lim)
5622 (/= (preceding-char) ?:)))
5623 t)
5624 ;; "for" (inside configuration declaration):
5625 ((and (looking-at "f")
5626 (save-excursion
5627 (backward-sexp)
5628 (not (looking-at "end\\s-+\\w")))
5629 (vhdl-has-syntax 'configuration))
5630 t)
5631 ))
5632
5633 (defun vhdl-corresponding-mid (&optional lim)
5634 (cond
5635 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5636 "begin")
5637 ((looking-at "then")
5638 "<else>")
5639 (t
5640 "end")))
5641
5642 (defun vhdl-corresponding-end (&optional lim)
5643 "If the word at the current position corresponds to a \"begin\"
5644 keyword, then return a vector containing enough information to find
5645 the corresponding \"end\" keyword, else return nil. The keyword to
5646 search forward for is aref 0. The column in which the keyword must
5647 appear is aref 1 or nil if any column is suitable.
5648 Assumes that the caller will make sure that we are not in the middle
5649 of an identifier that just happens to contain a \"begin\" keyword."
5650 (save-excursion
5651 (and (looking-at vhdl-begin-fwd-re)
5652 (/= (preceding-char) ?_)
5653 (not (vhdl-in-literal))
5654 (vhdl-begin-p lim)
5655 (cond
5656 ;; "is", "generate", "loop":
5657 ((looking-at "[igl]")
5658 (vector "end"
5659 (and (vhdl-last-word (point))
5660 (or (vhdl-first-word (point))
5661 (save-excursion
5662 (vhdl-beginning-of-statement-1 lim)
5663 (vhdl-backward-skip-label lim)
5664 (vhdl-first-word (point)))))))
5665 ;; "begin", "else", "for":
5666 ((looking-at "be\\|[ef]")
5667 (vector "end"
5668 (and (vhdl-last-word (point))
5669 (or (vhdl-first-word (point))
5670 (save-excursion
5671 (vhdl-beginning-of-statement-1 lim)
5672 (vhdl-backward-skip-label lim)
5673 (vhdl-first-word (point)))))))
5674 ;; "component", "units", "record":
5675 ((looking-at "[cur]")
5676 ;; The first end found will close the block
5677 (vector "end" nil))
5678 ;; "block", "process", "procedural":
5679 ((looking-at "bl\\|p")
5680 (vector "end"
5681 (or (vhdl-first-word (point))
5682 (save-excursion
5683 (vhdl-beginning-of-statement-1 lim)
5684 (vhdl-backward-skip-label lim)
5685 (vhdl-first-word (point))))))
5686 ;; "then":
5687 ((looking-at "t")
5688 (vector "elsif\\|else\\|end\\s-+if"
5689 (and (vhdl-last-word (point))
5690 (or (vhdl-first-word (point))
5691 (save-excursion
5692 (vhdl-beginning-of-statement-1 lim)
5693 (vhdl-backward-skip-label lim)
5694 (vhdl-first-word (point)))))))
5695 ))))
5696
5697 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5698
5699 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5700
5701 (defun vhdl-end-p (&optional lim)
5702 "Return t if we are looking at a real \"end\" keyword.
5703 Assumes that the caller will make sure that we are looking at
5704 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5705 the middle of an identifier that just happens to contain an \"end\"
5706 keyword."
5707 (or (not (looking-at "else"))
5708 ;; make sure that the "else" isn't inside a conditional signal
5709 ;; assignment.
5710 (save-excursion
5711 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5712 (or (eq (following-char) ?\;)
5713 (eq (point) lim)
5714 (vhdl-in-literal)))))
5715
5716 (defun vhdl-corresponding-begin (&optional lim)
5717 "If the word at the current position corresponds to an \"end\"
5718 keyword, then return a vector containing enough information to find
5719 the corresponding \"begin\" keyword, else return nil. The keyword to
5720 search backward for is aref 0. The column in which the keyword must
5721 appear is aref 1 or nil if any column is suitable. The supplementary
5722 keyword to search forward for is aref 2 or nil if this is not
5723 required. If aref 3 is t, then the \"begin\" keyword may be found in
5724 the middle of a statement.
5725 Assumes that the caller will make sure that we are not in the middle
5726 of an identifier that just happens to contain an \"end\" keyword."
5727 (save-excursion
5728 (let (pos)
5729 (if (and (looking-at vhdl-end-fwd-re)
5730 (not (vhdl-in-literal))
5731 (vhdl-end-p lim))
5732 (if (looking-at "el")
5733 ;; "else", "elsif":
5734 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5735 ;; "end ...":
5736 (setq pos (point))
5737 (forward-sexp)
5738 (skip-chars-forward " \t\n")
5739 (cond
5740 ;; "end if":
5741 ((looking-at "if\\b[^_]")
5742 (vector "else\\|elsif\\|if"
5743 (vhdl-first-word pos)
5744 "else\\|then" nil))
5745 ;; "end component":
5746 ((looking-at "component\\b[^_]")
5747 (vector (buffer-substring (match-beginning 1)
5748 (match-end 1))
5749 (vhdl-first-word pos)
5750 nil nil))
5751 ;; "end units", "end record":
5752 ((looking-at "\\(units\\|record\\)\\b[^_]")
5753 (vector (buffer-substring (match-beginning 1)
5754 (match-end 1))
5755 (vhdl-first-word pos)
5756 nil t))
5757 ;; "end block", "end process", "end procedural":
5758 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5759 (vector "begin" (vhdl-first-word pos) nil nil))
5760 ;; "end case":
5761 ((looking-at "case\\b[^_]")
5762 (vector "case" (vhdl-first-word pos) "is" nil))
5763 ;; "end generate":
5764 ((looking-at "generate\\b[^_]")
5765 (vector "generate\\|for\\|if"
5766 (vhdl-first-word pos)
5767 "generate" nil))
5768 ;; "end loop":
5769 ((looking-at "loop\\b[^_]")
5770 (vector "loop\\|while\\|for"
5771 (vhdl-first-word pos)
5772 "loop" nil))
5773 ;; "end for" (inside configuration declaration):
5774 ((looking-at "for\\b[^_]")
5775 (vector "for" (vhdl-first-word pos) nil nil))
5776 ;; "end [id]":
5777 (t
5778 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5779 (vhdl-first-word pos)
5780 ;; return an alist of (statement . keyword) mappings
5781 '(
5782 ;; "begin ... end [id]":
5783 ("begin" . nil)
5784 ;; "architecture ... is ... begin ... end [id]":
5785 ("architecture" . "is")
5786 ;; "configuration ... is ... end [id]":
5787 ("configuration" . "is")
5788 ;; "entity ... is ... end [id]":
5789 ("entity" . "is")
5790 ;; "package ... is ... end [id]":
5791 ("package" . "is")
5792 ;; "procedure ... is ... begin ... end [id]":
5793 ("procedure" . "is")
5794 ;; "function ... is ... begin ... end [id]":
5795 ("function" . "is")
5796 )
5797 nil))
5798 ))) ; "end ..."
5799 )))
5800
5801 (defconst vhdl-leader-re
5802 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5803
5804 (defun vhdl-end-of-leader ()
5805 (save-excursion
5806 (cond ((looking-at "block\\|process\\|procedural")
5807 (if (save-excursion
5808 (forward-sexp)
5809 (skip-chars-forward " \t\n")
5810 (= (following-char) ?\())
5811 (forward-sexp 2)
5812 (forward-sexp))
5813 (when (looking-at "[ \t\n]*is")
5814 (goto-char (match-end 0)))
5815 (point))
5816 ((looking-at "component")
5817 (forward-sexp 2)
5818 (when (looking-at "[ \t\n]*is")
5819 (goto-char (match-end 0)))
5820 (point))
5821 ((looking-at "for")
5822 (forward-sexp 2)
5823 (skip-chars-forward " \t\n")
5824 (while (looking-at "[,:(]")
5825 (forward-sexp)
5826 (skip-chars-forward " \t\n"))
5827 (point))
5828 (t nil)
5829 )))
5830
5831 (defconst vhdl-trailer-re
5832 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5833
5834 (defconst vhdl-statement-fwd-re
5835 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5836 "A regular expression for searching forward that matches all known
5837 \"statement\" keywords.")
5838
5839 (defconst vhdl-statement-bwd-re
5840 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5841 "A regular expression for searching backward that matches all known
5842 \"statement\" keywords.")
5843
5844 (defun vhdl-statement-p (&optional lim)
5845 "Return t if we are looking at a real \"statement\" keyword.
5846 Assumes that the caller will make sure that we are looking at
5847 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5848 in the middle of an identifier that just happens to contain a
5849 \"statement\" keyword."
5850 (cond
5851 ;; "for" ... "generate":
5852 ((and (looking-at "f")
5853 ;; Make sure it's the start of a parameter specification.
5854 (save-excursion
5855 (forward-sexp 2)
5856 (skip-chars-forward " \t\n")
5857 (looking-at "in\\b[^_]"))
5858 ;; Make sure it's not an "end for".
5859 (save-excursion
5860 (backward-sexp)
5861 (not (looking-at "end\\s-+\\w"))))
5862 t)
5863 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5864 ((and (looking-at "i")
5865 ;; Make sure it's not an "end if".
5866 (save-excursion
5867 (backward-sexp)
5868 (not (looking-at "end\\s-+\\w"))))
5869 t)
5870 ;; "while" ... "loop":
5871 ((looking-at "w")
5872 t)
5873 ))
5874
5875 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5876 "Regexp describing a case statement alternative key.")
5877
5878 (defun vhdl-case-alternative-p (&optional lim)
5879 "Return t if we are looking at a real case alternative.
5880 Assumes that the caller will make sure that we are looking at
5881 vhdl-case-alternative-re, and are not inside a literal, and that
5882 we are not in the middle of an identifier that just happens to
5883 contain a \"when\" keyword."
5884 (save-excursion
5885 (let (foundp)
5886 (while (and (not foundp)
5887 (re-search-backward ";\\|<=" lim 'move))
5888 (if (or (= (preceding-char) ?_)
5889 (vhdl-in-literal))
5890 (backward-char)
5891 (setq foundp t)))
5892 (or (eq (following-char) ?\;)
5893 (eq (point) lim)))
5894 ))
5895
5896 ;; Core syntactic movement functions:
5897
5898 (defconst vhdl-b-t-b-re
5899 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5900
5901 (defun vhdl-backward-to-block (&optional lim)
5902 "Move backward to the previous \"begin\" or \"end\" keyword."
5903 (let (foundp)
5904 (while (and (not foundp)
5905 (re-search-backward vhdl-b-t-b-re lim 'move))
5906 (if (or (= (preceding-char) ?_)
5907 (vhdl-in-literal))
5908 (backward-char)
5909 (cond
5910 ;; "begin" keyword:
5911 ((and (looking-at vhdl-begin-fwd-re)
5912 (/= (preceding-char) ?_)
5913 (vhdl-begin-p lim))
5914 (setq foundp 'begin))
5915 ;; "end" keyword:
5916 ((and (looking-at vhdl-end-fwd-re)
5917 (/= (preceding-char) ?_)
5918 (vhdl-end-p lim))
5919 (setq foundp 'end))
5920 ))
5921 )
5922 foundp
5923 ))
5924
5925 (defun vhdl-forward-sexp (&optional count lim)
5926 "Move forward across one balanced expression (sexp).
5927 With COUNT, do it that many times."
5928 (interactive "p")
5929 (let ((count (or count 1))
5930 (case-fold-search t)
5931 end-vec target)
5932 (save-excursion
5933 (while (> count 0)
5934 ;; skip whitespace
5935 (skip-chars-forward " \t\n")
5936 ;; Check for an unbalanced "end" keyword
5937 (if (and (looking-at vhdl-end-fwd-re)
5938 (/= (preceding-char) ?_)
5939 (not (vhdl-in-literal))
5940 (vhdl-end-p lim)
5941 (not (looking-at "else")))
5942 (error
5943 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5944 ;; If the current keyword is a "begin" keyword, then find the
5945 ;; corresponding "end" keyword.
5946 (if (setq end-vec (vhdl-corresponding-end lim))
5947 (let (
5948 ;; end-re is the statement keyword to search for
5949 (end-re
5950 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5951 ;; column is either the statement keyword target column
5952 ;; or nil
5953 (column (aref end-vec 1))
5954 (eol (vhdl-point 'eol))
5955 foundp literal placeholder)
5956 ;; Look for the statement keyword.
5957 (while (and (not foundp)
5958 (re-search-forward end-re nil t)
5959 (setq placeholder (match-end 1))
5960 (goto-char (match-beginning 0)))
5961 ;; If we are in a literal, or not in the right target
5962 ;; column and not on the same line as the begin, then
5963 ;; try again.
5964 (if (or (and column
5965 (/= (current-indentation) column)
5966 (> (point) eol))
5967 (= (preceding-char) ?_)
5968 (setq literal (vhdl-in-literal)))
5969 (if (eq literal 'comment)
5970 (end-of-line)
5971 (forward-char))
5972 ;; An "else" keyword corresponds to both the opening brace
5973 ;; of the following sexp and the closing brace of the
5974 ;; previous sexp.
5975 (if (not (looking-at "else"))
5976 (goto-char placeholder))
5977 (setq foundp t))
5978 )
5979 (if (not foundp)
5980 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5981 )
5982 ;; If the current keyword is not a "begin" keyword, then just
5983 ;; perform the normal forward-sexp.
5984 (forward-sexp)
5985 )
5986 (setq count (1- count))
5987 )
5988 (setq target (point)))
5989 (goto-char target)
5990 nil))
5991
5992 (defun vhdl-backward-sexp (&optional count lim)
5993 "Move backward across one balanced expression (sexp).
5994 With COUNT, do it that many times. LIM bounds any required backward
5995 searches."
5996 (interactive "p")
5997 (let ((count (or count 1))
5998 (case-fold-search t)
5999 begin-vec target)
6000 (save-excursion
6001 (while (> count 0)
6002 ;; Perform the normal backward-sexp, unless we are looking at
6003 ;; "else" - an "else" keyword corresponds to both the opening brace
6004 ;; of the following sexp and the closing brace of the previous sexp.
6005 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6006 (/= (preceding-char) ?_)
6007 (not (vhdl-in-literal)))
6008 nil
6009 (backward-sexp)
6010 (if (and (looking-at vhdl-begin-fwd-re)
6011 (/= (preceding-char) ?_)
6012 (not (vhdl-in-literal))
6013 (vhdl-begin-p lim))
6014 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6015 ;; If the current keyword is an "end" keyword, then find the
6016 ;; corresponding "begin" keyword.
6017 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6018 (/= (preceding-char) ?_))
6019 (let (
6020 ;; begin-re is the statement keyword to search for
6021 (begin-re
6022 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6023 ;; column is either the statement keyword target column
6024 ;; or nil
6025 (column (aref begin-vec 1))
6026 ;; internal-p controls where the statement keyword can
6027 ;; be found.
6028 (internal-p (aref begin-vec 3))
6029 (last-backward (point)) last-forward
6030 foundp literal keyword)
6031 ;; Look for the statement keyword.
6032 (while (and (not foundp)
6033 (re-search-backward begin-re lim t)
6034 (setq keyword
6035 (buffer-substring (match-beginning 1)
6036 (match-end 1))))
6037 ;; If we are in a literal or in the wrong column,
6038 ;; then try again.
6039 (if (or (and column
6040 (and (/= (current-indentation) column)
6041 ;; possibly accept current-column as
6042 ;; well as current-indentation.
6043 (or (not internal-p)
6044 (/= (current-column) column))))
6045 (= (preceding-char) ?_)
6046 (vhdl-in-literal))
6047 (backward-char)
6048 ;; If there is a supplementary keyword, then
6049 ;; search forward for it.
6050 (if (and (setq begin-re (aref begin-vec 2))
6051 (or (not (listp begin-re))
6052 ;; If begin-re is an alist, then find the
6053 ;; element corresponding to the actual
6054 ;; keyword that we found.
6055 (progn
6056 (setq begin-re
6057 (assoc keyword begin-re))
6058 (and begin-re
6059 (setq begin-re (cdr begin-re))))))
6060 (and
6061 (setq begin-re
6062 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6063 (save-excursion
6064 (setq last-forward (point))
6065 ;; Look for the supplementary keyword
6066 ;; (bounded by the backward search start
6067 ;; point).
6068 (while (and (not foundp)
6069 (re-search-forward begin-re
6070 last-backward t)
6071 (goto-char (match-beginning 1)))
6072 ;; If we are in a literal, then try again.
6073 (if (or (= (preceding-char) ?_)
6074 (setq literal
6075 (vhdl-in-literal)))
6076 (if (eq literal 'comment)
6077 (goto-char
6078 (min (vhdl-point 'eol) last-backward))
6079 (forward-char))
6080 ;; We have found the supplementary keyword.
6081 ;; Save the position of the keyword in foundp.
6082 (setq foundp (point)))
6083 )
6084 foundp)
6085 ;; If the supplementary keyword was found, then
6086 ;; move point to the supplementary keyword.
6087 (goto-char foundp))
6088 ;; If there was no supplementary keyword, then
6089 ;; point is already at the statement keyword.
6090 (setq foundp t)))
6091 ) ; end of the search for the statement keyword
6092 (if (not foundp)
6093 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6094 ))
6095 (setq count (1- count))
6096 )
6097 (setq target (point)))
6098 (goto-char target)
6099 nil))
6100
6101 (defun vhdl-backward-up-list (&optional count limit)
6102 "Move backward out of one level of blocks.
6103 With argument, do this that many times."
6104 (interactive "p")
6105 (let ((count (or count 1))
6106 target)
6107 (save-excursion
6108 (while (> count 0)
6109 (if (looking-at vhdl-defun-re)
6110 (error "ERROR: Unbalanced blocks"))
6111 (vhdl-backward-to-block limit)
6112 (setq count (1- count)))
6113 (setq target (point)))
6114 (goto-char target)))
6115
6116 (defun vhdl-end-of-defun (&optional count)
6117 "Move forward to the end of a VHDL defun."
6118 (interactive)
6119 (let ((case-fold-search t))
6120 (vhdl-beginning-of-defun)
6121 (if (not (looking-at "block\\|process\\|procedural"))
6122 (re-search-forward "\\bis\\b"))
6123 (vhdl-forward-sexp)))
6124
6125 (defun vhdl-mark-defun ()
6126 "Put mark at end of this \"defun\", point at beginning."
6127 (interactive)
6128 (let ((case-fold-search t))
6129 (push-mark)
6130 (vhdl-beginning-of-defun)
6131 (push-mark)
6132 (if (not (looking-at "block\\|process\\|procedural"))
6133 (re-search-forward "\\bis\\b"))
6134 (vhdl-forward-sexp)
6135 (exchange-point-and-mark)))
6136
6137 (defun vhdl-beginning-of-libunit ()
6138 "Move backward to the beginning of a VHDL library unit.
6139 Returns the location of the corresponding begin keyword, unless search
6140 stops due to beginning or end of buffer.
6141 Note that if point is between the \"libunit\" keyword and the
6142 corresponding \"begin\" keyword, then that libunit will not be
6143 recognized, and the search will continue backwards. If point is
6144 at the \"begin\" keyword, then the defun will be recognized. The
6145 returned point is at the first character of the \"libunit\" keyword."
6146 (let ((last-forward (point))
6147 (last-backward
6148 ;; Just in case we are actually sitting on the "begin"
6149 ;; keyword, allow for the keyword and an extra character,
6150 ;; as this will be used when looking forward for the
6151 ;; "begin" keyword.
6152 (save-excursion (forward-word 1) (1+ (point))))
6153 foundp literal placeholder)
6154 ;; Find the "libunit" keyword.
6155 (while (and (not foundp)
6156 (re-search-backward vhdl-libunit-re nil 'move))
6157 ;; If we are in a literal, or not at a real libunit, then try again.
6158 (if (or (= (preceding-char) ?_)
6159 (vhdl-in-literal)
6160 (not (vhdl-libunit-p)))
6161 (backward-char)
6162 ;; Find the corresponding "begin" keyword.
6163 (setq last-forward (point))
6164 (while (and (not foundp)
6165 (re-search-forward "\\bis\\b[^_]" last-backward t)
6166 (setq placeholder (match-beginning 0)))
6167 (if (or (= (preceding-char) ?_)
6168 (setq literal (vhdl-in-literal)))
6169 ;; It wasn't a real keyword, so keep searching.
6170 (if (eq literal 'comment)
6171 (goto-char
6172 (min (vhdl-point 'eol) last-backward))
6173 (forward-char))
6174 ;; We have found the begin keyword, loop will exit.
6175 (setq foundp placeholder)))
6176 ;; Go back to the libunit keyword
6177 (goto-char last-forward)))
6178 foundp))
6179
6180 (defun vhdl-beginning-of-defun (&optional count)
6181 "Move backward to the beginning of a VHDL defun.
6182 With argument, do it that many times.
6183 Returns the location of the corresponding begin keyword, unless search
6184 stops due to beginning or end of buffer."
6185 ;; Note that if point is between the "defun" keyword and the
6186 ;; corresponding "begin" keyword, then that defun will not be
6187 ;; recognized, and the search will continue backwards. If point is
6188 ;; at the "begin" keyword, then the defun will be recognized. The
6189 ;; returned point is at the first character of the "defun" keyword.
6190 (interactive "p")
6191 (let ((count (or count 1))
6192 (case-fold-search t)
6193 (last-forward (point))
6194 foundp)
6195 (while (> count 0)
6196 (setq foundp nil)
6197 (goto-char last-forward)
6198 (let ((last-backward
6199 ;; Just in case we are actually sitting on the "begin"
6200 ;; keyword, allow for the keyword and an extra character,
6201 ;; as this will be used when looking forward for the
6202 ;; "begin" keyword.
6203 (save-excursion (forward-word 1) (1+ (point))))
6204 begin-string literal)
6205 (while (and (not foundp)
6206 (re-search-backward vhdl-defun-re nil 'move))
6207 ;; If we are in a literal, then try again.
6208 (if (or (= (preceding-char) ?_)
6209 (vhdl-in-literal))
6210 (backward-char)
6211 (if (setq begin-string (vhdl-corresponding-defun))
6212 ;; This is a real defun keyword.
6213 ;; Find the corresponding "begin" keyword.
6214 ;; Look for the begin keyword.
6215 (progn
6216 ;; Save the search start point.
6217 (setq last-forward (point))
6218 (while (and (not foundp)
6219 (search-forward begin-string last-backward t))
6220 (if (or (= (preceding-char) ?_)
6221 (save-match-data
6222 (setq literal (vhdl-in-literal))))
6223 ;; It wasn't a real keyword, so keep searching.
6224 (if (eq literal 'comment)
6225 (goto-char
6226 (min (vhdl-point 'eol) last-backward))
6227 (forward-char))
6228 ;; We have found the begin keyword, loop will exit.
6229 (setq foundp (match-beginning 0)))
6230 )
6231 ;; Go back to the defun keyword
6232 (goto-char last-forward)) ; end search for begin keyword
6233 ))
6234 ) ; end of the search for the defun keyword
6235 )
6236 (setq count (1- count))
6237 )
6238 (vhdl-keep-region-active)
6239 foundp))
6240
6241 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6242 "Go to the beginning of the innermost VHDL statement.
6243 With prefix arg, go back N - 1 statements. If already at the
6244 beginning of a statement then go to the beginning of the preceding
6245 one. If within a string or comment, or next to a comment (only
6246 whitespace between), move by sentences instead of statements.
6247
6248 When called from a program, this function takes 3 optional args: the
6249 prefix arg, a buffer position limit which is the farthest back to
6250 search, and an argument indicating an interactive call."
6251 (interactive "p\np")
6252 (let ((count (or count 1))
6253 (case-fold-search t)
6254 (lim (or lim (point-min)))
6255 (here (point))
6256 state)
6257 (save-excursion
6258 (goto-char lim)
6259 (setq state (parse-partial-sexp (point) here nil nil)))
6260 (if (and interactive
6261 (or (nth 3 state)
6262 (nth 4 state)
6263 (looking-at (concat "[ \t]*" comment-start-skip))))
6264 (forward-sentence (- count))
6265 (while (> count 0)
6266 (vhdl-beginning-of-statement-1 lim)
6267 (setq count (1- count))))
6268 ;; its possible we've been left up-buf of lim
6269 (goto-char (max (point) lim))
6270 )
6271 (vhdl-keep-region-active))
6272
6273 (defconst vhdl-e-o-s-re
6274 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6275
6276 (defun vhdl-end-of-statement ()
6277 "Very simple implementation."
6278 (interactive)
6279 (re-search-forward vhdl-e-o-s-re))
6280
6281 (defconst vhdl-b-o-s-re
6282 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6283 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6284
6285 (defun vhdl-beginning-of-statement-1 (&optional lim)
6286 "Move to the start of the current statement, or the previous
6287 statement if already at the beginning of one."
6288 (let ((lim (or lim (point-min)))
6289 (here (point))
6290 (pos (point))
6291 donep)
6292 ;; go backwards one balanced expression, but be careful of
6293 ;; unbalanced paren being reached
6294 (if (not (vhdl-safe (progn (backward-sexp) t)))
6295 (progn
6296 (backward-up-list 1)
6297 (forward-char)
6298 (vhdl-forward-syntactic-ws here)
6299 (setq donep t)))
6300 (while (and (not donep)
6301 (not (bobp))
6302 ;; look backwards for a statement boundary
6303 (re-search-backward vhdl-b-o-s-re lim 'move))
6304 (if (or (= (preceding-char) ?_)
6305 (vhdl-in-literal))
6306 (backward-char)
6307 (cond
6308 ;; If we are looking at an open paren, then stop after it
6309 ((eq (following-char) ?\()
6310 (forward-char)
6311 (vhdl-forward-syntactic-ws here)
6312 (setq donep t))
6313 ;; If we are looking at a close paren, then skip it
6314 ((eq (following-char) ?\))
6315 (forward-char)
6316 (setq pos (point))
6317 (backward-sexp)
6318 (if (< (point) lim)
6319 (progn (goto-char pos)
6320 (vhdl-forward-syntactic-ws here)
6321 (setq donep t))))
6322 ;; If we are looking at a semicolon, then stop
6323 ((eq (following-char) ?\;)
6324 (progn
6325 (forward-char)
6326 (vhdl-forward-syntactic-ws here)
6327 (setq donep t)))
6328 ;; If we are looking at a "begin", then stop
6329 ((and (looking-at vhdl-begin-fwd-re)
6330 (/= (preceding-char) ?_)
6331 (vhdl-begin-p nil))
6332 ;; If it's a leader "begin", then find the
6333 ;; right place
6334 (if (looking-at vhdl-leader-re)
6335 (save-excursion
6336 ;; set a default stop point at the begin
6337 (setq pos (point))
6338 ;; is the start point inside the leader area ?
6339 (goto-char (vhdl-end-of-leader))
6340 (vhdl-forward-syntactic-ws here)
6341 (if (< (point) here)
6342 ;; start point was not inside leader area
6343 ;; set stop point at word after leader
6344 (setq pos (point))))
6345 (forward-word 1)
6346 (vhdl-forward-syntactic-ws here)
6347 (setq pos (point)))
6348 (goto-char pos)
6349 (setq donep t))
6350 ;; If we are looking at a "statement", then stop
6351 ((and (looking-at vhdl-statement-fwd-re)
6352 (/= (preceding-char) ?_)
6353 (vhdl-statement-p nil))
6354 (setq donep t))
6355 ;; If we are looking at a case alternative key, then stop
6356 ((and (looking-at vhdl-case-alternative-re)
6357 (vhdl-case-alternative-p lim))
6358 (save-excursion
6359 ;; set a default stop point at the when
6360 (setq pos (point))
6361 ;; is the start point inside the case alternative key ?
6362 (looking-at vhdl-case-alternative-re)
6363 (goto-char (match-end 0))
6364 (vhdl-forward-syntactic-ws here)
6365 (if (< (point) here)
6366 ;; start point was not inside the case alternative key
6367 ;; set stop point at word after case alternative keyleader
6368 (setq pos (point))))
6369 (goto-char pos)
6370 (setq donep t))
6371 ;; Bogus find, continue
6372 (t
6373 (backward-char)))))
6374 ))
6375
6376 ;; Defuns for calculating the current syntactic state:
6377
6378 (defun vhdl-get-library-unit (bod placeholder)
6379 "If there is an enclosing library unit at BOD, with its \"begin\"
6380 keyword at PLACEHOLDER, then return the library unit type."
6381 (let ((here (vhdl-point 'bol)))
6382 (if (save-excursion
6383 (goto-char placeholder)
6384 (vhdl-safe (vhdl-forward-sexp 1 bod))
6385 (<= here (point)))
6386 (save-excursion
6387 (goto-char bod)
6388 (cond
6389 ((looking-at "e") 'entity)
6390 ((looking-at "a") 'architecture)
6391 ((looking-at "c") 'configuration)
6392 ((looking-at "p")
6393 (save-excursion
6394 (goto-char bod)
6395 (forward-sexp)
6396 (vhdl-forward-syntactic-ws here)
6397 (if (looking-at "body\\b[^_]")
6398 'package-body 'package))))))
6399 ))
6400
6401 (defun vhdl-get-block-state (&optional lim)
6402 "Finds and records all the closest opens.
6403 LIM is the furthest back we need to search (it should be the
6404 previous libunit keyword)."
6405 (let ((here (point))
6406 (lim (or lim (point-min)))
6407 keyword sexp-start sexp-mid sexp-end
6408 preceding-sexp containing-sexp
6409 containing-begin containing-mid containing-paren)
6410 (save-excursion
6411 ;; Find the containing-paren, and use that as the limit
6412 (if (setq containing-paren
6413 (save-restriction
6414 (narrow-to-region lim (point))
6415 (vhdl-safe (scan-lists (point) -1 1))))
6416 (setq lim containing-paren))
6417 ;; Look backwards for "begin" and "end" keywords.
6418 (while (and (> (point) lim)
6419 (not containing-sexp))
6420 (setq keyword (vhdl-backward-to-block lim))
6421 (cond
6422 ((eq keyword 'begin)
6423 ;; Found a "begin" keyword
6424 (setq sexp-start (point))
6425 (setq sexp-mid (vhdl-corresponding-mid lim))
6426 (setq sexp-end (vhdl-safe
6427 (save-excursion
6428 (vhdl-forward-sexp 1 lim) (point))))
6429 (if (and sexp-end (<= sexp-end here))
6430 ;; we want to record this sexp, but we only want to
6431 ;; record the last-most of any of them before here
6432 (or preceding-sexp
6433 (setq preceding-sexp sexp-start))
6434 ;; we're contained in this sexp so put sexp-start on
6435 ;; front of list
6436 (setq containing-sexp sexp-start)
6437 (setq containing-mid sexp-mid)
6438 (setq containing-begin t)))
6439 ((eq keyword 'end)
6440 ;; Found an "end" keyword
6441 (forward-sexp)
6442 (setq sexp-end (point))
6443 (setq sexp-mid nil)
6444 (setq sexp-start
6445 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6446 (progn (backward-sexp) (point))))
6447 ;; we want to record this sexp, but we only want to
6448 ;; record the last-most of any of them before here
6449 (or preceding-sexp
6450 (setq preceding-sexp sexp-start)))
6451 )))
6452 ;; Check if the containing-paren should be the containing-sexp
6453 (if (and containing-paren
6454 (or (null containing-sexp)
6455 (< containing-sexp containing-paren)))
6456 (setq containing-sexp containing-paren
6457 preceding-sexp nil
6458 containing-begin nil
6459 containing-mid nil))
6460 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6461 ))
6462
6463
6464 (defconst vhdl-s-c-a-re
6465 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6466
6467 (defun vhdl-skip-case-alternative (&optional lim)
6468 "Skip forward over case/when bodies, with optional maximal
6469 limit. If no next case alternative is found, nil is returned and
6470 point is not moved."
6471 (let ((lim (or lim (point-max)))
6472 (here (point))
6473 donep foundp)
6474 (while (and (< (point) lim)
6475 (not donep))
6476 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6477 (save-match-data
6478 (not (vhdl-in-literal)))
6479 (/= (match-beginning 0) here))
6480 (progn
6481 (goto-char (match-beginning 0))
6482 (cond
6483 ((and (looking-at "case")
6484 (re-search-forward "\\bis[^_]" lim t))
6485 (backward-sexp)
6486 (vhdl-forward-sexp))
6487 (t
6488 (setq donep t
6489 foundp t))))))
6490 (if (not foundp)
6491 (goto-char here))
6492 foundp))
6493
6494 (defun vhdl-backward-skip-label (&optional lim)
6495 "Skip backward over a label, with optional maximal
6496 limit. If label is not found, nil is returned and point
6497 is not moved."
6498 (let ((lim (or lim (point-min)))
6499 placeholder)
6500 (if (save-excursion
6501 (vhdl-backward-syntactic-ws lim)
6502 (and (eq (preceding-char) ?:)
6503 (progn
6504 (backward-sexp)
6505 (setq placeholder (point))
6506 (looking-at vhdl-label-key))))
6507 (goto-char placeholder))
6508 ))
6509
6510 (defun vhdl-forward-skip-label (&optional lim)
6511 "Skip forward over a label, with optional maximal
6512 limit. If label is not found, nil is returned and point
6513 is not moved."
6514 (let ((lim (or lim (point-max))))
6515 (if (looking-at vhdl-label-key)
6516 (progn
6517 (goto-char (match-end 0))
6518 (vhdl-forward-syntactic-ws lim)))
6519 ))
6520
6521 (defun vhdl-get-syntactic-context ()
6522 "Guess the syntactic description of the current line of VHDL code."
6523 (save-excursion
6524 (save-restriction
6525 (beginning-of-line)
6526 (let* ((indent-point (point))
6527 (case-fold-search t)
6528 vec literal containing-sexp preceding-sexp
6529 containing-begin containing-mid containing-leader
6530 char-before-ip char-after-ip begin-after-ip end-after-ip
6531 placeholder lim library-unit
6532 )
6533
6534 ;; Reset the syntactic context
6535 (setq vhdl-syntactic-context nil)
6536
6537 (save-excursion
6538 ;; Move to the start of the previous library unit, and
6539 ;; record the position of the "begin" keyword.
6540 (setq placeholder (vhdl-beginning-of-libunit))
6541 ;; The position of the "libunit" keyword gives us a gross
6542 ;; limit point.
6543 (setq lim (point))
6544 )
6545
6546 ;; If there is a previous library unit, and we are enclosed by
6547 ;; it, then set the syntax accordingly.
6548 (and placeholder
6549 (setq library-unit (vhdl-get-library-unit lim placeholder))
6550 (vhdl-add-syntax library-unit lim))
6551
6552 ;; Find the surrounding state.
6553 (if (setq vec (vhdl-get-block-state lim))
6554 (progn
6555 (setq containing-sexp (aref vec 0))
6556 (setq preceding-sexp (aref vec 1))
6557 (setq containing-begin (aref vec 2))
6558 (setq containing-mid (aref vec 3))
6559 ))
6560
6561 ;; set the limit on the farthest back we need to search
6562 (setq lim (if containing-sexp
6563 (save-excursion
6564 (goto-char containing-sexp)
6565 ;; set containing-leader if required
6566 (if (looking-at vhdl-leader-re)
6567 (setq containing-leader (vhdl-end-of-leader)))
6568 (vhdl-point 'bol))
6569 (point-min)))
6570
6571 ;; cache char before and after indent point, and move point to
6572 ;; the most likely position to perform the majority of tests
6573 (goto-char indent-point)
6574 (skip-chars-forward " \t")
6575 (setq literal (vhdl-in-literal))
6576 (setq char-after-ip (following-char))
6577 (setq begin-after-ip (and
6578 (not literal)
6579 (looking-at vhdl-begin-fwd-re)
6580 (vhdl-begin-p)))
6581 (setq end-after-ip (and
6582 (not literal)
6583 (looking-at vhdl-end-fwd-re)
6584 (vhdl-end-p)))
6585 (vhdl-backward-syntactic-ws lim)
6586 (setq char-before-ip (preceding-char))
6587 (goto-char indent-point)
6588 (skip-chars-forward " \t")
6589
6590 ;; now figure out syntactic qualities of the current line
6591 (cond
6592 ;; CASE 1: in a string or comment.
6593 ((memq literal '(string comment))
6594 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6595 ;; CASE 2: Line is at top level.
6596 ((null containing-sexp)
6597 ;; Find the point to which indentation will be relative
6598 (save-excursion
6599 (if (null preceding-sexp)
6600 ;; CASE 2X.1
6601 ;; no preceding-sexp -> use the preceding statement
6602 (vhdl-beginning-of-statement-1 lim)
6603 ;; CASE 2X.2
6604 ;; if there is a preceding-sexp then indent relative to it
6605 (goto-char preceding-sexp)
6606 ;; if not at boi, then the block-opening keyword is
6607 ;; probably following a label, so we need a different
6608 ;; relpos
6609 (if (/= (point) (vhdl-point 'boi))
6610 ;; CASE 2X.3
6611 (vhdl-beginning-of-statement-1 lim)))
6612 ;; v-b-o-s could have left us at point-min
6613 (and (bobp)
6614 ;; CASE 2X.4
6615 (vhdl-forward-syntactic-ws indent-point))
6616 (setq placeholder (point)))
6617 (cond
6618 ;; CASE 2A : we are looking at a block-open
6619 (begin-after-ip
6620 (vhdl-add-syntax 'block-open placeholder))
6621 ;; CASE 2B: we are looking at a block-close
6622 (end-after-ip
6623 (vhdl-add-syntax 'block-close placeholder))
6624 ;; CASE 2C: we are looking at a top-level statement
6625 ((progn
6626 (vhdl-backward-syntactic-ws lim)
6627 (or (bobp)
6628 (= (preceding-char) ?\;)))
6629 (vhdl-add-syntax 'statement placeholder))
6630 ;; CASE 2D: we are looking at a top-level statement-cont
6631 (t
6632 (vhdl-beginning-of-statement-1 lim)
6633 ;; v-b-o-s could have left us at point-min
6634 (and (bobp)
6635 ;; CASE 2D.1
6636 (vhdl-forward-syntactic-ws indent-point))
6637 (vhdl-add-syntax 'statement-cont (point)))
6638 )) ; end CASE 2
6639 ;; CASE 3: line is inside parentheses. Most likely we are
6640 ;; either in a subprogram argument (interface) list, or a
6641 ;; continued expression containing parentheses.
6642 ((null containing-begin)
6643 (vhdl-backward-syntactic-ws containing-sexp)
6644 (cond
6645 ;; CASE 3A: we are looking at the arglist closing paren
6646 ((eq char-after-ip ?\))
6647 (goto-char containing-sexp)
6648 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6649 ;; CASE 3B: we are looking at the first argument in an empty
6650 ;; argument list.
6651 ((eq char-before-ip ?\()
6652 (goto-char containing-sexp)
6653 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6654 ;; CASE 3C: we are looking at an arglist continuation line,
6655 ;; but the preceding argument is on the same line as the
6656 ;; opening paren. This case includes multi-line
6657 ;; expression paren groupings.
6658 ((and (save-excursion
6659 (goto-char (1+ containing-sexp))
6660 (skip-chars-forward " \t")
6661 (not (eolp))
6662 (not (looking-at "--")))
6663 (save-excursion
6664 (vhdl-beginning-of-statement-1 containing-sexp)
6665 (skip-chars-backward " \t(")
6666 (<= (point) containing-sexp)))
6667 (goto-char containing-sexp)
6668 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6669 ;; CASE 3D: we are looking at just a normal arglist
6670 ;; continuation line
6671 (t (vhdl-beginning-of-statement-1 containing-sexp)
6672 (vhdl-forward-syntactic-ws indent-point)
6673 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6674 ))
6675 ;; CASE 4: A block mid open
6676 ((and begin-after-ip
6677 (looking-at containing-mid))
6678 (goto-char containing-sexp)
6679 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6680 (if (looking-at vhdl-trailer-re)
6681 ;; CASE 4.1
6682 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6683 (vhdl-backward-skip-label (vhdl-point 'boi))
6684 (vhdl-add-syntax 'block-open (point)))
6685 ;; CASE 5: block close brace
6686 (end-after-ip
6687 (goto-char containing-sexp)
6688 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6689 (if (looking-at vhdl-trailer-re)
6690 ;; CASE 5.1
6691 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6692 (vhdl-backward-skip-label (vhdl-point 'boi))
6693 (vhdl-add-syntax 'block-close (point)))
6694 ;; CASE 6: A continued statement
6695 ((and (/= char-before-ip ?\;)
6696 ;; check it's not a trailer begin keyword, or a begin
6697 ;; keyword immediately following a label.
6698 (not (and begin-after-ip
6699 (or (looking-at vhdl-trailer-re)
6700 (save-excursion
6701 (vhdl-backward-skip-label containing-sexp)))))
6702 ;; check it's not a statement keyword
6703 (not (and (looking-at vhdl-statement-fwd-re)
6704 (vhdl-statement-p)))
6705 ;; see if the b-o-s is before the indent point
6706 (> indent-point
6707 (save-excursion
6708 (vhdl-beginning-of-statement-1 containing-sexp)
6709 ;; If we ended up after a leader, then this will
6710 ;; move us forward to the start of the first
6711 ;; statement. Note that a containing sexp here is
6712 ;; always a keyword, not a paren, so this will
6713 ;; have no effect if we hit the containing-sexp.
6714 (vhdl-forward-syntactic-ws indent-point)
6715 (setq placeholder (point))))
6716 ;; check it's not a block-intro
6717 (/= placeholder containing-sexp)
6718 ;; check it's not a case block-intro
6719 (save-excursion
6720 (goto-char placeholder)
6721 (or (not (looking-at vhdl-case-alternative-re))
6722 (> (match-end 0) indent-point))))
6723 ;; Make placeholder skip a label, but only if it puts us
6724 ;; before the indent point at the start of a line.
6725 (let ((new placeholder))
6726 (if (and (> indent-point
6727 (save-excursion
6728 (goto-char placeholder)
6729 (vhdl-forward-skip-label indent-point)
6730 (setq new (point))))
6731 (save-excursion
6732 (goto-char new)
6733 (eq new (progn (back-to-indentation) (point)))))
6734 (setq placeholder new)))
6735 (vhdl-add-syntax 'statement-cont placeholder)
6736 (if begin-after-ip
6737 (vhdl-add-syntax 'block-open)))
6738 ;; Statement. But what kind?
6739 ;; CASE 7: A case alternative key
6740 ((and (looking-at vhdl-case-alternative-re)
6741 (vhdl-case-alternative-p containing-sexp))
6742 ;; for a case alternative key, we set relpos to the first
6743 ;; non-whitespace char on the line containing the "case"
6744 ;; keyword.
6745 (goto-char containing-sexp)
6746 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6747 (if (looking-at vhdl-trailer-re)
6748 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6749 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6750 ;; CASE 8: statement catchall
6751 (t
6752 ;; we know its a statement, but we need to find out if it is
6753 ;; the first statement in a block
6754 (if containing-leader
6755 (goto-char containing-leader)
6756 (goto-char containing-sexp)
6757 ;; Note that a containing sexp here is always a keyword,
6758 ;; not a paren, so skip over the keyword.
6759 (forward-sexp))
6760 ;; move to the start of the first statement
6761 (vhdl-forward-syntactic-ws indent-point)
6762 (setq placeholder (point))
6763 ;; we want to ignore case alternatives keys when skipping forward
6764 (let (incase-p)
6765 (while (looking-at vhdl-case-alternative-re)
6766 (setq incase-p (point))
6767 ;; we also want to skip over the body of the
6768 ;; case/when statement if that doesn't put us at
6769 ;; after the indent-point
6770 (while (vhdl-skip-case-alternative indent-point))
6771 ;; set up the match end
6772 (looking-at vhdl-case-alternative-re)
6773 (goto-char (match-end 0))
6774 ;; move to the start of the first case alternative statement
6775 (vhdl-forward-syntactic-ws indent-point)
6776 (setq placeholder (point)))
6777 (cond
6778 ;; CASE 8A: we saw a case/when statement so we must be
6779 ;; in a switch statement. find out if we are at the
6780 ;; statement just after a case alternative key
6781 ((and incase-p
6782 (= (point) indent-point))
6783 ;; relpos is the "when" keyword
6784 (vhdl-add-syntax 'statement-case-intro incase-p))
6785 ;; CASE 8B: any old statement
6786 ((< (point) indent-point)
6787 ;; relpos is the first statement of the block
6788 (vhdl-add-syntax 'statement placeholder)
6789 (if begin-after-ip
6790 (vhdl-add-syntax 'block-open)))
6791 ;; CASE 8C: first statement in a block
6792 (t
6793 (goto-char containing-sexp)
6794 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6795 (if (looking-at vhdl-trailer-re)
6796 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6797 (vhdl-backward-skip-label (vhdl-point 'boi))
6798 (vhdl-add-syntax 'statement-block-intro (point))
6799 (if begin-after-ip
6800 (vhdl-add-syntax 'block-open)))
6801 )))
6802 )
6803
6804 ;; now we need to look at any modifiers
6805 (goto-char indent-point)
6806 (skip-chars-forward " \t")
6807 (if (looking-at "--")
6808 (vhdl-add-syntax 'comment))
6809 (if (eq literal 'pound)
6810 (vhdl-add-syntax 'cpp-macro))
6811 ;; return the syntax
6812 vhdl-syntactic-context))))
6813
6814 ;; Standard indentation line-ups:
6815
6816 (defun vhdl-lineup-arglist (langelem)
6817 "Lineup the current arglist line with the arglist appearing just
6818 after the containing paren which starts the arglist."
6819 (save-excursion
6820 (let* ((containing-sexp
6821 (save-excursion
6822 ;; arglist-cont-nonempty gives relpos ==
6823 ;; to boi of containing-sexp paren. This
6824 ;; is good when offset is +, but bad
6825 ;; when it is vhdl-lineup-arglist, so we
6826 ;; have to special case a kludge here.
6827 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6828 (progn
6829 (beginning-of-line)
6830 (backward-up-list 1)
6831 (skip-chars-forward " \t" (vhdl-point 'eol)))
6832 (goto-char (cdr langelem)))
6833 (point)))
6834 (cs-curcol (save-excursion
6835 (goto-char (cdr langelem))
6836 (current-column))))
6837 (if (save-excursion
6838 (beginning-of-line)
6839 (looking-at "[ \t]*)"))
6840 (progn (goto-char (match-end 0))
6841 (backward-sexp)
6842 (forward-char)
6843 (vhdl-forward-syntactic-ws)
6844 (- (current-column) cs-curcol))
6845 (goto-char containing-sexp)
6846 (or (eolp)
6847 (let ((eol (vhdl-point 'eol))
6848 (here (progn
6849 (forward-char)
6850 (skip-chars-forward " \t")
6851 (point))))
6852 (vhdl-forward-syntactic-ws)
6853 (if (< (point) eol)
6854 (goto-char here))))
6855 (- (current-column) cs-curcol)
6856 ))))
6857
6858 (defun vhdl-lineup-arglist-intro (langelem)
6859 "Lineup an arglist-intro line to just after the open paren."
6860 (save-excursion
6861 (let ((cs-curcol (save-excursion
6862 (goto-char (cdr langelem))
6863 (current-column)))
6864 (ce-curcol (save-excursion
6865 (beginning-of-line)
6866 (backward-up-list 1)
6867 (skip-chars-forward " \t" (vhdl-point 'eol))
6868 (current-column))))
6869 (- ce-curcol cs-curcol -1))))
6870
6871 (defun vhdl-lineup-comment (langelem)
6872 "Support old behavior for comment indentation. We look at
6873 vhdl-comment-only-line-offset to decide how to indent comment
6874 only-lines."
6875 (save-excursion
6876 (back-to-indentation)
6877 ;; at or to the right of comment-column
6878 (if (>= (current-column) comment-column)
6879 (vhdl-comment-indent)
6880 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6881 (if (not (bolp))
6882 (or (car-safe vhdl-comment-only-line-offset)
6883 vhdl-comment-only-line-offset)
6884 (or (cdr-safe vhdl-comment-only-line-offset)
6885 (car-safe vhdl-comment-only-line-offset)
6886 -1000 ;jam it against the left side
6887 )))))
6888
6889 (defun vhdl-lineup-statement-cont (langelem)
6890 "Line up statement-cont after the assignment operator."
6891 (save-excursion
6892 (let* ((relpos (cdr langelem))
6893 (assignp (save-excursion
6894 (goto-char (vhdl-point 'boi))
6895 (and (re-search-forward "\\(<\\|:\\)="
6896 (vhdl-point 'eol) t)
6897 (- (point) (vhdl-point 'boi)))))
6898 (curcol (progn
6899 (goto-char relpos)
6900 (current-column)))
6901 foundp)
6902 (while (and (not foundp)
6903 (< (point) (vhdl-point 'eol)))
6904 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6905 (if (vhdl-in-literal)
6906 (forward-char)
6907 (if (= (preceding-char) ?\()
6908 ;; skip over any parenthesized expressions
6909 (goto-char (min (vhdl-point 'eol)
6910 (scan-lists (point) 1 1)))
6911 ;; found an assignment operator (not at eol)
6912 (setq foundp (not (looking-at "\\s-*$"))))))
6913 (if (not foundp)
6914 ;; there's no assignment operator on the line
6915 vhdl-basic-offset
6916 ;; calculate indentation column after assign and ws, unless
6917 ;; our line contains an assignment operator
6918 (if (not assignp)
6919 (progn
6920 (forward-char)
6921 (skip-chars-forward " \t")
6922 (setq assignp 0)))
6923 (- (current-column) assignp curcol))
6924 )))
6925
6926 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6927 ;; Progress reporting
6928
6929 (defvar vhdl-progress-info nil
6930 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6931
6932 (defun vhdl-update-progress-info (string pos)
6933 "Update progress information."
6934 (when (and vhdl-progress-info (not noninteractive)
6935 (< vhdl-progress-interval
6936 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6937 (let ((delta (- (aref vhdl-progress-info 1)
6938 (aref vhdl-progress-info 0))))
6939 (if (= 0 delta)
6940 (message (concat string "... (100%s)") "%")
6941 (message (concat string "... (%2d%s)")
6942 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6943 delta) "%")))
6944 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6945
6946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6947 ;; Indentation commands
6948
6949 (defun vhdl-electric-tab (&optional prefix-arg)
6950 "If preceeding character is part of a word or a paren then hippie-expand,
6951 else if right of non whitespace on line then insert tab,
6952 else if last command was a tab or return then dedent one step or if a comment
6953 toggle between normal indent and inline comment indent,
6954 else indent `correctly'."
6955 (interactive "*P")
6956 (vhdl-prepare-search-2
6957 (cond
6958 ;; indent region if region is active
6959 ((and (not (featurep 'xemacs)) (use-region-p))
6960 (vhdl-indent-region (region-beginning) (region-end) nil))
6961 ;; expand word
6962 ((= (char-syntax (preceding-char)) ?w)
6963 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6964 (case-replace nil)
6965 (hippie-expand-only-buffers
6966 (or (and (boundp 'hippie-expand-only-buffers)
6967 hippie-expand-only-buffers)
6968 '(vhdl-mode))))
6969 (vhdl-expand-abbrev prefix-arg)))
6970 ;; expand parenthesis
6971 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6972 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6973 (case-replace nil))
6974 (vhdl-expand-paren prefix-arg)))
6975 ;; insert tab
6976 ((> (current-column) (current-indentation))
6977 (insert-tab))
6978 ;; toggle comment indent
6979 ((and (looking-at "--")
6980 (or (eq last-command 'vhdl-electric-tab)
6981 (eq last-command 'vhdl-electric-return)))
6982 (cond ((= (current-indentation) 0) ; no indent
6983 (indent-to 1)
6984 (indent-according-to-mode))
6985 ((< (current-indentation) comment-column) ; normal indent
6986 (indent-to comment-column)
6987 (indent-according-to-mode))
6988 (t ; inline comment indent
6989 (delete-region (line-beginning-position) (point)))))
6990 ;; dedent
6991 ((and (>= (current-indentation) vhdl-basic-offset)
6992 (or (eq last-command 'vhdl-electric-tab)
6993 (eq last-command 'vhdl-electric-return)))
6994 (backward-delete-char-untabify vhdl-basic-offset nil))
6995 ;; indent line
6996 (t (indent-according-to-mode)))
6997 (setq this-command 'vhdl-electric-tab)))
6998
6999 (defun vhdl-electric-return ()
7000 "newline-and-indent or indent-new-comment-line if in comment and preceding
7001 character is a space."
7002 (interactive)
7003 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7004 (indent-new-comment-line)
7005 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7006 (vhdl-fix-case-word -1))
7007 (newline-and-indent)))
7008
7009 (defun vhdl-indent-line ()
7010 "Indent the current line as VHDL code. Returns the amount of
7011 indentation change."
7012 (interactive)
7013 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7014 (pos (- (point-max) (point)))
7015 (indent
7016 (if syntax
7017 ;; indent syntax-based
7018 (if (and (eq (caar syntax) 'comment)
7019 (>= (vhdl-get-offset (car syntax)) comment-column))
7020 ;; special case: comments at or right of comment-column
7021 (vhdl-get-offset (car syntax))
7022 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7023 ;; indent like previous nonblank line
7024 (save-excursion (beginning-of-line)
7025 (re-search-backward "^[^\n]" nil t)
7026 (current-indentation))))
7027 (shift-amt (- indent (current-indentation))))
7028 (and vhdl-echo-syntactic-information-p
7029 (message "syntax: %s, indent= %d" syntax indent))
7030 (unless (zerop shift-amt)
7031 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7032 (beginning-of-line)
7033 (indent-to indent))
7034 (if (< (point) (vhdl-point 'boi))
7035 (back-to-indentation)
7036 ;; If initial point was within line's indentation, position after
7037 ;; the indentation. Else stay at same point in text.
7038 (when (> (- (point-max) pos) (point))
7039 (goto-char (- (point-max) pos))))
7040 (run-hooks 'vhdl-special-indent-hook)
7041 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7042 shift-amt))
7043
7044 (defun vhdl-indent-region (beg end column)
7045 "Indent region as VHDL code.
7046 Adds progress reporting to `indent-region'."
7047 (interactive "r\nP")
7048 (when vhdl-progress-interval
7049 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7050 (count-lines (point-min) end) 0)))
7051 (indent-region beg end column)
7052 (when vhdl-progress-interval (message "Indenting...done"))
7053 (setq vhdl-progress-info nil))
7054
7055 (defun vhdl-indent-buffer ()
7056 "Indent whole buffer as VHDL code.
7057 Calls `indent-region' for whole buffer and adds progress reporting."
7058 (interactive)
7059 (vhdl-indent-region (point-min) (point-max) nil))
7060
7061 (defun vhdl-indent-group ()
7062 "Indent group of lines between empty lines."
7063 (interactive)
7064 (let ((beg (save-excursion
7065 (if (re-search-backward vhdl-align-group-separate nil t)
7066 (point-marker)
7067 (point-min-marker))))
7068 (end (save-excursion
7069 (if (re-search-forward vhdl-align-group-separate nil t)
7070 (point-marker)
7071 (point-max-marker)))))
7072 (vhdl-indent-region beg end nil)))
7073
7074 (defun vhdl-indent-sexp (&optional endpos)
7075 "Indent each line of the list starting just after point.
7076 If optional arg ENDPOS is given, indent each line, stopping when
7077 ENDPOS is encountered."
7078 (interactive)
7079 (save-excursion
7080 (let ((beg (point))
7081 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7082 (indent-region beg end nil))))
7083
7084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7085 ;; Miscellaneous commands
7086
7087 (defun vhdl-show-syntactic-information ()
7088 "Show syntactic information for current line."
7089 (interactive)
7090 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7091 (vhdl-keep-region-active))
7092
7093 ;; Verification and regression functions:
7094
7095 (defun vhdl-regress-line (&optional arg)
7096 "Check syntactic information for current line."
7097 (interactive "P")
7098 (let ((expected (save-excursion
7099 (end-of-line)
7100 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7101 (forward-char 4)
7102 (read (current-buffer)))))
7103 (actual (vhdl-get-syntactic-context))
7104 (expurgated))
7105 ;; remove the library unit symbols
7106 (mapc
7107 (function
7108 (lambda (elt)
7109 (if (memq (car elt) '(entity configuration package
7110 package-body architecture))
7111 nil
7112 (setq expurgated (append expurgated (list elt))))))
7113 actual)
7114 (if (and (not arg) expected (listp expected))
7115 (if (not (equal expected expurgated))
7116 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7117 (save-excursion
7118 (beginning-of-line)
7119 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7120 (end-of-line)
7121 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7122 (delete-region (point) (line-end-position)))
7123 (insert " -- ")
7124 (insert (format "%s" expurgated))))))
7125 (vhdl-keep-region-active))
7126
7127
7128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7129 ;;; Alignment, whitespace fixup, beautifying
7130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7131
7132 (defconst vhdl-align-alist
7133 '(
7134 ;; after some keywords
7135 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7136 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7137 ;; before ':'
7138 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7139 ;; after direction specifications
7140 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7141 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7142 ;; before "==", ":=", "=>", and "<="
7143 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7144 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7145 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7146 ;; before some keywords
7147 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7148 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7149 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7150 ;; before "=>" since "when/else ... =>" can occur
7151 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7152 )
7153 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7154 It is searched in order. If REGEXP is found anywhere in the first
7155 line of a region to be aligned, ALIGN-PATTERN will be used for that
7156 region. ALIGN-PATTERN must include the whitespace to be expanded or
7157 contracted. It may also provide regexps for the text surrounding the
7158 whitespace. SUBEXP specifies which sub-expression of
7159 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7160
7161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7162 ;; Align code
7163
7164 (defvar vhdl-align-try-all-clauses t
7165 "If REGEXP is not found on the first line of the region that clause
7166 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7167
7168 (defun vhdl-do-group (function &optional spacing)
7169 "Apply FUNCTION on group of lines between empty lines."
7170 (let
7171 ;; search for group beginning
7172 ((beg (save-excursion
7173 (if (re-search-backward vhdl-align-group-separate nil t)
7174 (progn (beginning-of-line 2) (back-to-indentation) (point))
7175 (point-min))))
7176 ;; search for group end
7177 (end (save-excursion
7178 (if (re-search-forward vhdl-align-group-separate nil t)
7179 (progn (beginning-of-line) (point))
7180 (point-max)))))
7181 ;; run FUNCTION
7182 (funcall function beg end spacing)))
7183
7184 (defun vhdl-do-list (function &optional spacing)
7185 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7186 parentheses."
7187 (let (beg end)
7188 (save-excursion
7189 ;; search for beginning of balanced group of parentheses
7190 (setq beg (vhdl-re-search-backward "[()]" nil t))
7191 (while (looking-at ")")
7192 (forward-char) (backward-sexp)
7193 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7194 ;; search for end of balanced group of parentheses
7195 (when beg
7196 (forward-list)
7197 (setq end (point))
7198 (goto-char (1+ beg))
7199 (skip-chars-forward " \t\n")
7200 (setq beg (point))))
7201 ;; run FUNCTION
7202 (if beg
7203 (funcall function beg end spacing)
7204 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7205
7206 (defun vhdl-do-same-indent (function &optional spacing)
7207 "Apply FUNCTION to block of lines with same indent."
7208 (let ((indent (current-indentation))
7209 beg end)
7210 ;; search for first line with same indent
7211 (save-excursion
7212 (while (and (not (bobp))
7213 (or (looking-at "^\\s-*\\(--.*\\)?$")
7214 (= (current-indentation) indent)))
7215 (unless (looking-at "^\\s-*$")
7216 (back-to-indentation) (setq beg (point)))
7217 (beginning-of-line -0)))
7218 ;; search for last line with same indent
7219 (save-excursion
7220 (while (and (not (eobp))
7221 (or (looking-at "^\\s-*\\(--.*\\)?$")
7222 (= (current-indentation) indent)))
7223 (if (looking-at "^\\s-*$")
7224 (beginning-of-line 2)
7225 (beginning-of-line 2)
7226 (setq end (point)))))
7227 ;; run FUNCTION
7228 (funcall function beg end spacing)))
7229
7230 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7231 "Attempt to align a range of lines based on the content of the
7232 lines. The definition of `alignment-list' determines the matching
7233 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7234 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7235 indentation is done before aligning."
7236 (interactive "r\np")
7237 (setq alignment-list (or alignment-list vhdl-align-alist))
7238 (setq spacing (or spacing 1))
7239 (save-excursion
7240 (let (bol indent)
7241 (goto-char end)
7242 (setq end (point-marker))
7243 (goto-char begin)
7244 (setq bol (setq begin (progn (beginning-of-line) (point))))
7245 ; (untabify bol end)
7246 (when indent
7247 (indent-region bol end nil))))
7248 (let ((copy (copy-alist alignment-list)))
7249 (vhdl-prepare-search-2
7250 (while copy
7251 (save-excursion
7252 (goto-char begin)
7253 (let (element
7254 (eol (point-at-eol)))
7255 (setq element (nth 0 copy))
7256 (when (and (or (and (listp (car element))
7257 (memq major-mode (car element)))
7258 (eq major-mode (car element)))
7259 (or vhdl-align-try-all-clauses
7260 (re-search-forward (car (cdr element)) eol t)))
7261 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7262 (car (cdr (cdr (cdr element)))) spacing))
7263 (setq copy (cdr copy))))))))
7264
7265 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7266 "Align a range of lines from BEGIN to END. The regular expression
7267 MATCH must match exactly one field: the whitespace to be
7268 contracted/expanded. The alignment column will equal the
7269 rightmost column of the widest whitespace block. SPACING is
7270 the amount of extra spaces to add to the calculated maximum required.
7271 SPACING defaults to 1 so that at least one space is inserted after
7272 the token in MATCH."
7273 (setq spacing (or spacing 1))
7274 (setq substr (or substr 1))
7275 (save-excursion
7276 (let (distance (max 0) (lines 0) bol eol width)
7277 ;; Determine the greatest whitespace distance to the alignment
7278 ;; character
7279 (goto-char begin)
7280 (setq eol (point-at-eol)
7281 bol (setq begin (progn (beginning-of-line) (point))))
7282 (while (< bol end)
7283 (save-excursion
7284 (when (and (re-search-forward match eol t)
7285 (not (vhdl-in-literal)))
7286 (setq distance (- (match-beginning substr) bol))
7287 (when (> distance max)
7288 (setq max distance))))
7289 (forward-line)
7290 (setq bol (point)
7291 eol (point-at-eol))
7292 (setq lines (1+ lines)))
7293 ;; Now insert enough maxs to push each assignment operator to
7294 ;; the same column. We need to use 'lines' as a counter, since
7295 ;; the location of the mark may change
7296 (goto-char (setq bol begin))
7297 (setq eol (point-at-eol))
7298 (while (> lines 0)
7299 (when (and (re-search-forward match eol t)
7300 (not (vhdl-in-literal)))
7301 (setq width (- (match-end substr) (match-beginning substr)))
7302 (setq distance (- (match-beginning substr) bol))
7303 (goto-char (match-beginning substr))
7304 (delete-char width)
7305 (insert-char ? (+ (- max distance) spacing)))
7306 (beginning-of-line)
7307 (forward-line)
7308 (setq bol (point)
7309 eol (point-at-eol))
7310 (setq lines (1- lines))))))
7311
7312 (defun vhdl-align-region-groups (beg end &optional spacing
7313 no-message no-comments)
7314 "Align region, treat groups of lines separately."
7315 (interactive "r\nP")
7316 (save-excursion
7317 (let (orig pos)
7318 (goto-char beg)
7319 (beginning-of-line)
7320 (setq orig (point-marker))
7321 (setq beg (point))
7322 (goto-char end)
7323 (setq end (point-marker))
7324 (untabify beg end)
7325 (unless no-message
7326 (when vhdl-progress-interval
7327 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7328 (count-lines (point-min) end) 0))))
7329 (vhdl-fixup-whitespace-region beg end t)
7330 (goto-char beg)
7331 (if (not vhdl-align-groups)
7332 ;; align entire region
7333 (progn (vhdl-align-region-1 beg end spacing)
7334 (unless no-comments
7335 (vhdl-align-inline-comment-region-1 beg end)))
7336 ;; align groups
7337 (while (and (< beg end)
7338 (re-search-forward vhdl-align-group-separate end t))
7339 (setq pos (point-marker))
7340 (vhdl-align-region-1 beg pos spacing)
7341 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7342 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7343 (setq beg (1+ pos))
7344 (goto-char beg))
7345 ;; align last group
7346 (when (< beg end)
7347 (vhdl-align-region-1 beg end spacing)
7348 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7349 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7350 (when vhdl-indent-tabs-mode
7351 (tabify orig end))
7352 (unless no-message
7353 (when vhdl-progress-interval (message "Aligning...done"))
7354 (setq vhdl-progress-info nil)))))
7355
7356 (defun vhdl-align-region (beg end &optional spacing)
7357 "Align region, treat blocks with same indent and argument lists separately."
7358 (interactive "r\nP")
7359 (if (not vhdl-align-same-indent)
7360 ;; align entire region
7361 (vhdl-align-region-groups beg end spacing)
7362 ;; align blocks with same indent and argument lists
7363 (save-excursion
7364 (let ((cur-beg beg)
7365 indent cur-end)
7366 (when vhdl-progress-interval
7367 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7368 (count-lines (point-min) end) 0)))
7369 (goto-char end)
7370 (setq end (point-marker))
7371 (goto-char cur-beg)
7372 (while (< (point) end)
7373 ;; is argument list opening?
7374 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7375 (point) (vhdl-point 'eol)))))
7376 ;; determine region for argument list
7377 (progn (goto-char cur-beg)
7378 (forward-sexp)
7379 (setq cur-end (point))
7380 (beginning-of-line 2))
7381 ;; determine region with same indent
7382 (setq indent (current-indentation))
7383 (setq cur-beg (point))
7384 (setq cur-end (vhdl-point 'bonl))
7385 (beginning-of-line 2)
7386 (while (and (< (point) end)
7387 (or (looking-at "^\\s-*\\(--.*\\)?$")
7388 (= (current-indentation) indent))
7389 (<= (save-excursion
7390 (nth 0 (parse-partial-sexp
7391 (point) (vhdl-point 'eol)))) 0))
7392 (unless (looking-at "^\\s-*$")
7393 (setq cur-end (vhdl-point 'bonl)))
7394 (beginning-of-line 2)))
7395 ;; align region
7396 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7397 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7398 (when vhdl-progress-interval (message "Aligning...done"))
7399 (setq vhdl-progress-info nil)))))
7400
7401 (defun vhdl-align-group (&optional spacing)
7402 "Align group of lines between empty lines."
7403 (interactive)
7404 (vhdl-do-group 'vhdl-align-region spacing))
7405
7406 (defun vhdl-align-list (&optional spacing)
7407 "Align the lines of a list surrounded by a balanced group of parentheses."
7408 (interactive)
7409 (vhdl-do-list 'vhdl-align-region-groups spacing))
7410
7411 (defun vhdl-align-same-indent (&optional spacing)
7412 "Align block of lines with same indent."
7413 (interactive)
7414 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7415
7416 (defun vhdl-align-declarations (&optional spacing)
7417 "Align the lines within the declarative part of a design unit."
7418 (interactive)
7419 (let (beg end)
7420 (vhdl-prepare-search-2
7421 (save-excursion
7422 ;; search for declarative part
7423 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7424 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7425 (setq beg (point))
7426 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7427 (setq end (point)))))
7428 (if beg
7429 (vhdl-align-region-groups beg end spacing)
7430 (error "ERROR: Not within the declarative part of a design unit"))))
7431
7432 (defun vhdl-align-buffer ()
7433 "Align buffer."
7434 (interactive)
7435 (vhdl-align-region (point-min) (point-max)))
7436
7437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7438 ;; Align inline comments
7439
7440 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7441 "Align inline comments in region."
7442 (save-excursion
7443 (let ((start-max comment-column)
7444 (length-max 0)
7445 comment-list start-list tmp-list start length
7446 cur-start prev-start no-code)
7447 (setq spacing (or spacing 2))
7448 (vhdl-prepare-search-2
7449 (goto-char beg)
7450 ;; search for comment start positions and lengths
7451 (while (< (point) end)
7452 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7453 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7454 (not (save-excursion (goto-char (match-beginning 2))
7455 (vhdl-in-literal))))
7456 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7457 (setq length (- (match-end 2) (match-beginning 2)))
7458 (setq start-max (max start start-max))
7459 (setq length-max (max length length-max))
7460 (setq comment-list (cons (cons start length) comment-list)))
7461 (beginning-of-line 2))
7462 (setq comment-list
7463 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7464 ;; reduce start positions
7465 (setq start-list (list (caar comment-list)))
7466 (setq comment-list (cdr comment-list))
7467 (while comment-list
7468 (unless (or (= (caar comment-list) (car start-list))
7469 (<= (+ (car start-list) (cdar comment-list))
7470 end-comment-column))
7471 (setq start-list (cons (caar comment-list) start-list)))
7472 (setq comment-list (cdr comment-list)))
7473 ;; align lines as nicely as possible
7474 (goto-char beg)
7475 (while (< (point) end)
7476 (setq cur-start nil)
7477 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7478 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7479 (not (save-excursion
7480 (goto-char (match-beginning 3))
7481 (vhdl-in-literal))))
7482 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7483 (>= (- (match-end 2) (match-beginning 2))
7484 comment-column))))
7485 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7486 (setq length (- (match-end 3) (match-beginning 3)))
7487 (setq no-code (= (match-beginning 1) (match-end 1)))
7488 ;; insert minimum whitespace
7489 (goto-char (match-end 2))
7490 (delete-region (match-beginning 2) (match-end 2))
7491 (insert-char ?\ spacing)
7492 (setq tmp-list start-list)
7493 ;; insert additional whitespace to align
7494 (setq cur-start
7495 (cond
7496 ;; align comment-only line to inline comment of previous line
7497 ((and no-code prev-start
7498 (<= length (- end-comment-column prev-start)))
7499 prev-start)
7500 ;; align all comments at `start-max' if this is possible
7501 ((<= (+ start-max length-max) end-comment-column)
7502 start-max)
7503 ;; align at `comment-column' if possible
7504 ((and (<= start comment-column)
7505 (<= length (- end-comment-column comment-column)))
7506 comment-column)
7507 ;; align at left-most possible start position otherwise
7508 (t
7509 (while (and tmp-list (< (car tmp-list) start))
7510 (setq tmp-list (cdr tmp-list)))
7511 (car tmp-list))))
7512 (indent-to cur-start))
7513 (setq prev-start cur-start)
7514 (beginning-of-line 2))))))
7515
7516 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7517 "Align inline comments within a region. Groups of code lines separated by
7518 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7519 (interactive "r\nP")
7520 (save-excursion
7521 (let (orig pos)
7522 (goto-char beg)
7523 (beginning-of-line)
7524 (setq orig (point-marker))
7525 (setq beg (point))
7526 (goto-char end)
7527 (setq end (point-marker))
7528 (untabify beg end)
7529 (unless no-message (message "Aligning inline comments..."))
7530 (goto-char beg)
7531 (if (not vhdl-align-groups)
7532 ;; align entire region
7533 (vhdl-align-inline-comment-region-1 beg end spacing)
7534 ;; align groups
7535 (while (and (< beg end)
7536 (re-search-forward vhdl-align-group-separate end t))
7537 (setq pos (point-marker))
7538 (vhdl-align-inline-comment-region-1 beg pos spacing)
7539 (setq beg (1+ pos))
7540 (goto-char beg))
7541 ;; align last group
7542 (when (< beg end)
7543 (vhdl-align-inline-comment-region-1 beg end spacing)))
7544 (when vhdl-indent-tabs-mode
7545 (tabify orig end))
7546 (unless no-message (message "Aligning inline comments...done")))))
7547
7548 (defun vhdl-align-inline-comment-group (&optional spacing)
7549 "Align inline comments within a group of lines between empty lines."
7550 (interactive)
7551 (save-excursion
7552 (let ((start (point))
7553 beg end)
7554 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7555 (point-marker) (point-max)))
7556 (goto-char start)
7557 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7558 (point) (point-min)))
7559 (untabify beg end)
7560 (message "Aligning inline comments...")
7561 (vhdl-align-inline-comment-region-1 beg end)
7562 (when vhdl-indent-tabs-mode
7563 (tabify beg end))
7564 (message "Aligning inline comments...done"))))
7565
7566 (defun vhdl-align-inline-comment-buffer ()
7567 "Align inline comments within buffer. Groups of code lines separated by
7568 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7569 (interactive)
7570 (vhdl-align-inline-comment-region (point-min) (point-max)))
7571
7572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7573 ;; Fixup whitespace
7574
7575 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7576 "Fixup whitespace in region. Surround operator symbols by one space,
7577 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7578 end of line, do nothing in comments and strings."
7579 (interactive "r")
7580 (unless no-message (message "Fixing up whitespace..."))
7581 (save-excursion
7582 (goto-char end)
7583 (setq end (point-marker))
7584 ;; have no space before and one space after `,' and ';'
7585 (goto-char beg)
7586 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7587 (if (match-string 1)
7588 (goto-char (match-end 1))
7589 (replace-match "\\3 " nil nil nil 3)))
7590 ;; have no space after `('
7591 (goto-char beg)
7592 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7593 (if (match-string 1)
7594 (goto-char (match-end 1))
7595 (replace-match "\\2")))
7596 ;; have no space before `)'
7597 (goto-char beg)
7598 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7599 (if (match-string 1)
7600 (goto-char (match-end 1))
7601 (replace-match "\\2")))
7602 ;; surround operator symbols by one space
7603 (goto-char beg)
7604 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7605 (if (match-string 1)
7606 (goto-char (match-end 1))
7607 (replace-match "\\3 \\4 \\5")
7608 (goto-char (match-end 2))))
7609 ;; eliminate multiple spaces and spaces at end of line
7610 (goto-char beg)
7611 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7612 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7613 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7614 (progn (replace-match "" nil nil) t))
7615 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7616 (progn (replace-match ";" nil nil) t))
7617 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7618 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7619 (progn (replace-match " " nil nil) t))
7620 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7621 (progn (replace-match " " nil nil) t))
7622 ; (re-search-forward "[^ \t-]+" end t))))
7623 (re-search-forward "[^ \t\"-]+" end t))))
7624 (unless no-message (message "Fixing up whitespace...done")))
7625
7626 (defun vhdl-fixup-whitespace-buffer ()
7627 "Fixup whitespace in buffer. Surround operator symbols by one space,
7628 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7629 end of line, do nothing in comments."
7630 (interactive)
7631 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7632
7633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7634 ;; Beautify
7635
7636 (defun vhdl-beautify-region (beg end)
7637 "Beautify region by applying indentation, whitespace fixup, alignment, and
7638 case fixing to a region. Calls functions `vhdl-indent-buffer',
7639 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7640 `vhdl-fix-case-buffer'."
7641 (interactive "r")
7642 (setq end (save-excursion (goto-char end) (point-marker)))
7643 (vhdl-indent-region beg end nil)
7644 (let ((vhdl-align-groups t))
7645 (vhdl-align-region beg end))
7646 (vhdl-fix-case-region beg end))
7647
7648 (defun vhdl-beautify-buffer ()
7649 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7650 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7651 buffer."
7652 (interactive)
7653 (vhdl-beautify-region (point-min) (point-max))
7654 (when noninteractive (save-buffer)))
7655
7656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7657 ;; Code filling
7658
7659 (defun vhdl-fill-region (beg end &optional arg)
7660 "Fill lines for a region of code."
7661 (interactive "r\np")
7662 (save-excursion
7663 (goto-char beg)
7664 (let ((margin (if arg (current-indentation) (current-column))))
7665 (goto-char end)
7666 (setq end (point-marker))
7667 ;; remove inline comments, newlines and whitespace
7668 (vhdl-comment-kill-region beg end)
7669 (vhdl-comment-kill-inline-region beg end)
7670 (subst-char-in-region beg (1- end) ?\n ?\ )
7671 (vhdl-fixup-whitespace-region beg end)
7672 ;; wrap and end-comment-column
7673 (goto-char beg)
7674 (while (re-search-forward "\\s-" end t)
7675 (when(> (current-column) vhdl-end-comment-column)
7676 (backward-char)
7677 (when (re-search-backward "\\s-" beg t)
7678 (replace-match "\n")
7679 (indent-to margin)))))))
7680
7681 (defun vhdl-fill-group ()
7682 "Fill group of lines between empty lines."
7683 (interactive)
7684 (vhdl-do-group 'vhdl-fill-region))
7685
7686 (defun vhdl-fill-list ()
7687 "Fill the lines of a list surrounded by a balanced group of parentheses."
7688 (interactive)
7689 (vhdl-do-list 'vhdl-fill-region))
7690
7691 (defun vhdl-fill-same-indent ()
7692 "Fill the lines of block of lines with same indent."
7693 (interactive)
7694 (vhdl-do-same-indent 'vhdl-fill-region))
7695
7696
7697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7698 ;;; Code updating/fixing
7699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7700
7701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7702 ;; Sensitivity list update
7703
7704 ;; Strategy:
7705 ;; - no sensitivity list is generated for processes with wait statements
7706 ;; - otherwise, do the following:
7707 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7708 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7709 ;; manually entered global signals)
7710 ;; 3. signals from 1. and 2. form the list of visible signals
7711 ;; 4. search for if/elsif conditions containing an event (sequential code)
7712 ;; 5. scan for strings that are within syntactical regions where signals are
7713 ;; read but not within sequential code, and that correspond to visible
7714 ;; signals
7715 ;; 6. replace sensitivity list by list of signals from 5.
7716
7717 (defun vhdl-update-sensitivity-list-process ()
7718 "Update sensitivity list of current process."
7719 (interactive)
7720 (save-excursion
7721 (vhdl-prepare-search-2
7722 (end-of-line)
7723 ;; look whether in process
7724 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7725 (equal (upcase (match-string 2)) "PROCESS")
7726 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7727 (error "ERROR: Not within a process")
7728 (message "Updating sensitivity list...")
7729 (vhdl-update-sensitivity-list)
7730 (message "Updating sensitivity list...done")))))
7731
7732 (defun vhdl-update-sensitivity-list-buffer ()
7733 "Update sensitivity list of all processes in current buffer."
7734 (interactive)
7735 (save-excursion
7736 (vhdl-prepare-search-2
7737 (goto-char (point-min))
7738 (message "Updating sensitivity lists...")
7739 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7740 (goto-char (match-beginning 0))
7741 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7742 (message "Updating sensitivity lists...done"))))
7743
7744 (defun vhdl-update-sensitivity-list ()
7745 "Update sensitivity list."
7746 (let ((proc-beg (point))
7747 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7748 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7749 seq-region-list)
7750 (cond
7751 ;; search for wait statement (no sensitivity list allowed)
7752 ((progn (goto-char proc-mid)
7753 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7754 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7755 ;; combinational process (update sensitivity list)
7756 (t
7757 (let
7758 ;; scan for visible signals
7759 ((visible-list (vhdl-get-visible-signals))
7760 ;; define syntactic regions where signals are read
7761 (scan-regions-list
7762 '(;; right-hand side of signal/variable assignment
7763 ;; (special case: "<=" is relational operator in a condition)
7764 ((re-search-forward "[<:]=" proc-end t)
7765 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7766 ;; if condition
7767 ((re-search-forward "^\\s-*if\\>" proc-end t)
7768 (re-search-forward "\\<then\\>" proc-end t))
7769 ;; elsif condition
7770 ((re-search-forward "\\<elsif\\>" proc-end t)
7771 (re-search-forward "\\<then\\>" proc-end t))
7772 ;; while loop condition
7773 ((re-search-forward "^\\s-*while\\>" proc-end t)
7774 (re-search-forward "\\<loop\\>" proc-end t))
7775 ;; exit/next condition
7776 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7777 (re-search-forward ";" proc-end t))
7778 ;; assert condition
7779 ((re-search-forward "\\<assert\\>" proc-end t)
7780 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7781 ;; case expression
7782 ((re-search-forward "^\\s-*case\\>" proc-end t)
7783 (re-search-forward "\\<is\\>" proc-end t))
7784 ;; parameter list of procedure call
7785 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7786 (1- (point)))
7787 (progn (backward-char) (forward-sexp)
7788 (while (looking-at "(") (forward-sexp)) (point)))))
7789 name read-list sens-list signal-list
7790 sens-beg sens-end beg end margin)
7791 ;; scan for signals in old sensitivity list
7792 (goto-char proc-beg)
7793 (re-search-forward "\\<process\\>" proc-mid t)
7794 (if (not (looking-at "[ \t\n]*("))
7795 (setq sens-beg (point))
7796 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7797 (goto-char (match-end 1))
7798 (forward-sexp)
7799 (setq sens-end (1- (point)))
7800 (goto-char sens-beg)
7801 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7802 (setq sens-list
7803 (cons (downcase (match-string 0)) sens-list))
7804 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7805 (setq signal-list (append visible-list sens-list))
7806 ;; search for sequential parts
7807 (goto-char proc-mid)
7808 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7809 (setq end (re-search-forward "\\<then\\>" proc-end t))
7810 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7811 (goto-char end)
7812 (backward-word 1)
7813 (vhdl-forward-sexp)
7814 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7815 (beginning-of-line)))
7816 ;; scan for signals read in process
7817 (while scan-regions-list
7818 (goto-char proc-mid)
7819 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7820 (setq end (eval (nth 1 (car scan-regions-list)))))
7821 (goto-char beg)
7822 (unless (or (vhdl-in-literal)
7823 (and seq-region-list
7824 (let ((tmp-list seq-region-list))
7825 (while (and tmp-list
7826 (< (point) (caar tmp-list)))
7827 (setq tmp-list (cdr tmp-list)))
7828 (and tmp-list (< (point) (cdar tmp-list))))))
7829 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7830 (setq name (match-string 1))
7831 (when (and (not (match-string 4)) ; not when formal parameter
7832 (not (and (match-string 3) ; not event attribute
7833 (not (member (downcase (match-string 3))
7834 '("event" "last_event" "transaction")))))
7835 (member (downcase name) signal-list))
7836 (unless (member-ignore-case name read-list)
7837 (setq read-list (cons name read-list))))
7838 (goto-char (match-end 1)))))
7839 (setq scan-regions-list (cdr scan-regions-list)))
7840 ;; update sensitivity list
7841 (goto-char sens-beg)
7842 (if sens-end
7843 (delete-region sens-beg sens-end)
7844 (when read-list
7845 (insert " ()") (backward-char)))
7846 (setq read-list (sort read-list 'string<))
7847 (when read-list
7848 (setq margin (current-column))
7849 (insert (car read-list))
7850 (setq read-list (cdr read-list))
7851 (while read-list
7852 (insert ",")
7853 (if (<= (+ (current-column) (length (car read-list)) 2)
7854 end-comment-column)
7855 (insert " ")
7856 (insert "\n") (indent-to margin))
7857 (insert (car read-list))
7858 (setq read-list (cdr read-list)))))))))
7859
7860 (defun vhdl-get-visible-signals ()
7861 "Get all signals visible in the current block."
7862 (let (beg end signal-list entity-name file-name)
7863 (vhdl-prepare-search-2
7864 ;; get entity name
7865 (save-excursion
7866 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7867 (not (equal "END" (upcase (match-string 1))))
7868 (setq entity-name (match-string 2)))
7869 (error "ERROR: Not within an architecture")))
7870 ;; search for signals declared in entity port clause
7871 (save-excursion
7872 (goto-char (point-min))
7873 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7874 (setq file-name
7875 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7876 "." (file-name-extension (buffer-file-name)))))
7877 (vhdl-visit-file
7878 file-name t
7879 (vhdl-prepare-search-2
7880 (goto-char (point-min))
7881 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7882 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7883 (when (setq beg (re-search-forward
7884 "^\\s-*port[ \t\n]*("
7885 (save-excursion
7886 (re-search-forward "^end\\>" nil t)) t))
7887 (setq end (save-excursion
7888 (backward-char) (forward-sexp) (point)))
7889 (vhdl-forward-syntactic-ws)
7890 (while (< (point) end)
7891 (when (looking-at "signal[ \t\n]+")
7892 (goto-char (match-end 0)))
7893 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7894 (setq signal-list
7895 (cons (downcase (match-string 1)) signal-list))
7896 (goto-char (match-end 0))
7897 (vhdl-forward-syntactic-ws))
7898 (re-search-forward ";" end 1)
7899 (vhdl-forward-syntactic-ws)))))))
7900 ;; search for signals declared in architecture declarative part
7901 (save-excursion
7902 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7903 (not (equal "END" (upcase (match-string 1))))
7904 (setq end (re-search-forward "^begin\\>" nil t))))
7905 (error "ERROR: No architecture declarative part found")
7906 ;; scan for all declared signal and alias names
7907 (goto-char beg)
7908 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7909 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7910 (if (match-string 2)
7911 ;; scan signal name
7912 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7913 (setq signal-list
7914 (cons (downcase (match-string 1)) signal-list))
7915 (goto-char (match-end 0)))
7916 ;; scan alias name, check is alias of (declared) signal
7917 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7918 (member (downcase (match-string 2)) signal-list))
7919 (setq signal-list
7920 (cons (downcase (match-string 1)) signal-list))
7921 (goto-char (match-end 0))))
7922 (setq beg (point))))))
7923 ;; search for signals declared in surrounding block declarative parts
7924 (save-excursion
7925 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7926 (match-string 2))
7927 (goto-char (match-end 2))
7928 (vhdl-backward-sexp)
7929 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7930 beg)
7931 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7932 ;; scan for all declared signal names
7933 (goto-char beg)
7934 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7935 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7936 (if (match-string 2)
7937 ;; scan signal name
7938 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7939 (setq signal-list
7940 (cons (downcase (match-string 1)) signal-list))
7941 (goto-char (match-end 0)))
7942 ;; scan alias name, check is alias of (declared) signal
7943 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7944 (member (downcase (match-string 2)) signal-list))
7945 (setq signal-list
7946 (cons (downcase (match-string 1)) signal-list))
7947 (goto-char (match-end 0))))))
7948 (goto-char beg)))
7949 signal-list)))
7950
7951 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7952 ;; Generic/port clause fixing
7953
7954 (defun vhdl-fix-clause ()
7955 "Fix closing parenthesis within generic/port clause."
7956 (interactive)
7957 (save-excursion
7958 (vhdl-prepare-search-2
7959 (let ((pos (point))
7960 beg end)
7961 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7962 (error "ERROR: Not within a generic/port clause")
7963 ;; search for end of clause
7964 (goto-char (match-end 0))
7965 (setq beg (1- (point)))
7966 (vhdl-forward-syntactic-ws)
7967 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7968 (goto-char (1- (match-end 0)))
7969 (setq end (point-marker))
7970 (forward-char)
7971 (vhdl-forward-syntactic-ws))
7972 (goto-char end)
7973 (when (> pos (point-at-eol))
7974 (error "ERROR: Not within a generic/port clause"))
7975 ;; delete closing parenthesis on separate line (not supported style)
7976 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7977 (vhdl-line-kill)
7978 (vhdl-backward-syntactic-ws)
7979 (setq end (point-marker))
7980 (insert ";"))
7981 ;; delete superfluous parentheses
7982 (while (progn (goto-char beg)
7983 (condition-case () (forward-sexp)
7984 (error (goto-char (point-max))))
7985 (< (point) end))
7986 (delete-char -1))
7987 ;; add closing parenthesis
7988 (when (> (point) end)
7989 (goto-char end)
7990 (insert ")")))))))
7991
7992 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7993 ;; Miscellaneous
7994
7995 (defun vhdl-remove-trailing-spaces ()
7996 "Remove trailing spaces in the whole buffer."
7997 (interactive)
7998 (save-match-data
7999 (save-excursion
8000 (goto-char (point-min))
8001 (while (re-search-forward "[ \t]+$" (point-max) t)
8002 (unless (vhdl-in-literal)
8003 (replace-match "" nil nil))))))
8004
8005
8006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8007 ;;; Electrification
8008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8009
8010 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8011 "Syntax of prompt inserted by template generators.")
8012
8013 (defvar vhdl-template-invoked-by-hook nil
8014 "Indicates whether a template has been invoked by a hook or by key or menu.
8015 Used for undoing after template abortion.")
8016
8017 ;; correct different behavior of function `unread-command-events' in XEmacs
8018 (defun vhdl-character-to-event (arg))
8019 (defalias 'vhdl-character-to-event
8020 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8021
8022 (defun vhdl-work-library ()
8023 "Return the working library name of the current project or \"work\" if no
8024 project is defined."
8025 (vhdl-resolve-env-variable
8026 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8027
8028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8029 ;; Enabling/disabling
8030
8031 (define-minor-mode vhdl-electric-mode
8032 "Toggle VHDL electric mode.
8033 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8034 :global t)
8035
8036 (define-minor-mode vhdl-stutter-mode
8037 "Toggle VHDL stuttering mode.
8038 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8039 :global t)
8040
8041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8042 ;; Stuttering
8043
8044 (defun vhdl-electric-dash (count)
8045 "-- starts a comment, --- draws a horizontal line,
8046 ---- starts a display comment."
8047 (interactive "p")
8048 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8049 (cond
8050 ((and abbrev-start-location (= abbrev-start-location (point)))
8051 (setq abbrev-start-location nil)
8052 (goto-char last-abbrev-location)
8053 (beginning-of-line nil)
8054 (vhdl-comment-display))
8055 ((/= (preceding-char) ?-) ; standard dash (minus)
8056 (self-insert-command count))
8057 (t (self-insert-command count)
8058 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8059 (let ((next-input (read-char)))
8060 (if (= next-input ?-) ; triple dash
8061 (progn
8062 (vhdl-comment-display-line)
8063 (message
8064 "Enter '-' for display comment, else continue coding")
8065 (let ((next-input (read-char)))
8066 (if (= next-input ?-) ; four dashes
8067 (vhdl-comment-display t)
8068 (setq unread-command-events ; pushback the char
8069 (list (vhdl-character-to-event next-input))))))
8070 (setq unread-command-events ; pushback the char
8071 (list (vhdl-character-to-event next-input)))
8072 (vhdl-comment-insert)))))
8073 (self-insert-command count)))
8074
8075 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8076 (interactive "p")
8077 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8078 (if (= (preceding-char) ?\()
8079 (progn (delete-char -1) (insert-char ?\[ 1))
8080 (insert-char ?\( 1))
8081 (self-insert-command count)))
8082
8083 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8084 (interactive "p")
8085 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8086 (progn
8087 (if (= (preceding-char) ?\))
8088 (progn (delete-char -1) (insert-char ?\] 1))
8089 (insert-char ?\) 1))
8090 (blink-matching-open))
8091 (self-insert-command count)))
8092
8093 (defun vhdl-electric-quote (count) "'' --> \""
8094 (interactive "p")
8095 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8096 (if (= (preceding-char) last-input-event)
8097 (progn (delete-char -1) (insert-char ?\" 1))
8098 (insert-char ?\' 1))
8099 (self-insert-command count)))
8100
8101 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8102 (interactive "p")
8103 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8104 (cond ((= (preceding-char) last-input-event)
8105 (progn (delete-char -1)
8106 (unless (eq (preceding-char) ? ) (insert " "))
8107 (insert ": ")
8108 (setq this-command 'vhdl-electric-colon)))
8109 ((and
8110 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8111 (progn (delete-char -1) (insert "= ")))
8112 (t (insert-char ?\; 1)))
8113 (self-insert-command count)))
8114
8115 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8116 (interactive "p")
8117 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8118 (cond ((= (preceding-char) last-input-event)
8119 (progn (delete-char -1)
8120 (unless (eq (preceding-char) ? ) (insert " "))
8121 (insert "<= ")))
8122 (t (insert-char ?\, 1)))
8123 (self-insert-command count)))
8124
8125 (defun vhdl-electric-period (count) "'..' --> ' => '"
8126 (interactive "p")
8127 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8128 (cond ((= (preceding-char) last-input-event)
8129 (progn (delete-char -1)
8130 (unless (eq (preceding-char) ? ) (insert " "))
8131 (insert "=> ")))
8132 (t (insert-char ?\. 1)))
8133 (self-insert-command count)))
8134
8135 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8136 (interactive "p")
8137 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8138 (cond ((= (preceding-char) last-input-event)
8139 (progn (delete-char -1)
8140 (unless (eq (preceding-char) ? ) (insert " "))
8141 (insert "== ")))
8142 (t (insert-char ?\= 1)))
8143 (self-insert-command count)))
8144
8145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8146 ;; VHDL templates
8147
8148 (defun vhdl-template-paired-parens ()
8149 "Insert a pair of round parentheses, placing point between them."
8150 (interactive)
8151 (insert "()")
8152 (backward-char))
8153
8154 (defun vhdl-template-alias ()
8155 "Insert alias declaration."
8156 (interactive)
8157 (let ((start (point)))
8158 (vhdl-insert-keyword "ALIAS ")
8159 (when (vhdl-template-field "name" nil t start (point))
8160 (insert " : ")
8161 (unless (vhdl-template-field
8162 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8163 nil t)
8164 (delete-char -3))
8165 (vhdl-insert-keyword " IS ")
8166 (vhdl-template-field "name" ";")
8167 (vhdl-comment-insert-inline))))
8168
8169 (defun vhdl-template-architecture ()
8170 "Insert architecture."
8171 (interactive)
8172 (let ((margin (current-indentation))
8173 (start (point))
8174 arch-name)
8175 (vhdl-insert-keyword "ARCHITECTURE ")
8176 (when (setq arch-name
8177 (vhdl-template-field "name" nil t start (point)))
8178 (vhdl-insert-keyword " OF ")
8179 (if (save-excursion
8180 (vhdl-prepare-search-1
8181 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8182 (insert (match-string 1))
8183 (vhdl-template-field "entity name"))
8184 (vhdl-insert-keyword " IS\n")
8185 (vhdl-template-begin-end
8186 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8187 (memq vhdl-insert-empty-lines '(unit all))))))
8188
8189 (defun vhdl-template-array (kind &optional secondary)
8190 "Insert array type definition."
8191 (interactive)
8192 (let ((start (point)))
8193 (vhdl-insert-keyword "ARRAY (")
8194 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8195 secondary)
8196 (vhdl-insert-keyword ") OF ")
8197 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8198 (vhdl-insert-keyword ";"))))
8199
8200 (defun vhdl-template-assert ()
8201 "Insert an assertion statement."
8202 (interactive)
8203 (let ((start (point)))
8204 (vhdl-insert-keyword "ASSERT ")
8205 (when vhdl-conditions-in-parenthesis (insert "("))
8206 (when (vhdl-template-field "condition (negated)" nil t start (point))
8207 (when vhdl-conditions-in-parenthesis (insert ")"))
8208 (setq start (point))
8209 (vhdl-insert-keyword " REPORT ")
8210 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8211 (delete-region start (point)))
8212 (setq start (point))
8213 (vhdl-insert-keyword " SEVERITY ")
8214 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8215 (delete-region start (point)))
8216 (insert ";"))))
8217
8218 (defun vhdl-template-attribute ()
8219 "Insert an attribute declaration or specification."
8220 (interactive)
8221 (if (eq (vhdl-decision-query
8222 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8223 (vhdl-template-attribute-spec)
8224 (vhdl-template-attribute-decl)))
8225
8226 (defun vhdl-template-attribute-decl ()
8227 "Insert an attribute declaration."
8228 (interactive)
8229 (let ((start (point)))
8230 (vhdl-insert-keyword "ATTRIBUTE ")
8231 (when (vhdl-template-field "name" " : " t start (point))
8232 (vhdl-template-field "type" ";")
8233 (vhdl-comment-insert-inline))))
8234
8235 (defun vhdl-template-attribute-spec ()
8236 "Insert an attribute specification."
8237 (interactive)
8238 (let ((start (point)))
8239 (vhdl-insert-keyword "ATTRIBUTE ")
8240 (when (vhdl-template-field "name" nil t start (point))
8241 (vhdl-insert-keyword " OF ")
8242 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8243 (vhdl-template-field "entity class")
8244 (vhdl-insert-keyword " IS ")
8245 (vhdl-template-field "expression" ";"))))
8246
8247 (defun vhdl-template-block ()
8248 "Insert a block."
8249 (interactive)
8250 (let ((margin (current-indentation))
8251 (start (point))
8252 label)
8253 (vhdl-insert-keyword ": BLOCK ")
8254 (goto-char start)
8255 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8256 (forward-word 1)
8257 (forward-char 1)
8258 (insert "(")
8259 (if (vhdl-template-field "[guard expression]" nil t)
8260 (insert ")")
8261 (delete-char -2))
8262 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8263 (insert "\n")
8264 (vhdl-template-begin-end "BLOCK" label margin)
8265 (vhdl-comment-block))))
8266
8267 (defun vhdl-template-block-configuration ()
8268 "Insert a block configuration statement."
8269 (interactive)
8270 (let ((margin (current-indentation))
8271 (start (point)))
8272 (vhdl-insert-keyword "FOR ")
8273 (when (vhdl-template-field "block name" nil t start (point))
8274 (vhdl-insert-keyword "\n\n")
8275 (indent-to margin)
8276 (vhdl-insert-keyword "END FOR;")
8277 (end-of-line 0)
8278 (indent-to (+ margin vhdl-basic-offset)))))
8279
8280 (defun vhdl-template-break ()
8281 "Insert a break statement."
8282 (interactive)
8283 (let (position)
8284 (vhdl-insert-keyword "BREAK")
8285 (setq position (point))
8286 (insert " ")
8287 (while (or
8288 (progn (vhdl-insert-keyword "FOR ")
8289 (if (vhdl-template-field "[quantity name]" " USE " t)
8290 (progn (vhdl-template-field "quantity name" " => ") t)
8291 (delete-region (point)
8292 (progn (forward-word -1) (point)))
8293 nil))
8294 (vhdl-template-field "[quantity name]" " => " t))
8295 (vhdl-template-field "expression")
8296 (setq position (point))
8297 (insert ", "))
8298 (delete-region position (point))
8299 (unless (vhdl-sequential-statement-p)
8300 (vhdl-insert-keyword " ON ")
8301 (if (vhdl-template-field "[sensitivity list]" nil t)
8302 (setq position (point))
8303 (delete-region position (point))))
8304 (vhdl-insert-keyword " WHEN ")
8305 (when vhdl-conditions-in-parenthesis (insert "("))
8306 (if (vhdl-template-field "[condition]" nil t)
8307 (when vhdl-conditions-in-parenthesis (insert ")"))
8308 (delete-region position (point)))
8309 (insert ";")))
8310
8311 (defun vhdl-template-case (&optional kind)
8312 "Insert a case statement."
8313 (interactive)
8314 (let ((margin (current-indentation))
8315 (start (point))
8316 label)
8317 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8318 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8319 (vhdl-insert-keyword "CASE ")
8320 (vhdl-insert-keyword ": CASE ")
8321 (goto-char start)
8322 (setq label (vhdl-template-field "[label]" nil t))
8323 (unless label (delete-char 2))
8324 (forward-word 1)
8325 (forward-char 1))
8326 (when (vhdl-template-field "expression" nil t start (point))
8327 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8328 (indent-to margin)
8329 (vhdl-insert-keyword "END CASE")
8330 (when label (insert " " label))
8331 (insert ";")
8332 (forward-line -1)
8333 (indent-to (+ margin vhdl-basic-offset))
8334 (vhdl-insert-keyword "WHEN ")
8335 (let ((position (point)))
8336 (insert " => ;\n")
8337 (indent-to (+ margin vhdl-basic-offset))
8338 (vhdl-insert-keyword "WHEN OTHERS => null;")
8339 (goto-char position)))))
8340
8341 (defun vhdl-template-case-is ()
8342 "Insert a sequential case statement."
8343 (interactive)
8344 (vhdl-template-case 'is))
8345
8346 (defun vhdl-template-case-use ()
8347 "Insert a simultaneous case statement."
8348 (interactive)
8349 (vhdl-template-case 'use))
8350
8351 (defun vhdl-template-component ()
8352 "Insert a component declaration."
8353 (interactive)
8354 (vhdl-template-component-decl))
8355
8356 (defun vhdl-template-component-conf ()
8357 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8358 since these are almost equivalent)."
8359 (interactive)
8360 (let ((margin (current-indentation))
8361 (result (vhdl-template-configuration-spec t)))
8362 (when result
8363 (insert "\n")
8364 (indent-to margin)
8365 (vhdl-insert-keyword "END FOR;")
8366 (when (eq result 'no-use)
8367 (end-of-line -0)))))
8368
8369 (defun vhdl-template-component-decl ()
8370 "Insert a component declaration."
8371 (interactive)
8372 (let ((margin (current-indentation))
8373 (start (point))
8374 name end-column)
8375 (vhdl-insert-keyword "COMPONENT ")
8376 (when (setq name (vhdl-template-field "name" nil t start (point)))
8377 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8378 (insert "\n\n")
8379 (indent-to margin)
8380 (vhdl-insert-keyword "END COMPONENT")
8381 (unless (vhdl-standard-p '87) (insert " " name))
8382 (insert ";")
8383 (setq end-column (current-column))
8384 (end-of-line -0)
8385 (indent-to (+ margin vhdl-basic-offset))
8386 (vhdl-template-generic-list t t)
8387 (insert "\n")
8388 (indent-to (+ margin vhdl-basic-offset))
8389 (vhdl-template-port-list t)
8390 (beginning-of-line 2)
8391 (forward-char end-column))))
8392
8393 (defun vhdl-template-component-inst ()
8394 "Insert a component instantiation statement."
8395 (interactive)
8396 (let ((margin (current-indentation))
8397 (start (point))
8398 unit position)
8399 (when (vhdl-template-field "instance label" nil t start (point))
8400 (insert ": ")
8401 (if (not (vhdl-use-direct-instantiation))
8402 (vhdl-template-field "component name")
8403 ;; direct instantiation
8404 (setq unit (vhdl-template-field
8405 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8406 (setq unit (upcase (or unit "")))
8407 (cond ((equal unit "ENTITY")
8408 (vhdl-template-field "library name" "." nil nil nil nil
8409 (vhdl-work-library))
8410 (vhdl-template-field "entity name" "(")
8411 (if (vhdl-template-field "[architecture name]" nil t)
8412 (insert ")")
8413 (delete-char -1)))
8414 ((equal unit "CONFIGURATION")
8415 (vhdl-template-field "library name" "." nil nil nil nil
8416 (vhdl-work-library))
8417 (vhdl-template-field "configuration name"))
8418 (t (vhdl-template-field "component name"))))
8419 (insert "\n")
8420 (indent-to (+ margin vhdl-basic-offset))
8421 (setq position (point))
8422 (vhdl-insert-keyword "GENERIC ")
8423 (when (vhdl-template-map position t t)
8424 (insert "\n")
8425 (indent-to (+ margin vhdl-basic-offset)))
8426 (setq position (point))
8427 (vhdl-insert-keyword "PORT ")
8428 (unless (vhdl-template-map position t t)
8429 (delete-region (line-beginning-position) (point))
8430 (delete-char -1))
8431 (insert ";"))))
8432
8433 (defun vhdl-template-conditional-signal-asst ()
8434 "Insert a conditional signal assignment."
8435 (interactive)
8436 (when (vhdl-template-field "target signal")
8437 (insert " <= ")
8438 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8439 ; (insert " "))
8440 (let ((margin (current-column))
8441 (start (point))
8442 position)
8443 (vhdl-template-field "waveform")
8444 (setq position (point))
8445 (vhdl-insert-keyword " WHEN ")
8446 (when vhdl-conditions-in-parenthesis (insert "("))
8447 (while (and (vhdl-template-field "[condition]" nil t)
8448 (progn
8449 (when vhdl-conditions-in-parenthesis (insert ")"))
8450 (setq position (point))
8451 (vhdl-insert-keyword " ELSE")
8452 (insert "\n")
8453 (indent-to margin)
8454 (vhdl-template-field "[waveform]" nil t)))
8455 (setq position (point))
8456 (vhdl-insert-keyword " WHEN ")
8457 (when vhdl-conditions-in-parenthesis (insert "(")))
8458 (delete-region position (point))
8459 (insert ";")
8460 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8461
8462 (defun vhdl-template-configuration ()
8463 "Insert a configuration specification if within an architecture,
8464 a block or component configuration if within a configuration declaration,
8465 a configuration declaration if not within a design unit."
8466 (interactive)
8467 (vhdl-prepare-search-1
8468 (cond
8469 ((and (save-excursion ; architecture body
8470 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8471 (equal "ARCHITECTURE" (upcase (match-string 1))))
8472 (vhdl-template-configuration-spec))
8473 ((and (save-excursion ; configuration declaration
8474 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8475 (equal "CONFIGURATION" (upcase (match-string 1))))
8476 (if (eq (vhdl-decision-query
8477 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8478 (vhdl-template-component-conf)
8479 (vhdl-template-block-configuration)))
8480 (t (vhdl-template-configuration-decl))))) ; otherwise
8481
8482 (defun vhdl-template-configuration-spec (&optional optional-use)
8483 "Insert a configuration specification."
8484 (interactive)
8485 (let ((margin (current-indentation))
8486 (start (point))
8487 aspect position)
8488 (vhdl-insert-keyword "FOR ")
8489 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8490 t start (point))
8491 (vhdl-template-field "component name" "\n")
8492 (indent-to (+ margin vhdl-basic-offset))
8493 (setq start (point))
8494 (vhdl-insert-keyword "USE ")
8495 (if (and optional-use
8496 (not (setq aspect (vhdl-template-field
8497 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8498 (progn (delete-region start (point)) 'no-use)
8499 (unless optional-use
8500 (setq aspect (vhdl-template-field
8501 "ENTITY | CONFIGURATION | OPEN" " ")))
8502 (setq aspect (upcase (or aspect "")))
8503 (cond ((equal aspect "ENTITY")
8504 (vhdl-template-field "library name" "." nil nil nil nil
8505 (vhdl-work-library))
8506 (vhdl-template-field "entity name" "(")
8507 (if (vhdl-template-field "[architecture name]" nil t)
8508 (insert ")")
8509 (delete-char -1))
8510 (insert "\n")
8511 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8512 (setq position (point))
8513 (vhdl-insert-keyword "GENERIC ")
8514 (when (vhdl-template-map position t t)
8515 (insert "\n")
8516 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8517 (setq position (point))
8518 (vhdl-insert-keyword "PORT ")
8519 (unless (vhdl-template-map position t t)
8520 (delete-region (line-beginning-position) (point))
8521 (delete-char -1))
8522 (insert ";")
8523 t)
8524 ((equal aspect "CONFIGURATION")
8525 (vhdl-template-field "library name" "." nil nil nil nil
8526 (vhdl-work-library))
8527 (vhdl-template-field "configuration name" ";"))
8528 (t (delete-char -1) (insert ";") t))))))
8529
8530
8531 (defun vhdl-template-configuration-decl ()
8532 "Insert a configuration declaration."
8533 (interactive)
8534 (let ((margin (current-indentation))
8535 (start (point))
8536 entity-exists string name position)
8537 (vhdl-insert-keyword "CONFIGURATION ")
8538 (when (setq name (vhdl-template-field "name" nil t start (point)))
8539 (vhdl-insert-keyword " OF ")
8540 (save-excursion
8541 (vhdl-prepare-search-1
8542 (setq entity-exists (vhdl-re-search-backward
8543 "\\<entity \\(\\w*\\) is\\>" nil t))
8544 (setq string (match-string 1))))
8545 (if (and entity-exists (not (equal string "")))
8546 (insert string)
8547 (vhdl-template-field "entity name"))
8548 (vhdl-insert-keyword " IS\n")
8549 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8550 (indent-to (+ margin vhdl-basic-offset))
8551 (setq position (point))
8552 (insert "\n")
8553 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8554 (indent-to margin)
8555 (vhdl-insert-keyword "END ")
8556 (unless (vhdl-standard-p '87)
8557 (vhdl-insert-keyword "CONFIGURATION "))
8558 (insert name ";")
8559 (goto-char position))))
8560
8561 (defun vhdl-template-constant ()
8562 "Insert a constant declaration."
8563 (interactive)
8564 (let ((start (point))
8565 (in-arglist (vhdl-in-argument-list-p)))
8566 (vhdl-insert-keyword "CONSTANT ")
8567 (when (vhdl-template-field "name" nil t start (point))
8568 (insert " : ")
8569 (when in-arglist (vhdl-insert-keyword "IN "))
8570 (vhdl-template-field "type")
8571 (if in-arglist
8572 (progn (insert ";")
8573 (vhdl-comment-insert-inline))
8574 (let ((position (point)))
8575 (insert " := ")
8576 (unless (vhdl-template-field "[initialization]" nil t)
8577 (delete-region position (point)))
8578 (insert ";")
8579 (vhdl-comment-insert-inline))))))
8580
8581 (defun vhdl-template-default ()
8582 "Insert nothing."
8583 (interactive)
8584 (insert " ")
8585 (unexpand-abbrev)
8586 (backward-word 1)
8587 (vhdl-case-word 1)
8588 (forward-char 1))
8589
8590 (defun vhdl-template-default-indent ()
8591 "Insert nothing and indent."
8592 (interactive)
8593 (insert " ")
8594 (unexpand-abbrev)
8595 (backward-word 1)
8596 (vhdl-case-word 1)
8597 (forward-char 1)
8598 (indent-according-to-mode))
8599
8600 (defun vhdl-template-disconnect ()
8601 "Insert a disconnect statement."
8602 (interactive)
8603 (let ((start (point)))
8604 (vhdl-insert-keyword "DISCONNECT ")
8605 (when (vhdl-template-field "signal names | OTHERS | ALL"
8606 " : " t start (point))
8607 (vhdl-template-field "type")
8608 (vhdl-insert-keyword " AFTER ")
8609 (vhdl-template-field "time expression" ";"))))
8610
8611 (defun vhdl-template-else ()
8612 "Insert an else statement."
8613 (interactive)
8614 (let (margin)
8615 (vhdl-prepare-search-1
8616 (vhdl-insert-keyword "ELSE")
8617 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8618 (equal "WHEN" (upcase (match-string 1))))
8619 (insert " ")
8620 (indent-according-to-mode)
8621 (setq margin (current-indentation))
8622 (insert "\n")
8623 (indent-to (+ margin vhdl-basic-offset))))))
8624
8625 (defun vhdl-template-elsif ()
8626 "Insert an elsif statement."
8627 (interactive)
8628 (let ((start (point))
8629 margin)
8630 (vhdl-insert-keyword "ELSIF ")
8631 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8632 (when vhdl-conditions-in-parenthesis (insert "("))
8633 (when (vhdl-template-field "condition" nil t start (point))
8634 (when vhdl-conditions-in-parenthesis (insert ")"))
8635 (indent-according-to-mode)
8636 (setq margin (current-indentation))
8637 (vhdl-insert-keyword
8638 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8639 (indent-to (+ margin vhdl-basic-offset))))))
8640
8641 (defun vhdl-template-entity ()
8642 "Insert an entity."
8643 (interactive)
8644 (let ((margin (current-indentation))
8645 (start (point))
8646 name end-column)
8647 (vhdl-insert-keyword "ENTITY ")
8648 (when (setq name (vhdl-template-field "name" nil t start (point)))
8649 (vhdl-insert-keyword " IS\n\n")
8650 (indent-to margin)
8651 (vhdl-insert-keyword "END ")
8652 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8653 (insert name ";")
8654 (setq end-column (current-column))
8655 (end-of-line -0)
8656 (indent-to (+ margin vhdl-basic-offset))
8657 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8658 (indent-to (+ margin vhdl-basic-offset))
8659 (when (vhdl-template-generic-list t)
8660 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8661 (insert "\n")
8662 (indent-to (+ margin vhdl-basic-offset))
8663 (when (vhdl-template-port-list t)
8664 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8665 (beginning-of-line 2)
8666 (forward-char end-column))))
8667
8668 (defun vhdl-template-exit ()
8669 "Insert an exit statement."
8670 (interactive)
8671 (let ((start (point)))
8672 (vhdl-insert-keyword "EXIT ")
8673 (if (vhdl-template-field "[loop label]" nil t start (point))
8674 (let ((position (point)))
8675 (vhdl-insert-keyword " WHEN ")
8676 (when vhdl-conditions-in-parenthesis (insert "("))
8677 (if (vhdl-template-field "[condition]" nil t)
8678 (when vhdl-conditions-in-parenthesis (insert ")"))
8679 (delete-region position (point))))
8680 (delete-char -1))
8681 (insert ";")))
8682
8683 (defun vhdl-template-file ()
8684 "Insert a file declaration."
8685 (interactive)
8686 (let ((start (point)))
8687 (vhdl-insert-keyword "FILE ")
8688 (when (vhdl-template-field "name" nil t start (point))
8689 (insert " : ")
8690 (vhdl-template-field "type")
8691 (unless (vhdl-standard-p '87)
8692 (vhdl-insert-keyword " OPEN ")
8693 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8694 nil t)
8695 (delete-char -6)))
8696 (vhdl-insert-keyword " IS ")
8697 (when (vhdl-standard-p '87)
8698 (vhdl-template-field "[IN | OUT]" " " t))
8699 (vhdl-template-field "filename-string" nil nil nil nil t)
8700 (insert ";")
8701 (vhdl-comment-insert-inline))))
8702
8703 (defun vhdl-template-for ()
8704 "Insert a block or component configuration if within a configuration
8705 declaration, a configuration specification if within an architecture
8706 declarative part (and not within a subprogram), a for-loop if within a
8707 sequential statement part (subprogram or process), and a for-generate
8708 otherwise."
8709 (interactive)
8710 (vhdl-prepare-search-1
8711 (cond
8712 ((vhdl-sequential-statement-p) ; sequential statement
8713 (vhdl-template-for-loop))
8714 ((and (save-excursion ; configuration declaration
8715 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8716 (equal "CONFIGURATION" (upcase (match-string 1))))
8717 (if (eq (vhdl-decision-query
8718 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8719 (vhdl-template-component-conf)
8720 (vhdl-template-block-configuration)))
8721 ((and (save-excursion
8722 (re-search-backward ; architecture declarative part
8723 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8724 (equal "ARCHITECTURE" (upcase (match-string 1))))
8725 (vhdl-template-configuration-spec))
8726 (t (vhdl-template-for-generate))))) ; concurrent statement
8727
8728 (defun vhdl-template-for-generate ()
8729 "Insert a for-generate."
8730 (interactive)
8731 (let ((margin (current-indentation))
8732 (start (point))
8733 label position)
8734 (vhdl-insert-keyword ": FOR ")
8735 (setq position (point-marker))
8736 (goto-char start)
8737 (when (setq label (vhdl-template-field "label" nil t start position))
8738 (goto-char position)
8739 (vhdl-template-field "loop variable")
8740 (vhdl-insert-keyword " IN ")
8741 (vhdl-template-field "range")
8742 (vhdl-template-generate-body margin label))))
8743
8744 (defun vhdl-template-for-loop ()
8745 "Insert a for loop."
8746 (interactive)
8747 (let ((margin (current-indentation))
8748 (start (point))
8749 label index)
8750 (if (not (eq vhdl-optional-labels 'all))
8751 (vhdl-insert-keyword "FOR ")
8752 (vhdl-insert-keyword ": FOR ")
8753 (goto-char start)
8754 (setq label (vhdl-template-field "[label]" nil t))
8755 (unless label (delete-char 2))
8756 (forward-word 1)
8757 (forward-char 1))
8758 (when (setq index (vhdl-template-field "loop variable"
8759 nil t start (point)))
8760 (vhdl-insert-keyword " IN ")
8761 (vhdl-template-field "range")
8762 (vhdl-insert-keyword " LOOP\n\n")
8763 (indent-to margin)
8764 (vhdl-insert-keyword "END LOOP")
8765 (if label
8766 (insert " " label ";")
8767 (insert ";")
8768 (when vhdl-self-insert-comments (insert " -- " index)))
8769 (forward-line -1)
8770 (indent-to (+ margin vhdl-basic-offset)))))
8771
8772 (defun vhdl-template-function (&optional kind)
8773 "Insert a function declaration or body."
8774 (interactive)
8775 (let ((margin (current-indentation))
8776 (start (point))
8777 name)
8778 (vhdl-insert-keyword "FUNCTION ")
8779 (when (setq name (vhdl-template-field "name" nil t start (point)))
8780 (vhdl-template-argument-list t)
8781 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8782 (end-of-line)
8783 (insert "\n")
8784 (indent-to (+ margin vhdl-basic-offset))
8785 (vhdl-insert-keyword "RETURN ")
8786 (vhdl-template-field "type")
8787 (if (if kind (eq kind 'body)
8788 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8789 (progn (vhdl-insert-keyword " IS\n")
8790 (vhdl-template-begin-end
8791 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8792 (vhdl-comment-block))
8793 (insert ";")))))
8794
8795 (defun vhdl-template-function-decl ()
8796 "Insert a function declaration."
8797 (interactive)
8798 (vhdl-template-function 'decl))
8799
8800 (defun vhdl-template-function-body ()
8801 "Insert a function declaration."
8802 (interactive)
8803 (vhdl-template-function 'body))
8804
8805 (defun vhdl-template-generate ()
8806 "Insert a generation scheme."
8807 (interactive)
8808 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8809 (vhdl-template-if-generate)
8810 (vhdl-template-for-generate)))
8811
8812 (defun vhdl-template-generic ()
8813 "Insert generic declaration, or generic map in instantiation statements."
8814 (interactive)
8815 (let ((start (point)))
8816 (vhdl-prepare-search-1
8817 (cond
8818 ((and (save-excursion ; entity declaration
8819 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8820 (equal "ENTITY" (upcase (match-string 1))))
8821 (vhdl-template-generic-list nil))
8822 ((or (save-excursion
8823 (or (beginning-of-line)
8824 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8825 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8826 (vhdl-insert-keyword "GENERIC ")
8827 (vhdl-template-map start))
8828 (t (vhdl-template-generic-list nil t))))))
8829
8830 (defun vhdl-template-group ()
8831 "Insert group or group template declaration."
8832 (interactive)
8833 (let ((start (point)))
8834 (if (eq (vhdl-decision-query
8835 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8836 (vhdl-template-group-template)
8837 (vhdl-template-group-decl))))
8838
8839 (defun vhdl-template-group-decl ()
8840 "Insert group declaration."
8841 (interactive)
8842 (let ((start (point)))
8843 (vhdl-insert-keyword "GROUP ")
8844 (when (vhdl-template-field "name" " : " t start (point))
8845 (vhdl-template-field "template name" " (")
8846 (vhdl-template-field "constituent list" ");")
8847 (vhdl-comment-insert-inline))))
8848
8849 (defun vhdl-template-group-template ()
8850 "Insert group template declaration."
8851 (interactive)
8852 (let ((start (point)))
8853 (vhdl-insert-keyword "GROUP ")
8854 (when (vhdl-template-field "template name" nil t start (point))
8855 (vhdl-insert-keyword " IS (")
8856 (vhdl-template-field "entity class list" ");")
8857 (vhdl-comment-insert-inline))))
8858
8859 (defun vhdl-template-if ()
8860 "Insert a sequential if statement or an if-generate statement."
8861 (interactive)
8862 (if (vhdl-sequential-statement-p)
8863 (vhdl-template-if-then)
8864 (if (and (vhdl-standard-p 'ams)
8865 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8866 (vhdl-template-if-use)
8867 (vhdl-template-if-generate))))
8868
8869 (defun vhdl-template-if-generate ()
8870 "Insert an if-generate."
8871 (interactive)
8872 (let ((margin (current-indentation))
8873 (start (point))
8874 label position)
8875 (vhdl-insert-keyword ": IF ")
8876 (setq position (point-marker))
8877 (goto-char start)
8878 (when (setq label (vhdl-template-field "label" nil t start position))
8879 (goto-char position)
8880 (when vhdl-conditions-in-parenthesis (insert "("))
8881 (vhdl-template-field "condition")
8882 (when vhdl-conditions-in-parenthesis (insert ")"))
8883 (vhdl-template-generate-body margin label))))
8884
8885 (defun vhdl-template-if-then-use (kind)
8886 "Insert a sequential if statement."
8887 (interactive)
8888 (let ((margin (current-indentation))
8889 (start (point))
8890 label)
8891 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8892 (vhdl-insert-keyword "IF ")
8893 (vhdl-insert-keyword ": IF ")
8894 (goto-char start)
8895 (setq label (vhdl-template-field "[label]" nil t))
8896 (unless label (delete-char 2))
8897 (forward-word 1)
8898 (forward-char 1))
8899 (when vhdl-conditions-in-parenthesis (insert "("))
8900 (when (vhdl-template-field "condition" nil t start (point))
8901 (when vhdl-conditions-in-parenthesis (insert ")"))
8902 (vhdl-insert-keyword
8903 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8904 (indent-to margin)
8905 (vhdl-insert-keyword "END IF")
8906 (when label (insert " " label))
8907 (insert ";")
8908 (forward-line -1)
8909 (indent-to (+ margin vhdl-basic-offset)))))
8910
8911 (defun vhdl-template-if-then ()
8912 "Insert a sequential if statement."
8913 (interactive)
8914 (vhdl-template-if-then-use 'then))
8915
8916 (defun vhdl-template-if-use ()
8917 "Insert a simultaneous if statement."
8918 (interactive)
8919 (vhdl-template-if-then-use 'use))
8920
8921 (defun vhdl-template-instance ()
8922 "Insert a component instantiation statement."
8923 (interactive)
8924 (vhdl-template-component-inst))
8925
8926 (defun vhdl-template-library ()
8927 "Insert a library specification."
8928 (interactive)
8929 (let ((margin (current-indentation))
8930 (start (point))
8931 name end-pos)
8932 (vhdl-insert-keyword "LIBRARY ")
8933 (when (setq name (vhdl-template-field "names" nil t start (point)))
8934 (insert ";")
8935 (unless (string-match "," name)
8936 (setq end-pos (point))
8937 (insert "\n")
8938 (indent-to margin)
8939 (vhdl-insert-keyword "USE ")
8940 (insert name)
8941 (vhdl-insert-keyword "..ALL;")
8942 (backward-char 5)
8943 (if (vhdl-template-field "package name")
8944 (forward-char 5)
8945 (delete-region end-pos (+ (point) 5)))))))
8946
8947 (defun vhdl-template-limit ()
8948 "Insert a limit."
8949 (interactive)
8950 (let ((start (point)))
8951 (vhdl-insert-keyword "LIMIT ")
8952 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8953 t start (point))
8954 (vhdl-template-field "type")
8955 (vhdl-insert-keyword " WITH ")
8956 (vhdl-template-field "real expression" ";"))))
8957
8958 (defun vhdl-template-loop ()
8959 "Insert a loop."
8960 (interactive)
8961 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8962 (cond ((eq char ?w)
8963 (vhdl-template-while-loop))
8964 ((eq char ?f)
8965 (vhdl-template-for-loop))
8966 (t (vhdl-template-bare-loop)))))
8967
8968 (defun vhdl-template-bare-loop ()
8969 "Insert a loop."
8970 (interactive)
8971 (let ((margin (current-indentation))
8972 (start (point))
8973 label)
8974 (if (not (eq vhdl-optional-labels 'all))
8975 (vhdl-insert-keyword "LOOP ")
8976 (vhdl-insert-keyword ": LOOP ")
8977 (goto-char start)
8978 (setq label (vhdl-template-field "[label]" nil t))
8979 (unless label (delete-char 2))
8980 (forward-word 1)
8981 (delete-char 1))
8982 (insert "\n\n")
8983 (indent-to margin)
8984 (vhdl-insert-keyword "END LOOP")
8985 (insert (if label (concat " " label ";") ";"))
8986 (forward-line -1)
8987 (indent-to (+ margin vhdl-basic-offset))))
8988
8989 (defun vhdl-template-map (&optional start optional secondary)
8990 "Insert a map specification with association list."
8991 (interactive)
8992 (let ((start (or start (point)))
8993 margin end-pos)
8994 (vhdl-insert-keyword "MAP (")
8995 (if (not vhdl-association-list-with-formals)
8996 (if (vhdl-template-field
8997 (concat (and optional "[") "association list" (and optional "]"))
8998 ")" (or (not secondary) optional)
8999 (and (not secondary) start) (point))
9000 t
9001 (if (and optional secondary) (delete-region start (point)))
9002 nil)
9003 (if vhdl-argument-list-indent
9004 (setq margin (current-column))
9005 (setq margin (+ (current-indentation) vhdl-basic-offset))
9006 (insert "\n")
9007 (indent-to margin))
9008 (if (vhdl-template-field
9009 (concat (and optional "[") "formal" (and optional "]"))
9010 " => " (or (not secondary) optional)
9011 (and (not secondary) start) (point))
9012 (progn
9013 (vhdl-template-field "actual" ",")
9014 (setq end-pos (point))
9015 (insert "\n")
9016 (indent-to margin)
9017 (while (vhdl-template-field "[formal]" " => " t)
9018 (vhdl-template-field "actual" ",")
9019 (setq end-pos (point))
9020 (insert "\n")
9021 (indent-to margin))
9022 (delete-region end-pos (point))
9023 (delete-char -1)
9024 (insert ")")
9025 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9026 t)
9027 (when (and optional secondary) (delete-region start (point)))
9028 nil))))
9029
9030 (defun vhdl-template-modify (&optional noerror)
9031 "Actualize modification date."
9032 (interactive)
9033 (vhdl-prepare-search-2
9034 (save-excursion
9035 (goto-char (point-min))
9036 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9037 (progn (delete-region (point) (progn (end-of-line) (point)))
9038 (vhdl-template-insert-date))
9039 (unless noerror
9040 (error "ERROR: Modification date prefix string \"%s\" not found"
9041 vhdl-modify-date-prefix-string))))))
9042
9043
9044 (defun vhdl-template-modify-noerror ()
9045 "Call `vhdl-template-modify' with NOERROR non-nil."
9046 (vhdl-template-modify t))
9047
9048 (defun vhdl-template-nature ()
9049 "Insert a nature declaration."
9050 (interactive)
9051 (let ((start (point))
9052 name mid-pos end-pos)
9053 (vhdl-insert-keyword "NATURE ")
9054 (when (setq name (vhdl-template-field "name" nil t start (point)))
9055 (vhdl-insert-keyword " IS ")
9056 (let ((definition
9057 (upcase
9058 (or (vhdl-template-field
9059 "across type | ARRAY | RECORD")
9060 ""))))
9061 (cond ((equal definition "")
9062 (insert ";"))
9063 ((equal definition "ARRAY")
9064 (delete-region (point) (progn (forward-word -1) (point)))
9065 (vhdl-template-array 'nature t))
9066 ((equal definition "RECORD")
9067 (setq mid-pos (point-marker))
9068 (delete-region (point) (progn (forward-word -1) (point)))
9069 (vhdl-template-record 'nature name t))
9070 (t
9071 (vhdl-insert-keyword " ACROSS ")
9072 (vhdl-template-field "through type")
9073 (vhdl-insert-keyword " THROUGH ")
9074 (vhdl-template-field "reference name")
9075 (vhdl-insert-keyword " REFERENCE;")))
9076 (when mid-pos
9077 (setq end-pos (point-marker))
9078 (goto-char mid-pos)
9079 (end-of-line))
9080 (vhdl-comment-insert-inline)
9081 (when end-pos (goto-char end-pos))))))
9082
9083 (defun vhdl-template-next ()
9084 "Insert a next statement."
9085 (interactive)
9086 (let ((start (point)))
9087 (vhdl-insert-keyword "NEXT ")
9088 (if (vhdl-template-field "[loop label]" nil t start (point))
9089 (let ((position (point)))
9090 (vhdl-insert-keyword " WHEN ")
9091 (when vhdl-conditions-in-parenthesis (insert "("))
9092 (if (vhdl-template-field "[condition]" nil t)
9093 (when vhdl-conditions-in-parenthesis (insert ")"))
9094 (delete-region position (point))))
9095 (delete-char -1))
9096 (insert ";")))
9097
9098 (defun vhdl-template-others ()
9099 "Insert an others aggregate."
9100 (interactive)
9101 (let ((start (point)))
9102 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9103 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9104 (vhdl-insert-keyword "OTHERS => '")
9105 (when (vhdl-template-field "value" nil t start (point))
9106 (insert "')")))
9107 (vhdl-insert-keyword "OTHERS "))))
9108
9109 (defun vhdl-template-package (&optional kind)
9110 "Insert a package specification or body."
9111 (interactive)
9112 (let ((margin (current-indentation))
9113 (start (point))
9114 name body position)
9115 (vhdl-insert-keyword "PACKAGE ")
9116 (setq body (if kind (eq kind 'body)
9117 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9118 (when body
9119 (vhdl-insert-keyword "BODY ")
9120 (when (save-excursion
9121 (vhdl-prepare-search-1
9122 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9123 (insert (setq name (match-string 1)))))
9124 (when (or name
9125 (setq name (vhdl-template-field "name" nil t start (point))))
9126 (vhdl-insert-keyword " IS\n")
9127 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9128 (indent-to (+ margin vhdl-basic-offset))
9129 (setq position (point))
9130 (insert "\n")
9131 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9132 (indent-to margin)
9133 (vhdl-insert-keyword "END ")
9134 (unless (vhdl-standard-p '87)
9135 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9136 (insert (or name "") ";")
9137 (goto-char position))))
9138
9139 (defun vhdl-template-package-decl ()
9140 "Insert a package specification."
9141 (interactive)
9142 (vhdl-template-package 'decl))
9143
9144 (defun vhdl-template-package-body ()
9145 "Insert a package body."
9146 (interactive)
9147 (vhdl-template-package 'body))
9148
9149 (defun vhdl-template-port ()
9150 "Insert a port declaration, or port map in instantiation statements."
9151 (interactive)
9152 (let ((start (point)))
9153 (vhdl-prepare-search-1
9154 (cond
9155 ((and (save-excursion ; entity declaration
9156 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9157 (equal "ENTITY" (upcase (match-string 1))))
9158 (vhdl-template-port-list nil))
9159 ((or (save-excursion
9160 (or (beginning-of-line)
9161 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9162 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9163 (vhdl-insert-keyword "PORT ")
9164 (vhdl-template-map start))
9165 (t (vhdl-template-port-list nil))))))
9166
9167 (defun vhdl-template-procedural ()
9168 "Insert a procedural."
9169 (interactive)
9170 (let ((margin (current-indentation))
9171 (start (point))
9172 (case-fold-search t)
9173 label)
9174 (vhdl-insert-keyword "PROCEDURAL ")
9175 (when (memq vhdl-optional-labels '(process all))
9176 (goto-char start)
9177 (insert ": ")
9178 (goto-char start)
9179 (setq label (vhdl-template-field "[label]" nil t))
9180 (unless label (delete-char 2))
9181 (forward-word 1)
9182 (forward-char 1))
9183 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9184 (insert "\n")
9185 (vhdl-template-begin-end "PROCEDURAL" label margin)
9186 (vhdl-comment-block)))
9187
9188 (defun vhdl-template-procedure (&optional kind)
9189 "Insert a procedure declaration or body."
9190 (interactive)
9191 (let ((margin (current-indentation))
9192 (start (point))
9193 name)
9194 (vhdl-insert-keyword "PROCEDURE ")
9195 (when (setq name (vhdl-template-field "name" nil t start (point)))
9196 (vhdl-template-argument-list)
9197 (if (if kind (eq kind 'body)
9198 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9199 (progn (vhdl-insert-keyword " IS")
9200 (when vhdl-auto-align
9201 (vhdl-align-region-groups start (point) 1))
9202 (end-of-line) (insert "\n")
9203 (vhdl-template-begin-end
9204 (unless (vhdl-standard-p '87) "PROCEDURE")
9205 name margin)
9206 (vhdl-comment-block))
9207 (insert ";")
9208 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9209 (end-of-line)))))
9210
9211 (defun vhdl-template-procedure-decl ()
9212 "Insert a procedure declaration."
9213 (interactive)
9214 (vhdl-template-procedure 'decl))
9215
9216 (defun vhdl-template-procedure-body ()
9217 "Insert a procedure body."
9218 (interactive)
9219 (vhdl-template-procedure 'body))
9220
9221 (defun vhdl-template-process (&optional kind)
9222 "Insert a process."
9223 (interactive)
9224 (let ((margin (current-indentation))
9225 (start (point))
9226 label seq input-signals clock reset final-pos)
9227 (setq seq (if kind (eq kind 'seq)
9228 (eq (vhdl-decision-query
9229 "process" "(c)ombinational or (s)equential?" t) ?s)))
9230 (vhdl-insert-keyword "PROCESS ")
9231 (when (memq vhdl-optional-labels '(process all))
9232 (goto-char start)
9233 (insert ": ")
9234 (goto-char start)
9235 (setq label (vhdl-template-field "[label]" nil t))
9236 (unless label (delete-char 2))
9237 (forward-word 1)
9238 (forward-char 1))
9239 (insert "(")
9240 (if (not seq)
9241 (unless (setq input-signals
9242 (vhdl-template-field "[sensitivity list]" ")" t))
9243 (setq input-signals "")
9244 (delete-char -2))
9245 (setq clock (or (and (not (equal "" vhdl-clock-name))
9246 (progn (insert vhdl-clock-name) vhdl-clock-name))
9247 (vhdl-template-field "clock name") "<clock>"))
9248 (when (eq vhdl-reset-kind 'async)
9249 (insert ", ")
9250 (setq reset (or (and (not (equal "" vhdl-reset-name))
9251 (progn (insert vhdl-reset-name) vhdl-reset-name))
9252 (vhdl-template-field "reset name") "<reset>")))
9253 (insert ")"))
9254 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9255 (insert "\n")
9256 (vhdl-template-begin-end "PROCESS" label margin)
9257 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9258 (when vhdl-prompt-for-comments
9259 (setq final-pos (point-marker))
9260 (vhdl-prepare-search-2
9261 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9262 (vhdl-re-search-backward "\\<process\\>" nil t))
9263 (end-of-line -0)
9264 (if (bobp)
9265 (progn (insert "\n") (forward-line -1))
9266 (insert "\n"))
9267 (indent-to margin)
9268 (insert "-- purpose: ")
9269 (if (not (vhdl-template-field "[description]" nil t))
9270 (vhdl-line-kill-entire)
9271 (insert "\n")
9272 (indent-to margin)
9273 (insert "-- type : ")
9274 (insert (if seq "sequential" "combinational") "\n")
9275 (indent-to margin)
9276 (insert "-- inputs : ")
9277 (if (not seq)
9278 (insert input-signals)
9279 (insert clock ", ")
9280 (when reset (insert reset ", "))
9281 (unless (vhdl-template-field "[signal names]" nil t)
9282 (delete-char -2)))
9283 (insert "\n")
9284 (indent-to margin)
9285 (insert "-- outputs: ")
9286 (vhdl-template-field "[signal names]" nil t))))
9287 (goto-char final-pos))))
9288
9289 (defun vhdl-template-process-comb ()
9290 "Insert a combinational process."
9291 (interactive)
9292 (vhdl-template-process 'comb))
9293
9294 (defun vhdl-template-process-seq ()
9295 "Insert a sequential process."
9296 (interactive)
9297 (vhdl-template-process 'seq))
9298
9299 (defun vhdl-template-quantity ()
9300 "Insert a quantity declaration."
9301 (interactive)
9302 (if (vhdl-in-argument-list-p)
9303 (let ((start (point)))
9304 (vhdl-insert-keyword "QUANTITY ")
9305 (when (vhdl-template-field "names" nil t start (point))
9306 (insert " : ")
9307 (vhdl-template-field "[IN | OUT]" " " t)
9308 (vhdl-template-field "type")
9309 (insert ";")
9310 (vhdl-comment-insert-inline)))
9311 (let ((char (vhdl-decision-query
9312 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9313 (cond ((eq char ?f) (vhdl-template-quantity-free))
9314 ((eq char ?b) (vhdl-template-quantity-branch))
9315 ((eq char ?s) (vhdl-template-quantity-source))
9316 (t (vhdl-template-undo (point) (point)))))))
9317
9318 (defun vhdl-template-quantity-free ()
9319 "Insert a free quantity declaration."
9320 (interactive)
9321 (vhdl-insert-keyword "QUANTITY ")
9322 (vhdl-template-field "names")
9323 (insert " : ")
9324 (vhdl-template-field "type")
9325 (let ((position (point)))
9326 (insert " := ")
9327 (unless (vhdl-template-field "[initialization]" nil t)
9328 (delete-region position (point)))
9329 (insert ";")
9330 (vhdl-comment-insert-inline)))
9331
9332 (defun vhdl-template-quantity-branch ()
9333 "Insert a branch quantity declaration."
9334 (interactive)
9335 (let (position)
9336 (vhdl-insert-keyword "QUANTITY ")
9337 (when (vhdl-template-field "[across names]" " " t)
9338 (vhdl-insert-keyword "ACROSS "))
9339 (when (vhdl-template-field "[through names]" " " t)
9340 (vhdl-insert-keyword "THROUGH "))
9341 (vhdl-template-field "plus terminal name")
9342 (setq position (point))
9343 (vhdl-insert-keyword " TO ")
9344 (unless (vhdl-template-field "[minus terminal name]" nil t)
9345 (delete-region position (point)))
9346 (insert ";")
9347 (vhdl-comment-insert-inline)))
9348
9349 (defun vhdl-template-quantity-source ()
9350 "Insert a source quantity declaration."
9351 (interactive)
9352 (vhdl-insert-keyword "QUANTITY ")
9353 (vhdl-template-field "names")
9354 (insert " : ")
9355 (vhdl-template-field "type" " ")
9356 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9357 (progn (vhdl-insert-keyword "NOISE ")
9358 (vhdl-template-field "power expression"))
9359 (vhdl-insert-keyword "SPECTRUM ")
9360 (vhdl-template-field "magnitude expression" ", ")
9361 (vhdl-template-field "phase expression"))
9362 (insert ";")
9363 (vhdl-comment-insert-inline))
9364
9365 (defun vhdl-template-record (kind &optional name secondary)
9366 "Insert a record type declaration."
9367 (interactive)
9368 (let ((margin (current-column))
9369 (start (point))
9370 (first t))
9371 (vhdl-insert-keyword "RECORD\n")
9372 (indent-to (+ margin vhdl-basic-offset))
9373 (when (or (vhdl-template-field "element names"
9374 nil (not secondary) start (point))
9375 secondary)
9376 (while (or first (vhdl-template-field "[element names]" nil t))
9377 (insert " : ")
9378 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9379 (vhdl-comment-insert-inline)
9380 (insert "\n")
9381 (indent-to (+ margin vhdl-basic-offset))
9382 (setq first nil))
9383 (delete-region (line-beginning-position) (point))
9384 (indent-to margin)
9385 (vhdl-insert-keyword "END RECORD")
9386 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9387 (insert ";")
9388 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9389
9390 (defun vhdl-template-report ()
9391 "Insert a report statement."
9392 (interactive)
9393 (let ((start (point)))
9394 (vhdl-insert-keyword "REPORT ")
9395 (if (equal "\"\"" (vhdl-template-field
9396 "string expression" nil t start (point) t))
9397 (delete-char -2)
9398 (setq start (point))
9399 (vhdl-insert-keyword " SEVERITY ")
9400 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9401 (delete-region start (point)))
9402 (insert ";"))))
9403
9404 (defun vhdl-template-return ()
9405 "Insert a return statement."
9406 (interactive)
9407 (let ((start (point)))
9408 (vhdl-insert-keyword "RETURN ")
9409 (unless (vhdl-template-field "[expression]" nil t start (point))
9410 (delete-char -1))
9411 (insert ";")))
9412
9413 (defun vhdl-template-selected-signal-asst ()
9414 "Insert a selected signal assignment."
9415 (interactive)
9416 (let ((margin (current-indentation))
9417 (start (point))
9418 (choices t))
9419 (let ((position (point)))
9420 (vhdl-insert-keyword " SELECT ")
9421 (goto-char position))
9422 (vhdl-insert-keyword "WITH ")
9423 (when (vhdl-template-field "selector expression"
9424 nil t start (+ (point) 7))
9425 (forward-word 1)
9426 (delete-char 1)
9427 (insert "\n")
9428 (indent-to (+ margin vhdl-basic-offset))
9429 (vhdl-template-field "target signal" " <= ")
9430 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9431 (insert "\n")
9432 (indent-to (+ margin vhdl-basic-offset))
9433 (vhdl-template-field "waveform")
9434 (vhdl-insert-keyword " WHEN ")
9435 (vhdl-template-field "choices" ",")
9436 (insert "\n")
9437 (indent-to (+ margin vhdl-basic-offset))
9438 (while (and choices (vhdl-template-field "[waveform]" nil t))
9439 (vhdl-insert-keyword " WHEN ")
9440 (if (setq choices (vhdl-template-field "[choices]" "," t))
9441 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9442 (vhdl-insert-keyword "OTHERS")))
9443 (when choices
9444 (fixup-whitespace)
9445 (delete-char -2))
9446 (insert ";")
9447 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9448
9449 (defun vhdl-template-signal ()
9450 "Insert a signal declaration."
9451 (interactive)
9452 (let ((start (point))
9453 (in-arglist (vhdl-in-argument-list-p)))
9454 (vhdl-insert-keyword "SIGNAL ")
9455 (when (vhdl-template-field "names" nil t start (point))
9456 (insert " : ")
9457 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9458 (vhdl-template-field "type")
9459 (if in-arglist
9460 (progn (insert ";")
9461 (vhdl-comment-insert-inline))
9462 (let ((position (point)))
9463 (insert " := ")
9464 (unless (vhdl-template-field "[initialization]" nil t)
9465 (delete-region position (point)))
9466 (insert ";")
9467 (vhdl-comment-insert-inline))))))
9468
9469 (defun vhdl-template-subnature ()
9470 "Insert a subnature declaration."
9471 (interactive)
9472 (let ((start (point))
9473 position)
9474 (vhdl-insert-keyword "SUBNATURE ")
9475 (when (vhdl-template-field "name" nil t start (point))
9476 (vhdl-insert-keyword " IS ")
9477 (vhdl-template-field "nature" " (")
9478 (if (vhdl-template-field "[index range]" nil t)
9479 (insert ")")
9480 (delete-char -2))
9481 (setq position (point))
9482 (vhdl-insert-keyword " TOLERANCE ")
9483 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9484 nil t nil nil t))
9485 (delete-region position (point))
9486 (vhdl-insert-keyword " ACROSS ")
9487 (vhdl-template-field "string expression" nil nil nil nil t)
9488 (vhdl-insert-keyword " THROUGH"))
9489 (insert ";")
9490 (vhdl-comment-insert-inline))))
9491
9492 (defun vhdl-template-subprogram-body ()
9493 "Insert a subprogram body."
9494 (interactive)
9495 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9496 (vhdl-template-function-body)
9497 (vhdl-template-procedure-body)))
9498
9499 (defun vhdl-template-subprogram-decl ()
9500 "Insert a subprogram declaration."
9501 (interactive)
9502 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9503 (vhdl-template-function-decl)
9504 (vhdl-template-procedure-decl)))
9505
9506 (defun vhdl-template-subtype ()
9507 "Insert a subtype declaration."
9508 (interactive)
9509 (let ((start (point)))
9510 (vhdl-insert-keyword "SUBTYPE ")
9511 (when (vhdl-template-field "name" nil t start (point))
9512 (vhdl-insert-keyword " IS ")
9513 (vhdl-template-field "type" " ")
9514 (unless
9515 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9516 (delete-char -1))
9517 (insert ";")
9518 (vhdl-comment-insert-inline))))
9519
9520 (defun vhdl-template-terminal ()
9521 "Insert a terminal declaration."
9522 (interactive)
9523 (let ((start (point)))
9524 (vhdl-insert-keyword "TERMINAL ")
9525 (when (vhdl-template-field "names" nil t start (point))
9526 (insert " : ")
9527 (vhdl-template-field "nature")
9528 (insert ";")
9529 (vhdl-comment-insert-inline))))
9530
9531 (defun vhdl-template-type ()
9532 "Insert a type declaration."
9533 (interactive)
9534 (let ((start (point))
9535 name mid-pos end-pos)
9536 (vhdl-insert-keyword "TYPE ")
9537 (when (setq name (vhdl-template-field "name" nil t start (point)))
9538 (vhdl-insert-keyword " IS ")
9539 (let ((definition
9540 (upcase
9541 (or (vhdl-template-field
9542 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9543 ""))))
9544 (cond ((equal definition "")
9545 (delete-char -4)
9546 (insert ";"))
9547 ((equal definition "ARRAY")
9548 (delete-region (point) (progn (forward-word -1) (point)))
9549 (vhdl-template-array 'type t))
9550 ((equal definition "RECORD")
9551 (setq mid-pos (point-marker))
9552 (delete-region (point) (progn (forward-word -1) (point)))
9553 (vhdl-template-record 'type name t))
9554 ((equal definition "ACCESS")
9555 (insert " ")
9556 (vhdl-template-field "type" ";"))
9557 ((equal definition "FILE")
9558 (vhdl-insert-keyword " OF ")
9559 (vhdl-template-field "type" ";"))
9560 (t (insert ";")))
9561 (when mid-pos
9562 (setq end-pos (point-marker))
9563 (goto-char mid-pos)
9564 (end-of-line))
9565 (vhdl-comment-insert-inline)
9566 (when end-pos (goto-char end-pos))))))
9567
9568 (defun vhdl-template-use ()
9569 "Insert a use clause."
9570 (interactive)
9571 (let ((start (point)))
9572 (vhdl-prepare-search-1
9573 (vhdl-insert-keyword "USE ")
9574 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9575 (vhdl-insert-keyword "..ALL;")
9576 (backward-char 6)
9577 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9578 (forward-char 1)
9579 (vhdl-template-field "package name")
9580 (forward-char 5))))))
9581
9582 (defun vhdl-template-variable ()
9583 "Insert a variable declaration."
9584 (interactive)
9585 (let ((start (point))
9586 (in-arglist (vhdl-in-argument-list-p)))
9587 (vhdl-prepare-search-2
9588 (if (or (save-excursion
9589 (and (vhdl-re-search-backward
9590 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9591 nil t)
9592 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9593 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9594 (vhdl-insert-keyword "VARIABLE ")
9595 (vhdl-insert-keyword "SHARED VARIABLE ")))
9596 (when (vhdl-template-field "names" nil t start (point))
9597 (insert " : ")
9598 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9599 (vhdl-template-field "type")
9600 (if in-arglist
9601 (progn (insert ";")
9602 (vhdl-comment-insert-inline))
9603 (let ((position (point)))
9604 (insert " := ")
9605 (unless (vhdl-template-field "[initialization]" nil t)
9606 (delete-region position (point)))
9607 (insert ";")
9608 (vhdl-comment-insert-inline))))))
9609
9610 (defun vhdl-template-wait ()
9611 "Insert a wait statement."
9612 (interactive)
9613 (vhdl-insert-keyword "WAIT ")
9614 (unless (vhdl-template-field
9615 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9616 nil t)
9617 (delete-char -1))
9618 (insert ";"))
9619
9620 (defun vhdl-template-when ()
9621 "Indent correctly if within a case statement."
9622 (interactive)
9623 (let ((position (point))
9624 margin)
9625 (vhdl-prepare-search-2
9626 (if (and (= (current-column) (current-indentation))
9627 (vhdl-re-search-forward "\\<end\\>" nil t)
9628 (looking-at "\\s-*\\<case\\>"))
9629 (progn
9630 (setq margin (current-indentation))
9631 (goto-char position)
9632 (delete-horizontal-space)
9633 (indent-to (+ margin vhdl-basic-offset)))
9634 (goto-char position)))
9635 (vhdl-insert-keyword "WHEN ")))
9636
9637 (defun vhdl-template-while-loop ()
9638 "Insert a while loop."
9639 (interactive)
9640 (let* ((margin (current-indentation))
9641 (start (point))
9642 label)
9643 (if (not (eq vhdl-optional-labels 'all))
9644 (vhdl-insert-keyword "WHILE ")
9645 (vhdl-insert-keyword ": WHILE ")
9646 (goto-char start)
9647 (setq label (vhdl-template-field "[label]" nil t))
9648 (unless label (delete-char 2))
9649 (forward-word 1)
9650 (forward-char 1))
9651 (when vhdl-conditions-in-parenthesis (insert "("))
9652 (when (vhdl-template-field "condition" nil t start (point))
9653 (when vhdl-conditions-in-parenthesis (insert ")"))
9654 (vhdl-insert-keyword " LOOP\n\n")
9655 (indent-to margin)
9656 (vhdl-insert-keyword "END LOOP")
9657 (insert (if label (concat " " label ";") ";"))
9658 (forward-line -1)
9659 (indent-to (+ margin vhdl-basic-offset)))))
9660
9661 (defun vhdl-template-with ()
9662 "Insert a with statement (i.e. selected signal assignment)."
9663 (interactive)
9664 (vhdl-prepare-search-1
9665 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9666 (equal ";" (match-string 1)))
9667 (vhdl-template-selected-signal-asst)
9668 (vhdl-insert-keyword "WITH "))))
9669
9670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9671 ;; Special templates
9672
9673 (defun vhdl-template-clocked-wait ()
9674 "Insert a wait statement for rising/falling clock edge."
9675 (interactive)
9676 (let ((start (point))
9677 clock)
9678 (vhdl-insert-keyword "WAIT UNTIL ")
9679 (when (setq clock
9680 (or (and (not (equal "" vhdl-clock-name))
9681 (progn (insert vhdl-clock-name) vhdl-clock-name))
9682 (vhdl-template-field "clock name" nil t start (point))))
9683 (insert "'event")
9684 (vhdl-insert-keyword " AND ")
9685 (insert clock)
9686 (insert
9687 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9688 (vhdl-comment-insert-inline
9689 (concat (if vhdl-clock-rising-edge "rising" "falling")
9690 " clock edge")))))
9691
9692 (defun vhdl-template-seq-process (clock reset)
9693 "Insert a template for the body of a sequential process."
9694 (let ((margin (current-indentation))
9695 position)
9696 (vhdl-insert-keyword "IF ")
9697 (when (eq vhdl-reset-kind 'async)
9698 (insert reset " = "
9699 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9700 (vhdl-insert-keyword " THEN")
9701 (vhdl-comment-insert-inline
9702 (concat "asynchronous reset (active "
9703 (if vhdl-reset-active-high "high" "low") ")"))
9704 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9705 (setq position (point))
9706 (insert "\n") (indent-to margin)
9707 (vhdl-insert-keyword "ELSIF "))
9708 (if (eq vhdl-clock-edge-condition 'function)
9709 (insert (if vhdl-clock-rising-edge "rising" "falling")
9710 "_edge(" clock ")")
9711 (insert clock "'event")
9712 (vhdl-insert-keyword " AND ")
9713 (insert clock " = "
9714 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9715 (vhdl-insert-keyword " THEN")
9716 (vhdl-comment-insert-inline
9717 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9718 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9719 (when (eq vhdl-reset-kind 'sync)
9720 (vhdl-insert-keyword "IF ")
9721 (setq reset (or (and (not (equal "" vhdl-reset-name))
9722 (progn (insert vhdl-reset-name) vhdl-reset-name))
9723 (vhdl-template-field "reset name") "<reset>"))
9724 (insert " = "
9725 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9726 (vhdl-insert-keyword " THEN")
9727 (vhdl-comment-insert-inline
9728 (concat "synchronous reset (active "
9729 (if vhdl-reset-active-high "high" "low") ")"))
9730 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9731 (setq position (point))
9732 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9733 (vhdl-insert-keyword "ELSE")
9734 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9735 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9736 (vhdl-insert-keyword "END IF;"))
9737 (when (eq vhdl-reset-kind 'none)
9738 (setq position (point)))
9739 (insert "\n") (indent-to margin)
9740 (vhdl-insert-keyword "END IF;")
9741 (goto-char position)
9742 reset))
9743
9744 (defun vhdl-template-standard-package (library package)
9745 "Insert specification of a standard package. Include a library
9746 specification, if not already there."
9747 (let ((margin (current-indentation)))
9748 (unless (equal library "std")
9749 (unless (or (save-excursion
9750 (vhdl-prepare-search-1
9751 (and (not (bobp))
9752 (re-search-backward
9753 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9754 library "\\|end\\)\\>") nil t)
9755 (match-string 2))))
9756 (equal (downcase library) "work"))
9757 (vhdl-insert-keyword "LIBRARY ")
9758 (insert library ";")
9759 (when package
9760 (insert "\n")
9761 (indent-to margin)))
9762 (when package
9763 (vhdl-insert-keyword "USE ")
9764 (insert library "." package)
9765 (vhdl-insert-keyword ".ALL;")))))
9766
9767 (defun vhdl-template-package-math-complex ()
9768 "Insert specification of `math_complex' package."
9769 (interactive)
9770 (vhdl-template-standard-package "ieee" "math_complex"))
9771
9772 (defun vhdl-template-package-math-real ()
9773 "Insert specification of `math_real' package."
9774 (interactive)
9775 (vhdl-template-standard-package "ieee" "math_real"))
9776
9777 (defun vhdl-template-package-numeric-bit ()
9778 "Insert specification of `numeric_bit' package."
9779 (interactive)
9780 (vhdl-template-standard-package "ieee" "numeric_bit"))
9781
9782 (defun vhdl-template-package-numeric-std ()
9783 "Insert specification of `numeric_std' package."
9784 (interactive)
9785 (vhdl-template-standard-package "ieee" "numeric_std"))
9786
9787 (defun vhdl-template-package-std-logic-1164 ()
9788 "Insert specification of `std_logic_1164' package."
9789 (interactive)
9790 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9791
9792 (defun vhdl-template-package-std-logic-arith ()
9793 "Insert specification of `std_logic_arith' package."
9794 (interactive)
9795 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9796
9797 (defun vhdl-template-package-std-logic-misc ()
9798 "Insert specification of `std_logic_misc' package."
9799 (interactive)
9800 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9801
9802 (defun vhdl-template-package-std-logic-signed ()
9803 "Insert specification of `std_logic_signed' package."
9804 (interactive)
9805 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9806
9807 (defun vhdl-template-package-std-logic-textio ()
9808 "Insert specification of `std_logic_textio' package."
9809 (interactive)
9810 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9811
9812 (defun vhdl-template-package-std-logic-unsigned ()
9813 "Insert specification of `std_logic_unsigned' package."
9814 (interactive)
9815 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9816
9817 (defun vhdl-template-package-textio ()
9818 "Insert specification of `textio' package."
9819 (interactive)
9820 (vhdl-template-standard-package "std" "textio"))
9821
9822 (defun vhdl-template-directive (directive)
9823 "Insert directive."
9824 (unless (= (current-indentation) (current-column))
9825 (delete-horizontal-space)
9826 (insert " "))
9827 (insert "-- pragma " directive))
9828
9829 (defun vhdl-template-directive-translate-on ()
9830 "Insert directive 'translate_on'."
9831 (interactive)
9832 (vhdl-template-directive "translate_on"))
9833
9834 (defun vhdl-template-directive-translate-off ()
9835 "Insert directive 'translate_off'."
9836 (interactive)
9837 (vhdl-template-directive "translate_off"))
9838
9839 (defun vhdl-template-directive-synthesis-on ()
9840 "Insert directive 'synthesis_on'."
9841 (interactive)
9842 (vhdl-template-directive "synthesis_on"))
9843
9844 (defun vhdl-template-directive-synthesis-off ()
9845 "Insert directive 'synthesis_off'."
9846 (interactive)
9847 (vhdl-template-directive "synthesis_off"))
9848
9849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9850 ;; Header and footer templates
9851
9852 (defun vhdl-template-header (&optional file-title)
9853 "Insert a VHDL file header."
9854 (interactive)
9855 (unless (equal vhdl-file-header "")
9856 (let (pos)
9857 (save-excursion
9858 (goto-char (point-min))
9859 (vhdl-insert-string-or-file vhdl-file-header)
9860 (setq pos (point-marker)))
9861 (vhdl-template-replace-header-keywords
9862 (point-min-marker) pos file-title))))
9863
9864 (defun vhdl-template-footer ()
9865 "Insert a VHDL file footer."
9866 (interactive)
9867 (unless (equal vhdl-file-footer "")
9868 (let (pos)
9869 (save-excursion
9870 (goto-char (point-max))
9871 (setq pos (point-marker))
9872 (vhdl-insert-string-or-file vhdl-file-footer)
9873 (unless (= (preceding-char) ?\n)
9874 (insert "\n")))
9875 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9876
9877 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9878 is-model)
9879 "Replace keywords in header and footer."
9880 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9881 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9882 pos)
9883 (vhdl-prepare-search-2
9884 (save-excursion
9885 (goto-char beg)
9886 (while (search-forward "<projectdesc>" end t)
9887 (replace-match project-desc t t))
9888 (goto-char beg)
9889 (while (search-forward "<filename>" end t)
9890 (replace-match (buffer-name) t t))
9891 (goto-char beg)
9892 (while (search-forward "<copyright>" end t)
9893 (replace-match vhdl-copyright-string t t))
9894 (goto-char beg)
9895 (while (search-forward "<author>" end t)
9896 (replace-match "" t t)
9897 (insert (user-full-name))
9898 (when user-mail-address (insert " <" user-mail-address ">")))
9899 (goto-char beg)
9900 (while (search-forward "<login>" end t)
9901 (replace-match (user-login-name) t t))
9902 (goto-char beg)
9903 (while (search-forward "<project>" end t)
9904 (replace-match project-title t t))
9905 (goto-char beg)
9906 (while (search-forward "<company>" end t)
9907 (replace-match vhdl-company-name t t))
9908 (goto-char beg)
9909 (while (search-forward "<platform>" end t)
9910 (replace-match vhdl-platform-spec t t))
9911 (goto-char beg)
9912 (while (search-forward "<standard>" end t)
9913 (replace-match
9914 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9915 ((vhdl-standard-p '93) "'93"))
9916 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9917 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9918 (goto-char beg)
9919 ;; Replace <RCS> with $, so that RCS for the source is
9920 ;; not over-enthusiastic with replacements
9921 (while (search-forward "<RCS>" end t)
9922 (replace-match "$" nil t))
9923 (goto-char beg)
9924 (while (search-forward "<date>" end t)
9925 (replace-match "" t t)
9926 (vhdl-template-insert-date))
9927 (goto-char beg)
9928 (while (search-forward "<year>" end t)
9929 (replace-match (format-time-string "%Y" nil) t t))
9930 (goto-char beg)
9931 (when file-title
9932 (while (search-forward "<title string>" end t)
9933 (replace-match file-title t t))
9934 (goto-char beg))
9935 (let (string)
9936 (while
9937 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9938 (setq string (read-string (concat (match-string 1) ": ")))
9939 (replace-match string t t)))
9940 (goto-char beg)
9941 (when (and (not is-model) (search-forward "<cursor>" end t))
9942 (replace-match "" t t)
9943 (setq pos (point))))
9944 (when pos (goto-char pos))
9945 (unless is-model
9946 (when (or (not project-title) (equal project-title ""))
9947 (message "You can specify a project title in user option `vhdl-project-alist'"))
9948 (when (or (not project-desc) (equal project-desc ""))
9949 (message "You can specify a project description in user option `vhdl-project-alist'"))
9950 (when (equal vhdl-platform-spec "")
9951 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9952 (when (equal vhdl-company-name "")
9953 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9954
9955 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9956 ;; Comment templates and functions
9957
9958 (defun vhdl-comment-indent ()
9959 "Indent comments."
9960 (let* ((position (point))
9961 (col
9962 (progn
9963 (forward-line -1)
9964 (if (re-search-forward "--" position t)
9965 (- (current-column) 2) ; existing comment at bol stays there
9966 (goto-char position)
9967 (skip-chars-backward " \t")
9968 (max comment-column ; else indent to comment column
9969 (1+ (current-column))))))) ; except leave at least one space
9970 (goto-char position)
9971 col))
9972
9973 (defun vhdl-comment-insert ()
9974 "Start a comment at the end of the line.
9975 If on line with code, indent at least `comment-column'.
9976 If starting after end-comment-column, start a new line."
9977 (interactive)
9978 (when (> (current-column) end-comment-column) (newline-and-indent))
9979 (if (or (looking-at "\\s-*$") ; end of line
9980 (and (not unread-command-events) ; called with key binding or menu
9981 (not (end-of-line))))
9982 (let (margin)
9983 (while (= (preceding-char) ?-) (delete-char -1))
9984 (setq margin (current-column))
9985 (delete-horizontal-space)
9986 (if (bolp)
9987 (progn (indent-to margin) (insert "--"))
9988 (insert " ")
9989 (indent-to comment-column)
9990 (insert "--"))
9991 (if (not unread-command-events) (insert " ")))
9992 ;; else code following current point implies commenting out code
9993 (let (next-input code)
9994 (while (= (preceding-char) ?-) (delete-char -2))
9995 (while (= (setq next-input (read-char)) 13) ; CR
9996 (insert "--") ; or have a space after it?
9997 (forward-char -2)
9998 (forward-line 1)
9999 (message "Enter CR if commenting out a line of code.")
10000 (setq code t))
10001 (unless code
10002 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10003 (setq unread-command-events
10004 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10005
10006 (defun vhdl-comment-display (&optional line-exists)
10007 "Add 2 comment lines at the current indent, making a display comment."
10008 (interactive)
10009 (let ((margin (current-indentation)))
10010 (unless line-exists (vhdl-comment-display-line))
10011 (insert "\n") (indent-to margin)
10012 (insert "\n") (indent-to margin)
10013 (vhdl-comment-display-line)
10014 (end-of-line -0)
10015 (insert "-- ")))
10016
10017 (defun vhdl-comment-display-line ()
10018 "Displays one line of dashes."
10019 (interactive)
10020 (while (= (preceding-char) ?-) (delete-char -2))
10021 (let* ((col (current-column))
10022 (len (- end-comment-column col)))
10023 (insert-char ?- len)))
10024
10025 (defun vhdl-comment-append-inline ()
10026 "Append empty inline comment to current line."
10027 (interactive)
10028 (end-of-line)
10029 (delete-horizontal-space)
10030 (insert " ")
10031 (indent-to comment-column)
10032 (insert "-- "))
10033
10034 (defun vhdl-comment-insert-inline (&optional string always-insert)
10035 "Insert inline comment."
10036 (when (or (and string (or vhdl-self-insert-comments always-insert))
10037 (and (not string) vhdl-prompt-for-comments))
10038 (let ((position (point)))
10039 (insert " ")
10040 (indent-to comment-column)
10041 (insert "-- ")
10042 (if (not (or (and string (progn (insert string) t))
10043 (vhdl-template-field "[comment]" nil t)))
10044 (delete-region position (point))
10045 (while (= (preceding-char) ?\ ) (delete-char -1))
10046 ;; (when (> (current-column) end-comment-column)
10047 ;; (setq position (point-marker))
10048 ;; (re-search-backward "-- ")
10049 ;; (insert "\n")
10050 ;; (indent-to comment-column)
10051 ;; (goto-char position))
10052 ))))
10053
10054 (defun vhdl-comment-block ()
10055 "Insert comment for code block."
10056 (when vhdl-prompt-for-comments
10057 (let ((final-pos (point-marker)))
10058 (vhdl-prepare-search-2
10059 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10060 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10061 (let (margin)
10062 (back-to-indentation)
10063 (setq margin (current-column))
10064 (end-of-line -0)
10065 (if (bobp)
10066 (progn (insert "\n") (forward-line -1))
10067 (insert "\n"))
10068 (indent-to margin)
10069 (insert "-- purpose: ")
10070 (unless (vhdl-template-field "[description]" nil t)
10071 (vhdl-line-kill-entire)))))
10072 (goto-char final-pos))))
10073
10074 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10075 "Comment out region if not commented out, uncomment otherwise."
10076 (interactive "r\nP")
10077 (save-excursion
10078 (goto-char (1- end))
10079 (end-of-line)
10080 (setq end (point-marker))
10081 (goto-char beg)
10082 (beginning-of-line)
10083 (setq beg (point))
10084 (if (looking-at comment-start)
10085 (comment-region beg end '(4))
10086 (comment-region beg end))))
10087
10088 (defun vhdl-comment-uncomment-line (&optional arg)
10089 "Comment out line if not commented out, uncomment otherwise."
10090 (interactive "p")
10091 (save-excursion
10092 (beginning-of-line)
10093 (let ((position (point)))
10094 (forward-line (or arg 1))
10095 (vhdl-comment-uncomment-region position (point)))))
10096
10097 (defun vhdl-comment-kill-region (beg end)
10098 "Kill comments in region."
10099 (interactive "r")
10100 (save-excursion
10101 (goto-char end)
10102 (setq end (point-marker))
10103 (goto-char beg)
10104 (beginning-of-line)
10105 (while (< (point) end)
10106 (if (looking-at "^\\(\\s-*--.*\n\\)")
10107 (progn (delete-region (match-beginning 1) (match-end 1)))
10108 (beginning-of-line 2)))))
10109
10110 (defun vhdl-comment-kill-inline-region (beg end)
10111 "Kill inline comments in region."
10112 (interactive "r")
10113 (save-excursion
10114 (goto-char end)
10115 (setq end (point-marker))
10116 (goto-char beg)
10117 (beginning-of-line)
10118 (while (< (point) end)
10119 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10120 (delete-region (match-beginning 1) (match-end 1)))
10121 (beginning-of-line 2))))
10122
10123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10124 ;; Subtemplates
10125
10126 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10127 "Insert a begin ... end pair with optional name after the end.
10128 Point is left between them."
10129 (let (position)
10130 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10131 (indent-to margin)
10132 (vhdl-insert-keyword "BEGIN")
10133 (when (and (or construct name) vhdl-self-insert-comments)
10134 (insert " --")
10135 (when construct (insert " ") (vhdl-insert-keyword construct))
10136 (when name (insert " " name)))
10137 (insert "\n")
10138 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10139 (indent-to (+ margin vhdl-basic-offset))
10140 (setq position (point))
10141 (insert "\n")
10142 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10143 (indent-to margin)
10144 (vhdl-insert-keyword "END")
10145 (when construct (insert " ") (vhdl-insert-keyword construct))
10146 (insert (if name (concat " " name) "") ";")
10147 (goto-char position)))
10148
10149 (defun vhdl-template-argument-list (&optional is-function)
10150 "Read from user a procedure or function argument list."
10151 (insert " (")
10152 (let ((margin (current-column))
10153 (start (point))
10154 (end-pos (point))
10155 not-empty interface semicolon-pos)
10156 (unless vhdl-argument-list-indent
10157 (setq margin (+ (current-indentation) vhdl-basic-offset))
10158 (insert "\n")
10159 (indent-to margin))
10160 (setq interface (vhdl-template-field
10161 (concat "[CONSTANT | SIGNAL"
10162 (unless is-function " | VARIABLE") "]") " " t))
10163 (while (vhdl-template-field "[names]" nil t)
10164 (setq not-empty t)
10165 (insert " : ")
10166 (unless is-function
10167 (if (and interface (equal (upcase interface) "CONSTANT"))
10168 (vhdl-insert-keyword "IN ")
10169 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10170 (vhdl-template-field "type")
10171 (setq semicolon-pos (point))
10172 (insert ";")
10173 (vhdl-comment-insert-inline)
10174 (setq end-pos (point))
10175 (insert "\n")
10176 (indent-to margin)
10177 (setq interface (vhdl-template-field
10178 (concat "[CONSTANT | SIGNAL"
10179 (unless is-function " | VARIABLE") "]") " " t)))
10180 (delete-region end-pos (point))
10181 (when semicolon-pos (goto-char semicolon-pos))
10182 (if not-empty
10183 (progn (delete-char 1) (insert ")"))
10184 (delete-char -2))))
10185
10186 (defun vhdl-template-generic-list (optional &optional no-value)
10187 "Read from user a generic spec argument list."
10188 (let (margin
10189 (start (point)))
10190 (vhdl-insert-keyword "GENERIC (")
10191 (setq margin (current-column))
10192 (unless vhdl-argument-list-indent
10193 (let ((position (point)))
10194 (back-to-indentation)
10195 (setq margin (+ (current-column) vhdl-basic-offset))
10196 (goto-char position)
10197 (insert "\n")
10198 (indent-to margin)))
10199 (let ((vhdl-generics (vhdl-template-field
10200 (concat (and optional "[") "name"
10201 (and no-value "s") (and optional "]"))
10202 nil optional)))
10203 (if (not vhdl-generics)
10204 (if optional
10205 (progn (vhdl-line-kill-entire) (end-of-line -0)
10206 (unless vhdl-argument-list-indent
10207 (vhdl-line-kill-entire) (end-of-line -0)))
10208 (vhdl-template-undo start (point))
10209 nil )
10210 (insert " : ")
10211 (let (semicolon-pos end-pos)
10212 (while vhdl-generics
10213 (vhdl-template-field "type")
10214 (if no-value
10215 (progn (setq semicolon-pos (point))
10216 (insert ";"))
10217 (insert " := ")
10218 (unless (vhdl-template-field "[value]" nil t)
10219 (delete-char -4))
10220 (setq semicolon-pos (point))
10221 (insert ";"))
10222 (vhdl-comment-insert-inline)
10223 (setq end-pos (point))
10224 (insert "\n")
10225 (indent-to margin)
10226 (setq vhdl-generics (vhdl-template-field
10227 (concat "[name" (and no-value "s") "]")
10228 " : " t)))
10229 (delete-region end-pos (point))
10230 (goto-char semicolon-pos)
10231 (insert ")")
10232 (end-of-line)
10233 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10234 t)))))
10235
10236 (defun vhdl-template-port-list (optional)
10237 "Read from user a port spec argument list."
10238 (let ((start (point))
10239 margin vhdl-ports object)
10240 (vhdl-insert-keyword "PORT (")
10241 (setq margin (current-column))
10242 (unless vhdl-argument-list-indent
10243 (let ((position (point)))
10244 (back-to-indentation)
10245 (setq margin (+ (current-column) vhdl-basic-offset))
10246 (goto-char position)
10247 (insert "\n")
10248 (indent-to margin)))
10249 (when (vhdl-standard-p 'ams)
10250 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10251 " " t)))
10252 (setq vhdl-ports (vhdl-template-field
10253 (concat (and optional "[") "names" (and optional "]"))
10254 nil optional))
10255 (if (not vhdl-ports)
10256 (if optional
10257 (progn (vhdl-line-kill-entire) (end-of-line -0)
10258 (unless vhdl-argument-list-indent
10259 (vhdl-line-kill-entire) (end-of-line -0)))
10260 (vhdl-template-undo start (point))
10261 nil)
10262 (insert " : ")
10263 (let (semicolon-pos end-pos)
10264 (while vhdl-ports
10265 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10266 (vhdl-template-field "IN | OUT | INOUT" " "))
10267 ((equal "QUANTITY" (upcase object))
10268 (vhdl-template-field "[IN | OUT]" " " t)))
10269 (vhdl-template-field
10270 (if (and object (equal "TERMINAL" (upcase object)))
10271 "nature" "type"))
10272 (setq semicolon-pos (point))
10273 (insert ";")
10274 (vhdl-comment-insert-inline)
10275 (setq end-pos (point))
10276 (insert "\n")
10277 (indent-to margin)
10278 (when (vhdl-standard-p 'ams)
10279 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10280 " " t)))
10281 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10282 (delete-region end-pos (point))
10283 (goto-char semicolon-pos)
10284 (insert ")")
10285 (end-of-line)
10286 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10287 t))))
10288
10289 (defun vhdl-template-generate-body (margin label)
10290 "Insert body for generate template."
10291 (vhdl-insert-keyword " GENERATE")
10292 ; (if (not (vhdl-standard-p '87))
10293 ; (vhdl-template-begin-end "GENERATE" label margin)
10294 (insert "\n\n")
10295 (indent-to margin)
10296 (vhdl-insert-keyword "END GENERATE ")
10297 (insert label ";")
10298 (end-of-line 0)
10299 (indent-to (+ margin vhdl-basic-offset)))
10300
10301 (defun vhdl-template-insert-date ()
10302 "Insert date in appropriate format."
10303 (interactive)
10304 (insert
10305 (cond
10306 ;; 'american, 'european, 'scientific kept for backward compatibility
10307 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10308 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10309 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10310 (t (format-time-string vhdl-date-format nil)))))
10311
10312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10313 ;; Help functions
10314
10315 (defun vhdl-electric-space (count)
10316 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10317 if in comment and past end-comment-column."
10318 (interactive "p")
10319 (cond ((vhdl-in-comment-p)
10320 (self-insert-command count)
10321 (cond ((>= (current-column) (+ 2 end-comment-column))
10322 (backward-char 1)
10323 (skip-chars-backward "^ \t\n")
10324 (indent-new-comment-line)
10325 (skip-chars-forward "^ \t\n")
10326 (forward-char 1))
10327 ((>= (current-column) end-comment-column)
10328 (indent-new-comment-line))
10329 (t nil)))
10330 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10331 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10332 (vhdl-prepare-search-1
10333 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10334 (self-insert-command count))
10335 (t (self-insert-command count))))
10336
10337 (defun vhdl-template-field (prompt &optional follow-string optional
10338 begin end is-string default)
10339 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10340 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10341 an empty string is inserted, return nil and call `vhdl-template-undo' for
10342 the region between BEGIN and END. IS-STRING indicates whether a string
10343 with double-quotes is to be inserted. DEFAULT specifies a default string."
10344 (let ((position (point))
10345 string)
10346 (insert "<" prompt ">")
10347 (setq string
10348 (condition-case ()
10349 (read-from-minibuffer (concat prompt ": ")
10350 (or (and is-string '("\"\"" . 2)) default)
10351 vhdl-minibuffer-local-map)
10352 (quit (if (and optional begin end)
10353 (progn (beep) "")
10354 (keyboard-quit)))))
10355 (when (or (not (equal string "")) optional)
10356 (delete-region position (point)))
10357 (when (and (equal string "") optional begin end)
10358 (vhdl-template-undo begin end)
10359 (message "Template aborted"))
10360 (unless (equal string "")
10361 (insert string)
10362 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10363 vhdl-keywords-regexp)
10364 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10365 vhdl-types-regexp)
10366 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10367 (concat "'" vhdl-attributes-regexp))
10368 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10369 vhdl-enum-values-regexp))
10370 (when (or (not (equal string "")) (not optional))
10371 (insert (or follow-string "")))
10372 (if (equal string "") nil string)))
10373
10374 (defun vhdl-decision-query (string prompt &optional optional)
10375 "Query a decision from the user."
10376 (let ((start (point)))
10377 (when string (vhdl-insert-keyword (concat string " ")))
10378 (message "%s" (or prompt ""))
10379 (let ((char (read-char)))
10380 (delete-region start (point))
10381 (if (and optional (eq char ?\r))
10382 (progn (insert " ")
10383 (unexpand-abbrev)
10384 (throw 'abort "ERROR: Template aborted"))
10385 char))))
10386
10387 (defun vhdl-insert-keyword (keyword)
10388 "Insert KEYWORD and adjust case."
10389 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10390
10391 (defun vhdl-case-keyword (keyword)
10392 "Adjust case of KEYWORD."
10393 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10394
10395 (defun vhdl-case-word (num)
10396 "Adjust case of following NUM words."
10397 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10398
10399 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10400 "If preceeding character is part of a word or a paren then hippie-expand,
10401 else insert tab (used for word completion in VHDL minibuffer)."
10402 (interactive "P")
10403 (cond
10404 ;; expand word
10405 ((= (char-syntax (preceding-char)) ?w)
10406 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10407 (case-replace nil)
10408 (hippie-expand-only-buffers
10409 (or (and (boundp 'hippie-expand-only-buffers)
10410 hippie-expand-only-buffers)
10411 '(vhdl-mode))))
10412 (vhdl-expand-abbrev prefix-arg)))
10413 ;; expand parenthesis
10414 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10415 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10416 (case-replace nil))
10417 (vhdl-expand-paren prefix-arg)))
10418 ;; insert tab
10419 (t (insert-tab))))
10420
10421 (defun vhdl-template-search-prompt ()
10422 "Search for left out template prompts and query again."
10423 (interactive)
10424 (vhdl-prepare-search-2
10425 (when (or (re-search-forward
10426 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10427 (re-search-backward
10428 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10429 (let ((string (match-string 1)))
10430 (replace-match "")
10431 (vhdl-template-field string)))))
10432
10433 (defun vhdl-template-undo (begin end)
10434 "Undo aborted template by deleting region and unexpanding the keyword."
10435 (cond (vhdl-template-invoked-by-hook
10436 (goto-char end)
10437 (insert " ")
10438 (delete-region begin end)
10439 (unexpand-abbrev))
10440 (t (delete-region begin end))))
10441
10442 (defun vhdl-insert-string-or-file (string)
10443 "Insert STRING or file contents if STRING is an existing file name."
10444 (unless (equal string "")
10445 (let ((file-name
10446 (progn (string-match "^\\([^\n]+\\)" string)
10447 (vhdl-resolve-env-variable (match-string 1 string)))))
10448 (if (file-exists-p file-name)
10449 (forward-char (cadr (insert-file-contents file-name)))
10450 (insert string)))))
10451
10452 (defun vhdl-beginning-of-block ()
10453 "Move cursor to the beginning of the enclosing block."
10454 (let (pos)
10455 (save-excursion
10456 (beginning-of-line)
10457 ;; search backward for block beginning or end
10458 (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))
10459 ;; not consider subprogram declarations
10460 (or (and (match-string 5)
10461 (save-match-data
10462 (save-excursion
10463 (goto-char (match-end 5))
10464 (forward-word 1)
10465 (vhdl-forward-syntactic-ws)
10466 (when (looking-at "(")
10467 (forward-sexp))
10468 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10469 (match-string 1)))
10470 ;; not consider configuration specifications
10471 (and (match-string 6)
10472 (save-match-data
10473 (save-excursion
10474 (vhdl-end-of-block)
10475 (beginning-of-line)
10476 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10477 (match-string 2))
10478 ;; skip subblock if block end found
10479 (vhdl-beginning-of-block)))
10480 (when pos (goto-char pos))))
10481
10482 (defun vhdl-end-of-block ()
10483 "Move cursor to the end of the enclosing block."
10484 (let (pos)
10485 (save-excursion
10486 (end-of-line)
10487 ;; search forward for block beginning or end
10488 (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))
10489 ;; not consider subprogram declarations
10490 (or (and (match-string 5)
10491 (save-match-data
10492 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10493 (match-string 1)))
10494 ;; not consider configuration specifications
10495 (and (match-string 6)
10496 (save-match-data
10497 (save-excursion
10498 (vhdl-end-of-block)
10499 (beginning-of-line)
10500 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10501 (not (match-string 2)))
10502 ;; skip subblock if block beginning found
10503 (vhdl-end-of-block)))
10504 (when pos (goto-char pos))))
10505
10506 (defun vhdl-sequential-statement-p ()
10507 "Check if point is within sequential statement part."
10508 (let ((start (point)))
10509 (save-excursion
10510 (vhdl-prepare-search-2
10511 ;; is sequential statement if ...
10512 (and (re-search-backward "^\\s-*begin\\>" nil t)
10513 ;; ... point is between "begin" and "end" of ...
10514 (progn (vhdl-end-of-block)
10515 (< start (point)))
10516 ;; ... a sequential block
10517 (progn (vhdl-beginning-of-block)
10518 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10519
10520 (defun vhdl-in-argument-list-p ()
10521 "Check if within an argument list."
10522 (save-excursion
10523 (vhdl-prepare-search-2
10524 (or (string-match "arglist"
10525 (format "%s" (caar (vhdl-get-syntactic-context))))
10526 (progn (beginning-of-line)
10527 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10528
10529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10530 ;; Abbrev hooks
10531
10532 (defun vhdl-hooked-abbrev (func)
10533 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10534 but not if inside a comment or quote."
10535 (if (or (vhdl-in-literal)
10536 (save-excursion
10537 (forward-word -1)
10538 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10539 (progn
10540 (insert " ")
10541 (unexpand-abbrev)
10542 (delete-char -1))
10543 (if (not vhdl-electric-mode)
10544 (progn
10545 (insert " ")
10546 (unexpand-abbrev)
10547 (backward-word 1)
10548 (vhdl-case-word 1)
10549 (delete-char 1))
10550 (let ((invoke-char last-command-event)
10551 (abbrev-mode -1)
10552 (vhdl-template-invoked-by-hook t))
10553 (let ((caught (catch 'abort
10554 (funcall func))))
10555 (when (stringp caught) (message "%s" caught)))
10556 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10557 ;; delete CR which is still in event queue
10558 (if (fboundp 'enqueue-eval-event)
10559 (enqueue-eval-event 'delete-char -1)
10560 (setq unread-command-events ; push back a delete char
10561 (list (vhdl-character-to-event ?\177))))))))
10562
10563 (defun vhdl-template-alias-hook ()
10564 (vhdl-hooked-abbrev 'vhdl-template-alias))
10565 (defun vhdl-template-architecture-hook ()
10566 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10567 (defun vhdl-template-assert-hook ()
10568 (vhdl-hooked-abbrev 'vhdl-template-assert))
10569 (defun vhdl-template-attribute-hook ()
10570 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10571 (defun vhdl-template-block-hook ()
10572 (vhdl-hooked-abbrev 'vhdl-template-block))
10573 (defun vhdl-template-break-hook ()
10574 (vhdl-hooked-abbrev 'vhdl-template-break))
10575 (defun vhdl-template-case-hook ()
10576 (vhdl-hooked-abbrev 'vhdl-template-case))
10577 (defun vhdl-template-component-hook ()
10578 (vhdl-hooked-abbrev 'vhdl-template-component))
10579 (defun vhdl-template-instance-hook ()
10580 (vhdl-hooked-abbrev 'vhdl-template-instance))
10581 (defun vhdl-template-conditional-signal-asst-hook ()
10582 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10583 (defun vhdl-template-configuration-hook ()
10584 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10585 (defun vhdl-template-constant-hook ()
10586 (vhdl-hooked-abbrev 'vhdl-template-constant))
10587 (defun vhdl-template-disconnect-hook ()
10588 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10589 (defun vhdl-template-display-comment-hook ()
10590 (vhdl-hooked-abbrev 'vhdl-comment-display))
10591 (defun vhdl-template-else-hook ()
10592 (vhdl-hooked-abbrev 'vhdl-template-else))
10593 (defun vhdl-template-elsif-hook ()
10594 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10595 (defun vhdl-template-entity-hook ()
10596 (vhdl-hooked-abbrev 'vhdl-template-entity))
10597 (defun vhdl-template-exit-hook ()
10598 (vhdl-hooked-abbrev 'vhdl-template-exit))
10599 (defun vhdl-template-file-hook ()
10600 (vhdl-hooked-abbrev 'vhdl-template-file))
10601 (defun vhdl-template-for-hook ()
10602 (vhdl-hooked-abbrev 'vhdl-template-for))
10603 (defun vhdl-template-function-hook ()
10604 (vhdl-hooked-abbrev 'vhdl-template-function))
10605 (defun vhdl-template-generic-hook ()
10606 (vhdl-hooked-abbrev 'vhdl-template-generic))
10607 (defun vhdl-template-group-hook ()
10608 (vhdl-hooked-abbrev 'vhdl-template-group))
10609 (defun vhdl-template-library-hook ()
10610 (vhdl-hooked-abbrev 'vhdl-template-library))
10611 (defun vhdl-template-limit-hook ()
10612 (vhdl-hooked-abbrev 'vhdl-template-limit))
10613 (defun vhdl-template-if-hook ()
10614 (vhdl-hooked-abbrev 'vhdl-template-if))
10615 (defun vhdl-template-bare-loop-hook ()
10616 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10617 (defun vhdl-template-map-hook ()
10618 (vhdl-hooked-abbrev 'vhdl-template-map))
10619 (defun vhdl-template-nature-hook ()
10620 (vhdl-hooked-abbrev 'vhdl-template-nature))
10621 (defun vhdl-template-next-hook ()
10622 (vhdl-hooked-abbrev 'vhdl-template-next))
10623 (defun vhdl-template-others-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-others))
10625 (defun vhdl-template-package-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-package))
10627 (defun vhdl-template-port-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-port))
10629 (defun vhdl-template-procedural-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10631 (defun vhdl-template-procedure-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10633 (defun vhdl-template-process-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-process))
10635 (defun vhdl-template-quantity-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10637 (defun vhdl-template-report-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-report))
10639 (defun vhdl-template-return-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-return))
10641 (defun vhdl-template-selected-signal-asst-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10643 (defun vhdl-template-signal-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-signal))
10645 (defun vhdl-template-subnature-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10647 (defun vhdl-template-subtype-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10649 (defun vhdl-template-terminal-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10651 (defun vhdl-template-type-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-type))
10653 (defun vhdl-template-use-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-use))
10655 (defun vhdl-template-variable-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-variable))
10657 (defun vhdl-template-wait-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-wait))
10659 (defun vhdl-template-when-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-when))
10661 (defun vhdl-template-while-loop-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10663 (defun vhdl-template-with-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-with))
10665 (defun vhdl-template-and-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-and))
10667 (defun vhdl-template-or-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-or))
10669 (defun vhdl-template-nand-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-nand))
10671 (defun vhdl-template-nor-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-nor))
10673 (defun vhdl-template-xor-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-xor))
10675 (defun vhdl-template-xnor-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10677 (defun vhdl-template-not-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-not))
10679
10680 (defun vhdl-template-default-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-default))
10682 (defun vhdl-template-default-indent-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10684
10685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10686 ;; Template insertion from completion list
10687
10688 (defun vhdl-template-insert-construct (name)
10689 "Insert the built-in construct template with NAME."
10690 (interactive
10691 (list (let ((completion-ignore-case t))
10692 (completing-read "Construct name: "
10693 vhdl-template-construct-alist nil t))))
10694 (vhdl-template-insert-fun
10695 (cadr (assoc name vhdl-template-construct-alist))))
10696
10697 (defun vhdl-template-insert-package (name)
10698 "Insert the built-in package template with NAME."
10699 (interactive
10700 (list (let ((completion-ignore-case t))
10701 (completing-read "Package name: "
10702 vhdl-template-package-alist nil t))))
10703 (vhdl-template-insert-fun
10704 (cadr (assoc name vhdl-template-package-alist))))
10705
10706 (defun vhdl-template-insert-directive (name)
10707 "Insert the built-in directive template with NAME."
10708 (interactive
10709 (list (let ((completion-ignore-case t))
10710 (completing-read "Directive name: "
10711 vhdl-template-directive-alist nil t))))
10712 (vhdl-template-insert-fun
10713 (cadr (assoc name vhdl-template-directive-alist))))
10714
10715 (defun vhdl-template-insert-fun (fun)
10716 "Call FUN to insert a built-in template."
10717 (let ((caught (catch 'abort (when fun (funcall fun)))))
10718 (when (stringp caught) (message "%s" caught))))
10719
10720
10721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10722 ;;; Models
10723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10724
10725 (defun vhdl-model-insert (model-name)
10726 "Insert the user model with name MODEL-NAME."
10727 (interactive
10728 (let ((completion-ignore-case t))
10729 (list (completing-read "Model name: " vhdl-model-alist))))
10730 (indent-according-to-mode)
10731 (let ((start (point-marker))
10732 (margin (current-indentation))
10733 model position prompt string end)
10734 (vhdl-prepare-search-2
10735 (when (setq model (assoc model-name vhdl-model-alist))
10736 ;; insert model
10737 (beginning-of-line)
10738 (delete-horizontal-space)
10739 (goto-char start)
10740 (vhdl-insert-string-or-file (nth 1 model))
10741 (setq end (point-marker))
10742 ;; indent code
10743 (goto-char start)
10744 (beginning-of-line)
10745 (while (< (point) end)
10746 (unless (looking-at "^$")
10747 (insert-char ? margin))
10748 (beginning-of-line 2))
10749 (goto-char start)
10750 ;; insert clock
10751 (unless (equal "" vhdl-clock-name)
10752 (while (re-search-forward "<clock>" end t)
10753 (replace-match vhdl-clock-name)))
10754 (goto-char start)
10755 ;; insert reset
10756 (unless (equal "" vhdl-reset-name)
10757 (while (re-search-forward "<reset>" end t)
10758 (replace-match vhdl-reset-name)))
10759 ;; replace header prompts
10760 (vhdl-template-replace-header-keywords start end nil t)
10761 (goto-char start)
10762 ;; query other prompts
10763 (while (re-search-forward
10764 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10765 (unless (equal "cursor" (match-string 1))
10766 (setq position (match-beginning 1))
10767 (setq prompt (match-string 1))
10768 (replace-match "")
10769 (setq string (vhdl-template-field prompt nil t))
10770 ;; replace occurrences of same prompt
10771 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10772 (replace-match (or string "")))
10773 (goto-char position)))
10774 (goto-char start)
10775 ;; goto final position
10776 (if (re-search-forward "<cursor>" end t)
10777 (replace-match "")
10778 (goto-char end))))))
10779
10780 (defun vhdl-model-defun ()
10781 "Define help and hook functions for user models."
10782 (let ((model-alist vhdl-model-alist)
10783 model-name model-keyword)
10784 (while model-alist
10785 ;; define functions for user models that can be invoked from menu and key
10786 ;; bindings and which themselves call `vhdl-model-insert' with the model
10787 ;; name as argument
10788 (setq model-name (nth 0 (car model-alist)))
10789 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10790 ,(concat "Insert model for \"" model-name "\".")
10791 (interactive)
10792 (vhdl-model-insert ,model-name)))
10793 ;; define hooks for user models that are invoked from keyword abbrevs
10794 (setq model-keyword (nth 3 (car model-alist)))
10795 (unless (equal model-keyword "")
10796 (eval `(defun
10797 ,(vhdl-function-name
10798 "vhdl-model" model-name "hook") ()
10799 (vhdl-hooked-abbrev
10800 ',(vhdl-function-name "vhdl-model" model-name)))))
10801 (setq model-alist (cdr model-alist)))))
10802
10803 (vhdl-model-defun)
10804
10805
10806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10807 ;;; Port translation
10808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10809
10810 (defvar vhdl-port-list nil
10811 "Variable to hold last port map parsed.")
10812 ;; structure: (parenthesised expression means list of such entries)
10813 ;; (ent-name
10814 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10815 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10816 ;; (lib-name pack-key))
10817
10818 (defun vhdl-parse-string (string &optional optional)
10819 "Check that the text following point matches the regexp in STRING."
10820 (if (looking-at string)
10821 (goto-char (match-end 0))
10822 (unless optional
10823 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10824 (vhdl-current-line) string)))
10825 nil))
10826
10827 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10828 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10829 (vhdl-prepare-search-1
10830 (if (string-match (car regexp-cons) string)
10831 (if adjust-case
10832 (funcall vhdl-file-name-case
10833 (replace-match (cdr regexp-cons) t nil string))
10834 (replace-match (cdr regexp-cons) t nil string))
10835 string)))
10836
10837 (defun vhdl-parse-group-comment ()
10838 "Parse comment and empty lines between groups of lines."
10839 (let ((start (point))
10840 string)
10841 (vhdl-forward-comment (point-max))
10842 (setq string (buffer-substring-no-properties start (point)))
10843 (vhdl-forward-syntactic-ws)
10844 ;; strip off leading blanks and first newline
10845 (while (string-match "^\\(\\s-+\\)" string)
10846 (setq string (concat (substring string 0 (match-beginning 1))
10847 (substring string (match-end 1)))))
10848 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10849 (substring string 1)
10850 string)))
10851
10852 (defun vhdl-paste-group-comment (string indent)
10853 "Paste comment and empty lines from STRING between groups of lines
10854 with INDENT."
10855 (let ((pos (point-marker)))
10856 (when (> indent 0)
10857 (while (string-match "^\\(--\\)" string)
10858 (setq string (concat (substring string 0 (match-beginning 1))
10859 (make-string indent ? )
10860 (substring string (match-beginning 1))))))
10861 (beginning-of-line)
10862 (insert string)
10863 (goto-char pos)))
10864
10865 (defvar vhdl-port-flattened nil
10866 "Indicates whether a port has been flattened.")
10867
10868 (defun vhdl-port-flatten (&optional as-alist)
10869 "Flatten port list so that only one generic/port exists per line.
10870 This operation is performed on an internally stored port and is only
10871 reflected in a subsequent paste operation."
10872 (interactive)
10873 (if (not vhdl-port-list)
10874 (error "ERROR: No port has been read")
10875 (message "Flattening port for next paste...")
10876 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10877 (old-vhdl-port-list (cdr vhdl-port-list))
10878 old-port-list new-port-list old-port new-port names)
10879 ;; traverse port list and flatten entries
10880 (while (cdr old-vhdl-port-list)
10881 (setq old-port-list (car old-vhdl-port-list))
10882 (setq new-port-list nil)
10883 (while old-port-list
10884 (setq old-port (car old-port-list))
10885 (setq names (car old-port))
10886 (while names
10887 (setq new-port (cons (if as-alist (car names) (list (car names)))
10888 (cdr old-port)))
10889 (setq new-port-list (append new-port-list (list new-port)))
10890 (setq names (cdr names)))
10891 (setq old-port-list (cdr old-port-list)))
10892 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10893 (setq new-vhdl-port-list (append new-vhdl-port-list
10894 (list new-port-list))))
10895 (setq vhdl-port-list
10896 (append new-vhdl-port-list (list old-vhdl-port-list))
10897 vhdl-port-flattened t)
10898 (message "Flattening port for next paste...done"))))
10899
10900 (defvar vhdl-port-reversed-direction nil
10901 "Indicates whether port directions are reversed.")
10902
10903 (defun vhdl-port-reverse-direction ()
10904 "Reverse direction for all ports (useful in testbenches).
10905 This operation is performed on an internally stored port and is only
10906 reflected in a subsequent paste operation."
10907 (interactive)
10908 (if (not vhdl-port-list)
10909 (error "ERROR: No port has been read")
10910 (message "Reversing port directions for next paste...")
10911 (let ((port-list (nth 2 vhdl-port-list))
10912 port-dir-car port-dir)
10913 ;; traverse port list and reverse directions
10914 (while port-list
10915 (setq port-dir-car (cddr (car port-list))
10916 port-dir (car port-dir-car))
10917 (setcar port-dir-car
10918 (cond ((equal port-dir "in") "out")
10919 ((equal port-dir "out") "in")
10920 (t port-dir)))
10921 (setq port-list (cdr port-list)))
10922 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10923 (message "Reversing port directions for next paste...done"))))
10924
10925 (defun vhdl-port-copy ()
10926 "Get generic and port information from an entity or component declaration."
10927 (interactive)
10928 (save-excursion
10929 (let (parse-error end-of-list
10930 decl-type name generic-list port-list context-clause
10931 object names direct type init comment group-comment)
10932 (vhdl-prepare-search-2
10933 (setq
10934 parse-error
10935 (catch 'parse
10936 ;; check if within entity or component declaration
10937 (end-of-line)
10938 (when (or (not (re-search-backward
10939 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10940 (equal "END" (upcase (match-string 1))))
10941 (throw 'parse "ERROR: Not within an entity or component declaration"))
10942 (setq decl-type (downcase (match-string-no-properties 1)))
10943 (forward-word 1)
10944 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10945 (setq name (match-string-no-properties 1))
10946 (message "Reading port of %s \"%s\"..." decl-type name)
10947 (vhdl-forward-syntactic-ws)
10948 ;; parse generic clause
10949 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10950 ;; parse group comment and spacing
10951 (setq group-comment (vhdl-parse-group-comment))
10952 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10953 (while (not end-of-list)
10954 ;; parse names (accept extended identifiers)
10955 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10956 (setq names (list (match-string-no-properties 1)))
10957 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10958 (setq names
10959 (append names (list (match-string-no-properties 1)))))
10960 ;; parse type
10961 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10962 (setq type (match-string-no-properties 1))
10963 (setq comment nil)
10964 (while (looking-at "(")
10965 (setq type
10966 (concat type
10967 (buffer-substring-no-properties
10968 (point) (progn (forward-sexp) (point)))
10969 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10970 (match-string-no-properties 1)))))
10971 ;; special case: closing parenthesis is on separate line
10972 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10973 (setq comment (substring type (match-beginning 2)))
10974 (setq type (substring type 0 (match-beginning 1))))
10975 ;; strip of trailing group-comment
10976 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10977 (setq type (substring type 0 (match-end 1)))
10978 ;; parse initialization expression
10979 (setq init nil)
10980 (when (vhdl-parse-string ":=[ \t\n]*" t)
10981 (vhdl-parse-string "\\([^();\n]*\\)")
10982 (setq init (match-string-no-properties 1))
10983 (while (looking-at "(")
10984 (setq init
10985 (concat init
10986 (buffer-substring-no-properties
10987 (point) (progn (forward-sexp) (point)))
10988 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10989 (match-string-no-properties 1))))))
10990 ;; special case: closing parenthesis is on separate line
10991 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10992 (setq comment (substring init (match-beginning 2)))
10993 (setq init (substring init 0 (match-beginning 1)))
10994 (vhdl-forward-syntactic-ws))
10995 (skip-chars-forward " \t")
10996 ;; parse inline comment, special case: as above, no initial.
10997 (unless comment
10998 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10999 (match-string-no-properties 1))))
11000 (vhdl-forward-syntactic-ws)
11001 (setq end-of-list (vhdl-parse-string ")" t))
11002 (vhdl-parse-string "\\s-*;\\s-*")
11003 ;; parse inline comment
11004 (unless comment
11005 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11006 (match-string-no-properties 1))))
11007 ;; save everything in list
11008 (setq generic-list (append generic-list
11009 (list (list names type init
11010 comment group-comment))))
11011 ;; parse group comment and spacing
11012 (setq group-comment (vhdl-parse-group-comment))))
11013 ;; parse port clause
11014 (when (vhdl-parse-string "port[ \t\n]*(" t)
11015 ;; parse group comment and spacing
11016 (setq group-comment (vhdl-parse-group-comment))
11017 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11018 (while (not end-of-list)
11019 ;; parse object
11020 (setq object
11021 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11022 (match-string-no-properties 1)))
11023 ;; parse names (accept extended identifiers)
11024 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11025 (setq names (list (match-string-no-properties 1)))
11026 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11027 (setq names (append names (list (match-string-no-properties 1)))))
11028 ;; parse direction
11029 (vhdl-parse-string ":[ \t\n]*")
11030 (setq direct
11031 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11032 (match-string-no-properties 1)))
11033 ;; parse type
11034 (vhdl-parse-string "\\([^();\n]+\\)")
11035 (setq type (match-string-no-properties 1))
11036 (setq comment nil)
11037 (while (looking-at "(")
11038 (setq type (concat type
11039 (buffer-substring-no-properties
11040 (point) (progn (forward-sexp) (point)))
11041 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11042 (match-string-no-properties 1)))))
11043 ;; special case: closing parenthesis is on separate line
11044 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11045 (setq comment (substring type (match-beginning 2)))
11046 (setq type (substring type 0 (match-beginning 1))))
11047 ;; strip of trailing group-comment
11048 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11049 (setq type (substring type 0 (match-end 1)))
11050 (vhdl-forward-syntactic-ws)
11051 (setq end-of-list (vhdl-parse-string ")" t))
11052 (vhdl-parse-string "\\s-*;\\s-*")
11053 ;; parse inline comment
11054 (unless comment
11055 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11056 (match-string-no-properties 1))))
11057 ;; save everything in list
11058 (setq port-list (append port-list
11059 (list (list names object direct type
11060 comment group-comment))))
11061 ;; parse group comment and spacing
11062 (setq group-comment (vhdl-parse-group-comment))))
11063 ; (vhdl-parse-string "end\\>")
11064 ;; parse context clause
11065 (setq context-clause (vhdl-scan-context-clause))
11066 ; ;; add surrounding package to context clause
11067 ; (when (and (equal decl-type "component")
11068 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11069 ; (setq context-clause
11070 ; (append context-clause
11071 ; (list (cons (vhdl-work-library)
11072 ; (match-string-no-properties 1))))))
11073 (message "Reading port of %s \"%s\"...done" decl-type name)
11074 nil)))
11075 ;; finish parsing
11076 (if parse-error
11077 (error parse-error)
11078 (setq vhdl-port-list (list name generic-list port-list context-clause)
11079 vhdl-port-reversed-direction nil
11080 vhdl-port-flattened nil)))))
11081
11082 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11083 "Paste a context clause."
11084 (let ((margin (current-indentation))
11085 (clause-list (nth 3 vhdl-port-list))
11086 clause)
11087 (while clause-list
11088 (setq clause (car clause-list))
11089 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11090 (downcase exclude-pack-name)))
11091 (save-excursion
11092 (re-search-backward
11093 (concat "^\\s-*use\\s-+" (car clause)
11094 "\." (cdr clause) "\\>") nil t)))
11095 (vhdl-template-standard-package (car clause) (cdr clause))
11096 (insert "\n"))
11097 (setq clause-list (cdr clause-list)))))
11098
11099 (defun vhdl-port-paste-generic (&optional no-init)
11100 "Paste a generic clause."
11101 (let ((margin (current-indentation))
11102 (generic-list (nth 1 vhdl-port-list))
11103 list-margin start names generic)
11104 ;; paste generic clause
11105 (when generic-list
11106 (setq start (point))
11107 (vhdl-insert-keyword "GENERIC (")
11108 (unless vhdl-argument-list-indent
11109 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11110 (setq list-margin (current-column))
11111 (while generic-list
11112 (setq generic (car generic-list))
11113 ;; paste group comment and spacing
11114 (when (memq vhdl-include-group-comments '(decl always))
11115 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11116 ;; paste names
11117 (setq names (nth 0 generic))
11118 (while names
11119 (insert (car names))
11120 (setq names (cdr names))
11121 (when names (insert ", ")))
11122 ;; paste type
11123 (insert " : " (nth 1 generic))
11124 ;; paste initialization
11125 (when (and (not no-init) (nth 2 generic))
11126 (insert " := " (nth 2 generic)))
11127 (unless (cdr generic-list) (insert ")"))
11128 (insert ";")
11129 ;; paste comment
11130 (when (and vhdl-include-port-comments (nth 3 generic))
11131 (vhdl-comment-insert-inline (nth 3 generic) t))
11132 (setq generic-list (cdr generic-list))
11133 (when generic-list (insert "\n") (indent-to list-margin)))
11134 ;; align generic clause
11135 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11136
11137 (defun vhdl-port-paste-port ()
11138 "Paste a port clause."
11139 (let ((margin (current-indentation))
11140 (port-list (nth 2 vhdl-port-list))
11141 list-margin start names port)
11142 ;; paste port clause
11143 (when port-list
11144 (setq start (point))
11145 (vhdl-insert-keyword "PORT (")
11146 (unless vhdl-argument-list-indent
11147 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11148 (setq list-margin (current-column))
11149 (while port-list
11150 (setq port (car port-list))
11151 ;; paste group comment and spacing
11152 (when (memq vhdl-include-group-comments '(decl always))
11153 (vhdl-paste-group-comment (nth 5 port) list-margin))
11154 ;; paste object
11155 (when (nth 1 port) (insert (nth 1 port) " "))
11156 ;; paste names
11157 (setq names (nth 0 port))
11158 (while names
11159 (insert (car names))
11160 (setq names (cdr names))
11161 (when names (insert ", ")))
11162 ;; paste direction
11163 (insert " : ")
11164 (when (nth 2 port) (insert (nth 2 port) " "))
11165 ;; paste type
11166 (insert (nth 3 port))
11167 (unless (cdr port-list) (insert ")"))
11168 (insert ";")
11169 ;; paste comment
11170 (when (and vhdl-include-port-comments (nth 4 port))
11171 (vhdl-comment-insert-inline (nth 4 port) t))
11172 (setq port-list (cdr port-list))
11173 (when port-list (insert "\n") (indent-to list-margin)))
11174 ;; align port clause
11175 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11176
11177 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11178 "Paste as an entity or component declaration."
11179 (unless no-indent (indent-according-to-mode))
11180 (let ((margin (current-indentation))
11181 (name (nth 0 vhdl-port-list)))
11182 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11183 (insert name)
11184 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11185 (vhdl-insert-keyword " IS"))
11186 ;; paste generic and port clause
11187 (when (nth 1 vhdl-port-list)
11188 (insert "\n")
11189 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11190 (insert "\n"))
11191 (indent-to (+ margin vhdl-basic-offset))
11192 (vhdl-port-paste-generic (eq kind 'component)))
11193 (when (nth 2 vhdl-port-list)
11194 (insert "\n")
11195 (when (and (memq vhdl-insert-empty-lines '(unit all))
11196 (eq kind 'entity))
11197 (insert "\n"))
11198 (indent-to (+ margin vhdl-basic-offset)))
11199 (vhdl-port-paste-port)
11200 (insert "\n")
11201 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11202 (insert "\n"))
11203 (indent-to margin)
11204 (vhdl-insert-keyword "END")
11205 (if (eq kind 'entity)
11206 (progn
11207 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11208 (insert " " name))
11209 (vhdl-insert-keyword " COMPONENT")
11210 (unless (vhdl-standard-p '87) (insert " " name)))
11211 (insert ";")))
11212
11213 (defun vhdl-port-paste-entity (&optional no-indent)
11214 "Paste as an entity declaration."
11215 (interactive)
11216 (if (not vhdl-port-list)
11217 (error "ERROR: No port read")
11218 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11219 (vhdl-port-paste-declaration 'entity no-indent)
11220 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11221
11222 (defun vhdl-port-paste-component (&optional no-indent)
11223 "Paste as a component declaration."
11224 (interactive)
11225 (if (not vhdl-port-list)
11226 (error "ERROR: No port read")
11227 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11228 (vhdl-port-paste-declaration 'component no-indent)
11229 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11230
11231 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11232 "Paste as a generic map."
11233 (interactive)
11234 (unless secondary (indent-according-to-mode))
11235 (let ((margin (current-indentation))
11236 list-margin start generic
11237 (generic-list (nth 1 vhdl-port-list)))
11238 (when generic-list
11239 (setq start (point))
11240 (vhdl-insert-keyword "GENERIC MAP (")
11241 (if (not vhdl-association-list-with-formals)
11242 ;; paste list of actual generics
11243 (while generic-list
11244 (insert (if no-constants
11245 (car (nth 0 (car generic-list)))
11246 (or (nth 2 (car generic-list)) " ")))
11247 (setq generic-list (cdr generic-list))
11248 (insert (if generic-list ", " ")"))
11249 (when (and (not generic-list) secondary
11250 (null (nth 2 vhdl-port-list)))
11251 (insert ";")))
11252 (unless vhdl-argument-list-indent
11253 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11254 (setq list-margin (current-column))
11255 (while generic-list
11256 (setq generic (car generic-list))
11257 ;; paste group comment and spacing
11258 (when (eq vhdl-include-group-comments 'always)
11259 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11260 ;; paste formal and actual generic
11261 (insert (car (nth 0 generic)) " => "
11262 (if no-constants
11263 (car (nth 0 generic))
11264 (or (nth 2 generic) "")))
11265 (setq generic-list (cdr generic-list))
11266 (insert (if generic-list "," ")"))
11267 (when (and (not generic-list) secondary
11268 (null (nth 2 vhdl-port-list)))
11269 (insert ";"))
11270 ;; paste comment
11271 (when (or vhdl-include-type-comments
11272 (and vhdl-include-port-comments (nth 3 generic)))
11273 (vhdl-comment-insert-inline
11274 (concat
11275 (when vhdl-include-type-comments
11276 (concat "[" (nth 1 generic) "] "))
11277 (when vhdl-include-port-comments (nth 3 generic))) t))
11278 (when generic-list (insert "\n") (indent-to list-margin)))
11279 ;; align generic map
11280 (when vhdl-auto-align
11281 (vhdl-align-region-groups start (point) 1 t))))))
11282
11283 (defun vhdl-port-paste-port-map ()
11284 "Paste as a port map."
11285 (let ((margin (current-indentation))
11286 list-margin start port
11287 (port-list (nth 2 vhdl-port-list)))
11288 (when port-list
11289 (setq start (point))
11290 (vhdl-insert-keyword "PORT MAP (")
11291 (if (not vhdl-association-list-with-formals)
11292 ;; paste list of actual ports
11293 (while port-list
11294 (insert (vhdl-replace-string vhdl-actual-port-name
11295 (car (nth 0 (car port-list)))))
11296 (setq port-list (cdr port-list))
11297 (insert (if port-list ", " ")")))
11298 (unless vhdl-argument-list-indent
11299 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11300 (setq list-margin (current-column))
11301 (while port-list
11302 (setq port (car port-list))
11303 ;; paste group comment and spacing
11304 (when (eq vhdl-include-group-comments 'always)
11305 (vhdl-paste-group-comment (nth 5 port) list-margin))
11306 ;; paste formal and actual port
11307 (insert (car (nth 0 port)) " => ")
11308 (insert (vhdl-replace-string vhdl-actual-port-name
11309 (car (nth 0 port))))
11310 (setq port-list (cdr port-list))
11311 (insert (if port-list "," ");"))
11312 ;; paste comment
11313 (when (or vhdl-include-direction-comments
11314 vhdl-include-type-comments
11315 (and vhdl-include-port-comments (nth 4 port)))
11316 (vhdl-comment-insert-inline
11317 (concat
11318 (cond ((and vhdl-include-direction-comments
11319 vhdl-include-type-comments)
11320 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11321 (nth 3 port) "] "))
11322 ((and vhdl-include-direction-comments (nth 2 port))
11323 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11324 (vhdl-include-direction-comments " ")
11325 (vhdl-include-type-comments
11326 (concat "[" (nth 3 port) "] ")))
11327 (when vhdl-include-port-comments (nth 4 port))) t))
11328 (when port-list (insert "\n") (indent-to list-margin)))
11329 ;; align port clause
11330 (when vhdl-auto-align
11331 (vhdl-align-region-groups start (point) 1))))))
11332
11333 (defun vhdl-port-paste-instance (&optional name no-indent title)
11334 "Paste as an instantiation."
11335 (interactive)
11336 (if (not vhdl-port-list)
11337 (error "ERROR: No port read")
11338 (let ((orig-vhdl-port-list vhdl-port-list))
11339 ;; flatten local copy of port list (must be flat for port mapping)
11340 (vhdl-port-flatten)
11341 (unless no-indent (indent-according-to-mode))
11342 (let ((margin (current-indentation)))
11343 ;; paste instantiation
11344 (cond (name
11345 (insert name))
11346 ((equal (cdr vhdl-instance-name) "")
11347 (setq name (vhdl-template-field "instance name")))
11348 ((string-match "\%d" (cdr vhdl-instance-name))
11349 (let ((n 1))
11350 (while (save-excursion
11351 (setq name (format (vhdl-replace-string
11352 vhdl-instance-name
11353 (nth 0 vhdl-port-list)) n))
11354 (goto-char (point-min))
11355 (vhdl-re-search-forward name nil t))
11356 (setq n (1+ n)))
11357 (insert name)))
11358 (t (insert (vhdl-replace-string vhdl-instance-name
11359 (nth 0 vhdl-port-list)))))
11360 (message "Pasting port as instantiation \"%s\"..." name)
11361 (insert ": ")
11362 (when title
11363 (save-excursion
11364 (beginning-of-line)
11365 (indent-to vhdl-basic-offset)
11366 (insert "-- instance \"" name "\"\n")))
11367 (if (not (vhdl-use-direct-instantiation))
11368 (insert (nth 0 vhdl-port-list))
11369 (vhdl-insert-keyword "ENTITY ")
11370 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11371 (when (nth 1 vhdl-port-list)
11372 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11373 (vhdl-port-paste-generic-map t t))
11374 (when (nth 2 vhdl-port-list)
11375 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11376 (vhdl-port-paste-port-map))
11377 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11378 (insert ";"))
11379 (message "Pasting port as instantiation \"%s\"...done" name))
11380 (setq vhdl-port-list orig-vhdl-port-list))))
11381
11382 (defun vhdl-port-paste-constants (&optional no-indent)
11383 "Paste generics as constants."
11384 (interactive)
11385 (if (not vhdl-port-list)
11386 (error "ERROR: No port read")
11387 (let ((orig-vhdl-port-list vhdl-port-list))
11388 (message "Pasting port as constants...")
11389 ;; flatten local copy of port list (must be flat for constant initial.)
11390 (vhdl-port-flatten)
11391 (unless no-indent (indent-according-to-mode))
11392 (let ((margin (current-indentation))
11393 start generic name
11394 (generic-list (nth 1 vhdl-port-list)))
11395 (when generic-list
11396 (setq start (point))
11397 (while generic-list
11398 (setq generic (car generic-list))
11399 ;; paste group comment and spacing
11400 (when (memq vhdl-include-group-comments '(decl always))
11401 (vhdl-paste-group-comment (nth 4 generic) margin))
11402 (vhdl-insert-keyword "CONSTANT ")
11403 ;; paste generic constants
11404 (setq name (nth 0 generic))
11405 (when name
11406 (insert (car name))
11407 ;; paste type
11408 (insert " : " (nth 1 generic))
11409 ;; paste initialization
11410 (when (nth 2 generic)
11411 (insert " := " (nth 2 generic)))
11412 (insert ";")
11413 ;; paste comment
11414 (when (and vhdl-include-port-comments (nth 3 generic))
11415 (vhdl-comment-insert-inline (nth 3 generic) t))
11416 (setq generic-list (cdr generic-list))
11417 (when generic-list (insert "\n") (indent-to margin))))
11418 ;; align signal list
11419 (when vhdl-auto-align
11420 (vhdl-align-region-groups start (point) 1))))
11421 (message "Pasting port as constants...done")
11422 (setq vhdl-port-list orig-vhdl-port-list))))
11423
11424 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11425 "Paste ports as internal signals."
11426 (interactive)
11427 (if (not vhdl-port-list)
11428 (error "ERROR: No port read")
11429 (message "Pasting port as signals...")
11430 (unless no-indent (indent-according-to-mode))
11431 (let ((margin (current-indentation))
11432 start port names
11433 (port-list (nth 2 vhdl-port-list)))
11434 (when port-list
11435 (setq start (point))
11436 (while port-list
11437 (setq port (car port-list))
11438 ;; paste group comment and spacing
11439 (when (memq vhdl-include-group-comments '(decl always))
11440 (vhdl-paste-group-comment (nth 5 port) margin))
11441 ;; paste object
11442 (if (nth 1 port)
11443 (insert (nth 1 port) " ")
11444 (vhdl-insert-keyword "SIGNAL "))
11445 ;; paste actual port signals
11446 (setq names (nth 0 port))
11447 (while names
11448 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11449 (setq names (cdr names))
11450 (when names (insert ", ")))
11451 ;; paste type
11452 (insert " : " (nth 3 port))
11453 ;; paste initialization (inputs only)
11454 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11455 (insert " := " (if (string-match "(.+)" (nth 3 port))
11456 "(others => '0')" "'0'")))
11457 (insert ";")
11458 ;; paste comment
11459 (when (or vhdl-include-direction-comments
11460 (and vhdl-include-port-comments (nth 4 port)))
11461 (vhdl-comment-insert-inline
11462 (concat
11463 (cond ((and vhdl-include-direction-comments (nth 2 port))
11464 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11465 (vhdl-include-direction-comments " "))
11466 (when vhdl-include-port-comments (nth 4 port))) t))
11467 (setq port-list (cdr port-list))
11468 (when port-list (insert "\n") (indent-to margin)))
11469 ;; align signal list
11470 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11471 (message "Pasting port as signals...done")))
11472
11473 (defun vhdl-port-paste-initializations (&optional no-indent)
11474 "Paste ports as signal initializations."
11475 (interactive)
11476 (if (not vhdl-port-list)
11477 (error "ERROR: No port read")
11478 (let ((orig-vhdl-port-list vhdl-port-list))
11479 (message "Pasting port as initializations...")
11480 ;; flatten local copy of port list (must be flat for signal initial.)
11481 (vhdl-port-flatten)
11482 (unless no-indent (indent-according-to-mode))
11483 (let ((margin (current-indentation))
11484 start port name
11485 (port-list (nth 2 vhdl-port-list)))
11486 (when port-list
11487 (setq start (point))
11488 (while port-list
11489 (setq port (car port-list))
11490 ;; paste actual port signal (inputs only)
11491 (when (equal "IN" (upcase (nth 2 port)))
11492 (setq name (car (nth 0 port)))
11493 (insert (vhdl-replace-string vhdl-actual-port-name name))
11494 ;; paste initialization
11495 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11496 "(others => '0')" "'0'") ";"))
11497 (setq port-list (cdr port-list))
11498 (when (and port-list
11499 (equal "IN" (upcase (nth 2 (car port-list)))))
11500 (insert "\n") (indent-to margin)))
11501 ;; align signal list
11502 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11503 (message "Pasting port as initializations...done")
11504 (setq vhdl-port-list orig-vhdl-port-list))))
11505
11506 (defun vhdl-port-paste-testbench ()
11507 "Paste as a bare-bones testbench."
11508 (interactive)
11509 (if (not vhdl-port-list)
11510 (error "ERROR: No port read")
11511 (let ((case-fold-search t)
11512 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11513 (nth 0 vhdl-port-list)))
11514 (source-buffer (current-buffer))
11515 arch-name config-name ent-file-name arch-file-name
11516 ent-buffer arch-buffer position)
11517 ;; open entity file
11518 (unless (eq vhdl-testbench-create-files 'none)
11519 (setq ent-file-name
11520 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11521 ent-name t)
11522 "." (file-name-extension (buffer-file-name))))
11523 (if (file-exists-p ent-file-name)
11524 (if (y-or-n-p
11525 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11526 (progn (find-file ent-file-name)
11527 (erase-buffer)
11528 (set-buffer-modified-p nil))
11529 (if (eq vhdl-testbench-create-files 'separate)
11530 (setq ent-file-name nil)
11531 (error "ERROR: Pasting port as testbench...aborted")))
11532 (find-file ent-file-name)))
11533 (unless (and (eq vhdl-testbench-create-files 'separate)
11534 (null ent-file-name))
11535 ;; paste entity header
11536 (if vhdl-testbench-include-header
11537 (progn (vhdl-template-header
11538 (concat "Testbench for design \""
11539 (nth 0 vhdl-port-list) "\""))
11540 (goto-char (point-max)))
11541 (vhdl-comment-display-line) (insert "\n\n"))
11542 ;; paste std_logic_1164 package
11543 (when vhdl-testbench-include-library
11544 (vhdl-template-package-std-logic-1164)
11545 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11546 ;; paste entity declaration
11547 (vhdl-insert-keyword "ENTITY ")
11548 (insert ent-name)
11549 (vhdl-insert-keyword " IS")
11550 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11551 (insert "\n")
11552 (vhdl-insert-keyword "END ")
11553 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11554 (insert ent-name ";")
11555 (insert "\n\n")
11556 (vhdl-comment-display-line) (insert "\n"))
11557 ;; get architecture name
11558 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11559 (read-from-minibuffer "architecture name: "
11560 nil vhdl-minibuffer-local-map)
11561 (vhdl-replace-string vhdl-testbench-architecture-name
11562 (nth 0 vhdl-port-list))))
11563 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11564 ;; open architecture file
11565 (if (not (eq vhdl-testbench-create-files 'separate))
11566 (insert "\n")
11567 (setq ent-buffer (current-buffer))
11568 (setq arch-file-name
11569 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11570 (concat ent-name " " arch-name) t)
11571 "." (file-name-extension (buffer-file-name))))
11572 (when (and (file-exists-p arch-file-name)
11573 (not (y-or-n-p (concat "File \"" arch-file-name
11574 "\" exists; overwrite? "))))
11575 (error "ERROR: Pasting port as testbench...aborted"))
11576 (find-file arch-file-name)
11577 (erase-buffer)
11578 (set-buffer-modified-p nil)
11579 ;; paste architecture header
11580 (if vhdl-testbench-include-header
11581 (progn (vhdl-template-header
11582 (concat "Testbench architecture for design \""
11583 (nth 0 vhdl-port-list) "\""))
11584 (goto-char (point-max)))
11585 (vhdl-comment-display-line) (insert "\n\n")))
11586 ;; paste architecture body
11587 (vhdl-insert-keyword "ARCHITECTURE ")
11588 (insert arch-name)
11589 (vhdl-insert-keyword " OF ")
11590 (insert ent-name)
11591 (vhdl-insert-keyword " IS")
11592 (insert "\n\n") (indent-to vhdl-basic-offset)
11593 ;; paste component declaration
11594 (unless (vhdl-use-direct-instantiation)
11595 (vhdl-port-paste-component t)
11596 (insert "\n\n") (indent-to vhdl-basic-offset))
11597 ;; paste constants
11598 (when (nth 1 vhdl-port-list)
11599 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11600 (vhdl-port-paste-constants t)
11601 (insert "\n\n") (indent-to vhdl-basic-offset))
11602 ;; paste internal signals
11603 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11604 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11605 (insert "\n")
11606 ;; paste custom declarations
11607 (unless (equal "" vhdl-testbench-declarations)
11608 (insert "\n")
11609 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11610 (setq position (point))
11611 (insert "\n\n")
11612 (vhdl-comment-display-line) (insert "\n")
11613 (when vhdl-testbench-include-configuration
11614 (setq config-name (vhdl-replace-string
11615 vhdl-testbench-configuration-name
11616 (concat ent-name " " arch-name)))
11617 (insert "\n")
11618 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11619 (vhdl-insert-keyword " OF ") (insert ent-name)
11620 (vhdl-insert-keyword " IS\n")
11621 (indent-to vhdl-basic-offset)
11622 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11623 (indent-to vhdl-basic-offset)
11624 (vhdl-insert-keyword "END FOR;\n")
11625 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11626 (vhdl-comment-display-line) (insert "\n"))
11627 (goto-char position)
11628 (vhdl-template-begin-end
11629 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11630 ;; paste instantiation
11631 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11632 (vhdl-port-paste-instance
11633 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11634 (insert "\n")
11635 ;; paste custom statements
11636 (unless (equal "" vhdl-testbench-statements)
11637 (insert "\n")
11638 (vhdl-insert-string-or-file vhdl-testbench-statements))
11639 (insert "\n")
11640 (indent-to vhdl-basic-offset)
11641 (unless (eq vhdl-testbench-create-files 'none)
11642 (setq arch-buffer (current-buffer))
11643 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11644 (set-buffer arch-buffer) (save-buffer))
11645 (message "%s"
11646 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11647 ent-name arch-name)
11648 (and ent-file-name
11649 (format "\n File created: \"%s\"" ent-file-name))
11650 (and arch-file-name
11651 (format "\n File created: \"%s\"" arch-file-name)))))))
11652
11653
11654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11655 ;;; Subprogram interface translation
11656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11657
11658 (defvar vhdl-subprog-list nil
11659 "Variable to hold last subprogram interface parsed.")
11660 ;; structure: (parenthesised expression means list of such entries)
11661 ;; (subprog-name kind
11662 ;; ((names) object direct type init comment group-comment)
11663 ;; return-type return-comment group-comment)
11664
11665 (defvar vhdl-subprog-flattened nil
11666 "Indicates whether an subprogram interface has been flattened.")
11667
11668 (defun vhdl-subprog-flatten ()
11669 "Flatten interface list so that only one parameter exists per line."
11670 (interactive)
11671 (if (not vhdl-subprog-list)
11672 (error "ERROR: No subprogram interface has been read")
11673 (message "Flattening subprogram interface...")
11674 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11675 new-subprog-list old-subprog new-subprog names)
11676 ;; traverse parameter list and flatten entries
11677 (while old-subprog-list
11678 (setq old-subprog (car old-subprog-list))
11679 (setq names (car old-subprog))
11680 (while names
11681 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11682 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11683 (setq names (cdr names)))
11684 (setq old-subprog-list (cdr old-subprog-list)))
11685 (setq vhdl-subprog-list
11686 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11687 new-subprog-list (nth 3 vhdl-subprog-list)
11688 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11689 vhdl-subprog-flattened t)
11690 (message "Flattening subprogram interface...done"))))
11691
11692 (defun vhdl-subprog-copy ()
11693 "Get interface information from a subprogram specification."
11694 (interactive)
11695 (save-excursion
11696 (let (parse-error pos end-of-list
11697 name kind param-list object names direct type init
11698 comment group-comment
11699 return-type return-comment return-group-comment)
11700 (vhdl-prepare-search-2
11701 (setq
11702 parse-error
11703 (catch 'parse
11704 ;; check if within function declaration
11705 (setq pos (point))
11706 (end-of-line)
11707 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11708 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11709 (goto-char (match-end 0))
11710 (save-excursion (backward-char)
11711 (forward-sexp)
11712 (<= pos (point))))
11713 (throw 'parse "ERROR: Not within a subprogram specification"))
11714 (setq name (match-string-no-properties 5))
11715 (setq kind (if (match-string 2) 'procedure 'function))
11716 (setq end-of-list (not (match-string 7)))
11717 (message "Reading interface of subprogram \"%s\"..." name)
11718 ;; parse parameter list
11719 (setq group-comment (vhdl-parse-group-comment))
11720 (setq end-of-list (or end-of-list
11721 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11722 (while (not end-of-list)
11723 ;; parse object
11724 (setq object
11725 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11726 (match-string-no-properties 1)))
11727 ;; parse names (accept extended identifiers)
11728 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11729 (setq names (list (match-string-no-properties 1)))
11730 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11731 (setq names (append names (list (match-string-no-properties 1)))))
11732 ;; parse direction
11733 (vhdl-parse-string ":[ \t\n]*")
11734 (setq direct
11735 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11736 (match-string-no-properties 1)))
11737 ;; parse type
11738 (vhdl-parse-string "\\([^():;\n]+\\)")
11739 (setq type (match-string-no-properties 1))
11740 (setq comment nil)
11741 (while (looking-at "(")
11742 (setq type
11743 (concat type
11744 (buffer-substring-no-properties
11745 (point) (progn (forward-sexp) (point)))
11746 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11747 (match-string-no-properties 1)))))
11748 ;; special case: closing parenthesis is on separate line
11749 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11750 (setq comment (substring type (match-beginning 2)))
11751 (setq type (substring type 0 (match-beginning 1))))
11752 ;; strip off trailing group-comment
11753 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11754 (setq type (substring type 0 (match-end 1)))
11755 ;; parse initialization expression
11756 (setq init nil)
11757 (when (vhdl-parse-string ":=[ \t\n]*" t)
11758 (vhdl-parse-string "\\([^();\n]*\\)")
11759 (setq init (match-string-no-properties 1))
11760 (while (looking-at "(")
11761 (setq init
11762 (concat init
11763 (buffer-substring-no-properties
11764 (point) (progn (forward-sexp) (point)))
11765 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11766 (match-string-no-properties 1))))))
11767 ;; special case: closing parenthesis is on separate line
11768 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11769 (setq comment (substring init (match-beginning 2)))
11770 (setq init (substring init 0 (match-beginning 1)))
11771 (vhdl-forward-syntactic-ws))
11772 (skip-chars-forward " \t")
11773 ;; parse inline comment, special case: as above, no initial.
11774 (unless comment
11775 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11776 (match-string-no-properties 1))))
11777 (vhdl-forward-syntactic-ws)
11778 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11779 ;; parse inline comment
11780 (unless comment
11781 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11782 (match-string-no-properties 1))))
11783 (setq return-group-comment (vhdl-parse-group-comment))
11784 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11785 ;; parse return type
11786 (when (match-string 3)
11787 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11788 (setq return-type (match-string-no-properties 1))
11789 (when (and return-type
11790 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11791 (setq return-comment (substring return-type (match-beginning 2)))
11792 (setq return-type (substring return-type 0 (match-beginning 1))))
11793 ;; strip of trailing group-comment
11794 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11795 (setq return-type (substring return-type 0 (match-end 1)))
11796 ;; parse return comment
11797 (unless return-comment
11798 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11799 (match-string-no-properties 1)))))
11800 ;; parse inline comment
11801 (unless comment
11802 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11803 (match-string-no-properties 1))))
11804 ;; save everything in list
11805 (setq param-list (append param-list
11806 (list (list names object direct type init
11807 comment group-comment))))
11808 ;; parse group comment and spacing
11809 (setq group-comment (vhdl-parse-group-comment)))
11810 (message "Reading interface of subprogram \"%s\"...done" name)
11811 nil)))
11812 ;; finish parsing
11813 (if parse-error
11814 (error parse-error)
11815 (setq vhdl-subprog-list
11816 (list name kind param-list return-type return-comment
11817 return-group-comment)
11818 vhdl-subprog-flattened nil)))))
11819
11820 (defun vhdl-subprog-paste-specification (kind)
11821 "Paste as a subprogram specification."
11822 (indent-according-to-mode)
11823 (let ((margin (current-column))
11824 (param-list (nth 2 vhdl-subprog-list))
11825 list-margin start names param)
11826 ;; paste keyword and name
11827 (vhdl-insert-keyword
11828 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11829 (insert (nth 0 vhdl-subprog-list))
11830 (if (not param-list)
11831 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11832 (setq start (point))
11833 ;; paste parameter list
11834 (insert " (")
11835 (unless vhdl-argument-list-indent
11836 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11837 (setq list-margin (current-column))
11838 (while param-list
11839 (setq param (car param-list))
11840 ;; paste group comment and spacing
11841 (when (memq vhdl-include-group-comments (list kind 'always))
11842 (vhdl-paste-group-comment (nth 6 param) list-margin))
11843 ;; paste object
11844 (when (nth 1 param) (insert (nth 1 param) " "))
11845 ;; paste names
11846 (setq names (nth 0 param))
11847 (while names
11848 (insert (car names))
11849 (setq names (cdr names))
11850 (when names (insert ", ")))
11851 ;; paste direction
11852 (insert " : ")
11853 (when (nth 2 param) (insert (nth 2 param) " "))
11854 ;; paste type
11855 (insert (nth 3 param))
11856 ;; paste initialization
11857 (when (nth 4 param) (insert " := " (nth 4 param)))
11858 ;; terminate line
11859 (if (cdr param-list)
11860 (insert ";")
11861 (insert ")")
11862 (when (null (nth 3 vhdl-subprog-list))
11863 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11864 ;; paste comment
11865 (when (and vhdl-include-port-comments (nth 5 param))
11866 (vhdl-comment-insert-inline (nth 5 param) t))
11867 (setq param-list (cdr param-list))
11868 (when param-list (insert "\n") (indent-to list-margin)))
11869 (when (nth 3 vhdl-subprog-list)
11870 (insert "\n") (indent-to list-margin)
11871 ;; paste group comment and spacing
11872 (when (memq vhdl-include-group-comments (list kind 'always))
11873 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11874 ;; paste return type
11875 (insert "return " (nth 3 vhdl-subprog-list))
11876 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11877 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11878 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11879 ;; align parameter list
11880 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11881 ;; paste body
11882 (when (eq kind 'body)
11883 (insert "\n")
11884 (vhdl-template-begin-end
11885 (unless (vhdl-standard-p '87)
11886 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11887 (nth 0 vhdl-subprog-list) margin))))
11888
11889 (defun vhdl-subprog-paste-declaration ()
11890 "Paste as a subprogram declaration."
11891 (interactive)
11892 (if (not vhdl-subprog-list)
11893 (error "ERROR: No subprogram interface read")
11894 (message "Pasting interface as subprogram declaration \"%s\"..."
11895 (car vhdl-subprog-list))
11896 ;; paste specification
11897 (vhdl-subprog-paste-specification 'decl)
11898 (message "Pasting interface as subprogram declaration \"%s\"...done"
11899 (car vhdl-subprog-list))))
11900
11901 (defun vhdl-subprog-paste-body ()
11902 "Paste as a subprogram body."
11903 (interactive)
11904 (if (not vhdl-subprog-list)
11905 (error "ERROR: No subprogram interface read")
11906 (message "Pasting interface as subprogram body \"%s\"..."
11907 (car vhdl-subprog-list))
11908 ;; paste specification and body
11909 (vhdl-subprog-paste-specification 'body)
11910 (message "Pasting interface as subprogram body \"%s\"...done"
11911 (car vhdl-subprog-list))))
11912
11913 (defun vhdl-subprog-paste-call ()
11914 "Paste as a subprogram call."
11915 (interactive)
11916 (if (not vhdl-subprog-list)
11917 (error "ERROR: No subprogram interface read")
11918 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11919 param-list margin list-margin param start)
11920 ;; flatten local copy of interface list (must be flat for parameter mapping)
11921 (vhdl-subprog-flatten)
11922 (setq param-list (nth 2 vhdl-subprog-list))
11923 (indent-according-to-mode)
11924 (setq margin (current-indentation))
11925 (message "Pasting interface as subprogram call \"%s\"..."
11926 (car vhdl-subprog-list))
11927 ;; paste name
11928 (insert (nth 0 vhdl-subprog-list))
11929 (if (not param-list)
11930 (insert ";")
11931 (setq start (point))
11932 ;; paste parameter list
11933 (insert " (")
11934 (unless vhdl-argument-list-indent
11935 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11936 (setq list-margin (current-column))
11937 (while param-list
11938 (setq param (car param-list))
11939 ;; paste group comment and spacing
11940 (when (eq vhdl-include-group-comments 'always)
11941 (vhdl-paste-group-comment (nth 6 param) list-margin))
11942 ;; paste formal port
11943 (insert (car (nth 0 param)) " => ")
11944 (setq param-list (cdr param-list))
11945 (insert (if param-list "," ");"))
11946 ;; paste comment
11947 (when (and vhdl-include-port-comments (nth 5 param))
11948 (vhdl-comment-insert-inline (nth 5 param)))
11949 (when param-list (insert "\n") (indent-to list-margin)))
11950 ;; align parameter list
11951 (when vhdl-auto-align
11952 (vhdl-align-region-groups start (point) 1)))
11953 (message "Pasting interface as subprogram call \"%s\"...done"
11954 (car vhdl-subprog-list))
11955 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11956
11957
11958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11959 ;;; Miscellaneous
11960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11961
11962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11963 ;; Hippie expand customization
11964
11965 (defvar vhdl-expand-upper-case nil)
11966
11967 (defun vhdl-try-expand-abbrev (old)
11968 "Try expanding abbreviations from `vhdl-abbrev-list'."
11969 (unless old
11970 (he-init-string (he-dabbrev-beg) (point))
11971 (setq he-expand-list
11972 (let ((abbrev-list vhdl-abbrev-list)
11973 (sel-abbrev-list '()))
11974 (while abbrev-list
11975 (when (or (not (stringp (car abbrev-list)))
11976 (string-match
11977 (concat "^" he-search-string) (car abbrev-list)))
11978 (setq sel-abbrev-list
11979 (cons (car abbrev-list) sel-abbrev-list)))
11980 (setq abbrev-list (cdr abbrev-list)))
11981 (nreverse sel-abbrev-list))))
11982 (while (and he-expand-list
11983 (or (not (stringp (car he-expand-list)))
11984 (he-string-member (car he-expand-list) he-tried-table t)))
11985 ; (equal (car he-expand-list) he-search-string)))
11986 (unless (stringp (car he-expand-list))
11987 (setq vhdl-expand-upper-case (car he-expand-list)))
11988 (setq he-expand-list (cdr he-expand-list)))
11989 (if (null he-expand-list)
11990 (progn (when old (he-reset-string))
11991 nil)
11992 (he-substitute-string
11993 (if vhdl-expand-upper-case
11994 (upcase (car he-expand-list))
11995 (car he-expand-list))
11996 t)
11997 (setq he-expand-list (cdr he-expand-list))
11998 t))
11999
12000 (defun vhdl-he-list-beg ()
12001 "Also looks at the word before `(' in order to better match parenthesized
12002 expressions (e.g. for index ranges of types and signals)."
12003 (save-excursion
12004 (condition-case ()
12005 (progn (backward-up-list 1)
12006 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12007 (error ()))
12008 (point)))
12009
12010 ;; override `he-list-beg' from `hippie-exp'
12011 (unless (and (boundp 'viper-mode) viper-mode)
12012 (defalias 'he-list-beg 'vhdl-he-list-beg))
12013
12014 ;; function for expanding abbrevs and dabbrevs
12015 (defun vhdl-expand-abbrev (arg))
12016 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12017 '(try-expand-dabbrev
12018 try-expand-dabbrev-all-buffers
12019 vhdl-try-expand-abbrev)))
12020
12021 ;; function for expanding parenthesis
12022 (defun vhdl-expand-paren (arg))
12023 (fset 'vhdl-expand-paren (make-hippie-expand-function
12024 '(try-expand-list
12025 try-expand-list-all-buffers)))
12026
12027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12028 ;; Case fixing
12029
12030 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12031 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12032 depending on parameter UPPER-CASE."
12033 (let ((case-replace nil)
12034 (last-update 0))
12035 (vhdl-prepare-search-2
12036 (save-excursion
12037 (goto-char end)
12038 (setq end (point-marker))
12039 (goto-char beg)
12040 (while (re-search-forward word-regexp end t)
12041 (or (vhdl-in-literal)
12042 (if upper-case
12043 (upcase-word -1)
12044 (downcase-word -1)))
12045 (when (and count vhdl-progress-interval (not noninteractive)
12046 (< vhdl-progress-interval
12047 (- (nth 1 (current-time)) last-update)))
12048 (message "Fixing case... (%2d%s)"
12049 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12050 "%")
12051 (setq last-update (nth 1 (current-time)))))
12052 (goto-char end)))))
12053
12054 (defun vhdl-fix-case-region (beg end &optional arg)
12055 "Convert all VHDL words in region to lower or upper case, depending on
12056 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12057 (interactive "r\nP")
12058 (vhdl-fix-case-region-1
12059 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12060 (vhdl-fix-case-region-1
12061 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12062 (vhdl-fix-case-region-1
12063 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12064 (vhdl-fix-case-region-1
12065 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12066 (when vhdl-progress-interval (message "Fixing case...done")))
12067
12068 (defun vhdl-fix-case-buffer ()
12069 "Convert all VHDL words in buffer to lower or upper case, depending on
12070 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12071 (interactive)
12072 (vhdl-fix-case-region (point-min) (point-max)))
12073
12074 (defun vhdl-fix-case-word (&optional arg)
12075 "Convert word after cursor to upper case if necessary."
12076 (interactive "p")
12077 (save-excursion
12078 (when arg (backward-word 1))
12079 (vhdl-prepare-search-1
12080 (when (and vhdl-upper-case-keywords
12081 (looking-at vhdl-keywords-regexp))
12082 (upcase-word 1))
12083 (when (and vhdl-upper-case-types
12084 (looking-at vhdl-types-regexp))
12085 (upcase-word 1))
12086 (when (and vhdl-upper-case-attributes
12087 (looking-at vhdl-attributes-regexp))
12088 (upcase-word 1))
12089 (when (and vhdl-upper-case-enum-values
12090 (looking-at vhdl-enum-values-regexp))
12091 (upcase-word 1)))))
12092
12093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12094 ;; Line handling functions
12095
12096 (defun vhdl-current-line ()
12097 "Return the line number of the line containing point."
12098 (save-restriction
12099 (widen)
12100 (1+ (count-lines (point-min) (point-at-bol)))))
12101
12102 (defun vhdl-line-kill-entire (&optional arg)
12103 "Delete entire line."
12104 (interactive "p")
12105 (beginning-of-line)
12106 (kill-line (or arg 1)))
12107
12108 (defun vhdl-line-kill (&optional arg)
12109 "Kill current line."
12110 (interactive "p")
12111 (vhdl-line-kill-entire arg))
12112
12113 (defun vhdl-line-copy (&optional arg)
12114 "Copy current line."
12115 (interactive "p")
12116 (save-excursion
12117 (let ((position (point-at-bol)))
12118 (forward-line (or arg 1))
12119 (copy-region-as-kill position (point)))))
12120
12121 (defun vhdl-line-yank ()
12122 "Yank entire line."
12123 (interactive)
12124 (beginning-of-line)
12125 (yank))
12126
12127 (defun vhdl-line-expand (&optional prefix-arg)
12128 "Hippie-expand current line."
12129 (interactive "P")
12130 (let ((case-fold-search t) (case-replace nil)
12131 (hippie-expand-try-functions-list
12132 '(try-expand-line try-expand-line-all-buffers)))
12133 (hippie-expand prefix-arg)))
12134
12135 (defun vhdl-line-transpose-next (&optional arg)
12136 "Interchange this line with next line."
12137 (interactive "p")
12138 (forward-line 1)
12139 (transpose-lines (or arg 1))
12140 (forward-line -1))
12141
12142 (defun vhdl-line-transpose-previous (&optional arg)
12143 "Interchange this line with previous line."
12144 (interactive "p")
12145 (forward-line 1)
12146 (transpose-lines (- 0 (or arg 0)))
12147 (forward-line -1))
12148
12149 (defun vhdl-line-open ()
12150 "Open a new line and indent."
12151 (interactive)
12152 (end-of-line -0)
12153 (newline-and-indent))
12154
12155 (defun vhdl-delete-indentation ()
12156 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12157 it works within comments too."
12158 (interactive)
12159 (let ((fill-prefix "-- "))
12160 (delete-indentation)))
12161
12162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12163 ;; Move functions
12164
12165 (defun vhdl-forward-same-indent ()
12166 "Move forward to next line with same indent."
12167 (interactive)
12168 (let ((pos (point))
12169 (indent (current-indentation)))
12170 (beginning-of-line 2)
12171 (while (and (not (eobp))
12172 (or (looking-at "^\\s-*\\(--.*\\)?$")
12173 (> (current-indentation) indent)))
12174 (beginning-of-line 2))
12175 (if (= (current-indentation) indent)
12176 (back-to-indentation)
12177 (message "No following line with same indent found in this block")
12178 (goto-char pos)
12179 nil)))
12180
12181 (defun vhdl-backward-same-indent ()
12182 "Move backward to previous line with same indent."
12183 (interactive)
12184 (let ((pos (point))
12185 (indent (current-indentation)))
12186 (beginning-of-line -0)
12187 (while (and (not (bobp))
12188 (or (looking-at "^\\s-*\\(--.*\\)?$")
12189 (> (current-indentation) indent)))
12190 (beginning-of-line -0))
12191 (if (= (current-indentation) indent)
12192 (back-to-indentation)
12193 (message "No preceding line with same indent found in this block")
12194 (goto-char pos)
12195 nil)))
12196
12197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12198 ;; Statistics
12199
12200 (defun vhdl-statistics-buffer ()
12201 "Get some file statistics."
12202 (interactive)
12203 (let ((no-stats 0)
12204 (no-code-lines 0)
12205 (no-lines (count-lines (point-min) (point-max))))
12206 (save-excursion
12207 ;; count statements
12208 (goto-char (point-min))
12209 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12210 (if (match-string 1)
12211 (goto-char (match-end 1))
12212 (setq no-stats (1+ no-stats))))
12213 ;; count code lines
12214 (goto-char (point-min))
12215 (while (not (eobp))
12216 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12217 (setq no-code-lines (1+ no-code-lines)))
12218 (beginning-of-line 2)))
12219 ;; print results
12220 (message "\n\
12221 File statistics: \"%s\"\n\
12222 ---------------------\n\
12223 # statements : %5d\n\
12224 # code lines : %5d\n\
12225 # total lines : %5d\n\ "
12226 (buffer-file-name) no-stats no-code-lines no-lines)
12227 (unless vhdl-emacs-21 (vhdl-show-messages))))
12228
12229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12230 ;; Help functions
12231
12232 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12233 "Like `re-search-forward', but does not match within literals."
12234 (let (pos)
12235 (save-excursion
12236 (while (and (setq pos (re-search-forward regexp bound noerror count))
12237 (vhdl-in-literal))))
12238 (when pos (goto-char pos))
12239 pos))
12240
12241 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12242 "Like `re-search-backward', but does not match within literals."
12243 (let (pos)
12244 (save-excursion
12245 (while (and (setq pos (re-search-backward regexp bound noerror count))
12246 (vhdl-in-literal))))
12247 (when pos (goto-char pos))
12248 pos))
12249
12250
12251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12252 ;;; Project
12253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12254
12255 (defun vhdl-set-project (name)
12256 "Set current project to NAME."
12257 (interactive
12258 (list (let ((completion-ignore-case t))
12259 (completing-read "Project name: " vhdl-project-alist nil t))))
12260 (cond ((equal name "")
12261 (setq vhdl-project nil)
12262 (message "Current VHDL project: None"))
12263 ((assoc name vhdl-project-alist)
12264 (setq vhdl-project name)
12265 (message "Current VHDL project: \"%s\"" name))
12266 (t
12267 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12268 (vhdl-speedbar-update-current-project))
12269
12270 (defun vhdl-set-default-project ()
12271 "Set current project as default on startup."
12272 (interactive)
12273 (customize-set-variable 'vhdl-project vhdl-project)
12274 (customize-save-customized))
12275
12276 (defun vhdl-toggle-project (name token indent)
12277 "Set current project to NAME or unset if NAME is current project."
12278 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12279
12280 (defun vhdl-export-project (file-name)
12281 "Write project setup for current project."
12282 (interactive
12283 (let ((name (vhdl-resolve-env-variable
12284 (vhdl-replace-string
12285 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12286 (concat (subst-char-in-string
12287 ? ?_ (or (vhdl-project-p)
12288 (error "ERROR: No current project")))
12289 " " (user-login-name))))))
12290 (list (read-file-name
12291 "Write project file: "
12292 (when (file-name-absolute-p name) "") nil nil name))))
12293 (setq file-name (abbreviate-file-name file-name))
12294 (let ((orig-buffer (current-buffer)))
12295 (unless (file-exists-p (file-name-directory file-name))
12296 (make-directory (file-name-directory file-name) t))
12297 (if (not (file-writable-p file-name))
12298 (error "ERROR: File not writable: \"%s\"" file-name)
12299 (set-buffer (find-file-noselect file-name t t))
12300 (erase-buffer)
12301 (insert ";; -*- Emacs-Lisp -*-\n\n"
12302 ";;; " (file-name-nondirectory file-name)
12303 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12304 ";; Project : " vhdl-project "\n"
12305 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12306 (user-login-name) "\n\n\n"
12307 ";; project name\n"
12308 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12309 ";; project setup\n"
12310 "(aput 'vhdl-project-alist vhdl-project\n'")
12311 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12312 (insert ")\n")
12313 (save-buffer)
12314 (kill-buffer (current-buffer))
12315 (set-buffer orig-buffer))))
12316
12317 (defun vhdl-import-project (file-name &optional auto not-make-current)
12318 "Read project setup and set current project."
12319 (interactive
12320 (let ((name (vhdl-resolve-env-variable
12321 (vhdl-replace-string
12322 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12323 (concat "" " " (user-login-name))))))
12324 (list (read-file-name
12325 "Read project file: " (when (file-name-absolute-p name) "") nil t
12326 (file-name-directory name)))))
12327 (when (file-exists-p file-name)
12328 (condition-case ()
12329 (let ((current-project vhdl-project))
12330 (load-file file-name)
12331 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12332 (adelete 'vhdl-project-alist vhdl-project)
12333 (error ""))
12334 (when not-make-current
12335 (setq vhdl-project current-project))
12336 (vhdl-update-mode-menu)
12337 (vhdl-speedbar-refresh)
12338 (unless not-make-current
12339 (message "Current VHDL project: \"%s\"%s"
12340 vhdl-project (if auto " (auto-loaded)" ""))))
12341 (error (vhdl-warning
12342 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12343
12344 (defun vhdl-duplicate-project ()
12345 "Duplicate setup of current project."
12346 (interactive)
12347 (let ((new-name (read-from-minibuffer "New project name: "))
12348 (project-entry (aget vhdl-project-alist vhdl-project t)))
12349 (setq vhdl-project-alist
12350 (append vhdl-project-alist
12351 (list (cons new-name project-entry))))
12352 (vhdl-update-mode-menu)))
12353
12354 (defun vhdl-auto-load-project ()
12355 "Automatically load project setup at startup."
12356 (let ((file-name-list vhdl-project-file-name)
12357 file-list list-length)
12358 (while file-name-list
12359 (setq file-list
12360 (append file-list
12361 (file-expand-wildcards
12362 (vhdl-resolve-env-variable
12363 (vhdl-replace-string
12364 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12365 (concat "\*" " " (user-login-name)))))))
12366 (setq list-length (or list-length (length file-list)))
12367 (setq file-name-list (cdr file-name-list)))
12368 (while file-list
12369 (vhdl-import-project (expand-file-name (car file-list)) t
12370 (not (> list-length 0)))
12371 (setq list-length (1- list-length))
12372 (setq file-list (cdr file-list)))))
12373
12374 ;; automatically load project setup when idle after startup
12375 (when (memq 'startup vhdl-project-auto-load)
12376 (if noninteractive
12377 (vhdl-auto-load-project)
12378 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12379
12380
12381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12382 ;;; Hideshow
12383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12384 ;; (using `hideshow.el')
12385
12386 (defconst vhdl-hs-start-regexp
12387 (concat
12388 "\\(^\\)\\s-*\\("
12389 ;; generic/port clause
12390 "\\(generic\\|port\\)[ \t\n]*(\\|"
12391 ;; component
12392 "component\\>\\|"
12393 ;; component instantiation
12394 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12395 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12396 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12397 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12398 ;; subprogram
12399 "\\(function\\|procedure\\)\\>\\|"
12400 ;; process, block
12401 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12402 ;; configuration declaration
12403 "configuration\\>"
12404 "\\)")
12405 "Regexp to match start of construct to hide.")
12406
12407 (defun vhdl-hs-forward-sexp-func (count)
12408 "Find end of construct to hide (for hideshow). Only searches forward."
12409 (let ((pos (point)))
12410 (vhdl-prepare-search-2
12411 (beginning-of-line)
12412 (cond
12413 ;; generic/port clause
12414 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12415 (goto-char (match-end 0))
12416 (backward-char)
12417 (forward-sexp))
12418 ;; component declaration
12419 ((looking-at "^\\s-*component\\>")
12420 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12421 ;; component instantiation
12422 ((looking-at
12423 (concat
12424 "^\\s-*\\w+\\s-*:[ \t\n]*"
12425 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12426 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12427 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12428 (goto-char (match-end 0))
12429 (backward-char)
12430 (forward-sexp)
12431 (setq pos (point))
12432 (vhdl-forward-syntactic-ws)
12433 (when (looking-at "port\\s-+map[ \t\n]*(")
12434 (goto-char (match-end 0))
12435 (backward-char)
12436 (forward-sexp)
12437 (setq pos (point)))
12438 (goto-char pos))
12439 ;; subprogram declaration/body
12440 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12441 (goto-char (match-end 0))
12442 (vhdl-forward-syntactic-ws)
12443 (when (looking-at "(")
12444 (forward-sexp))
12445 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12446 (vhdl-in-literal)))
12447 ;; subprogram body
12448 (when (match-string 2)
12449 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12450 (backward-word 1)
12451 (vhdl-forward-sexp)))
12452 ;; block (recursive)
12453 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12454 (goto-char (match-end 0))
12455 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12456 (match-beginning 2))
12457 (vhdl-hs-forward-sexp-func count)))
12458 ;; process
12459 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12460 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12461 ;; configuration declaration
12462 ((looking-at "^\\s-*configuration\\>")
12463 (forward-word 4)
12464 (vhdl-forward-sexp))
12465 (t (goto-char pos))))))
12466
12467 (defun vhdl-hideshow-init ()
12468 "Initialize `hideshow'."
12469 (when vhdl-hideshow-menu
12470 (vhdl-hs-minor-mode 1)))
12471
12472 (defun vhdl-hs-minor-mode (&optional arg)
12473 "Toggle hideshow minor mode and update menu bar."
12474 (interactive "P")
12475 (require 'hideshow)
12476 ;; check for hideshow version 5.x
12477 (if (not (boundp 'hs-block-start-mdata-select))
12478 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12479 ;; initialize hideshow
12480 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12481 (setq hs-special-modes-alist
12482 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12483 'vhdl-hs-forward-sexp-func nil)
12484 hs-special-modes-alist)))
12485 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
12486 (if vhdl-hide-all-init
12487 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
12488 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
12489 (hs-minor-mode arg)
12490 (force-mode-line-update))) ; hack to update menu bar
12491
12492
12493 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12494 ;;; Font locking
12495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12496 ;; (using `font-lock.el')
12497
12498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12499 ;; Help functions
12500
12501 (defun vhdl-within-translate-off ()
12502 "Return point if within translate-off region, else nil."
12503 (and (save-excursion
12504 (re-search-backward
12505 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12506 (equal "off" (match-string 1))
12507 (point)))
12508
12509 (defun vhdl-start-translate-off (limit)
12510 "Return point before translate-off pragma if before LIMIT, else nil."
12511 (when (re-search-forward
12512 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12513 (match-beginning 0)))
12514
12515 (defun vhdl-end-translate-off (limit)
12516 "Return point after translate-on pragma if before LIMIT, else nil."
12517 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12518
12519 (defun vhdl-match-translate-off (limit)
12520 "Match a translate-off block, setting match-data and returning t, else nil."
12521 (when (< (point) limit)
12522 (let ((start (or (vhdl-within-translate-off)
12523 (vhdl-start-translate-off limit)))
12524 (case-fold-search t))
12525 (when start
12526 (let ((end (or (vhdl-end-translate-off limit) limit)))
12527 (set-match-data (list start end))
12528 (goto-char end))))))
12529
12530 (defun vhdl-font-lock-match-item (limit)
12531 "Match, and move over, any declaration item after point. Adapted from
12532 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12533 (condition-case nil
12534 (save-restriction
12535 (narrow-to-region (point-min) limit)
12536 ;; match item
12537 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12538 (save-match-data
12539 (goto-char (match-end 1))
12540 ;; move to next item
12541 (if (looking-at "\\(\\s-*,\\)")
12542 (goto-char (match-end 1))
12543 (end-of-line) t))))
12544 (error t)))
12545
12546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12547 ;; Syntax definitions
12548
12549 (defconst vhdl-font-lock-syntactic-keywords
12550 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12551 "Mark single quotes as having string quote syntax in 'c' instances.")
12552
12553 (defvar vhdl-font-lock-keywords nil
12554 "Regular expressions to highlight in VHDL Mode.")
12555
12556 (defvar vhdl-font-lock-keywords-0
12557 ;; set in `vhdl-font-lock-init' because dependent on user options
12558 "For consideration as a value of `vhdl-font-lock-keywords'.
12559 This does highlighting of template prompts and directives (pragmas).")
12560
12561 (defvar vhdl-font-lock-keywords-1 nil
12562 ;; set in `vhdl-font-lock-init' because dependent on user options
12563 "For consideration as a value of `vhdl-font-lock-keywords'.
12564 This does highlighting of keywords and standard identifiers.")
12565
12566 (defconst vhdl-font-lock-keywords-2
12567 (list
12568 ;; highlight names of units, subprograms, and components when declared
12569 (list
12570 (concat
12571 "^\\s-*\\("
12572 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12573 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12574 "\\)\\s-+\\(\\w+\\)")
12575 5 'font-lock-function-name-face)
12576
12577 ;; highlight entity names of architectures and configurations
12578 (list
12579 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12580 2 'font-lock-function-name-face)
12581
12582 ;; highlight labels of common constructs
12583 (list
12584 (concat
12585 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12586 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12587 "postponed\\|process\\|"
12588 (when (vhdl-standard-p 'ams) "procedural\\|")
12589 "with\\|while"
12590 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12591 1 'font-lock-function-name-face)
12592
12593 ;; highlight label and component name of component instantiations
12594 (list
12595 (concat
12596 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12597 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12598 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12599
12600 ;; highlight label and instantiated unit of component instantiations
12601 (list
12602 (concat
12603 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12604 "\\(component\\|configuration\\|entity\\)\\s-+"
12605 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12606 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12607 '(5 font-lock-function-name-face nil t)
12608 '(7 font-lock-function-name-face nil t))
12609
12610 ;; highlight names and labels at end of constructs
12611 (list
12612 (concat
12613 "^\\s-*end\\s-+\\(\\("
12614 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12615 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12616 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12617 (when (vhdl-standard-p 'ams) "procedural\\|")
12618 "units"
12619 "\\)\\s-+\\)?\\(\\w*\\)")
12620 5 'font-lock-function-name-face)
12621
12622 ;; highlight labels in exit and next statements
12623 (list
12624 (concat
12625 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12626 3 'font-lock-function-name-face)
12627
12628 ;; highlight entity name in attribute specifications
12629 (list
12630 (concat
12631 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12632 1 'font-lock-function-name-face)
12633
12634 ;; highlight labels in block and component specifications
12635 (list
12636 (concat
12637 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12638 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12639 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12640
12641 ;; highlight names in library clauses
12642 (list "^\\s-*library\\>"
12643 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12644
12645 ;; highlight names in use clauses
12646 (list
12647 (concat
12648 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12649 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12650 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12651 '(7 font-lock-function-name-face nil t))
12652
12653 ;; highlight attribute name in attribute declarations/specifications
12654 (list
12655 (concat
12656 "^\\s-*attribute\\s-+\\(\\w+\\)")
12657 1 'vhdl-font-lock-attribute-face)
12658
12659 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12660 (list
12661 (concat
12662 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12663 3 'font-lock-type-face)
12664
12665 ;; highlight signal/variable/constant declaration names
12666 (list "\\(:[^=]\\)"
12667 '(vhdl-font-lock-match-item
12668 (progn (goto-char (match-beginning 1))
12669 (skip-syntax-backward " ")
12670 (skip-syntax-backward "w_")
12671 (skip-syntax-backward " ")
12672 (while (= (preceding-char) ?,)
12673 (backward-char 1)
12674 (skip-syntax-backward " ")
12675 (skip-syntax-backward "w_")
12676 (skip-syntax-backward " ")))
12677 ; (skip-chars-backward "^-(\n\";")
12678 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12679
12680 ;; highlight formal parameters in component instantiations and subprogram
12681 ;; calls
12682 (list "\\(=>\\)"
12683 '(vhdl-font-lock-match-item
12684 (progn (goto-char (match-beginning 1))
12685 (skip-syntax-backward " ")
12686 (while (= (preceding-char) ?\)) (backward-sexp))
12687 (skip-syntax-backward "w_")
12688 (skip-syntax-backward " ")
12689 (when (memq (preceding-char) '(?n ?N ?|))
12690 (goto-char (point-max))))
12691 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12692
12693 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12694 ;; variables
12695 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12696 '(vhdl-font-lock-match-item
12697 (progn (goto-char (match-end 1)) (match-beginning 2))
12698 nil (1 font-lock-variable-name-face)))
12699 )
12700 "For consideration as a value of `vhdl-font-lock-keywords'.
12701 This does context sensitive highlighting of names and labels.")
12702
12703 (defvar vhdl-font-lock-keywords-3 nil
12704 ;; set in `vhdl-font-lock-init' because dependent on user options
12705 "For consideration as a value of `vhdl-font-lock-keywords'.
12706 This does highlighting of words with special syntax.")
12707
12708 (defvar vhdl-font-lock-keywords-4 nil
12709 ;; set in `vhdl-font-lock-init' because dependent on user options
12710 "For consideration as a value of `vhdl-font-lock-keywords'.
12711 This does highlighting of additional reserved words.")
12712
12713 (defconst vhdl-font-lock-keywords-5
12714 ;; background highlight translate-off regions
12715 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12716 "For consideration as a value of `vhdl-font-lock-keywords'.
12717 This does background highlighting of translate-off regions.")
12718
12719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12720 ;; Font and color definitions
12721
12722 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12723 "Face name to use for prompts.")
12724
12725 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12726 "Face name to use for standardized attributes.")
12727
12728 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12729 "Face name to use for standardized enumeration values.")
12730
12731 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12732 "Face name to use for standardized functions and packages.")
12733
12734 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12735 "Face name to use for directives.")
12736
12737 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12738 "Face name to use for additional reserved words.")
12739
12740 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12741 "Face name to use for translate-off regions.")
12742
12743 ;; face names to use for words with special syntax.
12744 (let ((syntax-alist vhdl-special-syntax-alist)
12745 name)
12746 (while syntax-alist
12747 (setq name (vhdl-function-name
12748 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12749 (eval `(defvar ,name ',name
12750 ,(concat "Face name to use for "
12751 (nth 0 (car syntax-alist)) ".")))
12752 (setq syntax-alist (cdr syntax-alist))))
12753
12754 (defgroup vhdl-highlight-faces nil
12755 "Faces for highlighting."
12756 :group 'vhdl-highlight)
12757
12758 ;; add faces used from `font-lock'
12759 (custom-add-to-group
12760 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12761 (custom-add-to-group
12762 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12763 (custom-add-to-group
12764 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12765 (custom-add-to-group
12766 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12767 (custom-add-to-group
12768 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12769 (custom-add-to-group
12770 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12771
12772 (defface vhdl-font-lock-prompt-face
12773 '((((min-colors 88) (class color) (background light))
12774 (:foreground "Red1" :bold t))
12775 (((class color) (background light)) (:foreground "Red" :bold t))
12776 (((class color) (background dark)) (:foreground "Pink" :bold t))
12777 (t (:inverse-video t)))
12778 "Font lock mode face used to highlight prompts."
12779 :group 'vhdl-highlight-faces)
12780
12781 (defface vhdl-font-lock-attribute-face
12782 '((((class color) (background light)) (:foreground "Orchid"))
12783 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12784 (t (:italic t :bold t)))
12785 "Font lock mode face used to highlight standardized attributes."
12786 :group 'vhdl-highlight-faces)
12787
12788 (defface vhdl-font-lock-enumvalue-face
12789 '((((class color) (background light)) (:foreground "SaddleBrown"))
12790 (((class color) (background dark)) (:foreground "BurlyWood"))
12791 (t (:italic t :bold t)))
12792 "Font lock mode face used to highlight standardized enumeration values."
12793 :group 'vhdl-highlight-faces)
12794
12795 (defface vhdl-font-lock-function-face
12796 '((((class color) (background light)) (:foreground "Cyan4"))
12797 (((class color) (background dark)) (:foreground "Orchid1"))
12798 (t (:italic t :bold t)))
12799 "Font lock mode face used to highlight standardized functions and packages."
12800 :group 'vhdl-highlight-faces)
12801
12802 (defface vhdl-font-lock-directive-face
12803 '((((class color) (background light)) (:foreground "CadetBlue"))
12804 (((class color) (background dark)) (:foreground "Aquamarine"))
12805 (t (:italic t :bold t)))
12806 "Font lock mode face used to highlight directives."
12807 :group 'vhdl-highlight-faces)
12808
12809 (defface vhdl-font-lock-reserved-words-face
12810 '((((class color) (background light)) (:foreground "Orange" :bold t))
12811 (((min-colors 88) (class color) (background dark))
12812 (:foreground "Yellow1" :bold t))
12813 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12814 (t ()))
12815 "Font lock mode face used to highlight additional reserved words."
12816 :group 'vhdl-highlight-faces)
12817
12818 (defface vhdl-font-lock-translate-off-face
12819 '((((class color) (background light)) (:background "LightGray"))
12820 (((class color) (background dark)) (:background "DimGray"))
12821 (t ()))
12822 "Font lock mode face used to background highlight translate-off regions."
12823 :group 'vhdl-highlight-faces)
12824
12825 ;; font lock mode faces used to highlight words with special syntax.
12826 (let ((syntax-alist vhdl-special-syntax-alist))
12827 (while syntax-alist
12828 (eval `(defface ,(vhdl-function-name
12829 "vhdl-font-lock" (caar syntax-alist) "face")
12830 '((((class color) (background light))
12831 (:foreground ,(nth 2 (car syntax-alist))))
12832 (((class color) (background dark))
12833 (:foreground ,(nth 3 (car syntax-alist))))
12834 (t ()))
12835 ,(concat "Font lock mode face used to highlight "
12836 (nth 0 (car syntax-alist)) ".")
12837 :group 'vhdl-highlight-faces))
12838 (setq syntax-alist (cdr syntax-alist))))
12839
12840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12841 ;; Font lock initialization
12842
12843 (defun vhdl-font-lock-init ()
12844 "Initialize fontification."
12845 ;; highlight template prompts and directives
12846 (setq vhdl-font-lock-keywords-0
12847 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12848 vhdl-template-prompt-syntax ">\\)")
12849 2 'vhdl-font-lock-prompt-face t)
12850 (list (concat "--\\s-*"
12851 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12852 2 'vhdl-font-lock-directive-face t)
12853 ;; highlight c-preprocessor directives
12854 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12855 '(1 font-lock-builtin-face)
12856 '(3 font-lock-variable-name-face nil t))))
12857 ;; highlight keywords and standardized types, attributes, enumeration
12858 ;; values, and subprograms
12859 (setq vhdl-font-lock-keywords-1
12860 (list
12861 (list (concat "'" vhdl-attributes-regexp)
12862 1 'vhdl-font-lock-attribute-face)
12863 (list vhdl-types-regexp 1 'font-lock-type-face)
12864 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12865 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12866 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12867 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12868 ;; highlight words with special syntax.
12869 (setq vhdl-font-lock-keywords-3
12870 (let ((syntax-alist vhdl-special-syntax-alist)
12871 keywords)
12872 (while syntax-alist
12873 (setq keywords
12874 (cons
12875 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12876 (vhdl-function-name
12877 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12878 keywords))
12879 (setq syntax-alist (cdr syntax-alist)))
12880 keywords))
12881 ;; highlight additional reserved words
12882 (setq vhdl-font-lock-keywords-4
12883 (list (list vhdl-reserved-words-regexp 1
12884 'vhdl-font-lock-reserved-words-face)))
12885 ;; highlight everything together
12886 (setq vhdl-font-lock-keywords
12887 (append
12888 vhdl-font-lock-keywords-0
12889 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12890 (when (or vhdl-highlight-forbidden-words
12891 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12892 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12893 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12894 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12895
12896 ;; initialize fontification for VHDL Mode
12897 (vhdl-font-lock-init)
12898
12899 (defun vhdl-fontify-buffer ()
12900 "Re-initialize fontification and fontify buffer."
12901 (interactive)
12902 (setq font-lock-defaults
12903 `(vhdl-font-lock-keywords
12904 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12905 beginning-of-line))
12906 (when (fboundp 'font-lock-unset-defaults)
12907 (font-lock-unset-defaults)) ; not implemented in XEmacs
12908 (font-lock-set-defaults)
12909 (font-lock-mode nil)
12910 (font-lock-mode t))
12911
12912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12913 ;; Initialization for postscript printing
12914
12915 (defun vhdl-ps-print-settings ()
12916 "Initialize custom face and page settings for postscript printing."
12917 ;; define custom face settings
12918 (unless (or (not vhdl-print-customize-faces)
12919 ps-print-color-p)
12920 (set (make-local-variable 'ps-bold-faces)
12921 '(font-lock-keyword-face
12922 font-lock-type-face
12923 vhdl-font-lock-attribute-face
12924 vhdl-font-lock-enumvalue-face
12925 vhdl-font-lock-directive-face))
12926 (set (make-local-variable 'ps-italic-faces)
12927 '(font-lock-comment-face
12928 font-lock-function-name-face
12929 font-lock-type-face
12930 vhdl-font-lock-attribute-face
12931 vhdl-font-lock-enumvalue-face
12932 vhdl-font-lock-directive-face))
12933 (set (make-local-variable 'ps-underlined-faces)
12934 '(font-lock-string-face))
12935 (setq ps-always-build-face-reference t))
12936 ;; define page settings, so that a line containing 79 characters (default)
12937 ;; fits into one column
12938 (when vhdl-print-two-column
12939 (set (make-local-variable 'ps-landscape-mode) t)
12940 (set (make-local-variable 'ps-number-of-columns) 2)
12941 (set (make-local-variable 'ps-font-size) 7.0)
12942 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12943 (set (make-local-variable 'ps-header-font-size) 9.0)
12944 (set (make-local-variable 'ps-header-offset) 12.0)
12945 (when (eq ps-paper-type 'letter)
12946 (set (make-local-variable 'ps-inter-column) 40.0)
12947 (set (make-local-variable 'ps-left-margin) 40.0)
12948 (set (make-local-variable 'ps-right-margin) 40.0))))
12949
12950 (defun vhdl-ps-print-init ()
12951 "Initialize postscript printing."
12952 (if (featurep 'xemacs)
12953 (when (boundp 'ps-print-color-p)
12954 (vhdl-ps-print-settings))
12955 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
12956 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
12957
12958
12959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12960 ;;; Hierarchy browser (using `speedbar.el')
12961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12962 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12963 ;; directory by using the speedbar.
12964
12965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12966 ;; Variables
12967
12968 (defvar vhdl-entity-alist nil
12969 "Cache with entities and corresponding architectures for each
12970 project/directory.")
12971 ;; structure: (parenthesised expression means list of such entries)
12972 ;; (cache-key
12973 ;; (ent-key ent-name ent-file ent-line
12974 ;; (arch-key arch-name arch-file arch-line
12975 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12976 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12977 ;; (lib-name pack-key))
12978 ;; mra-key (lib-name pack-key))
12979
12980 (defvar vhdl-config-alist nil
12981 "Cache with configurations for each project/directory.")
12982 ;; structure: (parenthesised expression means list of such entries)
12983 ;; (cache-key
12984 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12985 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12986 ;; inst-conf-key inst-lib-key)
12987 ;; (lib-name pack-key)))
12988
12989 (defvar vhdl-package-alist nil
12990 "Cache with packages for each project/directory.")
12991 ;; structure: (parenthesised expression means list of such entries)
12992 ;; (cache-key
12993 ;; (pack-key pack-name pack-file pack-line
12994 ;; (comp-key comp-name comp-file comp-line)
12995 ;; (func-key func-name func-file func-line)
12996 ;; (lib-name pack-key)
12997 ;; pack-body-file pack-body-line
12998 ;; (func-key func-name func-body-file func-body-line)
12999 ;; (lib-name pack-key)))
13000
13001 (defvar vhdl-ent-inst-alist nil
13002 "Cache with instantiated entities for each project/directory.")
13003 ;; structure: (parenthesised expression means list of such entries)
13004 ;; (cache-key (inst-ent-key))
13005
13006 (defvar vhdl-file-alist nil
13007 "Cache with design units in each file for each project/directory.")
13008 ;; structure: (parenthesised expression means list of such entries)
13009 ;; (cache-key
13010 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13011 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13012
13013 (defvar vhdl-directory-alist nil
13014 "Cache with source directories for each project.")
13015 ;; structure: (parenthesised expression means list of such entries)
13016 ;; (cache-key (directory))
13017
13018 (defvar vhdl-speedbar-shown-unit-alist nil
13019 "Alist of design units simultaneously open in the current speedbar for each
13020 directory and project.")
13021
13022 (defvar vhdl-speedbar-shown-project-list nil
13023 "List of projects simultaneously open in the current speedbar.")
13024
13025 (defvar vhdl-updated-project-list nil
13026 "List of projects and directories with updated files.")
13027
13028 (defvar vhdl-modified-file-list nil
13029 "List of modified files to be rescanned for hierarchy updating.")
13030
13031 (defvar vhdl-speedbar-hierarchy-depth 0
13032 "Depth of instantiation hierarchy to display.")
13033
13034 (defvar vhdl-speedbar-show-projects nil
13035 "Non-nil means project hierarchy is displayed in speedbar, directory
13036 hierarchy otherwise.")
13037
13038 (defun vhdl-get-end-of-unit ()
13039 "Return position of end of current unit."
13040 (let ((pos (point)))
13041 (save-excursion
13042 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13043 (save-excursion
13044 (goto-char (match-beginning 0))
13045 (vhdl-backward-syntactic-ws)
13046 (and (/= (preceding-char) ?\;) (not (bobp))))))
13047 (re-search-backward "^[ \t]*end\\>" pos 1)
13048 (point))))
13049
13050 (defun vhdl-match-string-downcase (num &optional string)
13051 "Like `match-string-no-properties' with down-casing."
13052 (let ((match (match-string-no-properties num string)))
13053 (and match (downcase match))))
13054
13055
13056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13057 ;; Scan functions
13058
13059 (defun vhdl-scan-context-clause ()
13060 "Scan the context clause that preceeds a design unit."
13061 (let (lib-alist)
13062 (save-excursion
13063 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13064 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13065 (equal "USE" (upcase (match-string 1))))
13066 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13067 (setq lib-alist (cons (cons (match-string-no-properties 1)
13068 (vhdl-match-string-downcase 2))
13069 lib-alist))))))
13070 lib-alist))
13071
13072 (defun vhdl-scan-directory-contents (name &optional project update num-string
13073 non-final)
13074 "Scan contents of VHDL files in directory or file pattern NAME."
13075 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13076 ; (unless (file-directory-p (match-string 1 name))
13077 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13078 (let* ((dir-name (match-string 1 name))
13079 (file-pattern (match-string 2 name))
13080 (is-directory (= 0 (length file-pattern)))
13081 (file-list
13082 (if update
13083 (list name)
13084 (if is-directory
13085 (vhdl-get-source-files t dir-name)
13086 (vhdl-directory-files
13087 dir-name t (wildcard-to-regexp file-pattern)))))
13088 (key (or project dir-name))
13089 (file-exclude-regexp
13090 (or (nth 3 (aget vhdl-project-alist project)) ""))
13091 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13092 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13093 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13094 ent-alist conf-alist pack-alist ent-inst-list file-alist
13095 tmp-list tmp-entry no-files files-exist big-files)
13096 (when (or project update)
13097 (setq ent-alist (aget vhdl-entity-alist key t)
13098 conf-alist (aget vhdl-config-alist key t)
13099 pack-alist (aget vhdl-package-alist key t)
13100 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13101 file-alist (aget vhdl-file-alist key t)))
13102 (when (and (not is-directory) (null file-list))
13103 (message "No such file: \"%s\"" name))
13104 (setq files-exist file-list)
13105 (when file-list
13106 (setq no-files (length file-list))
13107 (message "Scanning %s %s\"%s\"..."
13108 (if is-directory "directory" "files") (or num-string "") name)
13109 ;; exclude files
13110 (unless (equal file-exclude-regexp "")
13111 (let ((case-fold-search nil)
13112 file-tmp-list)
13113 (while file-list
13114 (unless (string-match file-exclude-regexp (car file-list))
13115 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13116 (setq file-list (cdr file-list)))
13117 (setq file-list (nreverse file-tmp-list))))
13118 ;; do for all files
13119 (while file-list
13120 (unless noninteractive
13121 (message "Scanning %s %s\"%s\"... (%2d%s)"
13122 (if is-directory "directory" "files")
13123 (or num-string "") name
13124 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13125 (let ((file-name (abbreviate-file-name (car file-list)))
13126 ent-list arch-list arch-ent-list conf-list
13127 pack-list pack-body-list inst-list inst-ent-list)
13128 ;; scan file
13129 (vhdl-visit-file
13130 file-name nil
13131 (vhdl-prepare-search-2
13132 (save-excursion
13133 ;; scan for design units
13134 (if (and limit-design-file-size
13135 (< limit-design-file-size (buffer-size)))
13136 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13137 (setq big-files t))
13138 ;; scan for entities
13139 (goto-char (point-min))
13140 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13141 (let* ((ent-name (match-string-no-properties 1))
13142 (ent-key (downcase ent-name))
13143 (ent-entry (aget ent-alist ent-key t))
13144 (lib-alist (vhdl-scan-context-clause)))
13145 (if (nth 1 ent-entry)
13146 (vhdl-warning-when-idle
13147 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13148 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13149 file-name (vhdl-current-line))
13150 (setq ent-list (cons ent-key ent-list))
13151 (aput 'ent-alist ent-key
13152 (list ent-name file-name (vhdl-current-line)
13153 (nth 3 ent-entry) (nth 4 ent-entry)
13154 lib-alist)))))
13155 ;; scan for architectures
13156 (goto-char (point-min))
13157 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13158 (let* ((arch-name (match-string-no-properties 1))
13159 (arch-key (downcase arch-name))
13160 (ent-name (match-string-no-properties 2))
13161 (ent-key (downcase ent-name))
13162 (ent-entry (aget ent-alist ent-key t))
13163 (arch-alist (nth 3 ent-entry))
13164 (arch-entry (aget arch-alist arch-key t))
13165 (lib-arch-alist (vhdl-scan-context-clause)))
13166 (if arch-entry
13167 (vhdl-warning-when-idle
13168 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13169 arch-name ent-name (nth 1 arch-entry)
13170 (nth 2 arch-entry) file-name (vhdl-current-line))
13171 (setq arch-list (cons arch-key arch-list)
13172 arch-ent-list (cons ent-key arch-ent-list))
13173 (aput 'arch-alist arch-key
13174 (list arch-name file-name (vhdl-current-line) nil
13175 lib-arch-alist))
13176 (aput 'ent-alist ent-key
13177 (list (or (nth 0 ent-entry) ent-name)
13178 (nth 1 ent-entry) (nth 2 ent-entry)
13179 (vhdl-sort-alist arch-alist)
13180 arch-key (nth 5 ent-entry))))))
13181 ;; scan for configurations
13182 (goto-char (point-min))
13183 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13184 (let* ((conf-name (match-string-no-properties 1))
13185 (conf-key (downcase conf-name))
13186 (conf-entry (aget conf-alist conf-key t))
13187 (ent-name (match-string-no-properties 2))
13188 (ent-key (downcase ent-name))
13189 (lib-alist (vhdl-scan-context-clause))
13190 (conf-line (vhdl-current-line))
13191 (end-of-unit (vhdl-get-end-of-unit))
13192 arch-key comp-conf-list inst-key-list
13193 inst-comp-key inst-ent-key inst-arch-key
13194 inst-conf-key inst-lib-key)
13195 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13196 (setq arch-key (vhdl-match-string-downcase 1)))
13197 (if conf-entry
13198 (vhdl-warning-when-idle
13199 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13200 conf-name ent-name (nth 1 conf-entry)
13201 (nth 2 conf-entry) file-name conf-line)
13202 (setq conf-list (cons conf-key conf-list))
13203 ;; scan for subconfigurations and subentities
13204 (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)
13205 (setq inst-comp-key (vhdl-match-string-downcase 3)
13206 inst-key-list (split-string
13207 (vhdl-match-string-downcase 1)
13208 "[ \t\n]*,[ \t\n]*"))
13209 (vhdl-forward-syntactic-ws)
13210 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13211 (setq
13212 inst-lib-key (vhdl-match-string-downcase 3)
13213 inst-ent-key (and (match-string 2)
13214 (vhdl-match-string-downcase 4))
13215 inst-arch-key (and (match-string 2)
13216 (vhdl-match-string-downcase 6))
13217 inst-conf-key (and (not (match-string 2))
13218 (vhdl-match-string-downcase 4)))
13219 (while inst-key-list
13220 (setq comp-conf-list
13221 (cons (list (car inst-key-list)
13222 inst-comp-key inst-ent-key
13223 inst-arch-key inst-conf-key
13224 inst-lib-key)
13225 comp-conf-list))
13226 (setq inst-key-list (cdr inst-key-list)))))
13227 (aput 'conf-alist conf-key
13228 (list conf-name file-name conf-line ent-key
13229 arch-key comp-conf-list lib-alist)))))
13230 ;; scan for packages
13231 (goto-char (point-min))
13232 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13233 (let* ((pack-name (match-string-no-properties 2))
13234 (pack-key (downcase pack-name))
13235 (is-body (match-string-no-properties 1))
13236 (pack-entry (aget pack-alist pack-key t))
13237 (pack-line (vhdl-current-line))
13238 (end-of-unit (vhdl-get-end-of-unit))
13239 comp-name func-name comp-alist func-alist lib-alist)
13240 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13241 (vhdl-warning-when-idle
13242 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13243 (if is-body " body" "") pack-name
13244 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13245 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13246 file-name (vhdl-current-line))
13247 ;; scan for context clauses
13248 (setq lib-alist (vhdl-scan-context-clause))
13249 ;; scan for component and subprogram declarations/bodies
13250 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13251 (if (equal (upcase (match-string 1)) "COMPONENT")
13252 (setq comp-name (match-string-no-properties 2)
13253 comp-alist
13254 (cons (list (downcase comp-name) comp-name
13255 file-name (vhdl-current-line))
13256 comp-alist))
13257 (setq func-name (match-string-no-properties 2)
13258 func-alist
13259 (cons (list (downcase func-name) func-name
13260 file-name (vhdl-current-line))
13261 func-alist))))
13262 (setq func-alist (nreverse func-alist))
13263 (setq comp-alist (nreverse comp-alist))
13264 (if is-body
13265 (setq pack-body-list (cons pack-key pack-body-list))
13266 (setq pack-list (cons pack-key pack-list)))
13267 (aput
13268 'pack-alist pack-key
13269 (if is-body
13270 (list (or (nth 0 pack-entry) pack-name)
13271 (nth 1 pack-entry) (nth 2 pack-entry)
13272 (nth 3 pack-entry) (nth 4 pack-entry)
13273 (nth 5 pack-entry)
13274 file-name pack-line func-alist lib-alist)
13275 (list pack-name file-name pack-line
13276 comp-alist func-alist lib-alist
13277 (nth 6 pack-entry) (nth 7 pack-entry)
13278 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13279 ;; scan for hierarchy
13280 (if (and limit-hier-file-size
13281 (< limit-hier-file-size (buffer-size)))
13282 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13283 (setq big-files t))
13284 ;; scan for architectures
13285 (goto-char (point-min))
13286 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13287 (let* ((ent-name (match-string-no-properties 2))
13288 (ent-key (downcase ent-name))
13289 (arch-name (match-string-no-properties 1))
13290 (arch-key (downcase arch-name))
13291 (ent-entry (aget ent-alist ent-key t))
13292 (arch-alist (nth 3 ent-entry))
13293 (arch-entry (aget arch-alist arch-key t))
13294 (beg-of-unit (point))
13295 (end-of-unit (vhdl-get-end-of-unit))
13296 (inst-no 0)
13297 inst-alist inst-path)
13298 ;; scan for contained instantiations
13299 (while (and (re-search-forward
13300 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13301 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13302 "component[ \t\n]+\\(\\w+\\)\\|"
13303 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13304 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13305 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13306 (or (not limit-hier-inst-no)
13307 (<= (setq inst-no (1+ inst-no))
13308 limit-hier-inst-no)))
13309 (cond
13310 ;; block/generate beginning found
13311 ((match-string 14)
13312 (setq inst-path
13313 (cons (match-string-no-properties 1) inst-path)))
13314 ;; block/generate end found
13315 ((match-string 16)
13316 (setq inst-path (cdr inst-path)))
13317 ;; instantiation found
13318 (t
13319 (let* ((inst-name (match-string-no-properties 1))
13320 (inst-key (downcase inst-name))
13321 (inst-comp-name
13322 (or (match-string-no-properties 3)
13323 (match-string-no-properties 6)))
13324 (inst-ent-key
13325 (or (and (match-string 8)
13326 (vhdl-match-string-downcase 11))
13327 (and inst-comp-name
13328 (downcase inst-comp-name))))
13329 (inst-arch-key (vhdl-match-string-downcase 13))
13330 (inst-conf-key
13331 (and (not (match-string 8))
13332 (vhdl-match-string-downcase 11)))
13333 (inst-lib-key (vhdl-match-string-downcase 10)))
13334 (goto-char (match-end 1))
13335 (setq inst-list (cons inst-key inst-list)
13336 inst-ent-list
13337 (cons inst-ent-key inst-ent-list))
13338 (setq inst-alist
13339 (append
13340 inst-alist
13341 (list (list inst-key inst-name file-name
13342 (vhdl-current-line) inst-comp-name
13343 inst-ent-key inst-arch-key
13344 inst-conf-key inst-lib-key
13345 (reverse inst-path)))))))))
13346 ;; scan for contained configuration specifications
13347 (goto-char beg-of-unit)
13348 (while (re-search-forward
13349 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13350 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13351 (let* ((inst-comp-name (match-string-no-properties 3))
13352 (inst-ent-key
13353 (and (match-string 6)
13354 (vhdl-match-string-downcase 9)))
13355 (inst-arch-key (vhdl-match-string-downcase 11))
13356 (inst-conf-key
13357 (and (not (match-string 6))
13358 (vhdl-match-string-downcase 9)))
13359 (inst-lib-key (vhdl-match-string-downcase 8))
13360 (inst-key-list
13361 (split-string (vhdl-match-string-downcase 1)
13362 "[ \t\n]*,[ \t\n]*"))
13363 (tmp-inst-alist inst-alist)
13364 inst-entry)
13365 (while tmp-inst-alist
13366 (when (and (or (equal "all" (car inst-key-list))
13367 (member (nth 0 (car tmp-inst-alist))
13368 inst-key-list))
13369 (equal
13370 (downcase
13371 (or (nth 4 (car tmp-inst-alist)) ""))
13372 (downcase inst-comp-name)))
13373 (setq inst-entry (car tmp-inst-alist))
13374 (setq inst-ent-list
13375 (cons (or inst-ent-key (nth 5 inst-entry))
13376 (vhdl-delete
13377 (nth 5 inst-entry) inst-ent-list)))
13378 (setq inst-entry
13379 (list (nth 0 inst-entry) (nth 1 inst-entry)
13380 (nth 2 inst-entry) (nth 3 inst-entry)
13381 (nth 4 inst-entry)
13382 (or inst-ent-key (nth 5 inst-entry))
13383 (or inst-arch-key (nth 6 inst-entry))
13384 inst-conf-key inst-lib-key))
13385 (setcar tmp-inst-alist inst-entry))
13386 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13387 ;; save in cache
13388 (aput 'arch-alist arch-key
13389 (list (nth 0 arch-entry) (nth 1 arch-entry)
13390 (nth 2 arch-entry) inst-alist
13391 (nth 4 arch-entry)))
13392 (aput 'ent-alist ent-key
13393 (list (nth 0 ent-entry) (nth 1 ent-entry)
13394 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13395 (nth 4 ent-entry) (nth 5 ent-entry)))
13396 (when (and limit-hier-inst-no
13397 (> inst-no limit-hier-inst-no))
13398 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13399 (setq big-files t))
13400 (goto-char end-of-unit))))
13401 ;; remember design units for this file
13402 (aput 'file-alist file-name
13403 (list ent-list arch-list arch-ent-list conf-list
13404 pack-list pack-body-list inst-list inst-ent-list))
13405 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13406 (setq file-list (cdr file-list))))
13407 (when (or (and (not project) files-exist)
13408 (and project (not non-final)))
13409 ;; consistency checks:
13410 ;; check whether each architecture has a corresponding entity
13411 (setq tmp-list ent-alist)
13412 (while tmp-list
13413 (when (null (nth 2 (car tmp-list)))
13414 (setq tmp-entry (car (nth 4 (car tmp-list))))
13415 (vhdl-warning-when-idle
13416 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13417 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13418 (nth 3 tmp-entry)))
13419 (setq tmp-list (cdr tmp-list)))
13420 ;; check whether configuration has a corresponding entity/architecture
13421 (setq tmp-list conf-alist)
13422 (while tmp-list
13423 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13424 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13425 (setq tmp-entry (car tmp-list))
13426 (vhdl-warning-when-idle
13427 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13428 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13429 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13430 (setq tmp-entry (car tmp-list))
13431 (vhdl-warning-when-idle
13432 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13433 (nth 1 tmp-entry) (nth 4 tmp-entry)
13434 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13435 (setq tmp-list (cdr tmp-list)))
13436 ;; check whether each package body has a package declaration
13437 (setq tmp-list pack-alist)
13438 (while tmp-list
13439 (when (null (nth 2 (car tmp-list)))
13440 (setq tmp-entry (car tmp-list))
13441 (vhdl-warning-when-idle
13442 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13443 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13444 (setq tmp-list (cdr tmp-list)))
13445 ;; sort lists
13446 (setq ent-alist (vhdl-sort-alist ent-alist))
13447 (setq conf-alist (vhdl-sort-alist conf-alist))
13448 (setq pack-alist (vhdl-sort-alist pack-alist))
13449 ;; remember updated directory/project
13450 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13451 ;; clear directory alists
13452 (unless project
13453 (adelete 'vhdl-entity-alist key)
13454 (adelete 'vhdl-config-alist key)
13455 (adelete 'vhdl-package-alist key)
13456 (adelete 'vhdl-ent-inst-alist key)
13457 (adelete 'vhdl-file-alist key))
13458 ;; put directory contents into cache
13459 (aput 'vhdl-entity-alist key ent-alist)
13460 (aput 'vhdl-config-alist key conf-alist)
13461 (aput 'vhdl-package-alist key pack-alist)
13462 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13463 (aput 'vhdl-file-alist key file-alist)
13464 ;; final messages
13465 (message "Scanning %s %s\"%s\"...done"
13466 (if is-directory "directory" "files") (or num-string "") name)
13467 (unless project (message "Scanning directory...done"))
13468 (when big-files
13469 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13470 ;; save cache when scanned non-interactively
13471 (when (or (not project) (not non-final))
13472 (when (and noninteractive vhdl-speedbar-save-cache)
13473 (vhdl-save-cache key)))
13474 t))
13475
13476 (defun vhdl-scan-project-contents (project)
13477 "Scan the contents of all VHDL files found in the directories and files
13478 of PROJECT."
13479 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13480 (default-dir (vhdl-resolve-env-variable
13481 (nth 1 (aget vhdl-project-alist project))))
13482 (file-exclude-regexp
13483 (or (nth 3 (aget vhdl-project-alist project)) ""))
13484 dir-list-tmp dir dir-name num-dir act-dir recursive)
13485 ;; clear project alists
13486 (adelete 'vhdl-entity-alist project)
13487 (adelete 'vhdl-config-alist project)
13488 (adelete 'vhdl-package-alist project)
13489 (adelete 'vhdl-ent-inst-alist project)
13490 (adelete 'vhdl-file-alist project)
13491 ;; expand directory names by default-directory
13492 (message "Collecting source files...")
13493 (while dir-list
13494 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13495 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13496 (setq recursive (match-string 1 dir)
13497 dir-name (match-string 3 dir))
13498 (setq dir-list-tmp
13499 (cons (concat recursive
13500 (if (file-name-absolute-p dir-name) "" default-dir)
13501 dir-name)
13502 dir-list-tmp))
13503 (setq dir-list (cdr dir-list)))
13504 ;; resolve path wildcards
13505 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13506 ;; expand directories
13507 (while dir-list-tmp
13508 (setq dir (car dir-list-tmp))
13509 ;; get subdirectories
13510 (if (string-match "-r \\(.*[/\\]\\)" dir)
13511 (setq dir-list (append dir-list (vhdl-get-subdirs
13512 (match-string 1 dir))))
13513 (setq dir-list (append dir-list (list dir))))
13514 (setq dir-list-tmp (cdr dir-list-tmp)))
13515 ;; exclude files
13516 (unless (equal file-exclude-regexp "")
13517 (let ((case-fold-search nil))
13518 (while dir-list
13519 (unless (string-match file-exclude-regexp (car dir-list))
13520 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13521 (setq dir-list (cdr dir-list)))
13522 (setq dir-list (nreverse dir-list-tmp))))
13523 (message "Collecting source files...done")
13524 ;; scan for design units for each directory in DIR-LIST
13525 (setq dir-list-tmp nil
13526 num-dir (length dir-list)
13527 act-dir 1)
13528 (while dir-list
13529 (setq dir-name (abbreviate-file-name
13530 (expand-file-name (car dir-list))))
13531 (vhdl-scan-directory-contents dir-name project nil
13532 (format "(%s/%s) " act-dir num-dir)
13533 (cdr dir-list))
13534 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13535 (setq dir-list (cdr dir-list)
13536 act-dir (1+ act-dir)))
13537 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13538 (message "Scanning project \"%s\"...done" project)))
13539
13540 (defun vhdl-update-file-contents (file-name)
13541 "Update hierarchy information by contents of current buffer."
13542 (setq file-name (abbreviate-file-name file-name))
13543 (let* ((dir-name (file-name-directory file-name))
13544 (directory-alist vhdl-directory-alist)
13545 updated)
13546 (while directory-alist
13547 (when (member dir-name (nth 1 (car directory-alist)))
13548 (let* ((vhdl-project (nth 0 (car directory-alist)))
13549 (project (vhdl-project-p))
13550 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13551 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13552 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13553 (ent-inst-list (car (aget vhdl-ent-inst-alist
13554 (or project dir-name) t)))
13555 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13556 (file-entry (aget file-alist file-name t))
13557 (ent-list (nth 0 file-entry))
13558 (arch-list (nth 1 file-entry))
13559 (arch-ent-list (nth 2 file-entry))
13560 (conf-list (nth 3 file-entry))
13561 (pack-list (nth 4 file-entry))
13562 (pack-body-list (nth 5 file-entry))
13563 (inst-ent-list (nth 7 file-entry))
13564 (cache-key (or project dir-name))
13565 arch-alist key ent-key entry)
13566 ;; delete design units previously contained in this file:
13567 ;; entities
13568 (while ent-list
13569 (setq key (car ent-list)
13570 entry (aget ent-alist key t))
13571 (when (equal file-name (nth 1 entry))
13572 (if (nth 3 entry)
13573 (aput 'ent-alist key
13574 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13575 (adelete 'ent-alist key)))
13576 (setq ent-list (cdr ent-list)))
13577 ;; architectures
13578 (while arch-list
13579 (setq key (car arch-list)
13580 ent-key (car arch-ent-list)
13581 entry (aget ent-alist ent-key t)
13582 arch-alist (nth 3 entry))
13583 (when (equal file-name (nth 1 (aget arch-alist key t)))
13584 (adelete 'arch-alist key)
13585 (if (or (nth 1 entry) arch-alist)
13586 (aput 'ent-alist ent-key
13587 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13588 arch-alist (nth 4 entry) (nth 5 entry)))
13589 (adelete 'ent-alist ent-key)))
13590 (setq arch-list (cdr arch-list)
13591 arch-ent-list (cdr arch-ent-list)))
13592 ;; configurations
13593 (while conf-list
13594 (setq key (car conf-list))
13595 (when (equal file-name (nth 1 (aget conf-alist key t)))
13596 (adelete 'conf-alist key))
13597 (setq conf-list (cdr conf-list)))
13598 ;; package declarations
13599 (while pack-list
13600 (setq key (car pack-list)
13601 entry (aget pack-alist key t))
13602 (when (equal file-name (nth 1 entry))
13603 (if (nth 6 entry)
13604 (aput 'pack-alist key
13605 (list (nth 0 entry) nil nil nil nil nil
13606 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13607 (nth 9 entry)))
13608 (adelete 'pack-alist key)))
13609 (setq pack-list (cdr pack-list)))
13610 ;; package bodies
13611 (while pack-body-list
13612 (setq key (car pack-body-list)
13613 entry (aget pack-alist key t))
13614 (when (equal file-name (nth 6 entry))
13615 (if (nth 1 entry)
13616 (aput 'pack-alist key
13617 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13618 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13619 nil nil nil nil))
13620 (adelete 'pack-alist key)))
13621 (setq pack-body-list (cdr pack-body-list)))
13622 ;; instantiated entities
13623 (while inst-ent-list
13624 (setq ent-inst-list
13625 (vhdl-delete (car inst-ent-list) ent-inst-list))
13626 (setq inst-ent-list (cdr inst-ent-list)))
13627 ;; update caches
13628 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13629 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13630 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13631 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13632 ;; scan file
13633 (vhdl-scan-directory-contents file-name project t)
13634 (when (or (and vhdl-speedbar-show-projects project)
13635 (and (not vhdl-speedbar-show-projects) (not project)))
13636 (vhdl-speedbar-refresh project))
13637 (setq updated t)))
13638 (setq directory-alist (cdr directory-alist)))
13639 updated))
13640
13641 (defun vhdl-update-hierarchy ()
13642 "Update directory and hierarchy information in speedbar."
13643 (let ((file-list (reverse vhdl-modified-file-list))
13644 updated)
13645 (when (and vhdl-speedbar-update-on-saving file-list)
13646 (while file-list
13647 (setq updated
13648 (or (vhdl-update-file-contents (car file-list))
13649 updated))
13650 (setq file-list (cdr file-list)))
13651 (setq vhdl-modified-file-list nil)
13652 (vhdl-speedbar-update-current-unit)
13653 (when updated (message "Updating hierarchy...done")))))
13654
13655 ;; structure (parenthesised expression means list of such entries)
13656 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13657 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13658 ;; comp-lib-name level)
13659 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13660 conf-inst-alist level indent
13661 &optional include-top ent-hier)
13662 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13663 entity ENT-KEY."
13664 (let* ((ent-entry (aget ent-alist ent-key t))
13665 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13666 (cdar (last (nth 3 ent-entry)))))
13667 (inst-alist (nth 3 arch-entry))
13668 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13669 hier-list subcomp-list tmp-list inst-key inst-comp-name
13670 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13671 (when (= level 0) (message "Extract design hierarchy..."))
13672 (when include-top
13673 (setq level (1+ level)))
13674 (when (member ent-key ent-hier)
13675 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13676 ;; check configured architecture (already checked during scanning)
13677 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13678 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13679 ;; process all instances
13680 (while inst-alist
13681 (setq inst-entry (car inst-alist)
13682 inst-key (nth 0 inst-entry)
13683 inst-comp-name (nth 4 inst-entry)
13684 inst-conf-key (nth 7 inst-entry))
13685 ;; search entry in configuration's instantiations list
13686 (setq tmp-list conf-inst-alist)
13687 (while (and tmp-list
13688 (not (and (member (nth 0 (car tmp-list))
13689 (list "all" inst-key))
13690 (equal (nth 1 (car tmp-list))
13691 (downcase (or inst-comp-name ""))))))
13692 (setq tmp-list (cdr tmp-list)))
13693 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13694 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13695 (when (and inst-conf-key (not inst-conf-entry))
13696 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13697 ;; determine entity
13698 (setq inst-ent-key
13699 (or (nth 2 (car tmp-list)) ; from configuration
13700 (nth 3 inst-conf-entry) ; from subconfiguration
13701 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13702 ; from configuration spec.
13703 (nth 5 inst-entry))) ; from direct instantiation
13704 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13705 ;; determine architecture
13706 (setq inst-arch-key
13707 (or (nth 3 (car tmp-list)) ; from configuration
13708 (nth 4 inst-conf-entry) ; from subconfiguration
13709 (nth 6 inst-entry) ; from direct instantiation
13710 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13711 ; from configuration spec.
13712 (nth 4 inst-ent-entry) ; MRA
13713 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13714 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13715 ;; set library
13716 (setq inst-lib-key
13717 (or (nth 5 (car tmp-list)) ; from configuration
13718 (nth 8 inst-entry))) ; from direct instantiation
13719 ;; gather information for this instance
13720 (setq comp-entry
13721 (list (nth 1 inst-entry)
13722 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13723 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13724 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13725 (or (nth 0 inst-arch-entry) inst-arch-key)
13726 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13727 (or (nth 0 inst-conf-entry) inst-conf-key)
13728 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13729 inst-lib-key level))
13730 ;; get subcomponent hierarchy
13731 (setq subcomp-list (vhdl-get-hierarchy
13732 ent-alist conf-alist
13733 inst-ent-key inst-arch-key inst-conf-key
13734 (nth 5 inst-conf-entry)
13735 (1+ level) indent nil (cons ent-key ent-hier)))
13736 ;; add to list
13737 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13738 (setq inst-alist (cdr inst-alist)))
13739 (when include-top
13740 (setq hier-list
13741 (cons (list nil nil (nth 0 ent-entry)
13742 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13743 (nth 0 arch-entry)
13744 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13745 nil nil
13746 nil (1- level))
13747 hier-list)))
13748 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13749 hier-list))
13750
13751 (defun vhdl-get-instantiations (ent-key indent)
13752 "Get all instantiations of entity ENT-KEY."
13753 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13754 arch-alist inst-alist ent-inst-list
13755 ent-entry arch-entry inst-entry)
13756 (while ent-alist
13757 (setq ent-entry (car ent-alist))
13758 (setq arch-alist (nth 4 ent-entry))
13759 (while arch-alist
13760 (setq arch-entry (car arch-alist))
13761 (setq inst-alist (nth 4 arch-entry))
13762 (while inst-alist
13763 (setq inst-entry (car inst-alist))
13764 (when (equal ent-key (nth 5 inst-entry))
13765 (setq ent-inst-list
13766 (cons (list (nth 1 inst-entry)
13767 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13768 (nth 1 ent-entry)
13769 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13770 (nth 1 arch-entry)
13771 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13772 ent-inst-list)))
13773 (setq inst-alist (cdr inst-alist)))
13774 (setq arch-alist (cdr arch-alist)))
13775 (setq ent-alist (cdr ent-alist)))
13776 (nreverse ent-inst-list)))
13777
13778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13779 ;; Caching in file
13780
13781 (defun vhdl-save-caches ()
13782 "Save all updated hierarchy caches to file."
13783 (interactive)
13784 (condition-case nil
13785 (when vhdl-speedbar-save-cache
13786 ;; update hierarchy
13787 (vhdl-update-hierarchy)
13788 (let ((project-list vhdl-updated-project-list))
13789 (message "Saving hierarchy caches...")
13790 ;; write updated project caches
13791 (while project-list
13792 (vhdl-save-cache (car project-list))
13793 (setq project-list (cdr project-list)))
13794 (message "Saving hierarchy caches...done")))
13795 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13796 (sit-for 2)))))
13797
13798 (defun vhdl-save-cache (key)
13799 "Save current hierarchy cache to file."
13800 (let* ((orig-buffer (current-buffer))
13801 (vhdl-project key)
13802 (project (vhdl-project-p))
13803 (default-directory key)
13804 (directory (abbreviate-file-name (vhdl-default-directory)))
13805 (file-name (vhdl-resolve-env-variable
13806 (vhdl-replace-string
13807 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13808 (concat
13809 (subst-char-in-string ? ?_ (or project "dir"))
13810 " " (user-login-name)))))
13811 (file-dir-name (expand-file-name file-name directory))
13812 (cache-key (or project directory))
13813 (key (if project "project" "directory")))
13814 (unless (file-exists-p (file-name-directory file-dir-name))
13815 (make-directory (file-name-directory file-dir-name) t))
13816 (if (not (file-writable-p file-dir-name))
13817 (progn (vhdl-warning (format "File not writable: \"%s\""
13818 (abbreviate-file-name file-dir-name)))
13819 (sit-for 2))
13820 (message "Saving cache: \"%s\"" file-dir-name)
13821 (set-buffer (find-file-noselect file-dir-name t t))
13822 (erase-buffer)
13823 (insert ";; -*- Emacs-Lisp -*-\n\n"
13824 ";;; " (file-name-nondirectory file-name)
13825 " - design hierarchy cache file for Emacs VHDL Mode "
13826 vhdl-version "\n")
13827 (insert "\n;; " (if project "Project " "Directory") " : ")
13828 (if project (insert project) (prin1 directory (current-buffer)))
13829 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13830 (user-login-name) "\n\n"
13831 "\n;; version number\n"
13832 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13833 "\n;; " (if project "project" "directory") " name"
13834 "\n(setq " key " ")
13835 (prin1 (or project directory) (current-buffer))
13836 (insert ")\n")
13837 (when (member 'hierarchy vhdl-speedbar-save-cache)
13838 (insert "\n;; entity and architecture cache\n"
13839 "(aput 'vhdl-entity-alist " key " '")
13840 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13841 (insert ")\n\n;; configuration cache\n"
13842 "(aput 'vhdl-config-alist " key " '")
13843 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13844 (insert ")\n\n;; package cache\n"
13845 "(aput 'vhdl-package-alist " key " '")
13846 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13847 (insert ")\n\n;; instantiated entities cache\n"
13848 "(aput 'vhdl-ent-inst-alist " key " '")
13849 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13850 (insert ")\n\n;; design units per file cache\n"
13851 "(aput 'vhdl-file-alist " key " '")
13852 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13853 (when project
13854 (insert ")\n\n;; source directories in project cache\n"
13855 "(aput 'vhdl-directory-alist " key " '")
13856 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13857 (insert ")\n"))
13858 (when (member 'display vhdl-speedbar-save-cache)
13859 (insert "\n;; shown design units cache\n"
13860 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13861 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13862 (current-buffer))
13863 (insert ")\n"))
13864 (setq vhdl-updated-project-list
13865 (delete cache-key vhdl-updated-project-list))
13866 (save-buffer)
13867 (kill-buffer (current-buffer))
13868 (set-buffer orig-buffer))))
13869
13870 (defun vhdl-load-cache (key)
13871 "Load hierarchy cache information from file."
13872 (let* ((vhdl-project key)
13873 (default-directory key)
13874 (directory (vhdl-default-directory))
13875 (file-name (vhdl-resolve-env-variable
13876 (vhdl-replace-string
13877 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13878 (concat
13879 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13880 " " (user-login-name)))))
13881 (file-dir-name (expand-file-name file-name directory))
13882 vhdl-cache-version)
13883 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13884 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13885 (when (file-exists-p file-dir-name)
13886 (condition-case ()
13887 (progn (load-file file-dir-name)
13888 (string< (mapconcat
13889 (lambda (a) (format "%3d" (string-to-number a)))
13890 (split-string "3.33" "\\.") "")
13891 (mapconcat
13892 (lambda (a) (format "%3d" (string-to-number a)))
13893 (split-string vhdl-cache-version "\\.") "")))
13894 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13895 nil))))))
13896
13897 (defun vhdl-require-hierarchy-info ()
13898 "Make sure that hierarchy information is available. Load cache or scan files
13899 if required."
13900 (if (vhdl-project-p)
13901 (unless (or (assoc vhdl-project vhdl-file-alist)
13902 (vhdl-load-cache vhdl-project))
13903 (vhdl-scan-project-contents vhdl-project))
13904 (let ((directory (abbreviate-file-name default-directory)))
13905 (unless (or (assoc directory vhdl-file-alist)
13906 (vhdl-load-cache directory))
13907 (vhdl-scan-directory-contents directory)))))
13908
13909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13910 ;; Add hierarchy browser functionality to speedbar
13911
13912 (defvar vhdl-speedbar-key-map nil
13913 "Keymap used when in the VHDL hierarchy browser mode.")
13914
13915 (defvar vhdl-speedbar-menu-items nil
13916 "Additional menu-items to add to speedbar frame.")
13917
13918 (defun vhdl-speedbar-initialize ()
13919 "Initialize speedbar."
13920 ;; general settings
13921 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13922 ;; VHDL file extensions (extracted from `auto-mode-alist')
13923 (let ((mode-alist auto-mode-alist))
13924 (while mode-alist
13925 (when (eq (cdar mode-alist) 'vhdl-mode)
13926 (speedbar-add-supported-extension (caar mode-alist)))
13927 (setq mode-alist (cdr mode-alist))))
13928 ;; hierarchy browser settings
13929 (when (boundp 'speedbar-mode-functions-list)
13930 ;; special functions
13931 (speedbar-add-mode-functions-list
13932 '("vhdl directory"
13933 (speedbar-item-info . vhdl-speedbar-item-info)
13934 (speedbar-line-directory . speedbar-files-line-path)))
13935 (speedbar-add-mode-functions-list
13936 '("vhdl project"
13937 (speedbar-item-info . vhdl-speedbar-item-info)
13938 (speedbar-line-directory . vhdl-speedbar-line-project)))
13939 ;; keymap
13940 (unless vhdl-speedbar-key-map
13941 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13942 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13943 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13944 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13945 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13946 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13947 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13948 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13949 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13950 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13951 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13952 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13953 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13954 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13955 (let ((key 0))
13956 (while (<= key 9)
13957 (define-key vhdl-speedbar-key-map (int-to-string key)
13958 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13959 (setq key (1+ key)))))
13960 (define-key speedbar-key-map "h"
13961 (lambda () (interactive)
13962 (speedbar-change-initial-expansion-list "vhdl directory")))
13963 (define-key speedbar-key-map "H"
13964 (lambda () (interactive)
13965 (speedbar-change-initial-expansion-list "vhdl project")))
13966 ;; menu
13967 (unless vhdl-speedbar-menu-items
13968 (setq
13969 vhdl-speedbar-menu-items
13970 `(["Edit" speedbar-edit-line t]
13971 ["Expand" speedbar-expand-line
13972 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13973 ["Contract" vhdl-speedbar-contract-level t]
13974 ["Expand All" vhdl-speedbar-expand-all t]
13975 ["Contract All" vhdl-speedbar-contract-all t]
13976 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13977 (while (<= key 9)
13978 (setq menu-list
13979 (cons `[,(if (= key 0) "All" (int-to-string key))
13980 (vhdl-speedbar-set-depth ,key)
13981 :style radio
13982 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13983 :keys ,(int-to-string key)]
13984 menu-list))
13985 (setq key (1+ key)))
13986 (nreverse menu-list))
13987 "--"
13988 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13989 (or (vhdl-speedbar-check-unit 'entity)
13990 (vhdl-speedbar-check-unit 'subprogram))]
13991 ["Place Component" vhdl-speedbar-place-component
13992 (vhdl-speedbar-check-unit 'entity)]
13993 ["Generate Configuration" vhdl-speedbar-configuration
13994 (vhdl-speedbar-check-unit 'architecture)]
13995 ["Select as MRA" vhdl-speedbar-select-mra
13996 (vhdl-speedbar-check-unit 'architecture)]
13997 ["Make" vhdl-speedbar-make-design
13998 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13999 ["Generate Makefile" vhdl-speedbar-generate-makefile
14000 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14001 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14002 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14003 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14004 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14005 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14006 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14007 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14008 ;; hook-ups
14009 (speedbar-add-expansion-list
14010 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14011 vhdl-speedbar-display-directory))
14012 (speedbar-add-expansion-list
14013 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14014 vhdl-speedbar-display-projects))
14015 (setq speedbar-stealthy-function-list
14016 (append
14017 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14018 ("vhdl project" vhdl-speedbar-update-current-project
14019 vhdl-speedbar-update-current-unit)
14020 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14021 ; (speedbar-extension-list-to-regex
14022 ; speedbar-ignored-path-expressions))))
14023 )
14024 speedbar-stealthy-function-list))
14025 (when (eq vhdl-speedbar-display-mode 'directory)
14026 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14027 (when (eq vhdl-speedbar-display-mode 'project)
14028 (setq speedbar-initial-expansion-list-name "vhdl project"))
14029 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14030
14031 (defun vhdl-speedbar (&optional arg)
14032 "Open/close speedbar."
14033 (interactive)
14034 (if (not (fboundp 'speedbar))
14035 (error "WARNING: Speedbar is not available or not installed")
14036 (condition-case ()
14037 (speedbar-frame-mode arg)
14038 (error (error "WARNING: An error occurred while opening speedbar")))))
14039
14040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14041 ;; Display functions
14042
14043 (defvar vhdl-speedbar-last-selected-project nil
14044 "Name of last selected project.")
14045
14046 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14047 (defmacro speedbar-with-writable (&rest forms)
14048 "Allow the buffer to be writable and evaluate FORMS."
14049 (list 'let '((inhibit-read-only t))
14050 (cons 'progn forms)))
14051 (put 'speedbar-with-writable 'lisp-indent-function 0)
14052
14053 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14054 "Display directory and hierarchy information in speedbar."
14055 (setq vhdl-speedbar-show-projects nil)
14056 (setq speedbar-ignored-directory-regexp
14057 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14058 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14059 (setq speedbar-last-selected-file nil)
14060 (speedbar-with-writable
14061 (condition-case nil
14062 (progn
14063 ;; insert directory path
14064 (speedbar-directory-buttons directory depth)
14065 ;; insert subdirectories
14066 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14067 ;; scan and insert hierarchy of current directory
14068 (vhdl-speedbar-insert-dir-hierarchy directory depth
14069 speedbar-power-click)
14070 ;; expand subdirectories
14071 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14072 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14073
14074 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14075 "Display projects and hierarchy information in speedbar."
14076 (setq vhdl-speedbar-show-projects t)
14077 (setq speedbar-ignored-directory-regexp ".")
14078 (setq speedbar-last-selected-file nil)
14079 (setq vhdl-speedbar-last-selected-project nil)
14080 (speedbar-with-writable
14081 (condition-case nil
14082 ;; insert projects
14083 (vhdl-speedbar-insert-projects)
14084 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14085 (setq speedbar-full-text-cache nil)) ; prevent caching
14086
14087 (defun vhdl-speedbar-insert-projects ()
14088 "Insert all projects in speedbar."
14089 (vhdl-speedbar-make-title-line "Projects:")
14090 (let ((project-alist (if vhdl-project-sort
14091 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14092 vhdl-project-alist))
14093 (vhdl-speedbar-update-current-unit nil))
14094 ;; insert projects
14095 (while project-alist
14096 (speedbar-make-tag-line
14097 'angle ?+ 'vhdl-speedbar-expand-project
14098 (caar project-alist) (caar project-alist)
14099 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14100 (setq project-alist (cdr project-alist)))
14101 (setq project-alist vhdl-project-alist)
14102 ;; expand projects
14103 (while project-alist
14104 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14105 (goto-char (point-min))
14106 (when (re-search-forward
14107 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14108 (goto-char (match-end 1))
14109 (speedbar-do-function-pointer)))
14110 (setq project-alist (cdr project-alist))))
14111 ; (vhdl-speedbar-update-current-project)
14112 ; (vhdl-speedbar-update-current-unit nil t)
14113 )
14114
14115 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14116 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14117 otherwise use cached data."
14118 (when (or rescan (and (not (assoc project vhdl-file-alist))
14119 (not (vhdl-load-cache project))))
14120 (vhdl-scan-project-contents project))
14121 ;; insert design hierarchy
14122 (vhdl-speedbar-insert-hierarchy
14123 (aget vhdl-entity-alist project t)
14124 (aget vhdl-config-alist project t)
14125 (aget vhdl-package-alist project t)
14126 (car (aget vhdl-ent-inst-alist project t)) indent)
14127 (insert (int-to-string indent) ":\n")
14128 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14129 (put-text-property (1- (point)) (point) 'invisible nil)
14130 ;; expand design units
14131 (vhdl-speedbar-expand-units project))
14132
14133 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14134 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14135 otherwise use cached data."
14136 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14137 (not (vhdl-load-cache directory))))
14138 (vhdl-scan-directory-contents directory))
14139 ;; insert design hierarchy
14140 (vhdl-speedbar-insert-hierarchy
14141 (aget vhdl-entity-alist directory t)
14142 (aget vhdl-config-alist directory t)
14143 (aget vhdl-package-alist directory t)
14144 (car (aget vhdl-ent-inst-alist directory t)) depth)
14145 ;; expand design units
14146 (vhdl-speedbar-expand-units directory)
14147 (aput 'vhdl-directory-alist directory (list (list directory))))
14148
14149 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14150 ent-inst-list depth)
14151 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14152 (if (not (or ent-alist conf-alist pack-alist))
14153 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14154 (let (ent-entry conf-entry pack-entry)
14155 ;; insert entities
14156 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14157 (while ent-alist
14158 (setq ent-entry (car ent-alist))
14159 (speedbar-make-tag-line
14160 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14161 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14162 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14163 'vhdl-speedbar-entity-face depth)
14164 (unless (nth 2 ent-entry)
14165 (end-of-line 0) (insert "!") (forward-char 1))
14166 (unless (member (nth 0 ent-entry) ent-inst-list)
14167 (end-of-line 0) (insert " (top)") (forward-char 1))
14168 (setq ent-alist (cdr ent-alist)))
14169 ;; insert configurations
14170 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14171 (while conf-alist
14172 (setq conf-entry (car conf-alist))
14173 (speedbar-make-tag-line
14174 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14175 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14176 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14177 'vhdl-speedbar-configuration-face depth)
14178 (setq conf-alist (cdr conf-alist)))
14179 ;; insert packages
14180 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14181 (while pack-alist
14182 (setq pack-entry (car pack-alist))
14183 (vhdl-speedbar-make-pack-line
14184 (nth 0 pack-entry) (nth 1 pack-entry)
14185 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14186 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14187 depth)
14188 (setq pack-alist (cdr pack-alist))))))
14189
14190 (defun vhdl-speedbar-rescan-hierarchy ()
14191 "Rescan hierarchy for the directory or project under the cursor."
14192 (interactive)
14193 (let (key path)
14194 (cond
14195 ;; current project
14196 (vhdl-speedbar-show-projects
14197 (setq key (vhdl-speedbar-line-project))
14198 (vhdl-scan-project-contents key))
14199 ;; top-level directory
14200 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14201 (re-search-forward "[0-9]+:" nil t)
14202 (vhdl-scan-directory-contents
14203 (abbreviate-file-name (speedbar-line-directory))))
14204 ;; current directory
14205 (t (setq path (speedbar-line-directory))
14206 (string-match "^\\(.+[/\\]\\)" path)
14207 (vhdl-scan-directory-contents
14208 (abbreviate-file-name (match-string 1 path)))))
14209 (vhdl-speedbar-refresh key)))
14210
14211 (defun vhdl-speedbar-expand-dirs (directory)
14212 "Expand subdirectories in DIRECTORY according to
14213 `speedbar-shown-directories'."
14214 ;; (nicked from `speedbar-default-directory-list')
14215 (let ((sf (cdr (reverse speedbar-shown-directories)))
14216 (vhdl-speedbar-update-current-unit nil))
14217 (setq speedbar-shown-directories
14218 (list (expand-file-name default-directory)))
14219 (while sf
14220 (when (speedbar-goto-this-file (car sf))
14221 (beginning-of-line)
14222 (when (looking-at "[0-9]+:\\s-*<")
14223 (goto-char (match-end 0))
14224 (speedbar-do-function-pointer)))
14225 (setq sf (cdr sf))))
14226 (vhdl-speedbar-update-current-unit nil t))
14227
14228 (defun vhdl-speedbar-expand-units (key)
14229 "Expand design units in directory/project KEY according to
14230 `vhdl-speedbar-shown-unit-alist'."
14231 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14232 (vhdl-speedbar-update-current-unit nil)
14233 vhdl-updated-project-list)
14234 (adelete 'vhdl-speedbar-shown-unit-alist key)
14235 (vhdl-prepare-search-1
14236 (while unit-alist ; expand units
14237 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14238 (beginning-of-line)
14239 (let ((arch-alist (nth 1 (car unit-alist)))
14240 position)
14241 (when (looking-at "^[0-9]+:\\s-*\\[")
14242 (goto-char (match-end 0))
14243 (setq position (point))
14244 (speedbar-do-function-pointer)
14245 (select-frame speedbar-frame)
14246 (while arch-alist ; expand architectures
14247 (goto-char position)
14248 (when (re-search-forward
14249 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14250 (car arch-alist) "\\>\\)") nil t)
14251 (beginning-of-line)
14252 (when (looking-at "^[0-9]+:\\s-*{")
14253 (goto-char (match-end 0))
14254 (speedbar-do-function-pointer)
14255 (select-frame speedbar-frame)))
14256 (setq arch-alist (cdr arch-alist))))
14257 (setq unit-alist (cdr unit-alist))))))
14258 (vhdl-speedbar-update-current-unit nil t))
14259
14260 (defun vhdl-speedbar-contract-level ()
14261 "Contract current level in current directory/project."
14262 (interactive)
14263 (when (or (save-excursion
14264 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14265 (and (save-excursion
14266 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14267 (re-search-backward
14268 (format "^[0-%d]:\\s-*[[{<]-"
14269 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14270 (goto-char (match-end 0))
14271 (speedbar-do-function-pointer)
14272 (speedbar-center-buffer-smartly)))
14273
14274 (defun vhdl-speedbar-contract-all ()
14275 "Contract all expanded design units in current directory/project."
14276 (interactive)
14277 (if (and vhdl-speedbar-show-projects
14278 (save-excursion (beginning-of-line) (looking-at "^0:")))
14279 (progn (setq vhdl-speedbar-shown-project-list nil)
14280 (vhdl-speedbar-refresh))
14281 (let ((key (vhdl-speedbar-line-key)))
14282 (adelete 'vhdl-speedbar-shown-unit-alist key)
14283 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14284 (when (memq 'display vhdl-speedbar-save-cache)
14285 (add-to-list 'vhdl-updated-project-list key)))))
14286
14287 (defun vhdl-speedbar-expand-all ()
14288 "Expand all design units in current directory/project."
14289 (interactive)
14290 (let* ((key (vhdl-speedbar-line-key))
14291 (ent-alist (aget vhdl-entity-alist key t))
14292 (conf-alist (aget vhdl-config-alist key t))
14293 (pack-alist (aget vhdl-package-alist key t))
14294 arch-alist unit-alist subunit-alist)
14295 (add-to-list 'vhdl-speedbar-shown-project-list key)
14296 (while ent-alist
14297 (setq arch-alist (nth 4 (car ent-alist)))
14298 (setq subunit-alist nil)
14299 (while arch-alist
14300 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14301 (setq arch-alist (cdr arch-alist)))
14302 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14303 (setq ent-alist (cdr ent-alist)))
14304 (while conf-alist
14305 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14306 (setq conf-alist (cdr conf-alist)))
14307 (while pack-alist
14308 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14309 (setq pack-alist (cdr pack-alist)))
14310 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14311 (vhdl-speedbar-refresh)
14312 (when (memq 'display vhdl-speedbar-save-cache)
14313 (add-to-list 'vhdl-updated-project-list key))))
14314
14315 (defun vhdl-speedbar-expand-project (text token indent)
14316 "Expand/contract the project under the cursor."
14317 (cond
14318 ((string-match "+" text) ; expand project
14319 (speedbar-change-expand-button-char ?-)
14320 (unless (member token vhdl-speedbar-shown-project-list)
14321 (setq vhdl-speedbar-shown-project-list
14322 (cons token vhdl-speedbar-shown-project-list)))
14323 (speedbar-with-writable
14324 (save-excursion
14325 (end-of-line) (forward-char 1)
14326 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14327 speedbar-power-click))))
14328 ((string-match "-" text) ; contract project
14329 (speedbar-change-expand-button-char ?+)
14330 (setq vhdl-speedbar-shown-project-list
14331 (delete token vhdl-speedbar-shown-project-list))
14332 (speedbar-delete-subblock indent))
14333 (t (error "Nothing to display")))
14334 (when (equal (selected-frame) speedbar-frame)
14335 (speedbar-center-buffer-smartly)))
14336
14337 (defun vhdl-speedbar-expand-entity (text token indent)
14338 "Expand/contract the entity under the cursor."
14339 (cond
14340 ((string-match "+" text) ; expand entity
14341 (let* ((key (vhdl-speedbar-line-key indent))
14342 (ent-alist (aget vhdl-entity-alist key t))
14343 (ent-entry (aget ent-alist token t))
14344 (arch-alist (nth 3 ent-entry))
14345 (inst-alist (vhdl-get-instantiations token indent))
14346 (subpack-alist (nth 5 ent-entry))
14347 (multiple-arch (> (length arch-alist) 1))
14348 arch-entry inst-entry)
14349 (if (not (or arch-alist inst-alist subpack-alist))
14350 (speedbar-change-expand-button-char ??)
14351 (speedbar-change-expand-button-char ?-)
14352 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14353 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14354 (aput 'unit-alist token nil)
14355 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14356 (speedbar-with-writable
14357 (save-excursion
14358 (end-of-line) (forward-char 1)
14359 ;; insert architectures
14360 (when arch-alist
14361 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14362 (while arch-alist
14363 (setq arch-entry (car arch-alist))
14364 (speedbar-make-tag-line
14365 'curly ?+ 'vhdl-speedbar-expand-architecture
14366 (cons token (nth 0 arch-entry))
14367 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14368 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14369 'vhdl-speedbar-architecture-face (1+ indent))
14370 (when (and multiple-arch
14371 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14372 (end-of-line 0) (insert " (mra)") (forward-char 1))
14373 (setq arch-alist (cdr arch-alist)))
14374 ;; insert instantiations
14375 (when inst-alist
14376 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14377 (while inst-alist
14378 (setq inst-entry (car inst-alist))
14379 (vhdl-speedbar-make-inst-line
14380 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14381 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14382 nil nil nil (1+ indent) 0 " in ")
14383 (setq inst-alist (cdr inst-alist)))
14384 ;; insert required packages
14385 (vhdl-speedbar-insert-subpackages
14386 subpack-alist (1+ indent) indent)))
14387 (when (memq 'display vhdl-speedbar-save-cache)
14388 (add-to-list 'vhdl-updated-project-list key))
14389 (vhdl-speedbar-update-current-unit t t))))
14390 ((string-match "-" text) ; contract entity
14391 (speedbar-change-expand-button-char ?+)
14392 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14393 (let* ((key (vhdl-speedbar-line-key indent))
14394 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14395 (adelete 'unit-alist token)
14396 (if unit-alist
14397 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14398 (adelete 'vhdl-speedbar-shown-unit-alist key))
14399 (speedbar-delete-subblock indent)
14400 (when (memq 'display vhdl-speedbar-save-cache)
14401 (add-to-list 'vhdl-updated-project-list key))))
14402 (t (error "Nothing to display")))
14403 (when (equal (selected-frame) speedbar-frame)
14404 (speedbar-center-buffer-smartly)))
14405
14406 (defun vhdl-speedbar-expand-architecture (text token indent)
14407 "Expand/contract the architecture under the cursor."
14408 (cond
14409 ((string-match "+" text) ; expand architecture
14410 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14411 (ent-alist (aget vhdl-entity-alist key t))
14412 (conf-alist (aget vhdl-config-alist key t))
14413 (hier-alist (vhdl-get-hierarchy
14414 ent-alist conf-alist (car token) (cdr token) nil nil
14415 0 (1- indent)))
14416 (ent-entry (aget ent-alist (car token) t))
14417 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14418 (subpack-alist (nth 4 arch-entry))
14419 entry)
14420 (if (not (or hier-alist subpack-alist))
14421 (speedbar-change-expand-button-char ??)
14422 (speedbar-change-expand-button-char ?-)
14423 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14424 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14425 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14426 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14427 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14428 (speedbar-with-writable
14429 (save-excursion
14430 (end-of-line) (forward-char 1)
14431 ;; insert instance hierarchy
14432 (when hier-alist
14433 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14434 (1+ indent)))
14435 (while hier-alist
14436 (setq entry (car hier-alist))
14437 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14438 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14439 (vhdl-speedbar-make-inst-line
14440 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14441 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14442 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14443 (setq hier-alist (cdr hier-alist)))
14444 ;; insert required packages
14445 (vhdl-speedbar-insert-subpackages
14446 subpack-alist (1+ indent) (1- indent))))
14447 (when (memq 'display vhdl-speedbar-save-cache)
14448 (add-to-list 'vhdl-updated-project-list key))
14449 (vhdl-speedbar-update-current-unit t t))))
14450 ((string-match "-" text) ; contract architecture
14451 (speedbar-change-expand-button-char ?+)
14452 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14453 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14454 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14455 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14456 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14457 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14458 (speedbar-delete-subblock indent)
14459 (when (memq 'display vhdl-speedbar-save-cache)
14460 (add-to-list 'vhdl-updated-project-list key))))
14461 (t (error "Nothing to display")))
14462 (when (equal (selected-frame) speedbar-frame)
14463 (speedbar-center-buffer-smartly)))
14464
14465 (defun vhdl-speedbar-expand-config (text token indent)
14466 "Expand/contract the configuration under the cursor."
14467 (cond
14468 ((string-match "+" text) ; expand configuration
14469 (let* ((key (vhdl-speedbar-line-key indent))
14470 (conf-alist (aget vhdl-config-alist key t))
14471 (conf-entry (aget conf-alist token))
14472 (ent-alist (aget vhdl-entity-alist key t))
14473 (hier-alist (vhdl-get-hierarchy
14474 ent-alist conf-alist (nth 3 conf-entry)
14475 (nth 4 conf-entry) token (nth 5 conf-entry)
14476 0 indent t))
14477 (subpack-alist (nth 6 conf-entry))
14478 entry)
14479 (if (not (or hier-alist subpack-alist))
14480 (speedbar-change-expand-button-char ??)
14481 (speedbar-change-expand-button-char ?-)
14482 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14483 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14484 (aput 'unit-alist token nil)
14485 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14486 (speedbar-with-writable
14487 (save-excursion
14488 (end-of-line) (forward-char 1)
14489 ;; insert instance hierarchy
14490 (when hier-alist
14491 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14492 (while hier-alist
14493 (setq entry (car hier-alist))
14494 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14495 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14496 (vhdl-speedbar-make-inst-line
14497 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14498 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14499 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14500 (setq hier-alist (cdr hier-alist)))
14501 ;; insert required packages
14502 (vhdl-speedbar-insert-subpackages
14503 subpack-alist (1+ indent) indent)))
14504 (when (memq 'display vhdl-speedbar-save-cache)
14505 (add-to-list 'vhdl-updated-project-list key))
14506 (vhdl-speedbar-update-current-unit t t))))
14507 ((string-match "-" text) ; contract configuration
14508 (speedbar-change-expand-button-char ?+)
14509 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14510 (let* ((key (vhdl-speedbar-line-key indent))
14511 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14512 (adelete 'unit-alist token)
14513 (if unit-alist
14514 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14515 (adelete 'vhdl-speedbar-shown-unit-alist key))
14516 (speedbar-delete-subblock indent)
14517 (when (memq 'display vhdl-speedbar-save-cache)
14518 (add-to-list 'vhdl-updated-project-list key))))
14519 (t (error "Nothing to display")))
14520 (when (equal (selected-frame) speedbar-frame)
14521 (speedbar-center-buffer-smartly)))
14522
14523 (defun vhdl-speedbar-expand-package (text token indent)
14524 "Expand/contract the package under the cursor."
14525 (cond
14526 ((string-match "+" text) ; expand package
14527 (let* ((key (vhdl-speedbar-line-key indent))
14528 (pack-alist (aget vhdl-package-alist key t))
14529 (pack-entry (aget pack-alist token t))
14530 (comp-alist (nth 3 pack-entry))
14531 (func-alist (nth 4 pack-entry))
14532 (func-body-alist (nth 8 pack-entry))
14533 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14534 comp-entry func-entry func-body-entry)
14535 (if (not (or comp-alist func-alist subpack-alist))
14536 (speedbar-change-expand-button-char ??)
14537 (speedbar-change-expand-button-char ?-)
14538 ;; add package to `vhdl-speedbar-shown-unit-alist'
14539 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14540 (aput 'unit-alist token nil)
14541 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14542 (speedbar-with-writable
14543 (save-excursion
14544 (end-of-line) (forward-char 1)
14545 ;; insert components
14546 (when comp-alist
14547 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14548 (while comp-alist
14549 (setq comp-entry (car comp-alist))
14550 (speedbar-make-tag-line
14551 nil nil nil
14552 (cons token (nth 0 comp-entry))
14553 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14554 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14555 'vhdl-speedbar-entity-face (1+ indent))
14556 (setq comp-alist (cdr comp-alist)))
14557 ;; insert subprograms
14558 (when func-alist
14559 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14560 (while func-alist
14561 (setq func-entry (car func-alist)
14562 func-body-entry (aget func-body-alist (car func-entry) t))
14563 (when (nth 2 func-entry)
14564 (vhdl-speedbar-make-subprogram-line
14565 (nth 1 func-entry)
14566 (cons (nth 2 func-entry) (nth 3 func-entry))
14567 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14568 (1+ indent)))
14569 (setq func-alist (cdr func-alist)))
14570 ;; insert required packages
14571 (vhdl-speedbar-insert-subpackages
14572 subpack-alist (1+ indent) indent)))
14573 (when (memq 'display vhdl-speedbar-save-cache)
14574 (add-to-list 'vhdl-updated-project-list key))
14575 (vhdl-speedbar-update-current-unit t t))))
14576 ((string-match "-" text) ; contract package
14577 (speedbar-change-expand-button-char ?+)
14578 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14579 (let* ((key (vhdl-speedbar-line-key indent))
14580 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14581 (adelete 'unit-alist token)
14582 (if unit-alist
14583 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14584 (adelete 'vhdl-speedbar-shown-unit-alist key))
14585 (speedbar-delete-subblock indent)
14586 (when (memq 'display vhdl-speedbar-save-cache)
14587 (add-to-list 'vhdl-updated-project-list key))))
14588 (t (error "Nothing to display")))
14589 (when (equal (selected-frame) speedbar-frame)
14590 (speedbar-center-buffer-smartly)))
14591
14592 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14593 "Insert required packages."
14594 (let* ((pack-alist (aget vhdl-package-alist
14595 (vhdl-speedbar-line-key dir-indent) t))
14596 pack-key lib-name pack-entry)
14597 (when subpack-alist
14598 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14599 (while subpack-alist
14600 (setq pack-key (cdar subpack-alist)
14601 lib-name (caar subpack-alist))
14602 (setq pack-entry (aget pack-alist pack-key t))
14603 (vhdl-speedbar-make-subpack-line
14604 (or (nth 0 pack-entry) pack-key) lib-name
14605 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14606 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14607 (setq subpack-alist (cdr subpack-alist)))))
14608
14609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14610 ;; Display help functions
14611
14612 (defvar vhdl-speedbar-update-current-unit t
14613 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14614
14615 (defun vhdl-speedbar-update-current-project ()
14616 "Highlight project that is currently active."
14617 (when (and vhdl-speedbar-show-projects
14618 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14619 (and (boundp 'speedbar-frame)
14620 (frame-live-p speedbar-frame)))
14621 (let ((last-frame (selected-frame))
14622 (project-alist vhdl-project-alist)
14623 pos)
14624 (select-frame speedbar-frame)
14625 (speedbar-with-writable
14626 (save-excursion
14627 (while project-alist
14628 (goto-char (point-min))
14629 (when (re-search-forward
14630 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14631 (put-text-property (match-beginning 1) (match-end 1) 'face
14632 (if (equal (caar project-alist) vhdl-project)
14633 'speedbar-selected-face
14634 'speedbar-directory-face))
14635 (when (equal (caar project-alist) vhdl-project)
14636 (setq pos (1- (match-beginning 1)))))
14637 (setq project-alist (cdr project-alist))))
14638 (when pos (goto-char pos)))
14639 (select-frame last-frame)
14640 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14641 t)
14642
14643 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14644 "Highlight all design units that are contained in the current file.
14645 NO-POSITION non-nil means do not re-position cursor."
14646 (let ((last-frame (selected-frame))
14647 (project-list vhdl-speedbar-shown-project-list)
14648 file-alist pos file-name)
14649 ;; get current file name
14650 (if (fboundp 'speedbar-select-attached-frame)
14651 (speedbar-select-attached-frame)
14652 (select-frame speedbar-attached-frame))
14653 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14654 (when (and vhdl-speedbar-update-current-unit
14655 (or always (not (equal file-name speedbar-last-selected-file))))
14656 (if vhdl-speedbar-show-projects
14657 (while project-list
14658 (setq file-alist (append file-alist (aget vhdl-file-alist
14659 (car project-list) t)))
14660 (setq project-list (cdr project-list)))
14661 (setq file-alist (aget vhdl-file-alist
14662 (abbreviate-file-name default-directory) t)))
14663 (select-frame speedbar-frame)
14664 (set-buffer speedbar-buffer)
14665 (speedbar-with-writable
14666 (vhdl-prepare-search-1
14667 (save-excursion
14668 ;; unhighlight last units
14669 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14670 (vhdl-speedbar-update-units
14671 "\\[.\\] " (nth 0 file-entry)
14672 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14673 (vhdl-speedbar-update-units
14674 "{.} " (nth 1 file-entry)
14675 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14676 (vhdl-speedbar-update-units
14677 "\\[.\\] " (nth 3 file-entry)
14678 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14679 (vhdl-speedbar-update-units
14680 "[]>] " (nth 4 file-entry)
14681 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14682 (vhdl-speedbar-update-units
14683 "\\[.\\].+(" '("body")
14684 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14685 (vhdl-speedbar-update-units
14686 "> " (nth 6 file-entry)
14687 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14688 ;; highlight current units
14689 (let* ((file-entry (aget file-alist file-name t)))
14690 (setq
14691 pos (vhdl-speedbar-update-units
14692 "\\[.\\] " (nth 0 file-entry)
14693 file-name 'vhdl-speedbar-entity-selected-face pos)
14694 pos (vhdl-speedbar-update-units
14695 "{.} " (nth 1 file-entry)
14696 file-name 'vhdl-speedbar-architecture-selected-face pos)
14697 pos (vhdl-speedbar-update-units
14698 "\\[.\\] " (nth 3 file-entry)
14699 file-name 'vhdl-speedbar-configuration-selected-face pos)
14700 pos (vhdl-speedbar-update-units
14701 "[]>] " (nth 4 file-entry)
14702 file-name 'vhdl-speedbar-package-selected-face pos)
14703 pos (vhdl-speedbar-update-units
14704 "\\[.\\].+(" '("body")
14705 file-name 'vhdl-speedbar-package-selected-face pos)
14706 pos (vhdl-speedbar-update-units
14707 "> " (nth 6 file-entry)
14708 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14709 ;; move speedbar so the first highlighted unit is visible
14710 (when (and pos (not no-position))
14711 (goto-char pos)
14712 (speedbar-center-buffer-smartly)
14713 (speedbar-position-cursor-on-line))
14714 (setq speedbar-last-selected-file file-name))
14715 (select-frame last-frame)
14716 t))
14717
14718 (defun vhdl-speedbar-update-units (text unit-list file-name face
14719 &optional pos)
14720 "Help function to highlight design units."
14721 (while unit-list
14722 (goto-char (point-min))
14723 (while (re-search-forward
14724 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14725 (when (equal file-name (car (get-text-property
14726 (match-beginning 1) 'speedbar-token)))
14727 (setq pos (or pos (point-marker)))
14728 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14729 (setq unit-list (cdr unit-list)))
14730 pos)
14731
14732 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14733 ent-name ent-file-marker
14734 arch-name arch-file-marker
14735 conf-name conf-file-marker
14736 lib-name depth offset delimiter)
14737 "Insert instantiation entry."
14738 (let ((start (point))
14739 visible-start)
14740 (insert (int-to-string depth) ":")
14741 (put-text-property start (point) 'invisible t)
14742 (setq visible-start (point))
14743 (insert-char ? (* depth speedbar-indentation-width))
14744 (while (> offset 0)
14745 (insert "|")
14746 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14747 (setq offset (1- offset)))
14748 (put-text-property visible-start (point) 'invisible nil)
14749 (setq start (point))
14750 (insert ">")
14751 (speedbar-make-button start (point) nil nil nil)
14752 (setq visible-start (point))
14753 (insert " ")
14754 (setq start (point))
14755 (if (not inst-name)
14756 (insert "(top)")
14757 (insert inst-name)
14758 (speedbar-make-button
14759 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14760 'vhdl-speedbar-find-file inst-file-marker))
14761 (insert delimiter)
14762 (when ent-name
14763 (setq start (point))
14764 (insert ent-name)
14765 (speedbar-make-button
14766 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14767 'vhdl-speedbar-find-file ent-file-marker)
14768 (when arch-name
14769 (insert " (")
14770 (setq start (point))
14771 (insert arch-name)
14772 (speedbar-make-button
14773 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14774 'vhdl-speedbar-find-file arch-file-marker)
14775 (insert ")"))
14776 (when conf-name
14777 (insert " (")
14778 (setq start (point))
14779 (insert conf-name)
14780 (speedbar-make-button
14781 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14782 'vhdl-speedbar-find-file conf-file-marker)
14783 (insert ")")))
14784 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14785 (setq start (point))
14786 (insert " (" lib-name ")")
14787 (put-text-property (+ 2 start) (1- (point)) 'face
14788 'vhdl-speedbar-library-face))
14789 (insert-char ?\n 1)
14790 (put-text-property visible-start (point) 'invisible nil)))
14791
14792 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14793 body-file-marker depth)
14794 "Insert package entry."
14795 (let ((start (point))
14796 visible-start)
14797 (insert (int-to-string depth) ":")
14798 (put-text-property start (point) 'invisible t)
14799 (setq visible-start (point))
14800 (insert-char ? (* depth speedbar-indentation-width))
14801 (put-text-property visible-start (point) 'invisible nil)
14802 (setq start (point))
14803 (insert "[+]")
14804 (speedbar-make-button
14805 start (point) 'speedbar-button-face 'speedbar-highlight-face
14806 'vhdl-speedbar-expand-package pack-key)
14807 (setq visible-start (point))
14808 (insert-char ? 1 nil)
14809 (setq start (point))
14810 (insert pack-name)
14811 (speedbar-make-button
14812 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14813 'vhdl-speedbar-find-file pack-file-marker)
14814 (unless (car pack-file-marker)
14815 (insert "!"))
14816 (when (car body-file-marker)
14817 (insert " (")
14818 (setq start (point))
14819 (insert "body")
14820 (speedbar-make-button
14821 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14822 'vhdl-speedbar-find-file body-file-marker)
14823 (insert ")"))
14824 (insert-char ?\n 1)
14825 (put-text-property visible-start (point) 'invisible nil)))
14826
14827 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14828 pack-body-file-marker depth)
14829 "Insert used package entry."
14830 (let ((start (point))
14831 visible-start)
14832 (insert (int-to-string depth) ":")
14833 (put-text-property start (point) 'invisible t)
14834 (setq visible-start (point))
14835 (insert-char ? (* depth speedbar-indentation-width))
14836 (put-text-property visible-start (point) 'invisible nil)
14837 (setq start (point))
14838 (insert ">")
14839 (speedbar-make-button start (point) nil nil nil)
14840 (setq visible-start (point))
14841 (insert " ")
14842 (setq start (point))
14843 (insert pack-name)
14844 (speedbar-make-button
14845 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14846 'vhdl-speedbar-find-file pack-file-marker)
14847 (when (car pack-body-file-marker)
14848 (insert " (")
14849 (setq start (point))
14850 (insert "body")
14851 (speedbar-make-button
14852 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14853 'vhdl-speedbar-find-file pack-body-file-marker)
14854 (insert ")"))
14855 (setq start (point))
14856 (insert " (" lib-name ")")
14857 (put-text-property (+ 2 start) (1- (point)) 'face
14858 'vhdl-speedbar-library-face)
14859 (insert-char ?\n 1)
14860 (put-text-property visible-start (point) 'invisible nil)))
14861
14862 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14863 func-body-file-marker
14864 depth)
14865 "Insert subprogram entry."
14866 (let ((start (point))
14867 visible-start)
14868 (insert (int-to-string depth) ":")
14869 (put-text-property start (point) 'invisible t)
14870 (setq visible-start (point))
14871 (insert-char ? (* depth speedbar-indentation-width))
14872 (put-text-property visible-start (point) 'invisible nil)
14873 (setq start (point))
14874 (insert ">")
14875 (speedbar-make-button start (point) nil nil nil)
14876 (setq visible-start (point))
14877 (insert " ")
14878 (setq start (point))
14879 (insert func-name)
14880 (speedbar-make-button
14881 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14882 'vhdl-speedbar-find-file func-file-marker)
14883 (when (car func-body-file-marker)
14884 (insert " (")
14885 (setq start (point))
14886 (insert "body")
14887 (speedbar-make-button
14888 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14889 'vhdl-speedbar-find-file func-body-file-marker)
14890 (insert ")"))
14891 (insert-char ?\n 1)
14892 (put-text-property visible-start (point) 'invisible nil)))
14893
14894 (defun vhdl-speedbar-make-title-line (text &optional depth)
14895 "Insert design unit title entry."
14896 (let ((start (point))
14897 visible-start)
14898 (when depth
14899 (insert (int-to-string depth) ":")
14900 (put-text-property start (point) 'invisible t))
14901 (setq visible-start (point))
14902 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14903 (setq start (point))
14904 (insert text)
14905 (speedbar-make-button start (point) nil nil nil nil)
14906 (insert-char ?\n 1)
14907 (put-text-property visible-start (point) 'invisible nil)))
14908
14909 (defun vhdl-speedbar-insert-dirs (files level)
14910 "Insert subdirectories."
14911 (let ((dirs (car files)))
14912 (while dirs
14913 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14914 (car dirs) 'speedbar-dir-follow nil
14915 'speedbar-directory-face level)
14916 (setq dirs (cdr dirs)))))
14917
14918 (defun vhdl-speedbar-dired (text token indent)
14919 "Speedbar click handler for directory expand button in hierarchy mode."
14920 (cond ((string-match "+" text) ; we have to expand this dir
14921 (setq speedbar-shown-directories
14922 (cons (expand-file-name
14923 (concat (speedbar-line-directory indent) token "/"))
14924 speedbar-shown-directories))
14925 (speedbar-change-expand-button-char ?-)
14926 (speedbar-reset-scanners)
14927 (speedbar-with-writable
14928 (save-excursion
14929 (end-of-line) (forward-char 1)
14930 (vhdl-speedbar-insert-dirs
14931 (speedbar-file-lists
14932 (concat (speedbar-line-directory indent) token "/"))
14933 (1+ indent))
14934 (speedbar-reset-scanners)
14935 (vhdl-speedbar-insert-dir-hierarchy
14936 (abbreviate-file-name
14937 (concat (speedbar-line-directory indent) token "/"))
14938 (1+ indent) speedbar-power-click)))
14939 (vhdl-speedbar-update-current-unit t t))
14940 ((string-match "-" text) ; we have to contract this node
14941 (speedbar-reset-scanners)
14942 (let ((oldl speedbar-shown-directories)
14943 (newl nil)
14944 (td (expand-file-name
14945 (concat (speedbar-line-directory indent) token))))
14946 (while oldl
14947 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14948 (setq newl (cons (car oldl) newl)))
14949 (setq oldl (cdr oldl)))
14950 (setq speedbar-shown-directories (nreverse newl)))
14951 (speedbar-change-expand-button-char ?+)
14952 (speedbar-delete-subblock indent))
14953 (t (error "Nothing to display")))
14954 (when (equal (selected-frame) speedbar-frame)
14955 (speedbar-center-buffer-smartly)))
14956
14957 (defun vhdl-speedbar-item-info ()
14958 "Derive and display information about this line item."
14959 (save-excursion
14960 (beginning-of-line)
14961 ;; skip invisible number info
14962 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14963 (cond
14964 ;; project/directory entry
14965 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14966 (if vhdl-speedbar-show-projects
14967 (message "Project \"%s\"" (match-string-no-properties 1))
14968 (speedbar-files-item-info)))
14969 ;; design unit entry
14970 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14971 (goto-char (match-end 1))
14972 (let ((face (get-text-property (point) 'face)))
14973 (message
14974 "%s \"%s\" in \"%s\""
14975 ;; design unit kind
14976 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14977 (eq face 'vhdl-speedbar-entity-selected-face))
14978 (if (equal (match-string 2) ">") "Component" "Entity"))
14979 ((or (eq face 'vhdl-speedbar-architecture-face)
14980 (eq face 'vhdl-speedbar-architecture-selected-face))
14981 "Architecture")
14982 ((or (eq face 'vhdl-speedbar-configuration-face)
14983 (eq face 'vhdl-speedbar-configuration-selected-face))
14984 "Configuration")
14985 ((or (eq face 'vhdl-speedbar-package-face)
14986 (eq face 'vhdl-speedbar-package-selected-face))
14987 "Package")
14988 ((or (eq face 'vhdl-speedbar-instantiation-face)
14989 (eq face 'vhdl-speedbar-instantiation-selected-face))
14990 "Instantiation")
14991 ((eq face 'vhdl-speedbar-subprogram-face)
14992 "Subprogram")
14993 (t ""))
14994 ;; design unit name
14995 (buffer-substring-no-properties
14996 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14997 (match-end 1))
14998 ;; file name
14999 (file-relative-name
15000 (or (car (get-text-property (point) 'speedbar-token))
15001 "?")
15002 (vhdl-default-directory)))))
15003 (t (message "")))))
15004
15005 (defun vhdl-speedbar-line-text ()
15006 "Calls `speedbar-line-text' and removes text properties."
15007 (let ((string (speedbar-line-text)))
15008 (set-text-properties 0 (length string) nil string)
15009 string))
15010
15011 (defun vhdl-speedbar-higher-text ()
15012 "Get speedbar-line-text of higher level."
15013 (let (depth string)
15014 (save-excursion
15015 (beginning-of-line)
15016 (looking-at "^\\([0-9]+\\):")
15017 (setq depth (string-to-number (match-string 1)))
15018 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15019 (setq string (match-string 1))
15020 (set-text-properties 0 (length string) nil string)
15021 string))))
15022
15023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15024 ;; Help functions
15025
15026 (defun vhdl-speedbar-line-key (&optional indent)
15027 "Get currently displayed directory of project name."
15028 (if vhdl-speedbar-show-projects
15029 (vhdl-speedbar-line-project)
15030 (abbreviate-file-name
15031 (file-name-as-directory (speedbar-line-directory indent)))))
15032
15033 (defun vhdl-speedbar-line-project (&optional indent)
15034 "Get currently displayed project name."
15035 (and vhdl-speedbar-show-projects
15036 (save-excursion
15037 (end-of-line)
15038 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15039 (match-string-no-properties 1))))
15040
15041 (defun vhdl-add-modified-file ()
15042 "Add file to `vhdl-modified-file-list'."
15043 (when vhdl-file-alist
15044 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15045 nil)
15046
15047 (defun vhdl-resolve-paths (path-list)
15048 "Resolve path wildcards in PATH-LIST."
15049 (let (path-list-1 path-list-2 path-beg path-end dir)
15050 ;; eliminate non-existent directories
15051 (while path-list
15052 (setq dir (car path-list))
15053 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15054 (if (file-directory-p (match-string 2 dir))
15055 (setq path-list-1 (cons dir path-list-1))
15056 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15057 (setq path-list (cdr path-list)))
15058 ;; resolve path wildcards
15059 (while path-list-1
15060 (setq dir (car path-list-1))
15061 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15062 (progn
15063 (setq path-beg (match-string 1 dir)
15064 path-end (match-string 5 dir))
15065 (setq path-list-1
15066 (append
15067 (mapcar
15068 (function
15069 (lambda (var) (concat path-beg var path-end)))
15070 (let ((all-list (vhdl-directory-files
15071 (match-string 2 dir) t
15072 (concat "\\<" (wildcard-to-regexp
15073 (match-string 4 dir)))))
15074 dir-list)
15075 (while all-list
15076 (when (file-directory-p (car all-list))
15077 (setq dir-list (cons (car all-list) dir-list)))
15078 (setq all-list (cdr all-list)))
15079 dir-list))
15080 (cdr path-list-1))))
15081 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15082 (when (file-directory-p (match-string 2 dir))
15083 (setq path-list-2 (cons dir path-list-2)))
15084 (setq path-list-1 (cdr path-list-1))))
15085 (nreverse path-list-2)))
15086
15087 (defun vhdl-speedbar-goto-this-unit (directory unit)
15088 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15089 (let ((dest (point)))
15090 (if (and (if vhdl-speedbar-show-projects
15091 (progn (goto-char (point-min)) t)
15092 (speedbar-goto-this-file directory))
15093 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15094 (progn (speedbar-position-cursor-on-line)
15095 t)
15096 (goto-char dest)
15097 nil)))
15098
15099 (defun vhdl-speedbar-find-file (text token indent)
15100 "When user clicks on TEXT, load file with name and position in TOKEN.
15101 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15102 is already shown in a buffer."
15103 (if (not (car token))
15104 (error "ERROR: File cannot be found")
15105 (let ((buffer (get-file-buffer (car token))))
15106 (speedbar-find-file-in-frame (car token))
15107 (when (or vhdl-speedbar-jump-to-unit buffer)
15108 (goto-char (point-min))
15109 (forward-line (1- (cdr token)))
15110 (recenter))
15111 (vhdl-speedbar-update-current-unit t t)
15112 (speedbar-set-timer dframe-update-speed)
15113 (speedbar-maybee-jump-to-attached-frame))))
15114
15115 (defun vhdl-speedbar-port-copy ()
15116 "Copy the port of the entity/component or subprogram under the cursor."
15117 (interactive)
15118 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15119 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15120 (error "ERROR: No entity/component or subprogram under cursor")
15121 (beginning-of-line)
15122 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15123 (condition-case info
15124 (let ((token (get-text-property
15125 (match-beginning 3) 'speedbar-token)))
15126 (vhdl-visit-file (car token) t
15127 (progn (goto-char (point-min))
15128 (forward-line (1- (cdr token)))
15129 (end-of-line)
15130 (if is-entity
15131 (vhdl-port-copy)
15132 (vhdl-subprog-copy)))))
15133 (error (error "ERROR: %s not scanned successfully\n (%s)"
15134 (if is-entity "Port" "Interface") (cadr info))))
15135 (error "ERROR: No entity/component or subprogram on current line")))))
15136
15137 (defun vhdl-speedbar-place-component ()
15138 "Place the entity/component under the cursor as component."
15139 (interactive)
15140 (if (not (vhdl-speedbar-check-unit 'entity))
15141 (error "ERROR: No entity/component under cursor")
15142 (vhdl-speedbar-port-copy)
15143 (if (fboundp 'speedbar-select-attached-frame)
15144 (speedbar-select-attached-frame)
15145 (select-frame speedbar-attached-frame))
15146 (vhdl-compose-place-component)
15147 (select-frame speedbar-frame)))
15148
15149 (defun vhdl-speedbar-configuration ()
15150 "Generate configuration for the architecture under the cursor."
15151 (interactive)
15152 (if (not (vhdl-speedbar-check-unit 'architecture))
15153 (error "ERROR: No architecture under cursor")
15154 (let ((arch-name (vhdl-speedbar-line-text))
15155 (ent-name (vhdl-speedbar-higher-text)))
15156 (if (fboundp 'speedbar-select-attached-frame)
15157 (speedbar-select-attached-frame)
15158 (select-frame speedbar-attached-frame))
15159 (vhdl-compose-configuration ent-name arch-name))))
15160
15161 (defun vhdl-speedbar-select-mra ()
15162 "Select the architecture under the cursor as MRA."
15163 (interactive)
15164 (if (not (vhdl-speedbar-check-unit 'architecture))
15165 (error "ERROR: No architecture under cursor")
15166 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15167 (ent-key (downcase (vhdl-speedbar-higher-text)))
15168 (ent-alist (aget vhdl-entity-alist
15169 (or (vhdl-project-p) default-directory) t))
15170 (ent-entry (aget ent-alist ent-key t)))
15171 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15172 (speedbar-refresh))))
15173
15174 (defun vhdl-speedbar-make-design ()
15175 "Make (compile) design unit or directory/project under the cursor."
15176 (interactive)
15177 (if (not (save-excursion (beginning-of-line)
15178 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15179 (error "ERROR: No primary design unit or directory/project under cursor")
15180 (let ((is-unit (match-string 2))
15181 (unit-name (vhdl-speedbar-line-text))
15182 (vhdl-project (vhdl-speedbar-line-project))
15183 (directory (file-name-as-directory
15184 (or (speedbar-line-file) (speedbar-line-directory)))))
15185 (if (fboundp 'speedbar-select-attached-frame)
15186 (speedbar-select-attached-frame)
15187 (select-frame speedbar-attached-frame))
15188 (let ((default-directory directory))
15189 (vhdl-make (and is-unit unit-name))))))
15190
15191 (defun vhdl-speedbar-generate-makefile ()
15192 "Generate Makefile for directory/project under the cursor."
15193 (interactive)
15194 (let ((vhdl-project (vhdl-speedbar-line-project))
15195 (default-directory (file-name-as-directory
15196 (or (speedbar-line-file) (speedbar-line-directory)))))
15197 (vhdl-generate-makefile)))
15198
15199 (defun vhdl-speedbar-check-unit (design-unit)
15200 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15201 expansion function)."
15202 (save-excursion
15203 (speedbar-position-cursor-on-line)
15204 (cond ((eq design-unit 'entity)
15205 (memq (get-text-property (match-end 0) 'face)
15206 '(vhdl-speedbar-entity-face
15207 vhdl-speedbar-entity-selected-face)))
15208 ((eq design-unit 'architecture)
15209 (memq (get-text-property (match-end 0) 'face)
15210 '(vhdl-speedbar-architecture-face
15211 vhdl-speedbar-architecture-selected-face)))
15212 ((eq design-unit 'subprogram)
15213 (eq (get-text-property (match-end 0) 'face)
15214 'vhdl-speedbar-subprogram-face))
15215 (t nil))))
15216
15217 (defun vhdl-speedbar-set-depth (depth)
15218 "Set hierarchy display depth to DEPTH and refresh speedbar."
15219 (setq vhdl-speedbar-hierarchy-depth depth)
15220 (speedbar-refresh))
15221
15222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15223 ;; Fontification
15224
15225 (defface vhdl-speedbar-entity-face
15226 '((((class color) (background light)) (:foreground "ForestGreen"))
15227 (((class color) (background dark)) (:foreground "PaleGreen")))
15228 "Face used for displaying entity names."
15229 :group 'speedbar-faces)
15230
15231 (defface vhdl-speedbar-architecture-face
15232 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15233 (((class color) (background light)) (:foreground "Blue"))
15234
15235 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15236 "Face used for displaying architecture names."
15237 :group 'speedbar-faces)
15238
15239 (defface vhdl-speedbar-configuration-face
15240 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15241 (((class color) (background dark)) (:foreground "Salmon")))
15242 "Face used for displaying configuration names."
15243 :group 'speedbar-faces)
15244
15245 (defface vhdl-speedbar-package-face
15246 '((((class color) (background light)) (:foreground "Grey50"))
15247 (((class color) (background dark)) (:foreground "Grey80")))
15248 "Face used for displaying package names."
15249 :group 'speedbar-faces)
15250
15251 (defface vhdl-speedbar-library-face
15252 '((((class color) (background light)) (:foreground "Purple"))
15253 (((class color) (background dark)) (:foreground "Orchid1")))
15254 "Face used for displaying library names."
15255 :group 'speedbar-faces)
15256
15257 (defface vhdl-speedbar-instantiation-face
15258 '((((class color) (background light)) (:foreground "Brown"))
15259 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15260 (((class color) (background dark)) (:foreground "Yellow")))
15261 "Face used for displaying instantiation names."
15262 :group 'speedbar-faces)
15263
15264 (defface vhdl-speedbar-subprogram-face
15265 '((((class color) (background light)) (:foreground "Orchid4"))
15266 (((class color) (background dark)) (:foreground "BurlyWood2")))
15267 "Face used for displaying subprogram names."
15268 :group 'speedbar-faces)
15269
15270 (defface vhdl-speedbar-entity-selected-face
15271 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15272 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15273 "Face used for displaying entity names."
15274 :group 'speedbar-faces)
15275
15276 (defface vhdl-speedbar-architecture-selected-face
15277 '((((min-colors 88) (class color) (background light)) (:foreground
15278 "Blue1" :underline t))
15279 (((class color) (background light)) (:foreground "Blue" :underline t))
15280 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15281 "Face used for displaying architecture names."
15282 :group 'speedbar-faces)
15283
15284 (defface vhdl-speedbar-configuration-selected-face
15285 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15286 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15287 "Face used for displaying configuration names."
15288 :group 'speedbar-faces)
15289
15290 (defface vhdl-speedbar-package-selected-face
15291 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15292 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15293 "Face used for displaying package names."
15294 :group 'speedbar-faces)
15295
15296 (defface vhdl-speedbar-instantiation-selected-face
15297 '((((class color) (background light)) (:foreground "Brown" :underline t))
15298 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15299 "Face used for displaying instantiation names."
15300 :group 'speedbar-faces)
15301
15302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15303 ;; Initialization
15304
15305 ;; add speedbar
15306 (when (fboundp 'speedbar)
15307 (condition-case ()
15308 (when (and vhdl-speedbar-auto-open
15309 (not (and (boundp 'speedbar-frame)
15310 (frame-live-p speedbar-frame))))
15311 (speedbar-frame-mode 1)
15312 (if (fboundp 'speedbar-select-attached-frame)
15313 (speedbar-select-attached-frame)
15314 (select-frame speedbar-attached-frame)))
15315 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15316
15317 ;; initialize speedbar
15318 (if (not (boundp 'speedbar-frame))
15319 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15320 (vhdl-speedbar-initialize)
15321 (when speedbar-frame (vhdl-speedbar-refresh)))
15322
15323
15324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15325 ;;; Structural composition
15326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15327
15328 (defun vhdl-get-components-package-name ()
15329 "Return the name of the components package."
15330 (let ((project (vhdl-project-p)))
15331 (if project
15332 (vhdl-replace-string (car vhdl-components-package-name)
15333 (subst-char-in-string ? ?_ project))
15334 (cdr vhdl-components-package-name))))
15335
15336 (defun vhdl-compose-new-component ()
15337 "Create entity and architecture for new component."
15338 (interactive)
15339 (let* ((case-fold-search t)
15340 (ent-name (read-from-minibuffer "entity name: "
15341 nil vhdl-minibuffer-local-map))
15342 (arch-name
15343 (if (equal (cdr vhdl-compose-architecture-name) "")
15344 (read-from-minibuffer "architecture name: "
15345 nil vhdl-minibuffer-local-map)
15346 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15347 ent-file-name arch-file-name ent-buffer arch-buffer project)
15348 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15349 ;; open entity file
15350 (unless (eq vhdl-compose-create-files 'none)
15351 (setq ent-file-name
15352 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15353 "." (file-name-extension (buffer-file-name))))
15354 (when (and (file-exists-p ent-file-name)
15355 (not (y-or-n-p (concat "File \"" ent-file-name
15356 "\" exists; overwrite? "))))
15357 (error "ERROR: Creating component...aborted"))
15358 (find-file ent-file-name)
15359 (erase-buffer)
15360 (set-buffer-modified-p nil))
15361 ;; insert header
15362 (if vhdl-compose-include-header
15363 (progn (vhdl-template-header)
15364 (goto-char (point-max)))
15365 (vhdl-comment-display-line) (insert "\n\n"))
15366 ;; insert library clause
15367 (vhdl-template-package-std-logic-1164)
15368 (when vhdl-use-components-package
15369 (insert "\n")
15370 (vhdl-template-standard-package (vhdl-work-library)
15371 (vhdl-get-components-package-name)))
15372 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15373 ;; insert entity declaration
15374 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15375 (vhdl-insert-keyword " IS\n")
15376 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15377 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15378 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15379 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15380 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15381 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15382 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15383 (vhdl-insert-keyword "END ")
15384 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15385 (insert ent-name ";\n\n")
15386 (vhdl-comment-display-line) (insert "\n")
15387 ;; open architecture file
15388 (if (not (eq vhdl-compose-create-files 'separate))
15389 (insert "\n")
15390 (setq ent-buffer (current-buffer))
15391 (setq arch-file-name
15392 (concat (vhdl-replace-string vhdl-architecture-file-name
15393 (concat ent-name " " arch-name) t)
15394 "." (file-name-extension (buffer-file-name))))
15395 (when (and (file-exists-p arch-file-name)
15396 (not (y-or-n-p (concat "File \"" arch-file-name
15397 "\" exists; overwrite? "))))
15398 (error "ERROR: Creating component...aborted"))
15399 (find-file arch-file-name)
15400 (erase-buffer)
15401 (set-buffer-modified-p nil)
15402 ;; insert header
15403 (if vhdl-compose-include-header
15404 (progn (vhdl-template-header)
15405 (goto-char (point-max)))
15406 (vhdl-comment-display-line) (insert "\n\n")))
15407 ;; insert architecture body
15408 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15409 (vhdl-insert-keyword " OF ") (insert ent-name)
15410 (vhdl-insert-keyword " IS\n\n")
15411 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15412 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15413 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15414 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15415 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15416 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15417 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15418 (vhdl-insert-keyword "BEGIN")
15419 (when vhdl-self-insert-comments
15420 (insert " -- ")
15421 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15422 (insert arch-name))
15423 (insert "\n\n")
15424 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15425 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15426 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15427 (vhdl-insert-keyword "END ")
15428 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15429 (insert arch-name ";\n\n")
15430 ;; insert footer and save
15431 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15432 (vhdl-template-footer)
15433 (vhdl-comment-display-line) (insert "\n"))
15434 (goto-char (point-min))
15435 (setq arch-buffer (current-buffer))
15436 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15437 (set-buffer arch-buffer) (save-buffer)
15438 (message "%s"
15439 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15440 (and ent-file-name
15441 (format "\n File created: \"%s\"" ent-file-name))
15442 (and arch-file-name
15443 (format "\n File created: \"%s\"" arch-file-name))))))
15444
15445 (defun vhdl-compose-place-component ()
15446 "Place new component by pasting current port as component declaration and
15447 component instantiation."
15448 (interactive)
15449 (if (not vhdl-port-list)
15450 (error "ERROR: No port has been read")
15451 (save-excursion
15452 (vhdl-prepare-search-2
15453 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15454 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15455 (error "ERROR: No architecture found"))
15456 (let* ((ent-name (match-string 1))
15457 (ent-file-name
15458 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15459 "." (file-name-extension (buffer-file-name))))
15460 (orig-buffer (current-buffer)))
15461 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15462 ;; place component declaration
15463 (unless (or vhdl-use-components-package
15464 (vhdl-use-direct-instantiation)
15465 (save-excursion
15466 (re-search-forward
15467 (concat "^\\s-*component\\s-+"
15468 (car vhdl-port-list) "\\>") nil t)))
15469 (re-search-forward "^begin\\>" nil)
15470 (beginning-of-line)
15471 (skip-chars-backward " \t\n")
15472 (insert "\n\n") (indent-to vhdl-basic-offset)
15473 (vhdl-port-paste-component t))
15474 ;; place component instantiation
15475 (re-search-forward "^end\\>" nil)
15476 (beginning-of-line)
15477 (skip-chars-backward " \t\n")
15478 (insert "\n\n") (indent-to vhdl-basic-offset)
15479 (vhdl-port-paste-instance nil t t)
15480 ;; place use clause for used packages
15481 (when (nth 3 vhdl-port-list)
15482 ;; open entity file
15483 (when (file-exists-p ent-file-name)
15484 (find-file ent-file-name))
15485 (goto-char (point-min))
15486 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15487 (error "ERROR: Entity not found: \"%s\"" ent-name))
15488 (goto-char (match-beginning 0))
15489 (if (and (save-excursion
15490 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15491 (match-string 1))
15492 (progn (goto-char (match-end 0))
15493 (beginning-of-line 2))
15494 (insert "\n")
15495 (backward-char))
15496 (vhdl-port-paste-context-clause)
15497 (switch-to-buffer orig-buffer))
15498 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15499
15500 (defun vhdl-compose-wire-components ()
15501 "Connect components."
15502 (interactive)
15503 (save-excursion
15504 (vhdl-prepare-search-2
15505 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15506 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15507 (error "ERROR: No architecture found"))
15508 (let* ((ent-name (match-string 1))
15509 (ent-file-name
15510 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15511 "." (file-name-extension (buffer-file-name))))
15512 (arch-decl-pos (point-marker))
15513 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15514 (arch-end-pos (re-search-forward "^end\\>" nil))
15515 (pack-name (vhdl-get-components-package-name))
15516 (pack-file-name
15517 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15518 "." (file-name-extension (buffer-file-name))))
15519 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15520 port-alist generic-alist inst-alist
15521 signal-name signal-entry signal-alist local-list written-list
15522 single-in-list multi-in-list single-out-list multi-out-list
15523 constant-name constant-entry constant-alist single-list multi-list
15524 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15525 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15526 signal-beg-pos signal-pos
15527 constant-temp-pos port-temp-pos signal-temp-pos)
15528 (message "Wiring components...")
15529 ;; process all instances
15530 (goto-char arch-stat-pos)
15531 (while (re-search-forward
15532 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15533 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15534 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15535 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15536 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15537 (setq inst-name (match-string-no-properties 1)
15538 comp-name (match-string-no-properties 4)
15539 comp-ent-name (match-string-no-properties 12)
15540 has-generic (or (match-string 7) (match-string 17)))
15541 ;; get port ...
15542 (if comp-name
15543 ;; ... from component declaration
15544 (vhdl-visit-file
15545 (when vhdl-use-components-package pack-file-name) t
15546 (save-excursion
15547 (goto-char (point-min))
15548 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15549 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15550 (vhdl-port-copy)))
15551 ;; ... from entity declaration (direct instantiation)
15552 (setq comp-ent-file-name
15553 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15554 "." (file-name-extension (buffer-file-name))))
15555 (vhdl-visit-file
15556 comp-ent-file-name t
15557 (save-excursion
15558 (goto-char (point-min))
15559 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15560 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15561 (vhdl-port-copy))))
15562 (vhdl-port-flatten t)
15563 (setq generic-alist (nth 1 vhdl-port-list)
15564 port-alist (nth 2 vhdl-port-list)
15565 vhdl-port-list nil)
15566 (setq constant-alist nil
15567 signal-alist nil)
15568 (when has-generic
15569 ;; process all constants in generic map
15570 (vhdl-forward-syntactic-ws)
15571 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15572 (setq constant-name (match-string-no-properties 3))
15573 (setq constant-entry
15574 (cons constant-name
15575 (if (match-string 1)
15576 (or (aget generic-alist (match-string 2) t)
15577 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15578 (cdar generic-alist))))
15579 (setq constant-alist (cons constant-entry constant-alist))
15580 (setq constant-name (downcase constant-name))
15581 (if (or (member constant-name single-list)
15582 (member constant-name multi-list))
15583 (progn (setq single-list (delete constant-name single-list))
15584 (add-to-list 'multi-list constant-name))
15585 (add-to-list 'single-list constant-name))
15586 (unless (match-string 1)
15587 (setq generic-alist (cdr generic-alist)))
15588 (vhdl-forward-syntactic-ws))
15589 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15590 ;; process all signals in port map
15591 (vhdl-forward-syntactic-ws)
15592 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15593 (setq signal-name (match-string-no-properties 3))
15594 (setq signal-entry (cons signal-name
15595 (if (match-string 1)
15596 (or (aget port-alist (match-string 2) t)
15597 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15598 (cdar port-alist))))
15599 (setq signal-alist (cons signal-entry signal-alist))
15600 (setq signal-name (downcase signal-name))
15601 (if (equal (upcase (nth 2 signal-entry)) "IN")
15602 ;; input signal
15603 (cond
15604 ((member signal-name local-list)
15605 nil)
15606 ((or (member signal-name single-out-list)
15607 (member signal-name multi-out-list))
15608 (setq single-out-list (delete signal-name single-out-list))
15609 (setq multi-out-list (delete signal-name multi-out-list))
15610 (add-to-list 'local-list signal-name))
15611 ((member signal-name single-in-list)
15612 (setq single-in-list (delete signal-name single-in-list))
15613 (add-to-list 'multi-in-list signal-name))
15614 ((not (member signal-name multi-in-list))
15615 (add-to-list 'single-in-list signal-name)))
15616 ;; output signal
15617 (cond
15618 ((member signal-name local-list)
15619 nil)
15620 ((or (member signal-name single-in-list)
15621 (member signal-name multi-in-list))
15622 (setq single-in-list (delete signal-name single-in-list))
15623 (setq multi-in-list (delete signal-name multi-in-list))
15624 (add-to-list 'local-list signal-name))
15625 ((member signal-name single-out-list)
15626 (setq single-out-list (delete signal-name single-out-list))
15627 (add-to-list 'multi-out-list signal-name))
15628 ((not (member signal-name multi-out-list))
15629 (add-to-list 'single-out-list signal-name))))
15630 (unless (match-string 1)
15631 (setq port-alist (cdr port-alist)))
15632 (vhdl-forward-syntactic-ws))
15633 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15634 (nreverse signal-alist)) inst-alist)))
15635 ;; prepare signal insertion
15636 (vhdl-goto-marker arch-decl-pos)
15637 (forward-line 1)
15638 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15639 (setq signal-pos (point-marker))
15640 (while (progn (vhdl-forward-syntactic-ws)
15641 (looking-at "signal\\>"))
15642 (beginning-of-line 2)
15643 (delete-region signal-pos (point)))
15644 (setq signal-beg-pos signal-pos)
15645 ;; open entity file
15646 (when (file-exists-p ent-file-name)
15647 (find-file ent-file-name))
15648 (goto-char (point-min))
15649 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15650 (error "ERROR: Entity not found: \"%s\"" ent-name))
15651 ;; prepare generic clause insertion
15652 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15653 (match-string 1))
15654 (goto-char (match-beginning 0))
15655 (indent-to vhdl-basic-offset)
15656 (insert "generic ();\n\n")
15657 (backward-char 4))
15658 (backward-char)
15659 (setq generic-pos (point-marker))
15660 (forward-sexp) (end-of-line)
15661 (delete-region generic-pos (point)) (delete-char 1)
15662 (insert "(\n")
15663 (when multi-list
15664 (insert "\n")
15665 (indent-to (* 2 vhdl-basic-offset))
15666 (insert "-- global generics\n"))
15667 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15668 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15669 ;; prepare port clause insertion
15670 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15671 (match-string 1))
15672 (goto-char (match-beginning 0))
15673 (indent-to vhdl-basic-offset)
15674 (insert "port ();\n\n")
15675 (backward-char 4))
15676 (backward-char)
15677 (setq port-in-pos (point-marker))
15678 (forward-sexp) (end-of-line)
15679 (delete-region port-in-pos (point)) (delete-char 1)
15680 (insert "(\n")
15681 (when (or multi-in-list multi-out-list)
15682 (insert "\n")
15683 (indent-to (* 2 vhdl-basic-offset))
15684 (insert "-- global ports\n"))
15685 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15686 port-out-pos (point-marker) port-inst-pos (point-marker)
15687 port-end-pos (point-marker))
15688 ;; insert generics, ports and signals
15689 (setq inst-alist (nreverse inst-alist))
15690 (while inst-alist
15691 (setq inst-name (nth 0 (car inst-alist))
15692 constant-alist (nth 1 (car inst-alist))
15693 signal-alist (nth 2 (car inst-alist))
15694 constant-temp-pos generic-inst-pos
15695 port-temp-pos port-inst-pos
15696 signal-temp-pos signal-pos)
15697 ;; generics
15698 (while constant-alist
15699 (setq constant-name (downcase (caar constant-alist))
15700 constant-entry (car constant-alist))
15701 (cond ((member constant-name written-list)
15702 nil)
15703 ((member constant-name multi-list)
15704 (vhdl-goto-marker generic-pos)
15705 (setq generic-end-pos
15706 (vhdl-max-marker
15707 generic-end-pos
15708 (vhdl-compose-insert-generic constant-entry)))
15709 (setq generic-pos (point-marker))
15710 (add-to-list 'written-list constant-name))
15711 (t
15712 (vhdl-goto-marker
15713 (vhdl-max-marker generic-inst-pos generic-pos))
15714 (setq generic-end-pos
15715 (vhdl-compose-insert-generic constant-entry))
15716 (setq generic-inst-pos (point-marker))
15717 (add-to-list 'written-list constant-name)))
15718 (setq constant-alist (cdr constant-alist)))
15719 (when (/= constant-temp-pos generic-inst-pos)
15720 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15721 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15722 (insert "-- generics for \"" inst-name "\"\n")
15723 (vhdl-goto-marker generic-inst-pos))
15724 ;; ports and signals
15725 (while signal-alist
15726 (setq signal-name (downcase (caar signal-alist))
15727 signal-entry (car signal-alist))
15728 (cond ((member signal-name written-list)
15729 nil)
15730 ((member signal-name multi-in-list)
15731 (vhdl-goto-marker port-in-pos)
15732 (setq port-end-pos
15733 (vhdl-max-marker
15734 port-end-pos (vhdl-compose-insert-port signal-entry)))
15735 (setq port-in-pos (point-marker))
15736 (add-to-list 'written-list signal-name))
15737 ((member signal-name multi-out-list)
15738 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15739 (setq port-end-pos
15740 (vhdl-max-marker
15741 port-end-pos (vhdl-compose-insert-port signal-entry)))
15742 (setq port-out-pos (point-marker))
15743 (add-to-list 'written-list signal-name))
15744 ((or (member signal-name single-in-list)
15745 (member signal-name single-out-list))
15746 (vhdl-goto-marker
15747 (vhdl-max-marker
15748 port-inst-pos
15749 (vhdl-max-marker port-out-pos port-in-pos)))
15750 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15751 (setq port-inst-pos (point-marker))
15752 (add-to-list 'written-list signal-name))
15753 ((equal (upcase (nth 2 signal-entry)) "OUT")
15754 (vhdl-goto-marker signal-pos)
15755 (vhdl-compose-insert-signal signal-entry)
15756 (setq signal-pos (point-marker))
15757 (add-to-list 'written-list signal-name)))
15758 (setq signal-alist (cdr signal-alist)))
15759 (when (/= port-temp-pos port-inst-pos)
15760 (vhdl-goto-marker
15761 (vhdl-max-marker port-temp-pos
15762 (vhdl-max-marker port-in-pos port-out-pos)))
15763 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15764 (insert "-- ports to \"" inst-name "\"\n")
15765 (vhdl-goto-marker port-inst-pos))
15766 (when (/= signal-temp-pos signal-pos)
15767 (vhdl-goto-marker signal-temp-pos)
15768 (insert "\n") (indent-to vhdl-basic-offset)
15769 (insert "-- outputs of \"" inst-name "\"\n")
15770 (vhdl-goto-marker signal-pos))
15771 (setq inst-alist (cdr inst-alist)))
15772 ;; finalize generic/port clause
15773 (vhdl-goto-marker generic-end-pos) (backward-char)
15774 (when (= generic-beg-pos generic-end-pos)
15775 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15776 (insert ";") (backward-char))
15777 (insert ")")
15778 (vhdl-goto-marker port-end-pos) (backward-char)
15779 (when (= port-beg-pos port-end-pos)
15780 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15781 (insert ";") (backward-char))
15782 (insert ")")
15783 ;; align everything
15784 (when vhdl-auto-align
15785 (vhdl-goto-marker generic-beg-pos)
15786 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15787 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15788 (vhdl-goto-marker signal-beg-pos)
15789 (vhdl-align-region-groups signal-beg-pos signal-pos))
15790 (switch-to-buffer (marker-buffer signal-beg-pos))
15791 (message "Wiring components...done")))))
15792
15793 (defun vhdl-compose-insert-generic (entry)
15794 "Insert ENTRY as generic declaration."
15795 (let (pos)
15796 (indent-to (* 2 vhdl-basic-offset))
15797 (insert (nth 0 entry) " : " (nth 1 entry))
15798 (when (nth 2 entry)
15799 (insert " := " (nth 2 entry)))
15800 (insert ";")
15801 (setq pos (point-marker))
15802 (when (and vhdl-include-port-comments (nth 3 entry))
15803 (vhdl-comment-insert-inline (nth 3 entry) t))
15804 (insert "\n")
15805 pos))
15806
15807 (defun vhdl-compose-insert-port (entry)
15808 "Insert ENTRY as port declaration."
15809 (let (pos)
15810 (indent-to (* 2 vhdl-basic-offset))
15811 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15812 (setq pos (point-marker))
15813 (when (and vhdl-include-port-comments (nth 4 entry))
15814 (vhdl-comment-insert-inline (nth 4 entry) t))
15815 (insert "\n")
15816 pos))
15817
15818 (defun vhdl-compose-insert-signal (entry)
15819 "Insert ENTRY as signal declaration."
15820 (indent-to vhdl-basic-offset)
15821 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15822 (when (and vhdl-include-port-comments (nth 4 entry))
15823 (vhdl-comment-insert-inline (nth 4 entry) t))
15824 (insert "\n"))
15825
15826 (defun vhdl-compose-components-package ()
15827 "Generate a package containing component declarations for all entities in the
15828 current project/directory."
15829 (interactive)
15830 (vhdl-require-hierarchy-info)
15831 (let* ((project (vhdl-project-p))
15832 (pack-name (vhdl-get-components-package-name))
15833 (pack-file-name
15834 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15835 "." (file-name-extension (buffer-file-name))))
15836 (ent-alist (aget vhdl-entity-alist
15837 (or project default-directory) t))
15838 (lazy-lock-minimum-size 0)
15839 clause-pos component-pos)
15840 (message "Generating components package \"%s\"..." pack-name)
15841 ;; open package file
15842 (when (and (file-exists-p pack-file-name)
15843 (not (y-or-n-p (concat "File \"" pack-file-name
15844 "\" exists; overwrite? "))))
15845 (error "ERROR: Generating components package...aborted"))
15846 (find-file pack-file-name)
15847 (erase-buffer)
15848 ;; insert header
15849 (if vhdl-compose-include-header
15850 (progn (vhdl-template-header
15851 (concat "Components package (generated by Emacs VHDL Mode "
15852 vhdl-version ")"))
15853 (goto-char (point-max)))
15854 (vhdl-comment-display-line) (insert "\n\n"))
15855 ;; insert std_logic_1164 package
15856 (vhdl-template-package-std-logic-1164)
15857 (insert "\n") (setq clause-pos (point-marker))
15858 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15859 ;; insert package declaration
15860 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15861 (vhdl-insert-keyword " IS\n\n")
15862 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15863 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15864 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15865 (indent-to vhdl-basic-offset)
15866 (setq component-pos (point-marker))
15867 (insert "\n\n") (vhdl-insert-keyword "END ")
15868 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15869 (insert pack-name ";\n\n")
15870 ;; insert footer
15871 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15872 (vhdl-template-footer)
15873 (vhdl-comment-display-line) (insert "\n"))
15874 ;; insert component declarations
15875 (while ent-alist
15876 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15877 (progn (goto-char (point-min))
15878 (forward-line (1- (nth 3 (car ent-alist))))
15879 (end-of-line)
15880 (vhdl-port-copy)))
15881 (goto-char component-pos)
15882 (vhdl-port-paste-component t)
15883 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15884 (setq component-pos (point-marker))
15885 (goto-char clause-pos)
15886 (vhdl-port-paste-context-clause pack-name)
15887 (setq clause-pos (point-marker))
15888 (setq ent-alist (cdr ent-alist)))
15889 (goto-char (point-min))
15890 (save-buffer)
15891 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15892 pack-name pack-file-name)))
15893
15894 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15895 &optional insert-conf)
15896 "Generate block configuration for architecture."
15897 (let ((margin (current-indentation))
15898 (beg (point-at-bol))
15899 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15900 ;; insert block configuration (for architecture)
15901 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15902 (setq margin (+ margin vhdl-basic-offset))
15903 ;; process all instances
15904 (while inst-alist
15905 (setq inst-entry (car inst-alist))
15906 ;; is component?
15907 (when (nth 4 inst-entry)
15908 (setq insert-conf t)
15909 (setq inst-path (nth 9 inst-entry))
15910 ;; skip common path with previous instance
15911 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15912 (setq inst-path (cdr inst-path)
15913 inst-prev-path (cdr inst-prev-path)))
15914 ;; insert block configuration end (for previous block/generate)
15915 (while inst-prev-path
15916 (setq margin (- margin vhdl-basic-offset))
15917 (indent-to margin)
15918 (vhdl-insert-keyword "END FOR;\n")
15919 (setq inst-prev-path (cdr inst-prev-path)))
15920 ;; insert block configuration beginning (for current block/generate)
15921 (indent-to margin)
15922 (while inst-path
15923 (setq margin (+ margin vhdl-basic-offset))
15924 (vhdl-insert-keyword "FOR ")
15925 (insert (car inst-path) "\n")
15926 (indent-to margin)
15927 (setq inst-path (cdr inst-path)))
15928 ;; insert component configuration beginning
15929 (vhdl-insert-keyword "FOR ")
15930 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15931 ;; find subconfiguration
15932 (setq conf-key (nth 7 inst-entry))
15933 (setq tmp-alist conf-alist)
15934 ;; use first configuration found for instance's entity
15935 (while (and tmp-alist (null conf-key))
15936 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15937 (setq conf-key (nth 0 (car tmp-alist))))
15938 (setq tmp-alist (cdr tmp-alist)))
15939 (setq conf-entry (aget conf-alist conf-key t))
15940 ;; insert binding indication ...
15941 ;; ... with subconfiguration (if exists)
15942 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15943 (progn
15944 (indent-to (+ margin vhdl-basic-offset))
15945 (vhdl-insert-keyword "USE CONFIGURATION ")
15946 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15947 (insert ";\n"))
15948 ;; ... with entity (if exists)
15949 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15950 (when ent-entry
15951 (indent-to (+ margin vhdl-basic-offset))
15952 (vhdl-insert-keyword "USE ENTITY ")
15953 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15954 ;; insert architecture name (if architecture exists)
15955 (when (nth 3 ent-entry)
15956 (setq arch-name
15957 ;; choose architecture name a) from configuration,
15958 ;; b) from mra, or c) from first architecture
15959 (or (nth 0 (aget (nth 3 ent-entry)
15960 (or (nth 6 inst-entry)
15961 (nth 4 ent-entry)) t))
15962 (nth 1 (car (nth 3 ent-entry)))))
15963 (insert "(" arch-name ")"))
15964 (insert ";\n")
15965 ;; insert block configuration (for architecture of subcomponent)
15966 (when (and vhdl-compose-configuration-hierarchical
15967 (nth 3 ent-entry))
15968 (indent-to (+ margin vhdl-basic-offset))
15969 (vhdl-compose-configuration-architecture
15970 (nth 0 ent-entry) arch-name
15971 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15972 ;; insert component configuration end
15973 (indent-to margin)
15974 (vhdl-insert-keyword "END FOR;\n")
15975 (setq inst-prev-path (nth 9 inst-entry)))
15976 (setq inst-alist (cdr inst-alist)))
15977 ;; insert block configuration end (for 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 (indent-to (- margin vhdl-basic-offset))
15984 ;; insert block configuration end or remove beginning (for architecture)
15985 (if insert-conf
15986 (vhdl-insert-keyword "END FOR;\n")
15987 (delete-region beg (point)))))
15988
15989 (defun vhdl-compose-configuration (&optional ent-name arch-name)
15990 "Generate configuration declaration."
15991 (interactive)
15992 (vhdl-require-hierarchy-info)
15993 (let ((ent-alist (aget vhdl-entity-alist
15994 (or (vhdl-project-p) default-directory) t))
15995 (conf-alist (aget vhdl-config-alist
15996 (or (vhdl-project-p) default-directory) t))
15997 (from-speedbar ent-name)
15998 inst-alist conf-name conf-file-name pos)
15999 (vhdl-prepare-search-2
16000 ;; get entity and architecture name
16001 (unless ent-name
16002 (save-excursion
16003 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16004 (not (equal "END" (upcase (match-string 1))))
16005 (setq ent-name (match-string-no-properties 3))
16006 (setq arch-name (match-string-no-properties 2)))
16007 (error "ERROR: Not within an architecture"))))
16008 (setq conf-name (vhdl-replace-string
16009 vhdl-compose-configuration-name
16010 (concat ent-name " " arch-name)))
16011 (setq inst-alist
16012 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16013 (downcase arch-name) t))))
16014 (message "Generating configuration \"%s\"..." conf-name)
16015 (if vhdl-compose-configuration-create-file
16016 ;; open configuration file
16017 (progn
16018 (setq conf-file-name
16019 (concat (vhdl-replace-string vhdl-configuration-file-name
16020 conf-name t)
16021 "." (file-name-extension (buffer-file-name))))
16022 (when (and (file-exists-p conf-file-name)
16023 (not (y-or-n-p (concat "File \"" conf-file-name
16024 "\" exists; overwrite? "))))
16025 (error "ERROR: Creating configuration...aborted"))
16026 (find-file conf-file-name)
16027 (erase-buffer)
16028 (set-buffer-modified-p nil)
16029 ;; insert header
16030 (if vhdl-compose-include-header
16031 (progn (vhdl-template-header
16032 (concat "Configuration declaration for design \""
16033 ent-name "(" arch-name ")\""))
16034 (goto-char (point-max)))
16035 (vhdl-comment-display-line) (insert "\n\n")))
16036 ;; goto end of architecture
16037 (unless from-speedbar
16038 (re-search-forward "^end\\>" nil)
16039 (end-of-line) (insert "\n\n")
16040 (vhdl-comment-display-line) (insert "\n\n")))
16041 ;; insert library clause
16042 (setq pos (point))
16043 (vhdl-template-standard-package (vhdl-work-library) nil)
16044 (when (/= pos (point))
16045 (insert "\n\n"))
16046 ;; insert configuration
16047 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16048 (vhdl-insert-keyword " OF ") (insert ent-name)
16049 (vhdl-insert-keyword " IS\n")
16050 (indent-to vhdl-basic-offset)
16051 ;; insert block configuration (for architecture)
16052 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16053 (vhdl-insert-keyword "END ") (insert conf-name ";")
16054 (when conf-file-name
16055 ;; insert footer and save
16056 (insert "\n\n")
16057 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16058 (vhdl-template-footer)
16059 (vhdl-comment-display-line) (insert "\n"))
16060 (save-buffer))
16061 (message "%s"
16062 (concat (format "Generating configuration \"%s\"...done" conf-name)
16063 (and conf-file-name
16064 (format "\n File created: \"%s\"" conf-file-name))))))
16065
16066
16067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16068 ;;; Compilation / Makefile generation
16069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16070 ;; (using `compile.el')
16071
16072 (defun vhdl-makefile-name ()
16073 "Return the Makefile name of the current project or the current compiler if
16074 no project is defined."
16075 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16076 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16077 (vhdl-replace-string
16078 (cons "\\(.*\\)\n\\(.*\\)"
16079 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16080 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16081
16082 (defun vhdl-compile-directory ()
16083 "Return the directory where compilation/make should be run."
16084 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16085 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16086 (directory (vhdl-resolve-env-variable
16087 (if project
16088 (vhdl-replace-string
16089 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16090 (nth 6 compiler)))))
16091 (file-name-as-directory
16092 (if (file-name-absolute-p directory)
16093 directory
16094 (expand-file-name directory (vhdl-default-directory))))))
16095
16096 (defun vhdl-uniquify (in-list)
16097 "Remove duplicate elements from IN-LIST."
16098 (let (out-list)
16099 (while in-list
16100 (add-to-list 'out-list (car in-list))
16101 (setq in-list (cdr in-list)))
16102 out-list))
16103
16104 (defun vhdl-set-compiler (name)
16105 "Set current compiler to NAME."
16106 (interactive
16107 (list (let ((completion-ignore-case t))
16108 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16109 (if (assoc name vhdl-compiler-alist)
16110 (progn (setq vhdl-compiler name)
16111 (message "Current compiler: \"%s\"" vhdl-compiler))
16112 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16113
16114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16115 ;; Compilation
16116
16117 (defun vhdl-compile-init ()
16118 "Initialize for compilation."
16119 (when (or (null compilation-error-regexp-alist)
16120 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16121 compilation-error-regexp-alist)))
16122 ;; `compilation-error-regexp-alist'
16123 (let ((commands-alist vhdl-compiler-alist)
16124 regexp-alist sublist)
16125 (while commands-alist
16126 (setq sublist (nth 11 (car commands-alist)))
16127 (unless (or (equal "" (car sublist))
16128 (assoc (car sublist) regexp-alist))
16129 (setq regexp-alist (cons (list (nth 0 sublist)
16130 (if (= 0 (nth 1 sublist))
16131 (if (featurep 'xemacs) 9 nil)
16132 (nth 1 sublist))
16133 (nth 2 sublist) (nth 3 sublist))
16134 regexp-alist)))
16135 (setq commands-alist (cdr commands-alist)))
16136 (setq compilation-error-regexp-alist
16137 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16138 ;; `compilation-file-regexp-alist'
16139 (let ((commands-alist vhdl-compiler-alist)
16140 regexp-alist sublist)
16141 ;; matches vhdl-mode file name output
16142 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16143 (while commands-alist
16144 (setq sublist (nth 12 (car commands-alist)))
16145 (unless (or (equal "" (car sublist))
16146 (assoc (car sublist) regexp-alist))
16147 (setq regexp-alist (cons sublist regexp-alist)))
16148 (setq commands-alist (cdr commands-alist)))
16149 (setq compilation-file-regexp-alist
16150 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16151
16152 (defvar vhdl-compile-file-name nil
16153 "Name of file to be compiled.")
16154
16155 (defun vhdl-compile-print-file-name ()
16156 "Function called within `compile' to print out file name for compilers that
16157 do not print any file names."
16158 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16159
16160 (defun vhdl-get-compile-options (project compiler file-name
16161 &optional file-options-only)
16162 "Get compiler options. Returning nil means do not compile this file."
16163 (let* ((compiler-options (nth 1 compiler))
16164 (project-entry (aget (nth 4 project) vhdl-compiler))
16165 (project-options (nth 0 project-entry))
16166 (exception-list (and file-name (nth 2 project-entry)))
16167 (work-library (vhdl-work-library))
16168 (case-fold-search nil)
16169 file-options)
16170 (while (and exception-list
16171 (not (string-match (caar exception-list) file-name)))
16172 (setq exception-list (cdr exception-list)))
16173 (if (and exception-list (not (cdar exception-list)))
16174 nil
16175 (if (and file-options-only (not exception-list))
16176 'default
16177 (setq file-options (cdar exception-list))
16178 ;; insert library name in compiler-specific options
16179 (setq compiler-options
16180 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16181 work-library))
16182 ;; insert compiler-specific options in project-specific options
16183 (when project-options
16184 (setq project-options
16185 (vhdl-replace-string
16186 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16187 (concat work-library "\n" compiler-options))))
16188 ;; insert project-specific options in file-specific options
16189 (when file-options
16190 (setq file-options
16191 (vhdl-replace-string
16192 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16193 (concat work-library "\n" compiler-options "\n"
16194 project-options))))
16195 ;; return options
16196 (or file-options project-options compiler-options)))))
16197
16198 (defun vhdl-get-make-options (project compiler)
16199 "Get make options."
16200 (let* ((compiler-options (nth 3 compiler))
16201 (project-entry (aget (nth 4 project) vhdl-compiler))
16202 (project-options (nth 1 project-entry))
16203 (makefile-name (vhdl-makefile-name)))
16204 ;; insert Makefile name in compiler-specific options
16205 (setq compiler-options
16206 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16207 makefile-name))
16208 ;; insert compiler-specific options in project-specific options
16209 (when project-options
16210 (setq project-options
16211 (vhdl-replace-string
16212 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16213 (concat makefile-name "\n" compiler-options))))
16214 ;; return options
16215 (or project-options compiler-options)))
16216
16217 (defun vhdl-compile ()
16218 "Compile current buffer using the VHDL compiler specified in
16219 `vhdl-compiler'."
16220 (interactive)
16221 (vhdl-compile-init)
16222 (let* ((project (aget vhdl-project-alist vhdl-project))
16223 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16224 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16225 (command (nth 0 compiler))
16226 (file-name (buffer-file-name))
16227 (options (vhdl-get-compile-options project compiler file-name))
16228 (default-directory (vhdl-compile-directory))
16229 compilation-process-setup-function)
16230 (unless (file-directory-p default-directory)
16231 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16232 ;; put file name into quotes if it contains spaces
16233 (when (string-match " " file-name)
16234 (setq file-name (concat "\"" file-name "\"")))
16235 ;; print out file name if compiler does not
16236 (setq vhdl-compile-file-name (buffer-file-name))
16237 (when (and (= 0 (nth 1 (nth 10 compiler)))
16238 (= 0 (nth 1 (nth 11 compiler))))
16239 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16240 ;; run compilation
16241 (if options
16242 (when command
16243 (compile (concat command " " options " " file-name)))
16244 (vhdl-warning "Your project settings tell me not to compile this file"))))
16245
16246 (defvar vhdl-make-target "all"
16247 "Default target for `vhdl-make' command.")
16248
16249 (defun vhdl-make (&optional target)
16250 "Call make command for compilation of all updated source files (requires
16251 `Makefile'). Optional argument TARGET allows to compile the design
16252 specified by a target."
16253 (interactive)
16254 (setq vhdl-make-target
16255 (or target (read-from-minibuffer "Target: " vhdl-make-target
16256 vhdl-minibuffer-local-map)))
16257 (vhdl-compile-init)
16258 (let* ((project (aget vhdl-project-alist vhdl-project))
16259 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16260 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16261 (command (nth 2 compiler))
16262 (options (vhdl-get-make-options project compiler))
16263 (default-directory (vhdl-compile-directory)))
16264 (unless (file-directory-p default-directory)
16265 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16266 ;; run make
16267 (compile (concat (if (equal command "") "make" command)
16268 " " options " " vhdl-make-target))))
16269
16270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16271 ;; Makefile generation
16272
16273 (defun vhdl-generate-makefile ()
16274 "Generate `Makefile'."
16275 (interactive)
16276 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16277 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16278 (command (nth 4 compiler)))
16279 ;; generate makefile
16280 (if command
16281 (let ((default-directory (vhdl-compile-directory)))
16282 (compile (vhdl-replace-string
16283 (cons "\\(.*\\) \\(.*\\)" command)
16284 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16285 (vhdl-generate-makefile-1))))
16286
16287 (defun vhdl-get-packages (lib-alist work-library)
16288 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16289 (let (pack-list)
16290 (while lib-alist
16291 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16292 (setq pack-list (cons (cdar lib-alist) pack-list)))
16293 (setq lib-alist (cdr lib-alist)))
16294 pack-list))
16295
16296 (defun vhdl-generate-makefile-1 ()
16297 "Generate Makefile for current project or directory."
16298 ;; scan hierarchy if required
16299 (if (vhdl-project-p)
16300 (unless (or (assoc vhdl-project vhdl-file-alist)
16301 (vhdl-load-cache vhdl-project))
16302 (vhdl-scan-project-contents vhdl-project))
16303 (let ((directory (abbreviate-file-name default-directory)))
16304 (unless (or (assoc directory vhdl-file-alist)
16305 (vhdl-load-cache directory))
16306 (vhdl-scan-directory-contents directory))))
16307 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16308 (project (vhdl-project-p))
16309 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16310 (conf-alist (aget vhdl-config-alist (or project directory) t))
16311 (pack-alist (aget vhdl-package-alist (or project directory) t))
16312 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16313 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16314 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16315 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16316 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16317 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16318 (adjust-case (nth 5 regexp-list))
16319 (work-library (downcase (vhdl-work-library)))
16320 (compile-directory (expand-file-name (vhdl-compile-directory)
16321 default-directory))
16322 (makefile-name (vhdl-makefile-name))
16323 rule-alist arch-alist inst-alist
16324 target-list depend-list unit-list prim-list second-list subcomp-list
16325 lib-alist lib-body-alist pack-list all-pack-list
16326 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16327 conf-key conf-file-name pack-key pack-file-name
16328 ent-entry arch-entry conf-entry pack-entry inst-entry
16329 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16330 tmp-key tmp-list rule)
16331 ;; check prerequisites
16332 (unless (file-exists-p compile-directory)
16333 (make-directory compile-directory t))
16334 (unless regexp-list
16335 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16336 vhdl-compiler))
16337 (message "Generating makefile \"%s\"..." makefile-name)
16338 ;; rules for all entities
16339 (setq tmp-list ent-alist)
16340 (while ent-alist
16341 (setq ent-entry (car ent-alist)
16342 ent-key (nth 0 ent-entry))
16343 (when (nth 2 ent-entry)
16344 (setq ent-file-name (file-relative-name
16345 (nth 2 ent-entry) compile-directory)
16346 arch-alist (nth 4 ent-entry)
16347 lib-alist (nth 6 ent-entry)
16348 rule (aget rule-alist ent-file-name)
16349 target-list (nth 0 rule)
16350 depend-list (nth 1 rule)
16351 second-list nil
16352 subcomp-list nil)
16353 (setq tmp-key (vhdl-replace-string
16354 ent-regexp (funcall adjust-case ent-key)))
16355 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16356 ;; rule target for this entity
16357 (setq target-list (cons ent-key target-list))
16358 ;; rule dependencies for all used packages
16359 (setq pack-list (vhdl-get-packages lib-alist work-library))
16360 (setq depend-list (append depend-list pack-list))
16361 (setq all-pack-list pack-list)
16362 ;; add rule
16363 (aput 'rule-alist ent-file-name (list target-list depend-list))
16364 ;; rules for all corresponding architectures
16365 (while arch-alist
16366 (setq arch-entry (car arch-alist)
16367 arch-key (nth 0 arch-entry)
16368 ent-arch-key (concat ent-key "-" arch-key)
16369 arch-file-name (file-relative-name (nth 2 arch-entry)
16370 compile-directory)
16371 inst-alist (nth 4 arch-entry)
16372 lib-alist (nth 5 arch-entry)
16373 rule (aget rule-alist arch-file-name)
16374 target-list (nth 0 rule)
16375 depend-list (nth 1 rule))
16376 (setq tmp-key (vhdl-replace-string
16377 arch-regexp
16378 (funcall adjust-case (concat arch-key " " ent-key))))
16379 (setq unit-list
16380 (cons (cons ent-arch-key tmp-key) unit-list))
16381 (setq second-list (cons ent-arch-key second-list))
16382 ;; rule target for this architecture
16383 (setq target-list (cons ent-arch-key target-list))
16384 ;; rule dependency for corresponding entity
16385 (setq depend-list (cons ent-key depend-list))
16386 ;; rule dependencies for contained component instantiations
16387 (while inst-alist
16388 (setq inst-entry (car inst-alist))
16389 (when (or (null (nth 8 inst-entry))
16390 (equal (downcase (nth 8 inst-entry)) work-library))
16391 (setq inst-ent-key (or (nth 7 inst-entry)
16392 (nth 5 inst-entry)))
16393 (setq depend-list (cons inst-ent-key depend-list)
16394 subcomp-list (cons inst-ent-key subcomp-list)))
16395 (setq inst-alist (cdr inst-alist)))
16396 ;; rule dependencies for all used packages
16397 (setq pack-list (vhdl-get-packages lib-alist work-library))
16398 (setq depend-list (append depend-list pack-list))
16399 (setq all-pack-list (append all-pack-list pack-list))
16400 ;; add rule
16401 (aput 'rule-alist arch-file-name (list target-list depend-list))
16402 (setq arch-alist (cdr arch-alist)))
16403 (setq prim-list (cons (list ent-key second-list
16404 (append subcomp-list all-pack-list))
16405 prim-list)))
16406 (setq ent-alist (cdr ent-alist)))
16407 (setq ent-alist tmp-list)
16408 ;; rules for all configurations
16409 (setq tmp-list conf-alist)
16410 (while conf-alist
16411 (setq conf-entry (car conf-alist)
16412 conf-key (nth 0 conf-entry)
16413 conf-file-name (file-relative-name
16414 (nth 2 conf-entry) compile-directory)
16415 ent-key (nth 4 conf-entry)
16416 arch-key (nth 5 conf-entry)
16417 inst-alist (nth 6 conf-entry)
16418 lib-alist (nth 7 conf-entry)
16419 rule (aget rule-alist conf-file-name)
16420 target-list (nth 0 rule)
16421 depend-list (nth 1 rule)
16422 subcomp-list (list ent-key))
16423 (setq tmp-key (vhdl-replace-string
16424 conf-regexp (funcall adjust-case conf-key)))
16425 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16426 ;; rule target for this configuration
16427 (setq target-list (cons conf-key target-list))
16428 ;; rule dependency for corresponding entity and architecture
16429 (setq depend-list
16430 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16431 ;; rule dependencies for used packages
16432 (setq pack-list (vhdl-get-packages lib-alist work-library))
16433 (setq depend-list (append depend-list pack-list))
16434 ;; rule dependencies for contained component configurations
16435 (while inst-alist
16436 (setq inst-entry (car inst-alist))
16437 (setq inst-ent-key (nth 2 inst-entry)
16438 ; comp-arch-key (nth 2 inst-entry))
16439 inst-conf-key (nth 4 inst-entry))
16440 (when (equal (downcase (nth 5 inst-entry)) work-library)
16441 (when inst-ent-key
16442 (setq depend-list (cons inst-ent-key depend-list)
16443 subcomp-list (cons inst-ent-key subcomp-list)))
16444 ; (when comp-arch-key
16445 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16446 ; depend-list)))
16447 (when inst-conf-key
16448 (setq depend-list (cons inst-conf-key depend-list)
16449 subcomp-list (cons inst-conf-key subcomp-list))))
16450 (setq inst-alist (cdr inst-alist)))
16451 ;; add rule
16452 (aput 'rule-alist conf-file-name (list target-list depend-list))
16453 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16454 prim-list))
16455 (setq conf-alist (cdr conf-alist)))
16456 (setq conf-alist tmp-list)
16457 ;; rules for all packages
16458 (setq tmp-list pack-alist)
16459 (while pack-alist
16460 (setq pack-entry (car pack-alist)
16461 pack-key (nth 0 pack-entry)
16462 pack-body-key nil)
16463 (when (nth 2 pack-entry)
16464 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16465 compile-directory)
16466 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16467 rule (aget rule-alist pack-file-name)
16468 target-list (nth 0 rule) depend-list (nth 1 rule))
16469 (setq tmp-key (vhdl-replace-string
16470 pack-regexp (funcall adjust-case pack-key)))
16471 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16472 ;; rule target for this package
16473 (setq target-list (cons pack-key target-list))
16474 ;; rule dependencies for all used packages
16475 (setq pack-list (vhdl-get-packages lib-alist work-library))
16476 (setq depend-list (append depend-list pack-list))
16477 (setq all-pack-list pack-list)
16478 ;; add rule
16479 (aput 'rule-alist pack-file-name (list target-list depend-list))
16480 ;; rules for this package's body
16481 (when (nth 7 pack-entry)
16482 (setq pack-body-key (concat pack-key "-body")
16483 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16484 compile-directory)
16485 rule (aget rule-alist pack-body-file-name)
16486 target-list (nth 0 rule)
16487 depend-list (nth 1 rule))
16488 (setq tmp-key (vhdl-replace-string
16489 pack-body-regexp (funcall adjust-case pack-key)))
16490 (setq unit-list
16491 (cons (cons pack-body-key tmp-key) unit-list))
16492 ;; rule target for this package's body
16493 (setq target-list (cons pack-body-key target-list))
16494 ;; rule dependency for corresponding package declaration
16495 (setq depend-list (cons pack-key depend-list))
16496 ;; rule dependencies for all used packages
16497 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16498 (setq depend-list (append depend-list pack-list))
16499 (setq all-pack-list (append all-pack-list pack-list))
16500 ;; add rule
16501 (aput 'rule-alist pack-body-file-name
16502 (list target-list depend-list)))
16503 (setq prim-list
16504 (cons (list pack-key (when pack-body-key (list pack-body-key))
16505 all-pack-list)
16506 prim-list)))
16507 (setq pack-alist (cdr pack-alist)))
16508 (setq pack-alist tmp-list)
16509 ;; generate Makefile
16510 (let* ((project (aget vhdl-project-alist project))
16511 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16512 (compiler-id (nth 9 compiler))
16513 (library-directory
16514 (vhdl-resolve-env-variable
16515 (vhdl-replace-string
16516 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16517 compiler-id)))
16518 (makefile-path-name (expand-file-name
16519 makefile-name compile-directory))
16520 (orig-buffer (current-buffer))
16521 cell second-list subcomp-list options unit-key unit-name)
16522 ;; sort lists
16523 (setq unit-list (vhdl-sort-alist unit-list))
16524 (setq prim-list (vhdl-sort-alist prim-list))
16525 (setq tmp-list rule-alist)
16526 (while tmp-list ; pre-sort rule targets
16527 (setq cell (cdar tmp-list))
16528 (setcar cell (sort (car cell) 'string<))
16529 (setq tmp-list (cdr tmp-list)))
16530 (setq rule-alist ; sort by first rule target
16531 (sort rule-alist
16532 (function (lambda (a b)
16533 (string< (car (cadr a)) (car (cadr b)))))))
16534 ;; open and clear Makefile
16535 (set-buffer (find-file-noselect makefile-path-name t t))
16536 (erase-buffer)
16537 (insert "# -*- Makefile -*-\n"
16538 "### " (file-name-nondirectory makefile-name)
16539 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16540 "\n")
16541 (if project
16542 (insert "\n# Project : " (nth 0 project))
16543 (insert "\n# Directory : \"" directory "\""))
16544 (insert "\n# Platform : " vhdl-compiler
16545 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16546 (user-login-name) "\n")
16547 ;; insert compile and option variable settings
16548 (insert "\n\n# Define compilation command and options\n"
16549 "\nCOMPILE = " (nth 0 compiler)
16550 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16551 "\n")
16552 ;; insert library paths
16553 (setq library-directory
16554 (directory-file-name
16555 (if (file-name-absolute-p library-directory)
16556 library-directory
16557 (file-relative-name
16558 (expand-file-name library-directory directory)
16559 compile-directory))))
16560 (insert "\n\n# Define library paths\n"
16561 "\nLIBRARY-" work-library " = " library-directory "\n")
16562 ;; insert variable definitions for all library unit files
16563 (insert "\n\n# Define library unit files\n")
16564 (setq tmp-list unit-list)
16565 (while unit-list
16566 (insert "\nUNIT-" work-library "-" (caar unit-list)
16567 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16568 (setq unit-list (cdr unit-list)))
16569 ;; insert variable definition for list of all library unit files
16570 (insert "\n\n\n# Define list of all library unit files\n"
16571 "\nALL_UNITS =")
16572 (setq unit-list tmp-list)
16573 (while unit-list
16574 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16575 (setq unit-list (cdr unit-list)))
16576 (insert "\n")
16577 (setq unit-list tmp-list)
16578 ;; insert `make all' rule
16579 (insert "\n\n\n# Rule for compiling entire design\n"
16580 "\nall :"
16581 " \\\n\t\tlibrary"
16582 " \\\n\t\t$(ALL_UNITS)\n")
16583 ;; insert `make clean' rule
16584 (insert "\n\n# Rule for cleaning entire design\n"
16585 "\nclean : "
16586 "\n\t-rm -f $(ALL_UNITS)\n")
16587 ;; insert `make library' rule
16588 (insert "\n\n# Rule for creating library directory\n"
16589 "\nlibrary :"
16590 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16591 "\n$(LIBRARY-" work-library ") :"
16592 "\n\t"
16593 (vhdl-replace-string
16594 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16595 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16596 "\n")
16597 ;; insert rule for each library unit
16598 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16599 (while prim-list
16600 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16601 (setq subcomp-list
16602 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16603 (setq unit-key (caar prim-list)
16604 unit-name (or (nth 0 (aget ent-alist unit-key t))
16605 (nth 0 (aget conf-alist unit-key t))
16606 (nth 0 (aget pack-alist unit-key t))))
16607 (insert "\n" unit-key)
16608 (unless (equal unit-key unit-name)
16609 (insert " \\\n" unit-name))
16610 (insert " :"
16611 " \\\n\t\tlibrary"
16612 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16613 (while second-list
16614 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16615 (setq second-list (cdr second-list)))
16616 (while subcomp-list
16617 (when (and (assoc (car subcomp-list) unit-list)
16618 (not (equal unit-key (car subcomp-list))))
16619 (insert " \\\n\t\t" (car subcomp-list)))
16620 (setq subcomp-list (cdr subcomp-list)))
16621 (insert "\n")
16622 (setq prim-list (cdr prim-list)))
16623 ;; insert rule for each library unit file
16624 (insert "\n\n# Rules for compiling single library unit files\n")
16625 (while rule-alist
16626 (setq rule (car rule-alist))
16627 ;; get compiler options for this file
16628 (setq options
16629 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16630 ;; insert rule if file is supposed to be compiled
16631 (setq target-list (nth 1 rule)
16632 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16633 ;; insert targets
16634 (setq tmp-list target-list)
16635 (while target-list
16636 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16637 (if (cdr target-list) " \\" " :"))
16638 (setq target-list (cdr target-list)))
16639 (setq target-list tmp-list)
16640 ;; insert file name as first dependency
16641 (insert " \\\n\t\t" (nth 0 rule))
16642 ;; insert dependencies (except if also target or unit does not exist)
16643 (while depend-list
16644 (when (and (not (member (car depend-list) target-list))
16645 (assoc (car depend-list) unit-list))
16646 (insert " \\\n\t\t"
16647 "$(UNIT-" work-library "-" (car depend-list) ")"))
16648 (setq depend-list (cdr depend-list)))
16649 ;; insert compile command
16650 (if options
16651 (insert "\n\t$(COMPILE) "
16652 (if (eq options 'default) "$(OPTIONS)" options) " "
16653 (nth 0 rule) "\n")
16654 (setq tmp-list target-list)
16655 (while target-list
16656 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16657 (if (cdr target-list) " \\" "\n"))
16658 (setq target-list (cdr target-list)))
16659 (setq target-list tmp-list))
16660 (setq rule-alist (cdr rule-alist)))
16661 (insert "\n\n### " makefile-name " ends here\n")
16662 ;; run Makefile generation hook
16663 (run-hooks 'vhdl-makefile-generation-hook)
16664 (message "Generating makefile \"%s\"...done" makefile-name)
16665 ;; save and close file
16666 (if (file-writable-p makefile-path-name)
16667 (progn (save-buffer)
16668 (kill-buffer (current-buffer))
16669 (set-buffer orig-buffer)
16670 (add-to-history 'file-name-history makefile-path-name))
16671 (vhdl-warning-when-idle
16672 (format "File not writable: \"%s\""
16673 (abbreviate-file-name makefile-path-name)))
16674 (switch-to-buffer (current-buffer))))))
16675
16676
16677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16678 ;;; Bug reports
16679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16680 ;; (using `reporter.el')
16681
16682 (defconst vhdl-mode-help-address
16683 "Reto Zimmermann <reto@gnu.org>"
16684 "Address for VHDL Mode bug reports.")
16685
16686 (defun vhdl-submit-bug-report ()
16687 "Submit via mail a bug report on VHDL Mode."
16688 (interactive)
16689 ;; load in reporter
16690 (and
16691 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16692 (let ((reporter-prompt-for-summary-p t))
16693 (reporter-submit-bug-report
16694 vhdl-mode-help-address
16695 (concat "VHDL Mode " vhdl-version)
16696 (list
16697 ;; report all important user options
16698 'vhdl-offsets-alist
16699 'vhdl-comment-only-line-offset
16700 'tab-width
16701 'vhdl-electric-mode
16702 'vhdl-stutter-mode
16703 'vhdl-indent-tabs-mode
16704 'vhdl-project-alist
16705 'vhdl-project
16706 'vhdl-project-file-name
16707 'vhdl-project-auto-load
16708 'vhdl-project-sort
16709 'vhdl-compiler-alist
16710 'vhdl-compiler
16711 'vhdl-compile-use-local-error-regexp
16712 'vhdl-makefile-generation-hook
16713 'vhdl-default-library
16714 'vhdl-standard
16715 'vhdl-basic-offset
16716 'vhdl-upper-case-keywords
16717 'vhdl-upper-case-types
16718 'vhdl-upper-case-attributes
16719 'vhdl-upper-case-enum-values
16720 'vhdl-upper-case-constants
16721 'vhdl-use-direct-instantiation
16722 'vhdl-compose-configuration-name
16723 'vhdl-entity-file-name
16724 'vhdl-architecture-file-name
16725 'vhdl-configuration-file-name
16726 'vhdl-package-file-name
16727 'vhdl-file-name-case
16728 'vhdl-electric-keywords
16729 'vhdl-optional-labels
16730 'vhdl-insert-empty-lines
16731 'vhdl-argument-list-indent
16732 'vhdl-association-list-with-formals
16733 'vhdl-conditions-in-parenthesis
16734 'vhdl-zero-string
16735 'vhdl-one-string
16736 'vhdl-file-header
16737 'vhdl-file-footer
16738 'vhdl-company-name
16739 'vhdl-copyright-string
16740 'vhdl-platform-spec
16741 'vhdl-date-format
16742 'vhdl-modify-date-prefix-string
16743 'vhdl-modify-date-on-saving
16744 'vhdl-reset-kind
16745 'vhdl-reset-active-high
16746 'vhdl-clock-rising-edge
16747 'vhdl-clock-edge-condition
16748 'vhdl-clock-name
16749 'vhdl-reset-name
16750 'vhdl-model-alist
16751 'vhdl-include-port-comments
16752 'vhdl-include-direction-comments
16753 'vhdl-include-type-comments
16754 'vhdl-include-group-comments
16755 'vhdl-actual-port-name
16756 'vhdl-instance-name
16757 'vhdl-testbench-entity-name
16758 'vhdl-testbench-architecture-name
16759 'vhdl-testbench-configuration-name
16760 'vhdl-testbench-dut-name
16761 'vhdl-testbench-include-header
16762 'vhdl-testbench-declarations
16763 'vhdl-testbench-statements
16764 'vhdl-testbench-initialize-signals
16765 'vhdl-testbench-include-library
16766 'vhdl-testbench-include-configuration
16767 'vhdl-testbench-create-files
16768 'vhdl-testbench-entity-file-name
16769 'vhdl-testbench-architecture-file-name
16770 'vhdl-compose-create-files
16771 'vhdl-compose-configuration-create-file
16772 'vhdl-compose-configuration-hierarchical
16773 'vhdl-compose-configuration-use-subconfiguration
16774 'vhdl-compose-include-header
16775 'vhdl-compose-architecture-name
16776 'vhdl-components-package-name
16777 'vhdl-use-components-package
16778 'vhdl-self-insert-comments
16779 'vhdl-prompt-for-comments
16780 'vhdl-inline-comment-column
16781 'vhdl-end-comment-column
16782 'vhdl-auto-align
16783 'vhdl-align-groups
16784 'vhdl-align-group-separate
16785 'vhdl-align-same-indent
16786 'vhdl-highlight-keywords
16787 'vhdl-highlight-names
16788 'vhdl-highlight-special-words
16789 'vhdl-highlight-forbidden-words
16790 'vhdl-highlight-verilog-keywords
16791 'vhdl-highlight-translate-off
16792 'vhdl-highlight-case-sensitive
16793 'vhdl-special-syntax-alist
16794 'vhdl-forbidden-words
16795 'vhdl-forbidden-syntax
16796 'vhdl-directive-keywords
16797 'vhdl-speedbar-auto-open
16798 'vhdl-speedbar-display-mode
16799 'vhdl-speedbar-scan-limit
16800 'vhdl-speedbar-jump-to-unit
16801 'vhdl-speedbar-update-on-saving
16802 'vhdl-speedbar-save-cache
16803 'vhdl-speedbar-cache-file-name
16804 'vhdl-index-menu
16805 'vhdl-source-file-menu
16806 'vhdl-hideshow-menu
16807 'vhdl-hide-all-init
16808 'vhdl-print-two-column
16809 'vhdl-print-customize-faces
16810 'vhdl-intelligent-tab
16811 'vhdl-indent-syntax-based
16812 'vhdl-word-completion-case-sensitive
16813 'vhdl-word-completion-in-minibuffer
16814 'vhdl-underscore-is-part-of-word
16815 'vhdl-mode-hook)
16816 (function
16817 (lambda ()
16818 (insert
16819 (if vhdl-special-indent-hook
16820 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16821 "vhdl-special-indent-hook is set to '"
16822 (format "%s" vhdl-special-indent-hook)
16823 ".\nPerhaps this is your problem?\n"
16824 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16825 "\n"))))
16826 nil
16827 "Hi Reto,"))))
16828
16829
16830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16831 ;;; Documentation
16832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16833
16834 (defconst vhdl-doc-release-notes nil
16835 "\
16836 Release Notes for VHDL Mode 3.33
16837 ================================
16838
16839 - New Features
16840 - User Options
16841
16842
16843 New Features
16844 ------------
16845
16846 CONFIGURATION DECLARATION GENERATION:
16847 - Automatic generation of a configuration declaration for a design.
16848 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16849
16850
16851 User Options
16852 ------------
16853
16854 `vhdl-configuration-file-name': (new)
16855 Specify how the configuration file name is obtained.
16856 `vhdl-compose-configuration-name': (new)
16857 Specify how the configuration name is optained.
16858 `vhdl-compose-configuration-create-file': (new)
16859 Specify whether a new file should be created for a configuration.
16860 `vhdl-compose-configuration-hierarchical': (new)
16861 Specify whether hierarchical configurations should be created.
16862 `vhdl-compose-configuration-use-subconfiguration': (new)
16863 Specify whether subconfigurations should be used inside configurations.
16864 ")
16865
16866
16867 (defconst vhdl-doc-keywords nil
16868 "\
16869 Reserved words in VHDL
16870 ----------------------
16871
16872 VHDL'93 (IEEE Std 1076-1993):
16873 `vhdl-93-keywords' : keywords
16874 `vhdl-93-types' : standardized types
16875 `vhdl-93-attributes' : standardized attributes
16876 `vhdl-93-enum-values' : standardized enumeration values
16877 `vhdl-93-functions' : standardized functions
16878 `vhdl-93-packages' : standardized packages and libraries
16879
16880 VHDL-AMS (IEEE Std 1076.1):
16881 `vhdl-ams-keywords' : keywords
16882 `vhdl-ams-types' : standardized types
16883 `vhdl-ams-attributes' : standardized attributes
16884 `vhdl-ams-enum-values' : standardized enumeration values
16885 `vhdl-ams-functions' : standardized functions
16886
16887 Math Packages (IEEE Std 1076.2):
16888 `vhdl-math-types' : standardized types
16889 `vhdl-math-constants' : standardized constants
16890 `vhdl-math-functions' : standardized functions
16891 `vhdl-math-packages' : standardized packages
16892
16893 Forbidden words:
16894 `vhdl-verilog-keywords' : Verilog reserved words
16895
16896 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16897
16898
16899 (defconst vhdl-doc-coding-style nil
16900 "\
16901 For VHDL coding style and naming convention guidelines, see the following
16902 references:
16903
16904 \[1] Ben Cohen.
16905 \"VHDL Coding Styles and Methodologies\".
16906 Kluwer Academic Publishers, 1999.
16907 http://members.aol.com/vhdlcohen/vhdl/
16908
16909 \[2] Michael Keating and Pierre Bricaud.
16910 \"Reuse Methodology Manual, Second Edition\".
16911 Kluwer Academic Publishers, 1999.
16912 http://www.openmore.com/openmore/rmm2.html
16913
16914 \[3] European Space Agency.
16915 \"VHDL Modelling Guidelines\".
16916 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16917
16918 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16919 to visually support naming conventions.")
16920
16921
16922 (defun vhdl-version ()
16923 "Echo the current version of VHDL Mode in the minibuffer."
16924 (interactive)
16925 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16926 (vhdl-keep-region-active))
16927
16928 (defun vhdl-doc-variable (variable)
16929 "Display VARIABLE's documentation in *Help* buffer."
16930 (interactive)
16931 (unless (featurep 'xemacs)
16932 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16933 (with-output-to-temp-buffer
16934 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16935 (princ (documentation-property variable 'variable-documentation))
16936 (with-current-buffer standard-output
16937 (help-mode))
16938 (help-print-return-message)))
16939
16940 (defun vhdl-doc-mode ()
16941 "Display VHDL Mode documentation in *Help* buffer."
16942 (interactive)
16943 (unless (featurep 'xemacs)
16944 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16945 (with-output-to-temp-buffer
16946 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16947 (princ mode-name)
16948 (princ " mode:\n")
16949 (princ (documentation 'vhdl-mode))
16950 (with-current-buffer standard-output
16951 (help-mode))
16952 (help-print-return-message)))
16953
16954
16955 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16956
16957 (provide 'vhdl-mode)
16958
16959 ;;; vhdl-mode.el ends here