Cleanup the bug-report email addresses and make sure the
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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, or (at your option)
28 ;; 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; see the file COPYING. If not, write to the
37 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 ;; Boston, MA 02110-1301, USA.
39
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;;; Commentary:
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43
44 ;; This package provides an Emacs major mode for editing VHDL code.
45 ;; It includes the following features:
46
47 ;; - Syntax highlighting
48 ;; - Indentation
49 ;; - Template insertion (electrification)
50 ;; - Insertion of file headers
51 ;; - Insertion of user-specified models
52 ;; - Port translation / testbench generation
53 ;; - Structural composition
54 ;; - Configuration generation
55 ;; - Sensitivity list updating
56 ;; - File browser
57 ;; - Design hierarchy browser
58 ;; - Source file compilation (syntax analysis)
59 ;; - Makefile generation
60 ;; - Code hiding
61 ;; - Word/keyword completion
62 ;; - Block commenting
63 ;; - Code fixing/alignment/beautification
64 ;; - Postscript printing
65 ;; - VHDL'87/'93 and VHDL-AMS supported
66 ;; - Comprehensive menu
67 ;; - Fully customizable
68 ;; - Works under GNU Emacs (recommended) and XEmacs
69
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71 ;; Documentation
72
73 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
74
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 ;; Emacs Versions
77
78 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
79 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
80
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 ;; Installation
83
84 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
85
86 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
87 ;; or into an arbitrary directory that is added to the load path by the
88 ;; following line in your Emacs start-up file `.emacs':
89
90 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
91
92 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
93 ;; directory. Otherwise, byte-compile the source file:
94 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
95 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
96
97 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
98 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
99 ;; (not required in Emacs 20.X):
100
101 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
102 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
103
104 ;; More detailed installation instructions are included in the official
105 ;; VHDL Mode distribution.
106
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108 ;; Acknowledgements
109
110 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
111 ;; and Steve Grout.
112
113 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
114 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
115
116 ;; Many thanks to all the users who sent me bug reports and enhancement
117 ;; requests.
118 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
119 ;; enhancement suggestions and the fruitful discussions.
120 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
121 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
122
123 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
124 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
125 ;; giving me the opportunity to develop this code.
126 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
127 ;; of the Swiss Government.
128
129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130
131 ;;; Code:
132
133 ;; Emacs 21+ handling
134 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
135 "Non-nil if GNU Emacs 21, 22, ... is used.")
136 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
137 "Non-nil if GNU Emacs 22, ... is used.")
138
139 (defvar compilation-file-regexp-alist)
140 (defvar conf-alist)
141 (defvar conf-entry)
142 (defvar conf-key)
143 (defvar ent-alist)
144 (defvar itimer-version)
145 (defvar lazy-lock-defer-contextually)
146 (defvar lazy-lock-defer-on-scrolling)
147 (defvar lazy-lock-defer-on-the-fly)
148 (defvar speedbar-attached-frame)
149
150
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;;; Variables
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154
155 ;; help function for user options
156 (defun vhdl-custom-set (variable value &rest functions)
157 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
158 (if (fboundp 'custom-set-default)
159 (custom-set-default variable value)
160 (set-default variable value))
161 (while functions
162 (when (fboundp (car functions)) (funcall (car functions)))
163 (setq functions (cdr functions))))
164
165 (defun vhdl-widget-directory-validate (widget)
166 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
167 '/' or is empty)."
168 (let ((val (widget-value widget)))
169 (unless (string-match "^\\(\\|.*/\\)$" val)
170 (widget-put widget :error "Invalid directory entry: must end with '/'")
171 widget)))
172
173 ;; help string for user options
174 (defconst vhdl-name-doc-string "
175
176 FROM REGEXP is a regular expression matching the original name:
177 \".*\" matches the entire string
178 \"\\(...\\)\" matches a substring
179 TO STRING specifies the string to be inserted as new name:
180 \"\\&\" means substitute entire matched text
181 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
182 Examples:
183 \".*\" \"\\&\" inserts original string
184 \".*\" \"\\&_i\" attaches \"_i\" to original string
185 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
186 \".*\" \"foo\" inserts constant string \"foo\"
187 \".*\" \"\" inserts empty string")
188
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190 ;; User variables
191
192 (defgroup vhdl nil
193 "Customizations for VHDL Mode."
194 :prefix "vhdl-"
195 :group 'languages
196 ; :version "21.2" ; comment out for XEmacs
197 )
198
199 (defgroup vhdl-mode nil
200 "Customizations for modes."
201 :group 'vhdl)
202
203 (defcustom vhdl-electric-mode t
204 "*Non-nil enables electrification (automatic template generation).
205 If nil, template generators can still be invoked through key bindings and
206 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
207 toggled by `\\[vhdl-electric-mode]'."
208 :type 'boolean
209 :group 'vhdl-mode)
210
211 (defcustom vhdl-stutter-mode t
212 "*Non-nil enables stuttering.
213 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
214 by `\\[vhdl-stutter-mode]'."
215 :type 'boolean
216 :group 'vhdl-mode)
217
218 (defcustom vhdl-indent-tabs-mode nil
219 "*Non-nil means indentation can insert tabs.
220 Overrides local variable `indent-tabs-mode'."
221 :type 'boolean
222 :group 'vhdl-mode)
223
224
225 (defgroup vhdl-compile nil
226 "Customizations for compilation."
227 :group 'vhdl)
228
229 (defcustom vhdl-compiler-alist
230 '(
231 ;; Cadence Leapfrog: cv -file test.vhd
232 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
233 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
234 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
235 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
236 ("\\1/entity" "\\2/\\1" "\\1/configuration"
237 "\\1/package" "\\1/body" downcase))
238 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
239 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
240 ;; (PLL_400X_TOP) is not declared [10.3].
241 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
242 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
243 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
244 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
245 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
246 ;; Ikos Voyager: analyze test.vhd
247 ;; analyze test.vhd
248 ;; E L4/C5: this library unit is inaccessible
249 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
250 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
251 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
252 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
253 nil)
254 ;; ModelSim, Model Technology: vcom test.vhd
255 ;; ERROR: test.vhd(14): Unknown identifier: positiv
256 ;; WARNING[2]: test.vhd(85): Possible infinite loop
257 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
258 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
259 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
260 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
261 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
262 "\\1/_primary.dat" "\\1/body.dat" downcase))
263 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
264 ;; test.vhd:34: error message
265 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
266 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
267 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
268 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
269 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
270 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
271 ;; ERROR: test.vhd(24): near "dnd": expecting: END
272 ;; WARNING[4]: test.vhd(30): A space is required between ...
273 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
274 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
275 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
276 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
277 "\\1/_primary.dat" "\\1/body.dat" downcase))
278 ;; Savant: scram -publish-cc test.vhd
279 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
280 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
281 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
282 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
283 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
284 "\\1_config.vhdl" "\\1_package.vhdl"
285 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
286 ;; Simili: vhdlp -work test.vhd
287 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
288 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
289 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
290 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
291 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
292 "\\1/prim.var" "\\1/_body.var" downcase))
293 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
294 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
295 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
296 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
297 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
298 nil)
299 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
300 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
301 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
303 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
304 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
305 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
306 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
307 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
309 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
310 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
311 ;; Synplify:
312 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
313 ("Synplify" "n/a" "n/a" "make" "-f \\1"
314 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
315 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
316 nil)
317 ;; Vantage: 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 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
321 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
322 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
323 ("^ *Compiling \"\\(.+\\)\" " 1)
324 nil)
325 ;; VeriBest: vc vhdl test.vhd
326 ;; (no file name printed out!)
327 ;; 32: Z <= A and BitA ;
328 ;; ^^^^
329 ;; [Error] Name BITA is unknown
330 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
331 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
332 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
333 nil)
334 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
335 ;; Compiling "test.vhd" line 1...
336 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
337 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
338 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
339 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
340 ("^ *Compiling \"\\(.+\\)\" " 1)
341 nil)
342 )
343 "*List of available VHDL compilers and their properties.
344 Each list entry specifies the following items for a compiler:
345 Compiler:
346 Compiler name : name used in option `vhdl-compiler' to choose compiler
347 Compile command : command used for source file compilation
348 Compile options : compile options (\"\\1\" inserts library name)
349 Make command : command used for compilation using a Makefile
350 Make options : make options (\"\\1\" inserts Makefile name)
351 Generate Makefile: use built-in function or command to generate a Makefile
352 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
353 Library command : command to create library directory \(\"\\1\" inserts
354 library directory, \"\\2\" inserts library name)
355 Compile directory: where compilation is run and the Makefile is placed
356 Library directory: directory of default library
357 Makefile name : name of Makefile (default is \"Makefile\")
358 ID string : compiler identification string (see `vhdl-project-alist')
359 Error message:
360 Regexp : regular expression to match error messages (*)
361 File subexp index: index of subexpression that matches the file name
362 Line subexp index: index of subexpression that matches the line number
363 Column subexp idx: index of subexpression that matches the column number
364 File message:
365 Regexp : regular expression to match a file name message
366 File subexp index: index of subexpression that matches the file name
367 Unit-to-file name mapping: mapping of library unit names to names of files
368 generated by the compiler (used for Makefile generation)
369 To string : string a name is mapped to (\"\\1\" inserts the unit name,
370 \"\\2\" inserts the entity name for architectures)
371 Case adjustment : adjust case of inserted unit names
372
373 \(*) The regular expression must match the error message starting from the
374 beginning of the line (but not necessarily to the end of the line).
375
376 Compile options allows insertion of the library name (see `vhdl-project-alist')
377 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
378
379 For Makefile generation, the built-in function can be used (requires
380 specification of the unit-to-file name mapping). Alternatively, an
381 external command can be specified. Work directory allows specification of
382 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
383 used for Makefile generation). To use another library name than \"work\",
384 customize `vhdl-project-alist'. The library command is inserted in Makefiles
385 to automatically create the library directory if not existent.
386
387 Compile options, compile directory, library directory, and Makefile name are
388 overwritten by the project settings if a project is defined (see
389 `vhdl-project-alist'). Directory paths are relative to the source file
390 directory.
391
392 Some compilers do not include the file name in the error message, but print
393 out a file name message in advance. In this case, set \"File Subexp Index\"
394 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
395 If no file name at all is printed out, set both \"File Message\" entries to 0
396 \(a default file name message will be printed out instead, does not work in
397 XEmacs).
398
399 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
400 assigning its name to option `vhdl-compiler'.
401
402 Please send any missing or erroneous compiler properties to the maintainer for
403 updating.
404
405 NOTE: Activate new error and file message regexps and reflect the new setting
406 in the choice list of option `vhdl-compiler' by restarting Emacs."
407 :type '(repeat
408 (list :tag "Compiler" :indent 2
409 (string :tag "Compiler name ")
410 (string :tag "Compile command ")
411 (string :tag "Compile options " "-work \\1")
412 (string :tag "Make command " "make")
413 (string :tag "Make options " "-f \\1")
414 (choice :tag "Generate Makefile "
415 (const :tag "Built-in function" nil)
416 (string :tag "Command" "vmake \\2 > \\1"))
417 (string :tag "Library command " "mkdir \\1")
418 (directory :tag "Compile directory "
419 :validate vhdl-widget-directory-validate "./")
420 (directory :tag "Library directory "
421 :validate vhdl-widget-directory-validate "work/")
422 (file :tag "Makefile name " "Makefile")
423 (string :tag "ID string ")
424 (list :tag "Error message" :indent 4
425 (regexp :tag "Regexp ")
426 (integer :tag "File subexp index")
427 (integer :tag "Line subexp index")
428 (integer :tag "Column subexp idx"))
429 (list :tag "File message" :indent 4
430 (regexp :tag "Regexp ")
431 (integer :tag "File subexp index"))
432 (choice :tag "Unit-to-file name mapping"
433 :format "%t: %[Value Menu%] %v\n"
434 (const :tag "Not defined" nil)
435 (list :tag "To string" :indent 4
436 (string :tag "Entity " "\\1.vhd")
437 (string :tag "Architecture " "\\2_\\1.vhd")
438 (string :tag "Configuration " "\\1.vhd")
439 (string :tag "Package " "\\1.vhd")
440 (string :tag "Package Body " "\\1_body.vhd")
441 (choice :tag "Case adjustment "
442 (const :tag "None" identity)
443 (const :tag "Upcase" upcase)
444 (const :tag "Downcase" downcase))))))
445 :set (lambda (variable value)
446 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
447 :group 'vhdl-compile)
448
449 (defcustom vhdl-compiler "ModelSim"
450 "*Specifies the VHDL compiler to be used for syntax analysis.
451 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
452 :type (let ((alist vhdl-compiler-alist) list)
453 (while alist
454 (setq list (cons (list 'const (caar alist)) list))
455 (setq alist (cdr alist)))
456 (append '(choice) (nreverse list)))
457 :group 'vhdl-compile)
458
459 (defcustom vhdl-compile-use-local-error-regexp t
460 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
461 In this case, only error message regexps for VHDL compilers are active if
462 compilation is started from a VHDL buffer. Otherwise, the error message
463 regexps are appended to the predefined global regexps, and all regexps are
464 active all the time. Note that by doing that, the predefined global regexps
465 might result in erroneous parsing of error messages for some VHDL compilers.
466
467 NOTE: Activate the new setting by restarting Emacs."
468 :type 'boolean
469 :group 'vhdl-compile)
470
471 (defcustom vhdl-makefile-generation-hook nil
472 "*Functions to run at the end of Makefile generation.
473 Allows to insert user specific parts into a Makefile.
474
475 Example:
476 \(lambda nil
477 \(re-search-backward \"^# Rule for compiling entire design\")
478 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
479 :type 'hook
480 :group 'vhdl-compile)
481
482 (defcustom vhdl-default-library "work"
483 "*Name of default library.
484 Is overwritten by project settings if a project is active."
485 :type 'string
486 :group 'vhdl-compile)
487
488
489 (defgroup vhdl-project nil
490 "Customizations for projects."
491 :group 'vhdl)
492
493 (defcustom vhdl-project-alist
494 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
495 "~/example1/" ("src/system/" "src/components/") ""
496 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
497 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
498 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
499 ("Example 2" "Individual source files, multiple compilers in different directories"
500 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
501 nil "\\1/" "work" "\\1/work/" "Makefile" "")
502 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
503 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
504 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
505 -------------------------------------------------------------------------------
506 -- This is a multi-line project description
507 -- that can be used as a project dependent part of the file header.
508 "))
509 "*List of projects and their properties.
510 Name : name used in option `vhdl-project' to choose project
511 Title : title of project (single-line string)
512 Default directory: default project directory (absolute path)
513 Sources : a) source files : path + \"/\" + file name
514 b) directory : path + \"/\"
515 c) directory tree: \"-r \" + path + \"/\"
516 Exclude regexp : matches file/directory names to be excluded as sources
517 Compile options : project-specific options for each compiler
518 Compiler name : name of compiler for which these options are valid
519 Compile options: project-specific compiler options
520 (\"\\1\" inserts library name, \"\\2\" default options)
521 Make options: project-specific make options
522 (\"\\1\" inserts Makefile name, \"\\2\" default options)
523 Exceptions : file-specific exceptions
524 File name regexp: matches file names for which exceptions are valid
525 - Options : file-specific compiler options string
526 (\"\\1\" inserts library name, \"\\2\" default options,
527 \"\\3\" project-specific options)
528 - Do not compile: do not compile this file (in Makefile)
529 Compile directory: where compilation is run and the Makefile is placed
530 \(\"\\1\" inserts compiler ID string)
531 Library name : name of library (default is \"work\")
532 Library directory: path to library (\"\\1\" inserts compiler ID string)
533 Makefile name : name of Makefile
534 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
535 Description : description of project (multi-line string)
536
537 Project title and description are used to insert into the file header (see
538 option `vhdl-file-header').
539
540 The default directory must have an absolute path (use `M-TAB' for completion).
541 All other paths can be absolute or relative to the default directory. All
542 paths must end with '/'.
543
544 The design units found in the sources (files and directories) are shown in the
545 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
546 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
547 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
548 specified, the default directory is taken as source directory. Otherwise,
549 the default directory is only taken as source directory if there is a sources
550 entry with the empty string or \"./\". Exclude regexp allows to filter out
551 specific file and directory names from the list of sources (e.g. CVS
552 directories).
553
554 Files are compiled in the compile directory. Makefiles are also placed into
555 the compile directory. Library directory specifies which directory the
556 compiler compiles into (used to generate the Makefile).
557
558 Since different compile/library directories and Makefiles may exist for
559 different compilers within one project, these paths and names allow the
560 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
561 Compile options, compile directory, library directory, and Makefile name
562 overwrite the settings of the current compiler.
563
564 File-specific compiler options (highest priority) overwrite project-specific
565 options which overwrite default options (lowest priority). Lower priority
566 options can be inserted in higher priority options. This allows to reuse
567 default options (e.g. \"-file\") in project- or file-specific options (e.g.
568 \"-93 -file\").
569
570 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
571 by restarting Emacs."
572 :type `(repeat
573 (list :tag "Project" :indent 2
574 (string :tag "Name ")
575 (string :tag "Title ")
576 (directory :tag "Default directory"
577 :validate vhdl-widget-directory-validate
578 ,(abbreviate-file-name default-directory))
579 (repeat :tag "Sources " :indent 4
580 (directory :format " %v" "./"))
581 (regexp :tag "Exclude regexp ")
582 (repeat
583 :tag "Compile options " :indent 4
584 (list :tag "Compiler" :indent 6
585 ,(let ((alist vhdl-compiler-alist) list)
586 (while alist
587 (setq list (cons (list 'const (caar alist)) list))
588 (setq alist (cdr alist)))
589 (append '(choice :tag "Compiler name")
590 (nreverse list)))
591 (string :tag "Compile options" "\\2")
592 (string :tag "Make options " "\\2")
593 (repeat
594 :tag "Exceptions " :indent 8
595 (cons :format "%v"
596 (regexp :tag "File name regexp ")
597 (choice :format "%[Value Menu%] %v"
598 (string :tag "Options" "\\3")
599 (const :tag "Do not compile" nil))))))
600 (directory :tag "Compile directory"
601 :validate vhdl-widget-directory-validate "./")
602 (string :tag "Library name " "work")
603 (directory :tag "Library directory"
604 :validate vhdl-widget-directory-validate "work/")
605 (file :tag "Makefile name " "Makefile")
606 (string :tag "Description: (type `C-j' for newline)"
607 :format "%t\n%v\n")))
608 :set (lambda (variable value)
609 (vhdl-custom-set variable value
610 'vhdl-update-mode-menu
611 'vhdl-speedbar-refresh))
612 :group 'vhdl-project)
613
614 (defcustom vhdl-project nil
615 "*Specifies the default for the current project.
616 Select a project name from the ones defined in option `vhdl-project-alist'.
617 Is used to determine the project title and description to be inserted in file
618 headers and the source files/directories to be scanned in the hierarchy
619 browser. The current project can also be changed temporarily in the menu."
620 :type (let ((alist vhdl-project-alist) list)
621 (while alist
622 (setq list (cons (list 'const (caar alist)) list))
623 (setq alist (cdr alist)))
624 (append '(choice (const :tag "None" nil) (const :tag "--"))
625 (nreverse list)))
626 :group 'vhdl-project)
627
628 (defcustom vhdl-project-file-name '("\\1.prj")
629 "*List of file names/paths for importing/exporting project setups.
630 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
631 replaced by the user name (allows to have user-specific project setups).
632 The first entry is used as file name to import/export individual project
633 setups. All entries are used to automatically import project setups at
634 startup (see option `vhdl-project-auto-load'). Projects loaded from the
635 first entry are automatically made current. Hint: specify local project
636 setups in first entry, global setups in following entries; loading a local
637 project setup will make it current, while loading the global setups
638 is done without changing the current project.
639 Names can also have an absolute path (i.e. project setups can be stored
640 in global directories)."
641 :type '(repeat (string :tag "File name" "\\1.prj"))
642 :group 'vhdl-project)
643
644 (defcustom vhdl-project-auto-load '(startup)
645 "*Automatically load project setups from files.
646 All project setup files that match the file names specified in option
647 `vhdl-project-file-name' are automatically loaded. The project of the
648 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
649 entry is activated.
650 A project setup file can be obtained by exporting a project (see menu).
651 At startup: project setup file is loaded at Emacs startup"
652 :type '(set (const :tag "At startup" startup))
653 :group 'vhdl-project)
654
655 (defcustom vhdl-project-sort t
656 "*Non-nil means projects are displayed in alphabetical order."
657 :type 'boolean
658 :group 'vhdl-project)
659
660
661 (defgroup vhdl-style nil
662 "Customizations for coding styles."
663 :group 'vhdl
664 :group 'vhdl-template
665 :group 'vhdl-port
666 :group 'vhdl-compose)
667
668 (defcustom vhdl-standard '(87 nil)
669 "*VHDL standards used.
670 Basic standard:
671 VHDL'87 : IEEE Std 1076-1987
672 VHDL'93 : IEEE Std 1076-1993
673 Additional standards:
674 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
675 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
676
677 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
678 \"Activate Options\"."
679 :type '(list (choice :tag "Basic standard"
680 (const :tag "VHDL'87" 87)
681 (const :tag "VHDL'93" 93))
682 (set :tag "Additional standards" :indent 2
683 (const :tag "VHDL-AMS" ams)
684 (const :tag "Math packages" math)))
685 :set (lambda (variable value)
686 (vhdl-custom-set variable value
687 'vhdl-template-map-init
688 'vhdl-mode-abbrev-table-init
689 'vhdl-template-construct-alist-init
690 'vhdl-template-package-alist-init
691 'vhdl-update-mode-menu
692 'vhdl-words-init 'vhdl-font-lock-init))
693 :group 'vhdl-style)
694
695 (defcustom vhdl-basic-offset 2
696 "*Amount of basic offset used for indentation.
697 This value is used by + and - symbols in `vhdl-offsets-alist'."
698 :type 'integer
699 :group 'vhdl-style)
700
701 (defcustom vhdl-upper-case-keywords nil
702 "*Non-nil means convert keywords to upper case.
703 This is done when typed or expanded or by the fix case functions."
704 :type 'boolean
705 :set (lambda (variable value)
706 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
707 :group 'vhdl-style)
708
709 (defcustom vhdl-upper-case-types nil
710 "*Non-nil means convert standardized types to upper case.
711 This is done when expanded or by the fix case functions."
712 :type 'boolean
713 :set (lambda (variable value)
714 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
715 :group 'vhdl-style)
716
717 (defcustom vhdl-upper-case-attributes nil
718 "*Non-nil means convert standardized attributes to upper case.
719 This is done when expanded or by the fix case functions."
720 :type 'boolean
721 :set (lambda (variable value)
722 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
723 :group 'vhdl-style)
724
725 (defcustom vhdl-upper-case-enum-values nil
726 "*Non-nil means convert standardized enumeration values to upper case.
727 This is done when expanded or by the fix case functions."
728 :type 'boolean
729 :set (lambda (variable value)
730 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
731 :group 'vhdl-style)
732
733 (defcustom vhdl-upper-case-constants t
734 "*Non-nil means convert standardized constants to upper case.
735 This is done when expanded."
736 :type 'boolean
737 :set (lambda (variable value)
738 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
739 :group 'vhdl-style)
740
741 (defcustom vhdl-use-direct-instantiation 'standard
742 "*Non-nil means use VHDL'93 direct component instantiation.
743 Never : never
744 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
745 Always : always"
746 :type '(choice (const :tag "Never" never)
747 (const :tag "Standard" standard)
748 (const :tag "Always" always))
749 :group 'vhdl-style)
750
751
752 (defgroup vhdl-naming nil
753 "Customizations for naming conventions."
754 :group 'vhdl)
755
756 (defcustom vhdl-entity-file-name '(".*" . "\\&")
757 (concat
758 "*Specifies how the entity file name is obtained.
759 The entity file name can be obtained by modifying the entity name (e.g.
760 attaching or stripping off a substring). The file extension is automatically
761 taken from the file name of the current buffer."
762 vhdl-name-doc-string)
763 :type '(cons (regexp :tag "From regexp")
764 (string :tag "To string "))
765 :group 'vhdl-naming
766 :group 'vhdl-compose)
767
768 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
769 (concat
770 "*Specifies how the architecture file name is obtained.
771 The architecture file name can be obtained by modifying the entity
772 and/or architecture name (e.g. attaching or stripping off a substring). The
773 file extension is automatically taken from the file name of the current
774 buffer. The string that is matched against the regexp is the concatenation
775 of the entity and the architecture name separated by a space. This gives
776 access to both names (see default setting as example)."
777 vhdl-name-doc-string)
778 :type '(cons (regexp :tag "From regexp")
779 (string :tag "To string "))
780 :group 'vhdl-naming
781 :group 'vhdl-compose)
782
783 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
784 (concat
785 "*Specifies how the configuration file name is obtained.
786 The configuration file name can be obtained by modifying the configuration
787 name (e.g. attaching or stripping off a substring). The file extension is
788 automatically taken from the file name of the current buffer."
789 vhdl-name-doc-string)
790 :type '(cons (regexp :tag "From regexp")
791 (string :tag "To string "))
792 :group 'vhdl-naming
793 :group 'vhdl-compose)
794
795 (defcustom vhdl-package-file-name '(".*" . "\\&")
796 (concat
797 "*Specifies how the package file name is obtained.
798 The package file name can be obtained by modifying the package name (e.g.
799 attaching or stripping off a substring). The file extension is automatically
800 taken from the file name of the current buffer. Package files can be created
801 in a different directory by prepending a relative or absolute path to the
802 file name."
803 vhdl-name-doc-string)
804 :type '(cons (regexp :tag "From regexp")
805 (string :tag "To string "))
806 :group 'vhdl-naming
807 :group 'vhdl-compose)
808
809 (defcustom vhdl-file-name-case 'identity
810 "*Specifies how to change case for obtaining file names.
811 When deriving a file name from a VHDL unit name, case can be changed as
812 follows:
813 As Is: case is not changed (taken as is)
814 Lower Case: whole name is changed to lower case
815 Upper Case: whole name is changed to upper case
816 Capitalize: first letter of each word in name is capitalized"
817 :type '(choice (const :tag "As Is" identity)
818 (const :tag "Lower Case" downcase)
819 (const :tag "Upper Case" upcase)
820 (const :tag "Capitalize" capitalize))
821 :group 'vhdl-naming
822 :group 'vhdl-compose)
823
824
825 (defgroup vhdl-template nil
826 "Customizations for electrification."
827 :group 'vhdl)
828
829 (defcustom vhdl-electric-keywords '(vhdl user)
830 "*Type of keywords for which electrification is enabled.
831 VHDL keywords: invoke built-in templates
832 User keywords: invoke user models (see option `vhdl-model-alist')"
833 :type '(set (const :tag "VHDL keywords" vhdl)
834 (const :tag "User model keywords" user))
835 :set (lambda (variable value)
836 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
837 :group 'vhdl-template)
838
839 (defcustom vhdl-optional-labels 'process
840 "*Constructs for which labels are to be queried.
841 Template generators prompt for optional labels for:
842 None : no constructs
843 Processes only: processes only (also procedurals in VHDL-AMS)
844 All constructs: all constructs with optional labels and keyword END"
845 :type '(choice (const :tag "None" none)
846 (const :tag "Processes only" process)
847 (const :tag "All constructs" all))
848 :group 'vhdl-template)
849
850 (defcustom vhdl-insert-empty-lines 'unit
851 "*Specifies whether to insert empty lines in some templates.
852 This improves readability of code. Empty lines are inserted in:
853 None : no constructs
854 Design units only: entities, architectures, configurations, packages only
855 All constructs : also all constructs with BEGIN...END parts
856
857 Replaces option `vhdl-additional-empty-lines'."
858 :type '(choice (const :tag "None" none)
859 (const :tag "Design units only" unit)
860 (const :tag "All constructs" all))
861 :group 'vhdl-template
862 :group 'vhdl-port
863 :group 'vhdl-compose)
864
865 (defcustom vhdl-argument-list-indent nil
866 "*Non-nil means indent argument lists relative to opening parenthesis.
867 That is, argument, association, and port lists start on the same line as the
868 opening parenthesis and subsequent lines are indented accordingly.
869 Otherwise, lists start on a new line and are indented as normal code."
870 :type 'boolean
871 :group 'vhdl-template
872 :group 'vhdl-port
873 :group 'vhdl-compose)
874
875 (defcustom vhdl-association-list-with-formals t
876 "*Non-nil means write association lists with formal parameters.
877 Templates prompt for formal and actual parameters (ports/generics).
878 When pasting component instantiations, formals are included.
879 If nil, only a list of actual parameters is entered."
880 :type 'boolean
881 :group 'vhdl-template
882 :group 'vhdl-port
883 :group 'vhdl-compose)
884
885 (defcustom vhdl-conditions-in-parenthesis nil
886 "*Non-nil means place parenthesis around condition expressions."
887 :type 'boolean
888 :group 'vhdl-template)
889
890 (defcustom vhdl-zero-string "'0'"
891 "*String to use for a logic zero."
892 :type 'string
893 :group 'vhdl-template)
894
895 (defcustom vhdl-one-string "'1'"
896 "*String to use for a logic one."
897 :type 'string
898 :group 'vhdl-template)
899
900
901 (defgroup vhdl-header nil
902 "Customizations for file header."
903 :group 'vhdl-template
904 :group 'vhdl-compose)
905
906 (defcustom vhdl-file-header "\
907 -------------------------------------------------------------------------------
908 -- Title : <title string>
909 -- Project : <project>
910 -------------------------------------------------------------------------------
911 -- File : <filename>
912 -- Author : <author>
913 -- Company : <company>
914 -- Created : <date>
915 -- Last update: <date>
916 -- Platform : <platform>
917 -- Standard : <standard>
918 <projectdesc>-------------------------------------------------------------------------------
919 -- Description: <cursor>
920 <copyright>-------------------------------------------------------------------------------
921 -- Revisions :
922 -- Date Version Author Description
923 -- <date> 1.0 <login>\tCreated
924 -------------------------------------------------------------------------------
925
926 "
927 "*String or file to insert as file header.
928 If the string specifies an existing file name, the contents of the file is
929 inserted, otherwise the string itself is inserted as file header.
930 Type `C-j' for newlines.
931 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
932 if the header needs to be version controlled.
933
934 The following keywords for template generation are supported:
935 <filename> : replaced by the name of the buffer
936 <author> : replaced by the user name and email address
937 \(`user-full-name',`mail-host-address', `user-mail-address')
938 <login> : replaced by user login name (`user-login-name')
939 <company> : replaced by contents of option `vhdl-company-name'
940 <date> : replaced by the current date
941 <year> : replaced by the current year
942 <project> : replaced by title of current project (`vhdl-project')
943 <projectdesc> : replaced by description of current project (`vhdl-project')
944 <copyright> : replaced by copyright string (`vhdl-copyright-string')
945 <platform> : replaced by contents of option `vhdl-platform-spec'
946 <standard> : replaced by the VHDL language standard(s) used
947 <... string> : replaced by a queried string (\"...\" is the prompt word)
948 <title string>: replaced by file title in automatically generated files
949 <cursor> : final cursor position
950
951 The (multi-line) project description <projectdesc> can be used as a project
952 dependent part of the file header and can also contain the above keywords."
953 :type 'string
954 :group 'vhdl-header)
955
956 (defcustom vhdl-file-footer ""
957 "*String or file to insert as file footer.
958 If the string specifies an existing file name, the contents of the file is
959 inserted, otherwise the string itself is inserted as file footer (i.e. at
960 the end of the file).
961 Type `C-j' for newlines.
962 The same keywords as in option `vhdl-file-header' can be used."
963 :type 'string
964 :group 'vhdl-header)
965
966 (defcustom vhdl-company-name ""
967 "*Name of company to insert in file header.
968 See option `vhdl-file-header'."
969 :type 'string
970 :group 'vhdl-header)
971
972 (defcustom vhdl-copyright-string "\
973 -------------------------------------------------------------------------------
974 -- Copyright (c) <year> <company>
975 "
976 "*Copyright string to insert in file header.
977 Can be multi-line string (type `C-j' for newline) and contain other file
978 header keywords (see option `vhdl-file-header')."
979 :type 'string
980 :group 'vhdl-header)
981
982 (defcustom vhdl-platform-spec ""
983 "*Specification of VHDL platform to insert in file header.
984 The platform specification should contain names and versions of the
985 simulation and synthesis tools used.
986 See option `vhdl-file-header'."
987 :type 'string
988 :group 'vhdl-header)
989
990 (defcustom vhdl-date-format "%Y-%m-%d"
991 "*Specifies the date format to use in the header.
992 This string is passed as argument to the command `format-time-string'.
993 For more information on format strings, see the documentation for the
994 `format-time-string' command (C-h f `format-time-string')."
995 :type 'string
996 :group 'vhdl-header)
997
998 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
999 "*Prefix string of modification date in VHDL file header.
1000 If actualization of the modification date is called (menu,
1001 `\\[vhdl-template-modify]'), this string is searched and the rest
1002 of the line replaced by the current date."
1003 :type 'string
1004 :group 'vhdl-header)
1005
1006 (defcustom vhdl-modify-date-on-saving t
1007 "*Non-nil means update the modification date when the buffer is saved.
1008 Calls function `\\[vhdl-template-modify]').
1009
1010 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1011 \"Activate Options\"."
1012 :type 'boolean
1013 :group 'vhdl-header)
1014
1015
1016 (defgroup vhdl-sequential-process nil
1017 "Customizations for sequential processes."
1018 :group 'vhdl-template)
1019
1020 (defcustom vhdl-reset-kind 'async
1021 "*Specifies which kind of reset to use in sequential processes."
1022 :type '(choice (const :tag "None" none)
1023 (const :tag "Synchronous" sync)
1024 (const :tag "Asynchronous" async))
1025 :group 'vhdl-sequential-process)
1026
1027 (defcustom vhdl-reset-active-high nil
1028 "*Non-nil means reset in sequential processes is active high.
1029 Otherwise, reset is active low."
1030 :type 'boolean
1031 :group 'vhdl-sequential-process)
1032
1033 (defcustom vhdl-clock-rising-edge t
1034 "*Non-nil means rising edge of clock triggers sequential processes.
1035 Otherwise, falling edge triggers."
1036 :type 'boolean
1037 :group 'vhdl-sequential-process)
1038
1039 (defcustom vhdl-clock-edge-condition 'standard
1040 "*Syntax of the clock edge condition.
1041 Standard: \"clk'event and clk = '1'\"
1042 Function: \"rising_edge(clk)\""
1043 :type '(choice (const :tag "Standard" standard)
1044 (const :tag "Function" function))
1045 :group 'vhdl-sequential-process)
1046
1047 (defcustom vhdl-clock-name ""
1048 "*Name of clock signal to use in templates."
1049 :type 'string
1050 :group 'vhdl-sequential-process)
1051
1052 (defcustom vhdl-reset-name ""
1053 "*Name of reset signal to use in templates."
1054 :type 'string
1055 :group 'vhdl-sequential-process)
1056
1057
1058 (defgroup vhdl-model nil
1059 "Customizations for user models."
1060 :group 'vhdl)
1061
1062 (defcustom vhdl-model-alist
1063 '(("Example Model"
1064 "<label> : process (<clock>, <reset>)
1065 begin -- process <label>
1066 if <reset> = '0' then -- asynchronous reset (active low)
1067 <cursor>
1068 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1069 if <enable> = '1' then -- synchronous load
1070
1071 end if;
1072 end if;
1073 end process <label>;"
1074 "e" ""))
1075 "*List of user models.
1076 VHDL models (templates) can be specified by the user in this list. They can be
1077 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1078 electrification (i.e. overriding existing or creating new keywords, see
1079 option `vhdl-electric-keywords').
1080 Name : name of model (string of words and spaces)
1081 String : string or name of file to be inserted as model (newline: `C-j')
1082 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1083 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1084 Keyword : keyword to invoke model
1085
1086 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1087 A prompt that appears several times is queried once and replaced throughout
1088 the model. Special prompts are:
1089 <clock> : name specified in `vhdl-clock-name' (if not empty)
1090 <reset> : name specified in `vhdl-reset-name' (if not empty)
1091 <cursor>: final cursor position
1092 File header prompts (see variable `vhdl-file-header') are automatically
1093 replaced, so that user models can also be used to insert different types of
1094 headers.
1095
1096 If the string specifies an existing file name, the contents of the file is
1097 inserted, otherwise the string itself is inserted.
1098 The code within the models should be correctly indented.
1099 Type `C-j' for newlines.
1100
1101 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1102 \"Activate Options\"."
1103 :type '(repeat (list :tag "Model" :indent 2
1104 (string :tag "Name ")
1105 (string :tag "String : (type `C-j' for newline)"
1106 :format "%t\n%v")
1107 (sexp :tag "Key binding" x)
1108 (string :tag "Keyword " :format "%t: %v\n")))
1109 :set (lambda (variable value)
1110 (vhdl-custom-set variable value
1111 'vhdl-model-map-init
1112 'vhdl-model-defun
1113 'vhdl-mode-abbrev-table-init
1114 'vhdl-update-mode-menu))
1115 :group 'vhdl-model)
1116
1117
1118 (defgroup vhdl-compose nil
1119 "Customizations for structural composition."
1120 :group 'vhdl)
1121
1122 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1123 (concat
1124 "*Specifies how the component architecture name is obtained.
1125 The component architecture name can be obtained by modifying the entity name
1126 \(e.g. attaching or stripping off a substring).
1127 If TO STRING is empty, the architecture name is queried."
1128 vhdl-name-doc-string)
1129 :type '(cons (regexp :tag "From regexp")
1130 (string :tag "To string "))
1131 :group 'vhdl-compose)
1132
1133 (defcustom vhdl-compose-configuration-name
1134 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1135 (concat
1136 "*Specifies how the configuration name is obtained.
1137 The configuration name can be obtained by modifying the entity and/or
1138 architecture name (e.g. attaching or stripping off a substring). The string
1139 that is matched against the regexp is the concatenation of the entity and the
1140 architecture name separated by a space. This gives access to both names (see
1141 default setting as example)."
1142 vhdl-name-doc-string)
1143 :type '(cons (regexp :tag "From regexp")
1144 (string :tag "To string "))
1145 :group 'vhdl-compose)
1146
1147 (defcustom vhdl-components-package-name
1148 '((".*" . "\\&_components") . "components")
1149 (concat
1150 "*Specifies how the name for the components package is obtained.
1151 The components package is a package containing all component declarations for
1152 the current design. Its name can be obtained by modifying the project name
1153 \(e.g. attaching or stripping off a substring). If no project is defined, the
1154 DIRECTORY entry is chosen."
1155 vhdl-name-doc-string)
1156 :type '(cons (cons :tag "Project" :indent 2
1157 (regexp :tag "From regexp")
1158 (string :tag "To string "))
1159 (string :tag "Directory:\n String "))
1160 :group 'vhdl-compose)
1161
1162 (defcustom vhdl-use-components-package nil
1163 "*Non-nil means use a separate components package for component declarations.
1164 Otherwise, component declarations are inserted and searched for in the
1165 architecture declarative parts."
1166 :type 'boolean
1167 :group 'vhdl-compose)
1168
1169 (defcustom vhdl-compose-include-header t
1170 "*Non-nil means include a header in automatically generated files."
1171 :type 'boolean
1172 :group 'vhdl-compose)
1173
1174 (defcustom vhdl-compose-create-files 'single
1175 "*Specifies whether new files should be created for the new component.
1176 The component's entity and architecture are inserted:
1177 None : in current buffer
1178 Single file : in new single file
1179 Separate files: in two separate files
1180 The file names are obtained from variables `vhdl-entity-file-name' and
1181 `vhdl-architecture-file-name'."
1182 :type '(choice (const :tag "None" none)
1183 (const :tag "Single file" single)
1184 (const :tag "Separate files" separate))
1185 :group 'vhdl-compose)
1186
1187 (defcustom vhdl-compose-configuration-create-file nil
1188 "*Specifies whether a new file should be created for the configuration.
1189 If non-nil, a new file is created for the configuration.
1190 The file name is obtained from variable `vhdl-configuration-file-name'."
1191 :type 'boolean
1192 :group 'vhdl-compose)
1193
1194 (defcustom vhdl-compose-configuration-hierarchical t
1195 "*Specifies whether hierarchical configurations should be created.
1196 If non-nil, automatically created configurations are hierarchical and include
1197 the whole hierarchy of subcomponents. Otherwise the configuration only
1198 includes one level of subcomponents."
1199 :type 'boolean
1200 :group 'vhdl-compose)
1201
1202 (defcustom vhdl-compose-configuration-use-subconfiguration t
1203 "*Specifies whether subconfigurations should be used inside configurations.
1204 If non-nil, automatically created configurations use configurations in binding
1205 indications for subcomponents, if such configurations exist. Otherwise,
1206 entities are used in binding indications for subcomponents."
1207 :type 'boolean
1208 :group 'vhdl-compose)
1209
1210
1211 (defgroup vhdl-port nil
1212 "Customizations for port translation functions."
1213 :group 'vhdl
1214 :group 'vhdl-compose)
1215
1216 (defcustom vhdl-include-port-comments nil
1217 "*Non-nil means include port comments when a port is pasted."
1218 :type 'boolean
1219 :group 'vhdl-port)
1220
1221 (defcustom vhdl-include-direction-comments nil
1222 "*Non-nil means include port direction in instantiations as comments."
1223 :type 'boolean
1224 :group 'vhdl-port)
1225
1226 (defcustom vhdl-include-type-comments nil
1227 "*Non-nil means include generic/port type in instantiations as comments."
1228 :type 'boolean
1229 :group 'vhdl-port)
1230
1231 (defcustom vhdl-include-group-comments 'never
1232 "*Specifies whether to include group comments and spacings.
1233 The comments and empty lines between groups of ports are pasted:
1234 Never : never
1235 Declarations: in entity/component/constant/signal declarations only
1236 Always : also in generic/port maps"
1237 :type '(choice (const :tag "Never" never)
1238 (const :tag "Declarations" decl)
1239 (const :tag "Always" always))
1240 :group 'vhdl-port)
1241
1242 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1243 (concat
1244 "*Specifies how actual port names are obtained from formal port names.
1245 In a component instantiation, an actual port name can be obtained by
1246 modifying the formal port name (e.g. attaching or stripping off a substring)."
1247 vhdl-name-doc-string)
1248 :type '(cons (regexp :tag "From regexp")
1249 (string :tag "To string "))
1250 :group 'vhdl-port)
1251
1252 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1253 (concat
1254 "*Specifies how an instance name is obtained.
1255 The instance name can be obtained by modifying the name of the component to be
1256 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1257 by a unique number (starting with 1).
1258 If TO STRING is empty, the instance name is queried."
1259 vhdl-name-doc-string)
1260 :type '(cons (regexp :tag "From regexp")
1261 (string :tag "To string "))
1262 :group 'vhdl-port)
1263
1264
1265 (defgroup vhdl-testbench nil
1266 "Customizations for testbench generation."
1267 :group 'vhdl-port)
1268
1269 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1270 (concat
1271 "*Specifies how the testbench entity name is obtained.
1272 The entity name of a testbench can be obtained by modifying the name of
1273 the component to be tested (e.g. attaching or stripping off a substring)."
1274 vhdl-name-doc-string)
1275 :type '(cons (regexp :tag "From regexp")
1276 (string :tag "To string "))
1277 :group 'vhdl-testbench)
1278
1279 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1280 (concat
1281 "*Specifies how the testbench architecture name is obtained.
1282 The testbench architecture name can be obtained by modifying the name of
1283 the component to be tested (e.g. attaching or stripping off a substring).
1284 If TO STRING is empty, the architecture name is queried."
1285 vhdl-name-doc-string)
1286 :type '(cons (regexp :tag "From regexp")
1287 (string :tag "To string "))
1288 :group 'vhdl-testbench)
1289
1290 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1291 (concat
1292 "*Specifies how the testbench configuration name is obtained.
1293 The configuration name of a testbench can be obtained by modifying the entity
1294 and/or architecture name (e.g. attaching or stripping off a substring). The
1295 string that is matched against the regexp is the concatenation of the entity
1296 and the architecture name separated by a space. This gives access to both
1297 names (see default setting as example)."
1298 vhdl-name-doc-string)
1299 :type '(cons (regexp :tag "From regexp")
1300 (string :tag "To string "))
1301 :group 'vhdl-testbench)
1302
1303 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1304 (concat
1305 "*Specifies how a DUT instance name is obtained.
1306 The design-under-test instance name (i.e. the component instantiated in the
1307 testbench) can be obtained by modifying the component name (e.g. attaching
1308 or stripping off a substring)."
1309 vhdl-name-doc-string)
1310 :type '(cons (regexp :tag "From regexp")
1311 (string :tag "To string "))
1312 :group 'vhdl-testbench)
1313
1314 (defcustom vhdl-testbench-include-header t
1315 "*Non-nil means include a header in automatically generated files."
1316 :type 'boolean
1317 :group 'vhdl-testbench)
1318
1319 (defcustom vhdl-testbench-declarations "\
1320 -- clock
1321 signal Clk : std_logic := '1';
1322 "
1323 "*String or file to be inserted in the testbench declarative part.
1324 If the string specifies an existing file name, the contents of the file is
1325 inserted, otherwise the string itself is inserted in the testbench
1326 architecture before the BEGIN keyword.
1327 Type `C-j' for newlines."
1328 :type 'string
1329 :group 'vhdl-testbench)
1330
1331 (defcustom vhdl-testbench-statements "\
1332 -- clock generation
1333 Clk <= not Clk after 10 ns;
1334
1335 -- waveform generation
1336 WaveGen_Proc: process
1337 begin
1338 -- insert signal assignments here
1339
1340 wait until Clk = '1';
1341 end process WaveGen_Proc;
1342 "
1343 "*String or file to be inserted in the testbench statement part.
1344 If the string specifies an existing file name, the contents of the file is
1345 inserted, otherwise the string itself is inserted in the testbench
1346 architecture before the END keyword.
1347 Type `C-j' for newlines."
1348 :type 'string
1349 :group 'vhdl-testbench)
1350
1351 (defcustom vhdl-testbench-initialize-signals nil
1352 "*Non-nil means initialize signals with `0' when declared in testbench."
1353 :type 'boolean
1354 :group 'vhdl-testbench)
1355
1356 (defcustom vhdl-testbench-include-library t
1357 "*Non-nil means a library/use clause for std_logic_1164 is included."
1358 :type 'boolean
1359 :group 'vhdl-testbench)
1360
1361 (defcustom vhdl-testbench-include-configuration t
1362 "*Non-nil means a testbench configuration is attached at the end."
1363 :type 'boolean
1364 :group 'vhdl-testbench)
1365
1366 (defcustom vhdl-testbench-create-files 'single
1367 "*Specifies whether new files should be created for the testbench.
1368 testbench entity and architecture are inserted:
1369 None : in current buffer
1370 Single file : in new single file
1371 Separate files: in two separate files
1372 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1373 and `vhdl-testbench-architecture-file-name'."
1374 :type '(choice (const :tag "None" none)
1375 (const :tag "Single file" single)
1376 (const :tag "Separate files" separate))
1377 :group 'vhdl-testbench)
1378
1379 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1380 (concat
1381 "*Specifies how the testbench entity file name is obtained.
1382 The entity file name can be obtained by modifying the testbench entity name
1383 \(e.g. attaching or stripping off a substring). The file extension is
1384 automatically taken from the file name of the current buffer. Testbench
1385 files can be created in a different directory by prepending a relative or
1386 absolute path to the file name."
1387 vhdl-name-doc-string)
1388 :type '(cons (regexp :tag "From regexp")
1389 (string :tag "To string "))
1390 :group 'vhdl-testbench)
1391
1392 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1393 (concat
1394 "*Specifies how the testbench architecture file name is obtained.
1395 The architecture file name can be obtained by modifying the testbench entity
1396 and/or architecture name (e.g. attaching or stripping off a substring). The
1397 string that is matched against the regexp is the concatenation of the entity
1398 and the architecture name separated by a space. This gives access to both
1399 names (see default setting as example). Testbench files can be created in
1400 a different directory by prepending a relative or absolute path to the file
1401 name."
1402 vhdl-name-doc-string)
1403 :type '(cons (regexp :tag "From regexp")
1404 (string :tag "To string "))
1405 :group 'vhdl-testbench)
1406
1407
1408 (defgroup vhdl-comment nil
1409 "Customizations for comments."
1410 :group 'vhdl)
1411
1412 (defcustom vhdl-self-insert-comments t
1413 "*Non-nil means various templates automatically insert help comments."
1414 :type 'boolean
1415 :group 'vhdl-comment)
1416
1417 (defcustom vhdl-prompt-for-comments t
1418 "*Non-nil means various templates prompt for user definable comments."
1419 :type 'boolean
1420 :group 'vhdl-comment)
1421
1422 (defcustom vhdl-inline-comment-column 40
1423 "*Column to indent and align inline comments to.
1424 Overrides local option `comment-column'.
1425
1426 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1427 \"Activate Options\"."
1428 :type 'integer
1429 :group 'vhdl-comment)
1430
1431 (defcustom vhdl-end-comment-column 79
1432 "*End of comment column.
1433 Comments that exceed this column number are wrapped.
1434
1435 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1436 \"Activate Options\"."
1437 :type 'integer
1438 :group 'vhdl-comment)
1439
1440 (defvar end-comment-column)
1441
1442
1443 (defgroup vhdl-align nil
1444 "Customizations for alignment."
1445 :group 'vhdl)
1446
1447 (defcustom vhdl-auto-align t
1448 "*Non-nil means align some templates automatically after generation."
1449 :type 'boolean
1450 :group 'vhdl-align)
1451
1452 (defcustom vhdl-align-groups t
1453 "*Non-nil means align groups of code lines separately.
1454 A group of code lines is a region of consecutive lines between two lines that
1455 match the regexp in option `vhdl-align-group-separate'."
1456 :type 'boolean
1457 :group 'vhdl-align)
1458
1459 (defcustom vhdl-align-group-separate "^\\s-*$"
1460 "*Regexp for matching a line that separates groups of lines for alignment.
1461 Examples:
1462 \"^\\s-*$\": matches an empty line
1463 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1464 :type 'regexp
1465 :group 'vhdl-align)
1466
1467 (defcustom vhdl-align-same-indent t
1468 "*Non-nil means align blocks with same indent separately.
1469 When a region or the entire buffer is aligned, the code is divided into
1470 blocks of same indent which are aligned separately (except for argument/port
1471 lists). This gives nicer alignment in most cases.
1472 Option `vhdl-align-groups' still applies within these blocks."
1473 :type 'boolean
1474 :group 'vhdl-align)
1475
1476
1477 (defgroup vhdl-highlight nil
1478 "Customizations for highlighting."
1479 :group 'vhdl)
1480
1481 (defcustom vhdl-highlight-keywords t
1482 "*Non-nil means highlight VHDL keywords and other standardized words.
1483 The following faces are used:
1484 `font-lock-keyword-face' : keywords
1485 `font-lock-type-face' : standardized types
1486 `vhdl-font-lock-attribute-face': standardized attributes
1487 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1488 `vhdl-font-lock-function-face' : standardized function and package names
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-names t
1498 "*Non-nil means highlight declaration names and construct labels.
1499 The following faces are used:
1500 `font-lock-function-name-face' : names in declarations of units,
1501 subprograms, components, as well as labels of VHDL constructs
1502 `font-lock-type-face' : names in type/nature declarations
1503 `vhdl-font-lock-attribute-face': names in attribute declarations
1504 `font-lock-variable-name-face' : names in declarations of signals,
1505 variables, constants, subprogram parameters, generics, and ports
1506
1507 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1508 entry \"Fontify Buffer\")."
1509 :type 'boolean
1510 :set (lambda (variable value)
1511 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1512 :group 'vhdl-highlight)
1513
1514 (defcustom vhdl-highlight-special-words nil
1515 "*Non-nil means highlight words with special syntax.
1516 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1517 are highlighted accordingly.
1518 Can be used for visual support of naming conventions.
1519
1520 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1521 entry \"Fontify Buffer\")."
1522 :type 'boolean
1523 :set (lambda (variable value)
1524 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1525 :group 'vhdl-highlight)
1526
1527 (defcustom vhdl-highlight-forbidden-words nil
1528 "*Non-nil means highlight forbidden words.
1529 The reserved words specified in option `vhdl-forbidden-words' or having the
1530 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1531 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1532 use them.
1533
1534 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1535 entry \"Fontify Buffer\")."
1536 :type 'boolean
1537 :set (lambda (variable value)
1538 (vhdl-custom-set variable value
1539 'vhdl-words-init 'vhdl-font-lock-init))
1540 :group 'vhdl-highlight)
1541
1542 (defcustom vhdl-highlight-verilog-keywords nil
1543 "*Non-nil means highlight Verilog keywords as reserved words.
1544 Verilog keywords are highlighted in a warning color (face
1545 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1546
1547 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1548 entry \"Fontify Buffer\")."
1549 :type 'boolean
1550 :set (lambda (variable value)
1551 (vhdl-custom-set variable value
1552 'vhdl-words-init 'vhdl-font-lock-init))
1553 :group 'vhdl-highlight)
1554
1555 (defcustom vhdl-highlight-translate-off nil
1556 "*Non-nil means background-highlight code excluded from translation.
1557 That is, all code between \"-- pragma translate_off\" and
1558 \"-- pragma translate_on\" is highlighted using a different background color
1559 \(face `vhdl-font-lock-translate-off-face').
1560 Note: this might slow down on-the-fly fontification (and thus editing).
1561
1562 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1563 entry \"Fontify Buffer\")."
1564 :type 'boolean
1565 :set (lambda (variable value)
1566 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1567 :group 'vhdl-highlight)
1568
1569 (defcustom vhdl-highlight-case-sensitive nil
1570 "*Non-nil means consider case for highlighting.
1571 Possible trade-off:
1572 non-nil also upper-case VHDL words are highlighted, but case of words with
1573 special syntax is not considered
1574 nil only lower-case VHDL words are highlighted, but case of words with
1575 special syntax is considered
1576 Overrides local option `font-lock-keywords-case-fold-search'.
1577
1578 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1579 entry \"Fontify Buffer\")."
1580 :type 'boolean
1581 :group 'vhdl-highlight)
1582
1583 (defcustom vhdl-special-syntax-alist
1584 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1585 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1586 ("variable" "\\w+_v" "Grey50" "Grey80"))
1587 "*List of special syntax to be highlighted.
1588 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1589 syntax (as regular expression) are highlighted in the corresponding color.
1590
1591 Name : string of words and spaces
1592 Regexp : regular expression describing word syntax
1593 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1594 Color (light): foreground color for light background
1595 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1596 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1597 Color (dark) : foreground color for dark background
1598 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1599 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1600
1601 Can be used for visual support of naming conventions, such as highlighting
1602 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1603 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1604 common substrings or name suffices.
1605 For each entry, a new face is generated with the specified colors and name
1606 \"vhdl-font-lock-\" + name + \"-face\".
1607
1608 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1610 :type '(repeat (list :tag "Face" :indent 2
1611 (string :tag "Name ")
1612 (regexp :tag "Regexp " "\\w+_")
1613 (string :tag "Color (light)")
1614 (string :tag "Color (dark) ")))
1615 :set (lambda (variable value)
1616 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1617 :group 'vhdl-highlight)
1618
1619 (defcustom vhdl-forbidden-words '()
1620 "*List of forbidden words to be highlighted.
1621 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1622 words are highlighted in a warning color to indicate not to use them.
1623
1624 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1625 entry \"Fontify Buffer\")."
1626 :type '(repeat (string :format "%v"))
1627 :set (lambda (variable value)
1628 (vhdl-custom-set variable value
1629 'vhdl-words-init 'vhdl-font-lock-init))
1630 :group 'vhdl-highlight)
1631
1632 (defcustom vhdl-forbidden-syntax ""
1633 "*Syntax of forbidden words to be highlighted.
1634 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1635 syntax are highlighted in a warning color to indicate not to use them.
1636 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1637 highlights identifiers with 10 or more characters).
1638
1639 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1640 entry \"Fontify Buffer\")."
1641 :type 'regexp
1642 :set (lambda (variable value)
1643 (vhdl-custom-set variable value
1644 'vhdl-words-init 'vhdl-font-lock-init))
1645 :group 'vhdl-highlight)
1646
1647 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1648 "*List of compiler directive keywords recognized for highlighting.
1649
1650 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1651 entry \"Fontify Buffer\")."
1652 :type '(repeat (string :format "%v"))
1653 :set (lambda (variable value)
1654 (vhdl-custom-set variable value
1655 'vhdl-words-init 'vhdl-font-lock-init))
1656 :group 'vhdl-highlight)
1657
1658
1659 (defgroup vhdl-speedbar nil
1660 "Customizations for speedbar."
1661 :group 'vhdl)
1662
1663 (defcustom vhdl-speedbar-auto-open nil
1664 "*Non-nil means automatically open speedbar at startup.
1665 Alternatively, the speedbar can be opened from the VHDL menu."
1666 :type 'boolean
1667 :group 'vhdl-speedbar)
1668
1669 (defcustom vhdl-speedbar-display-mode 'files
1670 "*Specifies the default displaying mode when opening speedbar.
1671 Alternatively, the displaying mode can be selected from the speedbar menu or
1672 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1673 :type '(choice (const :tag "Files" files)
1674 (const :tag "Directory hierarchy" directory)
1675 (const :tag "Project hierarchy" project))
1676 :group 'vhdl-speedbar)
1677
1678 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1679 "*Limits scanning of large files and netlists.
1680 Design units: maximum file size to scan for design units
1681 Hierarchy (instances of subcomponents):
1682 File size: maximum file size to scan for instances (in bytes)
1683 Instances per arch: maximum number of instances to scan per architecture
1684
1685 \"None\" always means that there is no limit.
1686 In case of files not or incompletely scanned, a warning message and the file
1687 names are printed out.
1688 Background: scanning for instances is considerably slower than scanning for
1689 design units, especially when there are many instances. These limits should
1690 prevent the scanning of large netlists."
1691 :type '(list (choice :tag "Design units"
1692 :format "%t : %[Value Menu%] %v"
1693 (const :tag "None" nil)
1694 (integer :tag "File size"))
1695 (list :tag "Hierarchy" :indent 2
1696 (choice :tag "File size"
1697 :format "%t : %[Value Menu%] %v"
1698 (const :tag "None" nil)
1699 (integer :tag "Size "))
1700 (choice :tag "Instances per arch"
1701 (const :tag "None" nil)
1702 (integer :tag "Number "))))
1703 :group 'vhdl-speedbar)
1704
1705 (defcustom vhdl-speedbar-jump-to-unit t
1706 "*Non-nil means jump to the design unit code when opened in a buffer.
1707 The buffer cursor position is left unchanged otherwise."
1708 :type 'boolean
1709 :group 'vhdl-speedbar)
1710
1711 (defcustom vhdl-speedbar-update-on-saving t
1712 "*Automatically update design hierarchy when buffer is saved."
1713 :type 'boolean
1714 :group 'vhdl-speedbar)
1715
1716 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1717 "*Automatically save modified hierarchy caches when exiting Emacs.
1718 Hierarchy: design hierarchy information
1719 Display: displaying information (which design units to expand)"
1720 :type '(set (const :tag "Hierarchy" hierarchy)
1721 (const :tag "Display" display))
1722 :group 'vhdl-speedbar)
1723
1724 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1725 "*Name of file for saving hierarchy cache.
1726 \"\\1\" is replaced by the project name if a project is specified,
1727 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1728 different users to have cache files in the same directory). Can also have
1729 an absolute path (i.e. all caches can be stored in one global directory)."
1730 :type 'string
1731 :group 'vhdl-speedbar)
1732
1733
1734 (defgroup vhdl-menu nil
1735 "Customizations for menues."
1736 :group 'vhdl)
1737
1738 (defcustom vhdl-index-menu nil
1739 "*Non-nil means add an index menu for a source file when loading.
1740 Alternatively, the speedbar can be used. Note that the index menu scans a file
1741 when it is opened, while speedbar only scans the file upon request."
1742 :type 'boolean
1743 :group 'vhdl-menu)
1744
1745 (defcustom vhdl-source-file-menu nil
1746 "*Non-nil means add a menu of all source files in current directory.
1747 Alternatively, the speedbar can be used."
1748 :type 'boolean
1749 :group 'vhdl-menu)
1750
1751 (defcustom vhdl-hideshow-menu nil
1752 "*Non-nil means add hideshow menu and functionality at startup.
1753 Hideshow can also be enabled from the VHDL Mode menu.
1754 Hideshow allows hiding code of various VHDL constructs.
1755
1756 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1757 \"Activate Options\"."
1758 :type 'boolean
1759 :group 'vhdl-menu)
1760
1761 (defcustom vhdl-hide-all-init nil
1762 "*Non-nil means hide all design units initially after a file is loaded."
1763 :type 'boolean
1764 :group 'vhdl-menu)
1765
1766
1767 (defgroup vhdl-print nil
1768 "Customizations for printing."
1769 :group 'vhdl)
1770
1771 (defcustom vhdl-print-two-column t
1772 "*Non-nil means print code in two columns and landscape format.
1773 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1774 prints VHDL files in a nice two-column landscape style.
1775
1776 NOTE: Activate the new setting by restarting Emacs.
1777 Overrides `ps-print' settings locally."
1778 :type 'boolean
1779 :group 'vhdl-print)
1780
1781 (defcustom vhdl-print-customize-faces t
1782 "*Non-nil means use an optimized set of faces for postscript printing.
1783
1784 NOTE: Activate the new setting by restarting Emacs.
1785 Overrides `ps-print' settings locally."
1786 :type 'boolean
1787 :group 'vhdl-print)
1788
1789
1790 (defgroup vhdl-misc nil
1791 "Miscellaneous customizations."
1792 :group 'vhdl)
1793
1794 (defcustom vhdl-intelligent-tab t
1795 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1796 That is, if preceeding character is part of a word then complete word,
1797 else if not at beginning of line then insert tab,
1798 else if last command was a `TAB' or `RET' then dedent one step,
1799 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1800 If nil, TAB always indents current line (i.e. `TAB' is bound to
1801 `indent-according-to-mode').
1802
1803 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1804 \"Activate Options\"."
1805 :type 'boolean
1806 :group 'vhdl-misc)
1807
1808 (defcustom vhdl-indent-syntax-based t
1809 "*Non-nil means indent lines of code based on their syntactic context.
1810 Otherwise, a line is indented like the previous nonblank line. This can be
1811 useful in large files where syntax-based indentation gets very slow."
1812 :type 'boolean
1813 :group 'vhdl-misc)
1814
1815 (defcustom vhdl-word-completion-case-sensitive nil
1816 "*Non-nil means word completion using `TAB' is case sensitive.
1817 That is, `TAB' completes words that start with the same letters and case.
1818 Otherwise, case is ignored."
1819 :type 'boolean
1820 :group 'vhdl-misc)
1821
1822 (defcustom vhdl-word-completion-in-minibuffer t
1823 "*Non-nil enables word completion in minibuffer (for template prompts).
1824
1825 NOTE: Activate the new setting by restarting Emacs."
1826 :type 'boolean
1827 :group 'vhdl-misc)
1828
1829 (defcustom vhdl-underscore-is-part-of-word nil
1830 "*Non-nil means consider the underscore character `_' as part of word.
1831 An identifier containing underscores is then treated as a single word in
1832 select and move operations. All parts of an identifier separated by underscore
1833 are treated as single words otherwise.
1834
1835 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1836 \"Activate Options\"."
1837 :type 'boolean
1838 :set (lambda (variable value)
1839 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1840 :group 'vhdl-misc)
1841
1842
1843 (defgroup vhdl-related nil
1844 "Related general customizations."
1845 :group 'vhdl)
1846
1847 ;; add related general customizations
1848 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1849 (if (featurep 'xemacs)
1850 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1851 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1852 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1853 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1854 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1855 (unless (featurep 'xemacs)
1856 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1857 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1858 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1859 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1860
1861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1862 ;; Internal variables
1863
1864 (defvar vhdl-menu-max-size 20
1865 "*Specifies the maximum size of a menu before splitting it into submenues.")
1866
1867 (defvar vhdl-progress-interval 1
1868 "*Interval used to update progress status during long operations.
1869 If a number, percentage complete gets updated after each interval of
1870 that many seconds. To inhibit all messages, set this option to nil.")
1871
1872 (defvar vhdl-inhibit-startup-warnings-p nil
1873 "*If non-nil, inhibits start up compatibility warnings.")
1874
1875 (defvar vhdl-strict-syntax-p nil
1876 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1877 If the syntactic symbol for a particular line does not match a symbol
1878 in the offsets alist, an error is generated, otherwise no error is
1879 reported and the syntactic symbol is ignored.")
1880
1881 (defvar vhdl-echo-syntactic-information-p nil
1882 "*If non-nil, syntactic info is echoed when the line is indented.")
1883
1884 (defconst vhdl-offsets-alist-default
1885 '((string . -1000)
1886 (cpp-macro . -1000)
1887 (block-open . 0)
1888 (block-close . 0)
1889 (statement . 0)
1890 (statement-cont . vhdl-lineup-statement-cont)
1891 (statement-block-intro . +)
1892 (statement-case-intro . +)
1893 (case-alternative . +)
1894 (comment . vhdl-lineup-comment)
1895 (arglist-intro . +)
1896 (arglist-cont . 0)
1897 (arglist-cont-nonempty . vhdl-lineup-arglist)
1898 (arglist-close . vhdl-lineup-arglist)
1899 (entity . 0)
1900 (configuration . 0)
1901 (package . 0)
1902 (architecture . 0)
1903 (package-body . 0)
1904 )
1905 "Default settings for offsets of syntactic elements.
1906 Do not change this constant! See the variable `vhdl-offsets-alist' for
1907 more information.")
1908
1909 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1910 "*Association list of syntactic element symbols and indentation offsets.
1911 As described below, each cons cell in this list has the form:
1912
1913 (SYNTACTIC-SYMBOL . OFFSET)
1914
1915 When a line is indented, `vhdl-mode' first determines the syntactic
1916 context of the line by generating a list of symbols called syntactic
1917 elements. This list can contain more than one syntactic element and
1918 the global variable `vhdl-syntactic-context' contains the context list
1919 for the line being indented. Each element in this list is actually a
1920 cons cell of the syntactic symbol and a buffer position. This buffer
1921 position is call the relative indent point for the line. Some
1922 syntactic symbols may not have a relative indent point associated with
1923 them.
1924
1925 After the syntactic context list for a line is generated, `vhdl-mode'
1926 calculates the absolute indentation for the line by looking at each
1927 syntactic element in the list. First, it compares the syntactic
1928 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1929 finds a match, it adds the OFFSET to the column of the relative indent
1930 point. The sum of this calculation for each element in the syntactic
1931 list is the absolute offset for line being indented.
1932
1933 If the syntactic element does not match any in the `vhdl-offsets-alist',
1934 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1935 the element is ignored.
1936
1937 Actually, OFFSET can be an integer, a function, a variable, or one of
1938 the following symbols: `+', `-', `++', or `--'. These latter
1939 designate positive or negative multiples of `vhdl-basic-offset',
1940 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1941 called with a single argument containing the cons of the syntactic
1942 element symbol and the relative indent point. The function should
1943 return an integer offset.
1944
1945 Here is the current list of valid syntactic element symbols:
1946
1947 string -- inside multi-line string
1948 block-open -- statement block open
1949 block-close -- statement block close
1950 statement -- a VHDL statement
1951 statement-cont -- a continuation of a VHDL statement
1952 statement-block-intro -- the first line in a new statement block
1953 statement-case-intro -- the first line in a case alternative block
1954 case-alternative -- a case statement alternative clause
1955 comment -- a line containing only a comment
1956 arglist-intro -- the first line in an argument list
1957 arglist-cont -- subsequent argument list lines when no
1958 arguments follow on the same line as the
1959 the arglist opening paren
1960 arglist-cont-nonempty -- subsequent argument list lines when at
1961 least one argument follows on the same
1962 line as the arglist opening paren
1963 arglist-close -- the solo close paren of an argument list
1964 entity -- inside an entity declaration
1965 configuration -- inside a configuration declaration
1966 package -- inside a package declaration
1967 architecture -- inside an architecture body
1968 package-body -- inside a package body")
1969
1970 (defvar vhdl-comment-only-line-offset 0
1971 "*Extra offset for line which contains only the start of a comment.
1972 Can contain an integer or a cons cell of the form:
1973
1974 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1975
1976 Where NON-ANCHORED-OFFSET is the amount of offset given to
1977 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1978 the amount of offset to give column-zero anchored comment-only lines.
1979 Just an integer as value is equivalent to (<val> . 0)")
1980
1981 (defvar vhdl-special-indent-hook nil
1982 "*Hook for user defined special indentation adjustments.
1983 This hook gets called after a line is indented by the mode.")
1984
1985 (defvar vhdl-style-alist
1986 '(("IEEE"
1987 (vhdl-basic-offset . 4)
1988 (vhdl-offsets-alist . ())))
1989 "Styles of Indentation.
1990 Elements of this alist are of the form:
1991
1992 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1993
1994 where STYLE-STRING is a short descriptive string used to select a
1995 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1996 value for that variable when using the selected style.
1997
1998 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1999 case, the VALUE is a list containing elements of the form:
2000
2001 (SYNTACTIC-SYMBOL . VALUE)
2002
2003 as described in `vhdl-offsets-alist'. These are passed directly to
2004 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2005 your style, only those that are different from the default.")
2006
2007 ;; dynamically append the default value of most variables
2008 (or (assoc "Default" vhdl-style-alist)
2009 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2010 vhdl-strict-syntax-p
2011 vhdl-echo-syntactic-information-p
2012 vhdl-basic-offset
2013 vhdl-offsets-alist
2014 vhdl-comment-only-line-offset))
2015 (default (cons "Default"
2016 (mapcar
2017 (function
2018 (lambda (var)
2019 (cons var (symbol-value var))))
2020 varlist))))
2021 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2022
2023 (defvar vhdl-mode-hook nil
2024 "*Hook called by `vhdl-mode'.")
2025
2026
2027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2028 ;;; Required packages
2029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030
2031 ;; mandatory
2032 (require 'assoc)
2033 (require 'compile) ; XEmacs
2034 (require 'easymenu)
2035 (require 'hippie-exp)
2036
2037 ;; optional (minimize warning messages during compile)
2038 (eval-when-compile
2039 (require 'font-lock)
2040 (require 'ps-print)
2041 (require 'speedbar))
2042
2043
2044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2045 ;;; Compatibility
2046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2047
2048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2049 ;; XEmacs compatibility
2050
2051 ;; active regions
2052 (defun vhdl-keep-region-active ()
2053 "Do whatever is necessary to keep the region active in XEmacs.
2054 Ignore byte-compiler warnings you might see."
2055 (and (featurep 'xemacs)
2056 (setq zmacs-region-stays t)))
2057
2058 ;; `wildcard-to-regexp' is included only in XEmacs 21
2059 (unless (fboundp 'wildcard-to-regexp)
2060 (defun wildcard-to-regexp (wildcard)
2061 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2062 (let* ((i (string-match "[*?]" wildcard))
2063 (result (substring wildcard 0 i))
2064 (len (length wildcard)))
2065 (when i
2066 (while (< i len)
2067 (let ((ch (aref wildcard i)))
2068 (setq result (concat result
2069 (cond ((eq ch ?*) "[^\000]*")
2070 ((eq ch ??) "[^\000]")
2071 (t (char-to-string ch)))))
2072 (setq i (1+ i)))))
2073 (concat "\\`" result "\\'"))))
2074
2075 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2076 ;; `regexp-opt' accelerates fontification by 10-20%
2077 (unless (fboundp 'regexp-opt)
2078 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2079 (defun regexp-opt (strings &optional paren)
2080 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2081 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2082
2083 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2084 (unless (fboundp 'match-string-no-properties)
2085 (defalias 'match-string-no-properties 'match-string))
2086
2087 ;; `subst-char-in-string' undefined (XEmacs)
2088 (unless (fboundp 'subst-char-in-string)
2089 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2090 (let ((i (length string))
2091 (newstr (if inplace string (copy-sequence string))))
2092 (while (> i 0)
2093 (setq i (1- i))
2094 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2095 newstr)))
2096
2097 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2098 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2099 (not noninteractive))
2100 (load "itimer")
2101 (when (string< itimer-version "1.09")
2102 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2103 (beep) (sit-for 5)))
2104
2105 ;; `file-expand-wildcards' undefined (XEmacs)
2106 (unless (fboundp 'file-expand-wildcards)
2107 (defun file-expand-wildcards (pattern &optional full)
2108 "Taken from Emacs' `files.el'."
2109 (let* ((nondir (file-name-nondirectory pattern))
2110 (dirpart (file-name-directory pattern))
2111 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2112 (mapcar 'file-name-as-directory
2113 (file-expand-wildcards (directory-file-name dirpart)))
2114 (list dirpart)))
2115 contents)
2116 (while dirs
2117 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2118 (file-directory-p (directory-file-name (car dirs))))
2119 (let ((this-dir-contents
2120 (delq nil
2121 (mapcar #'(lambda (name)
2122 (unless (string-match "\\`\\.\\.?\\'"
2123 (file-name-nondirectory name))
2124 name))
2125 (directory-files (or (car dirs) ".") full
2126 (wildcard-to-regexp nondir))))))
2127 (setq contents
2128 (nconc
2129 (if (and (car dirs) (not full))
2130 (mapcar (function (lambda (name) (concat (car dirs) name)))
2131 this-dir-contents)
2132 this-dir-contents)
2133 contents))))
2134 (setq dirs (cdr dirs)))
2135 contents)))
2136
2137 ;; `member-ignore-case' undefined (XEmacs)
2138 (unless (fboundp 'member-ignore-case)
2139 (defalias 'member-ignore-case 'member))
2140
2141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2142 ;; Compatibility with older VHDL Mode versions
2143
2144 (defvar vhdl-warnings nil
2145 "Warnings to tell the user during start up.")
2146
2147 (defun vhdl-run-when-idle (secs repeat function)
2148 "Wait until idle, then run FUNCTION."
2149 (if (fboundp 'start-itimer)
2150 (start-itimer "vhdl-mode" function secs repeat t)
2151 ; (run-with-idle-timer secs repeat function)))
2152 ;; explicitely activate timer (necessary when Emacs is already idle)
2153 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2154
2155 (defun vhdl-warning-when-idle (&rest args)
2156 "Wait until idle, then print out warning STRING and beep."
2157 (if noninteractive
2158 (vhdl-warning (apply 'format args) t)
2159 (unless vhdl-warnings
2160 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2161 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2162
2163 (defun vhdl-warning (string &optional nobeep)
2164 "Print out warning STRING and beep."
2165 (message "WARNING: %s" string)
2166 (unless (or nobeep noninteractive) (beep)))
2167
2168 (defun vhdl-print-warnings ()
2169 "Print out messages in variable `vhdl-warnings'."
2170 (let ((no-warnings (length vhdl-warnings)))
2171 (setq vhdl-warnings (nreverse vhdl-warnings))
2172 (while vhdl-warnings
2173 (message "WARNING: %s" (car vhdl-warnings))
2174 (setq vhdl-warnings (cdr vhdl-warnings)))
2175 (beep)
2176 (when (> no-warnings 1)
2177 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2178
2179 ;; Backward compatibility checks and fixes
2180 ;; option `vhdl-compiler' changed format
2181 (unless (stringp vhdl-compiler)
2182 (setq vhdl-compiler "ModelSim")
2183 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2184
2185 ;; option `vhdl-standard' changed format
2186 (unless (listp vhdl-standard)
2187 (setq vhdl-standard '(87 nil))
2188 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2189
2190 ;; option `vhdl-model-alist' changed format
2191 (when (= (length (car vhdl-model-alist)) 3)
2192 (let ((old-alist vhdl-model-alist)
2193 new-alist)
2194 (while old-alist
2195 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2196 (setq old-alist (cdr old-alist)))
2197 (setq vhdl-model-alist (nreverse new-alist)))
2198 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2199
2200 ;; option `vhdl-project-alist' changed format
2201 (when (= (length (car vhdl-project-alist)) 3)
2202 (let ((old-alist vhdl-project-alist)
2203 new-alist)
2204 (while old-alist
2205 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2206 (setq old-alist (cdr old-alist)))
2207 (setq vhdl-project-alist (nreverse new-alist)))
2208 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2209
2210 ;; option `vhdl-project-alist' changed format (3.31.1)
2211 (when (= (length (car vhdl-project-alist)) 4)
2212 (let ((old-alist vhdl-project-alist)
2213 new-alist elem)
2214 (while old-alist
2215 (setq elem (car old-alist))
2216 (setq new-alist
2217 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2218 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2219 new-alist))
2220 (setq old-alist (cdr old-alist)))
2221 (setq vhdl-project-alist (nreverse new-alist)))
2222 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2223
2224 ;; option `vhdl-project-alist' changed format (3.31.12)
2225 (when (= (length (car vhdl-project-alist)) 10)
2226 (let ((tmp-alist vhdl-project-alist))
2227 (while tmp-alist
2228 (setcdr (nthcdr 3 (car tmp-alist))
2229 (cons "" (nthcdr 4 (car tmp-alist))))
2230 (setq tmp-alist (cdr tmp-alist))))
2231 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2232
2233 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2234 (when (= (length (car vhdl-compiler-alist)) 7)
2235 (let ((old-alist vhdl-compiler-alist)
2236 new-alist elem)
2237 (while old-alist
2238 (setq elem (car old-alist))
2239 (setq new-alist
2240 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2241 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2242 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2243 (nth 5 elem) (nth 6 elem) nil)
2244 new-alist))
2245 (setq old-alist (cdr old-alist)))
2246 (setq vhdl-compiler-alist (nreverse new-alist)))
2247 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2248
2249 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2250 (when (= (length (car vhdl-compiler-alist)) 12)
2251 (let ((tmp-alist vhdl-compiler-alist))
2252 (while tmp-alist
2253 (setcdr (nthcdr 4 (car tmp-alist))
2254 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2255 (setq tmp-alist (cdr tmp-alist))))
2256 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2257
2258 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2259 (when (= (length (car vhdl-compiler-alist)) 13)
2260 (let ((tmp-alist vhdl-compiler-alist))
2261 (while tmp-alist
2262 (setcdr (nthcdr 3 (car tmp-alist))
2263 (cons "" (nthcdr 4 (car tmp-alist))))
2264 (setq tmp-alist (cdr tmp-alist))))
2265 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2266
2267 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2268 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2269 (let ((tmp-alist vhdl-compiler-alist))
2270 (while tmp-alist
2271 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2272 '(0 . nil))
2273 (setq tmp-alist (cdr tmp-alist))))
2274 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2275
2276 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2277 (when (equal vhdl-project "")
2278 (setq vhdl-project nil)
2279 (customize-save-variable 'vhdl-project vhdl-project))
2280
2281 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2282 (when (stringp vhdl-project-file-name)
2283 (setq vhdl-project-file-name (list vhdl-project-file-name))
2284 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2285
2286 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2287 (if (not (boundp 'speedbar-indentation-width))
2288 (defvar speedbar-indentation-width 2)
2289 ;; set default to 2 if not already customized
2290 (unless (get 'speedbar-indentation-width 'saved-value)
2291 (setq speedbar-indentation-width 2)))
2292
2293
2294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2295 ;;; Help functions / inline substitutions / macros
2296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2297
2298 (defun vhdl-standard-p (standard)
2299 "Check if STANDARD is specified as used standard."
2300 (or (eq standard (car vhdl-standard))
2301 (memq standard (cadr vhdl-standard))))
2302
2303 (defun vhdl-project-p (&optional warning)
2304 "Return non-nil if a project is displayed, i.e. directories or files are
2305 specified."
2306 (if (assoc vhdl-project vhdl-project-alist)
2307 vhdl-project
2308 (when (and vhdl-project warning)
2309 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2310 nil))
2311
2312 (defun vhdl-resolve-env-variable (string)
2313 "Resolve environment variables in STRING."
2314 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2315 (setq string (concat (match-string 1 string)
2316 (getenv (match-string 2 string))
2317 (match-string 4 string))))
2318 string)
2319
2320 (defun vhdl-default-directory ()
2321 "Return the default directory of the current project or the directory of the
2322 current buffer if no project is defined."
2323 (if (vhdl-project-p)
2324 (expand-file-name (vhdl-resolve-env-variable
2325 (nth 1 (aget vhdl-project-alist vhdl-project))))
2326 default-directory))
2327
2328 (defmacro vhdl-prepare-search-1 (&rest body)
2329 "Enable case insensitive search and switch to syntax table that includes '_',
2330 then execute BODY, and finally restore the old environment. Used for
2331 consistent searching."
2332 `(let ((case-fold-search t) ; case insensitive search
2333 (current-syntax-table (syntax-table))
2334 result
2335 (restore-prog ; program to restore enviroment
2336 '(progn
2337 ;; restore syntax table
2338 (set-syntax-table current-syntax-table))))
2339 ;; use extended syntax table
2340 (set-syntax-table vhdl-mode-ext-syntax-table)
2341 ;; execute BODY safely
2342 (setq result
2343 (condition-case info
2344 (progn ,@body)
2345 (error (eval restore-prog) ; restore environment on error
2346 (error (cadr info))))) ; pass error up
2347 ;; restore environment
2348 (eval restore-prog)
2349 result))
2350
2351 (defmacro vhdl-prepare-search-2 (&rest body)
2352 "Enable case insensitive search, switch to syntax table that includes '_',
2353 and remove `intangible' overlays, then execute BODY, and finally restore the
2354 old environment. Used for consistent searching."
2355 `(let ((case-fold-search t) ; case insensitive search
2356 (current-syntax-table (syntax-table))
2357 result overlay-all-list overlay-intangible-list overlay
2358 (restore-prog ; program to restore enviroment
2359 '(progn
2360 ;; restore syntax table
2361 (set-syntax-table current-syntax-table)
2362 ;; restore `intangible' overlays
2363 (when (fboundp 'overlay-lists)
2364 (while overlay-intangible-list
2365 (overlay-put (car overlay-intangible-list) 'intangible t)
2366 (setq overlay-intangible-list
2367 (cdr overlay-intangible-list)))))))
2368 ;; use extended syntax table
2369 (set-syntax-table vhdl-mode-ext-syntax-table)
2370 ;; remove `intangible' overlays
2371 (when (fboundp 'overlay-lists)
2372 (setq overlay-all-list (overlay-lists))
2373 (setq overlay-all-list
2374 (append (car overlay-all-list) (cdr overlay-all-list)))
2375 (while overlay-all-list
2376 (setq overlay (car overlay-all-list))
2377 (when (memq 'intangible (overlay-properties overlay))
2378 (setq overlay-intangible-list
2379 (cons overlay overlay-intangible-list))
2380 (overlay-put overlay 'intangible nil))
2381 (setq overlay-all-list (cdr overlay-all-list))))
2382 ;; execute BODY safely
2383 (setq result
2384 (condition-case info
2385 (progn ,@body)
2386 (error (eval restore-prog) ; restore environment on error
2387 (error (cadr info))))) ; pass error up
2388 ;; restore environment
2389 (eval restore-prog)
2390 result))
2391
2392 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2393 "Visit file FILE-NAME and execute BODY."
2394 `(if (null ,file-name)
2395 (progn ,@body)
2396 (unless (file-directory-p ,file-name)
2397 (let ((source-buffer (current-buffer))
2398 (visiting-buffer (find-buffer-visiting ,file-name))
2399 file-opened)
2400 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2401 (condition-case ()
2402 (progn (set-buffer (create-file-buffer ,file-name))
2403 (setq file-opened t)
2404 (vhdl-insert-file-contents ,file-name)
2405 (modify-syntax-entry ?\- ". 12" (syntax-table))
2406 (modify-syntax-entry ?\n ">" (syntax-table))
2407 (modify-syntax-entry ?\^M ">" (syntax-table))
2408 (modify-syntax-entry ?_ "w" (syntax-table))
2409 t)
2410 (error
2411 (if ,issue-error
2412 (progn
2413 (when file-opened (kill-buffer (current-buffer)))
2414 (set-buffer source-buffer)
2415 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2416 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2417 nil))))
2418 (condition-case info
2419 (progn ,@body)
2420 (error
2421 (if ,issue-error
2422 (progn
2423 (when file-opened (kill-buffer (current-buffer)))
2424 (set-buffer source-buffer)
2425 (error (cadr info)))
2426 (vhdl-warning (cadr info))))))
2427 (when file-opened (kill-buffer (current-buffer)))
2428 (set-buffer source-buffer)))))
2429
2430 (defun vhdl-insert-file-contents (filename)
2431 "Nicked from `insert-file-contents-literally', but allow coding system
2432 conversion."
2433 (let ((format-alist nil)
2434 (after-insert-file-functions nil)
2435 (jka-compr-compression-info-list nil))
2436 (insert-file-contents filename t)))
2437
2438 (defun vhdl-sort-alist (alist)
2439 "Sort ALIST."
2440 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2441
2442 (defun vhdl-get-subdirs (directory)
2443 "Recursively get subdirectories of DIRECTORY."
2444 (let ((dir-list (list (file-name-as-directory directory)))
2445 file-list)
2446 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2447 (while file-list
2448 (when (file-directory-p (car file-list))
2449 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2450 (setq file-list (cdr file-list)))
2451 dir-list))
2452
2453 (defun vhdl-aput (alist-symbol key &optional value)
2454 "As `aput', but delete key-value pair if VALUE is nil."
2455 (if value
2456 (aput alist-symbol key value)
2457 (adelete alist-symbol key)))
2458
2459 (defun vhdl-delete (elt list)
2460 "Delete by side effect the first occurrence of ELT as a member of LIST."
2461 (setq list (cons nil list))
2462 (let ((list1 list))
2463 (while (and (cdr list1) (not (equal elt (cadr list1))))
2464 (setq list1 (cdr list1)))
2465 (when list
2466 (setcdr list1 (cddr list1))))
2467 (cdr list))
2468
2469 (defun vhdl-speedbar-refresh (&optional key)
2470 "Refresh directory or project with name KEY."
2471 (when (and (boundp 'speedbar-frame)
2472 (frame-live-p speedbar-frame))
2473 (let ((pos (point))
2474 (last-frame (selected-frame)))
2475 (if (null key)
2476 (speedbar-refresh)
2477 (select-frame speedbar-frame)
2478 (when (save-excursion
2479 (goto-char (point-min))
2480 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2481 (goto-char (match-end 1))
2482 (speedbar-do-function-pointer)
2483 (backward-char 2)
2484 (speedbar-do-function-pointer)
2485 (message "Refreshing speedbar...done"))
2486 (select-frame last-frame)))))
2487
2488 (defun vhdl-show-messages ()
2489 "Get *Messages* buffer to show recent messages."
2490 (interactive)
2491 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2492
2493 (defun vhdl-use-direct-instantiation ()
2494 "Return whether direct instantiation is used."
2495 (or (eq vhdl-use-direct-instantiation 'always)
2496 (and (eq vhdl-use-direct-instantiation 'standard)
2497 (not (vhdl-standard-p '87)))))
2498
2499 (defun vhdl-max-marker (marker1 marker2)
2500 "Return larger marker."
2501 (if (> marker1 marker2) marker1 marker2))
2502
2503 (defun vhdl-goto-marker (marker)
2504 "Goto marker in appropriate buffer."
2505 (when (markerp marker)
2506 (set-buffer (marker-buffer marker)))
2507 (goto-char marker))
2508
2509 (defun vhdl-menu-split (list title)
2510 "Split menu LIST into several submenues, if number of
2511 elements > `vhdl-menu-max-size'."
2512 (if (> (length list) vhdl-menu-max-size)
2513 (let ((remain list)
2514 (result '())
2515 (sublist '())
2516 (menuno 1)
2517 (i 0))
2518 (while remain
2519 (setq sublist (cons (car remain) sublist))
2520 (setq remain (cdr remain))
2521 (setq i (+ i 1))
2522 (if (= i vhdl-menu-max-size)
2523 (progn
2524 (setq result (cons (cons (format "%s %s" title menuno)
2525 (nreverse sublist)) result))
2526 (setq i 0)
2527 (setq menuno (+ menuno 1))
2528 (setq sublist '()))))
2529 (and sublist
2530 (setq result (cons (cons (format "%s %s" title menuno)
2531 (nreverse sublist)) result)))
2532 (nreverse result))
2533 list))
2534
2535
2536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2537 ;;; Bindings
2538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539
2540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2541 ;; Key bindings
2542
2543 (defvar vhdl-template-map nil
2544 "Keymap for VHDL templates.")
2545
2546 (defun vhdl-template-map-init ()
2547 "Initialize `vhdl-template-map'."
2548 (setq vhdl-template-map (make-sparse-keymap))
2549 ;; key bindings for VHDL templates
2550 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2551 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2552 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2553 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2554 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2555 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2556 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2557 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2558 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2559 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2560 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2561 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2562 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2563 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2564 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2565 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2566 (define-key vhdl-template-map "el" 'vhdl-template-else)
2567 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2568 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2569 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2570 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2571 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2572 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2573 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2574 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2575 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2576 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2577 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2578 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2579 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2580 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2581 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2582 (define-key vhdl-template-map "li" 'vhdl-template-library)
2583 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2584 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2585 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2586 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2587 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2588 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2589 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2590 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2591 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2592 (define-key vhdl-template-map "po" 'vhdl-template-port)
2593 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2594 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2595 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2596 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2597 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2598 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2599 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2600 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2601 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2602 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2603 (define-key vhdl-template-map "us" 'vhdl-template-use)
2604 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2605 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2606 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2607 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2608 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2609 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2610 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2611 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2612 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2613 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2614 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2615 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2616 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2617 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2618 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2619 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2620 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2621 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2622 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2623 (when (vhdl-standard-p 'ams)
2624 (define-key vhdl-template-map "br" 'vhdl-template-break)
2625 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2626 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2627 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2628 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2629 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2630 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2631 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2632 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2633 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2634 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2635 )
2636 (when (vhdl-standard-p 'math)
2637 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2638 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2639 ))
2640
2641 ;; initialize template map for VHDL Mode
2642 (vhdl-template-map-init)
2643
2644 (defun vhdl-function-name (prefix string &optional postfix)
2645 "Generate a Lisp function name.
2646 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2647 STRING are replaced by `-' and substrings are converted to lower case."
2648 (let ((name prefix))
2649 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2650 (setq name
2651 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2652 (setq string (substring string (match-beginning 2))))
2653 (when postfix (setq name (concat name "-" postfix)))
2654 (intern name)))
2655
2656 (defvar vhdl-model-map nil
2657 "Keymap for VHDL models.")
2658
2659 (defun vhdl-model-map-init ()
2660 "Initialize `vhdl-model-map'."
2661 (setq vhdl-model-map (make-sparse-keymap))
2662 ;; key bindings for VHDL models
2663 (let ((model-alist vhdl-model-alist) model)
2664 (while model-alist
2665 (setq model (car model-alist))
2666 (define-key vhdl-model-map (nth 2 model)
2667 (vhdl-function-name "vhdl-model" (nth 0 model)))
2668 (setq model-alist (cdr model-alist)))))
2669
2670 ;; initialize user model map for VHDL Mode
2671 (vhdl-model-map-init)
2672
2673 (defvar vhdl-mode-map nil
2674 "Keymap for VHDL Mode.")
2675
2676 (defun vhdl-mode-map-init ()
2677 "Initialize `vhdl-mode-map'."
2678 (setq vhdl-mode-map (make-sparse-keymap))
2679 ;; template key bindings
2680 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2681 ;; model key bindings
2682 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2683 ;; standard key bindings
2684 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2685 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2686 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2687 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2688 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2689 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2690 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2691 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2692 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2693 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2694 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2695 ;; backspace/delete key bindings
2696 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2697 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2698 (define-key vhdl-mode-map [delete] 'delete-char)
2699 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2700 ;; mode specific key bindings
2701 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2702 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2703 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2704 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2705 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2706 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2707 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2708 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2709 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2710 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2711 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2712 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2713 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2714 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2715 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2716 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2717 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2718 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2719 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2720 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2721 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2722 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2723 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2724 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2725 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2726 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2727 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2728 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2729 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2730 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2731 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2732 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2733 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2734 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2735 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2736 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2737 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2738 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2740 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2741 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2742 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2743 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2746 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2747 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2748 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2749 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2750 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2751 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2752 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2753 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2754 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2755 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2756 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2757 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2758 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2759 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2760 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2761 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2762 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2763 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2764 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2765 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2766 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2767 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2768 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2769 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2770 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2771 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2772 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2773 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2774 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2775 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2776 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2777 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2778 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2779 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2780 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2781 ;; insert commands bindings
2782 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2783 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2784 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2785 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2786 ;; electric key bindings
2787 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2788 (when vhdl-intelligent-tab
2789 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2790 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2791 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2792 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2793 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2794 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2795 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2796 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2797 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2798 (when (vhdl-standard-p 'ams)
2799 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2800
2801 ;; initialize mode map for VHDL Mode
2802 (vhdl-mode-map-init)
2803
2804 ;; define special minibuffer keymap for enabling word completion in minibuffer
2805 ;; (useful in template generator prompts)
2806 (defvar vhdl-minibuffer-local-map
2807 (let ((map (make-sparse-keymap)))
2808 (set-keymap-parent map minibuffer-local-map)
2809 (when vhdl-word-completion-in-minibuffer
2810 (define-key map "\t" 'vhdl-minibuffer-tab))
2811 map)
2812 "Keymap for minibuffer used in VHDL Mode.")
2813
2814 ;; set up electric character functions to work with
2815 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2816 (mapc
2817 (function
2818 (lambda (sym)
2819 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2820 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2821 '(vhdl-electric-space
2822 vhdl-electric-tab
2823 vhdl-electric-return
2824 vhdl-electric-dash
2825 vhdl-electric-open-bracket
2826 vhdl-electric-close-bracket
2827 vhdl-electric-quote
2828 vhdl-electric-semicolon
2829 vhdl-electric-comma
2830 vhdl-electric-period
2831 vhdl-electric-equal))
2832
2833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2834 ;; Syntax table
2835
2836 (defvar vhdl-mode-syntax-table nil
2837 "Syntax table used in `vhdl-mode' buffers.")
2838
2839 (defvar vhdl-mode-ext-syntax-table nil
2840 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2841
2842 (defun vhdl-mode-syntax-table-init ()
2843 "Initialize `vhdl-mode-syntax-table'."
2844 (setq vhdl-mode-syntax-table (make-syntax-table))
2845 ;; define punctuation
2846 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2857 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2859 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2860 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2861 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2862 ;; define string
2863 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2864 ;; define underscore
2865 (when vhdl-underscore-is-part-of-word
2866 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2867 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2868 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2869 ;; and \n and \^M end a comment
2870 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2871 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2872 ;; define parentheses to match
2873 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2874 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2877 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2878 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2879 ;; extended syntax table including '_' (for simpler search regexps)
2880 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2881 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2882
2883 ;; initialize syntax table for VHDL Mode
2884 (vhdl-mode-syntax-table-init)
2885
2886 (defvar vhdl-syntactic-context nil
2887 "Buffer local variable containing syntactic analysis list.")
2888 (make-variable-buffer-local 'vhdl-syntactic-context)
2889
2890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2891 ;; Abbrev ook bindings
2892
2893 (defvar vhdl-mode-abbrev-table nil
2894 "Abbrev table to use in `vhdl-mode' buffers.")
2895
2896 (defun vhdl-mode-abbrev-table-init ()
2897 "Initialize `vhdl-mode-abbrev-table'."
2898 (define-abbrev-table 'vhdl-mode-abbrev-table
2899 (append
2900 (when (memq 'vhdl vhdl-electric-keywords)
2901 ;; VHDL'93 keywords
2902 '(
2903 ("--" "" vhdl-template-display-comment-hook 0)
2904 ("abs" "" vhdl-template-default-hook 0)
2905 ("access" "" vhdl-template-default-hook 0)
2906 ("after" "" vhdl-template-default-hook 0)
2907 ("alias" "" vhdl-template-alias-hook 0)
2908 ("all" "" vhdl-template-default-hook 0)
2909 ("and" "" vhdl-template-default-hook 0)
2910 ("arch" "" vhdl-template-architecture-hook 0)
2911 ("architecture" "" vhdl-template-architecture-hook 0)
2912 ("array" "" vhdl-template-default-hook 0)
2913 ("assert" "" vhdl-template-assert-hook 0)
2914 ("attr" "" vhdl-template-attribute-hook 0)
2915 ("attribute" "" vhdl-template-attribute-hook 0)
2916 ("begin" "" vhdl-template-default-indent-hook 0)
2917 ("block" "" vhdl-template-block-hook 0)
2918 ("body" "" vhdl-template-default-hook 0)
2919 ("buffer" "" vhdl-template-default-hook 0)
2920 ("bus" "" vhdl-template-default-hook 0)
2921 ("case" "" vhdl-template-case-hook 0)
2922 ("comp" "" vhdl-template-component-hook 0)
2923 ("component" "" vhdl-template-component-hook 0)
2924 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2925 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2926 ("conf" "" vhdl-template-configuration-hook 0)
2927 ("configuration" "" vhdl-template-configuration-hook 0)
2928 ("cons" "" vhdl-template-constant-hook 0)
2929 ("constant" "" vhdl-template-constant-hook 0)
2930 ("disconnect" "" vhdl-template-disconnect-hook 0)
2931 ("downto" "" vhdl-template-default-hook 0)
2932 ("else" "" vhdl-template-else-hook 0)
2933 ("elseif" "" vhdl-template-elsif-hook 0)
2934 ("elsif" "" vhdl-template-elsif-hook 0)
2935 ("end" "" vhdl-template-default-indent-hook 0)
2936 ("entity" "" vhdl-template-entity-hook 0)
2937 ("exit" "" vhdl-template-exit-hook 0)
2938 ("file" "" vhdl-template-file-hook 0)
2939 ("for" "" vhdl-template-for-hook 0)
2940 ("func" "" vhdl-template-function-hook 0)
2941 ("function" "" vhdl-template-function-hook 0)
2942 ("generic" "" vhdl-template-generic-hook 0)
2943 ("group" "" vhdl-template-group-hook 0)
2944 ("guarded" "" vhdl-template-default-hook 0)
2945 ("if" "" vhdl-template-if-hook 0)
2946 ("impure" "" vhdl-template-default-hook 0)
2947 ("in" "" vhdl-template-default-hook 0)
2948 ("inertial" "" vhdl-template-default-hook 0)
2949 ("inout" "" vhdl-template-default-hook 0)
2950 ("inst" "" vhdl-template-instance-hook 0)
2951 ("instance" "" vhdl-template-instance-hook 0)
2952 ("is" "" vhdl-template-default-hook 0)
2953 ("label" "" vhdl-template-default-hook 0)
2954 ("library" "" vhdl-template-library-hook 0)
2955 ("linkage" "" vhdl-template-default-hook 0)
2956 ("literal" "" vhdl-template-default-hook 0)
2957 ("loop" "" vhdl-template-bare-loop-hook 0)
2958 ("map" "" vhdl-template-map-hook 0)
2959 ("mod" "" vhdl-template-default-hook 0)
2960 ("nand" "" vhdl-template-default-hook 0)
2961 ("new" "" vhdl-template-default-hook 0)
2962 ("next" "" vhdl-template-next-hook 0)
2963 ("nor" "" vhdl-template-default-hook 0)
2964 ("not" "" vhdl-template-default-hook 0)
2965 ("null" "" vhdl-template-default-hook 0)
2966 ("of" "" vhdl-template-default-hook 0)
2967 ("on" "" vhdl-template-default-hook 0)
2968 ("open" "" vhdl-template-default-hook 0)
2969 ("or" "" vhdl-template-default-hook 0)
2970 ("others" "" vhdl-template-others-hook 0)
2971 ("out" "" vhdl-template-default-hook 0)
2972 ("pack" "" vhdl-template-package-hook 0)
2973 ("package" "" vhdl-template-package-hook 0)
2974 ("port" "" vhdl-template-port-hook 0)
2975 ("postponed" "" vhdl-template-default-hook 0)
2976 ("procedure" "" vhdl-template-procedure-hook 0)
2977 ("process" "" vhdl-template-process-hook 0)
2978 ("pure" "" vhdl-template-default-hook 0)
2979 ("range" "" vhdl-template-default-hook 0)
2980 ("record" "" vhdl-template-default-hook 0)
2981 ("register" "" vhdl-template-default-hook 0)
2982 ("reject" "" vhdl-template-default-hook 0)
2983 ("rem" "" vhdl-template-default-hook 0)
2984 ("report" "" vhdl-template-report-hook 0)
2985 ("return" "" vhdl-template-return-hook 0)
2986 ("rol" "" vhdl-template-default-hook 0)
2987 ("ror" "" vhdl-template-default-hook 0)
2988 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2989 ("severity" "" vhdl-template-default-hook 0)
2990 ("shared" "" vhdl-template-default-hook 0)
2991 ("sig" "" vhdl-template-signal-hook 0)
2992 ("signal" "" vhdl-template-signal-hook 0)
2993 ("sla" "" vhdl-template-default-hook 0)
2994 ("sll" "" vhdl-template-default-hook 0)
2995 ("sra" "" vhdl-template-default-hook 0)
2996 ("srl" "" vhdl-template-default-hook 0)
2997 ("subtype" "" vhdl-template-subtype-hook 0)
2998 ("then" "" vhdl-template-default-hook 0)
2999 ("to" "" vhdl-template-default-hook 0)
3000 ("transport" "" vhdl-template-default-hook 0)
3001 ("type" "" vhdl-template-type-hook 0)
3002 ("unaffected" "" vhdl-template-default-hook 0)
3003 ("units" "" vhdl-template-default-hook 0)
3004 ("until" "" vhdl-template-default-hook 0)
3005 ("use" "" vhdl-template-use-hook 0)
3006 ("var" "" vhdl-template-variable-hook 0)
3007 ("variable" "" vhdl-template-variable-hook 0)
3008 ("wait" "" vhdl-template-wait-hook 0)
3009 ("when" "" vhdl-template-when-hook 0)
3010 ("while" "" vhdl-template-while-loop-hook 0)
3011 ("with" "" vhdl-template-with-hook 0)
3012 ("xnor" "" vhdl-template-default-hook 0)
3013 ("xor" "" vhdl-template-default-hook 0)
3014 ))
3015 ;; VHDL-AMS keywords
3016 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3017 '(
3018 ("across" "" vhdl-template-default-hook 0)
3019 ("break" "" vhdl-template-break-hook 0)
3020 ("limit" "" vhdl-template-limit-hook 0)
3021 ("nature" "" vhdl-template-nature-hook 0)
3022 ("noise" "" vhdl-template-default-hook 0)
3023 ("procedural" "" vhdl-template-procedural-hook 0)
3024 ("quantity" "" vhdl-template-quantity-hook 0)
3025 ("reference" "" vhdl-template-default-hook 0)
3026 ("spectrum" "" vhdl-template-default-hook 0)
3027 ("subnature" "" vhdl-template-subnature-hook 0)
3028 ("terminal" "" vhdl-template-terminal-hook 0)
3029 ("through" "" vhdl-template-default-hook 0)
3030 ("tolerance" "" vhdl-template-default-hook 0)
3031 ))
3032 ;; user model keywords
3033 (when (memq 'user vhdl-electric-keywords)
3034 (let ((alist vhdl-model-alist)
3035 abbrev-list keyword)
3036 (while alist
3037 (setq keyword (nth 3 (car alist)))
3038 (unless (equal keyword "")
3039 (setq abbrev-list
3040 (cons (list keyword ""
3041 (vhdl-function-name
3042 "vhdl-model" (nth 0 (car alist)) "hook") 0)
3043 abbrev-list)))
3044 (setq alist (cdr alist)))
3045 abbrev-list)))))
3046
3047 ;; initialize abbrev table for VHDL Mode
3048 (vhdl-mode-abbrev-table-init)
3049
3050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3051 ;; Template completion lists
3052
3053 (defvar vhdl-template-construct-alist nil
3054 "List of built-in construct templates.")
3055
3056 (defun vhdl-template-construct-alist-init ()
3057 "Initialize `vhdl-template-construct-alist'."
3058 (setq
3059 vhdl-template-construct-alist
3060 (append
3061 '(
3062 ("alias declaration" vhdl-template-alias)
3063 ("architecture body" vhdl-template-architecture)
3064 ("assertion" vhdl-template-assert)
3065 ("attribute declaration" vhdl-template-attribute-decl)
3066 ("attribute specification" vhdl-template-attribute-spec)
3067 ("block configuration" vhdl-template-block-configuration)
3068 ("block statement" vhdl-template-block)
3069 ("case statement" vhdl-template-case-is)
3070 ("component configuration" vhdl-template-component-conf)
3071 ("component declaration" vhdl-template-component-decl)
3072 ("component instantiation statement" vhdl-template-component-inst)
3073 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3074 ("configuration declaration" vhdl-template-configuration-decl)
3075 ("configuration specification" vhdl-template-configuration-spec)
3076 ("constant declaration" vhdl-template-constant)
3077 ("disconnection specification" vhdl-template-disconnect)
3078 ("entity declaration" vhdl-template-entity)
3079 ("exit statement" vhdl-template-exit)
3080 ("file declaration" vhdl-template-file)
3081 ("generate statement" vhdl-template-generate)
3082 ("generic clause" vhdl-template-generic)
3083 ("group declaration" vhdl-template-group-decl)
3084 ("group template declaration" vhdl-template-group-template)
3085 ("if statement" vhdl-template-if-then)
3086 ("library clause" vhdl-template-library)
3087 ("loop statement" vhdl-template-loop)
3088 ("next statement" vhdl-template-next)
3089 ("package declaration" vhdl-template-package-decl)
3090 ("package body" vhdl-template-package-body)
3091 ("port clause" vhdl-template-port)
3092 ("process statement" vhdl-template-process)
3093 ("report statement" vhdl-template-report)
3094 ("return statement" vhdl-template-return)
3095 ("selected signal assignment" vhdl-template-selected-signal-asst)
3096 ("signal declaration" vhdl-template-signal)
3097 ("subprogram declaration" vhdl-template-subprogram-decl)
3098 ("subprogram body" vhdl-template-subprogram-body)
3099 ("subtype declaration" vhdl-template-subtype)
3100 ("type declaration" vhdl-template-type)
3101 ("use clause" vhdl-template-use)
3102 ("variable declaration" vhdl-template-variable)
3103 ("wait statement" vhdl-template-wait)
3104 )
3105 (when (vhdl-standard-p 'ams)
3106 '(
3107 ("break statement" vhdl-template-break)
3108 ("nature declaration" vhdl-template-nature)
3109 ("quantity declaration" vhdl-template-quantity)
3110 ("simultaneous case statement" vhdl-template-case-use)
3111 ("simultaneous if statement" vhdl-template-if-use)
3112 ("simultaneous procedural statement" vhdl-template-procedural)
3113 ("step limit specification" vhdl-template-limit)
3114 ("subnature declaration" vhdl-template-subnature)
3115 ("terminal declaration" vhdl-template-terminal)
3116 )))))
3117
3118 ;; initialize for VHDL Mode
3119 (vhdl-template-construct-alist-init)
3120
3121 (defvar vhdl-template-package-alist nil
3122 "List of built-in package templates.")
3123
3124 (defun vhdl-template-package-alist-init ()
3125 "Initialize `vhdl-template-package-alist'."
3126 (setq
3127 vhdl-template-package-alist
3128 (append
3129 '(
3130 ("numeric_bit" vhdl-template-package-numeric-bit)
3131 ("numeric_std" vhdl-template-package-numeric-std)
3132 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3133 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3134 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3135 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3136 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3137 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3138 ("textio" vhdl-template-package-textio)
3139 )
3140 (when (vhdl-standard-p 'math)
3141 '(
3142 ("math_complex" vhdl-template-package-math-complex)
3143 ("math_real" vhdl-template-package-math-real)
3144 )))))
3145
3146 ;; initialize for VHDL Mode
3147 (vhdl-template-package-alist-init)
3148
3149 (defvar vhdl-template-directive-alist
3150 '(
3151 ("translate_on" vhdl-template-directive-translate-on)
3152 ("translate_off" vhdl-template-directive-translate-off)
3153 ("synthesis_on" vhdl-template-directive-synthesis-on)
3154 ("synthesis_off" vhdl-template-directive-synthesis-off)
3155 )
3156 "List of built-in directive templates.")
3157
3158
3159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3160 ;;; Menues
3161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3162
3163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3164 ;; VHDL menu (using `easy-menu.el')
3165
3166 (defun vhdl-customize ()
3167 "Call the customize function with `vhdl' as argument."
3168 (interactive)
3169 (customize-browse 'vhdl))
3170
3171 (defun vhdl-create-mode-menu ()
3172 "Create VHDL Mode menu."
3173 `("VHDL"
3174 ,(append
3175 '("Project"
3176 ["None" (vhdl-set-project "")
3177 :style radio :selected (null vhdl-project)]
3178 "--")
3179 ;; add menu entries for defined projects
3180 (let ((project-alist vhdl-project-alist) menu-list name)
3181 (while project-alist
3182 (setq name (caar project-alist))
3183 (setq menu-list
3184 (cons `[,name (vhdl-set-project ,name)
3185 :style radio :selected (equal ,name vhdl-project)]
3186 menu-list))
3187 (setq project-alist (cdr project-alist)))
3188 (setq menu-list
3189 (if vhdl-project-sort
3190 (sort menu-list
3191 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3192 (nreverse menu-list)))
3193 (vhdl-menu-split menu-list "Project"))
3194 '("--" "--"
3195 ["Select Project..." vhdl-set-project t]
3196 ["Set As Default Project" vhdl-set-default-project t]
3197 "--"
3198 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3199 ["Import Project..." vhdl-import-project
3200 :keys "C-c C-p C-m" :active t]
3201 ["Export Project" vhdl-export-project vhdl-project]
3202 "--"
3203 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3204 "--"
3205 ("Compile"
3206 ["Compile Buffer" vhdl-compile t]
3207 ["Stop Compilation" kill-compilation t]
3208 "--"
3209 ["Make" vhdl-make t]
3210 ["Generate Makefile" vhdl-generate-makefile t]
3211 "--"
3212 ["Next Error" next-error t]
3213 ["Previous Error" previous-error t]
3214 ["First Error" first-error t]
3215 "--"
3216 ,(append
3217 '("Compiler")
3218 ;; add menu entries for defined compilers
3219 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3220 (while comp-alist
3221 (setq name (caar comp-alist))
3222 (setq menu-list
3223 (cons `[,name (setq vhdl-compiler ,name)
3224 :style radio :selected (equal ,name vhdl-compiler)]
3225 menu-list))
3226 (setq comp-alist (cdr comp-alist)))
3227 (setq menu-list (nreverse menu-list))
3228 (vhdl-menu-split menu-list "Compiler"))
3229 '("--" "--"
3230 ["Select Compiler..." vhdl-set-compiler t]
3231 "--"
3232 ["Customize Compiler..."
3233 (customize-option 'vhdl-compiler-alist) t])))
3234 "--"
3235 ,(append
3236 '("Template"
3237 ("VHDL Construct 1"
3238 ["Alias" vhdl-template-alias t]
3239 ["Architecture" vhdl-template-architecture t]
3240 ["Assert" vhdl-template-assert t]
3241 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3242 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3243 ["Block" vhdl-template-block t]
3244 ["Case" vhdl-template-case-is t]
3245 ["Component (Decl)" vhdl-template-component-decl t]
3246 ["(Component) Instance" vhdl-template-component-inst t]
3247 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3248 ["Configuration (Block)" vhdl-template-block-configuration t]
3249 ["Configuration (Comp)" vhdl-template-component-conf t]
3250 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3251 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3252 ["Constant" vhdl-template-constant t]
3253 ["Disconnect" vhdl-template-disconnect t]
3254 ["Else" vhdl-template-else t]
3255 ["Elsif" vhdl-template-elsif t]
3256 ["Entity" vhdl-template-entity t]
3257 ["Exit" vhdl-template-exit t]
3258 ["File" vhdl-template-file t]
3259 ["For (Generate)" vhdl-template-for-generate t]
3260 ["For (Loop)" vhdl-template-for-loop t]
3261 ["Function (Body)" vhdl-template-function-body t]
3262 ["Function (Decl)" vhdl-template-function-decl t]
3263 ["Generic" vhdl-template-generic t]
3264 ["Group (Decl)" vhdl-template-group-decl t]
3265 ["Group (Template)" vhdl-template-group-template t])
3266 ("VHDL Construct 2"
3267 ["If (Generate)" vhdl-template-if-generate t]
3268 ["If (Then)" vhdl-template-if-then t]
3269 ["Library" vhdl-template-library t]
3270 ["Loop" vhdl-template-bare-loop t]
3271 ["Map" vhdl-template-map t]
3272 ["Next" vhdl-template-next t]
3273 ["Others (Aggregate)" vhdl-template-others t]
3274 ["Package (Decl)" vhdl-template-package-decl t]
3275 ["Package (Body)" vhdl-template-package-body t]
3276 ["Port" vhdl-template-port t]
3277 ["Procedure (Body)" vhdl-template-procedure-body t]
3278 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3279 ["Process (Comb)" vhdl-template-process-comb t]
3280 ["Process (Seq)" vhdl-template-process-seq t]
3281 ["Report" vhdl-template-report t]
3282 ["Return" vhdl-template-return t]
3283 ["Select" vhdl-template-selected-signal-asst t]
3284 ["Signal" vhdl-template-signal t]
3285 ["Subtype" vhdl-template-subtype t]
3286 ["Type" vhdl-template-type t]
3287 ["Use" vhdl-template-use t]
3288 ["Variable" vhdl-template-variable t]
3289 ["Wait" vhdl-template-wait t]
3290 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3291 ["When" vhdl-template-when t]
3292 ["While (Loop)" vhdl-template-while-loop t]
3293 ["With" vhdl-template-with t]))
3294 (when (vhdl-standard-p 'ams)
3295 '(("VHDL-AMS Construct"
3296 ["Break" vhdl-template-break t]
3297 ["Case (Use)" vhdl-template-case-use t]
3298 ["If (Use)" vhdl-template-if-use t]
3299 ["Limit" vhdl-template-limit t]
3300 ["Nature" vhdl-template-nature t]
3301 ["Procedural" vhdl-template-procedural t]
3302 ["Quantity (Free)" vhdl-template-quantity-free t]
3303 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3304 ["Quantity (Source)" vhdl-template-quantity-source t]
3305 ["Subnature" vhdl-template-subnature t]
3306 ["Terminal" vhdl-template-terminal t])))
3307 '(["Insert Construct..." vhdl-template-insert-construct
3308 :keys "C-c C-i C-t"]
3309 "--")
3310 (list
3311 (append
3312 '("Package")
3313 (when (vhdl-standard-p 'math)
3314 '(["math_complex" vhdl-template-package-math-complex t]
3315 ["math_real" vhdl-template-package-math-real t]))
3316 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3317 ["numeric_std" vhdl-template-package-numeric-std t]
3318 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3319 ["textio" vhdl-template-package-textio t]
3320 "--"
3321 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3322 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3323 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3324 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3325 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3326 "--"
3327 ["Insert Package..." vhdl-template-insert-package
3328 :keys "C-c C-i C-p"])))
3329 '(("Directive"
3330 ["translate_on" vhdl-template-directive-translate-on t]
3331 ["translate_off" vhdl-template-directive-translate-off t]
3332 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3333 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3334 "--"
3335 ["Insert Directive..." vhdl-template-insert-directive
3336 :keys "C-c C-i C-d"])
3337 "--"
3338 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3339 ["Insert Footer" vhdl-template-footer t]
3340 ["Insert Date" vhdl-template-insert-date t]
3341 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3342 "--"
3343 ["Query Next Prompt" vhdl-template-search-prompt t]))
3344 ,(append
3345 '("Model")
3346 ;; add menu entries for defined models
3347 (let ((model-alist vhdl-model-alist) menu-list model)
3348 (while model-alist
3349 (setq model (car model-alist))
3350 (setq menu-list
3351 (cons
3352 (vector
3353 (nth 0 model)
3354 (vhdl-function-name "vhdl-model" (nth 0 model))
3355 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3356 menu-list))
3357 (setq model-alist (cdr model-alist)))
3358 (setq menu-list (nreverse menu-list))
3359 (vhdl-menu-split menu-list "Model"))
3360 '("--" "--"
3361 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3362 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3363 ("Port"
3364 ["Copy" vhdl-port-copy t]
3365 "--"
3366 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3367 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3368 ["Paste As Instance" vhdl-port-paste-instance
3369 :keys "C-c C-p C-i" :active vhdl-port-list]
3370 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3371 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3372 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3373 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3374 "--"
3375 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3376 "--"
3377 ["Flatten" vhdl-port-flatten
3378 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3379 ["Reverse Direction" vhdl-port-reverse-direction
3380 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3381 ("Compose"
3382 ["New Component" vhdl-compose-new-component t]
3383 ["Copy Component" vhdl-port-copy t]
3384 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3385 ["Wire Components" vhdl-compose-wire-components t]
3386 "--"
3387 ["Generate Configuration" vhdl-compose-configuration t]
3388 ["Generate Components Package" vhdl-compose-components-package t])
3389 ("Subprogram"
3390 ["Copy" vhdl-subprog-copy t]
3391 "--"
3392 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3393 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3394 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3395 "--"
3396 ["Flatten" vhdl-subprog-flatten
3397 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3398 "--"
3399 ("Comment"
3400 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3401 "--"
3402 ["Insert Inline Comment" vhdl-comment-append-inline t]
3403 ["Insert Horizontal Line" vhdl-comment-display-line t]
3404 ["Insert Display Comment" vhdl-comment-display t]
3405 "--"
3406 ["Fill Comment" fill-paragraph t]
3407 ["Fill Comment Region" fill-region (mark)]
3408 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3409 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3410 ("Line"
3411 ["Kill" vhdl-line-kill t]
3412 ["Copy" vhdl-line-copy t]
3413 ["Yank" vhdl-line-yank t]
3414 ["Expand" vhdl-line-expand t]
3415 "--"
3416 ["Transpose Next" vhdl-line-transpose-next t]
3417 ["Transpose Prev" vhdl-line-transpose-previous t]
3418 ["Open" vhdl-line-open t]
3419 ["Join" vhdl-delete-indentation t]
3420 "--"
3421 ["Goto" goto-line t]
3422 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3423 ("Move"
3424 ["Forward Statement" vhdl-end-of-statement t]
3425 ["Backward Statement" vhdl-beginning-of-statement t]
3426 ["Forward Expression" vhdl-forward-sexp t]
3427 ["Backward Expression" vhdl-backward-sexp t]
3428 ["Forward Same Indent" vhdl-forward-same-indent t]
3429 ["Backward Same Indent" vhdl-backward-same-indent t]
3430 ["Forward Function" vhdl-end-of-defun t]
3431 ["Backward Function" vhdl-beginning-of-defun t]
3432 ["Mark Function" vhdl-mark-defun t])
3433 "--"
3434 ("Indent"
3435 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3436 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3437 ["Region" vhdl-indent-region (mark)]
3438 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3439 ("Align"
3440 ["Group" vhdl-align-group t]
3441 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3442 ["List" vhdl-align-list t]
3443 ["Declarations" vhdl-align-declarations t]
3444 ["Region" vhdl-align-region (mark)]
3445 ["Buffer" vhdl-align-buffer t]
3446 "--"
3447 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3448 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3449 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3450 ("Fill"
3451 ["List" vhdl-fill-list t]
3452 ["Group" vhdl-fill-group t]
3453 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3454 ["Region" vhdl-fill-region (mark)])
3455 ("Beautify"
3456 ["Region" vhdl-beautify-region (mark)]
3457 ["Buffer" vhdl-beautify-buffer t])
3458 ("Fix"
3459 ["Generic/Port Clause" vhdl-fix-clause t]
3460 "--"
3461 ["Case Region" vhdl-fix-case-region (mark)]
3462 ["Case Buffer" vhdl-fix-case-buffer t]
3463 "--"
3464 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3465 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3466 "--"
3467 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3468 ("Update"
3469 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3470 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3471 "--"
3472 ["Fontify Buffer" vhdl-fontify-buffer t]
3473 ["Statistics Buffer" vhdl-statistics-buffer t]
3474 ["Show Messages" vhdl-show-messages t]
3475 ["Syntactic Info" vhdl-show-syntactic-information t]
3476 "--"
3477 ["Speedbar" vhdl-speedbar t]
3478 ["Hide/Show" vhdl-hs-minor-mode t]
3479 "--"
3480 ("Documentation"
3481 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3482 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3483 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3484 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3485 ["Version" vhdl-version t]
3486 ["Bug Report..." vhdl-submit-bug-report t]
3487 "--"
3488 ("Options"
3489 ("Mode"
3490 ["Electric Mode"
3491 (progn (customize-set-variable 'vhdl-electric-mode
3492 (not vhdl-electric-mode))
3493 (vhdl-mode-line-update))
3494 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3495 ["Stutter Mode"
3496 (progn (customize-set-variable 'vhdl-stutter-mode
3497 (not vhdl-stutter-mode))
3498 (vhdl-mode-line-update))
3499 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3500 ["Indent Tabs Mode"
3501 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3502 (not vhdl-indent-tabs-mode))
3503 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3504 :style toggle :selected vhdl-indent-tabs-mode]
3505 "--"
3506 ["Customize Group..." (customize-group 'vhdl-mode) t])
3507 ("Project"
3508 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3509 ,(append
3510 '("Selected Project at Startup"
3511 ["None" (progn (customize-set-variable 'vhdl-project nil)
3512 (vhdl-set-project ""))
3513 :style radio :selected (null vhdl-project)]
3514 "--")
3515 ;; add menu entries for defined projects
3516 (let ((project-alist vhdl-project-alist) menu-list name)
3517 (while project-alist
3518 (setq name (caar project-alist))
3519 (setq menu-list
3520 (cons `[,name (progn (customize-set-variable
3521 'vhdl-project ,name)
3522 (vhdl-set-project ,name))
3523 :style radio :selected (equal ,name vhdl-project)]
3524 menu-list))
3525 (setq project-alist (cdr project-alist)))
3526 (setq menu-list (nreverse menu-list))
3527 (vhdl-menu-split menu-list "Project")))
3528 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3529 ("Auto Load Setup File"
3530 ["At Startup"
3531 (customize-set-variable 'vhdl-project-auto-load
3532 (if (memq 'startup vhdl-project-auto-load)
3533 (delq 'startup vhdl-project-auto-load)
3534 (cons 'startup vhdl-project-auto-load)))
3535 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3536 ["Sort Projects"
3537 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3538 :style toggle :selected vhdl-project-sort]
3539 "--"
3540 ["Customize Group..." (customize-group 'vhdl-project) t])
3541 ("Compiler"
3542 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3543 ,(append
3544 '("Selected Compiler at Startup")
3545 ;; add menu entries for defined compilers
3546 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3547 (while comp-alist
3548 (setq name (caar comp-alist))
3549 (setq menu-list
3550 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3551 :style radio :selected (equal ,name vhdl-compiler)]
3552 menu-list))
3553 (setq comp-alist (cdr comp-alist)))
3554 (setq menu-list (nreverse menu-list))
3555 (vhdl-menu-split menu-list "Compler")))
3556 ["Use Local Error Regexp"
3557 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3558 (not vhdl-compile-use-local-error-regexp))
3559 :style toggle :selected vhdl-compile-use-local-error-regexp]
3560 ["Makefile Generation Hook..."
3561 (customize-option 'vhdl-makefile-generation-hook) t]
3562 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3563 "--"
3564 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3565 ("Style"
3566 ("VHDL Standard"
3567 ["VHDL'87"
3568 (progn (customize-set-variable 'vhdl-standard
3569 (list '87 (cadr vhdl-standard)))
3570 (vhdl-activate-customizations))
3571 :style radio :selected (eq '87 (car vhdl-standard))]
3572 ["VHDL'93"
3573 (progn (customize-set-variable 'vhdl-standard
3574 (list '93 (cadr vhdl-standard)))
3575 (vhdl-activate-customizations))
3576 :style radio :selected (eq '93 (car vhdl-standard))]
3577 "--"
3578 ["VHDL-AMS"
3579 (progn (customize-set-variable
3580 'vhdl-standard (list (car vhdl-standard)
3581 (if (memq 'ams (cadr vhdl-standard))
3582 (delq 'ams (cadr vhdl-standard))
3583 (cons 'ams (cadr vhdl-standard)))))
3584 (vhdl-activate-customizations))
3585 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3586 ["Math Packages"
3587 (progn (customize-set-variable
3588 'vhdl-standard (list (car vhdl-standard)
3589 (if (memq 'math (cadr vhdl-standard))
3590 (delq 'math (cadr vhdl-standard))
3591 (cons 'math (cadr vhdl-standard)))))
3592 (vhdl-activate-customizations))
3593 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3594 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3595 ["Upper Case Keywords"
3596 (customize-set-variable 'vhdl-upper-case-keywords
3597 (not vhdl-upper-case-keywords))
3598 :style toggle :selected vhdl-upper-case-keywords]
3599 ["Upper Case Types"
3600 (customize-set-variable 'vhdl-upper-case-types
3601 (not vhdl-upper-case-types))
3602 :style toggle :selected vhdl-upper-case-types]
3603 ["Upper Case Attributes"
3604 (customize-set-variable 'vhdl-upper-case-attributes
3605 (not vhdl-upper-case-attributes))
3606 :style toggle :selected vhdl-upper-case-attributes]
3607 ["Upper Case Enumeration Values"
3608 (customize-set-variable 'vhdl-upper-case-enum-values
3609 (not vhdl-upper-case-enum-values))
3610 :style toggle :selected vhdl-upper-case-enum-values]
3611 ["Upper Case Constants"
3612 (customize-set-variable 'vhdl-upper-case-constants
3613 (not vhdl-upper-case-constants))
3614 :style toggle :selected vhdl-upper-case-constants]
3615 ("Use Direct Instantiation"
3616 ["Never"
3617 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3618 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3619 ["Standard"
3620 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3621 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3622 ["Always"
3623 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3624 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3625 "--"
3626 ["Customize Group..." (customize-group 'vhdl-style) t])
3627 ("Naming"
3628 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3629 ["Architecture File Name..."
3630 (customize-option 'vhdl-architecture-file-name) t]
3631 ["Configuration File Name..."
3632 (customize-option 'vhdl-configuration-file-name) t]
3633 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3634 ("File Name Case"
3635 ["As Is"
3636 (customize-set-variable 'vhdl-file-name-case 'identity)
3637 :style radio :selected (eq 'identity vhdl-file-name-case)]
3638 ["Lower Case"
3639 (customize-set-variable 'vhdl-file-name-case 'downcase)
3640 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3641 ["Upper Case"
3642 (customize-set-variable 'vhdl-file-name-case 'upcase)
3643 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3644 ["Capitalize"
3645 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3646 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3647 "--"
3648 ["Customize Group..." (customize-group 'vhdl-naming) t])
3649 ("Template"
3650 ("Electric Keywords"
3651 ["VHDL Keywords"
3652 (customize-set-variable 'vhdl-electric-keywords
3653 (if (memq 'vhdl vhdl-electric-keywords)
3654 (delq 'vhdl vhdl-electric-keywords)
3655 (cons 'vhdl vhdl-electric-keywords)))
3656 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3657 ["User Model Keywords"
3658 (customize-set-variable 'vhdl-electric-keywords
3659 (if (memq 'user vhdl-electric-keywords)
3660 (delq 'user vhdl-electric-keywords)
3661 (cons 'user vhdl-electric-keywords)))
3662 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3663 ("Insert Optional Labels"
3664 ["None"
3665 (customize-set-variable 'vhdl-optional-labels 'none)
3666 :style radio :selected (eq 'none vhdl-optional-labels)]
3667 ["Processes Only"
3668 (customize-set-variable 'vhdl-optional-labels 'process)
3669 :style radio :selected (eq 'process vhdl-optional-labels)]
3670 ["All Constructs"
3671 (customize-set-variable 'vhdl-optional-labels 'all)
3672 :style radio :selected (eq 'all vhdl-optional-labels)])
3673 ("Insert Empty Lines"
3674 ["None"
3675 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3676 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3677 ["Design Units Only"
3678 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3679 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3680 ["All Constructs"
3681 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3682 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3683 ["Argument List Indent"
3684 (customize-set-variable 'vhdl-argument-list-indent
3685 (not vhdl-argument-list-indent))
3686 :style toggle :selected vhdl-argument-list-indent]
3687 ["Association List with Formals"
3688 (customize-set-variable 'vhdl-association-list-with-formals
3689 (not vhdl-association-list-with-formals))
3690 :style toggle :selected vhdl-association-list-with-formals]
3691 ["Conditions in Parenthesis"
3692 (customize-set-variable 'vhdl-conditions-in-parenthesis
3693 (not vhdl-conditions-in-parenthesis))
3694 :style toggle :selected vhdl-conditions-in-parenthesis]
3695 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3696 ["One String..." (customize-option 'vhdl-one-string) t]
3697 ("File Header"
3698 ["Header String..." (customize-option 'vhdl-file-header) t]
3699 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3700 ["Company Name..." (customize-option 'vhdl-company-name) t]
3701 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3702 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3703 ["Date Format..." (customize-option 'vhdl-date-format) t]
3704 ["Modify Date Prefix String..."
3705 (customize-option 'vhdl-modify-date-prefix-string) t]
3706 ["Modify Date on Saving"
3707 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3708 (not vhdl-modify-date-on-saving))
3709 (vhdl-activate-customizations))
3710 :style toggle :selected vhdl-modify-date-on-saving])
3711 ("Sequential Process"
3712 ("Kind of Reset"
3713 ["None"
3714 (customize-set-variable 'vhdl-reset-kind 'none)
3715 :style radio :selected (eq 'none vhdl-reset-kind)]
3716 ["Synchronous"
3717 (customize-set-variable 'vhdl-reset-kind 'sync)
3718 :style radio :selected (eq 'sync vhdl-reset-kind)]
3719 ["Asynchronous"
3720 (customize-set-variable 'vhdl-reset-kind 'async)
3721 :style radio :selected (eq 'async vhdl-reset-kind)])
3722 ["Reset is Active High"
3723 (customize-set-variable 'vhdl-reset-active-high
3724 (not vhdl-reset-active-high))
3725 :style toggle :selected vhdl-reset-active-high]
3726 ["Use Rising Clock Edge"
3727 (customize-set-variable 'vhdl-clock-rising-edge
3728 (not vhdl-clock-rising-edge))
3729 :style toggle :selected vhdl-clock-rising-edge]
3730 ("Clock Edge Condition"
3731 ["Standard"
3732 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3733 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3734 ["Function \"rising_edge\""
3735 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3736 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3737 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3738 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3739 "--"
3740 ["Customize Group..." (customize-group 'vhdl-template) t])
3741 ("Model"
3742 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3743 ("Port"
3744 ["Include Port Comments"
3745 (customize-set-variable 'vhdl-include-port-comments
3746 (not vhdl-include-port-comments))
3747 :style toggle :selected vhdl-include-port-comments]
3748 ["Include Direction Comments"
3749 (customize-set-variable 'vhdl-include-direction-comments
3750 (not vhdl-include-direction-comments))
3751 :style toggle :selected vhdl-include-direction-comments]
3752 ["Include Type Comments"
3753 (customize-set-variable 'vhdl-include-type-comments
3754 (not vhdl-include-type-comments))
3755 :style toggle :selected vhdl-include-type-comments]
3756 ("Include Group Comments"
3757 ["Never"
3758 (customize-set-variable 'vhdl-include-group-comments 'never)
3759 :style radio :selected (eq 'never vhdl-include-group-comments)]
3760 ["Declarations"
3761 (customize-set-variable 'vhdl-include-group-comments 'decl)
3762 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3763 ["Always"
3764 (customize-set-variable 'vhdl-include-group-comments 'always)
3765 :style radio :selected (eq 'always vhdl-include-group-comments)])
3766 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3767 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3768 ("Testbench"
3769 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3770 ["Architecture Name..."
3771 (customize-option 'vhdl-testbench-architecture-name) t]
3772 ["Configuration Name..."
3773 (customize-option 'vhdl-testbench-configuration-name) t]
3774 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3775 ["Include Header"
3776 (customize-set-variable 'vhdl-testbench-include-header
3777 (not vhdl-testbench-include-header))
3778 :style toggle :selected vhdl-testbench-include-header]
3779 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3780 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3781 ["Initialize Signals"
3782 (customize-set-variable 'vhdl-testbench-initialize-signals
3783 (not vhdl-testbench-initialize-signals))
3784 :style toggle :selected vhdl-testbench-initialize-signals]
3785 ["Include Library Clause"
3786 (customize-set-variable 'vhdl-testbench-include-library
3787 (not vhdl-testbench-include-library))
3788 :style toggle :selected vhdl-testbench-include-library]
3789 ["Include Configuration"
3790 (customize-set-variable 'vhdl-testbench-include-configuration
3791 (not vhdl-testbench-include-configuration))
3792 :style toggle :selected vhdl-testbench-include-configuration]
3793 ("Create Files"
3794 ["None"
3795 (customize-set-variable 'vhdl-testbench-create-files 'none)
3796 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3797 ["Single"
3798 (customize-set-variable 'vhdl-testbench-create-files 'single)
3799 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3800 ["Separate"
3801 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3802 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3803 ["Testbench Entity File Name..."
3804 (customize-option 'vhdl-testbench-entity-file-name) t]
3805 ["Testbench Architecture File Name..."
3806 (customize-option 'vhdl-testbench-architecture-file-name) t])
3807 "--"
3808 ["Customize Group..." (customize-group 'vhdl-port) t])
3809 ("Compose"
3810 ["Architecture Name..."
3811 (customize-option 'vhdl-compose-architecture-name) t]
3812 ["Configuration Name..."
3813 (customize-option 'vhdl-compose-configuration-name) t]
3814 ["Components Package Name..."
3815 (customize-option 'vhdl-components-package-name) t]
3816 ["Use Components Package"
3817 (customize-set-variable 'vhdl-use-components-package
3818 (not vhdl-use-components-package))
3819 :style toggle :selected vhdl-use-components-package]
3820 ["Include Header"
3821 (customize-set-variable 'vhdl-compose-include-header
3822 (not vhdl-compose-include-header))
3823 :style toggle :selected vhdl-compose-include-header]
3824 ("Create Entity/Architecture Files"
3825 ["None"
3826 (customize-set-variable 'vhdl-compose-create-files 'none)
3827 :style radio :selected (eq 'none vhdl-compose-create-files)]
3828 ["Single"
3829 (customize-set-variable 'vhdl-compose-create-files 'single)
3830 :style radio :selected (eq 'single vhdl-compose-create-files)]
3831 ["Separate"
3832 (customize-set-variable 'vhdl-compose-create-files 'separate)
3833 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3834 ["Create Configuration File"
3835 (customize-set-variable 'vhdl-compose-configuration-create-file
3836 (not vhdl-compose-configuration-create-file))
3837 :style toggle :selected vhdl-compose-configuration-create-file]
3838 ["Hierarchical Configuration"
3839 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3840 (not vhdl-compose-configuration-hierarchical))
3841 :style toggle :selected vhdl-compose-configuration-hierarchical]
3842 ["Use Subconfiguration"
3843 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3844 (not vhdl-compose-configuration-use-subconfiguration))
3845 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3846 "--"
3847 ["Customize Group..." (customize-group 'vhdl-compose) t])
3848 ("Comment"
3849 ["Self Insert Comments"
3850 (customize-set-variable 'vhdl-self-insert-comments
3851 (not vhdl-self-insert-comments))
3852 :style toggle :selected vhdl-self-insert-comments]
3853 ["Prompt for Comments"
3854 (customize-set-variable 'vhdl-prompt-for-comments
3855 (not vhdl-prompt-for-comments))
3856 :style toggle :selected vhdl-prompt-for-comments]
3857 ["Inline Comment Column..."
3858 (customize-option 'vhdl-inline-comment-column) t]
3859 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3860 "--"
3861 ["Customize Group..." (customize-group 'vhdl-comment) t])
3862 ("Align"
3863 ["Auto Align Templates"
3864 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3865 :style toggle :selected vhdl-auto-align]
3866 ["Align Line Groups"
3867 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3868 :style toggle :selected vhdl-align-groups]
3869 ["Group Separation String..."
3870 (customize-set-variable 'vhdl-align-group-separate) t]
3871 ["Align Lines with Same Indent"
3872 (customize-set-variable 'vhdl-align-same-indent
3873 (not vhdl-align-same-indent))
3874 :style toggle :selected vhdl-align-same-indent]
3875 "--"
3876 ["Customize Group..." (customize-group 'vhdl-align) t])
3877 ("Highlight"
3878 ["Highlighting On/Off..."
3879 (customize-option
3880 (if (fboundp 'global-font-lock-mode)
3881 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3882 ["Highlight Keywords"
3883 (progn (customize-set-variable 'vhdl-highlight-keywords
3884 (not vhdl-highlight-keywords))
3885 (vhdl-fontify-buffer))
3886 :style toggle :selected vhdl-highlight-keywords]
3887 ["Highlight Names"
3888 (progn (customize-set-variable 'vhdl-highlight-names
3889 (not vhdl-highlight-names))
3890 (vhdl-fontify-buffer))
3891 :style toggle :selected vhdl-highlight-names]
3892 ["Highlight Special Words"
3893 (progn (customize-set-variable 'vhdl-highlight-special-words
3894 (not vhdl-highlight-special-words))
3895 (vhdl-fontify-buffer))
3896 :style toggle :selected vhdl-highlight-special-words]
3897 ["Highlight Forbidden Words"
3898 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3899 (not vhdl-highlight-forbidden-words))
3900 (vhdl-fontify-buffer))
3901 :style toggle :selected vhdl-highlight-forbidden-words]
3902 ["Highlight Verilog Keywords"
3903 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3904 (not vhdl-highlight-verilog-keywords))
3905 (vhdl-fontify-buffer))
3906 :style toggle :selected vhdl-highlight-verilog-keywords]
3907 ["Highlight \"translate_off\""
3908 (progn (customize-set-variable 'vhdl-highlight-translate-off
3909 (not vhdl-highlight-translate-off))
3910 (vhdl-fontify-buffer))
3911 :style toggle :selected vhdl-highlight-translate-off]
3912 ["Case Sensitive Highlighting"
3913 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3914 (not vhdl-highlight-case-sensitive))
3915 (vhdl-fontify-buffer))
3916 :style toggle :selected vhdl-highlight-case-sensitive]
3917 ["Special Syntax Definition..."
3918 (customize-option 'vhdl-special-syntax-alist) t]
3919 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3920 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3921 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3922 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3923 "--"
3924 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3925 ("Speedbar"
3926 ["Auto Open at Startup"
3927 (customize-set-variable 'vhdl-speedbar-auto-open
3928 (not vhdl-speedbar-auto-open))
3929 :style toggle :selected vhdl-speedbar-auto-open]
3930 ("Default Displaying Mode"
3931 ["Files"
3932 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3933 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3934 ["Directory Hierarchy"
3935 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3936 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3937 ["Project Hierarchy"
3938 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3939 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3940 ["Indentation Offset..."
3941 (customize-option 'speedbar-indentation-width) t]
3942 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3943 ["Jump to Unit when Opening"
3944 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3945 (not vhdl-speedbar-jump-to-unit))
3946 :style toggle :selected vhdl-speedbar-jump-to-unit]
3947 ["Update Hierarchy on File Saving"
3948 (customize-set-variable 'vhdl-speedbar-update-on-saving
3949 (not vhdl-speedbar-update-on-saving))
3950 :style toggle :selected vhdl-speedbar-update-on-saving]
3951 ("Save in Cache File"
3952 ["Hierarchy Information"
3953 (customize-set-variable 'vhdl-speedbar-save-cache
3954 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3955 (delq 'hierarchy vhdl-speedbar-save-cache)
3956 (cons 'hierarchy vhdl-speedbar-save-cache)))
3957 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3958 ["Displaying Status"
3959 (customize-set-variable 'vhdl-speedbar-save-cache
3960 (if (memq 'display vhdl-speedbar-save-cache)
3961 (delq 'display vhdl-speedbar-save-cache)
3962 (cons 'display vhdl-speedbar-save-cache)))
3963 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3964 ["Cache File Name..."
3965 (customize-option 'vhdl-speedbar-cache-file-name) t]
3966 "--"
3967 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3968 ("Menu"
3969 ["Add Index Menu when Loading File"
3970 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3971 (vhdl-index-menu-init))
3972 :style toggle :selected vhdl-index-menu]
3973 ["Add Source File Menu when Loading File"
3974 (progn (customize-set-variable 'vhdl-source-file-menu
3975 (not vhdl-source-file-menu))
3976 (vhdl-add-source-files-menu))
3977 :style toggle :selected vhdl-source-file-menu]
3978 ["Add Hideshow Menu at Startup"
3979 (progn (customize-set-variable 'vhdl-hideshow-menu
3980 (not vhdl-hideshow-menu))
3981 (vhdl-activate-customizations))
3982 :style toggle :selected vhdl-hideshow-menu]
3983 ["Hide Everything Initially"
3984 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3985 :style toggle :selected vhdl-hide-all-init]
3986 "--"
3987 ["Customize Group..." (customize-group 'vhdl-menu) t])
3988 ("Print"
3989 ["In Two Column Format"
3990 (progn (customize-set-variable 'vhdl-print-two-column
3991 (not vhdl-print-two-column))
3992 (message "Activate new setting by saving options and restarting Emacs"))
3993 :style toggle :selected vhdl-print-two-column]
3994 ["Use Customized Faces"
3995 (progn (customize-set-variable 'vhdl-print-customize-faces
3996 (not vhdl-print-customize-faces))
3997 (message "Activate new setting by saving options and restarting Emacs"))
3998 :style toggle :selected vhdl-print-customize-faces]
3999 "--"
4000 ["Customize Group..." (customize-group 'vhdl-print) t])
4001 ("Miscellaneous"
4002 ["Use Intelligent Tab"
4003 (progn (customize-set-variable 'vhdl-intelligent-tab
4004 (not vhdl-intelligent-tab))
4005 (vhdl-activate-customizations))
4006 :style toggle :selected vhdl-intelligent-tab]
4007 ["Indent Syntax-Based"
4008 (customize-set-variable 'vhdl-indent-syntax-based
4009 (not vhdl-indent-syntax-based))
4010 :style toggle :selected vhdl-indent-syntax-based]
4011 ["Word Completion is Case Sensitive"
4012 (customize-set-variable 'vhdl-word-completion-case-sensitive
4013 (not vhdl-word-completion-case-sensitive))
4014 :style toggle :selected vhdl-word-completion-case-sensitive]
4015 ["Word Completion in Minibuffer"
4016 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4017 (not vhdl-word-completion-in-minibuffer))
4018 (message "Activate new setting by saving options and restarting Emacs"))
4019 :style toggle :selected vhdl-word-completion-in-minibuffer]
4020 ["Underscore is Part of Word"
4021 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4022 (not vhdl-underscore-is-part-of-word))
4023 (vhdl-activate-customizations))
4024 :style toggle :selected vhdl-underscore-is-part-of-word]
4025 "--"
4026 ["Customize Group..." (customize-group 'vhdl-misc) t])
4027 ["Related..." (customize-browse 'vhdl-related) t]
4028 "--"
4029 ["Save Options" customize-save-customized t]
4030 ["Activate Options" vhdl-activate-customizations t]
4031 ["Browse Options..." vhdl-customize t])))
4032
4033 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4034 "VHDL Mode menu.")
4035
4036 (defun vhdl-update-mode-menu ()
4037 "Update VHDL Mode menu."
4038 (interactive)
4039 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4040 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4041 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4042 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4043 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4044
4045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4046 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4047
4048 (defconst vhdl-imenu-generic-expression
4049 '(
4050 ("Subprogram"
4051 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4052 4)
4053 ("Instance"
4054 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4055 1)
4056 ("Component"
4057 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4058 2)
4059 ("Procedural"
4060 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4061 1)
4062 ("Process"
4063 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4064 1)
4065 ("Block"
4066 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4067 1)
4068 ("Package"
4069 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4070 3)
4071 ("Configuration"
4072 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4073 2)
4074 ("Architecture"
4075 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4076 2)
4077 ("Entity"
4078 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4079 2)
4080 )
4081 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4082
4083 (defun vhdl-index-menu-init ()
4084 "Initialize index menu."
4085 (set (make-local-variable 'imenu-case-fold-search) t)
4086 (set (make-local-variable 'imenu-generic-expression)
4087 vhdl-imenu-generic-expression)
4088 (when (and vhdl-index-menu (fboundp 'imenu))
4089 (if (or (not (boundp 'font-lock-maximum-size))
4090 (> font-lock-maximum-size (buffer-size)))
4091 (imenu-add-to-menubar "Index")
4092 (message "Scanning buffer for index...buffer too big"))))
4093
4094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4095 ;; Source file menu (using `easy-menu.el')
4096
4097 (defvar vhdl-sources-menu nil)
4098
4099 (defun vhdl-directory-files (directory &optional full match)
4100 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4101 message."
4102 (if (not (file-directory-p directory))
4103 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4104 (let ((dir (directory-files directory full match)))
4105 (setq dir (delete "." dir))
4106 (setq dir (delete ".." dir))
4107 dir)))
4108
4109 (defun vhdl-get-source-files (&optional full directory)
4110 "Get list of VHDL source files in DIRECTORY or current directory."
4111 (let ((mode-alist auto-mode-alist)
4112 filename-regexp)
4113 ;; create regular expressions for matching file names
4114 (setq filename-regexp "\\`[^.].*\\(")
4115 (while mode-alist
4116 (when (eq (cdar mode-alist) 'vhdl-mode)
4117 (setq filename-regexp
4118 (concat filename-regexp (caar mode-alist) "\\|")))
4119 (setq mode-alist (cdr mode-alist)))
4120 (setq filename-regexp
4121 (concat (substring filename-regexp 0
4122 (string-match "\\\\|$" filename-regexp)) "\\)"))
4123 ;; find files
4124 (vhdl-directory-files
4125 (or directory default-directory) full filename-regexp)))
4126
4127 (defun vhdl-add-source-files-menu ()
4128 "Scan directory for all VHDL source files and generate menu.
4129 The directory of the current source file is scanned."
4130 (interactive)
4131 (message "Scanning directory for source files ...")
4132 (let ((newmap (current-local-map))
4133 (file-list (vhdl-get-source-files))
4134 menu-list found)
4135 ;; Create list for menu
4136 (setq found nil)
4137 (while file-list
4138 (setq found t)
4139 (setq menu-list (cons (vector (car file-list)
4140 (list 'find-file (car file-list)) t)
4141 menu-list))
4142 (setq file-list (cdr file-list)))
4143 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4144 (when found (setq menu-list (cons "--" menu-list)))
4145 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4146 (setq menu-list (cons "Sources" menu-list))
4147 ;; Create menu
4148 (easy-menu-add menu-list)
4149 (easy-menu-define vhdl-sources-menu newmap
4150 "VHDL source files menu" menu-list))
4151 (message ""))
4152
4153
4154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4155 ;;; Mode definition
4156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4157 ;; performs all buffer local initializations
4158
4159 ;;;###autoload
4160 (defun vhdl-mode ()
4161 "Major mode for editing VHDL code.
4162
4163 Usage:
4164 ------
4165
4166 TEMPLATE INSERTION (electrification):
4167 After typing a VHDL keyword and entering `SPC', you are prompted for
4168 arguments while a template is generated for that VHDL construct. Typing
4169 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4170 template generation. Optional arguments are indicated by square
4171 brackets and removed if the queried string is left empty. Prompts for
4172 mandatory arguments remain in the code if the queried string is left
4173 empty. They can be queried again by `C-c C-t C-q'. Enabled
4174 electrification is indicated by `/e' in the modeline.
4175
4176 Typing `M-SPC' after a keyword inserts a space without calling the
4177 template generator. Automatic template generation (i.e.
4178 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4179 setting option `vhdl-electric-mode' (see OPTIONS).
4180
4181 Template generators can be invoked from the VHDL menu, by key
4182 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4183 the keyword (i.e. first word of menu entry not in parenthesis) and
4184 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4185 conf, comp, cons, func, inst, pack, sig, var.
4186
4187 Template styles can be customized in customization group
4188 `vhdl-template' \(see OPTIONS).
4189
4190
4191 HEADER INSERTION:
4192 A file header can be inserted by `C-c C-t C-h'. A file footer
4193 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4194 See customization group `vhdl-header'.
4195
4196
4197 STUTTERING:
4198 Double striking of some keys inserts cumbersome VHDL syntax elements.
4199 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4200 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4201 the modeline. The stuttering keys and their effects are:
4202
4203 ;; --> \" : \" [ --> ( -- --> comment
4204 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4205 .. --> \" => \" ] --> ) --- --> horizontal line
4206 ,, --> \" <= \" ]] --> ] ---- --> display comment
4207 == --> \" == \" '' --> \\\"
4208
4209
4210 WORD COMPLETION:
4211 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4212 word in the buffer that starts alike, inserts it and adjusts case.
4213 Re-typing `TAB' toggles through alternative word completions. This also
4214 works in the minibuffer (i.e. in template generator prompts).
4215
4216 Typing `TAB' after `(' looks for and inserts complete parenthesized
4217 expressions (e.g. for array index ranges). All keywords as well as
4218 standard types and subprograms of VHDL have predefined abbreviations
4219 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4220 beginning with \"std\").
4221
4222 Typing `TAB' after a non-word character indents the line if at the
4223 beginning of a line (i.e. no preceding non-blank characters), and
4224 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4225 stop.
4226
4227
4228 COMMENTS:
4229 `--' puts a single comment.
4230 `---' draws a horizontal line for separating code segments.
4231 `----' inserts a display comment, i.e. two horizontal lines
4232 with a comment in between.
4233 `--CR' comments out code on that line. Re-hitting CR comments
4234 out following lines.
4235 `C-c c' comments out a region if not commented out,
4236 uncomments a region if already commented out.
4237
4238 You are prompted for comments after object definitions (i.e. signals,
4239 variables, constants, ports) and after subprogram and process
4240 specifications if option `vhdl-prompt-for-comments' is non-nil.
4241 Comments are automatically inserted as additional labels (e.g. after
4242 begin statements) and as help comments if `vhdl-self-insert-comments' is
4243 non-nil.
4244
4245 Inline comments (i.e. comments after a piece of code on the same line)
4246 are indented at least to `vhdl-inline-comment-column'. Comments go at
4247 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4248 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4249 in a comment automatically opens a new comment line. `M-q' re-fills
4250 multi-line comments.
4251
4252
4253 INDENTATION:
4254 `TAB' indents a line if at the beginning of the line. The amount of
4255 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4256 always indents the current line (is bound to `TAB' if option
4257 `vhdl-intelligent-tab' is nil).
4258
4259 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4260 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4261 indented normally (nil) or relative to the opening parenthesis (non-nil)
4262 according to option `vhdl-argument-list-indent'.
4263
4264 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4265 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4266 and vice versa.
4267
4268 Syntax-based indentation can be very slow in large files. Option
4269 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4270
4271
4272 ALIGNMENT:
4273 The alignment functions align operators, keywords, and inline comments
4274 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4275 separated by blank lines, `C-c C-a C-i' a block of lines with same
4276 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4277 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4278 C-a C-d' all lines within the declarative part of a design unit. `C-c
4279 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4280 for a group of lines, and `C-c C-a M-c' for a region.
4281
4282 If option `vhdl-align-groups' is non-nil, groups of code lines
4283 separated by special lines (see option `vhdl-align-group-separate') are
4284 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4285 blocks of lines with same indent are aligned separately. Some templates
4286 are automatically aligned after generation if option `vhdl-auto-align'
4287 is non-nil.
4288
4289 Alignment tries to align inline comments at
4290 `vhdl-inline-comment-column' and tries inline comment not to exceed
4291 `vhdl-end-comment-column'.
4292
4293 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4294 symbols are surrounded by one space, and multiple spaces are eliminated.
4295
4296
4297 CODE FILLING:
4298 Code filling allows to condense code (e.g. sensitivity lists or port
4299 maps) by removing comments and newlines and re-wrapping so that all
4300 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4301 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4302 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4303 `C-c C-f M-f' an entire region.
4304
4305
4306 CODE BEAUTIFICATION:
4307 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4308 buffer respectively. This inludes indentation, alignment, and case
4309 fixing. Code beautification can also be run non-interactively using the
4310 command:
4311
4312 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4313
4314
4315 PORT TRANSLATION:
4316 Generic and port clauses from entity or component declarations can be
4317 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4318 as component instantiations and corresponding internal constants and
4319 signals, as a generic map with constants as actual generics, and as
4320 internal signal initializations (menu).
4321
4322 To include formals in component instantiations, see option
4323 `vhdl-association-list-with-formals'. To include comments in pasting,
4324 see options `vhdl-include-...-comments'.
4325
4326 A clause with several generic/port names on the same line can be
4327 flattened (`C-c C-p C-f') so that only one name per line exists. The
4328 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4329 outputs and vice versa, which can be useful in testbenches. (This
4330 reversion is done on the internal data structure and is only reflected
4331 in subsequent paste operations.)
4332
4333 Names for actual ports, instances, testbenches, and
4334 design-under-test instances can be derived from existing names according
4335 to options `vhdl-...-name'. See customization group `vhdl-port'.
4336
4337
4338 SUBPROGRAM TRANSLATION:
4339 Similar functionality exists for copying/pasting the interface of
4340 subprograms (function/procedure). A subprogram interface can be copied
4341 and then pasted as a subprogram declaration, body or call (uses
4342 association list with formals).
4343
4344
4345 TESTBENCH GENERATION:
4346 A copied port can also be pasted as a testbench. The generated
4347 testbench includes an entity, an architecture, and an optional
4348 configuration. The architecture contains the component declaration and
4349 instantiation of the DUT as well as internal constant and signal
4350 declarations. Additional user-defined templates can be inserted. The
4351 names used for entity/architecture/configuration/DUT as well as the file
4352 structure to be generated can be customized. See customization group
4353 `vhdl-testbench'.
4354
4355
4356 KEY BINDINGS:
4357 Key bindings (`C-c ...') exist for most commands (see in menu).
4358
4359
4360 VHDL MENU:
4361 All commands can be found in the VHDL menu including their key bindings.
4362
4363
4364 FILE BROWSER:
4365 The speedbar allows browsing of directories and file contents. It can
4366 be accessed from the VHDL menu and is automatically opened if option
4367 `vhdl-speedbar-auto-open' is non-nil.
4368
4369 In speedbar, open files and directories with `mouse-2' on the name and
4370 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4371
4372
4373 DESIGN HIERARCHY BROWSER:
4374 The speedbar can also be used for browsing the hierarchy of design units
4375 contained in the source files of the current directory or the specified
4376 projects (see option `vhdl-project-alist').
4377
4378 The speedbar can be switched between file, directory hierarchy and
4379 project hierarchy browsing mode in the speedbar menu or by typing `f',
4380 `h' or `H' in speedbar.
4381
4382 In speedbar, open design units with `mouse-2' on the name and browse
4383 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4384 from entities and components (in packages). Individual design units and
4385 complete designs can directly be compiled (\"Make\" menu entry).
4386
4387 The hierarchy is automatically updated upon saving a modified source
4388 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4389 hierarchy is only updated for projects that have been opened once in the
4390 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4391 options in group `vhdl-speedbar').
4392
4393 Simple design consistency checks are done during scanning, such as
4394 multiple declarations of the same unit or missing primary units that are
4395 required by secondary units.
4396
4397
4398 STRUCTURAL COMPOSITION:
4399 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4400 for a new component. Subcomponents (i.e. component declaration and
4401 instantiation) can be automatically placed from a previously read port
4402 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4403 all subcomponents can be automatically connected using internal signals
4404 and ports (`C-c C-c C-w') following these rules:
4405 - subcomponent actual ports with same name are considered to be
4406 connected by a signal (internal signal or port)
4407 - signals that are only inputs to subcomponents are considered as
4408 inputs to this component -> input port created
4409 - signals that are only outputs from subcomponents are considered as
4410 outputs from this component -> output port created
4411 - signals that are inputs to AND outputs from subcomponents are
4412 considered as internal connections -> internal signal created
4413
4414 Purpose: With appropriate naming conventions it is possible to
4415 create higher design levels with only a few mouse clicks or key
4416 strokes. A new design level can be created by simply generating a new
4417 component, placing the required subcomponents from the hierarchy
4418 browser, and wiring everything automatically.
4419
4420 Note: Automatic wiring only works reliably on templates of new
4421 components and component instantiations that were created by VHDL mode.
4422
4423 Component declarations can be placed in a components package (option
4424 `vhdl-use-components-package') which can be automatically generated for
4425 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4426 component instantiation is also supported (option
4427 `vhdl-use-direct-instantiation').
4428
4429 | Configuration declarations can automatically be generated either from
4430 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4431 | the speedbar menu (for the architecture under the cursor). The
4432 | configurations can optionally be hierarchical (i.e. include all
4433 | component levels of a hierarchical design, option
4434 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4435 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4436 | subcomponents in hierarchical configurations, the most-recently-analyzed
4437 | (mra) architecture is selected. If another architecture is desired, it
4438 | can be marked as most-recently-analyzed (speedbar menu) before
4439 | generating the configuration.
4440 |
4441 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4442 | declarations) are currently not considered when displaying
4443 | configurations in speedbar.
4444
4445 See the options group `vhdl-compose' for all relevant user options.
4446
4447
4448 SOURCE FILE COMPILATION:
4449 The syntax of the current buffer can be analyzed by calling a VHDL
4450 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4451 option `vhdl-compiler'. The available compilers are listed in option
4452 `vhdl-compiler-alist' including all required compilation command,
4453 command options, compilation directory, and error message syntax
4454 information. New compilers can be added.
4455
4456 All the source files of an entire design can be compiled by the `make'
4457 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4458
4459
4460 MAKEFILE GENERATION:
4461 Makefiles can be generated automatically by an internal generation
4462 routine (`C-c M-k'). The library unit dependency information is
4463 obtained from the hierarchy browser. Makefile generation can be
4464 customized for each compiler in option `vhdl-compiler-alist'.
4465
4466 Makefile generation can also be run non-interactively using the
4467 command:
4468
4469 emacs -batch -l ~/.emacs -l vhdl-mode
4470 [-compiler compilername] [-project projectname]
4471 -f vhdl-generate-makefile
4472
4473 The Makefile's default target \"all\" compiles the entire design, the
4474 target \"clean\" removes it and the target \"library\" creates the
4475 library directory if not existent. The Makefile also includes a target
4476 for each primary library unit which allows selective compilation of this
4477 unit, its secondary units and its subhierarchy (example: compilation of
4478 a design specified by a configuration). User specific parts can be
4479 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4480
4481 Limitations:
4482 - Only library units and dependencies within the current library are
4483 considered. Makefiles for designs that span multiple libraries are
4484 not (yet) supported.
4485 - Only one-level configurations are supported (also hierarchical),
4486 but configurations that go down several levels are not.
4487 - The \"others\" keyword in configurations is not supported.
4488
4489
4490 PROJECTS:
4491 Projects can be defined in option `vhdl-project-alist' and a current
4492 project be selected using option `vhdl-project' (permanently) or from
4493 the menu or speedbar (temporarily). For each project, title and
4494 description strings (for the file headers), source files/directories
4495 (for the hierarchy browser and Makefile generation), library name, and
4496 compiler-dependent options, exceptions and compilation directory can be
4497 specified. Compilation settings overwrite the settings of option
4498 `vhdl-compiler-alist'.
4499
4500 Project setups can be exported (i.e. written to a file) and imported.
4501 Imported setups are not automatically saved in `vhdl-project-alist' but
4502 can be saved afterwards in its customization buffer. When starting
4503 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4504 vhdl-mode\") in a directory with an existing project setup file, it is
4505 automatically loaded and its project activated if option
4506 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4507 files can be specified in option `vhdl-project-file-name'. Multiple
4508 project setups can be automatically loaded from global directories.
4509 This is an alternative to specifying project setups with option
4510 `vhdl-project-alist'.
4511
4512
4513 SPECIAL MENUES:
4514 As an alternative to the speedbar, an index menu can be added (set
4515 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4516 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4517 file) for browsing the file contents (is not populated if buffer is
4518 larger than `font-lock-maximum-size'). Also, a source file menu can be
4519 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4520 current directory for VHDL source files.
4521
4522
4523 VHDL STANDARDS:
4524 The VHDL standards to be used are specified in option `vhdl-standard'.
4525 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4526
4527
4528 KEYWORD CASE:
4529 Lower and upper case for keywords and standardized types, attributes,
4530 and enumeration values is supported. If the option
4531 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4532 lower case and are converted into upper case automatically (not for
4533 types, attributes, and enumeration values). The case of keywords,
4534 types, attributes,and enumeration values can be fixed for an entire
4535 region (menu) or buffer (`C-c C-x C-c') according to the options
4536 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4537
4538
4539 HIGHLIGHTING (fontification):
4540 Keywords and standardized types, attributes, enumeration values, and
4541 function names (controlled by option `vhdl-highlight-keywords'), as well
4542 as comments, strings, and template prompts are highlighted using
4543 different colors. Unit, subprogram, signal, variable, constant,
4544 parameter and generic/port names in declarations as well as labels are
4545 highlighted if option `vhdl-highlight-names' is non-nil.
4546
4547 Additional reserved words or words with a forbidden syntax (e.g. words
4548 that should be avoided) can be specified in option
4549 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4550 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4551 keywords are highlighted as forbidden words if option
4552 `vhdl-highlight-verilog-keywords' is non-nil.
4553
4554 Words with special syntax can be highlighted by specifying their
4555 syntax and color in option `vhdl-special-syntax-alist' and by setting
4556 option `vhdl-highlight-special-words' to non-nil. This allows to
4557 establish some naming conventions (e.g. to distinguish different kinds
4558 of signals or other objects by using name suffices) and to support them
4559 visually.
4560
4561 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4562 to support case-sensitive highlighting. However, keywords are then only
4563 highlighted if written in lower case.
4564
4565 Code between \"translate_off\" and \"translate_on\" pragmas is
4566 highlighted using a different background color if option
4567 `vhdl-highlight-translate-off' is non-nil.
4568
4569 For documentation and customization of the used colors see
4570 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4571 highlighting of matching parenthesis, see customization group
4572 `paren-showing'. Automatic buffer highlighting is turned on/off by
4573 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4574
4575
4576 USER MODELS:
4577 VHDL models (templates) can be specified by the user and made accessible
4578 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4579 electrification. See option `vhdl-model-alist'.
4580
4581
4582 HIDE/SHOW:
4583 The code of blocks, processes, subprograms, component declarations and
4584 instantiations, generic/port clauses, and configuration declarations can
4585 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4586 the code (see customization group `vhdl-menu'). XEmacs: limited
4587 functionality due to old `hideshow.el' package.
4588
4589
4590 CODE UPDATING:
4591 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4592 current process, `C-c C-u M-s' of all processes in the current buffer.
4593 Limitations:
4594 - Only declared local signals (ports, signals declared in
4595 architecture and blocks) are automatically inserted.
4596 - Global signals declared in packages are not automatically inserted.
4597 Insert them once manually (will be kept afterwards).
4598 - Out parameters of procedures are considered to be read.
4599 Use option `vhdl-entity-file-name' to specify the entity file name
4600 \(used to obtain the port names).
4601
4602
4603 CODE FIXING:
4604 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4605 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4606
4607
4608 PRINTING:
4609 Postscript printing with different faces (an optimized set of faces is
4610 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4611 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4612 postscript printing commands. Option `vhdl-print-two-column' defines
4613 appropriate default settings for nice landscape two-column printing.
4614 The paper format can be set by option `ps-paper-type'. Do not forget to
4615 switch `ps-print-color-p' to nil for printing on black-and-white
4616 printers.
4617
4618
4619 OPTIONS:
4620 User options allow customization of VHDL Mode. All options are
4621 accessible from the \"Options\" menu entry. Simple options (switches
4622 and choices) can directly be changed, while for complex options a
4623 customization buffer is opened. Changed options can be saved for future
4624 sessions using the \"Save Options\" menu entry.
4625
4626 Options and their detailed descriptions can also be accessed by using
4627 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4628 customize-group' for groups). Some customizations only take effect
4629 after some action (read the NOTE in the option documentation).
4630 Customization can also be done globally (i.e. site-wide, read the
4631 INSTALL file).
4632
4633 Not all options are described in this documentation, so go and see
4634 what other useful user options there are (`M-x vhdl-customize' or menu)!
4635
4636
4637 FILE EXTENSIONS:
4638 As default, files with extensions \".vhd\" and \".vhdl\" are
4639 automatically recognized as VHDL source files. To add an extension
4640 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4641
4642 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4643
4644
4645 HINTS:
4646 - To start Emacs with open VHDL hierarchy browser without having to load
4647 a VHDL file first, use the command:
4648
4649 emacs -l vhdl-mode -f speedbar-frame-mode
4650
4651 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4652
4653 - Some features only work on properly indented code.
4654
4655
4656 RELEASE NOTES:
4657 See also the release notes (menu) for added features in new releases.
4658
4659
4660 Maintenance:
4661 ------------
4662
4663 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4664 Add a description of the problem and include a reproducible test case.
4665
4666 Questions and enhancement requests can be sent to <reto@gnu.org>.
4667
4668 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4669 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4670 releases. You are kindly invited to participate in beta testing. Subscribe
4671 to above mailing lists by sending an email to <reto@gnu.org>.
4672
4673 VHDL Mode is officially distributed at
4674 http://opensource.ethz.ch/emacs/vhdl-mode.html
4675 where the latest version can be found.
4676
4677
4678 Known problems:
4679 ---------------
4680
4681 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4682 - XEmacs: Incorrect start-up when automatically opening speedbar.
4683 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4684
4685
4686 The VHDL Mode Authors
4687 Reto Zimmermann and Rod Whitby
4688
4689 Key bindings:
4690 -------------
4691
4692 \\{vhdl-mode-map}"
4693 (interactive)
4694 (kill-all-local-variables)
4695 (setq major-mode 'vhdl-mode)
4696 (setq mode-name "VHDL")
4697
4698 ;; set maps and tables
4699 (use-local-map vhdl-mode-map)
4700 (set-syntax-table vhdl-mode-syntax-table)
4701 (setq local-abbrev-table vhdl-mode-abbrev-table)
4702
4703 ;; set local variables
4704 (set (make-local-variable 'paragraph-start)
4705 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4706 (set (make-local-variable 'paragraph-separate) paragraph-start)
4707 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4708 (set (make-local-variable 'require-final-newline)
4709 (if vhdl-emacs-22 mode-require-final-newline t))
4710 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4711 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4712 (set (make-local-variable 'comment-start) "--")
4713 (set (make-local-variable 'comment-end) "")
4714 (when vhdl-emacs-21
4715 (set (make-local-variable 'comment-padding) ""))
4716 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4717 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4718 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4719 (set (make-local-variable 'comment-multi-line) nil)
4720 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4721 (set (make-local-variable 'hippie-expand-verbose) nil)
4722
4723 ;; setup the comment indent variable in a Emacs version portable way
4724 ;; ignore any byte compiler warnings you might get here
4725 (when (boundp 'comment-indent-function)
4726 (make-local-variable 'comment-indent-function)
4727 (setq comment-indent-function 'vhdl-comment-indent))
4728
4729 ;; initialize font locking
4730 (set (make-local-variable 'font-lock-defaults)
4731 (list
4732 '(nil vhdl-font-lock-keywords) nil
4733 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4734 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4735 (unless vhdl-emacs-21
4736 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4737 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4738 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4739 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4740 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4741 ; (turn-on-font-lock)
4742
4743 ;; variables for source file compilation
4744 (when vhdl-compile-use-local-error-regexp
4745 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4746 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4747
4748 ;; add index menu
4749 (vhdl-index-menu-init)
4750 ;; add source file menu
4751 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4752 ;; add VHDL menu
4753 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4754 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4755 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4756 ;; initialize hideshow and add menu
4757 (vhdl-hideshow-init)
4758 (run-hooks 'menu-bar-update-hook)
4759
4760 ;; miscellaneous
4761 (vhdl-ps-print-init)
4762 (vhdl-write-file-hooks-init)
4763 (vhdl-mode-line-update)
4764 (message "VHDL Mode %s.%s" vhdl-version
4765 (if noninteractive "" " See menu for documentation and release notes."))
4766
4767 ;; run hooks
4768 (if vhdl-emacs-22
4769 (run-mode-hooks 'vhdl-mode-hook)
4770 (run-hooks 'vhdl-mode-hook)))
4771
4772 (defun vhdl-activate-customizations ()
4773 "Activate all customizations on local variables."
4774 (interactive)
4775 (vhdl-mode-map-init)
4776 (use-local-map vhdl-mode-map)
4777 (set-syntax-table vhdl-mode-syntax-table)
4778 (setq comment-column vhdl-inline-comment-column)
4779 (setq end-comment-column vhdl-end-comment-column)
4780 (vhdl-write-file-hooks-init)
4781 (vhdl-update-mode-menu)
4782 (vhdl-hideshow-init)
4783 (run-hooks 'menu-bar-update-hook)
4784 (vhdl-mode-line-update))
4785
4786 (defun vhdl-write-file-hooks-init ()
4787 "Add/remove hooks when buffer is saved."
4788 (if vhdl-modify-date-on-saving
4789 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4790 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4791 (make-local-variable 'after-save-hook)
4792 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4793
4794 (defun vhdl-process-command-line-option (option)
4795 "Process command line options for VHDL Mode."
4796 (cond
4797 ;; set compiler
4798 ((equal option "-compiler")
4799 (vhdl-set-compiler (car command-line-args-left))
4800 (setq command-line-args-left (cdr command-line-args-left)))
4801 ;; set project
4802 ((equal option "-project")
4803 (vhdl-set-project (car command-line-args-left))
4804 (setq command-line-args-left (cdr command-line-args-left)))))
4805
4806 ;; make Emacs process VHDL Mode options
4807 (setq command-switch-alist
4808 (append command-switch-alist
4809 '(("-compiler" . vhdl-process-command-line-option)
4810 ("-project" . vhdl-process-command-line-option))))
4811
4812
4813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4814 ;;; Keywords and standardized words
4815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4816
4817 (defconst vhdl-93-keywords
4818 '(
4819 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4820 "assert" "attribute"
4821 "begin" "block" "body" "buffer" "bus"
4822 "case" "component" "configuration" "constant"
4823 "disconnect" "downto"
4824 "else" "elsif" "end" "entity" "exit"
4825 "file" "for" "function"
4826 "generate" "generic" "group" "guarded"
4827 "if" "impure" "in" "inertial" "inout" "is"
4828 "label" "library" "linkage" "literal" "loop"
4829 "map" "mod"
4830 "nand" "new" "next" "nor" "not" "null"
4831 "of" "on" "open" "or" "others" "out"
4832 "package" "port" "postponed" "procedure" "process" "pure"
4833 "range" "record" "register" "reject" "rem" "report" "return"
4834 "rol" "ror"
4835 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4836 "then" "to" "transport" "type"
4837 "unaffected" "units" "until" "use"
4838 "variable"
4839 "wait" "when" "while" "with"
4840 "xnor" "xor"
4841 )
4842 "List of VHDL'93 keywords.")
4843
4844 (defconst vhdl-ams-keywords
4845 '(
4846 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4847 "reference" "spectrum" "subnature" "terminal" "through"
4848 "tolerance"
4849 )
4850 "List of VHDL-AMS keywords.")
4851
4852 (defconst vhdl-verilog-keywords
4853 '(
4854 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4855 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4856 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4857 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4858 "endprimitive" "endspecify" "endtable" "endtask" "event"
4859 "for" "force" "forever" "fork" "function"
4860 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4861 "macromodule" "makefile" "medium" "module"
4862 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4863 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4864 "pullup"
4865 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4866 "rtranif0" "rtranif1"
4867 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4868 "strong1" "supply" "supply0" "supply1"
4869 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4870 "triand" "trior" "trireg"
4871 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4872 )
4873 "List of Verilog keywords as candidate for additional reserved words.")
4874
4875 (defconst vhdl-93-types
4876 '(
4877 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4878 "real" "time" "natural" "positive" "string" "line" "text" "side"
4879 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4880 "std_logic" "std_logic_vector"
4881 "std_ulogic" "std_ulogic_vector"
4882 )
4883 "List of VHDL'93 standardized types.")
4884
4885 (defconst vhdl-ams-types
4886 '(
4887 "domain_type" "real_vector"
4888 ;; from `nature_pkg' package
4889 "voltage" "current" "electrical" "position" "velocity" "force"
4890 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4891 "pressure" "flowrate" "fluid"
4892 )
4893 "List of VHDL-AMS standardized types.")
4894
4895 (defconst vhdl-math-types
4896 '(
4897 "complex" "complex_polar"
4898 )
4899 "List of Math Packages standardized types.")
4900
4901 (defconst vhdl-93-attributes
4902 '(
4903 "base" "left" "right" "high" "low" "pos" "val" "succ"
4904 "pred" "leftof" "rightof" "range" "reverse_range"
4905 "length" "delayed" "stable" "quiet" "transaction"
4906 "event" "active" "last_event" "last_active" "last_value"
4907 "driving" "driving_value" "ascending" "value" "image"
4908 "simple_name" "instance_name" "path_name"
4909 "foreign"
4910 )
4911 "List of VHDL'93 standardized attributes.")
4912
4913 (defconst vhdl-ams-attributes
4914 '(
4915 "across" "through"
4916 "reference" "contribution" "tolerance"
4917 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4918 "ramp" "slew"
4919 )
4920 "List of VHDL-AMS standardized attributes.")
4921
4922 (defconst vhdl-93-enum-values
4923 '(
4924 "true" "false"
4925 "note" "warning" "error" "failure"
4926 "read_mode" "write_mode" "append_mode"
4927 "open_ok" "status_error" "name_error" "mode_error"
4928 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4929 "right" "left"
4930 )
4931 "List of VHDL'93 standardized enumeration values.")
4932
4933 (defconst vhdl-ams-enum-values
4934 '(
4935 "quiescent_domain" "time_domain" "frequency_domain"
4936 ;; from `nature_pkg' package
4937 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4938 )
4939 "List of VHDL-AMS standardized enumeration values.")
4940
4941 (defconst vhdl-math-constants
4942 '(
4943 "math_e" "math_1_over_e"
4944 "math_pi" "math_two_pi" "math_1_over_pi"
4945 "math_half_pi" "math_q_pi" "math_3_half_pi"
4946 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4947 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4948 "math_deg_to_rad" "math_rad_to_deg"
4949 "cbase_1" "cbase_j" "czero"
4950 )
4951 "List of Math Packages standardized constants.")
4952
4953 (defconst vhdl-93-functions
4954 '(
4955 "now" "resolved" "rising_edge" "falling_edge"
4956 "read" "readline" "write" "writeline" "endfile"
4957 "resize" "is_X" "std_match"
4958 "shift_left" "shift_right" "rotate_left" "rotate_right"
4959 "to_unsigned" "to_signed" "to_integer"
4960 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4961 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4962 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4963 "shl" "shr" "ext" "sxt"
4964 "deallocate"
4965 )
4966 "List of VHDL'93 standardized functions.")
4967
4968 (defconst vhdl-ams-functions
4969 '(
4970 "frequency"
4971 )
4972 "List of VHDL-AMS standardized functions.")
4973
4974 (defconst vhdl-math-functions
4975 '(
4976 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4977 "sqrt" "cbrt" "exp" "log"
4978 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4979 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4980 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4981 )
4982 "List of Math Packages standardized functions.")
4983
4984 (defconst vhdl-93-packages
4985 '(
4986 "std_logic_1164" "numeric_std" "numeric_bit"
4987 "standard" "textio"
4988 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4989 "std_logic_misc" "std_logic_textio"
4990 "ieee" "std" "work"
4991 )
4992 "List of VHDL'93 standardized packages and libraries.")
4993
4994 (defconst vhdl-ams-packages
4995 '(
4996 ;; from `nature_pkg' package
4997 "nature_pkg"
4998 )
4999 "List of VHDL-AMS standardized packages and libraries.")
5000
5001 (defconst vhdl-math-packages
5002 '(
5003 "math_real" "math_complex"
5004 )
5005 "List of Math Packages standardized packages and libraries.")
5006
5007 (defvar vhdl-keywords nil
5008 "List of VHDL keywords.")
5009
5010 (defvar vhdl-types nil
5011 "List of VHDL standardized types.")
5012
5013 (defvar vhdl-attributes nil
5014 "List of VHDL standardized attributes.")
5015
5016 (defvar vhdl-enum-values nil
5017 "List of VHDL standardized enumeration values.")
5018
5019 (defvar vhdl-constants nil
5020 "List of VHDL standardized constants.")
5021
5022 (defvar vhdl-functions nil
5023 "List of VHDL standardized functions.")
5024
5025 (defvar vhdl-packages nil
5026 "List of VHDL standardized packages and libraries.")
5027
5028 (defvar vhdl-reserved-words nil
5029 "List of additional reserved words.")
5030
5031 (defvar vhdl-keywords-regexp nil
5032 "Regexp for VHDL keywords.")
5033
5034 (defvar vhdl-types-regexp nil
5035 "Regexp for VHDL standardized types.")
5036
5037 (defvar vhdl-attributes-regexp nil
5038 "Regexp for VHDL standardized attributes.")
5039
5040 (defvar vhdl-enum-values-regexp nil
5041 "Regexp for VHDL standardized enumeration values.")
5042
5043 (defvar vhdl-functions-regexp nil
5044 "Regexp for VHDL standardized functions.")
5045
5046 (defvar vhdl-packages-regexp nil
5047 "Regexp for VHDL standardized packages and libraries.")
5048
5049 (defvar vhdl-reserved-words-regexp nil
5050 "Regexp for additional reserved words.")
5051
5052 (defvar vhdl-directive-keywords-regexp nil
5053 "Regexp for compiler directive keywords.")
5054
5055 (defun vhdl-words-init ()
5056 "Initialize reserved words."
5057 (setq vhdl-keywords
5058 (append vhdl-93-keywords
5059 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5060 (setq vhdl-types
5061 (append vhdl-93-types
5062 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5063 (when (vhdl-standard-p 'math) vhdl-math-types)))
5064 (setq vhdl-attributes
5065 (append vhdl-93-attributes
5066 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5067 (setq vhdl-enum-values
5068 (append vhdl-93-enum-values
5069 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5070 (setq vhdl-constants
5071 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5072 (setq vhdl-functions
5073 (append vhdl-93-functions
5074 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5075 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5076 (setq vhdl-packages
5077 (append vhdl-93-packages
5078 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5079 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5080 (setq vhdl-reserved-words
5081 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5082 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5083 '("")))
5084 (setq vhdl-keywords-regexp
5085 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5086 (setq vhdl-types-regexp
5087 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5088 (setq vhdl-attributes-regexp
5089 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5090 (setq vhdl-enum-values-regexp
5091 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5092 (setq vhdl-functions-regexp
5093 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5094 (setq vhdl-packages-regexp
5095 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5096 (setq vhdl-reserved-words-regexp
5097 (concat "\\<\\("
5098 (unless (equal vhdl-forbidden-syntax "")
5099 (concat vhdl-forbidden-syntax "\\|"))
5100 (regexp-opt vhdl-reserved-words)
5101 "\\)\\>"))
5102 (setq vhdl-directive-keywords-regexp
5103 (concat "\\<\\(" (mapconcat 'regexp-quote
5104 vhdl-directive-keywords "\\|") "\\)\\>"))
5105 (vhdl-abbrev-list-init))
5106
5107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5108 ;; Words to expand
5109
5110 (defvar vhdl-abbrev-list nil
5111 "Predefined abbreviations for VHDL.")
5112
5113 (defun vhdl-abbrev-list-init ()
5114 (setq vhdl-abbrev-list
5115 (append
5116 (list vhdl-upper-case-keywords) vhdl-keywords
5117 (list vhdl-upper-case-types) vhdl-types
5118 (list vhdl-upper-case-attributes) vhdl-attributes
5119 (list vhdl-upper-case-enum-values) vhdl-enum-values
5120 (list vhdl-upper-case-constants) vhdl-constants
5121 (list nil) vhdl-functions
5122 (list nil) vhdl-packages)))
5123
5124 ;; initialize reserved words for VHDL Mode
5125 (vhdl-words-init)
5126
5127
5128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5129 ;;; Indentation
5130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5131
5132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5133 ;; Syntax analysis
5134
5135 ;; constant regular expressions for looking at various constructs
5136
5137 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5138 "Regexp describing a VHDL symbol.
5139 We cannot use just `word' syntax class since `_' cannot be in word
5140 class. Putting underscore in word class breaks forward word movement
5141 behavior that users are familiar with.")
5142
5143 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5144 "Regexp describing a case statement header key.")
5145
5146 (defconst vhdl-label-key
5147 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5148 "Regexp describing a VHDL label.")
5149
5150 ;; Macro definitions:
5151
5152 (defmacro vhdl-point (position)
5153 "Return the value of point at certain commonly referenced POSITIONs.
5154 POSITION can be one of the following symbols:
5155
5156 bol -- beginning of line
5157 eol -- end of line
5158 bod -- beginning of defun
5159 boi -- back to indentation
5160 eoi -- last whitespace on line
5161 ionl -- indentation of next line
5162 iopl -- indentation of previous line
5163 bonl -- beginning of next line
5164 bopl -- beginning of previous line
5165
5166 This function does not modify point or mark."
5167 (or (and (eq 'quote (car-safe position))
5168 (null (cddr position)))
5169 (error "ERROR: Bad buffer position requested: %s" position))
5170 (setq position (nth 1 position))
5171 `(let ((here (point)))
5172 ,@(cond
5173 ((eq position 'bol) '((beginning-of-line)))
5174 ((eq position 'eol) '((end-of-line)))
5175 ((eq position 'bod) '((save-match-data
5176 (vhdl-beginning-of-defun))))
5177 ((eq position 'boi) '((back-to-indentation)))
5178 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5179 ((eq position 'bonl) '((forward-line 1)))
5180 ((eq position 'bopl) '((forward-line -1)))
5181 ((eq position 'iopl)
5182 '((forward-line -1)
5183 (back-to-indentation)))
5184 ((eq position 'ionl)
5185 '((forward-line 1)
5186 (back-to-indentation)))
5187 (t (error "ERROR: Unknown buffer position requested: %s" position))
5188 )
5189 (prog1
5190 (point)
5191 (goto-char here))
5192 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5193 ;; doesn't hurt for v19
5194 ,@nil
5195 ))
5196
5197 (defmacro vhdl-safe (&rest body)
5198 "Safely execute BODY, return nil if an error occurred."
5199 `(condition-case nil
5200 (progn ,@body)
5201 (error nil)))
5202
5203 (defmacro vhdl-add-syntax (symbol &optional relpos)
5204 "A simple macro to append the syntax in SYMBOL to the syntax list.
5205 Try to increase performance by using this macro."
5206 `(setq vhdl-syntactic-context
5207 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5208
5209 (defmacro vhdl-has-syntax (symbol)
5210 "A simple macro to return check the syntax list.
5211 Try to increase performance by using this macro."
5212 `(assoc ,symbol vhdl-syntactic-context))
5213
5214 ;; Syntactic element offset manipulation:
5215
5216 (defun vhdl-read-offset (langelem)
5217 "Read new offset value for LANGELEM from minibuffer.
5218 Return a valid value only."
5219 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5220 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5221 (prompt "Offset: ")
5222 offset input interned)
5223 (while (not offset)
5224 (setq input (read-string prompt oldoff)
5225 offset (cond ((string-equal "+" input) '+)
5226 ((string-equal "-" input) '-)
5227 ((string-equal "++" input) '++)
5228 ((string-equal "--" input) '--)
5229 ((string-match "^-?[0-9]+$" input)
5230 (string-to-number input))
5231 ((fboundp (setq interned (intern input)))
5232 interned)
5233 ((boundp interned) interned)
5234 ;; error, but don't signal one, keep trying
5235 ;; to read an input value
5236 (t (ding)
5237 (setq prompt errmsg)
5238 nil))))
5239 offset))
5240
5241 (defun vhdl-set-offset (symbol offset &optional add-p)
5242 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5243 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5244 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5245 `vhdl-offsets-alist' if it doesn't already appear there."
5246 (interactive
5247 (let* ((langelem
5248 (intern (completing-read
5249 (concat "Syntactic symbol to change"
5250 (if current-prefix-arg " or add" "")
5251 ": ")
5252 (mapcar
5253 (function
5254 (lambda (langelem)
5255 (cons (format "%s" (car langelem)) nil)))
5256 vhdl-offsets-alist)
5257 nil (not current-prefix-arg)
5258 ;; initial contents tries to be the last element
5259 ;; on the syntactic analysis list for the current
5260 ;; line
5261 (let* ((syntax (vhdl-get-syntactic-context))
5262 (len (length syntax))
5263 (ic (format "%s" (car (nth (1- len) syntax)))))
5264 ic)
5265 )))
5266 (offset (vhdl-read-offset langelem)))
5267 (list langelem offset current-prefix-arg)))
5268 ;; sanity check offset
5269 (or (eq offset '+)
5270 (eq offset '-)
5271 (eq offset '++)
5272 (eq offset '--)
5273 (integerp offset)
5274 (fboundp offset)
5275 (boundp offset)
5276 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5277 offset))
5278 (let ((entry (assq symbol vhdl-offsets-alist)))
5279 (if entry
5280 (setcdr entry offset)
5281 (if add-p
5282 (setq vhdl-offsets-alist
5283 (cons (cons symbol offset) vhdl-offsets-alist))
5284 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5285 (vhdl-keep-region-active))
5286
5287 (defun vhdl-set-style (style &optional local)
5288 "Set `vhdl-mode' variables to use one of several different indentation styles.
5289 STYLE is a string representing the desired style and optional LOCAL is
5290 a flag which, if non-nil, means to make the style variables being
5291 changed buffer local, instead of the default, which is to set the
5292 global variables. Interactively, the flag comes from the prefix
5293 argument. The styles are chosen from the `vhdl-style-alist' variable."
5294 (interactive (list (completing-read "Use which VHDL indentation style? "
5295 vhdl-style-alist nil t)
5296 current-prefix-arg))
5297 (let ((vars (cdr (assoc style vhdl-style-alist))))
5298 (or vars
5299 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5300 ;; set all the variables
5301 (mapc
5302 (function
5303 (lambda (varentry)
5304 (let ((var (car varentry))
5305 (val (cdr varentry)))
5306 (and local
5307 (make-local-variable var))
5308 ;; special case for vhdl-offsets-alist
5309 (if (not (eq var 'vhdl-offsets-alist))
5310 (set var val)
5311 ;; reset vhdl-offsets-alist to the default value first
5312 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5313 ;; now set the langelems that are different
5314 (mapcar
5315 (function
5316 (lambda (langentry)
5317 (let ((langelem (car langentry))
5318 (offset (cdr langentry)))
5319 (vhdl-set-offset langelem offset)
5320 )))
5321 val))
5322 )))
5323 vars))
5324 (vhdl-keep-region-active))
5325
5326 (defun vhdl-get-offset (langelem)
5327 "Get offset from LANGELEM which is a cons cell of the form:
5328 \(SYMBOL . RELPOS). The symbol is matched against
5329 vhdl-offsets-alist and the offset found there is either returned,
5330 or added to the indentation at RELPOS. If RELPOS is nil, then
5331 the offset is simply returned."
5332 (let* ((symbol (car langelem))
5333 (relpos (cdr langelem))
5334 (match (assq symbol vhdl-offsets-alist))
5335 (offset (cdr-safe match)))
5336 ;; offset can be a number, a function, a variable, or one of the
5337 ;; symbols + or -
5338 (cond
5339 ((not match)
5340 (if vhdl-strict-syntax-p
5341 (error "ERROR: Don't know how to indent a %s" symbol)
5342 (setq offset 0
5343 relpos 0)))
5344 ((eq offset '+) (setq offset vhdl-basic-offset))
5345 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5346 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5347 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5348 ((and (not (numberp offset))
5349 (fboundp offset))
5350 (setq offset (funcall offset langelem)))
5351 ((not (numberp offset))
5352 (setq offset (eval offset)))
5353 )
5354 (+ (if (and relpos
5355 (< relpos (vhdl-point 'bol)))
5356 (save-excursion
5357 (goto-char relpos)
5358 (current-column))
5359 0)
5360 offset)))
5361
5362 ;; Syntactic support functions:
5363
5364 (defun vhdl-in-comment-p ()
5365 "Check if point is in a comment."
5366 (eq (vhdl-in-literal) 'comment))
5367
5368 (defun vhdl-in-string-p ()
5369 "Check if point is in a string."
5370 (eq (vhdl-in-literal) 'string))
5371
5372 (defun vhdl-in-literal ()
5373 "Determine if point is in a VHDL literal."
5374 (save-excursion
5375 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5376 (cond
5377 ((nth 3 state) 'string)
5378 ((nth 4 state) 'comment)
5379 ((vhdl-beginning-of-macro) 'pound)
5380 (t nil)))))
5381
5382 (defun vhdl-forward-comment (&optional direction)
5383 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5384 negative, skip forward otherwise."
5385 (interactive "p")
5386 (if (and direction (< direction 0))
5387 ;; skip backwards
5388 (progn
5389 (skip-chars-backward " \t\n")
5390 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5391 (goto-char (match-beginning 3))
5392 (skip-chars-backward " \t\n")))
5393 ;; skip forwards
5394 (skip-chars-forward " \t\n")
5395 (while (looking-at "--.*")
5396 (goto-char (match-end 0))
5397 (skip-chars-forward " \t\n"))))
5398
5399 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5400 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5401 (defalias 'vhdl-forward-comment 'forward-comment))
5402
5403 ;; This is the best we can do in Win-Emacs.
5404 (defun vhdl-win-il (&optional lim)
5405 "Determine if point is in a VHDL literal."
5406 (save-excursion
5407 (let* ((here (point))
5408 (state nil)
5409 (match nil)
5410 (lim (or lim (vhdl-point 'bod))))
5411 (goto-char lim )
5412 (while (< (point) here)
5413 (setq match
5414 (and (re-search-forward "--\\|[\"']"
5415 here 'move)
5416 (buffer-substring (match-beginning 0) (match-end 0))))
5417 (setq state
5418 (cond
5419 ;; no match
5420 ((null match) nil)
5421 ;; looking at the opening of a VHDL style comment
5422 ((string= "--" match)
5423 (if (<= here (progn (end-of-line) (point))) 'comment))
5424 ;; looking at the opening of a double quote string
5425 ((string= "\"" match)
5426 (if (not (save-restriction
5427 ;; this seems to be necessary since the
5428 ;; re-search-forward will not work without it
5429 (narrow-to-region (point) here)
5430 (re-search-forward
5431 ;; this regexp matches a double quote
5432 ;; which is preceded by an even number
5433 ;; of backslashes, including zero
5434 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5435 'string))
5436 ;; looking at the opening of a single quote string
5437 ((string= "'" match)
5438 (if (not (save-restriction
5439 ;; see comments from above
5440 (narrow-to-region (point) here)
5441 (re-search-forward
5442 ;; this matches a single quote which is
5443 ;; preceded by zero or two backslashes.
5444 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5445 here 'move)))
5446 'string))
5447 (t nil)))
5448 ) ; end-while
5449 state)))
5450
5451 (and (string-match "Win-Emacs" emacs-version)
5452 (fset 'vhdl-in-literal 'vhdl-win-il))
5453
5454 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5455 ;; defined as lexical whitespace or comments. Search no farther back
5456 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5457 ;; used for backward skipping, (point-max) is used for forward
5458 ;; skipping.
5459
5460 (defun vhdl-forward-syntactic-ws (&optional lim)
5461 "Forward skip of syntactic whitespace."
5462 (let* ((here (point-max))
5463 (hugenum (point-max)))
5464 (while (/= here (point))
5465 (setq here (point))
5466 (vhdl-forward-comment hugenum)
5467 ;; skip preprocessor directives
5468 (when (and (eq (char-after) ?#)
5469 (= (vhdl-point 'boi) (point)))
5470 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5471 (= (forward-line 1) 0)))
5472 (end-of-line)))
5473 (if lim (goto-char (min (point) lim)))))
5474
5475
5476 ;; This is the best we can do in Win-Emacs.
5477 (defun vhdl-win-fsws (&optional lim)
5478 "Forward skip syntactic whitespace for Win-Emacs."
5479 (let ((lim (or lim (point-max)))
5480 stop)
5481 (while (not stop)
5482 (skip-chars-forward " \t\n\r\f" lim)
5483 (cond
5484 ;; vhdl comment
5485 ((looking-at "--") (end-of-line))
5486 ;; none of the above
5487 (t (setq stop t))))))
5488
5489 (and (string-match "Win-Emacs" emacs-version)
5490 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5491
5492 (defun vhdl-beginning-of-macro (&optional lim)
5493 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5494 (let ((here (point)))
5495 (beginning-of-line)
5496 (while (eq (char-before (1- (point))) ?\\)
5497 (forward-line -1))
5498 (back-to-indentation)
5499 (if (and (<= (point) here)
5500 (eq (char-after) ?#))
5501 t
5502 (goto-char here)
5503 nil)))
5504
5505 (defun vhdl-backward-syntactic-ws (&optional lim)
5506 "Backward skip over syntactic whitespace."
5507 (let* ((here (point-min))
5508 (hugenum (- (point-max))))
5509 (while (/= here (point))
5510 (setq here (point))
5511 (vhdl-forward-comment hugenum)
5512 (vhdl-beginning-of-macro))
5513 (if lim (goto-char (max (point) lim)))))
5514
5515 ;; This is the best we can do in Win-Emacs.
5516 (defun vhdl-win-bsws (&optional lim)
5517 "Backward skip syntactic whitespace for Win-Emacs."
5518 (let ((lim (or lim (vhdl-point 'bod)))
5519 stop)
5520 (while (not stop)
5521 (skip-chars-backward " \t\n\r\f" lim)
5522 (cond
5523 ;; vhdl comment
5524 ((eq (vhdl-in-literal) 'comment)
5525 (skip-chars-backward "^-" lim)
5526 (skip-chars-backward "-" lim)
5527 (while (not (or (and (= (following-char) ?-)
5528 (= (char-after (1+ (point))) ?-))
5529 (<= (point) lim)))
5530 (skip-chars-backward "^-" lim)
5531 (skip-chars-backward "-" lim)))
5532 ;; none of the above
5533 (t (setq stop t))))))
5534
5535 (and (string-match "Win-Emacs" emacs-version)
5536 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5537
5538 ;; Functions to help finding the correct indentation column:
5539
5540 (defun vhdl-first-word (point)
5541 "If the keyword at POINT is at boi, then return (current-column) at
5542 that point, else nil."
5543 (save-excursion
5544 (and (goto-char point)
5545 (eq (point) (vhdl-point 'boi))
5546 (current-column))))
5547
5548 (defun vhdl-last-word (point)
5549 "If the keyword at POINT is at eoi, then return (current-column) at
5550 that point, else nil."
5551 (save-excursion
5552 (and (goto-char point)
5553 (save-excursion (or (eq (progn (forward-sexp) (point))
5554 (vhdl-point 'eoi))
5555 (looking-at "\\s-*\\(--\\)?")))
5556 (current-column))))
5557
5558 ;; Core syntactic evaluation functions:
5559
5560 (defconst vhdl-libunit-re
5561 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5562
5563 (defun vhdl-libunit-p ()
5564 (and
5565 (save-excursion
5566 (forward-sexp)
5567 (skip-chars-forward " \t\n")
5568 (not (looking-at "is\\b[^_]")))
5569 (save-excursion
5570 (backward-sexp)
5571 (and (not (looking-at "use\\b[^_]"))
5572 (progn
5573 (forward-sexp)
5574 (vhdl-forward-syntactic-ws)
5575 (/= (following-char) ?:))))
5576 ))
5577
5578 (defconst vhdl-defun-re
5579 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5580
5581 (defun vhdl-defun-p ()
5582 (save-excursion
5583 (if (looking-at "block\\|process\\|procedural")
5584 ;; "block", "process", "procedural":
5585 (save-excursion
5586 (backward-sexp)
5587 (not (looking-at "end\\s-+\\w")))
5588 ;; "architecture", "configuration", "entity",
5589 ;; "package", "procedure", "function":
5590 t)))
5591
5592 (defun vhdl-corresponding-defun ()
5593 "If the word at the current position corresponds to a \"defun\"
5594 keyword, then return a string that can be used to find the
5595 corresponding \"begin\" keyword, else return nil."
5596 (save-excursion
5597 (and (looking-at vhdl-defun-re)
5598 (vhdl-defun-p)
5599 (if (looking-at "block\\|process\\|procedural")
5600 ;; "block", "process". "procedural:
5601 (buffer-substring (match-beginning 0) (match-end 0))
5602 ;; "architecture", "configuration", "entity", "package",
5603 ;; "procedure", "function":
5604 "is"))))
5605
5606 (defconst vhdl-begin-fwd-re
5607 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5608 "A regular expression for searching forward that matches all known
5609 \"begin\" keywords.")
5610
5611 (defconst vhdl-begin-bwd-re
5612 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5613 "A regular expression for searching backward that matches all known
5614 \"begin\" keywords.")
5615
5616 (defun vhdl-begin-p (&optional lim)
5617 "Return t if we are looking at a real \"begin\" keyword.
5618 Assumes that the caller will make sure that we are looking at
5619 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5620 the middle of an identifier that just happens to contain a \"begin\"
5621 keyword."
5622 (cond
5623 ;; "[architecture|case|configuration|entity|package|
5624 ;; procedure|function] ... is":
5625 ((and (looking-at "i")
5626 (save-excursion
5627 ;; Skip backward over first sexp (needed to skip over a
5628 ;; procedure interface list, and is harmless in other
5629 ;; situations). Note that we need "return" in the
5630 ;; following search list so that we don't run into
5631 ;; semicolons in the function interface list.
5632 (backward-sexp)
5633 (let (foundp)
5634 (while (and (not foundp)
5635 (re-search-backward
5636 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5637 lim 'move))
5638 (if (or (= (preceding-char) ?_)
5639 (vhdl-in-literal))
5640 (backward-char)
5641 (setq foundp t))))
5642 (and (/= (following-char) ?\;)
5643 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5644 t)
5645 ;; "begin", "then":
5646 ((looking-at "be\\|t")
5647 t)
5648 ;; "else":
5649 ((and (looking-at "e")
5650 ;; make sure that the "else" isn't inside a
5651 ;; conditional signal assignment.
5652 (save-excursion
5653 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5654 (or (eq (following-char) ?\;)
5655 (eq (point) lim))))
5656 t)
5657 ;; "block", "generate", "loop", "process", "procedural",
5658 ;; "units", "record":
5659 ((and (looking-at "bl\\|[glpur]")
5660 (save-excursion
5661 (backward-sexp)
5662 (not (looking-at "end\\s-+\\w"))))
5663 t)
5664 ;; "component":
5665 ((and (looking-at "c")
5666 (save-excursion
5667 (backward-sexp)
5668 (not (looking-at "end\\s-+\\w")))
5669 ;; look out for the dreaded entity class in an attribute
5670 (save-excursion
5671 (vhdl-backward-syntactic-ws lim)
5672 (/= (preceding-char) ?:)))
5673 t)
5674 ;; "for" (inside configuration declaration):
5675 ((and (looking-at "f")
5676 (save-excursion
5677 (backward-sexp)
5678 (not (looking-at "end\\s-+\\w")))
5679 (vhdl-has-syntax 'configuration))
5680 t)
5681 ))
5682
5683 (defun vhdl-corresponding-mid (&optional lim)
5684 (cond
5685 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5686 "begin")
5687 ((looking-at "then")
5688 "<else>")
5689 (t
5690 "end")))
5691
5692 (defun vhdl-corresponding-end (&optional lim)
5693 "If the word at the current position corresponds to a \"begin\"
5694 keyword, then return a vector containing enough information to find
5695 the corresponding \"end\" keyword, else return nil. The keyword to
5696 search forward for is aref 0. The column in which the keyword must
5697 appear is aref 1 or nil if any column is suitable.
5698 Assumes that the caller will make sure that we are not in the middle
5699 of an identifier that just happens to contain a \"begin\" keyword."
5700 (save-excursion
5701 (and (looking-at vhdl-begin-fwd-re)
5702 (/= (preceding-char) ?_)
5703 (not (vhdl-in-literal))
5704 (vhdl-begin-p lim)
5705 (cond
5706 ;; "is", "generate", "loop":
5707 ((looking-at "[igl]")
5708 (vector "end"
5709 (and (vhdl-last-word (point))
5710 (or (vhdl-first-word (point))
5711 (save-excursion
5712 (vhdl-beginning-of-statement-1 lim)
5713 (vhdl-backward-skip-label lim)
5714 (vhdl-first-word (point)))))))
5715 ;; "begin", "else", "for":
5716 ((looking-at "be\\|[ef]")
5717 (vector "end"
5718 (and (vhdl-last-word (point))
5719 (or (vhdl-first-word (point))
5720 (save-excursion
5721 (vhdl-beginning-of-statement-1 lim)
5722 (vhdl-backward-skip-label lim)
5723 (vhdl-first-word (point)))))))
5724 ;; "component", "units", "record":
5725 ((looking-at "[cur]")
5726 ;; The first end found will close the block
5727 (vector "end" nil))
5728 ;; "block", "process", "procedural":
5729 ((looking-at "bl\\|p")
5730 (vector "end"
5731 (or (vhdl-first-word (point))
5732 (save-excursion
5733 (vhdl-beginning-of-statement-1 lim)
5734 (vhdl-backward-skip-label lim)
5735 (vhdl-first-word (point))))))
5736 ;; "then":
5737 ((looking-at "t")
5738 (vector "elsif\\|else\\|end\\s-+if"
5739 (and (vhdl-last-word (point))
5740 (or (vhdl-first-word (point))
5741 (save-excursion
5742 (vhdl-beginning-of-statement-1 lim)
5743 (vhdl-backward-skip-label lim)
5744 (vhdl-first-word (point)))))))
5745 ))))
5746
5747 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5748
5749 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5750
5751 (defun vhdl-end-p (&optional lim)
5752 "Return t if we are looking at a real \"end\" keyword.
5753 Assumes that the caller will make sure that we are looking at
5754 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5755 the middle of an identifier that just happens to contain an \"end\"
5756 keyword."
5757 (or (not (looking-at "else"))
5758 ;; make sure that the "else" isn't inside a conditional signal
5759 ;; assignment.
5760 (save-excursion
5761 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5762 (or (eq (following-char) ?\;)
5763 (eq (point) lim)
5764 (vhdl-in-literal)))))
5765
5766 (defun vhdl-corresponding-begin (&optional lim)
5767 "If the word at the current position corresponds to an \"end\"
5768 keyword, then return a vector containing enough information to find
5769 the corresponding \"begin\" keyword, else return nil. The keyword to
5770 search backward for is aref 0. The column in which the keyword must
5771 appear is aref 1 or nil if any column is suitable. The supplementary
5772 keyword to search forward for is aref 2 or nil if this is not
5773 required. If aref 3 is t, then the \"begin\" keyword may be found in
5774 the middle of a statement.
5775 Assumes that the caller will make sure that we are not in the middle
5776 of an identifier that just happens to contain an \"end\" keyword."
5777 (save-excursion
5778 (let (pos)
5779 (if (and (looking-at vhdl-end-fwd-re)
5780 (not (vhdl-in-literal))
5781 (vhdl-end-p lim))
5782 (if (looking-at "el")
5783 ;; "else", "elsif":
5784 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5785 ;; "end ...":
5786 (setq pos (point))
5787 (forward-sexp)
5788 (skip-chars-forward " \t\n")
5789 (cond
5790 ;; "end if":
5791 ((looking-at "if\\b[^_]")
5792 (vector "else\\|elsif\\|if"
5793 (vhdl-first-word pos)
5794 "else\\|then" nil))
5795 ;; "end component":
5796 ((looking-at "component\\b[^_]")
5797 (vector (buffer-substring (match-beginning 1)
5798 (match-end 1))
5799 (vhdl-first-word pos)
5800 nil nil))
5801 ;; "end units", "end record":
5802 ((looking-at "\\(units\\|record\\)\\b[^_]")
5803 (vector (buffer-substring (match-beginning 1)
5804 (match-end 1))
5805 (vhdl-first-word pos)
5806 nil t))
5807 ;; "end block", "end process", "end procedural":
5808 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5809 (vector "begin" (vhdl-first-word pos) nil nil))
5810 ;; "end case":
5811 ((looking-at "case\\b[^_]")
5812 (vector "case" (vhdl-first-word pos) "is" nil))
5813 ;; "end generate":
5814 ((looking-at "generate\\b[^_]")
5815 (vector "generate\\|for\\|if"
5816 (vhdl-first-word pos)
5817 "generate" nil))
5818 ;; "end loop":
5819 ((looking-at "loop\\b[^_]")
5820 (vector "loop\\|while\\|for"
5821 (vhdl-first-word pos)
5822 "loop" nil))
5823 ;; "end for" (inside configuration declaration):
5824 ((looking-at "for\\b[^_]")
5825 (vector "for" (vhdl-first-word pos) nil nil))
5826 ;; "end [id]":
5827 (t
5828 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5829 (vhdl-first-word pos)
5830 ;; return an alist of (statement . keyword) mappings
5831 '(
5832 ;; "begin ... end [id]":
5833 ("begin" . nil)
5834 ;; "architecture ... is ... begin ... end [id]":
5835 ("architecture" . "is")
5836 ;; "configuration ... is ... end [id]":
5837 ("configuration" . "is")
5838 ;; "entity ... is ... end [id]":
5839 ("entity" . "is")
5840 ;; "package ... is ... end [id]":
5841 ("package" . "is")
5842 ;; "procedure ... is ... begin ... end [id]":
5843 ("procedure" . "is")
5844 ;; "function ... is ... begin ... end [id]":
5845 ("function" . "is")
5846 )
5847 nil))
5848 ))) ; "end ..."
5849 )))
5850
5851 (defconst vhdl-leader-re
5852 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5853
5854 (defun vhdl-end-of-leader ()
5855 (save-excursion
5856 (cond ((looking-at "block\\|process\\|procedural")
5857 (if (save-excursion
5858 (forward-sexp)
5859 (skip-chars-forward " \t\n")
5860 (= (following-char) ?\())
5861 (forward-sexp 2)
5862 (forward-sexp))
5863 (when (looking-at "[ \t\n]*is")
5864 (goto-char (match-end 0)))
5865 (point))
5866 ((looking-at "component")
5867 (forward-sexp 2)
5868 (when (looking-at "[ \t\n]*is")
5869 (goto-char (match-end 0)))
5870 (point))
5871 ((looking-at "for")
5872 (forward-sexp 2)
5873 (skip-chars-forward " \t\n")
5874 (while (looking-at "[,:(]")
5875 (forward-sexp)
5876 (skip-chars-forward " \t\n"))
5877 (point))
5878 (t nil)
5879 )))
5880
5881 (defconst vhdl-trailer-re
5882 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5883
5884 (defconst vhdl-statement-fwd-re
5885 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5886 "A regular expression for searching forward that matches all known
5887 \"statement\" keywords.")
5888
5889 (defconst vhdl-statement-bwd-re
5890 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5891 "A regular expression for searching backward that matches all known
5892 \"statement\" keywords.")
5893
5894 (defun vhdl-statement-p (&optional lim)
5895 "Return t if we are looking at a real \"statement\" keyword.
5896 Assumes that the caller will make sure that we are looking at
5897 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5898 in the middle of an identifier that just happens to contain a
5899 \"statement\" keyword."
5900 (cond
5901 ;; "for" ... "generate":
5902 ((and (looking-at "f")
5903 ;; Make sure it's the start of a parameter specification.
5904 (save-excursion
5905 (forward-sexp 2)
5906 (skip-chars-forward " \t\n")
5907 (looking-at "in\\b[^_]"))
5908 ;; Make sure it's not an "end for".
5909 (save-excursion
5910 (backward-sexp)
5911 (not (looking-at "end\\s-+\\w"))))
5912 t)
5913 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5914 ((and (looking-at "i")
5915 ;; Make sure it's not an "end if".
5916 (save-excursion
5917 (backward-sexp)
5918 (not (looking-at "end\\s-+\\w"))))
5919 t)
5920 ;; "while" ... "loop":
5921 ((looking-at "w")
5922 t)
5923 ))
5924
5925 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5926 "Regexp describing a case statement alternative key.")
5927
5928 (defun vhdl-case-alternative-p (&optional lim)
5929 "Return t if we are looking at a real case alternative.
5930 Assumes that the caller will make sure that we are looking at
5931 vhdl-case-alternative-re, and are not inside a literal, and that
5932 we are not in the middle of an identifier that just happens to
5933 contain a \"when\" keyword."
5934 (save-excursion
5935 (let (foundp)
5936 (while (and (not foundp)
5937 (re-search-backward ";\\|<=" lim 'move))
5938 (if (or (= (preceding-char) ?_)
5939 (vhdl-in-literal))
5940 (backward-char)
5941 (setq foundp t)))
5942 (or (eq (following-char) ?\;)
5943 (eq (point) lim)))
5944 ))
5945
5946 ;; Core syntactic movement functions:
5947
5948 (defconst vhdl-b-t-b-re
5949 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5950
5951 (defun vhdl-backward-to-block (&optional lim)
5952 "Move backward to the previous \"begin\" or \"end\" keyword."
5953 (let (foundp)
5954 (while (and (not foundp)
5955 (re-search-backward vhdl-b-t-b-re lim 'move))
5956 (if (or (= (preceding-char) ?_)
5957 (vhdl-in-literal))
5958 (backward-char)
5959 (cond
5960 ;; "begin" keyword:
5961 ((and (looking-at vhdl-begin-fwd-re)
5962 (/= (preceding-char) ?_)
5963 (vhdl-begin-p lim))
5964 (setq foundp 'begin))
5965 ;; "end" keyword:
5966 ((and (looking-at vhdl-end-fwd-re)
5967 (/= (preceding-char) ?_)
5968 (vhdl-end-p lim))
5969 (setq foundp 'end))
5970 ))
5971 )
5972 foundp
5973 ))
5974
5975 (defun vhdl-forward-sexp (&optional count lim)
5976 "Move forward across one balanced expression (sexp).
5977 With COUNT, do it that many times."
5978 (interactive "p")
5979 (let ((count (or count 1))
5980 (case-fold-search t)
5981 end-vec target)
5982 (save-excursion
5983 (while (> count 0)
5984 ;; skip whitespace
5985 (skip-chars-forward " \t\n")
5986 ;; Check for an unbalanced "end" keyword
5987 (if (and (looking-at vhdl-end-fwd-re)
5988 (/= (preceding-char) ?_)
5989 (not (vhdl-in-literal))
5990 (vhdl-end-p lim)
5991 (not (looking-at "else")))
5992 (error
5993 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5994 ;; If the current keyword is a "begin" keyword, then find the
5995 ;; corresponding "end" keyword.
5996 (if (setq end-vec (vhdl-corresponding-end lim))
5997 (let (
5998 ;; end-re is the statement keyword to search for
5999 (end-re
6000 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6001 ;; column is either the statement keyword target column
6002 ;; or nil
6003 (column (aref end-vec 1))
6004 (eol (vhdl-point 'eol))
6005 foundp literal placeholder)
6006 ;; Look for the statement keyword.
6007 (while (and (not foundp)
6008 (re-search-forward end-re nil t)
6009 (setq placeholder (match-end 1))
6010 (goto-char (match-beginning 0)))
6011 ;; If we are in a literal, or not in the right target
6012 ;; column and not on the same line as the begin, then
6013 ;; try again.
6014 (if (or (and column
6015 (/= (current-indentation) column)
6016 (> (point) eol))
6017 (= (preceding-char) ?_)
6018 (setq literal (vhdl-in-literal)))
6019 (if (eq literal 'comment)
6020 (end-of-line)
6021 (forward-char))
6022 ;; An "else" keyword corresponds to both the opening brace
6023 ;; of the following sexp and the closing brace of the
6024 ;; previous sexp.
6025 (if (not (looking-at "else"))
6026 (goto-char placeholder))
6027 (setq foundp t))
6028 )
6029 (if (not foundp)
6030 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6031 )
6032 ;; If the current keyword is not a "begin" keyword, then just
6033 ;; perform the normal forward-sexp.
6034 (forward-sexp)
6035 )
6036 (setq count (1- count))
6037 )
6038 (setq target (point)))
6039 (goto-char target)
6040 nil))
6041
6042 (defun vhdl-backward-sexp (&optional count lim)
6043 "Move backward across one balanced expression (sexp).
6044 With COUNT, do it that many times. LIM bounds any required backward
6045 searches."
6046 (interactive "p")
6047 (let ((count (or count 1))
6048 (case-fold-search t)
6049 begin-vec target)
6050 (save-excursion
6051 (while (> count 0)
6052 ;; Perform the normal backward-sexp, unless we are looking at
6053 ;; "else" - an "else" keyword corresponds to both the opening brace
6054 ;; of the following sexp and the closing brace of the previous sexp.
6055 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6056 (/= (preceding-char) ?_)
6057 (not (vhdl-in-literal)))
6058 nil
6059 (backward-sexp)
6060 (if (and (looking-at vhdl-begin-fwd-re)
6061 (/= (preceding-char) ?_)
6062 (not (vhdl-in-literal))
6063 (vhdl-begin-p lim))
6064 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6065 ;; If the current keyword is an "end" keyword, then find the
6066 ;; corresponding "begin" keyword.
6067 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6068 (/= (preceding-char) ?_))
6069 (let (
6070 ;; begin-re is the statement keyword to search for
6071 (begin-re
6072 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6073 ;; column is either the statement keyword target column
6074 ;; or nil
6075 (column (aref begin-vec 1))
6076 ;; internal-p controls where the statement keyword can
6077 ;; be found.
6078 (internal-p (aref begin-vec 3))
6079 (last-backward (point)) last-forward
6080 foundp literal keyword)
6081 ;; Look for the statement keyword.
6082 (while (and (not foundp)
6083 (re-search-backward begin-re lim t)
6084 (setq keyword
6085 (buffer-substring (match-beginning 1)
6086 (match-end 1))))
6087 ;; If we are in a literal or in the wrong column,
6088 ;; then try again.
6089 (if (or (and column
6090 (and (/= (current-indentation) column)
6091 ;; possibly accept current-column as
6092 ;; well as current-indentation.
6093 (or (not internal-p)
6094 (/= (current-column) column))))
6095 (= (preceding-char) ?_)
6096 (vhdl-in-literal))
6097 (backward-char)
6098 ;; If there is a supplementary keyword, then
6099 ;; search forward for it.
6100 (if (and (setq begin-re (aref begin-vec 2))
6101 (or (not (listp begin-re))
6102 ;; If begin-re is an alist, then find the
6103 ;; element corresponding to the actual
6104 ;; keyword that we found.
6105 (progn
6106 (setq begin-re
6107 (assoc keyword begin-re))
6108 (and begin-re
6109 (setq begin-re (cdr begin-re))))))
6110 (and
6111 (setq begin-re
6112 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6113 (save-excursion
6114 (setq last-forward (point))
6115 ;; Look for the supplementary keyword
6116 ;; (bounded by the backward search start
6117 ;; point).
6118 (while (and (not foundp)
6119 (re-search-forward begin-re
6120 last-backward t)
6121 (goto-char (match-beginning 1)))
6122 ;; If we are in a literal, then try again.
6123 (if (or (= (preceding-char) ?_)
6124 (setq literal
6125 (vhdl-in-literal)))
6126 (if (eq literal 'comment)
6127 (goto-char
6128 (min (vhdl-point 'eol) last-backward))
6129 (forward-char))
6130 ;; We have found the supplementary keyword.
6131 ;; Save the position of the keyword in foundp.
6132 (setq foundp (point)))
6133 )
6134 foundp)
6135 ;; If the supplementary keyword was found, then
6136 ;; move point to the supplementary keyword.
6137 (goto-char foundp))
6138 ;; If there was no supplementary keyword, then
6139 ;; point is already at the statement keyword.
6140 (setq foundp t)))
6141 ) ; end of the search for the statement keyword
6142 (if (not foundp)
6143 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6144 ))
6145 (setq count (1- count))
6146 )
6147 (setq target (point)))
6148 (goto-char target)
6149 nil))
6150
6151 (defun vhdl-backward-up-list (&optional count limit)
6152 "Move backward out of one level of blocks.
6153 With argument, do this that many times."
6154 (interactive "p")
6155 (let ((count (or count 1))
6156 target)
6157 (save-excursion
6158 (while (> count 0)
6159 (if (looking-at vhdl-defun-re)
6160 (error "ERROR: Unbalanced blocks"))
6161 (vhdl-backward-to-block limit)
6162 (setq count (1- count)))
6163 (setq target (point)))
6164 (goto-char target)))
6165
6166 (defun vhdl-end-of-defun (&optional count)
6167 "Move forward to the end of a VHDL defun."
6168 (interactive)
6169 (let ((case-fold-search t))
6170 (vhdl-beginning-of-defun)
6171 (if (not (looking-at "block\\|process\\|procedural"))
6172 (re-search-forward "\\bis\\b"))
6173 (vhdl-forward-sexp)))
6174
6175 (defun vhdl-mark-defun ()
6176 "Put mark at end of this \"defun\", point at beginning."
6177 (interactive)
6178 (let ((case-fold-search t))
6179 (push-mark)
6180 (vhdl-beginning-of-defun)
6181 (push-mark)
6182 (if (not (looking-at "block\\|process\\|procedural"))
6183 (re-search-forward "\\bis\\b"))
6184 (vhdl-forward-sexp)
6185 (exchange-point-and-mark)))
6186
6187 (defun vhdl-beginning-of-libunit ()
6188 "Move backward to the beginning of a VHDL library unit.
6189 Returns the location of the corresponding begin keyword, unless search
6190 stops due to beginning or end of buffer.
6191 Note that if point is between the \"libunit\" keyword and the
6192 corresponding \"begin\" keyword, then that libunit will not be
6193 recognized, and the search will continue backwards. If point is
6194 at the \"begin\" keyword, then the defun will be recognized. The
6195 returned point is at the first character of the \"libunit\" keyword."
6196 (let ((last-forward (point))
6197 (last-backward
6198 ;; Just in case we are actually sitting on the "begin"
6199 ;; keyword, allow for the keyword and an extra character,
6200 ;; as this will be used when looking forward for the
6201 ;; "begin" keyword.
6202 (save-excursion (forward-word 1) (1+ (point))))
6203 foundp literal placeholder)
6204 ;; Find the "libunit" keyword.
6205 (while (and (not foundp)
6206 (re-search-backward vhdl-libunit-re nil 'move))
6207 ;; If we are in a literal, or not at a real libunit, then try again.
6208 (if (or (= (preceding-char) ?_)
6209 (vhdl-in-literal)
6210 (not (vhdl-libunit-p)))
6211 (backward-char)
6212 ;; Find the corresponding "begin" keyword.
6213 (setq last-forward (point))
6214 (while (and (not foundp)
6215 (re-search-forward "\\bis\\b[^_]" last-backward t)
6216 (setq placeholder (match-beginning 0)))
6217 (if (or (= (preceding-char) ?_)
6218 (setq literal (vhdl-in-literal)))
6219 ;; It wasn't a real keyword, so keep searching.
6220 (if (eq literal 'comment)
6221 (goto-char
6222 (min (vhdl-point 'eol) last-backward))
6223 (forward-char))
6224 ;; We have found the begin keyword, loop will exit.
6225 (setq foundp placeholder)))
6226 ;; Go back to the libunit keyword
6227 (goto-char last-forward)))
6228 foundp))
6229
6230 (defun vhdl-beginning-of-defun (&optional count)
6231 "Move backward to the beginning of a VHDL defun.
6232 With argument, do it that many times.
6233 Returns the location of the corresponding begin keyword, unless search
6234 stops due to beginning or end of buffer."
6235 ;; Note that if point is between the "defun" keyword and the
6236 ;; corresponding "begin" keyword, then that defun will not be
6237 ;; recognized, and the search will continue backwards. If point is
6238 ;; at the "begin" keyword, then the defun will be recognized. The
6239 ;; returned point is at the first character of the "defun" keyword.
6240 (interactive "p")
6241 (let ((count (or count 1))
6242 (case-fold-search t)
6243 (last-forward (point))
6244 foundp)
6245 (while (> count 0)
6246 (setq foundp nil)
6247 (goto-char last-forward)
6248 (let ((last-backward
6249 ;; Just in case we are actually sitting on the "begin"
6250 ;; keyword, allow for the keyword and an extra character,
6251 ;; as this will be used when looking forward for the
6252 ;; "begin" keyword.
6253 (save-excursion (forward-word 1) (1+ (point))))
6254 begin-string literal)
6255 (while (and (not foundp)
6256 (re-search-backward vhdl-defun-re nil 'move))
6257 ;; If we are in a literal, then try again.
6258 (if (or (= (preceding-char) ?_)
6259 (vhdl-in-literal))
6260 (backward-char)
6261 (if (setq begin-string (vhdl-corresponding-defun))
6262 ;; This is a real defun keyword.
6263 ;; Find the corresponding "begin" keyword.
6264 ;; Look for the begin keyword.
6265 (progn
6266 ;; Save the search start point.
6267 (setq last-forward (point))
6268 (while (and (not foundp)
6269 (search-forward begin-string last-backward t))
6270 (if (or (= (preceding-char) ?_)
6271 (save-match-data
6272 (setq literal (vhdl-in-literal))))
6273 ;; It wasn't a real keyword, so keep searching.
6274 (if (eq literal 'comment)
6275 (goto-char
6276 (min (vhdl-point 'eol) last-backward))
6277 (forward-char))
6278 ;; We have found the begin keyword, loop will exit.
6279 (setq foundp (match-beginning 0)))
6280 )
6281 ;; Go back to the defun keyword
6282 (goto-char last-forward)) ; end search for begin keyword
6283 ))
6284 ) ; end of the search for the defun keyword
6285 )
6286 (setq count (1- count))
6287 )
6288 (vhdl-keep-region-active)
6289 foundp))
6290
6291 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6292 "Go to the beginning of the innermost VHDL statement.
6293 With prefix arg, go back N - 1 statements. If already at the
6294 beginning of a statement then go to the beginning of the preceding
6295 one. If within a string or comment, or next to a comment (only
6296 whitespace between), move by sentences instead of statements.
6297
6298 When called from a program, this function takes 3 optional args: the
6299 prefix arg, a buffer position limit which is the farthest back to
6300 search, and an argument indicating an interactive call."
6301 (interactive "p\np")
6302 (let ((count (or count 1))
6303 (case-fold-search t)
6304 (lim (or lim (point-min)))
6305 (here (point))
6306 state)
6307 (save-excursion
6308 (goto-char lim)
6309 (setq state (parse-partial-sexp (point) here nil nil)))
6310 (if (and interactive
6311 (or (nth 3 state)
6312 (nth 4 state)
6313 (looking-at (concat "[ \t]*" comment-start-skip))))
6314 (forward-sentence (- count))
6315 (while (> count 0)
6316 (vhdl-beginning-of-statement-1 lim)
6317 (setq count (1- count))))
6318 ;; its possible we've been left up-buf of lim
6319 (goto-char (max (point) lim))
6320 )
6321 (vhdl-keep-region-active))
6322
6323 (defconst vhdl-e-o-s-re
6324 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6325
6326 (defun vhdl-end-of-statement ()
6327 "Very simple implementation."
6328 (interactive)
6329 (re-search-forward vhdl-e-o-s-re))
6330
6331 (defconst vhdl-b-o-s-re
6332 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6333 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6334
6335 (defun vhdl-beginning-of-statement-1 (&optional lim)
6336 "Move to the start of the current statement, or the previous
6337 statement if already at the beginning of one."
6338 (let ((lim (or lim (point-min)))
6339 (here (point))
6340 (pos (point))
6341 donep)
6342 ;; go backwards one balanced expression, but be careful of
6343 ;; unbalanced paren being reached
6344 (if (not (vhdl-safe (progn (backward-sexp) t)))
6345 (progn
6346 (backward-up-list 1)
6347 (forward-char)
6348 (vhdl-forward-syntactic-ws here)
6349 (setq donep t)))
6350 (while (and (not donep)
6351 (not (bobp))
6352 ;; look backwards for a statement boundary
6353 (re-search-backward vhdl-b-o-s-re lim 'move))
6354 (if (or (= (preceding-char) ?_)
6355 (vhdl-in-literal))
6356 (backward-char)
6357 (cond
6358 ;; If we are looking at an open paren, then stop after it
6359 ((eq (following-char) ?\()
6360 (forward-char)
6361 (vhdl-forward-syntactic-ws here)
6362 (setq donep t))
6363 ;; If we are looking at a close paren, then skip it
6364 ((eq (following-char) ?\))
6365 (forward-char)
6366 (setq pos (point))
6367 (backward-sexp)
6368 (if (< (point) lim)
6369 (progn (goto-char pos)
6370 (vhdl-forward-syntactic-ws here)
6371 (setq donep t))))
6372 ;; If we are looking at a semicolon, then stop
6373 ((eq (following-char) ?\;)
6374 (progn
6375 (forward-char)
6376 (vhdl-forward-syntactic-ws here)
6377 (setq donep t)))
6378 ;; If we are looking at a "begin", then stop
6379 ((and (looking-at vhdl-begin-fwd-re)
6380 (/= (preceding-char) ?_)
6381 (vhdl-begin-p nil))
6382 ;; If it's a leader "begin", then find the
6383 ;; right place
6384 (if (looking-at vhdl-leader-re)
6385 (save-excursion
6386 ;; set a default stop point at the begin
6387 (setq pos (point))
6388 ;; is the start point inside the leader area ?
6389 (goto-char (vhdl-end-of-leader))
6390 (vhdl-forward-syntactic-ws here)
6391 (if (< (point) here)
6392 ;; start point was not inside leader area
6393 ;; set stop point at word after leader
6394 (setq pos (point))))
6395 (forward-word 1)
6396 (vhdl-forward-syntactic-ws here)
6397 (setq pos (point)))
6398 (goto-char pos)
6399 (setq donep t))
6400 ;; If we are looking at a "statement", then stop
6401 ((and (looking-at vhdl-statement-fwd-re)
6402 (/= (preceding-char) ?_)
6403 (vhdl-statement-p nil))
6404 (setq donep t))
6405 ;; If we are looking at a case alternative key, then stop
6406 ((and (looking-at vhdl-case-alternative-re)
6407 (vhdl-case-alternative-p lim))
6408 (save-excursion
6409 ;; set a default stop point at the when
6410 (setq pos (point))
6411 ;; is the start point inside the case alternative key ?
6412 (looking-at vhdl-case-alternative-re)
6413 (goto-char (match-end 0))
6414 (vhdl-forward-syntactic-ws here)
6415 (if (< (point) here)
6416 ;; start point was not inside the case alternative key
6417 ;; set stop point at word after case alternative keyleader
6418 (setq pos (point))))
6419 (goto-char pos)
6420 (setq donep t))
6421 ;; Bogus find, continue
6422 (t
6423 (backward-char)))))
6424 ))
6425
6426 ;; Defuns for calculating the current syntactic state:
6427
6428 (defun vhdl-get-library-unit (bod placeholder)
6429 "If there is an enclosing library unit at BOD, with its \"begin\"
6430 keyword at PLACEHOLDER, then return the library unit type."
6431 (let ((here (vhdl-point 'bol)))
6432 (if (save-excursion
6433 (goto-char placeholder)
6434 (vhdl-safe (vhdl-forward-sexp 1 bod))
6435 (<= here (point)))
6436 (save-excursion
6437 (goto-char bod)
6438 (cond
6439 ((looking-at "e") 'entity)
6440 ((looking-at "a") 'architecture)
6441 ((looking-at "c") 'configuration)
6442 ((looking-at "p")
6443 (save-excursion
6444 (goto-char bod)
6445 (forward-sexp)
6446 (vhdl-forward-syntactic-ws here)
6447 (if (looking-at "body\\b[^_]")
6448 'package-body 'package))))))
6449 ))
6450
6451 (defun vhdl-get-block-state (&optional lim)
6452 "Finds and records all the closest opens.
6453 LIM is the furthest back we need to search (it should be the
6454 previous libunit keyword)."
6455 (let ((here (point))
6456 (lim (or lim (point-min)))
6457 keyword sexp-start sexp-mid sexp-end
6458 preceding-sexp containing-sexp
6459 containing-begin containing-mid containing-paren)
6460 (save-excursion
6461 ;; Find the containing-paren, and use that as the limit
6462 (if (setq containing-paren
6463 (save-restriction
6464 (narrow-to-region lim (point))
6465 (vhdl-safe (scan-lists (point) -1 1))))
6466 (setq lim containing-paren))
6467 ;; Look backwards for "begin" and "end" keywords.
6468 (while (and (> (point) lim)
6469 (not containing-sexp))
6470 (setq keyword (vhdl-backward-to-block lim))
6471 (cond
6472 ((eq keyword 'begin)
6473 ;; Found a "begin" keyword
6474 (setq sexp-start (point))
6475 (setq sexp-mid (vhdl-corresponding-mid lim))
6476 (setq sexp-end (vhdl-safe
6477 (save-excursion
6478 (vhdl-forward-sexp 1 lim) (point))))
6479 (if (and sexp-end (<= sexp-end here))
6480 ;; we want to record this sexp, but we only want to
6481 ;; record the last-most of any of them before here
6482 (or preceding-sexp
6483 (setq preceding-sexp sexp-start))
6484 ;; we're contained in this sexp so put sexp-start on
6485 ;; front of list
6486 (setq containing-sexp sexp-start)
6487 (setq containing-mid sexp-mid)
6488 (setq containing-begin t)))
6489 ((eq keyword 'end)
6490 ;; Found an "end" keyword
6491 (forward-sexp)
6492 (setq sexp-end (point))
6493 (setq sexp-mid nil)
6494 (setq sexp-start
6495 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6496 (progn (backward-sexp) (point))))
6497 ;; we want to record this sexp, but we only want to
6498 ;; record the last-most of any of them before here
6499 (or preceding-sexp
6500 (setq preceding-sexp sexp-start)))
6501 )))
6502 ;; Check if the containing-paren should be the containing-sexp
6503 (if (and containing-paren
6504 (or (null containing-sexp)
6505 (< containing-sexp containing-paren)))
6506 (setq containing-sexp containing-paren
6507 preceding-sexp nil
6508 containing-begin nil
6509 containing-mid nil))
6510 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6511 ))
6512
6513
6514 (defconst vhdl-s-c-a-re
6515 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6516
6517 (defun vhdl-skip-case-alternative (&optional lim)
6518 "Skip forward over case/when bodies, with optional maximal
6519 limit. If no next case alternative is found, nil is returned and
6520 point is not moved."
6521 (let ((lim (or lim (point-max)))
6522 (here (point))
6523 donep foundp)
6524 (while (and (< (point) lim)
6525 (not donep))
6526 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6527 (save-match-data
6528 (not (vhdl-in-literal)))
6529 (/= (match-beginning 0) here))
6530 (progn
6531 (goto-char (match-beginning 0))
6532 (cond
6533 ((and (looking-at "case")
6534 (re-search-forward "\\bis[^_]" lim t))
6535 (backward-sexp)
6536 (vhdl-forward-sexp))
6537 (t
6538 (setq donep t
6539 foundp t))))))
6540 (if (not foundp)
6541 (goto-char here))
6542 foundp))
6543
6544 (defun vhdl-backward-skip-label (&optional lim)
6545 "Skip backward over a label, with optional maximal
6546 limit. If label is not found, nil is returned and point
6547 is not moved."
6548 (let ((lim (or lim (point-min)))
6549 placeholder)
6550 (if (save-excursion
6551 (vhdl-backward-syntactic-ws lim)
6552 (and (eq (preceding-char) ?:)
6553 (progn
6554 (backward-sexp)
6555 (setq placeholder (point))
6556 (looking-at vhdl-label-key))))
6557 (goto-char placeholder))
6558 ))
6559
6560 (defun vhdl-forward-skip-label (&optional lim)
6561 "Skip forward over a label, with optional maximal
6562 limit. If label is not found, nil is returned and point
6563 is not moved."
6564 (let ((lim (or lim (point-max))))
6565 (if (looking-at vhdl-label-key)
6566 (progn
6567 (goto-char (match-end 0))
6568 (vhdl-forward-syntactic-ws lim)))
6569 ))
6570
6571 (defun vhdl-get-syntactic-context ()
6572 "Guess the syntactic description of the current line of VHDL code."
6573 (save-excursion
6574 (save-restriction
6575 (beginning-of-line)
6576 (let* ((indent-point (point))
6577 (case-fold-search t)
6578 vec literal containing-sexp preceding-sexp
6579 containing-begin containing-mid containing-leader
6580 char-before-ip char-after-ip begin-after-ip end-after-ip
6581 placeholder lim library-unit
6582 )
6583
6584 ;; Reset the syntactic context
6585 (setq vhdl-syntactic-context nil)
6586
6587 (save-excursion
6588 ;; Move to the start of the previous library unit, and
6589 ;; record the position of the "begin" keyword.
6590 (setq placeholder (vhdl-beginning-of-libunit))
6591 ;; The position of the "libunit" keyword gives us a gross
6592 ;; limit point.
6593 (setq lim (point))
6594 )
6595
6596 ;; If there is a previous library unit, and we are enclosed by
6597 ;; it, then set the syntax accordingly.
6598 (and placeholder
6599 (setq library-unit (vhdl-get-library-unit lim placeholder))
6600 (vhdl-add-syntax library-unit lim))
6601
6602 ;; Find the surrounding state.
6603 (if (setq vec (vhdl-get-block-state lim))
6604 (progn
6605 (setq containing-sexp (aref vec 0))
6606 (setq preceding-sexp (aref vec 1))
6607 (setq containing-begin (aref vec 2))
6608 (setq containing-mid (aref vec 3))
6609 ))
6610
6611 ;; set the limit on the farthest back we need to search
6612 (setq lim (if containing-sexp
6613 (save-excursion
6614 (goto-char containing-sexp)
6615 ;; set containing-leader if required
6616 (if (looking-at vhdl-leader-re)
6617 (setq containing-leader (vhdl-end-of-leader)))
6618 (vhdl-point 'bol))
6619 (point-min)))
6620
6621 ;; cache char before and after indent point, and move point to
6622 ;; the most likely position to perform the majority of tests
6623 (goto-char indent-point)
6624 (skip-chars-forward " \t")
6625 (setq literal (vhdl-in-literal))
6626 (setq char-after-ip (following-char))
6627 (setq begin-after-ip (and
6628 (not literal)
6629 (looking-at vhdl-begin-fwd-re)
6630 (vhdl-begin-p)))
6631 (setq end-after-ip (and
6632 (not literal)
6633 (looking-at vhdl-end-fwd-re)
6634 (vhdl-end-p)))
6635 (vhdl-backward-syntactic-ws lim)
6636 (setq char-before-ip (preceding-char))
6637 (goto-char indent-point)
6638 (skip-chars-forward " \t")
6639
6640 ;; now figure out syntactic qualities of the current line
6641 (cond
6642 ;; CASE 1: in a string or comment.
6643 ((memq literal '(string comment))
6644 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6645 ;; CASE 2: Line is at top level.
6646 ((null containing-sexp)
6647 ;; Find the point to which indentation will be relative
6648 (save-excursion
6649 (if (null preceding-sexp)
6650 ;; CASE 2X.1
6651 ;; no preceding-sexp -> use the preceding statement
6652 (vhdl-beginning-of-statement-1 lim)
6653 ;; CASE 2X.2
6654 ;; if there is a preceding-sexp then indent relative to it
6655 (goto-char preceding-sexp)
6656 ;; if not at boi, then the block-opening keyword is
6657 ;; probably following a label, so we need a different
6658 ;; relpos
6659 (if (/= (point) (vhdl-point 'boi))
6660 ;; CASE 2X.3
6661 (vhdl-beginning-of-statement-1 lim)))
6662 ;; v-b-o-s could have left us at point-min
6663 (and (bobp)
6664 ;; CASE 2X.4
6665 (vhdl-forward-syntactic-ws indent-point))
6666 (setq placeholder (point)))
6667 (cond
6668 ;; CASE 2A : we are looking at a block-open
6669 (begin-after-ip
6670 (vhdl-add-syntax 'block-open placeholder))
6671 ;; CASE 2B: we are looking at a block-close
6672 (end-after-ip
6673 (vhdl-add-syntax 'block-close placeholder))
6674 ;; CASE 2C: we are looking at a top-level statement
6675 ((progn
6676 (vhdl-backward-syntactic-ws lim)
6677 (or (bobp)
6678 (= (preceding-char) ?\;)))
6679 (vhdl-add-syntax 'statement placeholder))
6680 ;; CASE 2D: we are looking at a top-level statement-cont
6681 (t
6682 (vhdl-beginning-of-statement-1 lim)
6683 ;; v-b-o-s could have left us at point-min
6684 (and (bobp)
6685 ;; CASE 2D.1
6686 (vhdl-forward-syntactic-ws indent-point))
6687 (vhdl-add-syntax 'statement-cont (point)))
6688 )) ; end CASE 2
6689 ;; CASE 3: line is inside parentheses. Most likely we are
6690 ;; either in a subprogram argument (interface) list, or a
6691 ;; continued expression containing parentheses.
6692 ((null containing-begin)
6693 (vhdl-backward-syntactic-ws containing-sexp)
6694 (cond
6695 ;; CASE 3A: we are looking at the arglist closing paren
6696 ((eq char-after-ip ?\))
6697 (goto-char containing-sexp)
6698 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6699 ;; CASE 3B: we are looking at the first argument in an empty
6700 ;; argument list.
6701 ((eq char-before-ip ?\()
6702 (goto-char containing-sexp)
6703 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6704 ;; CASE 3C: we are looking at an arglist continuation line,
6705 ;; but the preceding argument is on the same line as the
6706 ;; opening paren. This case includes multi-line
6707 ;; expression paren groupings.
6708 ((and (save-excursion
6709 (goto-char (1+ containing-sexp))
6710 (skip-chars-forward " \t")
6711 (not (eolp))
6712 (not (looking-at "--")))
6713 (save-excursion
6714 (vhdl-beginning-of-statement-1 containing-sexp)
6715 (skip-chars-backward " \t(")
6716 (<= (point) containing-sexp)))
6717 (goto-char containing-sexp)
6718 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6719 ;; CASE 3D: we are looking at just a normal arglist
6720 ;; continuation line
6721 (t (vhdl-beginning-of-statement-1 containing-sexp)
6722 (vhdl-forward-syntactic-ws indent-point)
6723 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6724 ))
6725 ;; CASE 4: A block mid open
6726 ((and begin-after-ip
6727 (looking-at containing-mid))
6728 (goto-char containing-sexp)
6729 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6730 (if (looking-at vhdl-trailer-re)
6731 ;; CASE 4.1
6732 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6733 (vhdl-backward-skip-label (vhdl-point 'boi))
6734 (vhdl-add-syntax 'block-open (point)))
6735 ;; CASE 5: block close brace
6736 (end-after-ip
6737 (goto-char containing-sexp)
6738 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6739 (if (looking-at vhdl-trailer-re)
6740 ;; CASE 5.1
6741 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6742 (vhdl-backward-skip-label (vhdl-point 'boi))
6743 (vhdl-add-syntax 'block-close (point)))
6744 ;; CASE 6: A continued statement
6745 ((and (/= char-before-ip ?\;)
6746 ;; check it's not a trailer begin keyword, or a begin
6747 ;; keyword immediately following a label.
6748 (not (and begin-after-ip
6749 (or (looking-at vhdl-trailer-re)
6750 (save-excursion
6751 (vhdl-backward-skip-label containing-sexp)))))
6752 ;; check it's not a statement keyword
6753 (not (and (looking-at vhdl-statement-fwd-re)
6754 (vhdl-statement-p)))
6755 ;; see if the b-o-s is before the indent point
6756 (> indent-point
6757 (save-excursion
6758 (vhdl-beginning-of-statement-1 containing-sexp)
6759 ;; If we ended up after a leader, then this will
6760 ;; move us forward to the start of the first
6761 ;; statement. Note that a containing sexp here is
6762 ;; always a keyword, not a paren, so this will
6763 ;; have no effect if we hit the containing-sexp.
6764 (vhdl-forward-syntactic-ws indent-point)
6765 (setq placeholder (point))))
6766 ;; check it's not a block-intro
6767 (/= placeholder containing-sexp)
6768 ;; check it's not a case block-intro
6769 (save-excursion
6770 (goto-char placeholder)
6771 (or (not (looking-at vhdl-case-alternative-re))
6772 (> (match-end 0) indent-point))))
6773 ;; Make placeholder skip a label, but only if it puts us
6774 ;; before the indent point at the start of a line.
6775 (let ((new placeholder))
6776 (if (and (> indent-point
6777 (save-excursion
6778 (goto-char placeholder)
6779 (vhdl-forward-skip-label indent-point)
6780 (setq new (point))))
6781 (save-excursion
6782 (goto-char new)
6783 (eq new (progn (back-to-indentation) (point)))))
6784 (setq placeholder new)))
6785 (vhdl-add-syntax 'statement-cont placeholder)
6786 (if begin-after-ip
6787 (vhdl-add-syntax 'block-open)))
6788 ;; Statement. But what kind?
6789 ;; CASE 7: A case alternative key
6790 ((and (looking-at vhdl-case-alternative-re)
6791 (vhdl-case-alternative-p containing-sexp))
6792 ;; for a case alternative key, we set relpos to the first
6793 ;; non-whitespace char on the line containing the "case"
6794 ;; keyword.
6795 (goto-char containing-sexp)
6796 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6797 (if (looking-at vhdl-trailer-re)
6798 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6799 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6800 ;; CASE 8: statement catchall
6801 (t
6802 ;; we know its a statement, but we need to find out if it is
6803 ;; the first statement in a block
6804 (if containing-leader
6805 (goto-char containing-leader)
6806 (goto-char containing-sexp)
6807 ;; Note that a containing sexp here is always a keyword,
6808 ;; not a paren, so skip over the keyword.
6809 (forward-sexp))
6810 ;; move to the start of the first statement
6811 (vhdl-forward-syntactic-ws indent-point)
6812 (setq placeholder (point))
6813 ;; we want to ignore case alternatives keys when skipping forward
6814 (let (incase-p)
6815 (while (looking-at vhdl-case-alternative-re)
6816 (setq incase-p (point))
6817 ;; we also want to skip over the body of the
6818 ;; case/when statement if that doesn't put us at
6819 ;; after the indent-point
6820 (while (vhdl-skip-case-alternative indent-point))
6821 ;; set up the match end
6822 (looking-at vhdl-case-alternative-re)
6823 (goto-char (match-end 0))
6824 ;; move to the start of the first case alternative statement
6825 (vhdl-forward-syntactic-ws indent-point)
6826 (setq placeholder (point)))
6827 (cond
6828 ;; CASE 8A: we saw a case/when statement so we must be
6829 ;; in a switch statement. find out if we are at the
6830 ;; statement just after a case alternative key
6831 ((and incase-p
6832 (= (point) indent-point))
6833 ;; relpos is the "when" keyword
6834 (vhdl-add-syntax 'statement-case-intro incase-p))
6835 ;; CASE 8B: any old statement
6836 ((< (point) indent-point)
6837 ;; relpos is the first statement of the block
6838 (vhdl-add-syntax 'statement placeholder)
6839 (if begin-after-ip
6840 (vhdl-add-syntax 'block-open)))
6841 ;; CASE 8C: first statement in a block
6842 (t
6843 (goto-char containing-sexp)
6844 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6845 (if (looking-at vhdl-trailer-re)
6846 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6847 (vhdl-backward-skip-label (vhdl-point 'boi))
6848 (vhdl-add-syntax 'statement-block-intro (point))
6849 (if begin-after-ip
6850 (vhdl-add-syntax 'block-open)))
6851 )))
6852 )
6853
6854 ;; now we need to look at any modifiers
6855 (goto-char indent-point)
6856 (skip-chars-forward " \t")
6857 (if (looking-at "--")
6858 (vhdl-add-syntax 'comment))
6859 (if (eq literal 'pound)
6860 (vhdl-add-syntax 'cpp-macro))
6861 ;; return the syntax
6862 vhdl-syntactic-context))))
6863
6864 ;; Standard indentation line-ups:
6865
6866 (defun vhdl-lineup-arglist (langelem)
6867 "Lineup the current arglist line with the arglist appearing just
6868 after the containing paren which starts the arglist."
6869 (save-excursion
6870 (let* ((containing-sexp
6871 (save-excursion
6872 ;; arglist-cont-nonempty gives relpos ==
6873 ;; to boi of containing-sexp paren. This
6874 ;; is good when offset is +, but bad
6875 ;; when it is vhdl-lineup-arglist, so we
6876 ;; have to special case a kludge here.
6877 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6878 (progn
6879 (beginning-of-line)
6880 (backward-up-list 1)
6881 (skip-chars-forward " \t" (vhdl-point 'eol)))
6882 (goto-char (cdr langelem)))
6883 (point)))
6884 (cs-curcol (save-excursion
6885 (goto-char (cdr langelem))
6886 (current-column))))
6887 (if (save-excursion
6888 (beginning-of-line)
6889 (looking-at "[ \t]*)"))
6890 (progn (goto-char (match-end 0))
6891 (backward-sexp)
6892 (forward-char)
6893 (vhdl-forward-syntactic-ws)
6894 (- (current-column) cs-curcol))
6895 (goto-char containing-sexp)
6896 (or (eolp)
6897 (let ((eol (vhdl-point 'eol))
6898 (here (progn
6899 (forward-char)
6900 (skip-chars-forward " \t")
6901 (point))))
6902 (vhdl-forward-syntactic-ws)
6903 (if (< (point) eol)
6904 (goto-char here))))
6905 (- (current-column) cs-curcol)
6906 ))))
6907
6908 (defun vhdl-lineup-arglist-intro (langelem)
6909 "Lineup an arglist-intro line to just after the open paren."
6910 (save-excursion
6911 (let ((cs-curcol (save-excursion
6912 (goto-char (cdr langelem))
6913 (current-column)))
6914 (ce-curcol (save-excursion
6915 (beginning-of-line)
6916 (backward-up-list 1)
6917 (skip-chars-forward " \t" (vhdl-point 'eol))
6918 (current-column))))
6919 (- ce-curcol cs-curcol -1))))
6920
6921 (defun vhdl-lineup-comment (langelem)
6922 "Support old behavior for comment indentation. We look at
6923 vhdl-comment-only-line-offset to decide how to indent comment
6924 only-lines."
6925 (save-excursion
6926 (back-to-indentation)
6927 ;; at or to the right of comment-column
6928 (if (>= (current-column) comment-column)
6929 (vhdl-comment-indent)
6930 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6931 (if (not (bolp))
6932 (or (car-safe vhdl-comment-only-line-offset)
6933 vhdl-comment-only-line-offset)
6934 (or (cdr-safe vhdl-comment-only-line-offset)
6935 (car-safe vhdl-comment-only-line-offset)
6936 -1000 ;jam it against the left side
6937 )))))
6938
6939 (defun vhdl-lineup-statement-cont (langelem)
6940 "Line up statement-cont after the assignment operator."
6941 (save-excursion
6942 (let* ((relpos (cdr langelem))
6943 (assignp (save-excursion
6944 (goto-char (vhdl-point 'boi))
6945 (and (re-search-forward "\\(<\\|:\\)="
6946 (vhdl-point 'eol) t)
6947 (- (point) (vhdl-point 'boi)))))
6948 (curcol (progn
6949 (goto-char relpos)
6950 (current-column)))
6951 foundp)
6952 (while (and (not foundp)
6953 (< (point) (vhdl-point 'eol)))
6954 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6955 (if (vhdl-in-literal)
6956 (forward-char)
6957 (if (= (preceding-char) ?\()
6958 ;; skip over any parenthesized expressions
6959 (goto-char (min (vhdl-point 'eol)
6960 (scan-lists (point) 1 1)))
6961 ;; found an assignment operator (not at eol)
6962 (setq foundp (not (looking-at "\\s-*$"))))))
6963 (if (not foundp)
6964 ;; there's no assignment operator on the line
6965 vhdl-basic-offset
6966 ;; calculate indentation column after assign and ws, unless
6967 ;; our line contains an assignment operator
6968 (if (not assignp)
6969 (progn
6970 (forward-char)
6971 (skip-chars-forward " \t")
6972 (setq assignp 0)))
6973 (- (current-column) assignp curcol))
6974 )))
6975
6976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6977 ;; Progress reporting
6978
6979 (defvar vhdl-progress-info nil
6980 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6981
6982 (defun vhdl-update-progress-info (string pos)
6983 "Update progress information."
6984 (when (and vhdl-progress-info (not noninteractive)
6985 (< vhdl-progress-interval
6986 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6987 (let ((delta (- (aref vhdl-progress-info 1)
6988 (aref vhdl-progress-info 0))))
6989 (if (= 0 delta)
6990 (message (concat string "... (100%s)") "%")
6991 (message (concat string "... (%2d%s)")
6992 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6993 delta) "%")))
6994 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6995
6996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6997 ;; Indentation commands
6998
6999 (defun vhdl-electric-tab (&optional prefix-arg)
7000 "If preceeding character is part of a word or a paren then hippie-expand,
7001 else if right of non whitespace on line then insert tab,
7002 else if last command was a tab or return then dedent one step or if a comment
7003 toggle between normal indent and inline comment indent,
7004 else indent `correctly'."
7005 (interactive "*P")
7006 (vhdl-prepare-search-2
7007 (cond
7008 ;; expand word
7009 ((= (char-syntax (preceding-char)) ?w)
7010 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7011 (case-replace nil)
7012 (hippie-expand-only-buffers
7013 (or (and (boundp 'hippie-expand-only-buffers)
7014 hippie-expand-only-buffers)
7015 '(vhdl-mode))))
7016 (vhdl-expand-abbrev prefix-arg)))
7017 ;; expand parenthesis
7018 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7019 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7020 (case-replace nil))
7021 (vhdl-expand-paren prefix-arg)))
7022 ;; insert tab
7023 ((> (current-column) (current-indentation))
7024 (insert-tab))
7025 ;; toggle comment indent
7026 ((and (looking-at "--")
7027 (or (eq last-command 'vhdl-electric-tab)
7028 (eq last-command 'vhdl-electric-return)))
7029 (cond ((= (current-indentation) 0) ; no indent
7030 (indent-to 1)
7031 (indent-according-to-mode))
7032 ((< (current-indentation) comment-column) ; normal indent
7033 (indent-to comment-column)
7034 (indent-according-to-mode))
7035 (t ; inline comment indent
7036 (delete-region (line-beginning-position) (point)))))
7037 ;; dedent
7038 ((and (>= (current-indentation) vhdl-basic-offset)
7039 (or (eq last-command 'vhdl-electric-tab)
7040 (eq last-command 'vhdl-electric-return)))
7041 (backward-delete-char-untabify vhdl-basic-offset nil))
7042 ;; indent line
7043 (t (indent-according-to-mode)))
7044 (setq this-command 'vhdl-electric-tab)))
7045
7046 (defun vhdl-electric-return ()
7047 "newline-and-indent or indent-new-comment-line if in comment and preceding
7048 character is a space."
7049 (interactive)
7050 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7051 (indent-new-comment-line)
7052 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7053 (vhdl-fix-case-word -1))
7054 (newline-and-indent)))
7055
7056 (defun vhdl-indent-line ()
7057 "Indent the current line as VHDL code. Returns the amount of
7058 indentation change."
7059 (interactive)
7060 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7061 (pos (- (point-max) (point)))
7062 (indent
7063 (if syntax
7064 ;; indent syntax-based
7065 (if (and (eq (caar syntax) 'comment)
7066 (>= (vhdl-get-offset (car syntax)) comment-column))
7067 ;; special case: comments at or right of comment-column
7068 (vhdl-get-offset (car syntax))
7069 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7070 ;; indent like previous nonblank line
7071 (save-excursion (beginning-of-line)
7072 (re-search-backward "^[^\n]" nil t)
7073 (current-indentation))))
7074 (shift-amt (- indent (current-indentation))))
7075 (and vhdl-echo-syntactic-information-p
7076 (message "syntax: %s, indent= %d" syntax indent))
7077 (unless (zerop shift-amt)
7078 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7079 (beginning-of-line)
7080 (indent-to indent))
7081 (if (< (point) (vhdl-point 'boi))
7082 (back-to-indentation)
7083 ;; If initial point was within line's indentation, position after
7084 ;; the indentation. Else stay at same point in text.
7085 (when (> (- (point-max) pos) (point))
7086 (goto-char (- (point-max) pos))))
7087 (run-hooks 'vhdl-special-indent-hook)
7088 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7089 shift-amt))
7090
7091 (defun vhdl-indent-region (beg end column)
7092 "Indent region as VHDL code.
7093 Adds progress reporting to `indent-region'."
7094 (interactive "r\nP")
7095 (when vhdl-progress-interval
7096 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7097 (count-lines (point-min) end) 0)))
7098 (indent-region beg end column)
7099 (when vhdl-progress-interval (message "Indenting...done"))
7100 (setq vhdl-progress-info nil))
7101
7102 (defun vhdl-indent-buffer ()
7103 "Indent whole buffer as VHDL code.
7104 Calls `indent-region' for whole buffer and adds progress reporting."
7105 (interactive)
7106 (vhdl-indent-region (point-min) (point-max) nil))
7107
7108 (defun vhdl-indent-group ()
7109 "Indent group of lines between empty lines."
7110 (interactive)
7111 (let ((beg (save-excursion
7112 (if (re-search-backward vhdl-align-group-separate nil t)
7113 (point-marker)
7114 (point-min-marker))))
7115 (end (save-excursion
7116 (if (re-search-forward vhdl-align-group-separate nil t)
7117 (point-marker)
7118 (point-max-marker)))))
7119 (vhdl-indent-region beg end nil)))
7120
7121 (defun vhdl-indent-sexp (&optional endpos)
7122 "Indent each line of the list starting just after point.
7123 If optional arg ENDPOS is given, indent each line, stopping when
7124 ENDPOS is encountered."
7125 (interactive)
7126 (save-excursion
7127 (let ((beg (point))
7128 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7129 (indent-region beg end nil))))
7130
7131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7132 ;; Miscellaneous commands
7133
7134 (defun vhdl-show-syntactic-information ()
7135 "Show syntactic information for current line."
7136 (interactive)
7137 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7138 (vhdl-keep-region-active))
7139
7140 ;; Verification and regression functions:
7141
7142 (defun vhdl-regress-line (&optional arg)
7143 "Check syntactic information for current line."
7144 (interactive "P")
7145 (let ((expected (save-excursion
7146 (end-of-line)
7147 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7148 (forward-char 4)
7149 (read (current-buffer)))))
7150 (actual (vhdl-get-syntactic-context))
7151 (expurgated))
7152 ;; remove the library unit symbols
7153 (mapc
7154 (function
7155 (lambda (elt)
7156 (if (memq (car elt) '(entity configuration package
7157 package-body architecture))
7158 nil
7159 (setq expurgated (append expurgated (list elt))))))
7160 actual)
7161 (if (and (not arg) expected (listp expected))
7162 (if (not (equal expected expurgated))
7163 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7164 (save-excursion
7165 (beginning-of-line)
7166 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7167 (end-of-line)
7168 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7169 (delete-region (point) (line-end-position)))
7170 (insert " -- ")
7171 (insert (format "%s" expurgated))))))
7172 (vhdl-keep-region-active))
7173
7174
7175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7176 ;;; Alignment, whitespace fixup, beautifying
7177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7178
7179 (defconst vhdl-align-alist
7180 '(
7181 ;; after some keywords
7182 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7183 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7184 ;; before ':'
7185 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7186 ;; after direction specifications
7187 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7188 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7189 ;; before "==", ":=", "=>", and "<="
7190 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7191 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7192 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7193 ;; before some keywords
7194 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7195 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7196 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7197 ;; before "=>" since "when/else ... =>" can occur
7198 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7199 )
7200 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7201 It is searched in order. If REGEXP is found anywhere in the first
7202 line of a region to be aligned, ALIGN-PATTERN will be used for that
7203 region. ALIGN-PATTERN must include the whitespace to be expanded or
7204 contracted. It may also provide regexps for the text surrounding the
7205 whitespace. SUBEXP specifies which sub-expression of
7206 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7207
7208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7209 ;; Align code
7210
7211 (defvar vhdl-align-try-all-clauses t
7212 "If REGEXP is not found on the first line of the region that clause
7213 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7214
7215 (defun vhdl-do-group (function &optional spacing)
7216 "Apply FUNCTION on group of lines between empty lines."
7217 (let
7218 ;; search for group beginning
7219 ((beg (save-excursion
7220 (if (re-search-backward vhdl-align-group-separate nil t)
7221 (progn (beginning-of-line 2) (back-to-indentation) (point))
7222 (point-min))))
7223 ;; search for group end
7224 (end (save-excursion
7225 (if (re-search-forward vhdl-align-group-separate nil t)
7226 (progn (beginning-of-line) (point))
7227 (point-max)))))
7228 ;; run FUNCTION
7229 (funcall function beg end spacing)))
7230
7231 (defun vhdl-do-list (function &optional spacing)
7232 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7233 parentheses."
7234 (let (beg end)
7235 (save-excursion
7236 ;; search for beginning of balanced group of parentheses
7237 (setq beg (vhdl-re-search-backward "[()]" nil t))
7238 (while (looking-at ")")
7239 (forward-char) (backward-sexp)
7240 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7241 ;; search for end of balanced group of parentheses
7242 (when beg
7243 (forward-list)
7244 (setq end (point))
7245 (goto-char (1+ beg))
7246 (skip-chars-forward " \t\n")
7247 (setq beg (point))))
7248 ;; run FUNCTION
7249 (if beg
7250 (funcall function beg end spacing)
7251 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7252
7253 (defun vhdl-do-same-indent (function &optional spacing)
7254 "Apply FUNCTION to block of lines with same indent."
7255 (let ((indent (current-indentation))
7256 beg end)
7257 ;; search for first line with same indent
7258 (save-excursion
7259 (while (and (not (bobp))
7260 (or (looking-at "^\\s-*\\(--.*\\)?$")
7261 (= (current-indentation) indent)))
7262 (unless (looking-at "^\\s-*$")
7263 (back-to-indentation) (setq beg (point)))
7264 (beginning-of-line -0)))
7265 ;; search for last line with same indent
7266 (save-excursion
7267 (while (and (not (eobp))
7268 (or (looking-at "^\\s-*\\(--.*\\)?$")
7269 (= (current-indentation) indent)))
7270 (if (looking-at "^\\s-*$")
7271 (beginning-of-line 2)
7272 (beginning-of-line 2)
7273 (setq end (point)))))
7274 ;; run FUNCTION
7275 (funcall function beg end spacing)))
7276
7277 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7278 "Attempt to align a range of lines based on the content of the
7279 lines. The definition of `alignment-list' determines the matching
7280 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7281 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7282 indentation is done before aligning."
7283 (interactive "r\np")
7284 (setq alignment-list (or alignment-list vhdl-align-alist))
7285 (setq spacing (or spacing 1))
7286 (save-excursion
7287 (let (bol indent)
7288 (goto-char end)
7289 (setq end (point-marker))
7290 (goto-char begin)
7291 (setq bol (setq begin (progn (beginning-of-line) (point))))
7292 ; (untabify bol end)
7293 (when indent
7294 (indent-region bol end nil))))
7295 (let ((copy (copy-alist alignment-list)))
7296 (vhdl-prepare-search-2
7297 (while copy
7298 (save-excursion
7299 (goto-char begin)
7300 (let (element
7301 (eol (save-excursion (progn (end-of-line) (point)))))
7302 (setq element (nth 0 copy))
7303 (when (and (or (and (listp (car element))
7304 (memq major-mode (car element)))
7305 (eq major-mode (car element)))
7306 (or vhdl-align-try-all-clauses
7307 (re-search-forward (car (cdr element)) eol t)))
7308 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7309 (car (cdr (cdr (cdr element)))) spacing))
7310 (setq copy (cdr copy))))))))
7311
7312 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7313 "Align a range of lines from BEGIN to END. The regular expression
7314 MATCH must match exactly one field: the whitespace to be
7315 contracted/expanded. The alignment column will equal the
7316 rightmost column of the widest whitespace block. SPACING is
7317 the amount of extra spaces to add to the calculated maximum required.
7318 SPACING defaults to 1 so that at least one space is inserted after
7319 the token in MATCH."
7320 (setq spacing (or spacing 1))
7321 (setq substr (or substr 1))
7322 (save-excursion
7323 (let (distance (max 0) (lines 0) bol eol width)
7324 ;; Determine the greatest whitespace distance to the alignment
7325 ;; character
7326 (goto-char begin)
7327 (setq eol (progn (end-of-line) (point))
7328 bol (setq begin (progn (beginning-of-line) (point))))
7329 (while (< bol end)
7330 (save-excursion
7331 (when (and (re-search-forward match eol t)
7332 (not (vhdl-in-literal)))
7333 (setq distance (- (match-beginning substr) bol))
7334 (when (> distance max)
7335 (setq max distance))))
7336 (forward-line)
7337 (setq bol (point)
7338 eol (save-excursion (end-of-line) (point)))
7339 (setq lines (1+ lines)))
7340 ;; Now insert enough maxs to push each assignment operator to
7341 ;; the same column. We need to use 'lines' as a counter, since
7342 ;; the location of the mark may change
7343 (goto-char (setq bol begin))
7344 (setq eol (save-excursion (end-of-line) (point)))
7345 (while (> lines 0)
7346 (when (and (re-search-forward match eol t)
7347 (not (vhdl-in-literal)))
7348 (setq width (- (match-end substr) (match-beginning substr)))
7349 (setq distance (- (match-beginning substr) bol))
7350 (goto-char (match-beginning substr))
7351 (delete-char width)
7352 (insert-char ? (+ (- max distance) spacing)))
7353 (beginning-of-line)
7354 (forward-line)
7355 (setq bol (point)
7356 eol (save-excursion (end-of-line) (point)))
7357 (setq lines (1- lines))))))
7358
7359 (defun vhdl-align-region-groups (beg end &optional spacing
7360 no-message no-comments)
7361 "Align region, treat groups of lines separately."
7362 (interactive "r\nP")
7363 (save-excursion
7364 (let (orig pos)
7365 (goto-char beg)
7366 (beginning-of-line)
7367 (setq orig (point-marker))
7368 (setq beg (point))
7369 (goto-char end)
7370 (setq end (point-marker))
7371 (untabify beg end)
7372 (unless no-message
7373 (when vhdl-progress-interval
7374 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7375 (count-lines (point-min) end) 0))))
7376 (vhdl-fixup-whitespace-region beg end t)
7377 (goto-char beg)
7378 (if (not vhdl-align-groups)
7379 ;; align entire region
7380 (progn (vhdl-align-region-1 beg end spacing)
7381 (unless no-comments
7382 (vhdl-align-inline-comment-region-1 beg end)))
7383 ;; align groups
7384 (while (and (< beg end)
7385 (re-search-forward vhdl-align-group-separate end t))
7386 (setq pos (point-marker))
7387 (vhdl-align-region-1 beg pos spacing)
7388 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7389 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7390 (setq beg (1+ pos))
7391 (goto-char beg))
7392 ;; align last group
7393 (when (< beg end)
7394 (vhdl-align-region-1 beg end spacing)
7395 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7396 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7397 (when vhdl-indent-tabs-mode
7398 (tabify orig end))
7399 (unless no-message
7400 (when vhdl-progress-interval (message "Aligning...done"))
7401 (setq vhdl-progress-info nil)))))
7402
7403 (defun vhdl-align-region (beg end &optional spacing)
7404 "Align region, treat blocks with same indent and argument lists separately."
7405 (interactive "r\nP")
7406 (if (not vhdl-align-same-indent)
7407 ;; align entire region
7408 (vhdl-align-region-groups beg end spacing)
7409 ;; align blocks with same indent and argument lists
7410 (save-excursion
7411 (let ((cur-beg beg)
7412 indent cur-end)
7413 (when vhdl-progress-interval
7414 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7415 (count-lines (point-min) end) 0)))
7416 (goto-char end)
7417 (setq end (point-marker))
7418 (goto-char cur-beg)
7419 (while (< (point) end)
7420 ;; is argument list opening?
7421 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7422 (point) (vhdl-point 'eol)))))
7423 ;; determine region for argument list
7424 (progn (goto-char cur-beg)
7425 (forward-sexp)
7426 (setq cur-end (point))
7427 (beginning-of-line 2))
7428 ;; determine region with same indent
7429 (setq indent (current-indentation))
7430 (setq cur-beg (point))
7431 (setq cur-end (vhdl-point 'bonl))
7432 (beginning-of-line 2)
7433 (while (and (< (point) end)
7434 (or (looking-at "^\\s-*\\(--.*\\)?$")
7435 (= (current-indentation) indent))
7436 (<= (save-excursion
7437 (nth 0 (parse-partial-sexp
7438 (point) (vhdl-point 'eol)))) 0))
7439 (unless (looking-at "^\\s-*$")
7440 (setq cur-end (vhdl-point 'bonl)))
7441 (beginning-of-line 2)))
7442 ;; align region
7443 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7444 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7445 (when vhdl-progress-interval (message "Aligning...done"))
7446 (setq vhdl-progress-info nil)))))
7447
7448 (defun vhdl-align-group (&optional spacing)
7449 "Align group of lines between empty lines."
7450 (interactive)
7451 (vhdl-do-group 'vhdl-align-region spacing))
7452
7453 (defun vhdl-align-list (&optional spacing)
7454 "Align the lines of a list surrounded by a balanced group of parentheses."
7455 (interactive)
7456 (vhdl-do-list 'vhdl-align-region-groups spacing))
7457
7458 (defun vhdl-align-same-indent (&optional spacing)
7459 "Align block of lines with same indent."
7460 (interactive)
7461 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7462
7463 (defun vhdl-align-declarations (&optional spacing)
7464 "Align the lines within the declarative part of a design unit."
7465 (interactive)
7466 (let (beg end)
7467 (vhdl-prepare-search-2
7468 (save-excursion
7469 ;; search for declarative part
7470 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7471 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7472 (setq beg (point))
7473 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7474 (setq end (point)))))
7475 (if beg
7476 (vhdl-align-region-groups beg end spacing)
7477 (error "ERROR: Not within the declarative part of a design unit"))))
7478
7479 (defun vhdl-align-buffer ()
7480 "Align buffer."
7481 (interactive)
7482 (vhdl-align-region (point-min) (point-max)))
7483
7484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7485 ;; Align inline comments
7486
7487 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7488 "Align inline comments in region."
7489 (save-excursion
7490 (let ((start-max comment-column)
7491 (length-max 0)
7492 comment-list start-list tmp-list start length
7493 cur-start prev-start no-code)
7494 (setq spacing (or spacing 2))
7495 (vhdl-prepare-search-2
7496 (goto-char beg)
7497 ;; search for comment start positions and lengths
7498 (while (< (point) end)
7499 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7500 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7501 (not (save-excursion (goto-char (match-beginning 2))
7502 (vhdl-in-literal))))
7503 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7504 (setq length (- (match-end 2) (match-beginning 2)))
7505 (setq start-max (max start start-max))
7506 (setq length-max (max length length-max))
7507 (setq comment-list (cons (cons start length) comment-list)))
7508 (beginning-of-line 2))
7509 (setq comment-list
7510 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7511 ;; reduce start positions
7512 (setq start-list (list (caar comment-list)))
7513 (setq comment-list (cdr comment-list))
7514 (while comment-list
7515 (unless (or (= (caar comment-list) (car start-list))
7516 (<= (+ (car start-list) (cdar comment-list))
7517 end-comment-column))
7518 (setq start-list (cons (caar comment-list) start-list)))
7519 (setq comment-list (cdr comment-list)))
7520 ;; align lines as nicely as possible
7521 (goto-char beg)
7522 (while (< (point) end)
7523 (setq cur-start nil)
7524 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7525 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7526 (not (save-excursion
7527 (goto-char (match-beginning 3))
7528 (vhdl-in-literal))))
7529 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7530 (>= (- (match-end 2) (match-beginning 2))
7531 comment-column))))
7532 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7533 (setq length (- (match-end 3) (match-beginning 3)))
7534 (setq no-code (= (match-beginning 1) (match-end 1)))
7535 ;; insert minimum whitespace
7536 (goto-char (match-end 2))
7537 (delete-region (match-beginning 2) (match-end 2))
7538 (insert-char ?\ spacing)
7539 (setq tmp-list start-list)
7540 ;; insert additional whitespace to align
7541 (setq cur-start
7542 (cond
7543 ;; align comment-only line to inline comment of previous line
7544 ((and no-code prev-start
7545 (<= length (- end-comment-column prev-start)))
7546 prev-start)
7547 ;; align all comments at `start-max' if this is possible
7548 ((<= (+ start-max length-max) end-comment-column)
7549 start-max)
7550 ;; align at `comment-column' if possible
7551 ((and (<= start comment-column)
7552 (<= length (- end-comment-column comment-column)))
7553 comment-column)
7554 ;; align at left-most possible start position otherwise
7555 (t
7556 (while (and tmp-list (< (car tmp-list) start))
7557 (setq tmp-list (cdr tmp-list)))
7558 (car tmp-list))))
7559 (indent-to cur-start))
7560 (setq prev-start cur-start)
7561 (beginning-of-line 2))))))
7562
7563 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7564 "Align inline comments within a region. Groups of code lines separated by
7565 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7566 (interactive "r\nP")
7567 (save-excursion
7568 (let (orig pos)
7569 (goto-char beg)
7570 (beginning-of-line)
7571 (setq orig (point-marker))
7572 (setq beg (point))
7573 (goto-char end)
7574 (setq end (point-marker))
7575 (untabify beg end)
7576 (unless no-message (message "Aligning inline comments..."))
7577 (goto-char beg)
7578 (if (not vhdl-align-groups)
7579 ;; align entire region
7580 (vhdl-align-inline-comment-region-1 beg end spacing)
7581 ;; align groups
7582 (while (and (< beg end)
7583 (re-search-forward vhdl-align-group-separate end t))
7584 (setq pos (point-marker))
7585 (vhdl-align-inline-comment-region-1 beg pos spacing)
7586 (setq beg (1+ pos))
7587 (goto-char beg))
7588 ;; align last group
7589 (when (< beg end)
7590 (vhdl-align-inline-comment-region-1 beg end spacing)))
7591 (when vhdl-indent-tabs-mode
7592 (tabify orig end))
7593 (unless no-message (message "Aligning inline comments...done")))))
7594
7595 (defun vhdl-align-inline-comment-group (&optional spacing)
7596 "Align inline comments within a group of lines between empty lines."
7597 (interactive)
7598 (save-excursion
7599 (let ((start (point))
7600 beg end)
7601 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7602 (point-marker) (point-max)))
7603 (goto-char start)
7604 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7605 (point) (point-min)))
7606 (untabify beg end)
7607 (message "Aligning inline comments...")
7608 (vhdl-align-inline-comment-region-1 beg end)
7609 (when vhdl-indent-tabs-mode
7610 (tabify beg end))
7611 (message "Aligning inline comments...done"))))
7612
7613 (defun vhdl-align-inline-comment-buffer ()
7614 "Align inline comments within buffer. Groups of code lines separated by
7615 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7616 (interactive)
7617 (vhdl-align-inline-comment-region (point-min) (point-max)))
7618
7619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7620 ;; Fixup whitespace
7621
7622 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7623 "Fixup whitespace in region. Surround operator symbols by one space,
7624 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7625 end of line, do nothing in comments and strings."
7626 (interactive "r")
7627 (unless no-message (message "Fixing up whitespace..."))
7628 (save-excursion
7629 (goto-char end)
7630 (setq end (point-marker))
7631 ;; have no space before and one space after `,' and ';'
7632 (goto-char beg)
7633 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7634 (if (match-string 1)
7635 (goto-char (match-end 1))
7636 (replace-match "\\3 " nil nil nil 3)))
7637 ;; have no space after `('
7638 (goto-char beg)
7639 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7640 (if (match-string 1)
7641 (goto-char (match-end 1))
7642 (replace-match "\\2")))
7643 ;; have no space before `)'
7644 (goto-char beg)
7645 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7646 (if (match-string 1)
7647 (goto-char (match-end 1))
7648 (replace-match "\\2")))
7649 ;; surround operator symbols by one space
7650 (goto-char beg)
7651 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7652 (if (match-string 1)
7653 (goto-char (match-end 1))
7654 (replace-match "\\3 \\4 \\5")
7655 (goto-char (match-end 2))))
7656 ;; eliminate multiple spaces and spaces at end of line
7657 (goto-char beg)
7658 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7659 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7660 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7661 (progn (replace-match "" nil nil) t))
7662 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7663 (progn (replace-match ";" nil nil) t))
7664 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7665 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7666 (progn (replace-match " " nil nil) t))
7667 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7668 (progn (replace-match " " nil nil) t))
7669 ; (re-search-forward "[^ \t-]+" end t))))
7670 (re-search-forward "[^ \t\"-]+" end t))))
7671 (unless no-message (message "Fixing up whitespace...done")))
7672
7673 (defun vhdl-fixup-whitespace-buffer ()
7674 "Fixup whitespace in buffer. Surround operator symbols by one space,
7675 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7676 end of line, do nothing in comments."
7677 (interactive)
7678 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7679
7680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7681 ;; Beautify
7682
7683 (defun vhdl-beautify-region (beg end)
7684 "Beautify region by applying indentation, whitespace fixup, alignment, and
7685 case fixing to a region. Calls functions `vhdl-indent-buffer',
7686 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7687 `vhdl-fix-case-buffer'."
7688 (interactive "r")
7689 (setq end (save-excursion (goto-char end) (point-marker)))
7690 (vhdl-indent-region beg end nil)
7691 (let ((vhdl-align-groups t))
7692 (vhdl-align-region beg end))
7693 (vhdl-fix-case-region beg end))
7694
7695 (defun vhdl-beautify-buffer ()
7696 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7697 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7698 buffer."
7699 (interactive)
7700 (vhdl-beautify-region (point-min) (point-max))
7701 (when noninteractive (save-buffer)))
7702
7703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7704 ;; Code filling
7705
7706 (defun vhdl-fill-region (beg end &optional arg)
7707 "Fill lines for a region of code."
7708 (interactive "r\np")
7709 (save-excursion
7710 (goto-char beg)
7711 (let ((margin (if arg (current-indentation) (current-column))))
7712 (goto-char end)
7713 (setq end (point-marker))
7714 ;; remove inline comments, newlines and whitespace
7715 (vhdl-comment-kill-region beg end)
7716 (vhdl-comment-kill-inline-region beg end)
7717 (subst-char-in-region beg (1- end) ?\n ?\ )
7718 (vhdl-fixup-whitespace-region beg end)
7719 ;; wrap and end-comment-column
7720 (goto-char beg)
7721 (while (re-search-forward "\\s-" end t)
7722 (when(> (current-column) vhdl-end-comment-column)
7723 (backward-char)
7724 (when (re-search-backward "\\s-" beg t)
7725 (replace-match "\n")
7726 (indent-to margin)))))))
7727
7728 (defun vhdl-fill-group ()
7729 "Fill group of lines between empty lines."
7730 (interactive)
7731 (vhdl-do-group 'vhdl-fill-region))
7732
7733 (defun vhdl-fill-list ()
7734 "Fill the lines of a list surrounded by a balanced group of parentheses."
7735 (interactive)
7736 (vhdl-do-list 'vhdl-fill-region))
7737
7738 (defun vhdl-fill-same-indent ()
7739 "Fill the lines of block of lines with same indent."
7740 (interactive)
7741 (vhdl-do-same-indent 'vhdl-fill-region))
7742
7743
7744 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7745 ;;; Code updating/fixing
7746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7747
7748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7749 ;; Sensitivity list update
7750
7751 ;; Strategy:
7752 ;; - no sensitivity list is generated for processes with wait statements
7753 ;; - otherwise, do the following:
7754 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7755 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7756 ;; manually entered global signals)
7757 ;; 3. signals from 1. and 2. form the list of visible signals
7758 ;; 4. search for if/elsif conditions containing an event (sequential code)
7759 ;; 5. scan for strings that are within syntactical regions where signals are
7760 ;; read but not within sequential code, and that correspond to visible
7761 ;; signals
7762 ;; 6. replace sensitivity list by list of signals from 5.
7763
7764 (defun vhdl-update-sensitivity-list-process ()
7765 "Update sensitivity list of current process."
7766 (interactive)
7767 (save-excursion
7768 (vhdl-prepare-search-2
7769 (end-of-line)
7770 ;; look whether in process
7771 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7772 (equal (upcase (match-string 2)) "PROCESS")
7773 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7774 (error "ERROR: Not within a process")
7775 (message "Updating sensitivity list...")
7776 (vhdl-update-sensitivity-list)
7777 (message "Updating sensitivity list...done")))))
7778
7779 (defun vhdl-update-sensitivity-list-buffer ()
7780 "Update sensitivity list of all processes in current buffer."
7781 (interactive)
7782 (save-excursion
7783 (vhdl-prepare-search-2
7784 (goto-char (point-min))
7785 (message "Updating sensitivity lists...")
7786 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7787 (goto-char (match-beginning 0))
7788 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7789 (message "Updating sensitivity lists...done"))))
7790
7791 (defun vhdl-update-sensitivity-list ()
7792 "Update sensitivity list."
7793 (let ((proc-beg (point))
7794 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7795 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7796 seq-region-list)
7797 (cond
7798 ;; search for wait statement (no sensitivity list allowed)
7799 ((progn (goto-char proc-mid)
7800 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7801 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7802 ;; combinational process (update sensitivity list)
7803 (t
7804 (let
7805 ;; scan for visible signals
7806 ((visible-list (vhdl-get-visible-signals))
7807 ;; define syntactic regions where signals are read
7808 (scan-regions-list
7809 '(;; right-hand side of signal/variable assignment
7810 ;; (special case: "<=" is relational operator in a condition)
7811 ((re-search-forward "[<:]=" proc-end t)
7812 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7813 ;; if condition
7814 ((re-search-forward "^\\s-*if\\>" proc-end t)
7815 (re-search-forward "\\<then\\>" proc-end t))
7816 ;; elsif condition
7817 ((re-search-forward "\\<elsif\\>" proc-end t)
7818 (re-search-forward "\\<then\\>" proc-end t))
7819 ;; while loop condition
7820 ((re-search-forward "^\\s-*while\\>" proc-end t)
7821 (re-search-forward "\\<loop\\>" proc-end t))
7822 ;; exit/next condition
7823 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7824 (re-search-forward ";" proc-end t))
7825 ;; assert condition
7826 ((re-search-forward "\\<assert\\>" proc-end t)
7827 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7828 ;; case expression
7829 ((re-search-forward "^\\s-*case\\>" proc-end t)
7830 (re-search-forward "\\<is\\>" proc-end t))
7831 ;; parameter list of procedure call
7832 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7833 (1- (point)))
7834 (progn (backward-char) (forward-sexp)
7835 (while (looking-at "(") (forward-sexp)) (point)))))
7836 name read-list sens-list signal-list
7837 sens-beg sens-end beg end margin)
7838 ;; scan for signals in old sensitivity list
7839 (goto-char proc-beg)
7840 (re-search-forward "\\<process\\>" proc-mid t)
7841 (if (not (looking-at "[ \t\n]*("))
7842 (setq sens-beg (point))
7843 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7844 (goto-char (match-end 1))
7845 (forward-sexp)
7846 (setq sens-end (1- (point)))
7847 (goto-char sens-beg)
7848 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7849 (setq sens-list
7850 (cons (downcase (match-string 0)) sens-list))
7851 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7852 (setq signal-list (append visible-list sens-list))
7853 ;; search for sequential parts
7854 (goto-char proc-mid)
7855 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7856 (setq end (re-search-forward "\\<then\\>" proc-end t))
7857 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7858 (goto-char end)
7859 (backward-word 1)
7860 (vhdl-forward-sexp)
7861 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7862 (beginning-of-line)))
7863 ;; scan for signals read in process
7864 (while scan-regions-list
7865 (goto-char proc-mid)
7866 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7867 (setq end (eval (nth 1 (car scan-regions-list)))))
7868 (goto-char beg)
7869 (unless (or (vhdl-in-literal)
7870 (and seq-region-list
7871 (let ((tmp-list seq-region-list))
7872 (while (and tmp-list
7873 (< (point) (caar tmp-list)))
7874 (setq tmp-list (cdr tmp-list)))
7875 (and tmp-list (< (point) (cdar tmp-list))))))
7876 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7877 (setq name (match-string 1))
7878 (when (and (not (match-string 4)) ; not when formal parameter
7879 (not (and (match-string 3) ; not event attribute
7880 (not (member (downcase (match-string 3))
7881 '("event" "last_event" "transaction")))))
7882 (member (downcase name) signal-list))
7883 (unless (member-ignore-case name read-list)
7884 (setq read-list (cons name read-list))))
7885 (goto-char (match-end 1)))))
7886 (setq scan-regions-list (cdr scan-regions-list)))
7887 ;; update sensitivity list
7888 (goto-char sens-beg)
7889 (if sens-end
7890 (delete-region sens-beg sens-end)
7891 (when read-list
7892 (insert " ()") (backward-char)))
7893 (setq read-list (sort read-list 'string<))
7894 (when read-list
7895 (setq margin (current-column))
7896 (insert (car read-list))
7897 (setq read-list (cdr read-list))
7898 (while read-list
7899 (insert ",")
7900 (if (<= (+ (current-column) (length (car read-list)) 2)
7901 end-comment-column)
7902 (insert " ")
7903 (insert "\n") (indent-to margin))
7904 (insert (car read-list))
7905 (setq read-list (cdr read-list)))))))))
7906
7907 (defun vhdl-get-visible-signals ()
7908 "Get all signals visible in the current block."
7909 (let (beg end signal-list entity-name file-name)
7910 (vhdl-prepare-search-2
7911 ;; get entity name
7912 (save-excursion
7913 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7914 (not (equal "END" (upcase (match-string 1))))
7915 (setq entity-name (match-string 2)))
7916 (error "ERROR: Not within an architecture")))
7917 ;; search for signals declared in entity port clause
7918 (save-excursion
7919 (goto-char (point-min))
7920 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7921 (setq file-name
7922 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7923 "." (file-name-extension (buffer-file-name)))))
7924 (vhdl-visit-file
7925 file-name t
7926 (vhdl-prepare-search-2
7927 (goto-char (point-min))
7928 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7929 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7930 (when (setq beg (re-search-forward
7931 "^\\s-*port[ \t\n]*("
7932 (save-excursion
7933 (re-search-forward "^end\\>" nil t)) t))
7934 (setq end (save-excursion
7935 (backward-char) (forward-sexp) (point)))
7936 (vhdl-forward-syntactic-ws)
7937 (while (< (point) end)
7938 (when (looking-at "signal[ \t\n]+")
7939 (goto-char (match-end 0)))
7940 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7941 (setq signal-list
7942 (cons (downcase (match-string 1)) signal-list))
7943 (goto-char (match-end 0))
7944 (vhdl-forward-syntactic-ws))
7945 (re-search-forward ";" end 1)
7946 (vhdl-forward-syntactic-ws)))))))
7947 ;; search for signals declared in architecture declarative part
7948 (save-excursion
7949 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7950 (not (equal "END" (upcase (match-string 1))))
7951 (setq end (re-search-forward "^begin\\>" nil t))))
7952 (error "ERROR: No architecture declarative part found")
7953 ;; scan for all declared signal and alias names
7954 (goto-char beg)
7955 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7956 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7957 (if (match-string 2)
7958 ;; scan signal name
7959 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7960 (setq signal-list
7961 (cons (downcase (match-string 1)) signal-list))
7962 (goto-char (match-end 0)))
7963 ;; scan alias name, check is alias of (declared) signal
7964 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7965 (member (downcase (match-string 2)) signal-list))
7966 (setq signal-list
7967 (cons (downcase (match-string 1)) signal-list))
7968 (goto-char (match-end 0))))
7969 (setq beg (point))))))
7970 ;; search for signals declared in surrounding block declarative parts
7971 (save-excursion
7972 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7973 (match-string 2))
7974 (goto-char (match-end 2))
7975 (vhdl-backward-sexp)
7976 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7977 beg)
7978 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7979 ;; scan for all declared signal names
7980 (goto-char beg)
7981 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7982 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7983 (if (match-string 2)
7984 ;; scan signal name
7985 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7986 (setq signal-list
7987 (cons (downcase (match-string 1)) signal-list))
7988 (goto-char (match-end 0)))
7989 ;; scan alias name, check is alias of (declared) signal
7990 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7991 (member (downcase (match-string 2)) signal-list))
7992 (setq signal-list
7993 (cons (downcase (match-string 1)) signal-list))
7994 (goto-char (match-end 0))))))
7995 (goto-char beg)))
7996 signal-list)))
7997
7998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7999 ;; Generic/port clause fixing
8000
8001 (defun vhdl-fix-clause ()
8002 "Fix closing parenthesis within generic/port clause."
8003 (interactive)
8004 (save-excursion
8005 (vhdl-prepare-search-2
8006 (let ((pos (point))
8007 beg end)
8008 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8009 (error "ERROR: Not within a generic/port clause")
8010 ;; search for end of clause
8011 (goto-char (match-end 0))
8012 (setq beg (1- (point)))
8013 (vhdl-forward-syntactic-ws)
8014 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8015 (goto-char (1- (match-end 0)))
8016 (setq end (point-marker))
8017 (forward-char)
8018 (vhdl-forward-syntactic-ws))
8019 (goto-char end)
8020 (when (> pos (save-excursion (end-of-line) (point)))
8021 (error "ERROR: Not within a generic/port clause"))
8022 ;; delete closing parenthesis on separate line (not supported style)
8023 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8024 (vhdl-line-kill)
8025 (vhdl-backward-syntactic-ws)
8026 (setq end (point-marker))
8027 (insert ";"))
8028 ;; delete superfluous parentheses
8029 (while (progn (goto-char beg)
8030 (condition-case () (forward-sexp)
8031 (error (goto-char (point-max))))
8032 (< (point) end))
8033 (delete-backward-char 1))
8034 ;; add closing parenthesis
8035 (when (> (point) end)
8036 (goto-char end)
8037 (insert ")")))))))
8038
8039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8040 ;; Miscellaneous
8041
8042 (defun vhdl-remove-trailing-spaces ()
8043 "Remove trailing spaces in the whole buffer."
8044 (interactive)
8045 (save-match-data
8046 (save-excursion
8047 (goto-char (point-min))
8048 (while (re-search-forward "[ \t]+$" (point-max) t)
8049 (unless (vhdl-in-literal)
8050 (replace-match "" nil nil))))))
8051
8052
8053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8054 ;;; Electrification
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056
8057 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8058 "Syntax of prompt inserted by template generators.")
8059
8060 (defvar vhdl-template-invoked-by-hook nil
8061 "Indicates whether a template has been invoked by a hook or by key or menu.
8062 Used for undoing after template abortion.")
8063
8064 ;; correct different behavior of function `unread-command-events' in XEmacs
8065 (defun vhdl-character-to-event (arg))
8066 (defalias 'vhdl-character-to-event
8067 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8068
8069 (defun vhdl-work-library ()
8070 "Return the working library name of the current project or \"work\" if no
8071 project is defined."
8072 (vhdl-resolve-env-variable
8073 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8074
8075 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8076 ;; Enabling/disabling
8077
8078 (defun vhdl-mode-line-update ()
8079 "Update the modeline string for VHDL major mode."
8080 (setq mode-name (concat "VHDL"
8081 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8082 (and vhdl-electric-mode "e")
8083 (and vhdl-stutter-mode "s")))
8084 (force-mode-line-update t))
8085
8086 (defun vhdl-electric-mode (arg)
8087 "Toggle VHDL electric mode.
8088 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8089 (interactive "P")
8090 (setq vhdl-electric-mode
8091 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8092 ((> arg 0) t) (t nil)))
8093 (vhdl-mode-line-update))
8094
8095 (defun vhdl-stutter-mode (arg)
8096 "Toggle VHDL stuttering mode.
8097 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8098 (interactive "P")
8099 (setq vhdl-stutter-mode
8100 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8101 ((> arg 0) t) (t nil)))
8102 (vhdl-mode-line-update))
8103
8104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8105 ;; Stuttering
8106
8107 (defun vhdl-electric-dash (count)
8108 "-- starts a comment, --- draws a horizontal line,
8109 ---- starts a display comment."
8110 (interactive "p")
8111 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8112 (cond
8113 ((and abbrev-start-location (= abbrev-start-location (point)))
8114 (setq abbrev-start-location nil)
8115 (goto-char last-abbrev-location)
8116 (beginning-of-line nil)
8117 (vhdl-comment-display))
8118 ((/= (preceding-char) ?-) ; standard dash (minus)
8119 (self-insert-command count))
8120 (t (self-insert-command count)
8121 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8122 (let ((next-input (read-char)))
8123 (if (= next-input ?-) ; triple dash
8124 (progn
8125 (vhdl-comment-display-line)
8126 (message
8127 "Enter '-' for display comment, else continue coding")
8128 (let ((next-input (read-char)))
8129 (if (= next-input ?-) ; four dashes
8130 (vhdl-comment-display t)
8131 (setq unread-command-events ; pushback the char
8132 (list (vhdl-character-to-event next-input))))))
8133 (setq unread-command-events ; pushback the char
8134 (list (vhdl-character-to-event next-input)))
8135 (vhdl-comment-insert)))))
8136 (self-insert-command count)))
8137
8138 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8139 (interactive "p")
8140 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8141 (if (= (preceding-char) ?\()
8142 (progn (delete-char -1) (insert-char ?\[ 1))
8143 (insert-char ?\( 1))
8144 (self-insert-command count)))
8145
8146 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8147 (interactive "p")
8148 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8149 (progn
8150 (if (= (preceding-char) ?\))
8151 (progn (delete-char -1) (insert-char ?\] 1))
8152 (insert-char ?\) 1))
8153 (blink-matching-open))
8154 (self-insert-command count)))
8155
8156 (defun vhdl-electric-quote (count) "'' --> \""
8157 (interactive "p")
8158 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8159 (if (= (preceding-char) last-input-char)
8160 (progn (delete-backward-char 1) (insert-char ?\" 1))
8161 (insert-char ?\' 1))
8162 (self-insert-command count)))
8163
8164 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8165 (interactive "p")
8166 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8167 (cond ((= (preceding-char) last-input-char)
8168 (progn (delete-char -1)
8169 (unless (eq (preceding-char) ? ) (insert " "))
8170 (insert ": ")
8171 (setq this-command 'vhdl-electric-colon)))
8172 ((and
8173 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8174 (progn (delete-char -1) (insert "= ")))
8175 (t (insert-char ?\; 1)))
8176 (self-insert-command count)))
8177
8178 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8179 (interactive "p")
8180 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8181 (cond ((= (preceding-char) last-input-char)
8182 (progn (delete-char -1)
8183 (unless (eq (preceding-char) ? ) (insert " "))
8184 (insert "<= ")))
8185 (t (insert-char ?\, 1)))
8186 (self-insert-command count)))
8187
8188 (defun vhdl-electric-period (count) "'..' --> ' => '"
8189 (interactive "p")
8190 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8191 (cond ((= (preceding-char) last-input-char)
8192 (progn (delete-char -1)
8193 (unless (eq (preceding-char) ? ) (insert " "))
8194 (insert "=> ")))
8195 (t (insert-char ?\. 1)))
8196 (self-insert-command count)))
8197
8198 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8199 (interactive "p")
8200 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8201 (cond ((= (preceding-char) last-input-char)
8202 (progn (delete-char -1)
8203 (unless (eq (preceding-char) ? ) (insert " "))
8204 (insert "== ")))
8205 (t (insert-char ?\= 1)))
8206 (self-insert-command count)))
8207
8208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8209 ;; VHDL templates
8210
8211 (defun vhdl-template-paired-parens ()
8212 "Insert a pair of round parentheses, placing point between them."
8213 (interactive)
8214 (insert "()")
8215 (backward-char))
8216
8217 (defun vhdl-template-alias ()
8218 "Insert alias declaration."
8219 (interactive)
8220 (let ((start (point)))
8221 (vhdl-insert-keyword "ALIAS ")
8222 (when (vhdl-template-field "name" nil t start (point))
8223 (insert " : ")
8224 (unless (vhdl-template-field
8225 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8226 nil t)
8227 (delete-backward-char 3))
8228 (vhdl-insert-keyword " IS ")
8229 (vhdl-template-field "name" ";")
8230 (vhdl-comment-insert-inline))))
8231
8232 (defun vhdl-template-architecture ()
8233 "Insert architecture."
8234 (interactive)
8235 (let ((margin (current-indentation))
8236 (start (point))
8237 arch-name)
8238 (vhdl-insert-keyword "ARCHITECTURE ")
8239 (when (setq arch-name
8240 (vhdl-template-field "name" nil t start (point)))
8241 (vhdl-insert-keyword " OF ")
8242 (if (save-excursion
8243 (vhdl-prepare-search-1
8244 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8245 (insert (match-string 1))
8246 (vhdl-template-field "entity name"))
8247 (vhdl-insert-keyword " IS\n")
8248 (vhdl-template-begin-end
8249 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8250 (memq vhdl-insert-empty-lines '(unit all))))))
8251
8252 (defun vhdl-template-array (kind &optional secondary)
8253 "Insert array type definition."
8254 (interactive)
8255 (let ((start (point)))
8256 (vhdl-insert-keyword "ARRAY (")
8257 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8258 secondary)
8259 (vhdl-insert-keyword ") OF ")
8260 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8261 (vhdl-insert-keyword ";"))))
8262
8263 (defun vhdl-template-assert ()
8264 "Insert an assertion statement."
8265 (interactive)
8266 (let ((start (point)))
8267 (vhdl-insert-keyword "ASSERT ")
8268 (when vhdl-conditions-in-parenthesis (insert "("))
8269 (when (vhdl-template-field "condition (negated)" nil t start (point))
8270 (when vhdl-conditions-in-parenthesis (insert ")"))
8271 (setq start (point))
8272 (vhdl-insert-keyword " REPORT ")
8273 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8274 (delete-region start (point)))
8275 (setq start (point))
8276 (vhdl-insert-keyword " SEVERITY ")
8277 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8278 (delete-region start (point)))
8279 (insert ";"))))
8280
8281 (defun vhdl-template-attribute ()
8282 "Insert an attribute declaration or specification."
8283 (interactive)
8284 (if (eq (vhdl-decision-query
8285 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8286 (vhdl-template-attribute-spec)
8287 (vhdl-template-attribute-decl)))
8288
8289 (defun vhdl-template-attribute-decl ()
8290 "Insert an attribute declaration."
8291 (interactive)
8292 (let ((start (point)))
8293 (vhdl-insert-keyword "ATTRIBUTE ")
8294 (when (vhdl-template-field "name" " : " t start (point))
8295 (vhdl-template-field "type" ";")
8296 (vhdl-comment-insert-inline))))
8297
8298 (defun vhdl-template-attribute-spec ()
8299 "Insert an attribute specification."
8300 (interactive)
8301 (let ((start (point)))
8302 (vhdl-insert-keyword "ATTRIBUTE ")
8303 (when (vhdl-template-field "name" nil t start (point))
8304 (vhdl-insert-keyword " OF ")
8305 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8306 (vhdl-template-field "entity class")
8307 (vhdl-insert-keyword " IS ")
8308 (vhdl-template-field "expression" ";"))))
8309
8310 (defun vhdl-template-block ()
8311 "Insert a block."
8312 (interactive)
8313 (let ((margin (current-indentation))
8314 (start (point))
8315 label)
8316 (vhdl-insert-keyword ": BLOCK ")
8317 (goto-char start)
8318 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8319 (forward-word 1)
8320 (forward-char 1)
8321 (insert "(")
8322 (if (vhdl-template-field "[guard expression]" nil t)
8323 (insert ")")
8324 (delete-char -2))
8325 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8326 (insert "\n")
8327 (vhdl-template-begin-end "BLOCK" label margin)
8328 (vhdl-comment-block))))
8329
8330 (defun vhdl-template-block-configuration ()
8331 "Insert a block configuration statement."
8332 (interactive)
8333 (let ((margin (current-indentation))
8334 (start (point)))
8335 (vhdl-insert-keyword "FOR ")
8336 (when (vhdl-template-field "block name" nil t start (point))
8337 (vhdl-insert-keyword "\n\n")
8338 (indent-to margin)
8339 (vhdl-insert-keyword "END FOR;")
8340 (end-of-line 0)
8341 (indent-to (+ margin vhdl-basic-offset)))))
8342
8343 (defun vhdl-template-break ()
8344 "Insert a break statement."
8345 (interactive)
8346 (let (position)
8347 (vhdl-insert-keyword "BREAK")
8348 (setq position (point))
8349 (insert " ")
8350 (while (or
8351 (progn (vhdl-insert-keyword "FOR ")
8352 (if (vhdl-template-field "[quantity name]" " USE " t)
8353 (progn (vhdl-template-field "quantity name" " => ") t)
8354 (delete-region (point)
8355 (progn (forward-word -1) (point)))
8356 nil))
8357 (vhdl-template-field "[quantity name]" " => " t))
8358 (vhdl-template-field "expression")
8359 (setq position (point))
8360 (insert ", "))
8361 (delete-region position (point))
8362 (unless (vhdl-sequential-statement-p)
8363 (vhdl-insert-keyword " ON ")
8364 (if (vhdl-template-field "[sensitivity list]" nil t)
8365 (setq position (point))
8366 (delete-region position (point))))
8367 (vhdl-insert-keyword " WHEN ")
8368 (when vhdl-conditions-in-parenthesis (insert "("))
8369 (if (vhdl-template-field "[condition]" nil t)
8370 (when vhdl-conditions-in-parenthesis (insert ")"))
8371 (delete-region position (point)))
8372 (insert ";")))
8373
8374 (defun vhdl-template-case (&optional kind)
8375 "Insert a case statement."
8376 (interactive)
8377 (let ((margin (current-indentation))
8378 (start (point))
8379 label)
8380 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8381 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8382 (vhdl-insert-keyword "CASE ")
8383 (vhdl-insert-keyword ": CASE ")
8384 (goto-char start)
8385 (setq label (vhdl-template-field "[label]" nil t))
8386 (unless label (delete-char 2))
8387 (forward-word 1)
8388 (forward-char 1))
8389 (when (vhdl-template-field "expression" nil t start (point))
8390 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8391 (indent-to margin)
8392 (vhdl-insert-keyword "END CASE")
8393 (when label (insert " " label))
8394 (insert ";")
8395 (forward-line -1)
8396 (indent-to (+ margin vhdl-basic-offset))
8397 (vhdl-insert-keyword "WHEN ")
8398 (let ((position (point)))
8399 (insert " => ;\n")
8400 (indent-to (+ margin vhdl-basic-offset))
8401 (vhdl-insert-keyword "WHEN OTHERS => null;")
8402 (goto-char position)))))
8403
8404 (defun vhdl-template-case-is ()
8405 "Insert a sequential case statement."
8406 (interactive)
8407 (vhdl-template-case 'is))
8408
8409 (defun vhdl-template-case-use ()
8410 "Insert a simultaneous case statement."
8411 (interactive)
8412 (vhdl-template-case 'use))
8413
8414 (defun vhdl-template-component ()
8415 "Insert a component declaration."
8416 (interactive)
8417 (vhdl-template-component-decl))
8418
8419 (defun vhdl-template-component-conf ()
8420 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8421 since these are almost equivalent)."
8422 (interactive)
8423 (let ((margin (current-indentation))
8424 (result (vhdl-template-configuration-spec t)))
8425 (when result
8426 (insert "\n")
8427 (indent-to margin)
8428 (vhdl-insert-keyword "END FOR;")
8429 (when (eq result 'no-use)
8430 (end-of-line -0)))))
8431
8432 (defun vhdl-template-component-decl ()
8433 "Insert a component declaration."
8434 (interactive)
8435 (let ((margin (current-indentation))
8436 (start (point))
8437 name end-column)
8438 (vhdl-insert-keyword "COMPONENT ")
8439 (when (setq name (vhdl-template-field "name" nil t start (point)))
8440 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8441 (insert "\n\n")
8442 (indent-to margin)
8443 (vhdl-insert-keyword "END COMPONENT")
8444 (unless (vhdl-standard-p '87) (insert " " name))
8445 (insert ";")
8446 (setq end-column (current-column))
8447 (end-of-line -0)
8448 (indent-to (+ margin vhdl-basic-offset))
8449 (vhdl-template-generic-list t t)
8450 (insert "\n")
8451 (indent-to (+ margin vhdl-basic-offset))
8452 (vhdl-template-port-list t)
8453 (beginning-of-line 2)
8454 (forward-char end-column))))
8455
8456 (defun vhdl-template-component-inst ()
8457 "Insert a component instantiation statement."
8458 (interactive)
8459 (let ((margin (current-indentation))
8460 (start (point))
8461 unit position)
8462 (when (vhdl-template-field "instance label" nil t start (point))
8463 (insert ": ")
8464 (if (not (vhdl-use-direct-instantiation))
8465 (vhdl-template-field "component name")
8466 ;; direct instantiation
8467 (setq unit (vhdl-template-field
8468 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8469 (setq unit (upcase (or unit "")))
8470 (cond ((equal unit "ENTITY")
8471 (vhdl-template-field "library name" "." nil nil nil nil
8472 (vhdl-work-library))
8473 (vhdl-template-field "entity name" "(")
8474 (if (vhdl-template-field "[architecture name]" nil t)
8475 (insert ")")
8476 (delete-char -1)))
8477 ((equal unit "CONFIGURATION")
8478 (vhdl-template-field "library name" "." nil nil nil nil
8479 (vhdl-work-library))
8480 (vhdl-template-field "configuration name"))
8481 (t (vhdl-template-field "component name"))))
8482 (insert "\n")
8483 (indent-to (+ margin vhdl-basic-offset))
8484 (setq position (point))
8485 (vhdl-insert-keyword "GENERIC ")
8486 (when (vhdl-template-map position t t)
8487 (insert "\n")
8488 (indent-to (+ margin vhdl-basic-offset)))
8489 (setq position (point))
8490 (vhdl-insert-keyword "PORT ")
8491 (unless (vhdl-template-map position t t)
8492 (delete-region (line-beginning-position) (point))
8493 (delete-char -1))
8494 (insert ";"))))
8495
8496 (defun vhdl-template-conditional-signal-asst ()
8497 "Insert a conditional signal assignment."
8498 (interactive)
8499 (when (vhdl-template-field "target signal")
8500 (insert " <= ")
8501 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8502 ; (insert " "))
8503 (let ((margin (current-column))
8504 (start (point))
8505 position)
8506 (vhdl-template-field "waveform")
8507 (setq position (point))
8508 (vhdl-insert-keyword " WHEN ")
8509 (when vhdl-conditions-in-parenthesis (insert "("))
8510 (while (and (vhdl-template-field "[condition]" nil t)
8511 (progn
8512 (when vhdl-conditions-in-parenthesis (insert ")"))
8513 (setq position (point))
8514 (vhdl-insert-keyword " ELSE")
8515 (insert "\n")
8516 (indent-to margin)
8517 (vhdl-template-field "[waveform]" nil t)))
8518 (setq position (point))
8519 (vhdl-insert-keyword " WHEN ")
8520 (when vhdl-conditions-in-parenthesis (insert "(")))
8521 (delete-region position (point))
8522 (insert ";")
8523 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8524
8525 (defun vhdl-template-configuration ()
8526 "Insert a configuration specification if within an architecture,
8527 a block or component configuration if within a configuration declaration,
8528 a configuration declaration if not within a design unit."
8529 (interactive)
8530 (vhdl-prepare-search-1
8531 (cond
8532 ((and (save-excursion ; architecture body
8533 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8534 (equal "ARCHITECTURE" (upcase (match-string 1))))
8535 (vhdl-template-configuration-spec))
8536 ((and (save-excursion ; configuration declaration
8537 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8538 (equal "CONFIGURATION" (upcase (match-string 1))))
8539 (if (eq (vhdl-decision-query
8540 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8541 (vhdl-template-component-conf)
8542 (vhdl-template-block-configuration)))
8543 (t (vhdl-template-configuration-decl))))) ; otherwise
8544
8545 (defun vhdl-template-configuration-spec (&optional optional-use)
8546 "Insert a configuration specification."
8547 (interactive)
8548 (let ((margin (current-indentation))
8549 (start (point))
8550 aspect position)
8551 (vhdl-insert-keyword "FOR ")
8552 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8553 t start (point))
8554 (vhdl-template-field "component name" "\n")
8555 (indent-to (+ margin vhdl-basic-offset))
8556 (setq start (point))
8557 (vhdl-insert-keyword "USE ")
8558 (if (and optional-use
8559 (not (setq aspect (vhdl-template-field
8560 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8561 (progn (delete-region start (point)) 'no-use)
8562 (unless optional-use
8563 (setq aspect (vhdl-template-field
8564 "ENTITY | CONFIGURATION | OPEN" " ")))
8565 (setq aspect (upcase (or aspect "")))
8566 (cond ((equal aspect "ENTITY")
8567 (vhdl-template-field "library name" "." nil nil nil nil
8568 (vhdl-work-library))
8569 (vhdl-template-field "entity name" "(")
8570 (if (vhdl-template-field "[architecture name]" nil t)
8571 (insert ")")
8572 (delete-char -1))
8573 (insert "\n")
8574 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8575 (setq position (point))
8576 (vhdl-insert-keyword "GENERIC ")
8577 (when (vhdl-template-map position t t)
8578 (insert "\n")
8579 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8580 (setq position (point))
8581 (vhdl-insert-keyword "PORT ")
8582 (unless (vhdl-template-map position t t)
8583 (delete-region (line-beginning-position) (point))
8584 (delete-char -1))
8585 (insert ";")
8586 t)
8587 ((equal aspect "CONFIGURATION")
8588 (vhdl-template-field "library name" "." nil nil nil nil
8589 (vhdl-work-library))
8590 (vhdl-template-field "configuration name" ";"))
8591 (t (delete-backward-char 1) (insert ";") t))))))
8592
8593
8594 (defun vhdl-template-configuration-decl ()
8595 "Insert a configuration declaration."
8596 (interactive)
8597 (let ((margin (current-indentation))
8598 (start (point))
8599 entity-exists string name position)
8600 (vhdl-insert-keyword "CONFIGURATION ")
8601 (when (setq name (vhdl-template-field "name" nil t start (point)))
8602 (vhdl-insert-keyword " OF ")
8603 (save-excursion
8604 (vhdl-prepare-search-1
8605 (setq entity-exists (vhdl-re-search-backward
8606 "\\<entity \\(\\w*\\) is\\>" nil t))
8607 (setq string (match-string 1))))
8608 (if (and entity-exists (not (equal string "")))
8609 (insert string)
8610 (vhdl-template-field "entity name"))
8611 (vhdl-insert-keyword " IS\n")
8612 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8613 (indent-to (+ margin vhdl-basic-offset))
8614 (setq position (point))
8615 (insert "\n")
8616 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8617 (indent-to margin)
8618 (vhdl-insert-keyword "END ")
8619 (unless (vhdl-standard-p '87)
8620 (vhdl-insert-keyword "CONFIGURATION "))
8621 (insert name ";")
8622 (goto-char position))))
8623
8624 (defun vhdl-template-constant ()
8625 "Insert a constant declaration."
8626 (interactive)
8627 (let ((start (point))
8628 (in-arglist (vhdl-in-argument-list-p)))
8629 (vhdl-insert-keyword "CONSTANT ")
8630 (when (vhdl-template-field "name" nil t start (point))
8631 (insert " : ")
8632 (when in-arglist (vhdl-insert-keyword "IN "))
8633 (vhdl-template-field "type")
8634 (if in-arglist
8635 (progn (insert ";")
8636 (vhdl-comment-insert-inline))
8637 (let ((position (point)))
8638 (insert " := ")
8639 (unless (vhdl-template-field "[initialization]" nil t)
8640 (delete-region position (point)))
8641 (insert ";")
8642 (vhdl-comment-insert-inline))))))
8643
8644 (defun vhdl-template-default ()
8645 "Insert nothing."
8646 (interactive)
8647 (insert " ")
8648 (unexpand-abbrev)
8649 (backward-word 1)
8650 (vhdl-case-word 1)
8651 (forward-char 1))
8652
8653 (defun vhdl-template-default-indent ()
8654 "Insert nothing and indent."
8655 (interactive)
8656 (insert " ")
8657 (unexpand-abbrev)
8658 (backward-word 1)
8659 (vhdl-case-word 1)
8660 (forward-char 1)
8661 (indent-according-to-mode))
8662
8663 (defun vhdl-template-disconnect ()
8664 "Insert a disconnect statement."
8665 (interactive)
8666 (let ((start (point)))
8667 (vhdl-insert-keyword "DISCONNECT ")
8668 (when (vhdl-template-field "signal names | OTHERS | ALL"
8669 " : " t start (point))
8670 (vhdl-template-field "type")
8671 (vhdl-insert-keyword " AFTER ")
8672 (vhdl-template-field "time expression" ";"))))
8673
8674 (defun vhdl-template-else ()
8675 "Insert an else statement."
8676 (interactive)
8677 (let (margin)
8678 (vhdl-prepare-search-1
8679 (vhdl-insert-keyword "ELSE")
8680 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8681 (equal "WHEN" (upcase (match-string 1))))
8682 (insert " ")
8683 (indent-according-to-mode)
8684 (setq margin (current-indentation))
8685 (insert "\n")
8686 (indent-to (+ margin vhdl-basic-offset))))))
8687
8688 (defun vhdl-template-elsif ()
8689 "Insert an elsif statement."
8690 (interactive)
8691 (let ((start (point))
8692 margin)
8693 (vhdl-insert-keyword "ELSIF ")
8694 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8695 (when vhdl-conditions-in-parenthesis (insert "("))
8696 (when (vhdl-template-field "condition" nil t start (point))
8697 (when vhdl-conditions-in-parenthesis (insert ")"))
8698 (indent-according-to-mode)
8699 (setq margin (current-indentation))
8700 (vhdl-insert-keyword
8701 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8702 (indent-to (+ margin vhdl-basic-offset))))))
8703
8704 (defun vhdl-template-entity ()
8705 "Insert an entity."
8706 (interactive)
8707 (let ((margin (current-indentation))
8708 (start (point))
8709 name end-column)
8710 (vhdl-insert-keyword "ENTITY ")
8711 (when (setq name (vhdl-template-field "name" nil t start (point)))
8712 (vhdl-insert-keyword " IS\n\n")
8713 (indent-to margin)
8714 (vhdl-insert-keyword "END ")
8715 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8716 (insert name ";")
8717 (setq end-column (current-column))
8718 (end-of-line -0)
8719 (indent-to (+ margin vhdl-basic-offset))
8720 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8721 (indent-to (+ margin vhdl-basic-offset))
8722 (when (vhdl-template-generic-list t)
8723 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8724 (insert "\n")
8725 (indent-to (+ margin vhdl-basic-offset))
8726 (when (vhdl-template-port-list t)
8727 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8728 (beginning-of-line 2)
8729 (forward-char end-column))))
8730
8731 (defun vhdl-template-exit ()
8732 "Insert an exit statement."
8733 (interactive)
8734 (let ((start (point)))
8735 (vhdl-insert-keyword "EXIT ")
8736 (if (vhdl-template-field "[loop label]" nil t start (point))
8737 (let ((position (point)))
8738 (vhdl-insert-keyword " WHEN ")
8739 (when vhdl-conditions-in-parenthesis (insert "("))
8740 (if (vhdl-template-field "[condition]" nil t)
8741 (when vhdl-conditions-in-parenthesis (insert ")"))
8742 (delete-region position (point))))
8743 (delete-char -1))
8744 (insert ";")))
8745
8746 (defun vhdl-template-file ()
8747 "Insert a file declaration."
8748 (interactive)
8749 (let ((start (point)))
8750 (vhdl-insert-keyword "FILE ")
8751 (when (vhdl-template-field "name" nil t start (point))
8752 (insert " : ")
8753 (vhdl-template-field "type")
8754 (unless (vhdl-standard-p '87)
8755 (vhdl-insert-keyword " OPEN ")
8756 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8757 nil t)
8758 (delete-backward-char 6)))
8759 (vhdl-insert-keyword " IS ")
8760 (when (vhdl-standard-p '87)
8761 (vhdl-template-field "[IN | OUT]" " " t))
8762 (vhdl-template-field "filename-string" nil nil nil nil t)
8763 (insert ";")
8764 (vhdl-comment-insert-inline))))
8765
8766 (defun vhdl-template-for ()
8767 "Insert a block or component configuration if within a configuration
8768 declaration, a configuration specification if within an architecture
8769 declarative part (and not within a subprogram), a for-loop if within a
8770 sequential statement part (subprogram or process), and a for-generate
8771 otherwise."
8772 (interactive)
8773 (vhdl-prepare-search-1
8774 (cond
8775 ((vhdl-sequential-statement-p) ; sequential statement
8776 (vhdl-template-for-loop))
8777 ((and (save-excursion ; configuration declaration
8778 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8779 (equal "CONFIGURATION" (upcase (match-string 1))))
8780 (if (eq (vhdl-decision-query
8781 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8782 (vhdl-template-component-conf)
8783 (vhdl-template-block-configuration)))
8784 ((and (save-excursion
8785 (re-search-backward ; architecture declarative part
8786 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8787 (equal "ARCHITECTURE" (upcase (match-string 1))))
8788 (vhdl-template-configuration-spec))
8789 (t (vhdl-template-for-generate))))) ; concurrent statement
8790
8791 (defun vhdl-template-for-generate ()
8792 "Insert a for-generate."
8793 (interactive)
8794 (let ((margin (current-indentation))
8795 (start (point))
8796 label position)
8797 (vhdl-insert-keyword ": FOR ")
8798 (setq position (point-marker))
8799 (goto-char start)
8800 (when (setq label (vhdl-template-field "label" nil t start position))
8801 (goto-char position)
8802 (vhdl-template-field "loop variable")
8803 (vhdl-insert-keyword " IN ")
8804 (vhdl-template-field "range")
8805 (vhdl-template-generate-body margin label))))
8806
8807 (defun vhdl-template-for-loop ()
8808 "Insert a for loop."
8809 (interactive)
8810 (let ((margin (current-indentation))
8811 (start (point))
8812 label index)
8813 (if (not (eq vhdl-optional-labels 'all))
8814 (vhdl-insert-keyword "FOR ")
8815 (vhdl-insert-keyword ": FOR ")
8816 (goto-char start)
8817 (setq label (vhdl-template-field "[label]" nil t))
8818 (unless label (delete-char 2))
8819 (forward-word 1)
8820 (forward-char 1))
8821 (when (setq index (vhdl-template-field "loop variable"
8822 nil t start (point)))
8823 (vhdl-insert-keyword " IN ")
8824 (vhdl-template-field "range")
8825 (vhdl-insert-keyword " LOOP\n\n")
8826 (indent-to margin)
8827 (vhdl-insert-keyword "END LOOP")
8828 (if label
8829 (insert " " label ";")
8830 (insert ";")
8831 (when vhdl-self-insert-comments (insert " -- " index)))
8832 (forward-line -1)
8833 (indent-to (+ margin vhdl-basic-offset)))))
8834
8835 (defun vhdl-template-function (&optional kind)
8836 "Insert a function declaration or body."
8837 (interactive)
8838 (let ((margin (current-indentation))
8839 (start (point))
8840 name)
8841 (vhdl-insert-keyword "FUNCTION ")
8842 (when (setq name (vhdl-template-field "name" nil t start (point)))
8843 (vhdl-template-argument-list t)
8844 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8845 (end-of-line)
8846 (insert "\n")
8847 (indent-to (+ margin vhdl-basic-offset))
8848 (vhdl-insert-keyword "RETURN ")
8849 (vhdl-template-field "type")
8850 (if (if kind (eq kind 'body)
8851 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8852 (progn (vhdl-insert-keyword " IS\n")
8853 (vhdl-template-begin-end
8854 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8855 (vhdl-comment-block))
8856 (insert ";")))))
8857
8858 (defun vhdl-template-function-decl ()
8859 "Insert a function declaration."
8860 (interactive)
8861 (vhdl-template-function 'decl))
8862
8863 (defun vhdl-template-function-body ()
8864 "Insert a function declaration."
8865 (interactive)
8866 (vhdl-template-function 'body))
8867
8868 (defun vhdl-template-generate ()
8869 "Insert a generation scheme."
8870 (interactive)
8871 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8872 (vhdl-template-if-generate)
8873 (vhdl-template-for-generate)))
8874
8875 (defun vhdl-template-generic ()
8876 "Insert generic declaration, or generic map in instantiation statements."
8877 (interactive)
8878 (let ((start (point)))
8879 (vhdl-prepare-search-1
8880 (cond
8881 ((and (save-excursion ; entity declaration
8882 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8883 (equal "ENTITY" (upcase (match-string 1))))
8884 (vhdl-template-generic-list nil))
8885 ((or (save-excursion
8886 (or (beginning-of-line)
8887 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8888 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8889 (vhdl-insert-keyword "GENERIC ")
8890 (vhdl-template-map start))
8891 (t (vhdl-template-generic-list nil t))))))
8892
8893 (defun vhdl-template-group ()
8894 "Insert group or group template declaration."
8895 (interactive)
8896 (let ((start (point)))
8897 (if (eq (vhdl-decision-query
8898 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8899 (vhdl-template-group-template)
8900 (vhdl-template-group-decl))))
8901
8902 (defun vhdl-template-group-decl ()
8903 "Insert group declaration."
8904 (interactive)
8905 (let ((start (point)))
8906 (vhdl-insert-keyword "GROUP ")
8907 (when (vhdl-template-field "name" " : " t start (point))
8908 (vhdl-template-field "template name" " (")
8909 (vhdl-template-field "constituent list" ");")
8910 (vhdl-comment-insert-inline))))
8911
8912 (defun vhdl-template-group-template ()
8913 "Insert group template declaration."
8914 (interactive)
8915 (let ((start (point)))
8916 (vhdl-insert-keyword "GROUP ")
8917 (when (vhdl-template-field "template name" nil t start (point))
8918 (vhdl-insert-keyword " IS (")
8919 (vhdl-template-field "entity class list" ");")
8920 (vhdl-comment-insert-inline))))
8921
8922 (defun vhdl-template-if ()
8923 "Insert a sequential if statement or an if-generate statement."
8924 (interactive)
8925 (if (vhdl-sequential-statement-p)
8926 (vhdl-template-if-then)
8927 (if (and (vhdl-standard-p 'ams)
8928 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8929 (vhdl-template-if-use)
8930 (vhdl-template-if-generate))))
8931
8932 (defun vhdl-template-if-generate ()
8933 "Insert an if-generate."
8934 (interactive)
8935 (let ((margin (current-indentation))
8936 (start (point))
8937 label position)
8938 (vhdl-insert-keyword ": IF ")
8939 (setq position (point-marker))
8940 (goto-char start)
8941 (when (setq label (vhdl-template-field "label" nil t start position))
8942 (goto-char position)
8943 (when vhdl-conditions-in-parenthesis (insert "("))
8944 (vhdl-template-field "condition")
8945 (when vhdl-conditions-in-parenthesis (insert ")"))
8946 (vhdl-template-generate-body margin label))))
8947
8948 (defun vhdl-template-if-then-use (kind)
8949 "Insert a sequential if statement."
8950 (interactive)
8951 (let ((margin (current-indentation))
8952 (start (point))
8953 label)
8954 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8955 (vhdl-insert-keyword "IF ")
8956 (vhdl-insert-keyword ": IF ")
8957 (goto-char start)
8958 (setq label (vhdl-template-field "[label]" nil t))
8959 (unless label (delete-char 2))
8960 (forward-word 1)
8961 (forward-char 1))
8962 (when vhdl-conditions-in-parenthesis (insert "("))
8963 (when (vhdl-template-field "condition" nil t start (point))
8964 (when vhdl-conditions-in-parenthesis (insert ")"))
8965 (vhdl-insert-keyword
8966 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8967 (indent-to margin)
8968 (vhdl-insert-keyword "END IF")
8969 (when label (insert " " label))
8970 (insert ";")
8971 (forward-line -1)
8972 (indent-to (+ margin vhdl-basic-offset)))))
8973
8974 (defun vhdl-template-if-then ()
8975 "Insert a sequential if statement."
8976 (interactive)
8977 (vhdl-template-if-then-use 'then))
8978
8979 (defun vhdl-template-if-use ()
8980 "Insert a simultaneous if statement."
8981 (interactive)
8982 (vhdl-template-if-then-use 'use))
8983
8984 (defun vhdl-template-instance ()
8985 "Insert a component instantiation statement."
8986 (interactive)
8987 (vhdl-template-component-inst))
8988
8989 (defun vhdl-template-library ()
8990 "Insert a library specification."
8991 (interactive)
8992 (let ((margin (current-indentation))
8993 (start (point))
8994 name end-pos)
8995 (vhdl-insert-keyword "LIBRARY ")
8996 (when (setq name (vhdl-template-field "names" nil t start (point)))
8997 (insert ";")
8998 (unless (string-match "," name)
8999 (setq end-pos (point))
9000 (insert "\n")
9001 (indent-to margin)
9002 (vhdl-insert-keyword "USE ")
9003 (insert name)
9004 (vhdl-insert-keyword "..ALL;")
9005 (backward-char 5)
9006 (if (vhdl-template-field "package name")
9007 (forward-char 5)
9008 (delete-region end-pos (+ (point) 5)))))))
9009
9010 (defun vhdl-template-limit ()
9011 "Insert a limit."
9012 (interactive)
9013 (let ((start (point)))
9014 (vhdl-insert-keyword "LIMIT ")
9015 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9016 t start (point))
9017 (vhdl-template-field "type")
9018 (vhdl-insert-keyword " WITH ")
9019 (vhdl-template-field "real expression" ";"))))
9020
9021 (defun vhdl-template-loop ()
9022 "Insert a loop."
9023 (interactive)
9024 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9025 (cond ((eq char ?w)
9026 (vhdl-template-while-loop))
9027 ((eq char ?f)
9028 (vhdl-template-for-loop))
9029 (t (vhdl-template-bare-loop)))))
9030
9031 (defun vhdl-template-bare-loop ()
9032 "Insert a loop."
9033 (interactive)
9034 (let ((margin (current-indentation))
9035 (start (point))
9036 label)
9037 (if (not (eq vhdl-optional-labels 'all))
9038 (vhdl-insert-keyword "LOOP ")
9039 (vhdl-insert-keyword ": LOOP ")
9040 (goto-char start)
9041 (setq label (vhdl-template-field "[label]" nil t))
9042 (unless label (delete-char 2))
9043 (forward-word 1)
9044 (delete-char 1))
9045 (insert "\n\n")
9046 (indent-to margin)
9047 (vhdl-insert-keyword "END LOOP")
9048 (insert (if label (concat " " label ";") ";"))
9049 (forward-line -1)
9050 (indent-to (+ margin vhdl-basic-offset))))
9051
9052 (defun vhdl-template-map (&optional start optional secondary)
9053 "Insert a map specification with association list."
9054 (interactive)
9055 (let ((start (or start (point)))
9056 margin end-pos)
9057 (vhdl-insert-keyword "MAP (")
9058 (if (not vhdl-association-list-with-formals)
9059 (if (vhdl-template-field
9060 (concat (and optional "[") "association list" (and optional "]"))
9061 ")" (or (not secondary) optional)
9062 (and (not secondary) start) (point))
9063 t
9064 (if (and optional secondary) (delete-region start (point)))
9065 nil)
9066 (if vhdl-argument-list-indent
9067 (setq margin (current-column))
9068 (setq margin (+ (current-indentation) vhdl-basic-offset))
9069 (insert "\n")
9070 (indent-to margin))
9071 (if (vhdl-template-field
9072 (concat (and optional "[") "formal" (and optional "]"))
9073 " => " (or (not secondary) optional)
9074 (and (not secondary) start) (point))
9075 (progn
9076 (vhdl-template-field "actual" ",")
9077 (setq end-pos (point))
9078 (insert "\n")
9079 (indent-to margin)
9080 (while (vhdl-template-field "[formal]" " => " t)
9081 (vhdl-template-field "actual" ",")
9082 (setq end-pos (point))
9083 (insert "\n")
9084 (indent-to margin))
9085 (delete-region end-pos (point))
9086 (delete-backward-char 1)
9087 (insert ")")
9088 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9089 t)
9090 (when (and optional secondary) (delete-region start (point)))
9091 nil))))
9092
9093 (defun vhdl-template-modify (&optional noerror)
9094 "Actualize modification date."
9095 (interactive)
9096 (vhdl-prepare-search-2
9097 (save-excursion
9098 (goto-char (point-min))
9099 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9100 (progn (delete-region (point) (progn (end-of-line) (point)))
9101 (vhdl-template-insert-date))
9102 (unless noerror
9103 (error "ERROR: Modification date prefix string \"%s\" not found"
9104 vhdl-modify-date-prefix-string))))))
9105
9106
9107 (defun vhdl-template-modify-noerror ()
9108 "Call `vhdl-template-modify' with NOERROR non-nil."
9109 (vhdl-template-modify t))
9110
9111 (defun vhdl-template-nature ()
9112 "Insert a nature declaration."
9113 (interactive)
9114 (let ((start (point))
9115 name mid-pos end-pos)
9116 (vhdl-insert-keyword "NATURE ")
9117 (when (setq name (vhdl-template-field "name" nil t start (point)))
9118 (vhdl-insert-keyword " IS ")
9119 (let ((definition
9120 (upcase
9121 (or (vhdl-template-field
9122 "across type | ARRAY | RECORD")
9123 ""))))
9124 (cond ((equal definition "")
9125 (insert ";"))
9126 ((equal definition "ARRAY")
9127 (delete-region (point) (progn (forward-word -1) (point)))
9128 (vhdl-template-array 'nature t))
9129 ((equal definition "RECORD")
9130 (setq mid-pos (point-marker))
9131 (delete-region (point) (progn (forward-word -1) (point)))
9132 (vhdl-template-record 'nature name t))
9133 (t
9134 (vhdl-insert-keyword " ACROSS ")
9135 (vhdl-template-field "through type")
9136 (vhdl-insert-keyword " THROUGH ")
9137 (vhdl-template-field "reference name")
9138 (vhdl-insert-keyword " REFERENCE;")))
9139 (when mid-pos
9140 (setq end-pos (point-marker))
9141 (goto-char mid-pos)
9142 (end-of-line))
9143 (vhdl-comment-insert-inline)
9144 (when end-pos (goto-char end-pos))))))
9145
9146 (defun vhdl-template-next ()
9147 "Insert a next statement."
9148 (interactive)
9149 (let ((start (point)))
9150 (vhdl-insert-keyword "NEXT ")
9151 (if (vhdl-template-field "[loop label]" nil t start (point))
9152 (let ((position (point)))
9153 (vhdl-insert-keyword " WHEN ")
9154 (when vhdl-conditions-in-parenthesis (insert "("))
9155 (if (vhdl-template-field "[condition]" nil t)
9156 (when vhdl-conditions-in-parenthesis (insert ")"))
9157 (delete-region position (point))))
9158 (delete-char -1))
9159 (insert ";")))
9160
9161 (defun vhdl-template-others ()
9162 "Insert an others aggregate."
9163 (interactive)
9164 (let ((start (point)))
9165 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9166 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9167 (vhdl-insert-keyword "OTHERS => '")
9168 (when (vhdl-template-field "value" nil t start (point))
9169 (insert "')")))
9170 (vhdl-insert-keyword "OTHERS "))))
9171
9172 (defun vhdl-template-package (&optional kind)
9173 "Insert a package specification or body."
9174 (interactive)
9175 (let ((margin (current-indentation))
9176 (start (point))
9177 name body position)
9178 (vhdl-insert-keyword "PACKAGE ")
9179 (setq body (if kind (eq kind 'body)
9180 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9181 (when body
9182 (vhdl-insert-keyword "BODY ")
9183 (when (save-excursion
9184 (vhdl-prepare-search-1
9185 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9186 (insert (setq name (match-string 1)))))
9187 (when (or name
9188 (setq name (vhdl-template-field "name" nil t start (point))))
9189 (vhdl-insert-keyword " IS\n")
9190 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9191 (indent-to (+ margin vhdl-basic-offset))
9192 (setq position (point))
9193 (insert "\n")
9194 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9195 (indent-to margin)
9196 (vhdl-insert-keyword "END ")
9197 (unless (vhdl-standard-p '87)
9198 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9199 (insert (or name "") ";")
9200 (goto-char position))))
9201
9202 (defun vhdl-template-package-decl ()
9203 "Insert a package specification."
9204 (interactive)
9205 (vhdl-template-package 'decl))
9206
9207 (defun vhdl-template-package-body ()
9208 "Insert a package body."
9209 (interactive)
9210 (vhdl-template-package 'body))
9211
9212 (defun vhdl-template-port ()
9213 "Insert a port declaration, or port map in instantiation statements."
9214 (interactive)
9215 (let ((start (point)))
9216 (vhdl-prepare-search-1
9217 (cond
9218 ((and (save-excursion ; entity declaration
9219 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9220 (equal "ENTITY" (upcase (match-string 1))))
9221 (vhdl-template-port-list nil))
9222 ((or (save-excursion
9223 (or (beginning-of-line)
9224 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9225 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9226 (vhdl-insert-keyword "PORT ")
9227 (vhdl-template-map start))
9228 (t (vhdl-template-port-list nil))))))
9229
9230 (defun vhdl-template-procedural ()
9231 "Insert a procedural."
9232 (interactive)
9233 (let ((margin (current-indentation))
9234 (start (point))
9235 (case-fold-search t)
9236 label)
9237 (vhdl-insert-keyword "PROCEDURAL ")
9238 (when (memq vhdl-optional-labels '(process all))
9239 (goto-char start)
9240 (insert ": ")
9241 (goto-char start)
9242 (setq label (vhdl-template-field "[label]" nil t))
9243 (unless label (delete-char 2))
9244 (forward-word 1)
9245 (forward-char 1))
9246 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9247 (insert "\n")
9248 (vhdl-template-begin-end "PROCEDURAL" label margin)
9249 (vhdl-comment-block)))
9250
9251 (defun vhdl-template-procedure (&optional kind)
9252 "Insert a procedure declaration or body."
9253 (interactive)
9254 (let ((margin (current-indentation))
9255 (start (point))
9256 name)
9257 (vhdl-insert-keyword "PROCEDURE ")
9258 (when (setq name (vhdl-template-field "name" nil t start (point)))
9259 (vhdl-template-argument-list)
9260 (if (if kind (eq kind 'body)
9261 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9262 (progn (vhdl-insert-keyword " IS")
9263 (when vhdl-auto-align
9264 (vhdl-align-region-groups start (point) 1))
9265 (end-of-line) (insert "\n")
9266 (vhdl-template-begin-end
9267 (unless (vhdl-standard-p '87) "PROCEDURE")
9268 name margin)
9269 (vhdl-comment-block))
9270 (insert ";")
9271 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9272 (end-of-line)))))
9273
9274 (defun vhdl-template-procedure-decl ()
9275 "Insert a procedure declaration."
9276 (interactive)
9277 (vhdl-template-procedure 'decl))
9278
9279 (defun vhdl-template-procedure-body ()
9280 "Insert a procedure body."
9281 (interactive)
9282 (vhdl-template-procedure 'body))
9283
9284 (defun vhdl-template-process (&optional kind)
9285 "Insert a process."
9286 (interactive)
9287 (let ((margin (current-indentation))
9288 (start (point))
9289 label seq input-signals clock reset final-pos)
9290 (setq seq (if kind (eq kind 'seq)
9291 (eq (vhdl-decision-query
9292 "process" "(c)ombinational or (s)equential?" t) ?s)))
9293 (vhdl-insert-keyword "PROCESS ")
9294 (when (memq vhdl-optional-labels '(process all))
9295 (goto-char start)
9296 (insert ": ")
9297 (goto-char start)
9298 (setq label (vhdl-template-field "[label]" nil t))
9299 (unless label (delete-char 2))
9300 (forward-word 1)
9301 (forward-char 1))
9302 (insert "(")
9303 (if (not seq)
9304 (unless (setq input-signals
9305 (vhdl-template-field "[sensitivity list]" ")" t))
9306 (setq input-signals "")
9307 (delete-char -2))
9308 (setq clock (or (and (not (equal "" vhdl-clock-name))
9309 (progn (insert vhdl-clock-name) vhdl-clock-name))
9310 (vhdl-template-field "clock name") "<clock>"))
9311 (when (eq vhdl-reset-kind 'async)
9312 (insert ", ")
9313 (setq reset (or (and (not (equal "" vhdl-reset-name))
9314 (progn (insert vhdl-reset-name) vhdl-reset-name))
9315 (vhdl-template-field "reset name") "<reset>")))
9316 (insert ")"))
9317 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9318 (insert "\n")
9319 (vhdl-template-begin-end "PROCESS" label margin)
9320 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9321 (when vhdl-prompt-for-comments
9322 (setq final-pos (point-marker))
9323 (vhdl-prepare-search-2
9324 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9325 (vhdl-re-search-backward "\\<process\\>" nil t))
9326 (end-of-line -0)
9327 (if (bobp)
9328 (progn (insert "\n") (forward-line -1))
9329 (insert "\n"))
9330 (indent-to margin)
9331 (insert "-- purpose: ")
9332 (if (not (vhdl-template-field "[description]" nil t))
9333 (vhdl-line-kill-entire)
9334 (insert "\n")
9335 (indent-to margin)
9336 (insert "-- type : ")
9337 (insert (if seq "sequential" "combinational") "\n")
9338 (indent-to margin)
9339 (insert "-- inputs : ")
9340 (if (not seq)
9341 (insert input-signals)
9342 (insert clock ", ")
9343 (when reset (insert reset ", "))
9344 (unless (vhdl-template-field "[signal names]" nil t)
9345 (delete-char -2)))
9346 (insert "\n")
9347 (indent-to margin)
9348 (insert "-- outputs: ")
9349 (vhdl-template-field "[signal names]" nil t))))
9350 (goto-char final-pos))))
9351
9352 (defun vhdl-template-process-comb ()
9353 "Insert a combinational process."
9354 (interactive)
9355 (vhdl-template-process 'comb))
9356
9357 (defun vhdl-template-process-seq ()
9358 "Insert a sequential process."
9359 (interactive)
9360 (vhdl-template-process 'seq))
9361
9362 (defun vhdl-template-quantity ()
9363 "Insert a quantity declaration."
9364 (interactive)
9365 (if (vhdl-in-argument-list-p)
9366 (let ((start (point)))
9367 (vhdl-insert-keyword "QUANTITY ")
9368 (when (vhdl-template-field "names" nil t start (point))
9369 (insert " : ")
9370 (vhdl-template-field "[IN | OUT]" " " t)
9371 (vhdl-template-field "type")
9372 (insert ";")
9373 (vhdl-comment-insert-inline)))
9374 (let ((char (vhdl-decision-query
9375 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9376 (cond ((eq char ?f) (vhdl-template-quantity-free))
9377 ((eq char ?b) (vhdl-template-quantity-branch))
9378 ((eq char ?s) (vhdl-template-quantity-source))
9379 (t (vhdl-template-undo (point) (point)))))))
9380
9381 (defun vhdl-template-quantity-free ()
9382 "Insert a free quantity declaration."
9383 (interactive)
9384 (vhdl-insert-keyword "QUANTITY ")
9385 (vhdl-template-field "names")
9386 (insert " : ")
9387 (vhdl-template-field "type")
9388 (let ((position (point)))
9389 (insert " := ")
9390 (unless (vhdl-template-field "[initialization]" nil t)
9391 (delete-region position (point)))
9392 (insert ";")
9393 (vhdl-comment-insert-inline)))
9394
9395 (defun vhdl-template-quantity-branch ()
9396 "Insert a branch quantity declaration."
9397 (interactive)
9398 (let (position)
9399 (vhdl-insert-keyword "QUANTITY ")
9400 (when (vhdl-template-field "[across names]" " " t)
9401 (vhdl-insert-keyword "ACROSS "))
9402 (when (vhdl-template-field "[through names]" " " t)
9403 (vhdl-insert-keyword "THROUGH "))
9404 (vhdl-template-field "plus terminal name")
9405 (setq position (point))
9406 (vhdl-insert-keyword " TO ")
9407 (unless (vhdl-template-field "[minus terminal name]" nil t)
9408 (delete-region position (point)))
9409 (insert ";")
9410 (vhdl-comment-insert-inline)))
9411
9412 (defun vhdl-template-quantity-source ()
9413 "Insert a source quantity declaration."
9414 (interactive)
9415 (vhdl-insert-keyword "QUANTITY ")
9416 (vhdl-template-field "names")
9417 (insert " : ")
9418 (vhdl-template-field "type" " ")
9419 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9420 (progn (vhdl-insert-keyword "NOISE ")
9421 (vhdl-template-field "power expression"))
9422 (vhdl-insert-keyword "SPECTRUM ")
9423 (vhdl-template-field "magnitude expression" ", ")
9424 (vhdl-template-field "phase expression"))
9425 (insert ";")
9426 (vhdl-comment-insert-inline))
9427
9428 (defun vhdl-template-record (kind &optional name secondary)
9429 "Insert a record type declaration."
9430 (interactive)
9431 (let ((margin (current-column))
9432 (start (point))
9433 (first t))
9434 (vhdl-insert-keyword "RECORD\n")
9435 (indent-to (+ margin vhdl-basic-offset))
9436 (when (or (vhdl-template-field "element names"
9437 nil (not secondary) start (point))
9438 secondary)
9439 (while (or first (vhdl-template-field "[element names]" nil t))
9440 (insert " : ")
9441 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9442 (vhdl-comment-insert-inline)
9443 (insert "\n")
9444 (indent-to (+ margin vhdl-basic-offset))
9445 (setq first nil))
9446 (delete-region (line-beginning-position) (point))
9447 (indent-to margin)
9448 (vhdl-insert-keyword "END RECORD")
9449 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9450 (insert ";")
9451 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9452
9453 (defun vhdl-template-report ()
9454 "Insert a report statement."
9455 (interactive)
9456 (let ((start (point)))
9457 (vhdl-insert-keyword "REPORT ")
9458 (if (equal "\"\"" (vhdl-template-field
9459 "string expression" nil t start (point) t))
9460 (delete-backward-char 2)
9461 (setq start (point))
9462 (vhdl-insert-keyword " SEVERITY ")
9463 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9464 (delete-region start (point)))
9465 (insert ";"))))
9466
9467 (defun vhdl-template-return ()
9468 "Insert a return statement."
9469 (interactive)
9470 (let ((start (point)))
9471 (vhdl-insert-keyword "RETURN ")
9472 (unless (vhdl-template-field "[expression]" nil t start (point))
9473 (delete-char -1))
9474 (insert ";")))
9475
9476 (defun vhdl-template-selected-signal-asst ()
9477 "Insert a selected signal assignment."
9478 (interactive)
9479 (let ((margin (current-indentation))
9480 (start (point))
9481 (choices t))
9482 (let ((position (point)))
9483 (vhdl-insert-keyword " SELECT ")
9484 (goto-char position))
9485 (vhdl-insert-keyword "WITH ")
9486 (when (vhdl-template-field "selector expression"
9487 nil t start (+ (point) 7))
9488 (forward-word 1)
9489 (delete-char 1)
9490 (insert "\n")
9491 (indent-to (+ margin vhdl-basic-offset))
9492 (vhdl-template-field "target signal" " <= ")
9493 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9494 (insert "\n")
9495 (indent-to (+ margin vhdl-basic-offset))
9496 (vhdl-template-field "waveform")
9497 (vhdl-insert-keyword " WHEN ")
9498 (vhdl-template-field "choices" ",")
9499 (insert "\n")
9500 (indent-to (+ margin vhdl-basic-offset))
9501 (while (and choices (vhdl-template-field "[waveform]" nil t))
9502 (vhdl-insert-keyword " WHEN ")
9503 (if (setq choices (vhdl-template-field "[choices]" "," t))
9504 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9505 (vhdl-insert-keyword "OTHERS")))
9506 (when choices
9507 (fixup-whitespace)
9508 (delete-char -2))
9509 (insert ";")
9510 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9511
9512 (defun vhdl-template-signal ()
9513 "Insert a signal declaration."
9514 (interactive)
9515 (let ((start (point))
9516 (in-arglist (vhdl-in-argument-list-p)))
9517 (vhdl-insert-keyword "SIGNAL ")
9518 (when (vhdl-template-field "names" nil t start (point))
9519 (insert " : ")
9520 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9521 (vhdl-template-field "type")
9522 (if in-arglist
9523 (progn (insert ";")
9524 (vhdl-comment-insert-inline))
9525 (let ((position (point)))
9526 (insert " := ")
9527 (unless (vhdl-template-field "[initialization]" nil t)
9528 (delete-region position (point)))
9529 (insert ";")
9530 (vhdl-comment-insert-inline))))))
9531
9532 (defun vhdl-template-subnature ()
9533 "Insert a subnature declaration."
9534 (interactive)
9535 (let ((start (point))
9536 position)
9537 (vhdl-insert-keyword "SUBNATURE ")
9538 (when (vhdl-template-field "name" nil t start (point))
9539 (vhdl-insert-keyword " IS ")
9540 (vhdl-template-field "nature" " (")
9541 (if (vhdl-template-field "[index range]" nil t)
9542 (insert ")")
9543 (delete-char -2))
9544 (setq position (point))
9545 (vhdl-insert-keyword " TOLERANCE ")
9546 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9547 nil t nil nil t))
9548 (delete-region position (point))
9549 (vhdl-insert-keyword " ACROSS ")
9550 (vhdl-template-field "string expression" nil nil nil nil t)
9551 (vhdl-insert-keyword " THROUGH"))
9552 (insert ";")
9553 (vhdl-comment-insert-inline))))
9554
9555 (defun vhdl-template-subprogram-body ()
9556 "Insert a subprogram body."
9557 (interactive)
9558 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9559 (vhdl-template-function-body)
9560 (vhdl-template-procedure-body)))
9561
9562 (defun vhdl-template-subprogram-decl ()
9563 "Insert a subprogram declaration."
9564 (interactive)
9565 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9566 (vhdl-template-function-decl)
9567 (vhdl-template-procedure-decl)))
9568
9569 (defun vhdl-template-subtype ()
9570 "Insert a subtype declaration."
9571 (interactive)
9572 (let ((start (point)))
9573 (vhdl-insert-keyword "SUBTYPE ")
9574 (when (vhdl-template-field "name" nil t start (point))
9575 (vhdl-insert-keyword " IS ")
9576 (vhdl-template-field "type" " ")
9577 (unless
9578 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9579 (delete-char -1))
9580 (insert ";")
9581 (vhdl-comment-insert-inline))))
9582
9583 (defun vhdl-template-terminal ()
9584 "Insert a terminal declaration."
9585 (interactive)
9586 (let ((start (point)))
9587 (vhdl-insert-keyword "TERMINAL ")
9588 (when (vhdl-template-field "names" nil t start (point))
9589 (insert " : ")
9590 (vhdl-template-field "nature")
9591 (insert ";")
9592 (vhdl-comment-insert-inline))))
9593
9594 (defun vhdl-template-type ()
9595 "Insert a type declaration."
9596 (interactive)
9597 (let ((start (point))
9598 name mid-pos end-pos)
9599 (vhdl-insert-keyword "TYPE ")
9600 (when (setq name (vhdl-template-field "name" nil t start (point)))
9601 (vhdl-insert-keyword " IS ")
9602 (let ((definition
9603 (upcase
9604 (or (vhdl-template-field
9605 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9606 ""))))
9607 (cond ((equal definition "")
9608 (delete-backward-char 4)
9609 (insert ";"))
9610 ((equal definition "ARRAY")
9611 (delete-region (point) (progn (forward-word -1) (point)))
9612 (vhdl-template-array 'type t))
9613 ((equal definition "RECORD")
9614 (setq mid-pos (point-marker))
9615 (delete-region (point) (progn (forward-word -1) (point)))
9616 (vhdl-template-record 'type name t))
9617 ((equal definition "ACCESS")
9618 (insert " ")
9619 (vhdl-template-field "type" ";"))
9620 ((equal definition "FILE")
9621 (vhdl-insert-keyword " OF ")
9622 (vhdl-template-field "type" ";"))
9623 (t (insert ";")))
9624 (when mid-pos
9625 (setq end-pos (point-marker))
9626 (goto-char mid-pos)
9627 (end-of-line))
9628 (vhdl-comment-insert-inline)
9629 (when end-pos (goto-char end-pos))))))
9630
9631 (defun vhdl-template-use ()
9632 "Insert a use clause."
9633 (interactive)
9634 (let ((start (point)))
9635 (vhdl-prepare-search-1
9636 (vhdl-insert-keyword "USE ")
9637 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9638 (vhdl-insert-keyword "..ALL;")
9639 (backward-char 6)
9640 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9641 (forward-char 1)
9642 (vhdl-template-field "package name")
9643 (forward-char 5))))))
9644
9645 (defun vhdl-template-variable ()
9646 "Insert a variable declaration."
9647 (interactive)
9648 (let ((start (point))
9649 (in-arglist (vhdl-in-argument-list-p)))
9650 (vhdl-prepare-search-2
9651 (if (or (save-excursion
9652 (and (vhdl-re-search-backward
9653 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9654 nil t)
9655 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9656 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9657 (vhdl-insert-keyword "VARIABLE ")
9658 (vhdl-insert-keyword "SHARED VARIABLE ")))
9659 (when (vhdl-template-field "names" nil t start (point))
9660 (insert " : ")
9661 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9662 (vhdl-template-field "type")
9663 (if in-arglist
9664 (progn (insert ";")
9665 (vhdl-comment-insert-inline))
9666 (let ((position (point)))
9667 (insert " := ")
9668 (unless (vhdl-template-field "[initialization]" nil t)
9669 (delete-region position (point)))
9670 (insert ";")
9671 (vhdl-comment-insert-inline))))))
9672
9673 (defun vhdl-template-wait ()
9674 "Insert a wait statement."
9675 (interactive)
9676 (vhdl-insert-keyword "WAIT ")
9677 (unless (vhdl-template-field
9678 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9679 nil t)
9680 (delete-char -1))
9681 (insert ";"))
9682
9683 (defun vhdl-template-when ()
9684 "Indent correctly if within a case statement."
9685 (interactive)
9686 (let ((position (point))
9687 margin)
9688 (vhdl-prepare-search-2
9689 (if (and (= (current-column) (current-indentation))
9690 (vhdl-re-search-forward "\\<end\\>" nil t)
9691 (looking-at "\\s-*\\<case\\>"))
9692 (progn
9693 (setq margin (current-indentation))
9694 (goto-char position)
9695 (delete-horizontal-space)
9696 (indent-to (+ margin vhdl-basic-offset)))
9697 (goto-char position)))
9698 (vhdl-insert-keyword "WHEN ")))
9699
9700 (defun vhdl-template-while-loop ()
9701 "Insert a while loop."
9702 (interactive)
9703 (let* ((margin (current-indentation))
9704 (start (point))
9705 label)
9706 (if (not (eq vhdl-optional-labels 'all))
9707 (vhdl-insert-keyword "WHILE ")
9708 (vhdl-insert-keyword ": WHILE ")
9709 (goto-char start)
9710 (setq label (vhdl-template-field "[label]" nil t))
9711 (unless label (delete-char 2))
9712 (forward-word 1)
9713 (forward-char 1))
9714 (when vhdl-conditions-in-parenthesis (insert "("))
9715 (when (vhdl-template-field "condition" nil t start (point))
9716 (when vhdl-conditions-in-parenthesis (insert ")"))
9717 (vhdl-insert-keyword " LOOP\n\n")
9718 (indent-to margin)
9719 (vhdl-insert-keyword "END LOOP")
9720 (insert (if label (concat " " label ";") ";"))
9721 (forward-line -1)
9722 (indent-to (+ margin vhdl-basic-offset)))))
9723
9724 (defun vhdl-template-with ()
9725 "Insert a with statement (i.e. selected signal assignment)."
9726 (interactive)
9727 (vhdl-prepare-search-1
9728 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9729 (equal ";" (match-string 1)))
9730 (vhdl-template-selected-signal-asst)
9731 (vhdl-insert-keyword "WITH "))))
9732
9733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9734 ;; Special templates
9735
9736 (defun vhdl-template-clocked-wait ()
9737 "Insert a wait statement for rising/falling clock edge."
9738 (interactive)
9739 (let ((start (point))
9740 clock)
9741 (vhdl-insert-keyword "WAIT UNTIL ")
9742 (when (setq clock
9743 (or (and (not (equal "" vhdl-clock-name))
9744 (progn (insert vhdl-clock-name) vhdl-clock-name))
9745 (vhdl-template-field "clock name" nil t start (point))))
9746 (insert "'event")
9747 (vhdl-insert-keyword " AND ")
9748 (insert clock)
9749 (insert
9750 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9751 (vhdl-comment-insert-inline
9752 (concat (if vhdl-clock-rising-edge "rising" "falling")
9753 " clock edge")))))
9754
9755 (defun vhdl-template-seq-process (clock reset)
9756 "Insert a template for the body of a sequential process."
9757 (let ((margin (current-indentation))
9758 position)
9759 (vhdl-insert-keyword "IF ")
9760 (when (eq vhdl-reset-kind 'async)
9761 (insert reset " = "
9762 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9763 (vhdl-insert-keyword " THEN")
9764 (vhdl-comment-insert-inline
9765 (concat "asynchronous reset (active "
9766 (if vhdl-reset-active-high "high" "low") ")"))
9767 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9768 (setq position (point))
9769 (insert "\n") (indent-to margin)
9770 (vhdl-insert-keyword "ELSIF "))
9771 (if (eq vhdl-clock-edge-condition 'function)
9772 (insert (if vhdl-clock-rising-edge "rising" "falling")
9773 "_edge(" clock ")")
9774 (insert clock "'event")
9775 (vhdl-insert-keyword " AND ")
9776 (insert clock " = "
9777 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9778 (vhdl-insert-keyword " THEN")
9779 (vhdl-comment-insert-inline
9780 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9781 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9782 (when (eq vhdl-reset-kind 'sync)
9783 (vhdl-insert-keyword "IF ")
9784 (setq reset (or (and (not (equal "" vhdl-reset-name))
9785 (progn (insert vhdl-reset-name) vhdl-reset-name))
9786 (vhdl-template-field "reset name") "<reset>"))
9787 (insert " = "
9788 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9789 (vhdl-insert-keyword " THEN")
9790 (vhdl-comment-insert-inline
9791 (concat "synchronous reset (active "
9792 (if vhdl-reset-active-high "high" "low") ")"))
9793 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9794 (setq position (point))
9795 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9796 (vhdl-insert-keyword "ELSE")
9797 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9798 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9799 (vhdl-insert-keyword "END IF;"))
9800 (when (eq vhdl-reset-kind 'none)
9801 (setq position (point)))
9802 (insert "\n") (indent-to margin)
9803 (vhdl-insert-keyword "END IF;")
9804 (goto-char position)
9805 reset))
9806
9807 (defun vhdl-template-standard-package (library package)
9808 "Insert specification of a standard package. Include a library
9809 specification, if not already there."
9810 (let ((margin (current-indentation)))
9811 (unless (equal library "std")
9812 (unless (or (save-excursion
9813 (vhdl-prepare-search-1
9814 (and (not (bobp))
9815 (re-search-backward
9816 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9817 library "\\|end\\)\\>") nil t)
9818 (match-string 2))))
9819 (equal (downcase library) "work"))
9820 (vhdl-insert-keyword "LIBRARY ")
9821 (insert library ";")
9822 (when package
9823 (insert "\n")
9824 (indent-to margin)))
9825 (when package
9826 (vhdl-insert-keyword "USE ")
9827 (insert library "." package)
9828 (vhdl-insert-keyword ".ALL;")))))
9829
9830 (defun vhdl-template-package-math-complex ()
9831 "Insert specification of `math_complex' package."
9832 (interactive)
9833 (vhdl-template-standard-package "ieee" "math_complex"))
9834
9835 (defun vhdl-template-package-math-real ()
9836 "Insert specification of `math_real' package."
9837 (interactive)
9838 (vhdl-template-standard-package "ieee" "math_real"))
9839
9840 (defun vhdl-template-package-numeric-bit ()
9841 "Insert specification of `numeric_bit' package."
9842 (interactive)
9843 (vhdl-template-standard-package "ieee" "numeric_bit"))
9844
9845 (defun vhdl-template-package-numeric-std ()
9846 "Insert specification of `numeric_std' package."
9847 (interactive)
9848 (vhdl-template-standard-package "ieee" "numeric_std"))
9849
9850 (defun vhdl-template-package-std-logic-1164 ()
9851 "Insert specification of `std_logic_1164' package."
9852 (interactive)
9853 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9854
9855 (defun vhdl-template-package-std-logic-arith ()
9856 "Insert specification of `std_logic_arith' package."
9857 (interactive)
9858 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9859
9860 (defun vhdl-template-package-std-logic-misc ()
9861 "Insert specification of `std_logic_misc' package."
9862 (interactive)
9863 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9864
9865 (defun vhdl-template-package-std-logic-signed ()
9866 "Insert specification of `std_logic_signed' package."
9867 (interactive)
9868 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9869
9870 (defun vhdl-template-package-std-logic-textio ()
9871 "Insert specification of `std_logic_textio' package."
9872 (interactive)
9873 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9874
9875 (defun vhdl-template-package-std-logic-unsigned ()
9876 "Insert specification of `std_logic_unsigned' package."
9877 (interactive)
9878 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9879
9880 (defun vhdl-template-package-textio ()
9881 "Insert specification of `textio' package."
9882 (interactive)
9883 (vhdl-template-standard-package "std" "textio"))
9884
9885 (defun vhdl-template-directive (directive)
9886 "Insert directive."
9887 (unless (= (current-indentation) (current-column))
9888 (delete-horizontal-space)
9889 (insert " "))
9890 (insert "-- pragma " directive))
9891
9892 (defun vhdl-template-directive-translate-on ()
9893 "Insert directive 'translate_on'."
9894 (interactive)
9895 (vhdl-template-directive "translate_on"))
9896
9897 (defun vhdl-template-directive-translate-off ()
9898 "Insert directive 'translate_off'."
9899 (interactive)
9900 (vhdl-template-directive "translate_off"))
9901
9902 (defun vhdl-template-directive-synthesis-on ()
9903 "Insert directive 'synthesis_on'."
9904 (interactive)
9905 (vhdl-template-directive "synthesis_on"))
9906
9907 (defun vhdl-template-directive-synthesis-off ()
9908 "Insert directive 'synthesis_off'."
9909 (interactive)
9910 (vhdl-template-directive "synthesis_off"))
9911
9912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9913 ;; Header and footer templates
9914
9915 (defun vhdl-template-header (&optional file-title)
9916 "Insert a VHDL file header."
9917 (interactive)
9918 (unless (equal vhdl-file-header "")
9919 (let (pos)
9920 (save-excursion
9921 (goto-char (point-min))
9922 (vhdl-insert-string-or-file vhdl-file-header)
9923 (setq pos (point-marker)))
9924 (vhdl-template-replace-header-keywords
9925 (point-min-marker) pos file-title))))
9926
9927 (defun vhdl-template-footer ()
9928 "Insert a VHDL file footer."
9929 (interactive)
9930 (unless (equal vhdl-file-footer "")
9931 (let (pos)
9932 (save-excursion
9933 (goto-char (point-max))
9934 (setq pos (point-marker))
9935 (vhdl-insert-string-or-file vhdl-file-footer)
9936 (unless (= (preceding-char) ?\n)
9937 (insert "\n")))
9938 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9939
9940 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9941 is-model)
9942 "Replace keywords in header and footer."
9943 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9944 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9945 pos)
9946 (vhdl-prepare-search-2
9947 (save-excursion
9948 (goto-char beg)
9949 (while (search-forward "<projectdesc>" end t)
9950 (replace-match project-desc t t))
9951 (goto-char beg)
9952 (while (search-forward "<filename>" end t)
9953 (replace-match (buffer-name) t t))
9954 (goto-char beg)
9955 (while (search-forward "<copyright>" end t)
9956 (replace-match vhdl-copyright-string t t))
9957 (goto-char beg)
9958 (while (search-forward "<author>" end t)
9959 (replace-match "" t t)
9960 (insert (user-full-name))
9961 (when user-mail-address (insert " <" user-mail-address ">")))
9962 (goto-char beg)
9963 (while (search-forward "<login>" end t)
9964 (replace-match (user-login-name) t t))
9965 (goto-char beg)
9966 (while (search-forward "<project>" end t)
9967 (replace-match project-title t t))
9968 (goto-char beg)
9969 (while (search-forward "<company>" end t)
9970 (replace-match vhdl-company-name t t))
9971 (goto-char beg)
9972 (while (search-forward "<platform>" end t)
9973 (replace-match vhdl-platform-spec t t))
9974 (goto-char beg)
9975 (while (search-forward "<standard>" end t)
9976 (replace-match
9977 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9978 ((vhdl-standard-p '93) "'93"))
9979 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9980 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9981 (goto-char beg)
9982 ;; Replace <RCS> with $, so that RCS for the source is
9983 ;; not over-enthusiastic with replacements
9984 (while (search-forward "<RCS>" end t)
9985 (replace-match "$" nil t))
9986 (goto-char beg)
9987 (while (search-forward "<date>" end t)
9988 (replace-match "" t t)
9989 (vhdl-template-insert-date))
9990 (goto-char beg)
9991 (while (search-forward "<year>" end t)
9992 (replace-match (format-time-string "%Y" nil) t t))
9993 (goto-char beg)
9994 (when file-title
9995 (while (search-forward "<title string>" end t)
9996 (replace-match file-title t t))
9997 (goto-char beg))
9998 (let (string)
9999 (while
10000 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10001 (setq string (read-string (concat (match-string 1) ": ")))
10002 (replace-match string t t)))
10003 (goto-char beg)
10004 (when (and (not is-model) (search-forward "<cursor>" end t))
10005 (replace-match "" t t)
10006 (setq pos (point))))
10007 (when pos (goto-char pos))
10008 (unless is-model
10009 (when (or (not project-title) (equal project-title ""))
10010 (message "You can specify a project title in user option `vhdl-project-alist'"))
10011 (when (or (not project-desc) (equal project-desc ""))
10012 (message "You can specify a project description in user option `vhdl-project-alist'"))
10013 (when (equal vhdl-platform-spec "")
10014 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10015 (when (equal vhdl-company-name "")
10016 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10017
10018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10019 ;; Comment templates and functions
10020
10021 (defun vhdl-comment-indent ()
10022 "Indent comments."
10023 (let* ((position (point))
10024 (col
10025 (progn
10026 (forward-line -1)
10027 (if (re-search-forward "--" position t)
10028 (- (current-column) 2) ; existing comment at bol stays there
10029 (goto-char position)
10030 (skip-chars-backward " \t")
10031 (max comment-column ; else indent to comment column
10032 (1+ (current-column))))))) ; except leave at least one space
10033 (goto-char position)
10034 col))
10035
10036 (defun vhdl-comment-insert ()
10037 "Start a comment at the end of the line.
10038 If on line with code, indent at least `comment-column'.
10039 If starting after end-comment-column, start a new line."
10040 (interactive)
10041 (when (> (current-column) end-comment-column) (newline-and-indent))
10042 (if (or (looking-at "\\s-*$") ; end of line
10043 (and (not unread-command-events) ; called with key binding or menu
10044 (not (end-of-line))))
10045 (let (margin)
10046 (while (= (preceding-char) ?-) (delete-char -1))
10047 (setq margin (current-column))
10048 (delete-horizontal-space)
10049 (if (bolp)
10050 (progn (indent-to margin) (insert "--"))
10051 (insert " ")
10052 (indent-to comment-column)
10053 (insert "--"))
10054 (if (not unread-command-events) (insert " ")))
10055 ;; else code following current point implies commenting out code
10056 (let (next-input code)
10057 (while (= (preceding-char) ?-) (delete-char -2))
10058 (while (= (setq next-input (read-char)) 13) ; CR
10059 (insert "--") ; or have a space after it?
10060 (forward-char -2)
10061 (forward-line 1)
10062 (message "Enter CR if commenting out a line of code.")
10063 (setq code t))
10064 (unless code
10065 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10066 (setq unread-command-events
10067 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10068
10069 (defun vhdl-comment-display (&optional line-exists)
10070 "Add 2 comment lines at the current indent, making a display comment."
10071 (interactive)
10072 (let ((margin (current-indentation)))
10073 (unless line-exists (vhdl-comment-display-line))
10074 (insert "\n") (indent-to margin)
10075 (insert "\n") (indent-to margin)
10076 (vhdl-comment-display-line)
10077 (end-of-line -0)
10078 (insert "-- ")))
10079
10080 (defun vhdl-comment-display-line ()
10081 "Displays one line of dashes."
10082 (interactive)
10083 (while (= (preceding-char) ?-) (delete-char -2))
10084 (let* ((col (current-column))
10085 (len (- end-comment-column col)))
10086 (insert-char ?- len)))
10087
10088 (defun vhdl-comment-append-inline ()
10089 "Append empty inline comment to current line."
10090 (interactive)
10091 (end-of-line)
10092 (delete-horizontal-space)
10093 (insert " ")
10094 (indent-to comment-column)
10095 (insert "-- "))
10096
10097 (defun vhdl-comment-insert-inline (&optional string always-insert)
10098 "Insert inline comment."
10099 (when (or (and string (or vhdl-self-insert-comments always-insert))
10100 (and (not string) vhdl-prompt-for-comments))
10101 (let ((position (point)))
10102 (insert " ")
10103 (indent-to comment-column)
10104 (insert "-- ")
10105 (if (not (or (and string (progn (insert string) t))
10106 (vhdl-template-field "[comment]" nil t)))
10107 (delete-region position (point))
10108 (while (= (preceding-char) ? ) (delete-backward-char 1))
10109 ; (when (> (current-column) end-comment-column)
10110 ; (setq position (point-marker))
10111 ; (re-search-backward "-- ")
10112 ; (insert "\n")
10113 ; (indent-to comment-column)
10114 ; (goto-char position))
10115 ))))
10116
10117 (defun vhdl-comment-block ()
10118 "Insert comment for code block."
10119 (when vhdl-prompt-for-comments
10120 (let ((final-pos (point-marker)))
10121 (vhdl-prepare-search-2
10122 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10123 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10124 (let (margin)
10125 (back-to-indentation)
10126 (setq margin (current-column))
10127 (end-of-line -0)
10128 (if (bobp)
10129 (progn (insert "\n") (forward-line -1))
10130 (insert "\n"))
10131 (indent-to margin)
10132 (insert "-- purpose: ")
10133 (unless (vhdl-template-field "[description]" nil t)
10134 (vhdl-line-kill-entire)))))
10135 (goto-char final-pos))))
10136
10137 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10138 "Comment out region if not commented out, uncomment otherwise."
10139 (interactive "r\nP")
10140 (save-excursion
10141 (goto-char (1- end))
10142 (end-of-line)
10143 (setq end (point-marker))
10144 (goto-char beg)
10145 (beginning-of-line)
10146 (setq beg (point))
10147 (if (looking-at comment-start)
10148 (comment-region beg end '(4))
10149 (comment-region beg end))))
10150
10151 (defun vhdl-comment-uncomment-line (&optional arg)
10152 "Comment out line if not commented out, uncomment otherwise."
10153 (interactive "p")
10154 (save-excursion
10155 (beginning-of-line)
10156 (let ((position (point)))
10157 (forward-line (or arg 1))
10158 (vhdl-comment-uncomment-region position (point)))))
10159
10160 (defun vhdl-comment-kill-region (beg end)
10161 "Kill comments in region."
10162 (interactive "r")
10163 (save-excursion
10164 (goto-char end)
10165 (setq end (point-marker))
10166 (goto-char beg)
10167 (beginning-of-line)
10168 (while (< (point) end)
10169 (if (looking-at "^\\(\\s-*--.*\n\\)")
10170 (progn (delete-region (match-beginning 1) (match-end 1)))
10171 (beginning-of-line 2)))))
10172
10173 (defun vhdl-comment-kill-inline-region (beg end)
10174 "Kill inline comments in region."
10175 (interactive "r")
10176 (save-excursion
10177 (goto-char end)
10178 (setq end (point-marker))
10179 (goto-char beg)
10180 (beginning-of-line)
10181 (while (< (point) end)
10182 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10183 (delete-region (match-beginning 1) (match-end 1)))
10184 (beginning-of-line 2))))
10185
10186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10187 ;; Subtemplates
10188
10189 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10190 "Insert a begin ... end pair with optional name after the end.
10191 Point is left between them."
10192 (let (position)
10193 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10194 (indent-to margin)
10195 (vhdl-insert-keyword "BEGIN")
10196 (when (and (or construct name) vhdl-self-insert-comments)
10197 (insert " --")
10198 (when construct (insert " ") (vhdl-insert-keyword construct))
10199 (when name (insert " " name)))
10200 (insert "\n")
10201 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10202 (indent-to (+ margin vhdl-basic-offset))
10203 (setq position (point))
10204 (insert "\n")
10205 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10206 (indent-to margin)
10207 (vhdl-insert-keyword "END")
10208 (when construct (insert " ") (vhdl-insert-keyword construct))
10209 (insert (if name (concat " " name) "") ";")
10210 (goto-char position)))
10211
10212 (defun vhdl-template-argument-list (&optional is-function)
10213 "Read from user a procedure or function argument list."
10214 (insert " (")
10215 (let ((margin (current-column))
10216 (start (point))
10217 (end-pos (point))
10218 not-empty interface semicolon-pos)
10219 (unless vhdl-argument-list-indent
10220 (setq margin (+ (current-indentation) vhdl-basic-offset))
10221 (insert "\n")
10222 (indent-to margin))
10223 (setq interface (vhdl-template-field
10224 (concat "[CONSTANT | SIGNAL"
10225 (unless is-function " | VARIABLE") "]") " " t))
10226 (while (vhdl-template-field "[names]" nil t)
10227 (setq not-empty t)
10228 (insert " : ")
10229 (unless is-function
10230 (if (and interface (equal (upcase interface) "CONSTANT"))
10231 (vhdl-insert-keyword "IN ")
10232 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10233 (vhdl-template-field "type")
10234 (setq semicolon-pos (point))
10235 (insert ";")
10236 (vhdl-comment-insert-inline)
10237 (setq end-pos (point))
10238 (insert "\n")
10239 (indent-to margin)
10240 (setq interface (vhdl-template-field
10241 (concat "[CONSTANT | SIGNAL"
10242 (unless is-function " | VARIABLE") "]") " " t)))
10243 (delete-region end-pos (point))
10244 (when semicolon-pos (goto-char semicolon-pos))
10245 (if not-empty
10246 (progn (delete-char 1) (insert ")"))
10247 (delete-backward-char 2))))
10248
10249 (defun vhdl-template-generic-list (optional &optional no-value)
10250 "Read from user a generic spec argument list."
10251 (let (margin
10252 (start (point)))
10253 (vhdl-insert-keyword "GENERIC (")
10254 (setq margin (current-column))
10255 (unless vhdl-argument-list-indent
10256 (let ((position (point)))
10257 (back-to-indentation)
10258 (setq margin (+ (current-column) vhdl-basic-offset))
10259 (goto-char position)
10260 (insert "\n")
10261 (indent-to margin)))
10262 (let ((vhdl-generics (vhdl-template-field
10263 (concat (and optional "[") "name"
10264 (and no-value "s") (and optional "]"))
10265 nil optional)))
10266 (if (not vhdl-generics)
10267 (if optional
10268 (progn (vhdl-line-kill-entire) (end-of-line -0)
10269 (unless vhdl-argument-list-indent
10270 (vhdl-line-kill-entire) (end-of-line -0)))
10271 (vhdl-template-undo start (point))
10272 nil )
10273 (insert " : ")
10274 (let (semicolon-pos end-pos)
10275 (while vhdl-generics
10276 (vhdl-template-field "type")
10277 (if no-value
10278 (progn (setq semicolon-pos (point))
10279 (insert ";"))
10280 (insert " := ")
10281 (unless (vhdl-template-field "[value]" nil t)
10282 (delete-char -4))
10283 (setq semicolon-pos (point))
10284 (insert ";"))
10285 (vhdl-comment-insert-inline)
10286 (setq end-pos (point))
10287 (insert "\n")
10288 (indent-to margin)
10289 (setq vhdl-generics (vhdl-template-field
10290 (concat "[name" (and no-value "s") "]")
10291 " : " t)))
10292 (delete-region end-pos (point))
10293 (goto-char semicolon-pos)
10294 (insert ")")
10295 (end-of-line)
10296 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10297 t)))))
10298
10299 (defun vhdl-template-port-list (optional)
10300 "Read from user a port spec argument list."
10301 (let ((start (point))
10302 margin vhdl-ports object)
10303 (vhdl-insert-keyword "PORT (")
10304 (setq margin (current-column))
10305 (unless vhdl-argument-list-indent
10306 (let ((position (point)))
10307 (back-to-indentation)
10308 (setq margin (+ (current-column) vhdl-basic-offset))
10309 (goto-char position)
10310 (insert "\n")
10311 (indent-to margin)))
10312 (when (vhdl-standard-p 'ams)
10313 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10314 " " t)))
10315 (setq vhdl-ports (vhdl-template-field
10316 (concat (and optional "[") "names" (and optional "]"))
10317 nil optional))
10318 (if (not vhdl-ports)
10319 (if optional
10320 (progn (vhdl-line-kill-entire) (end-of-line -0)
10321 (unless vhdl-argument-list-indent
10322 (vhdl-line-kill-entire) (end-of-line -0)))
10323 (vhdl-template-undo start (point))
10324 nil)
10325 (insert " : ")
10326 (let (semicolon-pos end-pos)
10327 (while vhdl-ports
10328 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10329 (vhdl-template-field "IN | OUT | INOUT" " "))
10330 ((equal "QUANTITY" (upcase object))
10331 (vhdl-template-field "[IN | OUT]" " " t)))
10332 (vhdl-template-field
10333 (if (and object (equal "TERMINAL" (upcase object)))
10334 "nature" "type"))
10335 (setq semicolon-pos (point))
10336 (insert ";")
10337 (vhdl-comment-insert-inline)
10338 (setq end-pos (point))
10339 (insert "\n")
10340 (indent-to margin)
10341 (when (vhdl-standard-p 'ams)
10342 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10343 " " t)))
10344 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10345 (delete-region end-pos (point))
10346 (goto-char semicolon-pos)
10347 (insert ")")
10348 (end-of-line)
10349 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10350 t))))
10351
10352 (defun vhdl-template-generate-body (margin label)
10353 "Insert body for generate template."
10354 (vhdl-insert-keyword " GENERATE")
10355 ; (if (not (vhdl-standard-p '87))
10356 ; (vhdl-template-begin-end "GENERATE" label margin)
10357 (insert "\n\n")
10358 (indent-to margin)
10359 (vhdl-insert-keyword "END GENERATE ")
10360 (insert label ";")
10361 (end-of-line 0)
10362 (indent-to (+ margin vhdl-basic-offset)))
10363
10364 (defun vhdl-template-insert-date ()
10365 "Insert date in appropriate format."
10366 (interactive)
10367 (insert
10368 (cond
10369 ;; 'american, 'european, 'scientific kept for backward compatibility
10370 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10371 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10372 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10373 (t (format-time-string vhdl-date-format nil)))))
10374
10375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10376 ;; Help functions
10377
10378 (defun vhdl-electric-space (count)
10379 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10380 if in comment and past end-comment-column."
10381 (interactive "p")
10382 (cond ((vhdl-in-comment-p)
10383 (self-insert-command count)
10384 (cond ((>= (current-column) (+ 2 end-comment-column))
10385 (backward-char 1)
10386 (skip-chars-backward "^ \t\n")
10387 (indent-new-comment-line)
10388 (skip-chars-forward "^ \t\n")
10389 (forward-char 1))
10390 ((>= (current-column) end-comment-column)
10391 (indent-new-comment-line))
10392 (t nil)))
10393 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10394 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10395 (vhdl-prepare-search-1
10396 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10397 (self-insert-command count))
10398 (t (self-insert-command count))))
10399
10400 (defun vhdl-template-field (prompt &optional follow-string optional
10401 begin end is-string default)
10402 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10403 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10404 an empty string is inserted, return nil and call `vhdl-template-undo' for
10405 the region between BEGIN and END. IS-STRING indicates whether a string
10406 with double-quotes is to be inserted. DEFAULT specifies a default string."
10407 (let ((position (point))
10408 string)
10409 (insert "<" prompt ">")
10410 (setq string
10411 (condition-case ()
10412 (read-from-minibuffer (concat prompt ": ")
10413 (or (and is-string '("\"\"" . 2)) default)
10414 vhdl-minibuffer-local-map)
10415 (quit (if (and optional begin end)
10416 (progn (beep) "")
10417 (keyboard-quit)))))
10418 (when (or (not (equal string "")) optional)
10419 (delete-region position (point)))
10420 (when (and (equal string "") optional begin end)
10421 (vhdl-template-undo begin end)
10422 (message "Template aborted"))
10423 (unless (equal string "")
10424 (insert string)
10425 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10426 vhdl-keywords-regexp)
10427 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10428 vhdl-types-regexp)
10429 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10430 (concat "'" vhdl-attributes-regexp))
10431 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10432 vhdl-enum-values-regexp))
10433 (when (or (not (equal string "")) (not optional))
10434 (insert (or follow-string "")))
10435 (if (equal string "") nil string)))
10436
10437 (defun vhdl-decision-query (string prompt &optional optional)
10438 "Query a decision from the user."
10439 (let ((start (point)))
10440 (when string (vhdl-insert-keyword (concat string " ")))
10441 (message "%s" (or prompt ""))
10442 (let ((char (read-char)))
10443 (delete-region start (point))
10444 (if (and optional (eq char ?\r))
10445 (progn (insert " ")
10446 (unexpand-abbrev)
10447 (throw 'abort "ERROR: Template aborted"))
10448 char))))
10449
10450 (defun vhdl-insert-keyword (keyword)
10451 "Insert KEYWORD and adjust case."
10452 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10453
10454 (defun vhdl-case-keyword (keyword)
10455 "Adjust case of KEYWORD."
10456 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10457
10458 (defun vhdl-case-word (num)
10459 "Adjust case of following NUM words."
10460 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10461
10462 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10463 "If preceeding character is part of a word or a paren then hippie-expand,
10464 else insert tab (used for word completion in VHDL minibuffer)."
10465 (interactive "P")
10466 (cond
10467 ;; expand word
10468 ((= (char-syntax (preceding-char)) ?w)
10469 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10470 (case-replace nil)
10471 (hippie-expand-only-buffers
10472 (or (and (boundp 'hippie-expand-only-buffers)
10473 hippie-expand-only-buffers)
10474 '(vhdl-mode))))
10475 (vhdl-expand-abbrev prefix-arg)))
10476 ;; expand parenthesis
10477 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10478 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10479 (case-replace nil))
10480 (vhdl-expand-paren prefix-arg)))
10481 ;; insert tab
10482 (t (insert-tab))))
10483
10484 (defun vhdl-template-search-prompt ()
10485 "Search for left out template prompts and query again."
10486 (interactive)
10487 (vhdl-prepare-search-2
10488 (when (or (re-search-forward
10489 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10490 (re-search-backward
10491 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10492 (let ((string (match-string 1)))
10493 (replace-match "")
10494 (vhdl-template-field string)))))
10495
10496 (defun vhdl-template-undo (begin end)
10497 "Undo aborted template by deleting region and unexpanding the keyword."
10498 (cond (vhdl-template-invoked-by-hook
10499 (goto-char end)
10500 (insert " ")
10501 (delete-region begin end)
10502 (unexpand-abbrev))
10503 (t (delete-region begin end))))
10504
10505 (defun vhdl-insert-string-or-file (string)
10506 "Insert STRING or file contents if STRING is an existing file name."
10507 (unless (equal string "")
10508 (let ((file-name
10509 (progn (string-match "^\\([^\n]+\\)" string)
10510 (vhdl-resolve-env-variable (match-string 1 string)))))
10511 (if (file-exists-p file-name)
10512 (forward-char (cadr (insert-file-contents file-name)))
10513 (insert string)))))
10514
10515 (defun vhdl-beginning-of-block ()
10516 "Move cursor to the beginning of the enclosing block."
10517 (let (pos)
10518 (save-excursion
10519 (beginning-of-line)
10520 ;; search backward for block beginning or end
10521 (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))
10522 ;; not consider subprogram declarations
10523 (or (and (match-string 5)
10524 (save-match-data
10525 (save-excursion
10526 (goto-char (match-end 5))
10527 (forward-word 1)
10528 (vhdl-forward-syntactic-ws)
10529 (when (looking-at "(")
10530 (forward-sexp))
10531 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10532 (match-string 1)))
10533 ;; not consider configuration specifications
10534 (and (match-string 6)
10535 (save-match-data
10536 (save-excursion
10537 (vhdl-end-of-block)
10538 (beginning-of-line)
10539 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10540 (match-string 2))
10541 ;; skip subblock if block end found
10542 (vhdl-beginning-of-block)))
10543 (when pos (goto-char pos))))
10544
10545 (defun vhdl-end-of-block ()
10546 "Move cursor to the end of the enclosing block."
10547 (let (pos)
10548 (save-excursion
10549 (end-of-line)
10550 ;; search forward for block beginning or end
10551 (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))
10552 ;; not consider subprogram declarations
10553 (or (and (match-string 5)
10554 (save-match-data
10555 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10556 (match-string 1)))
10557 ;; not consider configuration specifications
10558 (and (match-string 6)
10559 (save-match-data
10560 (save-excursion
10561 (vhdl-end-of-block)
10562 (beginning-of-line)
10563 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10564 (not (match-string 2)))
10565 ;; skip subblock if block beginning found
10566 (vhdl-end-of-block)))
10567 (when pos (goto-char pos))))
10568
10569 (defun vhdl-sequential-statement-p ()
10570 "Check if point is within sequential statement part."
10571 (let ((start (point)))
10572 (save-excursion
10573 (vhdl-prepare-search-2
10574 ;; is sequential statement if ...
10575 (and (re-search-backward "^\\s-*begin\\>" nil t)
10576 ;; ... point is between "begin" and "end" of ...
10577 (progn (vhdl-end-of-block)
10578 (< start (point)))
10579 ;; ... a sequential block
10580 (progn (vhdl-beginning-of-block)
10581 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10582
10583 (defun vhdl-in-argument-list-p ()
10584 "Check if within an argument list."
10585 (save-excursion
10586 (vhdl-prepare-search-2
10587 (or (string-match "arglist"
10588 (format "%s" (caar (vhdl-get-syntactic-context))))
10589 (progn (beginning-of-line)
10590 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10591
10592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10593 ;; Abbrev hooks
10594
10595 (defun vhdl-hooked-abbrev (func)
10596 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10597 but not if inside a comment or quote."
10598 (if (or (vhdl-in-literal)
10599 (save-excursion
10600 (forward-word -1)
10601 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10602 (progn
10603 (insert " ")
10604 (unexpand-abbrev)
10605 (delete-char -1))
10606 (if (not vhdl-electric-mode)
10607 (progn
10608 (insert " ")
10609 (unexpand-abbrev)
10610 (backward-word 1)
10611 (vhdl-case-word 1)
10612 (delete-char 1))
10613 (let ((invoke-char last-command-char)
10614 (abbrev-mode -1)
10615 (vhdl-template-invoked-by-hook t))
10616 (let ((caught (catch 'abort
10617 (funcall func))))
10618 (when (stringp caught) (message "%s" caught)))
10619 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10620 ;; delete CR which is still in event queue
10621 (if (fboundp 'enqueue-eval-event)
10622 (enqueue-eval-event 'delete-char -1)
10623 (setq unread-command-events ; push back a delete char
10624 (list (vhdl-character-to-event ?\177))))))))
10625
10626 (defun vhdl-template-alias-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-alias))
10628 (defun vhdl-template-architecture-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10630 (defun vhdl-template-assert-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-assert))
10632 (defun vhdl-template-attribute-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10634 (defun vhdl-template-block-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-block))
10636 (defun vhdl-template-break-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-break))
10638 (defun vhdl-template-case-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-case))
10640 (defun vhdl-template-component-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-component))
10642 (defun vhdl-template-instance-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-instance))
10644 (defun vhdl-template-conditional-signal-asst-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10646 (defun vhdl-template-configuration-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10648 (defun vhdl-template-constant-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-constant))
10650 (defun vhdl-template-disconnect-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10652 (defun vhdl-template-display-comment-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-comment-display))
10654 (defun vhdl-template-else-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-else))
10656 (defun vhdl-template-elsif-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10658 (defun vhdl-template-entity-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-entity))
10660 (defun vhdl-template-exit-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-exit))
10662 (defun vhdl-template-file-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-file))
10664 (defun vhdl-template-for-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-for))
10666 (defun vhdl-template-function-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-function))
10668 (defun vhdl-template-generic-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-generic))
10670 (defun vhdl-template-group-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-group))
10672 (defun vhdl-template-library-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-library))
10674 (defun vhdl-template-limit-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-limit))
10676 (defun vhdl-template-if-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-if))
10678 (defun vhdl-template-bare-loop-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10680 (defun vhdl-template-map-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-map))
10682 (defun vhdl-template-nature-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-nature))
10684 (defun vhdl-template-next-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-next))
10686 (defun vhdl-template-others-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-others))
10688 (defun vhdl-template-package-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-package))
10690 (defun vhdl-template-port-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-port))
10692 (defun vhdl-template-procedural-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10694 (defun vhdl-template-procedure-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10696 (defun vhdl-template-process-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-process))
10698 (defun vhdl-template-quantity-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10700 (defun vhdl-template-report-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-report))
10702 (defun vhdl-template-return-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-return))
10704 (defun vhdl-template-selected-signal-asst-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10706 (defun vhdl-template-signal-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-signal))
10708 (defun vhdl-template-subnature-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10710 (defun vhdl-template-subtype-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10712 (defun vhdl-template-terminal-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10714 (defun vhdl-template-type-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-type))
10716 (defun vhdl-template-use-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-use))
10718 (defun vhdl-template-variable-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-variable))
10720 (defun vhdl-template-wait-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-wait))
10722 (defun vhdl-template-when-hook ()
10723 (vhdl-hooked-abbrev 'vhdl-template-when))
10724 (defun vhdl-template-while-loop-hook ()
10725 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10726 (defun vhdl-template-with-hook ()
10727 (vhdl-hooked-abbrev 'vhdl-template-with))
10728 (defun vhdl-template-and-hook ()
10729 (vhdl-hooked-abbrev 'vhdl-template-and))
10730 (defun vhdl-template-or-hook ()
10731 (vhdl-hooked-abbrev 'vhdl-template-or))
10732 (defun vhdl-template-nand-hook ()
10733 (vhdl-hooked-abbrev 'vhdl-template-nand))
10734 (defun vhdl-template-nor-hook ()
10735 (vhdl-hooked-abbrev 'vhdl-template-nor))
10736 (defun vhdl-template-xor-hook ()
10737 (vhdl-hooked-abbrev 'vhdl-template-xor))
10738 (defun vhdl-template-xnor-hook ()
10739 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10740 (defun vhdl-template-not-hook ()
10741 (vhdl-hooked-abbrev 'vhdl-template-not))
10742
10743 (defun vhdl-template-default-hook ()
10744 (vhdl-hooked-abbrev 'vhdl-template-default))
10745 (defun vhdl-template-default-indent-hook ()
10746 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10747
10748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10749 ;; Template insertion from completion list
10750
10751 (defun vhdl-template-insert-construct (name)
10752 "Insert the built-in construct template with NAME."
10753 (interactive
10754 (list (let ((completion-ignore-case t))
10755 (completing-read "Construct name: "
10756 vhdl-template-construct-alist nil t))))
10757 (vhdl-template-insert-fun
10758 (cadr (assoc name vhdl-template-construct-alist))))
10759
10760 (defun vhdl-template-insert-package (name)
10761 "Insert the built-in package template with NAME."
10762 (interactive
10763 (list (let ((completion-ignore-case t))
10764 (completing-read "Package name: "
10765 vhdl-template-package-alist nil t))))
10766 (vhdl-template-insert-fun
10767 (cadr (assoc name vhdl-template-package-alist))))
10768
10769 (defun vhdl-template-insert-directive (name)
10770 "Insert the built-in directive template with NAME."
10771 (interactive
10772 (list (let ((completion-ignore-case t))
10773 (completing-read "Directive name: "
10774 vhdl-template-directive-alist nil t))))
10775 (vhdl-template-insert-fun
10776 (cadr (assoc name vhdl-template-directive-alist))))
10777
10778 (defun vhdl-template-insert-fun (fun)
10779 "Call FUN to insert a built-in template."
10780 (let ((caught (catch 'abort (when fun (funcall fun)))))
10781 (when (stringp caught) (message "%s" caught))))
10782
10783
10784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10785 ;;; Models
10786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10787
10788 (defun vhdl-model-insert (model-name)
10789 "Insert the user model with name MODEL-NAME."
10790 (interactive
10791 (let ((completion-ignore-case t))
10792 (list (completing-read "Model name: " vhdl-model-alist))))
10793 (indent-according-to-mode)
10794 (let ((start (point-marker))
10795 (margin (current-indentation))
10796 model position prompt string end)
10797 (vhdl-prepare-search-2
10798 (when (setq model (assoc model-name vhdl-model-alist))
10799 ;; insert model
10800 (beginning-of-line)
10801 (delete-horizontal-space)
10802 (goto-char start)
10803 (vhdl-insert-string-or-file (nth 1 model))
10804 (setq end (point-marker))
10805 ;; indent code
10806 (goto-char start)
10807 (beginning-of-line)
10808 (while (< (point) end)
10809 (unless (looking-at "^$")
10810 (insert-char ? margin))
10811 (beginning-of-line 2))
10812 (goto-char start)
10813 ;; insert clock
10814 (unless (equal "" vhdl-clock-name)
10815 (while (re-search-forward "<clock>" end t)
10816 (replace-match vhdl-clock-name)))
10817 (goto-char start)
10818 ;; insert reset
10819 (unless (equal "" vhdl-reset-name)
10820 (while (re-search-forward "<reset>" end t)
10821 (replace-match vhdl-reset-name)))
10822 ;; replace header prompts
10823 (vhdl-template-replace-header-keywords start end nil t)
10824 (goto-char start)
10825 ;; query other prompts
10826 (while (re-search-forward
10827 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10828 (unless (equal "cursor" (match-string 1))
10829 (setq position (match-beginning 1))
10830 (setq prompt (match-string 1))
10831 (replace-match "")
10832 (setq string (vhdl-template-field prompt nil t))
10833 ;; replace occurrences of same prompt
10834 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10835 (replace-match (or string "")))
10836 (goto-char position)))
10837 (goto-char start)
10838 ;; goto final position
10839 (if (re-search-forward "<cursor>" end t)
10840 (replace-match "")
10841 (goto-char end))))))
10842
10843 (defun vhdl-model-defun ()
10844 "Define help and hook functions for user models."
10845 (let ((model-alist vhdl-model-alist)
10846 model-name model-keyword)
10847 (while model-alist
10848 ;; define functions for user models that can be invoked from menu and key
10849 ;; bindings and which themselves call `vhdl-model-insert' with the model
10850 ;; name as argument
10851 (setq model-name (nth 0 (car model-alist)))
10852 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10853 ,(concat "Insert model for \"" model-name "\".")
10854 (interactive)
10855 (vhdl-model-insert ,model-name)))
10856 ;; define hooks for user models that are invoked from keyword abbrevs
10857 (setq model-keyword (nth 3 (car model-alist)))
10858 (unless (equal model-keyword "")
10859 (eval `(defun
10860 ,(vhdl-function-name
10861 "vhdl-model" model-name "hook") ()
10862 (vhdl-hooked-abbrev
10863 ',(vhdl-function-name "vhdl-model" model-name)))))
10864 (setq model-alist (cdr model-alist)))))
10865
10866 (vhdl-model-defun)
10867
10868
10869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10870 ;;; Port translation
10871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10872
10873 (defvar vhdl-port-list nil
10874 "Variable to hold last port map parsed.")
10875 ;; structure: (parenthesised expression means list of such entries)
10876 ;; (ent-name
10877 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10878 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10879 ;; (lib-name pack-key))
10880
10881 (defun vhdl-parse-string (string &optional optional)
10882 "Check that the text following point matches the regexp in STRING."
10883 (if (looking-at string)
10884 (goto-char (match-end 0))
10885 (unless optional
10886 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10887 (vhdl-current-line) string)))
10888 nil))
10889
10890 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10891 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10892 (vhdl-prepare-search-1
10893 (if (string-match (car regexp-cons) string)
10894 (if adjust-case
10895 (funcall vhdl-file-name-case
10896 (replace-match (cdr regexp-cons) t nil string))
10897 (replace-match (cdr regexp-cons) t nil string))
10898 string)))
10899
10900 (defun vhdl-parse-group-comment ()
10901 "Parse comment and empty lines between groups of lines."
10902 (let ((start (point))
10903 string)
10904 (vhdl-forward-comment (point-max))
10905 (setq string (buffer-substring-no-properties start (point)))
10906 (vhdl-forward-syntactic-ws)
10907 ;; strip off leading blanks and first newline
10908 (while (string-match "^\\(\\s-+\\)" string)
10909 (setq string (concat (substring string 0 (match-beginning 1))
10910 (substring string (match-end 1)))))
10911 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10912 (substring string 1)
10913 string)))
10914
10915 (defun vhdl-paste-group-comment (string indent)
10916 "Paste comment and empty lines from STRING between groups of lines
10917 with INDENT."
10918 (let ((pos (point-marker)))
10919 (when (> indent 0)
10920 (while (string-match "^\\(--\\)" string)
10921 (setq string (concat (substring string 0 (match-beginning 1))
10922 (make-string indent ? )
10923 (substring string (match-beginning 1))))))
10924 (beginning-of-line)
10925 (insert string)
10926 (goto-char pos)))
10927
10928 (defvar vhdl-port-flattened nil
10929 "Indicates whether a port has been flattened.")
10930
10931 (defun vhdl-port-flatten (&optional as-alist)
10932 "Flatten port list so that only one generic/port exists per line.
10933 This operation is performed on an internally stored port and is only
10934 reflected in a subsequent paste operation."
10935 (interactive)
10936 (if (not vhdl-port-list)
10937 (error "ERROR: No port has been read")
10938 (message "Flattening port for next paste...")
10939 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10940 (old-vhdl-port-list (cdr vhdl-port-list))
10941 old-port-list new-port-list old-port new-port names)
10942 ;; traverse port list and flatten entries
10943 (while (cdr old-vhdl-port-list)
10944 (setq old-port-list (car old-vhdl-port-list))
10945 (setq new-port-list nil)
10946 (while old-port-list
10947 (setq old-port (car old-port-list))
10948 (setq names (car old-port))
10949 (while names
10950 (setq new-port (cons (if as-alist (car names) (list (car names)))
10951 (cdr old-port)))
10952 (setq new-port-list (append new-port-list (list new-port)))
10953 (setq names (cdr names)))
10954 (setq old-port-list (cdr old-port-list)))
10955 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10956 (setq new-vhdl-port-list (append new-vhdl-port-list
10957 (list new-port-list))))
10958 (setq vhdl-port-list
10959 (append new-vhdl-port-list (list old-vhdl-port-list))
10960 vhdl-port-flattened t)
10961 (message "Flattening port for next paste...done"))))
10962
10963 (defvar vhdl-port-reversed-direction nil
10964 "Indicates whether port directions are reversed.")
10965
10966 (defun vhdl-port-reverse-direction ()
10967 "Reverse direction for all ports (useful in testbenches).
10968 This operation is performed on an internally stored port and is only
10969 reflected in a subsequent paste operation."
10970 (interactive)
10971 (if (not vhdl-port-list)
10972 (error "ERROR: No port has been read")
10973 (message "Reversing port directions for next paste...")
10974 (let ((port-list (nth 2 vhdl-port-list))
10975 port-dir-car port-dir)
10976 ;; traverse port list and reverse directions
10977 (while port-list
10978 (setq port-dir-car (cddr (car port-list))
10979 port-dir (car port-dir-car))
10980 (setcar port-dir-car
10981 (cond ((equal port-dir "in") "out")
10982 ((equal port-dir "out") "in")
10983 (t port-dir)))
10984 (setq port-list (cdr port-list)))
10985 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10986 (message "Reversing port directions for next paste...done"))))
10987
10988 (defun vhdl-port-copy ()
10989 "Get generic and port information from an entity or component declaration."
10990 (interactive)
10991 (save-excursion
10992 (let (parse-error end-of-list
10993 decl-type name generic-list port-list context-clause
10994 object names direct type init comment group-comment)
10995 (vhdl-prepare-search-2
10996 (setq
10997 parse-error
10998 (catch 'parse
10999 ;; check if within entity or component declaration
11000 (end-of-line)
11001 (when (or (not (re-search-backward
11002 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11003 (equal "END" (upcase (match-string 1))))
11004 (throw 'parse "ERROR: Not within an entity or component declaration"))
11005 (setq decl-type (downcase (match-string-no-properties 1)))
11006 (forward-word 1)
11007 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11008 (setq name (match-string-no-properties 1))
11009 (message "Reading port of %s \"%s\"..." decl-type name)
11010 (vhdl-forward-syntactic-ws)
11011 ;; parse generic clause
11012 (when (vhdl-parse-string "generic[ \t\n]*(" t)
11013 ;; parse group comment and spacing
11014 (setq group-comment (vhdl-parse-group-comment))
11015 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11016 (while (not end-of-list)
11017 ;; parse names (accept extended identifiers)
11018 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11019 (setq names (list (match-string-no-properties 1)))
11020 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11021 (setq names
11022 (append names (list (match-string-no-properties 1)))))
11023 ;; parse type
11024 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11025 (setq type (match-string-no-properties 1))
11026 (setq comment nil)
11027 (while (looking-at "(")
11028 (setq type
11029 (concat type
11030 (buffer-substring-no-properties
11031 (point) (progn (forward-sexp) (point)))
11032 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11033 (match-string-no-properties 1)))))
11034 ;; special case: closing parenthesis is on separate line
11035 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11036 (setq comment (substring type (match-beginning 2)))
11037 (setq type (substring type 0 (match-beginning 1))))
11038 ;; strip of trailing group-comment
11039 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11040 (setq type (substring type 0 (match-end 1)))
11041 ;; parse initialization expression
11042 (setq init nil)
11043 (when (vhdl-parse-string ":=[ \t\n]*" t)
11044 (vhdl-parse-string "\\([^();\n]*\\)")
11045 (setq init (match-string-no-properties 1))
11046 (while (looking-at "(")
11047 (setq init
11048 (concat init
11049 (buffer-substring-no-properties
11050 (point) (progn (forward-sexp) (point)))
11051 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11052 (match-string-no-properties 1))))))
11053 ;; special case: closing parenthesis is on separate line
11054 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11055 (setq comment (substring init (match-beginning 2)))
11056 (setq init (substring init 0 (match-beginning 1)))
11057 (vhdl-forward-syntactic-ws))
11058 (skip-chars-forward " \t")
11059 ;; parse inline comment, special case: as above, no initial.
11060 (unless comment
11061 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11062 (match-string-no-properties 1))))
11063 (vhdl-forward-syntactic-ws)
11064 (setq end-of-list (vhdl-parse-string ")" t))
11065 (vhdl-parse-string "\\s-*;\\s-*")
11066 ;; parse inline comment
11067 (unless comment
11068 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11069 (match-string-no-properties 1))))
11070 ;; save everything in list
11071 (setq generic-list (append generic-list
11072 (list (list names type init
11073 comment group-comment))))
11074 ;; parse group comment and spacing
11075 (setq group-comment (vhdl-parse-group-comment))))
11076 ;; parse port clause
11077 (when (vhdl-parse-string "port[ \t\n]*(" t)
11078 ;; parse group comment and spacing
11079 (setq group-comment (vhdl-parse-group-comment))
11080 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11081 (while (not end-of-list)
11082 ;; parse object
11083 (setq object
11084 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11085 (match-string-no-properties 1)))
11086 ;; parse names (accept extended identifiers)
11087 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11088 (setq names (list (match-string-no-properties 1)))
11089 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11090 (setq names (append names (list (match-string-no-properties 1)))))
11091 ;; parse direction
11092 (vhdl-parse-string ":[ \t\n]*")
11093 (setq direct
11094 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11095 (match-string-no-properties 1)))
11096 ;; parse type
11097 (vhdl-parse-string "\\([^();\n]+\\)")
11098 (setq type (match-string-no-properties 1))
11099 (setq comment nil)
11100 (while (looking-at "(")
11101 (setq type (concat type
11102 (buffer-substring-no-properties
11103 (point) (progn (forward-sexp) (point)))
11104 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11105 (match-string-no-properties 1)))))
11106 ;; special case: closing parenthesis is on separate line
11107 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11108 (setq comment (substring type (match-beginning 2)))
11109 (setq type (substring type 0 (match-beginning 1))))
11110 ;; strip of trailing group-comment
11111 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11112 (setq type (substring type 0 (match-end 1)))
11113 (vhdl-forward-syntactic-ws)
11114 (setq end-of-list (vhdl-parse-string ")" t))
11115 (vhdl-parse-string "\\s-*;\\s-*")
11116 ;; parse inline comment
11117 (unless comment
11118 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11119 (match-string-no-properties 1))))
11120 ;; save everything in list
11121 (setq port-list (append port-list
11122 (list (list names object direct type
11123 comment group-comment))))
11124 ;; parse group comment and spacing
11125 (setq group-comment (vhdl-parse-group-comment))))
11126 ; (vhdl-parse-string "end\\>")
11127 ;; parse context clause
11128 (setq context-clause (vhdl-scan-context-clause))
11129 ; ;; add surrounding package to context clause
11130 ; (when (and (equal decl-type "component")
11131 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11132 ; (setq context-clause
11133 ; (append context-clause
11134 ; (list (cons (vhdl-work-library)
11135 ; (match-string-no-properties 1))))))
11136 (message "Reading port of %s \"%s\"...done" decl-type name)
11137 nil)))
11138 ;; finish parsing
11139 (if parse-error
11140 (error parse-error)
11141 (setq vhdl-port-list (list name generic-list port-list context-clause)
11142 vhdl-port-reversed-direction nil
11143 vhdl-port-flattened nil)))))
11144
11145 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11146 "Paste a context clause."
11147 (let ((margin (current-indentation))
11148 (clause-list (nth 3 vhdl-port-list))
11149 clause)
11150 (while clause-list
11151 (setq clause (car clause-list))
11152 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11153 (downcase exclude-pack-name)))
11154 (save-excursion
11155 (re-search-backward
11156 (concat "^\\s-*use\\s-+" (car clause)
11157 "\." (cdr clause) "\\>") nil t)))
11158 (vhdl-template-standard-package (car clause) (cdr clause))
11159 (insert "\n"))
11160 (setq clause-list (cdr clause-list)))))
11161
11162 (defun vhdl-port-paste-generic (&optional no-init)
11163 "Paste a generic clause."
11164 (let ((margin (current-indentation))
11165 (generic-list (nth 1 vhdl-port-list))
11166 list-margin start names generic)
11167 ;; paste generic clause
11168 (when generic-list
11169 (setq start (point))
11170 (vhdl-insert-keyword "GENERIC (")
11171 (unless vhdl-argument-list-indent
11172 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11173 (setq list-margin (current-column))
11174 (while generic-list
11175 (setq generic (car generic-list))
11176 ;; paste group comment and spacing
11177 (when (memq vhdl-include-group-comments '(decl always))
11178 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11179 ;; paste names
11180 (setq names (nth 0 generic))
11181 (while names
11182 (insert (car names))
11183 (setq names (cdr names))
11184 (when names (insert ", ")))
11185 ;; paste type
11186 (insert " : " (nth 1 generic))
11187 ;; paste initialization
11188 (when (and (not no-init) (nth 2 generic))
11189 (insert " := " (nth 2 generic)))
11190 (unless (cdr generic-list) (insert ")"))
11191 (insert ";")
11192 ;; paste comment
11193 (when (and vhdl-include-port-comments (nth 3 generic))
11194 (vhdl-comment-insert-inline (nth 3 generic) t))
11195 (setq generic-list (cdr generic-list))
11196 (when generic-list (insert "\n") (indent-to list-margin)))
11197 ;; align generic clause
11198 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11199
11200 (defun vhdl-port-paste-port ()
11201 "Paste a port clause."
11202 (let ((margin (current-indentation))
11203 (port-list (nth 2 vhdl-port-list))
11204 list-margin start names port)
11205 ;; paste port clause
11206 (when port-list
11207 (setq start (point))
11208 (vhdl-insert-keyword "PORT (")
11209 (unless vhdl-argument-list-indent
11210 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11211 (setq list-margin (current-column))
11212 (while port-list
11213 (setq port (car port-list))
11214 ;; paste group comment and spacing
11215 (when (memq vhdl-include-group-comments '(decl always))
11216 (vhdl-paste-group-comment (nth 5 port) list-margin))
11217 ;; paste object
11218 (when (nth 1 port) (insert (nth 1 port) " "))
11219 ;; paste names
11220 (setq names (nth 0 port))
11221 (while names
11222 (insert (car names))
11223 (setq names (cdr names))
11224 (when names (insert ", ")))
11225 ;; paste direction
11226 (insert " : ")
11227 (when (nth 2 port) (insert (nth 2 port) " "))
11228 ;; paste type
11229 (insert (nth 3 port))
11230 (unless (cdr port-list) (insert ")"))
11231 (insert ";")
11232 ;; paste comment
11233 (when (and vhdl-include-port-comments (nth 4 port))
11234 (vhdl-comment-insert-inline (nth 4 port) t))
11235 (setq port-list (cdr port-list))
11236 (when port-list (insert "\n") (indent-to list-margin)))
11237 ;; align port clause
11238 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11239
11240 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11241 "Paste as an entity or component declaration."
11242 (unless no-indent (indent-according-to-mode))
11243 (let ((margin (current-indentation))
11244 (name (nth 0 vhdl-port-list)))
11245 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11246 (insert name)
11247 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11248 (vhdl-insert-keyword " IS"))
11249 ;; paste generic and port clause
11250 (when (nth 1 vhdl-port-list)
11251 (insert "\n")
11252 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11253 (insert "\n"))
11254 (indent-to (+ margin vhdl-basic-offset))
11255 (vhdl-port-paste-generic (eq kind 'component)))
11256 (when (nth 2 vhdl-port-list)
11257 (insert "\n")
11258 (when (and (memq vhdl-insert-empty-lines '(unit all))
11259 (eq kind 'entity))
11260 (insert "\n"))
11261 (indent-to (+ margin vhdl-basic-offset)))
11262 (vhdl-port-paste-port)
11263 (insert "\n")
11264 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11265 (insert "\n"))
11266 (indent-to margin)
11267 (vhdl-insert-keyword "END")
11268 (if (eq kind 'entity)
11269 (progn
11270 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11271 (insert " " name))
11272 (vhdl-insert-keyword " COMPONENT")
11273 (unless (vhdl-standard-p '87) (insert " " name)))
11274 (insert ";")))
11275
11276 (defun vhdl-port-paste-entity (&optional no-indent)
11277 "Paste as an entity declaration."
11278 (interactive)
11279 (if (not vhdl-port-list)
11280 (error "ERROR: No port read")
11281 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11282 (vhdl-port-paste-declaration 'entity no-indent)
11283 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11284
11285 (defun vhdl-port-paste-component (&optional no-indent)
11286 "Paste as a component declaration."
11287 (interactive)
11288 (if (not vhdl-port-list)
11289 (error "ERROR: No port read")
11290 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11291 (vhdl-port-paste-declaration 'component no-indent)
11292 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11293
11294 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11295 "Paste as a generic map."
11296 (interactive)
11297 (unless secondary (indent-according-to-mode))
11298 (let ((margin (current-indentation))
11299 list-margin start generic
11300 (generic-list (nth 1 vhdl-port-list)))
11301 (when generic-list
11302 (setq start (point))
11303 (vhdl-insert-keyword "GENERIC MAP (")
11304 (if (not vhdl-association-list-with-formals)
11305 ;; paste list of actual generics
11306 (while generic-list
11307 (insert (if no-constants
11308 (car (nth 0 (car generic-list)))
11309 (or (nth 2 (car generic-list)) " ")))
11310 (setq generic-list (cdr generic-list))
11311 (insert (if generic-list ", " ")"))
11312 (when (and (not generic-list) secondary
11313 (null (nth 2 vhdl-port-list)))
11314 (insert ";")))
11315 (unless vhdl-argument-list-indent
11316 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11317 (setq list-margin (current-column))
11318 (while generic-list
11319 (setq generic (car generic-list))
11320 ;; paste group comment and spacing
11321 (when (eq vhdl-include-group-comments 'always)
11322 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11323 ;; paste formal and actual generic
11324 (insert (car (nth 0 generic)) " => "
11325 (if no-constants
11326 (car (nth 0 generic))
11327 (or (nth 2 generic) "")))
11328 (setq generic-list (cdr generic-list))
11329 (insert (if generic-list "," ")"))
11330 (when (and (not generic-list) secondary
11331 (null (nth 2 vhdl-port-list)))
11332 (insert ";"))
11333 ;; paste comment
11334 (when (or vhdl-include-type-comments
11335 (and vhdl-include-port-comments (nth 3 generic)))
11336 (vhdl-comment-insert-inline
11337 (concat
11338 (when vhdl-include-type-comments
11339 (concat "[" (nth 1 generic) "] "))
11340 (when vhdl-include-port-comments (nth 3 generic))) t))
11341 (when generic-list (insert "\n") (indent-to list-margin)))
11342 ;; align generic map
11343 (when vhdl-auto-align
11344 (vhdl-align-region-groups start (point) 1 t))))))
11345
11346 (defun vhdl-port-paste-port-map ()
11347 "Paste as a port map."
11348 (let ((margin (current-indentation))
11349 list-margin start port
11350 (port-list (nth 2 vhdl-port-list)))
11351 (when port-list
11352 (setq start (point))
11353 (vhdl-insert-keyword "PORT MAP (")
11354 (if (not vhdl-association-list-with-formals)
11355 ;; paste list of actual ports
11356 (while port-list
11357 (insert (vhdl-replace-string vhdl-actual-port-name
11358 (car (nth 0 (car port-list)))))
11359 (setq port-list (cdr port-list))
11360 (insert (if port-list ", " ")")))
11361 (unless vhdl-argument-list-indent
11362 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11363 (setq list-margin (current-column))
11364 (while port-list
11365 (setq port (car port-list))
11366 ;; paste group comment and spacing
11367 (when (eq vhdl-include-group-comments 'always)
11368 (vhdl-paste-group-comment (nth 5 port) list-margin))
11369 ;; paste formal and actual port
11370 (insert (car (nth 0 port)) " => ")
11371 (insert (vhdl-replace-string vhdl-actual-port-name
11372 (car (nth 0 port))))
11373 (setq port-list (cdr port-list))
11374 (insert (if port-list "," ");"))
11375 ;; paste comment
11376 (when (or vhdl-include-direction-comments
11377 vhdl-include-type-comments
11378 (and vhdl-include-port-comments (nth 4 port)))
11379 (vhdl-comment-insert-inline
11380 (concat
11381 (cond ((and vhdl-include-direction-comments
11382 vhdl-include-type-comments)
11383 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11384 (nth 3 port) "] "))
11385 ((and vhdl-include-direction-comments (nth 2 port))
11386 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11387 (vhdl-include-direction-comments " ")
11388 (vhdl-include-type-comments
11389 (concat "[" (nth 3 port) "] ")))
11390 (when vhdl-include-port-comments (nth 4 port))) t))
11391 (when port-list (insert "\n") (indent-to list-margin)))
11392 ;; align port clause
11393 (when vhdl-auto-align
11394 (vhdl-align-region-groups start (point) 1))))))
11395
11396 (defun vhdl-port-paste-instance (&optional name no-indent title)
11397 "Paste as an instantiation."
11398 (interactive)
11399 (if (not vhdl-port-list)
11400 (error "ERROR: No port read")
11401 (let ((orig-vhdl-port-list vhdl-port-list))
11402 ;; flatten local copy of port list (must be flat for port mapping)
11403 (vhdl-port-flatten)
11404 (unless no-indent (indent-according-to-mode))
11405 (let ((margin (current-indentation)))
11406 ;; paste instantiation
11407 (cond (name
11408 (insert name))
11409 ((equal (cdr vhdl-instance-name) "")
11410 (setq name (vhdl-template-field "instance name")))
11411 ((string-match "\%d" (cdr vhdl-instance-name))
11412 (let ((n 1))
11413 (while (save-excursion
11414 (setq name (format (vhdl-replace-string
11415 vhdl-instance-name
11416 (nth 0 vhdl-port-list)) n))
11417 (goto-char (point-min))
11418 (vhdl-re-search-forward name nil t))
11419 (setq n (1+ n)))
11420 (insert name)))
11421 (t (insert (vhdl-replace-string vhdl-instance-name
11422 (nth 0 vhdl-port-list)))))
11423 (message "Pasting port as instantiation \"%s\"..." name)
11424 (insert ": ")
11425 (when title
11426 (save-excursion
11427 (beginning-of-line)
11428 (indent-to vhdl-basic-offset)
11429 (insert "-- instance \"" name "\"\n")))
11430 (if (not (vhdl-use-direct-instantiation))
11431 (insert (nth 0 vhdl-port-list))
11432 (vhdl-insert-keyword "ENTITY ")
11433 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11434 (when (nth 1 vhdl-port-list)
11435 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11436 (vhdl-port-paste-generic-map t t))
11437 (when (nth 2 vhdl-port-list)
11438 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11439 (vhdl-port-paste-port-map))
11440 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11441 (insert ";"))
11442 (message "Pasting port as instantiation \"%s\"...done" name))
11443 (setq vhdl-port-list orig-vhdl-port-list))))
11444
11445 (defun vhdl-port-paste-constants (&optional no-indent)
11446 "Paste generics as constants."
11447 (interactive)
11448 (if (not vhdl-port-list)
11449 (error "ERROR: No port read")
11450 (let ((orig-vhdl-port-list vhdl-port-list))
11451 (message "Pasting port as constants...")
11452 ;; flatten local copy of port list (must be flat for constant initial.)
11453 (vhdl-port-flatten)
11454 (unless no-indent (indent-according-to-mode))
11455 (let ((margin (current-indentation))
11456 start generic name
11457 (generic-list (nth 1 vhdl-port-list)))
11458 (when generic-list
11459 (setq start (point))
11460 (while generic-list
11461 (setq generic (car generic-list))
11462 ;; paste group comment and spacing
11463 (when (memq vhdl-include-group-comments '(decl always))
11464 (vhdl-paste-group-comment (nth 4 generic) margin))
11465 (vhdl-insert-keyword "CONSTANT ")
11466 ;; paste generic constants
11467 (setq name (nth 0 generic))
11468 (when name
11469 (insert (car name))
11470 ;; paste type
11471 (insert " : " (nth 1 generic))
11472 ;; paste initialization
11473 (when (nth 2 generic)
11474 (insert " := " (nth 2 generic)))
11475 (insert ";")
11476 ;; paste comment
11477 (when (and vhdl-include-port-comments (nth 3 generic))
11478 (vhdl-comment-insert-inline (nth 3 generic) t))
11479 (setq generic-list (cdr generic-list))
11480 (when generic-list (insert "\n") (indent-to margin))))
11481 ;; align signal list
11482 (when vhdl-auto-align
11483 (vhdl-align-region-groups start (point) 1))))
11484 (message "Pasting port as constants...done")
11485 (setq vhdl-port-list orig-vhdl-port-list))))
11486
11487 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11488 "Paste ports as internal signals."
11489 (interactive)
11490 (if (not vhdl-port-list)
11491 (error "ERROR: No port read")
11492 (message "Pasting port as signals...")
11493 (unless no-indent (indent-according-to-mode))
11494 (let ((margin (current-indentation))
11495 start port names
11496 (port-list (nth 2 vhdl-port-list)))
11497 (when port-list
11498 (setq start (point))
11499 (while port-list
11500 (setq port (car port-list))
11501 ;; paste group comment and spacing
11502 (when (memq vhdl-include-group-comments '(decl always))
11503 (vhdl-paste-group-comment (nth 5 port) margin))
11504 ;; paste object
11505 (if (nth 1 port)
11506 (insert (nth 1 port) " ")
11507 (vhdl-insert-keyword "SIGNAL "))
11508 ;; paste actual port signals
11509 (setq names (nth 0 port))
11510 (while names
11511 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11512 (setq names (cdr names))
11513 (when names (insert ", ")))
11514 ;; paste type
11515 (insert " : " (nth 3 port))
11516 ;; paste initialization (inputs only)
11517 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11518 (insert " := " (if (string-match "(.+)" (nth 3 port))
11519 "(others => '0')" "'0'")))
11520 (insert ";")
11521 ;; paste comment
11522 (when (or vhdl-include-direction-comments
11523 (and vhdl-include-port-comments (nth 4 port)))
11524 (vhdl-comment-insert-inline
11525 (concat
11526 (cond ((and vhdl-include-direction-comments (nth 2 port))
11527 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11528 (vhdl-include-direction-comments " "))
11529 (when vhdl-include-port-comments (nth 4 port))) t))
11530 (setq port-list (cdr port-list))
11531 (when port-list (insert "\n") (indent-to margin)))
11532 ;; align signal list
11533 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11534 (message "Pasting port as signals...done")))
11535
11536 (defun vhdl-port-paste-initializations (&optional no-indent)
11537 "Paste ports as signal initializations."
11538 (interactive)
11539 (if (not vhdl-port-list)
11540 (error "ERROR: No port read")
11541 (let ((orig-vhdl-port-list vhdl-port-list))
11542 (message "Pasting port as initializations...")
11543 ;; flatten local copy of port list (must be flat for signal initial.)
11544 (vhdl-port-flatten)
11545 (unless no-indent (indent-according-to-mode))
11546 (let ((margin (current-indentation))
11547 start port name
11548 (port-list (nth 2 vhdl-port-list)))
11549 (when port-list
11550 (setq start (point))
11551 (while port-list
11552 (setq port (car port-list))
11553 ;; paste actual port signal (inputs only)
11554 (when (equal "IN" (upcase (nth 2 port)))
11555 (setq name (car (nth 0 port)))
11556 (insert (vhdl-replace-string vhdl-actual-port-name name))
11557 ;; paste initialization
11558 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11559 "(others => '0')" "'0'") ";"))
11560 (setq port-list (cdr port-list))
11561 (when (and port-list
11562 (equal "IN" (upcase (nth 2 (car port-list)))))
11563 (insert "\n") (indent-to margin)))
11564 ;; align signal list
11565 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11566 (message "Pasting port as initializations...done")
11567 (setq vhdl-port-list orig-vhdl-port-list))))
11568
11569 (defun vhdl-port-paste-testbench ()
11570 "Paste as a bare-bones testbench."
11571 (interactive)
11572 (if (not vhdl-port-list)
11573 (error "ERROR: No port read")
11574 (let ((case-fold-search t)
11575 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11576 (nth 0 vhdl-port-list)))
11577 (source-buffer (current-buffer))
11578 arch-name config-name ent-file-name arch-file-name
11579 ent-buffer arch-buffer position)
11580 ;; open entity file
11581 (unless (eq vhdl-testbench-create-files 'none)
11582 (setq ent-file-name
11583 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11584 ent-name t)
11585 "." (file-name-extension (buffer-file-name))))
11586 (if (file-exists-p ent-file-name)
11587 (if (y-or-n-p
11588 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11589 (progn (find-file ent-file-name)
11590 (erase-buffer)
11591 (set-buffer-modified-p nil))
11592 (if (eq vhdl-testbench-create-files 'separate)
11593 (setq ent-file-name nil)
11594 (error "ERROR: Pasting port as testbench...aborted")))
11595 (find-file ent-file-name)))
11596 (unless (and (eq vhdl-testbench-create-files 'separate)
11597 (null ent-file-name))
11598 ;; paste entity header
11599 (if vhdl-testbench-include-header
11600 (progn (vhdl-template-header
11601 (concat "Testbench for design \""
11602 (nth 0 vhdl-port-list) "\""))
11603 (goto-char (point-max)))
11604 (vhdl-comment-display-line) (insert "\n\n"))
11605 ;; paste std_logic_1164 package
11606 (when vhdl-testbench-include-library
11607 (vhdl-template-package-std-logic-1164)
11608 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11609 ;; paste entity declaration
11610 (vhdl-insert-keyword "ENTITY ")
11611 (insert ent-name)
11612 (vhdl-insert-keyword " IS")
11613 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11614 (insert "\n")
11615 (vhdl-insert-keyword "END ")
11616 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11617 (insert ent-name ";")
11618 (insert "\n\n")
11619 (vhdl-comment-display-line) (insert "\n"))
11620 ;; get architecture name
11621 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11622 (read-from-minibuffer "architecture name: "
11623 nil vhdl-minibuffer-local-map)
11624 (vhdl-replace-string vhdl-testbench-architecture-name
11625 (nth 0 vhdl-port-list))))
11626 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11627 ;; open architecture file
11628 (if (not (eq vhdl-testbench-create-files 'separate))
11629 (insert "\n")
11630 (setq ent-buffer (current-buffer))
11631 (setq arch-file-name
11632 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11633 (concat ent-name " " arch-name) t)
11634 "." (file-name-extension (buffer-file-name))))
11635 (when (and (file-exists-p arch-file-name)
11636 (not (y-or-n-p (concat "File \"" arch-file-name
11637 "\" exists; overwrite? "))))
11638 (error "ERROR: Pasting port as testbench...aborted"))
11639 (find-file arch-file-name)
11640 (erase-buffer)
11641 (set-buffer-modified-p nil)
11642 ;; paste architecture header
11643 (if vhdl-testbench-include-header
11644 (progn (vhdl-template-header
11645 (concat "Testbench architecture for design \""
11646 (nth 0 vhdl-port-list) "\""))
11647 (goto-char (point-max)))
11648 (vhdl-comment-display-line) (insert "\n\n")))
11649 ;; paste architecture body
11650 (vhdl-insert-keyword "ARCHITECTURE ")
11651 (insert arch-name)
11652 (vhdl-insert-keyword " OF ")
11653 (insert ent-name)
11654 (vhdl-insert-keyword " IS")
11655 (insert "\n\n") (indent-to vhdl-basic-offset)
11656 ;; paste component declaration
11657 (unless (vhdl-use-direct-instantiation)
11658 (vhdl-port-paste-component t)
11659 (insert "\n\n") (indent-to vhdl-basic-offset))
11660 ;; paste constants
11661 (when (nth 1 vhdl-port-list)
11662 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11663 (vhdl-port-paste-constants t)
11664 (insert "\n\n") (indent-to vhdl-basic-offset))
11665 ;; paste internal signals
11666 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11667 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11668 (insert "\n")
11669 ;; paste custom declarations
11670 (unless (equal "" vhdl-testbench-declarations)
11671 (insert "\n")
11672 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11673 (setq position (point))
11674 (insert "\n\n")
11675 (vhdl-comment-display-line) (insert "\n")
11676 (when vhdl-testbench-include-configuration
11677 (setq config-name (vhdl-replace-string
11678 vhdl-testbench-configuration-name
11679 (concat ent-name " " arch-name)))
11680 (insert "\n")
11681 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11682 (vhdl-insert-keyword " OF ") (insert ent-name)
11683 (vhdl-insert-keyword " IS\n")
11684 (indent-to vhdl-basic-offset)
11685 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11686 (indent-to vhdl-basic-offset)
11687 (vhdl-insert-keyword "END FOR;\n")
11688 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11689 (vhdl-comment-display-line) (insert "\n"))
11690 (goto-char position)
11691 (vhdl-template-begin-end
11692 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11693 ;; paste instantiation
11694 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11695 (vhdl-port-paste-instance
11696 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11697 (insert "\n")
11698 ;; paste custom statements
11699 (unless (equal "" vhdl-testbench-statements)
11700 (insert "\n")
11701 (vhdl-insert-string-or-file vhdl-testbench-statements))
11702 (insert "\n")
11703 (indent-to vhdl-basic-offset)
11704 (unless (eq vhdl-testbench-create-files 'none)
11705 (setq arch-buffer (current-buffer))
11706 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11707 (set-buffer arch-buffer) (save-buffer))
11708 (message "%s"
11709 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11710 ent-name arch-name)
11711 (and ent-file-name
11712 (format "\n File created: \"%s\"" ent-file-name))
11713 (and arch-file-name
11714 (format "\n File created: \"%s\"" arch-file-name)))))))
11715
11716
11717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11718 ;;; Subprogram interface translation
11719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11720
11721 (defvar vhdl-subprog-list nil
11722 "Variable to hold last subprogram interface parsed.")
11723 ;; structure: (parenthesised expression means list of such entries)
11724 ;; (subprog-name kind
11725 ;; ((names) object direct type init comment group-comment)
11726 ;; return-type return-comment group-comment)
11727
11728 (defvar vhdl-subprog-flattened nil
11729 "Indicates whether an subprogram interface has been flattened.")
11730
11731 (defun vhdl-subprog-flatten ()
11732 "Flatten interface list so that only one parameter exists per line."
11733 (interactive)
11734 (if (not vhdl-subprog-list)
11735 (error "ERROR: No subprogram interface has been read")
11736 (message "Flattening subprogram interface...")
11737 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11738 new-subprog-list old-subprog new-subprog names)
11739 ;; traverse parameter list and flatten entries
11740 (while old-subprog-list
11741 (setq old-subprog (car old-subprog-list))
11742 (setq names (car old-subprog))
11743 (while names
11744 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11745 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11746 (setq names (cdr names)))
11747 (setq old-subprog-list (cdr old-subprog-list)))
11748 (setq vhdl-subprog-list
11749 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11750 new-subprog-list (nth 3 vhdl-subprog-list)
11751 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11752 vhdl-subprog-flattened t)
11753 (message "Flattening subprogram interface...done"))))
11754
11755 (defun vhdl-subprog-copy ()
11756 "Get interface information from a subprogram specification."
11757 (interactive)
11758 (save-excursion
11759 (let (parse-error pos end-of-list
11760 name kind param-list object names direct type init
11761 comment group-comment
11762 return-type return-comment return-group-comment)
11763 (vhdl-prepare-search-2
11764 (setq
11765 parse-error
11766 (catch 'parse
11767 ;; check if within function declaration
11768 (setq pos (point))
11769 (end-of-line)
11770 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11771 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11772 (goto-char (match-end 0))
11773 (save-excursion (backward-char)
11774 (forward-sexp)
11775 (<= pos (point))))
11776 (throw 'parse "ERROR: Not within a subprogram specification"))
11777 (setq name (match-string-no-properties 5))
11778 (setq kind (if (match-string 2) 'procedure 'function))
11779 (setq end-of-list (not (match-string 7)))
11780 (message "Reading interface of subprogram \"%s\"..." name)
11781 ;; parse parameter list
11782 (setq group-comment (vhdl-parse-group-comment))
11783 (setq end-of-list (or end-of-list
11784 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11785 (while (not end-of-list)
11786 ;; parse object
11787 (setq object
11788 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11789 (match-string-no-properties 1)))
11790 ;; parse names (accept extended identifiers)
11791 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11792 (setq names (list (match-string-no-properties 1)))
11793 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11794 (setq names (append names (list (match-string-no-properties 1)))))
11795 ;; parse direction
11796 (vhdl-parse-string ":[ \t\n]*")
11797 (setq direct
11798 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11799 (match-string-no-properties 1)))
11800 ;; parse type
11801 (vhdl-parse-string "\\([^():;\n]+\\)")
11802 (setq type (match-string-no-properties 1))
11803 (setq comment nil)
11804 (while (looking-at "(")
11805 (setq type
11806 (concat type
11807 (buffer-substring-no-properties
11808 (point) (progn (forward-sexp) (point)))
11809 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11810 (match-string-no-properties 1)))))
11811 ;; special case: closing parenthesis is on separate line
11812 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11813 (setq comment (substring type (match-beginning 2)))
11814 (setq type (substring type 0 (match-beginning 1))))
11815 ;; strip off trailing group-comment
11816 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11817 (setq type (substring type 0 (match-end 1)))
11818 ;; parse initialization expression
11819 (setq init nil)
11820 (when (vhdl-parse-string ":=[ \t\n]*" t)
11821 (vhdl-parse-string "\\([^();\n]*\\)")
11822 (setq init (match-string-no-properties 1))
11823 (while (looking-at "(")
11824 (setq init
11825 (concat init
11826 (buffer-substring-no-properties
11827 (point) (progn (forward-sexp) (point)))
11828 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11829 (match-string-no-properties 1))))))
11830 ;; special case: closing parenthesis is on separate line
11831 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11832 (setq comment (substring init (match-beginning 2)))
11833 (setq init (substring init 0 (match-beginning 1)))
11834 (vhdl-forward-syntactic-ws))
11835 (skip-chars-forward " \t")
11836 ;; parse inline comment, special case: as above, no initial.
11837 (unless comment
11838 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11839 (match-string-no-properties 1))))
11840 (vhdl-forward-syntactic-ws)
11841 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11842 ;; parse inline comment
11843 (unless comment
11844 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11845 (match-string-no-properties 1))))
11846 (setq return-group-comment (vhdl-parse-group-comment))
11847 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11848 ;; parse return type
11849 (when (match-string 3)
11850 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11851 (setq return-type (match-string-no-properties 1))
11852 (when (and return-type
11853 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11854 (setq return-comment (substring return-type (match-beginning 2)))
11855 (setq return-type (substring return-type 0 (match-beginning 1))))
11856 ;; strip of trailing group-comment
11857 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11858 (setq return-type (substring return-type 0 (match-end 1)))
11859 ;; parse return comment
11860 (unless return-comment
11861 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11862 (match-string-no-properties 1)))))
11863 ;; parse inline comment
11864 (unless comment
11865 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11866 (match-string-no-properties 1))))
11867 ;; save everything in list
11868 (setq param-list (append param-list
11869 (list (list names object direct type init
11870 comment group-comment))))
11871 ;; parse group comment and spacing
11872 (setq group-comment (vhdl-parse-group-comment)))
11873 (message "Reading interface of subprogram \"%s\"...done" name)
11874 nil)))
11875 ;; finish parsing
11876 (if parse-error
11877 (error parse-error)
11878 (setq vhdl-subprog-list
11879 (list name kind param-list return-type return-comment
11880 return-group-comment)
11881 vhdl-subprog-flattened nil)))))
11882
11883 (defun vhdl-subprog-paste-specification (kind)
11884 "Paste as a subprogram specification."
11885 (indent-according-to-mode)
11886 (let ((margin (current-column))
11887 (param-list (nth 2 vhdl-subprog-list))
11888 list-margin start names param)
11889 ;; paste keyword and name
11890 (vhdl-insert-keyword
11891 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11892 (insert (nth 0 vhdl-subprog-list))
11893 (if (not param-list)
11894 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11895 (setq start (point))
11896 ;; paste parameter list
11897 (insert " (")
11898 (unless vhdl-argument-list-indent
11899 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11900 (setq list-margin (current-column))
11901 (while param-list
11902 (setq param (car param-list))
11903 ;; paste group comment and spacing
11904 (when (memq vhdl-include-group-comments (list kind 'always))
11905 (vhdl-paste-group-comment (nth 6 param) list-margin))
11906 ;; paste object
11907 (when (nth 1 param) (insert (nth 1 param) " "))
11908 ;; paste names
11909 (setq names (nth 0 param))
11910 (while names
11911 (insert (car names))
11912 (setq names (cdr names))
11913 (when names (insert ", ")))
11914 ;; paste direction
11915 (insert " : ")
11916 (when (nth 2 param) (insert (nth 2 param) " "))
11917 ;; paste type
11918 (insert (nth 3 param))
11919 ;; paste initialization
11920 (when (nth 4 param) (insert " := " (nth 4 param)))
11921 ;; terminate line
11922 (if (cdr param-list)
11923 (insert ";")
11924 (insert ")")
11925 (when (null (nth 3 vhdl-subprog-list))
11926 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11927 ;; paste comment
11928 (when (and vhdl-include-port-comments (nth 5 param))
11929 (vhdl-comment-insert-inline (nth 5 param) t))
11930 (setq param-list (cdr param-list))
11931 (when param-list (insert "\n") (indent-to list-margin)))
11932 (when (nth 3 vhdl-subprog-list)
11933 (insert "\n") (indent-to list-margin)
11934 ;; paste group comment and spacing
11935 (when (memq vhdl-include-group-comments (list kind 'always))
11936 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11937 ;; paste return type
11938 (insert "return " (nth 3 vhdl-subprog-list))
11939 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11940 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11941 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11942 ;; align parameter list
11943 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11944 ;; paste body
11945 (when (eq kind 'body)
11946 (insert "\n")
11947 (vhdl-template-begin-end
11948 (unless (vhdl-standard-p '87)
11949 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11950 (nth 0 vhdl-subprog-list) margin))))
11951
11952 (defun vhdl-subprog-paste-declaration ()
11953 "Paste as a subprogram declaration."
11954 (interactive)
11955 (if (not vhdl-subprog-list)
11956 (error "ERROR: No subprogram interface read")
11957 (message "Pasting interface as subprogram declaration \"%s\"..."
11958 (car vhdl-subprog-list))
11959 ;; paste specification
11960 (vhdl-subprog-paste-specification 'decl)
11961 (message "Pasting interface as subprogram declaration \"%s\"...done"
11962 (car vhdl-subprog-list))))
11963
11964 (defun vhdl-subprog-paste-body ()
11965 "Paste as a subprogram body."
11966 (interactive)
11967 (if (not vhdl-subprog-list)
11968 (error "ERROR: No subprogram interface read")
11969 (message "Pasting interface as subprogram body \"%s\"..."
11970 (car vhdl-subprog-list))
11971 ;; paste specification and body
11972 (vhdl-subprog-paste-specification 'body)
11973 (message "Pasting interface as subprogram body \"%s\"...done"
11974 (car vhdl-subprog-list))))
11975
11976 (defun vhdl-subprog-paste-call ()
11977 "Paste as a subprogram call."
11978 (interactive)
11979 (if (not vhdl-subprog-list)
11980 (error "ERROR: No subprogram interface read")
11981 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11982 param-list margin list-margin param start)
11983 ;; flatten local copy of interface list (must be flat for parameter mapping)
11984 (vhdl-subprog-flatten)
11985 (setq param-list (nth 2 vhdl-subprog-list))
11986 (indent-according-to-mode)
11987 (setq margin (current-indentation))
11988 (message "Pasting interface as subprogram call \"%s\"..."
11989 (car vhdl-subprog-list))
11990 ;; paste name
11991 (insert (nth 0 vhdl-subprog-list))
11992 (if (not param-list)
11993 (insert ";")
11994 (setq start (point))
11995 ;; paste parameter list
11996 (insert " (")
11997 (unless vhdl-argument-list-indent
11998 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11999 (setq list-margin (current-column))
12000 (while param-list
12001 (setq param (car param-list))
12002 ;; paste group comment and spacing
12003 (when (eq vhdl-include-group-comments 'always)
12004 (vhdl-paste-group-comment (nth 6 param) list-margin))
12005 ;; paste formal port
12006 (insert (car (nth 0 param)) " => ")
12007 (setq param-list (cdr param-list))
12008 (insert (if param-list "," ");"))
12009 ;; paste comment
12010 (when (and vhdl-include-port-comments (nth 5 param))
12011 (vhdl-comment-insert-inline (nth 5 param)))
12012 (when param-list (insert "\n") (indent-to list-margin)))
12013 ;; align parameter list
12014 (when vhdl-auto-align
12015 (vhdl-align-region-groups start (point) 1)))
12016 (message "Pasting interface as subprogram call \"%s\"...done"
12017 (car vhdl-subprog-list))
12018 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12019
12020
12021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12022 ;;; Miscellaneous
12023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12024
12025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12026 ;; Hippie expand customization
12027
12028 (defvar vhdl-expand-upper-case nil)
12029
12030 (defun vhdl-try-expand-abbrev (old)
12031 "Try expanding abbreviations from `vhdl-abbrev-list'."
12032 (unless old
12033 (he-init-string (he-dabbrev-beg) (point))
12034 (setq he-expand-list
12035 (let ((abbrev-list vhdl-abbrev-list)
12036 (sel-abbrev-list '()))
12037 (while abbrev-list
12038 (when (or (not (stringp (car abbrev-list)))
12039 (string-match
12040 (concat "^" he-search-string) (car abbrev-list)))
12041 (setq sel-abbrev-list
12042 (cons (car abbrev-list) sel-abbrev-list)))
12043 (setq abbrev-list (cdr abbrev-list)))
12044 (nreverse sel-abbrev-list))))
12045 (while (and he-expand-list
12046 (or (not (stringp (car he-expand-list)))
12047 (he-string-member (car he-expand-list) he-tried-table t)))
12048 ; (equal (car he-expand-list) he-search-string)))
12049 (unless (stringp (car he-expand-list))
12050 (setq vhdl-expand-upper-case (car he-expand-list)))
12051 (setq he-expand-list (cdr he-expand-list)))
12052 (if (null he-expand-list)
12053 (progn (when old (he-reset-string))
12054 nil)
12055 (he-substitute-string
12056 (if vhdl-expand-upper-case
12057 (upcase (car he-expand-list))
12058 (car he-expand-list))
12059 t)
12060 (setq he-expand-list (cdr he-expand-list))
12061 t))
12062
12063 (defun vhdl-he-list-beg ()
12064 "Also looks at the word before `(' in order to better match parenthesized
12065 expressions (e.g. for index ranges of types and signals)."
12066 (save-excursion
12067 (condition-case ()
12068 (progn (backward-up-list 1)
12069 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12070 (error ()))
12071 (point)))
12072
12073 ;; override `he-list-beg' from `hippie-exp'
12074 (unless (and (boundp 'viper-mode) viper-mode)
12075 (defalias 'he-list-beg 'vhdl-he-list-beg))
12076
12077 ;; function for expanding abbrevs and dabbrevs
12078 (defun vhdl-expand-abbrev (arg))
12079 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12080 '(try-expand-dabbrev
12081 try-expand-dabbrev-all-buffers
12082 vhdl-try-expand-abbrev)))
12083
12084 ;; function for expanding parenthesis
12085 (defun vhdl-expand-paren (arg))
12086 (fset 'vhdl-expand-paren (make-hippie-expand-function
12087 '(try-expand-list
12088 try-expand-list-all-buffers)))
12089
12090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12091 ;; Case fixing
12092
12093 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12094 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12095 depending on parameter UPPER-CASE."
12096 (let ((case-replace nil)
12097 (last-update 0))
12098 (vhdl-prepare-search-2
12099 (save-excursion
12100 (goto-char end)
12101 (setq end (point-marker))
12102 (goto-char beg)
12103 (while (re-search-forward word-regexp end t)
12104 (or (vhdl-in-literal)
12105 (if upper-case
12106 (upcase-word -1)
12107 (downcase-word -1)))
12108 (when (and count vhdl-progress-interval (not noninteractive)
12109 (< vhdl-progress-interval
12110 (- (nth 1 (current-time)) last-update)))
12111 (message "Fixing case... (%2d%s)"
12112 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12113 "%")
12114 (setq last-update (nth 1 (current-time)))))
12115 (goto-char end)))))
12116
12117 (defun vhdl-fix-case-region (beg end &optional arg)
12118 "Convert all VHDL words in region to lower or upper case, depending on
12119 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12120 (interactive "r\nP")
12121 (vhdl-fix-case-region-1
12122 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12123 (vhdl-fix-case-region-1
12124 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12125 (vhdl-fix-case-region-1
12126 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12127 (vhdl-fix-case-region-1
12128 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12129 (when vhdl-progress-interval (message "Fixing case...done")))
12130
12131 (defun vhdl-fix-case-buffer ()
12132 "Convert all VHDL words in buffer to lower or upper case, depending on
12133 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12134 (interactive)
12135 (vhdl-fix-case-region (point-min) (point-max)))
12136
12137 (defun vhdl-fix-case-word (&optional arg)
12138 "Convert word after cursor to upper case if necessary."
12139 (interactive "p")
12140 (save-excursion
12141 (when arg (backward-word 1))
12142 (vhdl-prepare-search-1
12143 (when (and vhdl-upper-case-keywords
12144 (looking-at vhdl-keywords-regexp))
12145 (upcase-word 1))
12146 (when (and vhdl-upper-case-types
12147 (looking-at vhdl-types-regexp))
12148 (upcase-word 1))
12149 (when (and vhdl-upper-case-attributes
12150 (looking-at vhdl-attributes-regexp))
12151 (upcase-word 1))
12152 (when (and vhdl-upper-case-enum-values
12153 (looking-at vhdl-enum-values-regexp))
12154 (upcase-word 1)))))
12155
12156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12157 ;; Line handling functions
12158
12159 (defun vhdl-current-line ()
12160 "Return the line number of the line containing point."
12161 (save-restriction
12162 (widen)
12163 (save-excursion
12164 (beginning-of-line)
12165 (1+ (count-lines 1 (point))))))
12166
12167 (defun vhdl-line-kill-entire (&optional arg)
12168 "Delete entire line."
12169 (interactive "p")
12170 (beginning-of-line)
12171 (kill-line (or arg 1)))
12172
12173 (defun vhdl-line-kill (&optional arg)
12174 "Kill current line."
12175 (interactive "p")
12176 (vhdl-line-kill-entire arg))
12177
12178 (defun vhdl-line-copy (&optional arg)
12179 "Copy current line."
12180 (interactive "p")
12181 (save-excursion
12182 (beginning-of-line)
12183 (let ((position (point)))
12184 (forward-line (or arg 1))
12185 (copy-region-as-kill position (point)))))
12186
12187 (defun vhdl-line-yank ()
12188 "Yank entire line."
12189 (interactive)
12190 (beginning-of-line)
12191 (yank))
12192
12193 (defun vhdl-line-expand (&optional prefix-arg)
12194 "Hippie-expand current line."
12195 (interactive "P")
12196 (let ((case-fold-search t) (case-replace nil)
12197 (hippie-expand-try-functions-list
12198 '(try-expand-line try-expand-line-all-buffers)))
12199 (hippie-expand prefix-arg)))
12200
12201 (defun vhdl-line-transpose-next (&optional arg)
12202 "Interchange this line with next line."
12203 (interactive "p")
12204 (forward-line 1)
12205 (transpose-lines (or arg 1))
12206 (forward-line -1))
12207
12208 (defun vhdl-line-transpose-previous (&optional arg)
12209 "Interchange this line with previous line."
12210 (interactive "p")
12211 (forward-line 1)
12212 (transpose-lines (- 0 (or arg 0)))
12213 (forward-line -1))
12214
12215 (defun vhdl-line-open ()
12216 "Open a new line and indent."
12217 (interactive)
12218 (end-of-line -0)
12219 (newline-and-indent))
12220
12221 (defun vhdl-delete-indentation ()
12222 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12223 it works within comments too."
12224 (interactive)
12225 (let ((fill-prefix "-- "))
12226 (delete-indentation)))
12227
12228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12229 ;; Move functions
12230
12231 (defun vhdl-forward-same-indent ()
12232 "Move forward to next line with same indent."
12233 (interactive)
12234 (let ((pos (point))
12235 (indent (current-indentation)))
12236 (beginning-of-line 2)
12237 (while (and (not (eobp))
12238 (or (looking-at "^\\s-*\\(--.*\\)?$")
12239 (> (current-indentation) indent)))
12240 (beginning-of-line 2))
12241 (if (= (current-indentation) indent)
12242 (back-to-indentation)
12243 (message "No following line with same indent found in this block")
12244 (goto-char pos)
12245 nil)))
12246
12247 (defun vhdl-backward-same-indent ()
12248 "Move backward to previous line with same indent."
12249 (interactive)
12250 (let ((pos (point))
12251 (indent (current-indentation)))
12252 (beginning-of-line -0)
12253 (while (and (not (bobp))
12254 (or (looking-at "^\\s-*\\(--.*\\)?$")
12255 (> (current-indentation) indent)))
12256 (beginning-of-line -0))
12257 (if (= (current-indentation) indent)
12258 (back-to-indentation)
12259 (message "No preceding line with same indent found in this block")
12260 (goto-char pos)
12261 nil)))
12262
12263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12264 ;; Statistics
12265
12266 (defun vhdl-statistics-buffer ()
12267 "Get some file statistics."
12268 (interactive)
12269 (let ((no-stats 0)
12270 (no-code-lines 0)
12271 (no-lines (count-lines (point-min) (point-max))))
12272 (save-excursion
12273 ;; count statements
12274 (goto-char (point-min))
12275 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12276 (if (match-string 1)
12277 (goto-char (match-end 1))
12278 (setq no-stats (1+ no-stats))))
12279 ;; count code lines
12280 (goto-char (point-min))
12281 (while (not (eobp))
12282 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12283 (setq no-code-lines (1+ no-code-lines)))
12284 (beginning-of-line 2)))
12285 ;; print results
12286 (message "\n\
12287 File statistics: \"%s\"\n\
12288 ---------------------\n\
12289 # statements : %5d\n\
12290 # code lines : %5d\n\
12291 # total lines : %5d\n\ "
12292 (buffer-file-name) no-stats no-code-lines no-lines)
12293 (unless vhdl-emacs-21 (vhdl-show-messages))))
12294
12295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12296 ;; Help functions
12297
12298 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12299 "Like `re-search-forward', but does not match within literals."
12300 (let (pos)
12301 (save-excursion
12302 (while (and (setq pos (re-search-forward regexp bound noerror count))
12303 (vhdl-in-literal))))
12304 (when pos (goto-char pos))
12305 pos))
12306
12307 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12308 "Like `re-search-backward', but does not match within literals."
12309 (let (pos)
12310 (save-excursion
12311 (while (and (setq pos (re-search-backward regexp bound noerror count))
12312 (vhdl-in-literal))))
12313 (when pos (goto-char pos))
12314 pos))
12315
12316
12317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12318 ;;; Project
12319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12320
12321 (defun vhdl-set-project (name)
12322 "Set current project to NAME."
12323 (interactive
12324 (list (let ((completion-ignore-case t))
12325 (completing-read "Project name: " vhdl-project-alist nil t))))
12326 (cond ((equal name "")
12327 (setq vhdl-project nil)
12328 (message "Current VHDL project: None"))
12329 ((assoc name vhdl-project-alist)
12330 (setq vhdl-project name)
12331 (message "Current VHDL project: \"%s\"" name))
12332 (t
12333 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12334 (vhdl-speedbar-update-current-project))
12335
12336 (defun vhdl-set-default-project ()
12337 "Set current project as default on startup."
12338 (interactive)
12339 (customize-set-variable 'vhdl-project vhdl-project)
12340 (customize-save-customized))
12341
12342 (defun vhdl-toggle-project (name token indent)
12343 "Set current project to NAME or unset if NAME is current project."
12344 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12345
12346 (defun vhdl-export-project (file-name)
12347 "Write project setup for current project."
12348 (interactive
12349 (let ((name (vhdl-resolve-env-variable
12350 (vhdl-replace-string
12351 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12352 (concat (subst-char-in-string
12353 ? ?_ (or (vhdl-project-p)
12354 (error "ERROR: No current project")))
12355 " " (user-login-name))))))
12356 (list (read-file-name
12357 "Write project file: "
12358 (when (file-name-absolute-p name) "") nil nil name))))
12359 (setq file-name (abbreviate-file-name file-name))
12360 (let ((orig-buffer (current-buffer)))
12361 (unless (file-exists-p (file-name-directory file-name))
12362 (make-directory (file-name-directory file-name) t))
12363 (if (not (file-writable-p file-name))
12364 (error "ERROR: File not writable: \"%s\"" file-name)
12365 (set-buffer (find-file-noselect file-name t t))
12366 (erase-buffer)
12367 (insert ";; -*- Emacs-Lisp -*-\n\n"
12368 ";;; " (file-name-nondirectory file-name)
12369 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12370 ";; Project : " vhdl-project "\n"
12371 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12372 (user-login-name) "\n\n\n"
12373 ";; project name\n"
12374 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12375 ";; project setup\n"
12376 "(aput 'vhdl-project-alist vhdl-project\n'")
12377 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12378 (insert ")\n")
12379 (save-buffer)
12380 (kill-buffer (current-buffer))
12381 (set-buffer orig-buffer))))
12382
12383 (defun vhdl-import-project (file-name &optional auto not-make-current)
12384 "Read project setup and set current project."
12385 (interactive
12386 (let ((name (vhdl-resolve-env-variable
12387 (vhdl-replace-string
12388 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12389 (concat "" " " (user-login-name))))))
12390 (list (read-file-name
12391 "Read project file: " (when (file-name-absolute-p name) "") nil t
12392 (file-name-directory name)))))
12393 (when (file-exists-p file-name)
12394 (condition-case ()
12395 (let ((current-project vhdl-project))
12396 (load-file file-name)
12397 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12398 (adelete 'vhdl-project-alist vhdl-project)
12399 (error ""))
12400 (when not-make-current
12401 (setq vhdl-project current-project))
12402 (vhdl-update-mode-menu)
12403 (vhdl-speedbar-refresh)
12404 (unless not-make-current
12405 (message "Current VHDL project: \"%s\"%s"
12406 vhdl-project (if auto " (auto-loaded)" ""))))
12407 (error (vhdl-warning
12408 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12409
12410 (defun vhdl-duplicate-project ()
12411 "Duplicate setup of current project."
12412 (interactive)
12413 (let ((new-name (read-from-minibuffer "New project name: "))
12414 (project-entry (aget vhdl-project-alist vhdl-project t)))
12415 (setq vhdl-project-alist
12416 (append vhdl-project-alist
12417 (list (cons new-name project-entry))))
12418 (vhdl-update-mode-menu)))
12419
12420 (defun vhdl-auto-load-project ()
12421 "Automatically load project setup at startup."
12422 (let ((file-name-list vhdl-project-file-name)
12423 file-list list-length)
12424 (while file-name-list
12425 (setq file-list
12426 (append file-list
12427 (file-expand-wildcards
12428 (vhdl-resolve-env-variable
12429 (vhdl-replace-string
12430 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12431 (concat "\*" " " (user-login-name)))))))
12432 (setq list-length (or list-length (length file-list)))
12433 (setq file-name-list (cdr file-name-list)))
12434 (while file-list
12435 (vhdl-import-project (expand-file-name (car file-list)) t
12436 (not (> list-length 0)))
12437 (setq list-length (1- list-length))
12438 (setq file-list (cdr file-list)))))
12439
12440 ;; automatically load project setup when idle after startup
12441 (when (memq 'startup vhdl-project-auto-load)
12442 (if noninteractive
12443 (vhdl-auto-load-project)
12444 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12445
12446
12447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12448 ;;; Hideshow
12449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12450 ;; (using `hideshow.el')
12451
12452 (defconst vhdl-hs-start-regexp
12453 (concat
12454 "\\(^\\)\\s-*\\("
12455 ;; generic/port clause
12456 "\\(generic\\|port\\)[ \t\n]*(\\|"
12457 ;; component
12458 "component\\>\\|"
12459 ;; component instantiation
12460 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12461 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12462 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12463 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12464 ;; subprogram
12465 "\\(function\\|procedure\\)\\>\\|"
12466 ;; process, block
12467 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12468 ;; configuration declaration
12469 "configuration\\>"
12470 "\\)")
12471 "Regexp to match start of construct to hide.")
12472
12473 (defun vhdl-hs-forward-sexp-func (count)
12474 "Find end of construct to hide (for hideshow). Only searches forward."
12475 (let ((pos (point)))
12476 (vhdl-prepare-search-2
12477 (beginning-of-line)
12478 (cond
12479 ;; generic/port clause
12480 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12481 (goto-char (match-end 0))
12482 (backward-char)
12483 (forward-sexp))
12484 ;; component declaration
12485 ((looking-at "^\\s-*component\\>")
12486 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12487 ;; component instantiation
12488 ((looking-at
12489 (concat
12490 "^\\s-*\\w+\\s-*:[ \t\n]*"
12491 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12492 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12493 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12494 (goto-char (match-end 0))
12495 (backward-char)
12496 (forward-sexp)
12497 (setq pos (point))
12498 (vhdl-forward-syntactic-ws)
12499 (when (looking-at "port\\s-+map[ \t\n]*(")
12500 (goto-char (match-end 0))
12501 (backward-char)
12502 (forward-sexp)
12503 (setq pos (point)))
12504 (goto-char pos))
12505 ;; subprogram declaration/body
12506 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12507 (goto-char (match-end 0))
12508 (vhdl-forward-syntactic-ws)
12509 (when (looking-at "(")
12510 (forward-sexp))
12511 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12512 (vhdl-in-literal)))
12513 ;; subprogram body
12514 (when (match-string 2)
12515 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12516 (backward-word 1)
12517 (vhdl-forward-sexp)))
12518 ;; block (recursive)
12519 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12520 (goto-char (match-end 0))
12521 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12522 (match-beginning 2))
12523 (vhdl-hs-forward-sexp-func count)))
12524 ;; process
12525 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12526 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12527 ;; configuration declaration
12528 ((looking-at "^\\s-*configuration\\>")
12529 (forward-word 4)
12530 (vhdl-forward-sexp))
12531 (t (goto-char pos))))))
12532
12533 (defun vhdl-hideshow-init ()
12534 "Initialize `hideshow'."
12535 (when vhdl-hideshow-menu
12536 (vhdl-hs-minor-mode 1)))
12537
12538 (defun vhdl-hs-minor-mode (&optional arg)
12539 "Toggle hideshow minor mode and update menu bar."
12540 (interactive "P")
12541 (require 'hideshow)
12542 ;; check for hideshow version 5.x
12543 (if (not (boundp 'hs-block-start-mdata-select))
12544 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12545 ;; initialize hideshow
12546 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12547 (setq hs-special-modes-alist
12548 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12549 'vhdl-hs-forward-sexp-func nil)
12550 hs-special-modes-alist)))
12551 (make-local-variable 'hs-minor-mode-hook)
12552 (if vhdl-hide-all-init
12553 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12554 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12555 (hs-minor-mode arg)
12556 (vhdl-mode-line-update))) ; hack to update menu bar
12557
12558
12559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12560 ;;; Font locking
12561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12562 ;; (using `font-lock.el')
12563
12564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12565 ;; Help functions
12566
12567 (defun vhdl-within-translate-off ()
12568 "Return point if within translate-off region, else nil."
12569 (and (save-excursion
12570 (re-search-backward
12571 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12572 (equal "off" (match-string 1))
12573 (point)))
12574
12575 (defun vhdl-start-translate-off (limit)
12576 "Return point before translate-off pragma if before LIMIT, else nil."
12577 (when (re-search-forward
12578 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12579 (match-beginning 0)))
12580
12581 (defun vhdl-end-translate-off (limit)
12582 "Return point after translate-on pragma if before LIMIT, else nil."
12583 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12584
12585 (defun vhdl-match-translate-off (limit)
12586 "Match a translate-off block, setting match-data and returning t, else nil."
12587 (when (< (point) limit)
12588 (let ((start (or (vhdl-within-translate-off)
12589 (vhdl-start-translate-off limit)))
12590 (case-fold-search t))
12591 (when start
12592 (let ((end (or (vhdl-end-translate-off limit) limit)))
12593 (set-match-data (list start end))
12594 (goto-char end))))))
12595
12596 (defun vhdl-font-lock-match-item (limit)
12597 "Match, and move over, any declaration item after point. Adapted from
12598 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12599 (condition-case nil
12600 (save-restriction
12601 (narrow-to-region (point-min) limit)
12602 ;; match item
12603 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12604 (save-match-data
12605 (goto-char (match-end 1))
12606 ;; move to next item
12607 (if (looking-at "\\(\\s-*,\\)")
12608 (goto-char (match-end 1))
12609 (end-of-line) t))))
12610 (error t)))
12611
12612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12613 ;; Syntax definitions
12614
12615 (defconst vhdl-font-lock-syntactic-keywords
12616 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12617 "Mark single quotes as having string quote syntax in 'c' instances.")
12618
12619 (defvar vhdl-font-lock-keywords nil
12620 "Regular expressions to highlight in VHDL Mode.")
12621
12622 (defvar vhdl-font-lock-keywords-0
12623 ;; set in `vhdl-font-lock-init' because dependent on user options
12624 "For consideration as a value of `vhdl-font-lock-keywords'.
12625 This does highlighting of template prompts and directives (pragmas).")
12626
12627 (defvar vhdl-font-lock-keywords-1 nil
12628 ;; set in `vhdl-font-lock-init' because dependent on user options
12629 "For consideration as a value of `vhdl-font-lock-keywords'.
12630 This does highlighting of keywords and standard identifiers.")
12631
12632 (defconst vhdl-font-lock-keywords-2
12633 (list
12634 ;; highlight names of units, subprograms, and components when declared
12635 (list
12636 (concat
12637 "^\\s-*\\("
12638 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12639 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12640 "\\)\\s-+\\(\\w+\\)")
12641 5 'font-lock-function-name-face)
12642
12643 ;; highlight entity names of architectures and configurations
12644 (list
12645 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12646 2 'font-lock-function-name-face)
12647
12648 ;; highlight labels of common constructs
12649 (list
12650 (concat
12651 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12652 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12653 "postponed\\|process\\|"
12654 (when (vhdl-standard-p 'ams) "procedural\\|")
12655 "with\\|while"
12656 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12657 1 'font-lock-function-name-face)
12658
12659 ;; highlight label and component name of component instantiations
12660 (list
12661 (concat
12662 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12663 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12664 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12665
12666 ;; highlight label and instantiated unit of component instantiations
12667 (list
12668 (concat
12669 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12670 "\\(component\\|configuration\\|entity\\)\\s-+"
12671 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12672 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12673 '(5 font-lock-function-name-face nil t)
12674 '(7 font-lock-function-name-face nil t))
12675
12676 ;; highlight names and labels at end of constructs
12677 (list
12678 (concat
12679 "^\\s-*end\\s-+\\(\\("
12680 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12681 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12682 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12683 (when (vhdl-standard-p 'ams) "procedural\\|")
12684 "units"
12685 "\\)\\s-+\\)?\\(\\w*\\)")
12686 5 'font-lock-function-name-face)
12687
12688 ;; highlight labels in exit and next statements
12689 (list
12690 (concat
12691 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12692 3 'font-lock-function-name-face)
12693
12694 ;; highlight entity name in attribute specifications
12695 (list
12696 (concat
12697 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12698 1 'font-lock-function-name-face)
12699
12700 ;; highlight labels in block and component specifications
12701 (list
12702 (concat
12703 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12704 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12705 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12706
12707 ;; highlight names in library clauses
12708 (list "^\\s-*library\\>"
12709 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12710
12711 ;; highlight names in use clauses
12712 (list
12713 (concat
12714 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12715 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12716 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12717 '(7 font-lock-function-name-face nil t))
12718
12719 ;; highlight attribute name in attribute declarations/specifications
12720 (list
12721 (concat
12722 "^\\s-*attribute\\s-+\\(\\w+\\)")
12723 1 'vhdl-font-lock-attribute-face)
12724
12725 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12726 (list
12727 (concat
12728 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12729 3 'font-lock-type-face)
12730
12731 ;; highlight signal/variable/constant declaration names
12732 (list "\\(:[^=]\\)"
12733 '(vhdl-font-lock-match-item
12734 (progn (goto-char (match-beginning 1))
12735 (skip-syntax-backward " ")
12736 (skip-syntax-backward "w_")
12737 (skip-syntax-backward " ")
12738 (while (= (preceding-char) ?,)
12739 (backward-char 1)
12740 (skip-syntax-backward " ")
12741 (skip-syntax-backward "w_")
12742 (skip-syntax-backward " ")))
12743 ; (skip-chars-backward "^-(\n\";")
12744 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12745
12746 ;; highlight formal parameters in component instantiations and subprogram
12747 ;; calls
12748 (list "\\(=>\\)"
12749 '(vhdl-font-lock-match-item
12750 (progn (goto-char (match-beginning 1))
12751 (skip-syntax-backward " ")
12752 (while (= (preceding-char) ?\)) (backward-sexp))
12753 (skip-syntax-backward "w_")
12754 (skip-syntax-backward " ")
12755 (when (memq (preceding-char) '(?n ?N ?|))
12756 (goto-char (point-max))))
12757 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12758
12759 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12760 ;; variables
12761 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12762 '(vhdl-font-lock-match-item
12763 (progn (goto-char (match-end 1)) (match-beginning 2))
12764 nil (1 font-lock-variable-name-face)))
12765 )
12766 "For consideration as a value of `vhdl-font-lock-keywords'.
12767 This does context sensitive highlighting of names and labels.")
12768
12769 (defvar vhdl-font-lock-keywords-3 nil
12770 ;; set in `vhdl-font-lock-init' because dependent on user options
12771 "For consideration as a value of `vhdl-font-lock-keywords'.
12772 This does highlighting of words with special syntax.")
12773
12774 (defvar vhdl-font-lock-keywords-4 nil
12775 ;; set in `vhdl-font-lock-init' because dependent on user options
12776 "For consideration as a value of `vhdl-font-lock-keywords'.
12777 This does highlighting of additional reserved words.")
12778
12779 (defconst vhdl-font-lock-keywords-5
12780 ;; background highlight translate-off regions
12781 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12782 "For consideration as a value of `vhdl-font-lock-keywords'.
12783 This does background highlighting of translate-off regions.")
12784
12785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12786 ;; Font and color definitions
12787
12788 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12789 "Face name to use for prompts.")
12790
12791 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12792 "Face name to use for standardized attributes.")
12793
12794 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12795 "Face name to use for standardized enumeration values.")
12796
12797 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12798 "Face name to use for standardized functions and packages.")
12799
12800 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12801 "Face name to use for directives.")
12802
12803 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12804 "Face name to use for additional reserved words.")
12805
12806 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12807 "Face name to use for translate-off regions.")
12808
12809 ;; face names to use for words with special syntax.
12810 (let ((syntax-alist vhdl-special-syntax-alist)
12811 name)
12812 (while syntax-alist
12813 (setq name (vhdl-function-name
12814 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12815 (eval `(defvar ,name ',name
12816 ,(concat "Face name to use for "
12817 (nth 0 (car syntax-alist)) ".")))
12818 (setq syntax-alist (cdr syntax-alist))))
12819
12820 (defgroup vhdl-highlight-faces nil
12821 "Faces for highlighting."
12822 :group 'vhdl-highlight)
12823
12824 ;; add faces used from `font-lock'
12825 (custom-add-to-group
12826 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12827 (custom-add-to-group
12828 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12829 (custom-add-to-group
12830 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12831 (custom-add-to-group
12832 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12833 (custom-add-to-group
12834 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12835 (custom-add-to-group
12836 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12837
12838 (defface vhdl-font-lock-prompt-face
12839 '((((min-colors 88) (class color) (background light))
12840 (:foreground "Red1" :bold t))
12841 (((class color) (background light)) (:foreground "Red" :bold t))
12842 (((class color) (background dark)) (:foreground "Pink" :bold t))
12843 (t (:inverse-video t)))
12844 "Font lock mode face used to highlight prompts."
12845 :group 'vhdl-highlight-faces)
12846
12847 (defface vhdl-font-lock-attribute-face
12848 '((((class color) (background light)) (:foreground "Orchid"))
12849 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12850 (t (:italic t :bold t)))
12851 "Font lock mode face used to highlight standardized attributes."
12852 :group 'vhdl-highlight-faces)
12853
12854 (defface vhdl-font-lock-enumvalue-face
12855 '((((class color) (background light)) (:foreground "SaddleBrown"))
12856 (((class color) (background dark)) (:foreground "BurlyWood"))
12857 (t (:italic t :bold t)))
12858 "Font lock mode face used to highlight standardized enumeration values."
12859 :group 'vhdl-highlight-faces)
12860
12861 (defface vhdl-font-lock-function-face
12862 '((((class color) (background light)) (:foreground "Cyan4"))
12863 (((class color) (background dark)) (:foreground "Orchid1"))
12864 (t (:italic t :bold t)))
12865 "Font lock mode face used to highlight standardized functions and packages."
12866 :group 'vhdl-highlight-faces)
12867
12868 (defface vhdl-font-lock-directive-face
12869 '((((class color) (background light)) (:foreground "CadetBlue"))
12870 (((class color) (background dark)) (:foreground "Aquamarine"))
12871 (t (:italic t :bold t)))
12872 "Font lock mode face used to highlight directives."
12873 :group 'vhdl-highlight-faces)
12874
12875 (defface vhdl-font-lock-reserved-words-face
12876 '((((class color) (background light)) (:foreground "Orange" :bold t))
12877 (((min-colors 88) (class color) (background dark))
12878 (:foreground "Yellow1" :bold t))
12879 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12880 (t ()))
12881 "Font lock mode face used to highlight additional reserved words."
12882 :group 'vhdl-highlight-faces)
12883
12884 (defface vhdl-font-lock-translate-off-face
12885 '((((class color) (background light)) (:background "LightGray"))
12886 (((class color) (background dark)) (:background "DimGray"))
12887 (t ()))
12888 "Font lock mode face used to background highlight translate-off regions."
12889 :group 'vhdl-highlight-faces)
12890
12891 ;; font lock mode faces used to highlight words with special syntax.
12892 (let ((syntax-alist vhdl-special-syntax-alist))
12893 (while syntax-alist
12894 (eval `(defface ,(vhdl-function-name
12895 "vhdl-font-lock" (caar syntax-alist) "face")
12896 '((((class color) (background light))
12897 (:foreground ,(nth 2 (car syntax-alist))))
12898 (((class color) (background dark))
12899 (:foreground ,(nth 3 (car syntax-alist))))
12900 (t ()))
12901 ,(concat "Font lock mode face used to highlight "
12902 (nth 0 (car syntax-alist)) ".")
12903 :group 'vhdl-highlight-faces))
12904 (setq syntax-alist (cdr syntax-alist))))
12905
12906 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12907 ;; Font lock initialization
12908
12909 (defun vhdl-font-lock-init ()
12910 "Initialize fontification."
12911 ;; highlight template prompts and directives
12912 (setq vhdl-font-lock-keywords-0
12913 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12914 vhdl-template-prompt-syntax ">\\)")
12915 2 'vhdl-font-lock-prompt-face t)
12916 (list (concat "--\\s-*"
12917 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12918 2 'vhdl-font-lock-directive-face t)
12919 ;; highlight c-preprocessor directives
12920 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12921 '(1 font-lock-builtin-face)
12922 '(3 font-lock-variable-name-face nil t))))
12923 ;; highlight keywords and standardized types, attributes, enumeration
12924 ;; values, and subprograms
12925 (setq vhdl-font-lock-keywords-1
12926 (list
12927 (list (concat "'" vhdl-attributes-regexp)
12928 1 'vhdl-font-lock-attribute-face)
12929 (list vhdl-types-regexp 1 'font-lock-type-face)
12930 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12931 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12932 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12933 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12934 ;; highlight words with special syntax.
12935 (setq vhdl-font-lock-keywords-3
12936 (let ((syntax-alist vhdl-special-syntax-alist)
12937 keywords)
12938 (while syntax-alist
12939 (setq keywords
12940 (cons
12941 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12942 (vhdl-function-name
12943 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12944 keywords))
12945 (setq syntax-alist (cdr syntax-alist)))
12946 keywords))
12947 ;; highlight additional reserved words
12948 (setq vhdl-font-lock-keywords-4
12949 (list (list vhdl-reserved-words-regexp 1
12950 'vhdl-font-lock-reserved-words-face)))
12951 ;; highlight everything together
12952 (setq vhdl-font-lock-keywords
12953 (append
12954 vhdl-font-lock-keywords-0
12955 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12956 (when (or vhdl-highlight-forbidden-words
12957 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12958 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12959 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12960 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12961
12962 ;; initialize fontification for VHDL Mode
12963 (vhdl-font-lock-init)
12964
12965 (defun vhdl-fontify-buffer ()
12966 "Re-initialize fontification and fontify buffer."
12967 (interactive)
12968 (setq font-lock-defaults
12969 (list
12970 'vhdl-font-lock-keywords nil
12971 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12972 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12973 (when (fboundp 'font-lock-unset-defaults)
12974 (font-lock-unset-defaults)) ; not implemented in XEmacs
12975 (font-lock-set-defaults)
12976 (font-lock-mode nil)
12977 (font-lock-mode t))
12978
12979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12980 ;; Initialization for postscript printing
12981
12982 (defun vhdl-ps-print-settings ()
12983 "Initialize custom face and page settings for postscript printing."
12984 ;; define custom face settings
12985 (unless (or (not vhdl-print-customize-faces)
12986 ps-print-color-p)
12987 (set (make-local-variable 'ps-bold-faces)
12988 '(font-lock-keyword-face
12989 font-lock-type-face
12990 vhdl-font-lock-attribute-face
12991 vhdl-font-lock-enumvalue-face
12992 vhdl-font-lock-directive-face))
12993 (set (make-local-variable 'ps-italic-faces)
12994 '(font-lock-comment-face
12995 font-lock-function-name-face
12996 font-lock-type-face
12997 vhdl-font-lock-attribute-face
12998 vhdl-font-lock-enumvalue-face
12999 vhdl-font-lock-directive-face))
13000 (set (make-local-variable 'ps-underlined-faces)
13001 '(font-lock-string-face))
13002 (setq ps-always-build-face-reference t))
13003 ;; define page settings, so that a line containing 79 characters (default)
13004 ;; fits into one column
13005 (when vhdl-print-two-column
13006 (set (make-local-variable 'ps-landscape-mode) t)
13007 (set (make-local-variable 'ps-number-of-columns) 2)
13008 (set (make-local-variable 'ps-font-size) 7.0)
13009 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13010 (set (make-local-variable 'ps-header-font-size) 9.0)
13011 (set (make-local-variable 'ps-header-offset) 12.0)
13012 (when (eq ps-paper-type 'letter)
13013 (set (make-local-variable 'ps-inter-column) 40.0)
13014 (set (make-local-variable 'ps-left-margin) 40.0)
13015 (set (make-local-variable 'ps-right-margin) 40.0))))
13016
13017 (defun vhdl-ps-print-init ()
13018 "Initialize postscript printing."
13019 (if (featurep 'xemacs)
13020 (when (boundp 'ps-print-color-p)
13021 (vhdl-ps-print-settings))
13022 (make-local-variable 'ps-print-hook)
13023 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13024
13025
13026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13027 ;;; Hierarchy browser (using `speedbar.el')
13028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13029 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13030 ;; directory by using the speedbar.
13031
13032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13033 ;; Variables
13034
13035 (defvar vhdl-entity-alist nil
13036 "Cache with entities and corresponding architectures for each
13037 project/directory.")
13038 ;; structure: (parenthesised expression means list of such entries)
13039 ;; (cache-key
13040 ;; (ent-key ent-name ent-file ent-line
13041 ;; (arch-key arch-name arch-file arch-line
13042 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13043 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13044 ;; (lib-name pack-key))
13045 ;; mra-key (lib-name pack-key))
13046
13047 (defvar vhdl-config-alist nil
13048 "Cache with configurations for each project/directory.")
13049 ;; structure: (parenthesised expression means list of such entries)
13050 ;; (cache-key
13051 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13052 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13053 ;; inst-conf-key inst-lib-key)
13054 ;; (lib-name pack-key)))
13055
13056 (defvar vhdl-package-alist nil
13057 "Cache with packages for each project/directory.")
13058 ;; structure: (parenthesised expression means list of such entries)
13059 ;; (cache-key
13060 ;; (pack-key pack-name pack-file pack-line
13061 ;; (comp-key comp-name comp-file comp-line)
13062 ;; (func-key func-name func-file func-line)
13063 ;; (lib-name pack-key)
13064 ;; pack-body-file pack-body-line
13065 ;; (func-key func-name func-body-file func-body-line)
13066 ;; (lib-name pack-key)))
13067
13068 (defvar vhdl-ent-inst-alist nil
13069 "Cache with instantiated entities for each project/directory.")
13070 ;; structure: (parenthesised expression means list of such entries)
13071 ;; (cache-key (inst-ent-key))
13072
13073 (defvar vhdl-file-alist nil
13074 "Cache with design units in each file for each project/directory.")
13075 ;; structure: (parenthesised expression means list of such entries)
13076 ;; (cache-key
13077 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13078 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13079
13080 (defvar vhdl-directory-alist nil
13081 "Cache with source directories for each project.")
13082 ;; structure: (parenthesised expression means list of such entries)
13083 ;; (cache-key (directory))
13084
13085 (defvar vhdl-speedbar-shown-unit-alist nil
13086 "Alist of design units simultaneously open in the current speedbar for each
13087 directory and project.")
13088
13089 (defvar vhdl-speedbar-shown-project-list nil
13090 "List of projects simultaneously open in the current speedbar.")
13091
13092 (defvar vhdl-updated-project-list nil
13093 "List of projects and directories with updated files.")
13094
13095 (defvar vhdl-modified-file-list nil
13096 "List of modified files to be rescanned for hierarchy updating.")
13097
13098 (defvar vhdl-speedbar-hierarchy-depth 0
13099 "Depth of instantiation hierarchy to display.")
13100
13101 (defvar vhdl-speedbar-show-projects nil
13102 "Non-nil means project hierarchy is displayed in speedbar, directory
13103 hierarchy otherwise.")
13104
13105 (defun vhdl-get-end-of-unit ()
13106 "Return position of end of current unit."
13107 (let ((pos (point)))
13108 (save-excursion
13109 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13110 (save-excursion
13111 (goto-char (match-beginning 0))
13112 (vhdl-backward-syntactic-ws)
13113 (and (/= (preceding-char) ?\;) (not (bobp))))))
13114 (re-search-backward "^[ \t]*end\\>" pos 1)
13115 (point))))
13116
13117 (defun vhdl-match-string-downcase (num &optional string)
13118 "Like `match-string-no-properties' with down-casing."
13119 (let ((match (match-string-no-properties num string)))
13120 (and match (downcase match))))
13121
13122
13123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13124 ;; Scan functions
13125
13126 (defun vhdl-scan-context-clause ()
13127 "Scan the context clause that preceeds a design unit."
13128 (let (lib-alist)
13129 (save-excursion
13130 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13131 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13132 (equal "USE" (upcase (match-string 1))))
13133 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13134 (setq lib-alist (cons (cons (match-string-no-properties 1)
13135 (vhdl-match-string-downcase 2))
13136 lib-alist))))))
13137 lib-alist))
13138
13139 (defun vhdl-scan-directory-contents (name &optional project update num-string
13140 non-final)
13141 "Scan contents of VHDL files in directory or file pattern NAME."
13142 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13143 ; (unless (file-directory-p (match-string 1 name))
13144 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13145 (let* ((dir-name (match-string 1 name))
13146 (file-pattern (match-string 2 name))
13147 (is-directory (= 0 (length file-pattern)))
13148 (file-list
13149 (if update
13150 (list name)
13151 (if is-directory
13152 (vhdl-get-source-files t dir-name)
13153 (vhdl-directory-files
13154 dir-name t (wildcard-to-regexp file-pattern)))))
13155 (key (or project dir-name))
13156 (file-exclude-regexp
13157 (or (nth 3 (aget vhdl-project-alist project)) ""))
13158 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13159 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13160 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13161 ent-alist conf-alist pack-alist ent-inst-list file-alist
13162 tmp-list tmp-entry no-files files-exist big-files)
13163 (when (or project update)
13164 (setq ent-alist (aget vhdl-entity-alist key t)
13165 conf-alist (aget vhdl-config-alist key t)
13166 pack-alist (aget vhdl-package-alist key t)
13167 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13168 file-alist (aget vhdl-file-alist key t)))
13169 (when (and (not is-directory) (null file-list))
13170 (message "No such file: \"%s\"" name))
13171 (setq files-exist file-list)
13172 (when file-list
13173 (setq no-files (length file-list))
13174 (message "Scanning %s %s\"%s\"..."
13175 (if is-directory "directory" "files") (or num-string "") name)
13176 ;; exclude files
13177 (unless (equal file-exclude-regexp "")
13178 (let ((case-fold-search nil)
13179 file-tmp-list)
13180 (while file-list
13181 (unless (string-match file-exclude-regexp (car file-list))
13182 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13183 (setq file-list (cdr file-list)))
13184 (setq file-list (nreverse file-tmp-list))))
13185 ;; do for all files
13186 (while file-list
13187 (unless noninteractive
13188 (message "Scanning %s %s\"%s\"... (%2d%s)"
13189 (if is-directory "directory" "files")
13190 (or num-string "") name
13191 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13192 (let ((file-name (abbreviate-file-name (car file-list)))
13193 ent-list arch-list arch-ent-list conf-list
13194 pack-list pack-body-list inst-list inst-ent-list)
13195 ;; scan file
13196 (vhdl-visit-file
13197 file-name nil
13198 (vhdl-prepare-search-2
13199 (save-excursion
13200 ;; scan for design units
13201 (if (and limit-design-file-size
13202 (< limit-design-file-size (buffer-size)))
13203 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13204 (setq big-files t))
13205 ;; scan for entities
13206 (goto-char (point-min))
13207 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13208 (let* ((ent-name (match-string-no-properties 1))
13209 (ent-key (downcase ent-name))
13210 (ent-entry (aget ent-alist ent-key t))
13211 (lib-alist (vhdl-scan-context-clause)))
13212 (if (nth 1 ent-entry)
13213 (vhdl-warning-when-idle
13214 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13215 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13216 file-name (vhdl-current-line))
13217 (setq ent-list (cons ent-key ent-list))
13218 (aput 'ent-alist ent-key
13219 (list ent-name file-name (vhdl-current-line)
13220 (nth 3 ent-entry) (nth 4 ent-entry)
13221 lib-alist)))))
13222 ;; scan for architectures
13223 (goto-char (point-min))
13224 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13225 (let* ((arch-name (match-string-no-properties 1))
13226 (arch-key (downcase arch-name))
13227 (ent-name (match-string-no-properties 2))
13228 (ent-key (downcase ent-name))
13229 (ent-entry (aget ent-alist ent-key t))
13230 (arch-alist (nth 3 ent-entry))
13231 (arch-entry (aget arch-alist arch-key t))
13232 (lib-arch-alist (vhdl-scan-context-clause)))
13233 (if arch-entry
13234 (vhdl-warning-when-idle
13235 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13236 arch-name ent-name (nth 1 arch-entry)
13237 (nth 2 arch-entry) file-name (vhdl-current-line))
13238 (setq arch-list (cons arch-key arch-list)
13239 arch-ent-list (cons ent-key arch-ent-list))
13240 (aput 'arch-alist arch-key
13241 (list arch-name file-name (vhdl-current-line) nil
13242 lib-arch-alist))
13243 (aput 'ent-alist ent-key
13244 (list (or (nth 0 ent-entry) ent-name)
13245 (nth 1 ent-entry) (nth 2 ent-entry)
13246 (vhdl-sort-alist arch-alist)
13247 arch-key (nth 5 ent-entry))))))
13248 ;; scan for configurations
13249 (goto-char (point-min))
13250 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13251 (let* ((conf-name (match-string-no-properties 1))
13252 (conf-key (downcase conf-name))
13253 (conf-entry (aget conf-alist conf-key t))
13254 (ent-name (match-string-no-properties 2))
13255 (ent-key (downcase ent-name))
13256 (lib-alist (vhdl-scan-context-clause))
13257 (conf-line (vhdl-current-line))
13258 (end-of-unit (vhdl-get-end-of-unit))
13259 arch-key comp-conf-list inst-key-list
13260 inst-comp-key inst-ent-key inst-arch-key
13261 inst-conf-key inst-lib-key)
13262 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13263 (setq arch-key (vhdl-match-string-downcase 1)))
13264 (if conf-entry
13265 (vhdl-warning-when-idle
13266 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13267 conf-name ent-name (nth 1 conf-entry)
13268 (nth 2 conf-entry) file-name conf-line)
13269 (setq conf-list (cons conf-key conf-list))
13270 ;; scan for subconfigurations and subentities
13271 (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)
13272 (setq inst-comp-key (vhdl-match-string-downcase 3)
13273 inst-key-list (split-string
13274 (vhdl-match-string-downcase 1)
13275 "[ \t\n]*,[ \t\n]*"))
13276 (vhdl-forward-syntactic-ws)
13277 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13278 (setq
13279 inst-lib-key (vhdl-match-string-downcase 3)
13280 inst-ent-key (and (match-string 2)
13281 (vhdl-match-string-downcase 4))
13282 inst-arch-key (and (match-string 2)
13283 (vhdl-match-string-downcase 6))
13284 inst-conf-key (and (not (match-string 2))
13285 (vhdl-match-string-downcase 4)))
13286 (while inst-key-list
13287 (setq comp-conf-list
13288 (cons (list (car inst-key-list)
13289 inst-comp-key inst-ent-key
13290 inst-arch-key inst-conf-key
13291 inst-lib-key)
13292 comp-conf-list))
13293 (setq inst-key-list (cdr inst-key-list)))))
13294 (aput 'conf-alist conf-key
13295 (list conf-name file-name conf-line ent-key
13296 arch-key comp-conf-list lib-alist)))))
13297 ;; scan for packages
13298 (goto-char (point-min))
13299 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13300 (let* ((pack-name (match-string-no-properties 2))
13301 (pack-key (downcase pack-name))
13302 (is-body (match-string-no-properties 1))
13303 (pack-entry (aget pack-alist pack-key t))
13304 (pack-line (vhdl-current-line))
13305 (end-of-unit (vhdl-get-end-of-unit))
13306 comp-name func-name comp-alist func-alist lib-alist)
13307 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13308 (vhdl-warning-when-idle
13309 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13310 (if is-body " body" "") pack-name
13311 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13312 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13313 file-name (vhdl-current-line))
13314 ;; scan for context clauses
13315 (setq lib-alist (vhdl-scan-context-clause))
13316 ;; scan for component and subprogram declarations/bodies
13317 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13318 (if (equal (upcase (match-string 1)) "COMPONENT")
13319 (setq comp-name (match-string-no-properties 2)
13320 comp-alist
13321 (cons (list (downcase comp-name) comp-name
13322 file-name (vhdl-current-line))
13323 comp-alist))
13324 (setq func-name (match-string-no-properties 2)
13325 func-alist
13326 (cons (list (downcase func-name) func-name
13327 file-name (vhdl-current-line))
13328 func-alist))))
13329 (setq func-alist (nreverse func-alist))
13330 (setq comp-alist (nreverse comp-alist))
13331 (if is-body
13332 (setq pack-body-list (cons pack-key pack-body-list))
13333 (setq pack-list (cons pack-key pack-list)))
13334 (aput
13335 'pack-alist pack-key
13336 (if is-body
13337 (list (or (nth 0 pack-entry) pack-name)
13338 (nth 1 pack-entry) (nth 2 pack-entry)
13339 (nth 3 pack-entry) (nth 4 pack-entry)
13340 (nth 5 pack-entry)
13341 file-name pack-line func-alist lib-alist)
13342 (list pack-name file-name pack-line
13343 comp-alist func-alist lib-alist
13344 (nth 6 pack-entry) (nth 7 pack-entry)
13345 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13346 ;; scan for hierarchy
13347 (if (and limit-hier-file-size
13348 (< limit-hier-file-size (buffer-size)))
13349 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13350 (setq big-files t))
13351 ;; scan for architectures
13352 (goto-char (point-min))
13353 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13354 (let* ((ent-name (match-string-no-properties 2))
13355 (ent-key (downcase ent-name))
13356 (arch-name (match-string-no-properties 1))
13357 (arch-key (downcase arch-name))
13358 (ent-entry (aget ent-alist ent-key t))
13359 (arch-alist (nth 3 ent-entry))
13360 (arch-entry (aget arch-alist arch-key t))
13361 (beg-of-unit (point))
13362 (end-of-unit (vhdl-get-end-of-unit))
13363 (inst-no 0)
13364 inst-alist inst-path)
13365 ;; scan for contained instantiations
13366 (while (and (re-search-forward
13367 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13368 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13369 "component[ \t\n]+\\(\\w+\\)\\|"
13370 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13371 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13372 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13373 (or (not limit-hier-inst-no)
13374 (<= (setq inst-no (1+ inst-no))
13375 limit-hier-inst-no)))
13376 (cond
13377 ;; block/generate beginning found
13378 ((match-string 14)
13379 (setq inst-path
13380 (cons (match-string-no-properties 1) inst-path)))
13381 ;; block/generate end found
13382 ((match-string 16)
13383 (setq inst-path (cdr inst-path)))
13384 ;; instantiation found
13385 (t
13386 (let* ((inst-name (match-string-no-properties 1))
13387 (inst-key (downcase inst-name))
13388 (inst-comp-name
13389 (or (match-string-no-properties 3)
13390 (match-string-no-properties 6)))
13391 (inst-ent-key
13392 (or (and (match-string 8)
13393 (vhdl-match-string-downcase 11))
13394 (and inst-comp-name
13395 (downcase inst-comp-name))))
13396 (inst-arch-key (vhdl-match-string-downcase 13))
13397 (inst-conf-key
13398 (and (not (match-string 8))
13399 (vhdl-match-string-downcase 11)))
13400 (inst-lib-key (vhdl-match-string-downcase 10)))
13401 (goto-char (match-end 1))
13402 (setq inst-list (cons inst-key inst-list)
13403 inst-ent-list
13404 (cons inst-ent-key inst-ent-list))
13405 (setq inst-alist
13406 (append
13407 inst-alist
13408 (list (list inst-key inst-name file-name
13409 (vhdl-current-line) inst-comp-name
13410 inst-ent-key inst-arch-key
13411 inst-conf-key inst-lib-key
13412 (reverse inst-path)))))))))
13413 ;; scan for contained configuration specifications
13414 (goto-char beg-of-unit)
13415 (while (re-search-forward
13416 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13417 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13418 (let* ((inst-comp-name (match-string-no-properties 3))
13419 (inst-ent-key
13420 (and (match-string 6)
13421 (vhdl-match-string-downcase 9)))
13422 (inst-arch-key (vhdl-match-string-downcase 11))
13423 (inst-conf-key
13424 (and (not (match-string 6))
13425 (vhdl-match-string-downcase 9)))
13426 (inst-lib-key (vhdl-match-string-downcase 8))
13427 (inst-key-list
13428 (split-string (vhdl-match-string-downcase 1)
13429 "[ \t\n]*,[ \t\n]*"))
13430 (tmp-inst-alist inst-alist)
13431 inst-entry)
13432 (while tmp-inst-alist
13433 (when (and (or (equal "all" (car inst-key-list))
13434 (member (nth 0 (car tmp-inst-alist))
13435 inst-key-list))
13436 (equal
13437 (downcase
13438 (or (nth 4 (car tmp-inst-alist)) ""))
13439 (downcase inst-comp-name)))
13440 (setq inst-entry (car tmp-inst-alist))
13441 (setq inst-ent-list
13442 (cons (or inst-ent-key (nth 5 inst-entry))
13443 (vhdl-delete
13444 (nth 5 inst-entry) inst-ent-list)))
13445 (setq inst-entry
13446 (list (nth 0 inst-entry) (nth 1 inst-entry)
13447 (nth 2 inst-entry) (nth 3 inst-entry)
13448 (nth 4 inst-entry)
13449 (or inst-ent-key (nth 5 inst-entry))
13450 (or inst-arch-key (nth 6 inst-entry))
13451 inst-conf-key inst-lib-key))
13452 (setcar tmp-inst-alist inst-entry))
13453 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13454 ;; save in cache
13455 (aput 'arch-alist arch-key
13456 (list (nth 0 arch-entry) (nth 1 arch-entry)
13457 (nth 2 arch-entry) inst-alist
13458 (nth 4 arch-entry)))
13459 (aput 'ent-alist ent-key
13460 (list (nth 0 ent-entry) (nth 1 ent-entry)
13461 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13462 (nth 4 ent-entry) (nth 5 ent-entry)))
13463 (when (and limit-hier-inst-no
13464 (> inst-no limit-hier-inst-no))
13465 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13466 (setq big-files t))
13467 (goto-char end-of-unit))))
13468 ;; remember design units for this file
13469 (aput 'file-alist file-name
13470 (list ent-list arch-list arch-ent-list conf-list
13471 pack-list pack-body-list inst-list inst-ent-list))
13472 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13473 (setq file-list (cdr file-list))))
13474 (when (or (and (not project) files-exist)
13475 (and project (not non-final)))
13476 ;; consistency checks:
13477 ;; check whether each architecture has a corresponding entity
13478 (setq tmp-list ent-alist)
13479 (while tmp-list
13480 (when (null (nth 2 (car tmp-list)))
13481 (setq tmp-entry (car (nth 4 (car tmp-list))))
13482 (vhdl-warning-when-idle
13483 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13484 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13485 (nth 3 tmp-entry)))
13486 (setq tmp-list (cdr tmp-list)))
13487 ;; check whether configuration has a corresponding entity/architecture
13488 (setq tmp-list conf-alist)
13489 (while tmp-list
13490 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13491 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13492 (setq tmp-entry (car tmp-list))
13493 (vhdl-warning-when-idle
13494 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13495 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13496 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13497 (setq tmp-entry (car tmp-list))
13498 (vhdl-warning-when-idle
13499 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13500 (nth 1 tmp-entry) (nth 4 tmp-entry)
13501 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13502 (setq tmp-list (cdr tmp-list)))
13503 ;; check whether each package body has a package declaration
13504 (setq tmp-list pack-alist)
13505 (while tmp-list
13506 (when (null (nth 2 (car tmp-list)))
13507 (setq tmp-entry (car tmp-list))
13508 (vhdl-warning-when-idle
13509 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13510 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13511 (setq tmp-list (cdr tmp-list)))
13512 ;; sort lists
13513 (setq ent-alist (vhdl-sort-alist ent-alist))
13514 (setq conf-alist (vhdl-sort-alist conf-alist))
13515 (setq pack-alist (vhdl-sort-alist pack-alist))
13516 ;; remember updated directory/project
13517 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13518 ;; clear directory alists
13519 (unless project
13520 (adelete 'vhdl-entity-alist key)
13521 (adelete 'vhdl-config-alist key)
13522 (adelete 'vhdl-package-alist key)
13523 (adelete 'vhdl-ent-inst-alist key)
13524 (adelete 'vhdl-file-alist key))
13525 ;; put directory contents into cache
13526 (aput 'vhdl-entity-alist key ent-alist)
13527 (aput 'vhdl-config-alist key conf-alist)
13528 (aput 'vhdl-package-alist key pack-alist)
13529 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13530 (aput 'vhdl-file-alist key file-alist)
13531 ;; final messages
13532 (message "Scanning %s %s\"%s\"...done"
13533 (if is-directory "directory" "files") (or num-string "") name)
13534 (unless project (message "Scanning directory...done"))
13535 (when big-files
13536 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13537 ;; save cache when scanned non-interactively
13538 (when (or (not project) (not non-final))
13539 (when (and noninteractive vhdl-speedbar-save-cache)
13540 (vhdl-save-cache key)))
13541 t))
13542
13543 (defun vhdl-scan-project-contents (project)
13544 "Scan the contents of all VHDL files found in the directories and files
13545 of PROJECT."
13546 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13547 (default-dir (vhdl-resolve-env-variable
13548 (nth 1 (aget vhdl-project-alist project))))
13549 (file-exclude-regexp
13550 (or (nth 3 (aget vhdl-project-alist project)) ""))
13551 dir-list-tmp dir dir-name num-dir act-dir recursive)
13552 ;; clear project alists
13553 (adelete 'vhdl-entity-alist project)
13554 (adelete 'vhdl-config-alist project)
13555 (adelete 'vhdl-package-alist project)
13556 (adelete 'vhdl-ent-inst-alist project)
13557 (adelete 'vhdl-file-alist project)
13558 ;; expand directory names by default-directory
13559 (message "Collecting source files...")
13560 (while dir-list
13561 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13562 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13563 (setq recursive (match-string 1 dir)
13564 dir-name (match-string 3 dir))
13565 (setq dir-list-tmp
13566 (cons (concat recursive
13567 (if (file-name-absolute-p dir-name) "" default-dir)
13568 dir-name)
13569 dir-list-tmp))
13570 (setq dir-list (cdr dir-list)))
13571 ;; resolve path wildcards
13572 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13573 ;; expand directories
13574 (while dir-list-tmp
13575 (setq dir (car dir-list-tmp))
13576 ;; get subdirectories
13577 (if (string-match "-r \\(.*[/\\]\\)" dir)
13578 (setq dir-list (append dir-list (vhdl-get-subdirs
13579 (match-string 1 dir))))
13580 (setq dir-list (append dir-list (list dir))))
13581 (setq dir-list-tmp (cdr dir-list-tmp)))
13582 ;; exclude files
13583 (unless (equal file-exclude-regexp "")
13584 (let ((case-fold-search nil))
13585 (while dir-list
13586 (unless (string-match file-exclude-regexp (car dir-list))
13587 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13588 (setq dir-list (cdr dir-list)))
13589 (setq dir-list (nreverse dir-list-tmp))))
13590 (message "Collecting source files...done")
13591 ;; scan for design units for each directory in DIR-LIST
13592 (setq dir-list-tmp nil
13593 num-dir (length dir-list)
13594 act-dir 1)
13595 (while dir-list
13596 (setq dir-name (abbreviate-file-name
13597 (expand-file-name (car dir-list))))
13598 (vhdl-scan-directory-contents dir-name project nil
13599 (format "(%s/%s) " act-dir num-dir)
13600 (cdr dir-list))
13601 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13602 (setq dir-list (cdr dir-list)
13603 act-dir (1+ act-dir)))
13604 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13605 (message "Scanning project \"%s\"...done" project)))
13606
13607 (defun vhdl-update-file-contents (file-name)
13608 "Update hierarchy information by contents of current buffer."
13609 (setq file-name (abbreviate-file-name file-name))
13610 (let* ((dir-name (file-name-directory file-name))
13611 (directory-alist vhdl-directory-alist)
13612 updated)
13613 (while directory-alist
13614 (when (member dir-name (nth 1 (car directory-alist)))
13615 (let* ((vhdl-project (nth 0 (car directory-alist)))
13616 (project (vhdl-project-p))
13617 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13618 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13619 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13620 (ent-inst-list (car (aget vhdl-ent-inst-alist
13621 (or project dir-name) t)))
13622 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13623 (file-entry (aget file-alist file-name t))
13624 (ent-list (nth 0 file-entry))
13625 (arch-list (nth 1 file-entry))
13626 (arch-ent-list (nth 2 file-entry))
13627 (conf-list (nth 3 file-entry))
13628 (pack-list (nth 4 file-entry))
13629 (pack-body-list (nth 5 file-entry))
13630 (inst-ent-list (nth 7 file-entry))
13631 (cache-key (or project dir-name))
13632 arch-alist key ent-key entry)
13633 ;; delete design units previously contained in this file:
13634 ;; entities
13635 (while ent-list
13636 (setq key (car ent-list)
13637 entry (aget ent-alist key t))
13638 (when (equal file-name (nth 1 entry))
13639 (if (nth 3 entry)
13640 (aput 'ent-alist key
13641 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13642 (adelete 'ent-alist key)))
13643 (setq ent-list (cdr ent-list)))
13644 ;; architectures
13645 (while arch-list
13646 (setq key (car arch-list)
13647 ent-key (car arch-ent-list)
13648 entry (aget ent-alist ent-key t)
13649 arch-alist (nth 3 entry))
13650 (when (equal file-name (nth 1 (aget arch-alist key t)))
13651 (adelete 'arch-alist key)
13652 (if (or (nth 1 entry) arch-alist)
13653 (aput 'ent-alist ent-key
13654 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13655 arch-alist (nth 4 entry) (nth 5 entry)))
13656 (adelete 'ent-alist ent-key)))
13657 (setq arch-list (cdr arch-list)
13658 arch-ent-list (cdr arch-ent-list)))
13659 ;; configurations
13660 (while conf-list
13661 (setq key (car conf-list))
13662 (when (equal file-name (nth 1 (aget conf-alist key t)))
13663 (adelete 'conf-alist key))
13664 (setq conf-list (cdr conf-list)))
13665 ;; package declarations
13666 (while pack-list
13667 (setq key (car pack-list)
13668 entry (aget pack-alist key t))
13669 (when (equal file-name (nth 1 entry))
13670 (if (nth 6 entry)
13671 (aput 'pack-alist key
13672 (list (nth 0 entry) nil nil nil nil nil
13673 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13674 (nth 9 entry)))
13675 (adelete 'pack-alist key)))
13676 (setq pack-list (cdr pack-list)))
13677 ;; package bodies
13678 (while pack-body-list
13679 (setq key (car pack-body-list)
13680 entry (aget pack-alist key t))
13681 (when (equal file-name (nth 6 entry))
13682 (if (nth 1 entry)
13683 (aput 'pack-alist key
13684 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13685 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13686 nil nil nil nil))
13687 (adelete 'pack-alist key)))
13688 (setq pack-body-list (cdr pack-body-list)))
13689 ;; instantiated entities
13690 (while inst-ent-list
13691 (setq ent-inst-list
13692 (vhdl-delete (car inst-ent-list) ent-inst-list))
13693 (setq inst-ent-list (cdr inst-ent-list)))
13694 ;; update caches
13695 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13696 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13697 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13698 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13699 ;; scan file
13700 (vhdl-scan-directory-contents file-name project t)
13701 (when (or (and vhdl-speedbar-show-projects project)
13702 (and (not vhdl-speedbar-show-projects) (not project)))
13703 (vhdl-speedbar-refresh project))
13704 (setq updated t)))
13705 (setq directory-alist (cdr directory-alist)))
13706 updated))
13707
13708 (defun vhdl-update-hierarchy ()
13709 "Update directory and hierarchy information in speedbar."
13710 (let ((file-list (reverse vhdl-modified-file-list))
13711 updated)
13712 (when (and vhdl-speedbar-update-on-saving file-list)
13713 (while file-list
13714 (setq updated
13715 (or (vhdl-update-file-contents (car file-list))
13716 updated))
13717 (setq file-list (cdr file-list)))
13718 (setq vhdl-modified-file-list nil)
13719 (vhdl-speedbar-update-current-unit)
13720 (when updated (message "Updating hierarchy...done")))))
13721
13722 ;; structure (parenthesised expression means list of such entries)
13723 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13724 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13725 ;; comp-lib-name level)
13726 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13727 conf-inst-alist level indent
13728 &optional include-top ent-hier)
13729 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13730 entity ENT-KEY."
13731 (let* ((ent-entry (aget ent-alist ent-key t))
13732 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13733 (cdar (last (nth 3 ent-entry)))))
13734 (inst-alist (nth 3 arch-entry))
13735 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13736 hier-list subcomp-list tmp-list inst-key inst-comp-name
13737 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13738 (when (= level 0) (message "Extract design hierarchy..."))
13739 (when include-top
13740 (setq level (1+ level)))
13741 (when (member ent-key ent-hier)
13742 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13743 ;; check configured architecture (already checked during scanning)
13744 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13745 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13746 ;; process all instances
13747 (while inst-alist
13748 (setq inst-entry (car inst-alist)
13749 inst-key (nth 0 inst-entry)
13750 inst-comp-name (nth 4 inst-entry)
13751 inst-conf-key (nth 7 inst-entry))
13752 ;; search entry in configuration's instantiations list
13753 (setq tmp-list conf-inst-alist)
13754 (while (and tmp-list
13755 (not (and (member (nth 0 (car tmp-list))
13756 (list "all" inst-key))
13757 (equal (nth 1 (car tmp-list))
13758 (downcase (or inst-comp-name ""))))))
13759 (setq tmp-list (cdr tmp-list)))
13760 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13761 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13762 (when (and inst-conf-key (not inst-conf-entry))
13763 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13764 ;; determine entity
13765 (setq inst-ent-key
13766 (or (nth 2 (car tmp-list)) ; from configuration
13767 (nth 3 inst-conf-entry) ; from subconfiguration
13768 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13769 ; from configuration spec.
13770 (nth 5 inst-entry))) ; from direct instantiation
13771 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13772 ;; determine architecture
13773 (setq inst-arch-key
13774 (or (nth 3 (car tmp-list)) ; from configuration
13775 (nth 4 inst-conf-entry) ; from subconfiguration
13776 (nth 6 inst-entry) ; from direct instantiation
13777 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13778 ; from configuration spec.
13779 (nth 4 inst-ent-entry) ; MRA
13780 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13781 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13782 ;; set library
13783 (setq inst-lib-key
13784 (or (nth 5 (car tmp-list)) ; from configuration
13785 (nth 8 inst-entry))) ; from direct instantiation
13786 ;; gather information for this instance
13787 (setq comp-entry
13788 (list (nth 1 inst-entry)
13789 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13790 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13791 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13792 (or (nth 0 inst-arch-entry) inst-arch-key)
13793 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13794 (or (nth 0 inst-conf-entry) inst-conf-key)
13795 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13796 inst-lib-key level))
13797 ;; get subcomponent hierarchy
13798 (setq subcomp-list (vhdl-get-hierarchy
13799 ent-alist conf-alist
13800 inst-ent-key inst-arch-key inst-conf-key
13801 (nth 5 inst-conf-entry)
13802 (1+ level) indent nil (cons ent-key ent-hier)))
13803 ;; add to list
13804 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13805 (setq inst-alist (cdr inst-alist)))
13806 (when include-top
13807 (setq hier-list
13808 (cons (list nil nil (nth 0 ent-entry)
13809 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13810 (nth 0 arch-entry)
13811 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13812 nil nil
13813 nil (1- level))
13814 hier-list)))
13815 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13816 hier-list))
13817
13818 (defun vhdl-get-instantiations (ent-key indent)
13819 "Get all instantiations of entity ENT-KEY."
13820 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13821 arch-alist inst-alist ent-inst-list
13822 ent-entry arch-entry inst-entry)
13823 (while ent-alist
13824 (setq ent-entry (car ent-alist))
13825 (setq arch-alist (nth 4 ent-entry))
13826 (while arch-alist
13827 (setq arch-entry (car arch-alist))
13828 (setq inst-alist (nth 4 arch-entry))
13829 (while inst-alist
13830 (setq inst-entry (car inst-alist))
13831 (when (equal ent-key (nth 5 inst-entry))
13832 (setq ent-inst-list
13833 (cons (list (nth 1 inst-entry)
13834 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13835 (nth 1 ent-entry)
13836 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13837 (nth 1 arch-entry)
13838 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13839 ent-inst-list)))
13840 (setq inst-alist (cdr inst-alist)))
13841 (setq arch-alist (cdr arch-alist)))
13842 (setq ent-alist (cdr ent-alist)))
13843 (nreverse ent-inst-list)))
13844
13845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13846 ;; Caching in file
13847
13848 (defun vhdl-save-caches ()
13849 "Save all updated hierarchy caches to file."
13850 (interactive)
13851 (condition-case nil
13852 (when vhdl-speedbar-save-cache
13853 ;; update hierarchy
13854 (vhdl-update-hierarchy)
13855 (let ((project-list vhdl-updated-project-list))
13856 (message "Saving hierarchy caches...")
13857 ;; write updated project caches
13858 (while project-list
13859 (vhdl-save-cache (car project-list))
13860 (setq project-list (cdr project-list)))
13861 (message "Saving hierarchy caches...done")))
13862 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13863 (sit-for 2)))))
13864
13865 (defun vhdl-save-cache (key)
13866 "Save current hierarchy cache to file."
13867 (let* ((orig-buffer (current-buffer))
13868 (vhdl-project key)
13869 (project (vhdl-project-p))
13870 (default-directory key)
13871 (directory (abbreviate-file-name (vhdl-default-directory)))
13872 (file-name (vhdl-resolve-env-variable
13873 (vhdl-replace-string
13874 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13875 (concat
13876 (subst-char-in-string ? ?_ (or project "dir"))
13877 " " (user-login-name)))))
13878 (file-dir-name (expand-file-name file-name directory))
13879 (cache-key (or project directory))
13880 (key (if project "project" "directory")))
13881 (unless (file-exists-p (file-name-directory file-dir-name))
13882 (make-directory (file-name-directory file-dir-name) t))
13883 (if (not (file-writable-p file-dir-name))
13884 (progn (vhdl-warning (format "File not writable: \"%s\""
13885 (abbreviate-file-name file-dir-name)))
13886 (sit-for 2))
13887 (message "Saving cache: \"%s\"" file-dir-name)
13888 (set-buffer (find-file-noselect file-dir-name t t))
13889 (erase-buffer)
13890 (insert ";; -*- Emacs-Lisp -*-\n\n"
13891 ";;; " (file-name-nondirectory file-name)
13892 " - design hierarchy cache file for Emacs VHDL Mode "
13893 vhdl-version "\n")
13894 (insert "\n;; " (if project "Project " "Directory") " : ")
13895 (if project (insert project) (prin1 directory (current-buffer)))
13896 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13897 (user-login-name) "\n\n"
13898 "\n;; version number\n"
13899 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13900 "\n;; " (if project "project" "directory") " name"
13901 "\n(setq " key " ")
13902 (prin1 (or project directory) (current-buffer))
13903 (insert ")\n")
13904 (when (member 'hierarchy vhdl-speedbar-save-cache)
13905 (insert "\n;; entity and architecture cache\n"
13906 "(aput 'vhdl-entity-alist " key " '")
13907 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13908 (insert ")\n\n;; configuration cache\n"
13909 "(aput 'vhdl-config-alist " key " '")
13910 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13911 (insert ")\n\n;; package cache\n"
13912 "(aput 'vhdl-package-alist " key " '")
13913 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13914 (insert ")\n\n;; instantiated entities cache\n"
13915 "(aput 'vhdl-ent-inst-alist " key " '")
13916 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13917 (insert ")\n\n;; design units per file cache\n"
13918 "(aput 'vhdl-file-alist " key " '")
13919 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13920 (when project
13921 (insert ")\n\n;; source directories in project cache\n"
13922 "(aput 'vhdl-directory-alist " key " '")
13923 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13924 (insert ")\n"))
13925 (when (member 'display vhdl-speedbar-save-cache)
13926 (insert "\n;; shown design units cache\n"
13927 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13928 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13929 (current-buffer))
13930 (insert ")\n"))
13931 (setq vhdl-updated-project-list
13932 (delete cache-key vhdl-updated-project-list))
13933 (save-buffer)
13934 (kill-buffer (current-buffer))
13935 (set-buffer orig-buffer))))
13936
13937 (defun vhdl-load-cache (key)
13938 "Load hierarchy cache information from file."
13939 (let* ((vhdl-project key)
13940 (default-directory key)
13941 (directory (vhdl-default-directory))
13942 (file-name (vhdl-resolve-env-variable
13943 (vhdl-replace-string
13944 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13945 (concat
13946 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13947 " " (user-login-name)))))
13948 (file-dir-name (expand-file-name file-name directory))
13949 vhdl-cache-version)
13950 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13951 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13952 (when (file-exists-p file-dir-name)
13953 (condition-case ()
13954 (progn (load-file file-dir-name)
13955 (string< (mapconcat
13956 (lambda (a) (format "%3d" (string-to-number a)))
13957 (split-string "3.33" "\\.") "")
13958 (mapconcat
13959 (lambda (a) (format "%3d" (string-to-number a)))
13960 (split-string vhdl-cache-version "\\.") "")))
13961 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13962 nil))))))
13963
13964 (defun vhdl-require-hierarchy-info ()
13965 "Make sure that hierarchy information is available. Load cache or scan files
13966 if required."
13967 (if (vhdl-project-p)
13968 (unless (or (assoc vhdl-project vhdl-file-alist)
13969 (vhdl-load-cache vhdl-project))
13970 (vhdl-scan-project-contents vhdl-project))
13971 (let ((directory (abbreviate-file-name default-directory)))
13972 (unless (or (assoc directory vhdl-file-alist)
13973 (vhdl-load-cache directory))
13974 (vhdl-scan-directory-contents directory)))))
13975
13976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13977 ;; Add hierarchy browser functionality to speedbar
13978
13979 (defvar vhdl-speedbar-key-map nil
13980 "Keymap used when in the VHDL hierarchy browser mode.")
13981
13982 (defvar vhdl-speedbar-menu-items nil
13983 "Additional menu-items to add to speedbar frame.")
13984
13985 (defun vhdl-speedbar-initialize ()
13986 "Initialize speedbar."
13987 ;; general settings
13988 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13989 ;; VHDL file extensions (extracted from `auto-mode-alist')
13990 (let ((mode-alist auto-mode-alist))
13991 (while mode-alist
13992 (when (eq (cdar mode-alist) 'vhdl-mode)
13993 (speedbar-add-supported-extension (caar mode-alist)))
13994 (setq mode-alist (cdr mode-alist))))
13995 ;; hierarchy browser settings
13996 (when (boundp 'speedbar-mode-functions-list)
13997 ;; special functions
13998 (speedbar-add-mode-functions-list
13999 '("vhdl directory"
14000 (speedbar-item-info . vhdl-speedbar-item-info)
14001 (speedbar-line-directory . speedbar-files-line-path)))
14002 (speedbar-add-mode-functions-list
14003 '("vhdl project"
14004 (speedbar-item-info . vhdl-speedbar-item-info)
14005 (speedbar-line-directory . vhdl-speedbar-line-project)))
14006 ;; keymap
14007 (unless vhdl-speedbar-key-map
14008 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14009 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14010 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14011 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14012 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14013 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14014 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14015 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14016 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14017 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14018 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14019 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14020 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14021 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14022 (let ((key 0))
14023 (while (<= key 9)
14024 (define-key vhdl-speedbar-key-map (int-to-string key)
14025 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14026 (setq key (1+ key)))))
14027 (define-key speedbar-key-map "h"
14028 (lambda () (interactive)
14029 (speedbar-change-initial-expansion-list "vhdl directory")))
14030 (define-key speedbar-key-map "H"
14031 (lambda () (interactive)
14032 (speedbar-change-initial-expansion-list "vhdl project")))
14033 ;; menu
14034 (unless vhdl-speedbar-menu-items
14035 (setq
14036 vhdl-speedbar-menu-items
14037 `(["Edit" speedbar-edit-line t]
14038 ["Expand" speedbar-expand-line
14039 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14040 ["Contract" vhdl-speedbar-contract-level t]
14041 ["Expand All" vhdl-speedbar-expand-all t]
14042 ["Contract All" vhdl-speedbar-contract-all t]
14043 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14044 (while (<= key 9)
14045 (setq menu-list
14046 (cons `[,(if (= key 0) "All" (int-to-string key))
14047 (vhdl-speedbar-set-depth ,key)
14048 :style radio
14049 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14050 :keys ,(int-to-string key)]
14051 menu-list))
14052 (setq key (1+ key)))
14053 (nreverse menu-list))
14054 "--"
14055 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14056 (or (vhdl-speedbar-check-unit 'entity)
14057 (vhdl-speedbar-check-unit 'subprogram))]
14058 ["Place Component" vhdl-speedbar-place-component
14059 (vhdl-speedbar-check-unit 'entity)]
14060 ["Generate Configuration" vhdl-speedbar-configuration
14061 (vhdl-speedbar-check-unit 'architecture)]
14062 ["Select as MRA" vhdl-speedbar-select-mra
14063 (vhdl-speedbar-check-unit 'architecture)]
14064 ["Make" vhdl-speedbar-make-design
14065 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14066 ["Generate Makefile" vhdl-speedbar-generate-makefile
14067 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14068 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14069 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14070 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14071 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14072 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14073 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14074 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14075 ;; hook-ups
14076 (speedbar-add-expansion-list
14077 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14078 vhdl-speedbar-display-directory))
14079 (speedbar-add-expansion-list
14080 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14081 vhdl-speedbar-display-projects))
14082 (setq speedbar-stealthy-function-list
14083 (append
14084 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14085 ("vhdl project" vhdl-speedbar-update-current-project
14086 vhdl-speedbar-update-current-unit)
14087 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14088 ; (speedbar-extension-list-to-regex
14089 ; speedbar-ignored-path-expressions))))
14090 )
14091 speedbar-stealthy-function-list))
14092 (when (eq vhdl-speedbar-display-mode 'directory)
14093 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14094 (when (eq vhdl-speedbar-display-mode 'project)
14095 (setq speedbar-initial-expansion-list-name "vhdl project"))
14096 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14097
14098 (defun vhdl-speedbar (&optional arg)
14099 "Open/close speedbar."
14100 (interactive)
14101 (if (not (fboundp 'speedbar))
14102 (error "WARNING: Speedbar is not available or not installed")
14103 (condition-case ()
14104 (speedbar-frame-mode arg)
14105 (error (error "WARNING: An error occurred while opening speedbar")))))
14106
14107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14108 ;; Display functions
14109
14110 (defvar vhdl-speedbar-last-selected-project nil
14111 "Name of last selected project.")
14112
14113 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14114 (defmacro speedbar-with-writable (&rest forms)
14115 "Allow the buffer to be writable and evaluate FORMS."
14116 (list 'let '((inhibit-read-only t))
14117 (cons 'progn forms)))
14118 (put 'speedbar-with-writable 'lisp-indent-function 0)
14119
14120 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14121 "Display directory and hierarchy information in speedbar."
14122 (setq vhdl-speedbar-show-projects nil)
14123 (setq speedbar-ignored-directory-regexp
14124 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14125 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14126 (setq speedbar-last-selected-file nil)
14127 (speedbar-with-writable
14128 (condition-case nil
14129 (progn
14130 ;; insert directory path
14131 (speedbar-directory-buttons directory depth)
14132 ;; insert subdirectories
14133 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14134 ;; scan and insert hierarchy of current directory
14135 (vhdl-speedbar-insert-dir-hierarchy directory depth
14136 speedbar-power-click)
14137 ;; expand subdirectories
14138 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14139 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14140
14141 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14142 "Display projects and hierarchy information in speedbar."
14143 (setq vhdl-speedbar-show-projects t)
14144 (setq speedbar-ignored-directory-regexp ".")
14145 (setq speedbar-last-selected-file nil)
14146 (setq vhdl-speedbar-last-selected-project nil)
14147 (speedbar-with-writable
14148 (condition-case nil
14149 ;; insert projects
14150 (vhdl-speedbar-insert-projects)
14151 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14152 (setq speedbar-full-text-cache nil)) ; prevent caching
14153
14154 (defun vhdl-speedbar-insert-projects ()
14155 "Insert all projects in speedbar."
14156 (vhdl-speedbar-make-title-line "Projects:")
14157 (let ((project-alist (if vhdl-project-sort
14158 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14159 vhdl-project-alist))
14160 (vhdl-speedbar-update-current-unit nil))
14161 ;; insert projects
14162 (while project-alist
14163 (speedbar-make-tag-line
14164 'angle ?+ 'vhdl-speedbar-expand-project
14165 (caar project-alist) (caar project-alist)
14166 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14167 (setq project-alist (cdr project-alist)))
14168 (setq project-alist vhdl-project-alist)
14169 ;; expand projects
14170 (while project-alist
14171 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14172 (goto-char (point-min))
14173 (when (re-search-forward
14174 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14175 (goto-char (match-end 1))
14176 (speedbar-do-function-pointer)))
14177 (setq project-alist (cdr project-alist))))
14178 ; (vhdl-speedbar-update-current-project)
14179 ; (vhdl-speedbar-update-current-unit nil t)
14180 )
14181
14182 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14183 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14184 otherwise use cached data."
14185 (when (or rescan (and (not (assoc project vhdl-file-alist))
14186 (not (vhdl-load-cache project))))
14187 (vhdl-scan-project-contents project))
14188 ;; insert design hierarchy
14189 (vhdl-speedbar-insert-hierarchy
14190 (aget vhdl-entity-alist project t)
14191 (aget vhdl-config-alist project t)
14192 (aget vhdl-package-alist project t)
14193 (car (aget vhdl-ent-inst-alist project t)) indent)
14194 (insert (int-to-string indent) ":\n")
14195 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14196 (put-text-property (1- (point)) (point) 'invisible nil)
14197 ;; expand design units
14198 (vhdl-speedbar-expand-units project))
14199
14200 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14201 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14202 otherwise use cached data."
14203 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14204 (not (vhdl-load-cache directory))))
14205 (vhdl-scan-directory-contents directory))
14206 ;; insert design hierarchy
14207 (vhdl-speedbar-insert-hierarchy
14208 (aget vhdl-entity-alist directory t)
14209 (aget vhdl-config-alist directory t)
14210 (aget vhdl-package-alist directory t)
14211 (car (aget vhdl-ent-inst-alist directory t)) depth)
14212 ;; expand design units
14213 (vhdl-speedbar-expand-units directory)
14214 (aput 'vhdl-directory-alist directory (list (list directory))))
14215
14216 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14217 ent-inst-list depth)
14218 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14219 (if (not (or ent-alist conf-alist pack-alist))
14220 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14221 (let (ent-entry conf-entry pack-entry)
14222 ;; insert entities
14223 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14224 (while ent-alist
14225 (setq ent-entry (car ent-alist))
14226 (speedbar-make-tag-line
14227 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14228 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14229 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14230 'vhdl-speedbar-entity-face depth)
14231 (unless (nth 2 ent-entry)
14232 (end-of-line 0) (insert "!") (forward-char 1))
14233 (unless (member (nth 0 ent-entry) ent-inst-list)
14234 (end-of-line 0) (insert " (top)") (forward-char 1))
14235 (setq ent-alist (cdr ent-alist)))
14236 ;; insert configurations
14237 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14238 (while conf-alist
14239 (setq conf-entry (car conf-alist))
14240 (speedbar-make-tag-line
14241 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14242 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14243 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14244 'vhdl-speedbar-configuration-face depth)
14245 (setq conf-alist (cdr conf-alist)))
14246 ;; insert packages
14247 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14248 (while pack-alist
14249 (setq pack-entry (car pack-alist))
14250 (vhdl-speedbar-make-pack-line
14251 (nth 0 pack-entry) (nth 1 pack-entry)
14252 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14253 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14254 depth)
14255 (setq pack-alist (cdr pack-alist))))))
14256
14257 (defun vhdl-speedbar-rescan-hierarchy ()
14258 "Rescan hierarchy for the directory or project under the cursor."
14259 (interactive)
14260 (let (key path)
14261 (cond
14262 ;; current project
14263 (vhdl-speedbar-show-projects
14264 (setq key (vhdl-speedbar-line-project))
14265 (vhdl-scan-project-contents key))
14266 ;; top-level directory
14267 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14268 (re-search-forward "[0-9]+:" nil t)
14269 (vhdl-scan-directory-contents
14270 (abbreviate-file-name (speedbar-line-directory))))
14271 ;; current directory
14272 (t (setq path (speedbar-line-directory))
14273 (string-match "^\\(.+[/\\]\\)" path)
14274 (vhdl-scan-directory-contents
14275 (abbreviate-file-name (match-string 1 path)))))
14276 (vhdl-speedbar-refresh key)))
14277
14278 (defun vhdl-speedbar-expand-dirs (directory)
14279 "Expand subdirectories in DIRECTORY according to
14280 `speedbar-shown-directories'."
14281 ;; (nicked from `speedbar-default-directory-list')
14282 (let ((sf (cdr (reverse speedbar-shown-directories)))
14283 (vhdl-speedbar-update-current-unit nil))
14284 (setq speedbar-shown-directories
14285 (list (expand-file-name default-directory)))
14286 (while sf
14287 (when (speedbar-goto-this-file (car sf))
14288 (beginning-of-line)
14289 (when (looking-at "[0-9]+:\\s-*<")
14290 (goto-char (match-end 0))
14291 (speedbar-do-function-pointer)))
14292 (setq sf (cdr sf))))
14293 (vhdl-speedbar-update-current-unit nil t))
14294
14295 (defun vhdl-speedbar-expand-units (key)
14296 "Expand design units in directory/project KEY according to
14297 `vhdl-speedbar-shown-unit-alist'."
14298 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14299 (vhdl-speedbar-update-current-unit nil)
14300 vhdl-updated-project-list)
14301 (adelete 'vhdl-speedbar-shown-unit-alist key)
14302 (vhdl-prepare-search-1
14303 (while unit-alist ; expand units
14304 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14305 (beginning-of-line)
14306 (let ((arch-alist (nth 1 (car unit-alist)))
14307 position)
14308 (when (looking-at "^[0-9]+:\\s-*\\[")
14309 (goto-char (match-end 0))
14310 (setq position (point))
14311 (speedbar-do-function-pointer)
14312 (select-frame speedbar-frame)
14313 (while arch-alist ; expand architectures
14314 (goto-char position)
14315 (when (re-search-forward
14316 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14317 (car arch-alist) "\\>\\)") nil t)
14318 (beginning-of-line)
14319 (when (looking-at "^[0-9]+:\\s-*{")
14320 (goto-char (match-end 0))
14321 (speedbar-do-function-pointer)
14322 (select-frame speedbar-frame)))
14323 (setq arch-alist (cdr arch-alist))))
14324 (setq unit-alist (cdr unit-alist))))))
14325 (vhdl-speedbar-update-current-unit nil t))
14326
14327 (defun vhdl-speedbar-contract-level ()
14328 "Contract current level in current directory/project."
14329 (interactive)
14330 (when (or (save-excursion
14331 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14332 (and (save-excursion
14333 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14334 (re-search-backward
14335 (format "^[0-%d]:\\s-*[[{<]-"
14336 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14337 (goto-char (match-end 0))
14338 (speedbar-do-function-pointer)
14339 (speedbar-center-buffer-smartly)))
14340
14341 (defun vhdl-speedbar-contract-all ()
14342 "Contract all expanded design units in current directory/project."
14343 (interactive)
14344 (if (and vhdl-speedbar-show-projects
14345 (save-excursion (beginning-of-line) (looking-at "^0:")))
14346 (progn (setq vhdl-speedbar-shown-project-list nil)
14347 (vhdl-speedbar-refresh))
14348 (let ((key (vhdl-speedbar-line-key)))
14349 (adelete 'vhdl-speedbar-shown-unit-alist key)
14350 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14351 (when (memq 'display vhdl-speedbar-save-cache)
14352 (add-to-list 'vhdl-updated-project-list key)))))
14353
14354 (defun vhdl-speedbar-expand-all ()
14355 "Expand all design units in current directory/project."
14356 (interactive)
14357 (let* ((key (vhdl-speedbar-line-key))
14358 (ent-alist (aget vhdl-entity-alist key t))
14359 (conf-alist (aget vhdl-config-alist key t))
14360 (pack-alist (aget vhdl-package-alist key t))
14361 arch-alist unit-alist subunit-alist)
14362 (add-to-list 'vhdl-speedbar-shown-project-list key)
14363 (while ent-alist
14364 (setq arch-alist (nth 4 (car ent-alist)))
14365 (setq subunit-alist nil)
14366 (while arch-alist
14367 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14368 (setq arch-alist (cdr arch-alist)))
14369 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14370 (setq ent-alist (cdr ent-alist)))
14371 (while conf-alist
14372 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14373 (setq conf-alist (cdr conf-alist)))
14374 (while pack-alist
14375 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14376 (setq pack-alist (cdr pack-alist)))
14377 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14378 (vhdl-speedbar-refresh)
14379 (when (memq 'display vhdl-speedbar-save-cache)
14380 (add-to-list 'vhdl-updated-project-list key))))
14381
14382 (defun vhdl-speedbar-expand-project (text token indent)
14383 "Expand/contract the project under the cursor."
14384 (cond
14385 ((string-match "+" text) ; expand project
14386 (speedbar-change-expand-button-char ?-)
14387 (unless (member token vhdl-speedbar-shown-project-list)
14388 (setq vhdl-speedbar-shown-project-list
14389 (cons token vhdl-speedbar-shown-project-list)))
14390 (speedbar-with-writable
14391 (save-excursion
14392 (end-of-line) (forward-char 1)
14393 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14394 speedbar-power-click))))
14395 ((string-match "-" text) ; contract project
14396 (speedbar-change-expand-button-char ?+)
14397 (setq vhdl-speedbar-shown-project-list
14398 (delete token vhdl-speedbar-shown-project-list))
14399 (speedbar-delete-subblock indent))
14400 (t (error "Nothing to display")))
14401 (when (equal (selected-frame) speedbar-frame)
14402 (speedbar-center-buffer-smartly)))
14403
14404 (defun vhdl-speedbar-expand-entity (text token indent)
14405 "Expand/contract the entity under the cursor."
14406 (cond
14407 ((string-match "+" text) ; expand entity
14408 (let* ((key (vhdl-speedbar-line-key indent))
14409 (ent-alist (aget vhdl-entity-alist key t))
14410 (ent-entry (aget ent-alist token t))
14411 (arch-alist (nth 3 ent-entry))
14412 (inst-alist (vhdl-get-instantiations token indent))
14413 (subpack-alist (nth 5 ent-entry))
14414 (multiple-arch (> (length arch-alist) 1))
14415 arch-entry inst-entry)
14416 (if (not (or arch-alist inst-alist subpack-alist))
14417 (speedbar-change-expand-button-char ??)
14418 (speedbar-change-expand-button-char ?-)
14419 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14420 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14421 (aput 'unit-alist token nil)
14422 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14423 (speedbar-with-writable
14424 (save-excursion
14425 (end-of-line) (forward-char 1)
14426 ;; insert architectures
14427 (when arch-alist
14428 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14429 (while arch-alist
14430 (setq arch-entry (car arch-alist))
14431 (speedbar-make-tag-line
14432 'curly ?+ 'vhdl-speedbar-expand-architecture
14433 (cons token (nth 0 arch-entry))
14434 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14435 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14436 'vhdl-speedbar-architecture-face (1+ indent))
14437 (when (and multiple-arch
14438 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14439 (end-of-line 0) (insert " (mra)") (forward-char 1))
14440 (setq arch-alist (cdr arch-alist)))
14441 ;; insert instantiations
14442 (when inst-alist
14443 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14444 (while inst-alist
14445 (setq inst-entry (car inst-alist))
14446 (vhdl-speedbar-make-inst-line
14447 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14448 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14449 nil nil nil (1+ indent) 0 " in ")
14450 (setq inst-alist (cdr inst-alist)))
14451 ;; insert required packages
14452 (vhdl-speedbar-insert-subpackages
14453 subpack-alist (1+ indent) indent)))
14454 (when (memq 'display vhdl-speedbar-save-cache)
14455 (add-to-list 'vhdl-updated-project-list key))
14456 (vhdl-speedbar-update-current-unit t t))))
14457 ((string-match "-" text) ; contract entity
14458 (speedbar-change-expand-button-char ?+)
14459 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14460 (let* ((key (vhdl-speedbar-line-key indent))
14461 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14462 (adelete 'unit-alist token)
14463 (if unit-alist
14464 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14465 (adelete 'vhdl-speedbar-shown-unit-alist key))
14466 (speedbar-delete-subblock indent)
14467 (when (memq 'display vhdl-speedbar-save-cache)
14468 (add-to-list 'vhdl-updated-project-list key))))
14469 (t (error "Nothing to display")))
14470 (when (equal (selected-frame) speedbar-frame)
14471 (speedbar-center-buffer-smartly)))
14472
14473 (defun vhdl-speedbar-expand-architecture (text token indent)
14474 "Expand/contract the architecture under the cursor."
14475 (cond
14476 ((string-match "+" text) ; expand architecture
14477 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14478 (ent-alist (aget vhdl-entity-alist key t))
14479 (conf-alist (aget vhdl-config-alist key t))
14480 (hier-alist (vhdl-get-hierarchy
14481 ent-alist conf-alist (car token) (cdr token) nil nil
14482 0 (1- indent)))
14483 (ent-entry (aget ent-alist (car token) t))
14484 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14485 (subpack-alist (nth 4 arch-entry))
14486 entry)
14487 (if (not (or hier-alist subpack-alist))
14488 (speedbar-change-expand-button-char ??)
14489 (speedbar-change-expand-button-char ?-)
14490 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14491 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14492 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14493 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14494 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14495 (speedbar-with-writable
14496 (save-excursion
14497 (end-of-line) (forward-char 1)
14498 ;; insert instance hierarchy
14499 (when hier-alist
14500 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14501 (1+ indent)))
14502 (while hier-alist
14503 (setq entry (car hier-alist))
14504 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14505 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14506 (vhdl-speedbar-make-inst-line
14507 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14508 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14509 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14510 (setq hier-alist (cdr hier-alist)))
14511 ;; insert required packages
14512 (vhdl-speedbar-insert-subpackages
14513 subpack-alist (1+ indent) (1- indent))))
14514 (when (memq 'display vhdl-speedbar-save-cache)
14515 (add-to-list 'vhdl-updated-project-list key))
14516 (vhdl-speedbar-update-current-unit t t))))
14517 ((string-match "-" text) ; contract architecture
14518 (speedbar-change-expand-button-char ?+)
14519 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14520 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14521 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14522 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14523 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14524 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14525 (speedbar-delete-subblock indent)
14526 (when (memq 'display vhdl-speedbar-save-cache)
14527 (add-to-list 'vhdl-updated-project-list key))))
14528 (t (error "Nothing to display")))
14529 (when (equal (selected-frame) speedbar-frame)
14530 (speedbar-center-buffer-smartly)))
14531
14532 (defun vhdl-speedbar-expand-config (text token indent)
14533 "Expand/contract the configuration under the cursor."
14534 (cond
14535 ((string-match "+" text) ; expand configuration
14536 (let* ((key (vhdl-speedbar-line-key indent))
14537 (conf-alist (aget vhdl-config-alist key t))
14538 (conf-entry (aget conf-alist token))
14539 (ent-alist (aget vhdl-entity-alist key t))
14540 (hier-alist (vhdl-get-hierarchy
14541 ent-alist conf-alist (nth 3 conf-entry)
14542 (nth 4 conf-entry) token (nth 5 conf-entry)
14543 0 indent t))
14544 (subpack-alist (nth 6 conf-entry))
14545 entry)
14546 (if (not (or hier-alist subpack-alist))
14547 (speedbar-change-expand-button-char ??)
14548 (speedbar-change-expand-button-char ?-)
14549 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14550 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14551 (aput 'unit-alist token nil)
14552 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14553 (speedbar-with-writable
14554 (save-excursion
14555 (end-of-line) (forward-char 1)
14556 ;; insert instance hierarchy
14557 (when hier-alist
14558 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14559 (while hier-alist
14560 (setq entry (car hier-alist))
14561 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14562 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14563 (vhdl-speedbar-make-inst-line
14564 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14565 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14566 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14567 (setq hier-alist (cdr hier-alist)))
14568 ;; insert required packages
14569 (vhdl-speedbar-insert-subpackages
14570 subpack-alist (1+ indent) indent)))
14571 (when (memq 'display vhdl-speedbar-save-cache)
14572 (add-to-list 'vhdl-updated-project-list key))
14573 (vhdl-speedbar-update-current-unit t t))))
14574 ((string-match "-" text) ; contract configuration
14575 (speedbar-change-expand-button-char ?+)
14576 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14577 (let* ((key (vhdl-speedbar-line-key indent))
14578 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14579 (adelete 'unit-alist token)
14580 (if unit-alist
14581 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14582 (adelete 'vhdl-speedbar-shown-unit-alist key))
14583 (speedbar-delete-subblock indent)
14584 (when (memq 'display vhdl-speedbar-save-cache)
14585 (add-to-list 'vhdl-updated-project-list key))))
14586 (t (error "Nothing to display")))
14587 (when (equal (selected-frame) speedbar-frame)
14588 (speedbar-center-buffer-smartly)))
14589
14590 (defun vhdl-speedbar-expand-package (text token indent)
14591 "Expand/contract the package under the cursor."
14592 (cond
14593 ((string-match "+" text) ; expand package
14594 (let* ((key (vhdl-speedbar-line-key indent))
14595 (pack-alist (aget vhdl-package-alist key t))
14596 (pack-entry (aget pack-alist token t))
14597 (comp-alist (nth 3 pack-entry))
14598 (func-alist (nth 4 pack-entry))
14599 (func-body-alist (nth 8 pack-entry))
14600 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14601 comp-entry func-entry func-body-entry)
14602 (if (not (or comp-alist func-alist subpack-alist))
14603 (speedbar-change-expand-button-char ??)
14604 (speedbar-change-expand-button-char ?-)
14605 ;; add package to `vhdl-speedbar-shown-unit-alist'
14606 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14607 (aput 'unit-alist token nil)
14608 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14609 (speedbar-with-writable
14610 (save-excursion
14611 (end-of-line) (forward-char 1)
14612 ;; insert components
14613 (when comp-alist
14614 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14615 (while comp-alist
14616 (setq comp-entry (car comp-alist))
14617 (speedbar-make-tag-line
14618 nil nil nil
14619 (cons token (nth 0 comp-entry))
14620 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14621 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14622 'vhdl-speedbar-entity-face (1+ indent))
14623 (setq comp-alist (cdr comp-alist)))
14624 ;; insert subprograms
14625 (when func-alist
14626 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14627 (while func-alist
14628 (setq func-entry (car func-alist)
14629 func-body-entry (aget func-body-alist (car func-entry) t))
14630 (when (nth 2 func-entry)
14631 (vhdl-speedbar-make-subprogram-line
14632 (nth 1 func-entry)
14633 (cons (nth 2 func-entry) (nth 3 func-entry))
14634 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14635 (1+ indent)))
14636 (setq func-alist (cdr func-alist)))
14637 ;; insert required packages
14638 (vhdl-speedbar-insert-subpackages
14639 subpack-alist (1+ indent) indent)))
14640 (when (memq 'display vhdl-speedbar-save-cache)
14641 (add-to-list 'vhdl-updated-project-list key))
14642 (vhdl-speedbar-update-current-unit t t))))
14643 ((string-match "-" text) ; contract package
14644 (speedbar-change-expand-button-char ?+)
14645 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14646 (let* ((key (vhdl-speedbar-line-key indent))
14647 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14648 (adelete 'unit-alist token)
14649 (if unit-alist
14650 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14651 (adelete 'vhdl-speedbar-shown-unit-alist key))
14652 (speedbar-delete-subblock indent)
14653 (when (memq 'display vhdl-speedbar-save-cache)
14654 (add-to-list 'vhdl-updated-project-list key))))
14655 (t (error "Nothing to display")))
14656 (when (equal (selected-frame) speedbar-frame)
14657 (speedbar-center-buffer-smartly)))
14658
14659 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14660 "Insert required packages."
14661 (let* ((pack-alist (aget vhdl-package-alist
14662 (vhdl-speedbar-line-key dir-indent) t))
14663 pack-key lib-name pack-entry)
14664 (when subpack-alist
14665 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14666 (while subpack-alist
14667 (setq pack-key (cdar subpack-alist)
14668 lib-name (caar subpack-alist))
14669 (setq pack-entry (aget pack-alist pack-key t))
14670 (vhdl-speedbar-make-subpack-line
14671 (or (nth 0 pack-entry) pack-key) lib-name
14672 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14673 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14674 (setq subpack-alist (cdr subpack-alist)))))
14675
14676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14677 ;; Display help functions
14678
14679 (defvar vhdl-speedbar-update-current-unit t
14680 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14681
14682 (defun vhdl-speedbar-update-current-project ()
14683 "Highlight project that is currently active."
14684 (when (and vhdl-speedbar-show-projects
14685 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14686 (and (boundp 'speedbar-frame)
14687 (frame-live-p speedbar-frame)))
14688 (let ((last-frame (selected-frame))
14689 (project-alist vhdl-project-alist)
14690 pos)
14691 (select-frame speedbar-frame)
14692 (speedbar-with-writable
14693 (save-excursion
14694 (while project-alist
14695 (goto-char (point-min))
14696 (when (re-search-forward
14697 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14698 (put-text-property (match-beginning 1) (match-end 1) 'face
14699 (if (equal (caar project-alist) vhdl-project)
14700 'speedbar-selected-face
14701 'speedbar-directory-face))
14702 (when (equal (caar project-alist) vhdl-project)
14703 (setq pos (1- (match-beginning 1)))))
14704 (setq project-alist (cdr project-alist))))
14705 (when pos (goto-char pos)))
14706 (select-frame last-frame)
14707 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14708 t)
14709
14710 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14711 "Highlight all design units that are contained in the current file.
14712 NO-POSITION non-nil means do not re-position cursor."
14713 (let ((last-frame (selected-frame))
14714 (project-list vhdl-speedbar-shown-project-list)
14715 file-alist pos file-name)
14716 ;; get current file name
14717 (if (fboundp 'speedbar-select-attached-frame)
14718 (speedbar-select-attached-frame)
14719 (select-frame speedbar-attached-frame))
14720 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14721 (when (and vhdl-speedbar-update-current-unit
14722 (or always (not (equal file-name speedbar-last-selected-file))))
14723 (if vhdl-speedbar-show-projects
14724 (while project-list
14725 (setq file-alist (append file-alist (aget vhdl-file-alist
14726 (car project-list) t)))
14727 (setq project-list (cdr project-list)))
14728 (setq file-alist (aget vhdl-file-alist
14729 (abbreviate-file-name default-directory) t)))
14730 (select-frame speedbar-frame)
14731 (set-buffer speedbar-buffer)
14732 (speedbar-with-writable
14733 (vhdl-prepare-search-1
14734 (save-excursion
14735 ;; unhighlight last units
14736 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14737 (vhdl-speedbar-update-units
14738 "\\[.\\] " (nth 0 file-entry)
14739 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14740 (vhdl-speedbar-update-units
14741 "{.} " (nth 1 file-entry)
14742 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14743 (vhdl-speedbar-update-units
14744 "\\[.\\] " (nth 3 file-entry)
14745 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14746 (vhdl-speedbar-update-units
14747 "[]>] " (nth 4 file-entry)
14748 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14749 (vhdl-speedbar-update-units
14750 "\\[.\\].+(" '("body")
14751 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14752 (vhdl-speedbar-update-units
14753 "> " (nth 6 file-entry)
14754 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14755 ;; highlight current units
14756 (let* ((file-entry (aget file-alist file-name t)))
14757 (setq
14758 pos (vhdl-speedbar-update-units
14759 "\\[.\\] " (nth 0 file-entry)
14760 file-name 'vhdl-speedbar-entity-selected-face pos)
14761 pos (vhdl-speedbar-update-units
14762 "{.} " (nth 1 file-entry)
14763 file-name 'vhdl-speedbar-architecture-selected-face pos)
14764 pos (vhdl-speedbar-update-units
14765 "\\[.\\] " (nth 3 file-entry)
14766 file-name 'vhdl-speedbar-configuration-selected-face pos)
14767 pos (vhdl-speedbar-update-units
14768 "[]>] " (nth 4 file-entry)
14769 file-name 'vhdl-speedbar-package-selected-face pos)
14770 pos (vhdl-speedbar-update-units
14771 "\\[.\\].+(" '("body")
14772 file-name 'vhdl-speedbar-package-selected-face pos)
14773 pos (vhdl-speedbar-update-units
14774 "> " (nth 6 file-entry)
14775 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14776 ;; move speedbar so the first highlighted unit is visible
14777 (when (and pos (not no-position))
14778 (goto-char pos)
14779 (speedbar-center-buffer-smartly)
14780 (speedbar-position-cursor-on-line))
14781 (setq speedbar-last-selected-file file-name))
14782 (select-frame last-frame)
14783 t))
14784
14785 (defun vhdl-speedbar-update-units (text unit-list file-name face
14786 &optional pos)
14787 "Help function to highlight design units."
14788 (while unit-list
14789 (goto-char (point-min))
14790 (while (re-search-forward
14791 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14792 (when (equal file-name (car (get-text-property
14793 (match-beginning 1) 'speedbar-token)))
14794 (setq pos (or pos (point-marker)))
14795 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14796 (setq unit-list (cdr unit-list)))
14797 pos)
14798
14799 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14800 ent-name ent-file-marker
14801 arch-name arch-file-marker
14802 conf-name conf-file-marker
14803 lib-name depth offset delimiter)
14804 "Insert instantiation entry."
14805 (let ((start (point))
14806 visible-start)
14807 (insert (int-to-string depth) ":")
14808 (put-text-property start (point) 'invisible t)
14809 (setq visible-start (point))
14810 (insert-char ? (* depth speedbar-indentation-width))
14811 (while (> offset 0)
14812 (insert "|")
14813 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14814 (setq offset (1- offset)))
14815 (put-text-property visible-start (point) 'invisible nil)
14816 (setq start (point))
14817 (insert ">")
14818 (speedbar-make-button start (point) nil nil nil)
14819 (setq visible-start (point))
14820 (insert " ")
14821 (setq start (point))
14822 (if (not inst-name)
14823 (insert "(top)")
14824 (insert inst-name)
14825 (speedbar-make-button
14826 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14827 'vhdl-speedbar-find-file inst-file-marker))
14828 (insert delimiter)
14829 (when ent-name
14830 (setq start (point))
14831 (insert ent-name)
14832 (speedbar-make-button
14833 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14834 'vhdl-speedbar-find-file ent-file-marker)
14835 (when arch-name
14836 (insert " (")
14837 (setq start (point))
14838 (insert arch-name)
14839 (speedbar-make-button
14840 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14841 'vhdl-speedbar-find-file arch-file-marker)
14842 (insert ")"))
14843 (when conf-name
14844 (insert " (")
14845 (setq start (point))
14846 (insert conf-name)
14847 (speedbar-make-button
14848 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14849 'vhdl-speedbar-find-file conf-file-marker)
14850 (insert ")")))
14851 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14852 (setq start (point))
14853 (insert " (" lib-name ")")
14854 (put-text-property (+ 2 start) (1- (point)) 'face
14855 'vhdl-speedbar-library-face))
14856 (insert-char ?\n 1)
14857 (put-text-property visible-start (point) 'invisible nil)))
14858
14859 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14860 body-file-marker depth)
14861 "Insert package entry."
14862 (let ((start (point))
14863 visible-start)
14864 (insert (int-to-string depth) ":")
14865 (put-text-property start (point) 'invisible t)
14866 (setq visible-start (point))
14867 (insert-char ? (* depth speedbar-indentation-width))
14868 (put-text-property visible-start (point) 'invisible nil)
14869 (setq start (point))
14870 (insert "[+]")
14871 (speedbar-make-button
14872 start (point) 'speedbar-button-face 'speedbar-highlight-face
14873 'vhdl-speedbar-expand-package pack-key)
14874 (setq visible-start (point))
14875 (insert-char ? 1 nil)
14876 (setq start (point))
14877 (insert pack-name)
14878 (speedbar-make-button
14879 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14880 'vhdl-speedbar-find-file pack-file-marker)
14881 (unless (car pack-file-marker)
14882 (insert "!"))
14883 (when (car body-file-marker)
14884 (insert " (")
14885 (setq start (point))
14886 (insert "body")
14887 (speedbar-make-button
14888 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14889 'vhdl-speedbar-find-file 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-subpack-line (pack-name lib-name pack-file-marker
14895 pack-body-file-marker depth)
14896 "Insert used package entry."
14897 (let ((start (point))
14898 visible-start)
14899 (insert (int-to-string depth) ":")
14900 (put-text-property start (point) 'invisible t)
14901 (setq visible-start (point))
14902 (insert-char ? (* depth speedbar-indentation-width))
14903 (put-text-property visible-start (point) 'invisible nil)
14904 (setq start (point))
14905 (insert ">")
14906 (speedbar-make-button start (point) nil nil nil)
14907 (setq visible-start (point))
14908 (insert " ")
14909 (setq start (point))
14910 (insert pack-name)
14911 (speedbar-make-button
14912 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14913 'vhdl-speedbar-find-file pack-file-marker)
14914 (when (car pack-body-file-marker)
14915 (insert " (")
14916 (setq start (point))
14917 (insert "body")
14918 (speedbar-make-button
14919 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14920 'vhdl-speedbar-find-file pack-body-file-marker)
14921 (insert ")"))
14922 (setq start (point))
14923 (insert " (" lib-name ")")
14924 (put-text-property (+ 2 start) (1- (point)) 'face
14925 'vhdl-speedbar-library-face)
14926 (insert-char ?\n 1)
14927 (put-text-property visible-start (point) 'invisible nil)))
14928
14929 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14930 func-body-file-marker
14931 depth)
14932 "Insert subprogram entry."
14933 (let ((start (point))
14934 visible-start)
14935 (insert (int-to-string depth) ":")
14936 (put-text-property start (point) 'invisible t)
14937 (setq visible-start (point))
14938 (insert-char ? (* depth speedbar-indentation-width))
14939 (put-text-property visible-start (point) 'invisible nil)
14940 (setq start (point))
14941 (insert ">")
14942 (speedbar-make-button start (point) nil nil nil)
14943 (setq visible-start (point))
14944 (insert " ")
14945 (setq start (point))
14946 (insert func-name)
14947 (speedbar-make-button
14948 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14949 'vhdl-speedbar-find-file func-file-marker)
14950 (when (car func-body-file-marker)
14951 (insert " (")
14952 (setq start (point))
14953 (insert "body")
14954 (speedbar-make-button
14955 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14956 'vhdl-speedbar-find-file func-body-file-marker)
14957 (insert ")"))
14958 (insert-char ?\n 1)
14959 (put-text-property visible-start (point) 'invisible nil)))
14960
14961 (defun vhdl-speedbar-make-title-line (text &optional depth)
14962 "Insert design unit title entry."
14963 (let ((start (point))
14964 visible-start)
14965 (when depth
14966 (insert (int-to-string depth) ":")
14967 (put-text-property start (point) 'invisible t))
14968 (setq visible-start (point))
14969 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14970 (setq start (point))
14971 (insert text)
14972 (speedbar-make-button start (point) nil nil nil nil)
14973 (insert-char ?\n 1)
14974 (put-text-property visible-start (point) 'invisible nil)))
14975
14976 (defun vhdl-speedbar-insert-dirs (files level)
14977 "Insert subdirectories."
14978 (let ((dirs (car files)))
14979 (while dirs
14980 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14981 (car dirs) 'speedbar-dir-follow nil
14982 'speedbar-directory-face level)
14983 (setq dirs (cdr dirs)))))
14984
14985 (defun vhdl-speedbar-dired (text token indent)
14986 "Speedbar click handler for directory expand button in hierarchy mode."
14987 (cond ((string-match "+" text) ; we have to expand this dir
14988 (setq speedbar-shown-directories
14989 (cons (expand-file-name
14990 (concat (speedbar-line-directory indent) token "/"))
14991 speedbar-shown-directories))
14992 (speedbar-change-expand-button-char ?-)
14993 (speedbar-reset-scanners)
14994 (speedbar-with-writable
14995 (save-excursion
14996 (end-of-line) (forward-char 1)
14997 (vhdl-speedbar-insert-dirs
14998 (speedbar-file-lists
14999 (concat (speedbar-line-directory indent) token "/"))
15000 (1+ indent))
15001 (speedbar-reset-scanners)
15002 (vhdl-speedbar-insert-dir-hierarchy
15003 (abbreviate-file-name
15004 (concat (speedbar-line-directory indent) token "/"))
15005 (1+ indent) speedbar-power-click)))
15006 (vhdl-speedbar-update-current-unit t t))
15007 ((string-match "-" text) ; we have to contract this node
15008 (speedbar-reset-scanners)
15009 (let ((oldl speedbar-shown-directories)
15010 (newl nil)
15011 (td (expand-file-name
15012 (concat (speedbar-line-directory indent) token))))
15013 (while oldl
15014 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15015 (setq newl (cons (car oldl) newl)))
15016 (setq oldl (cdr oldl)))
15017 (setq speedbar-shown-directories (nreverse newl)))
15018 (speedbar-change-expand-button-char ?+)
15019 (speedbar-delete-subblock indent))
15020 (t (error "Nothing to display")))
15021 (when (equal (selected-frame) speedbar-frame)
15022 (speedbar-center-buffer-smartly)))
15023
15024 (defun vhdl-speedbar-item-info ()
15025 "Derive and display information about this line item."
15026 (save-excursion
15027 (beginning-of-line)
15028 ;; skip invisible number info
15029 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15030 (cond
15031 ;; project/directory entry
15032 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15033 (if vhdl-speedbar-show-projects
15034 (message "Project \"%s\"" (match-string-no-properties 1))
15035 (speedbar-files-item-info)))
15036 ;; design unit entry
15037 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15038 (goto-char (match-end 1))
15039 (let ((face (get-text-property (point) 'face)))
15040 (message
15041 "%s \"%s\" in \"%s\""
15042 ;; design unit kind
15043 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15044 (eq face 'vhdl-speedbar-entity-selected-face))
15045 (if (equal (match-string 2) ">") "Component" "Entity"))
15046 ((or (eq face 'vhdl-speedbar-architecture-face)
15047 (eq face 'vhdl-speedbar-architecture-selected-face))
15048 "Architecture")
15049 ((or (eq face 'vhdl-speedbar-configuration-face)
15050 (eq face 'vhdl-speedbar-configuration-selected-face))
15051 "Configuration")
15052 ((or (eq face 'vhdl-speedbar-package-face)
15053 (eq face 'vhdl-speedbar-package-selected-face))
15054 "Package")
15055 ((or (eq face 'vhdl-speedbar-instantiation-face)
15056 (eq face 'vhdl-speedbar-instantiation-selected-face))
15057 "Instantiation")
15058 ((eq face 'vhdl-speedbar-subprogram-face)
15059 "Subprogram")
15060 (t ""))
15061 ;; design unit name
15062 (buffer-substring-no-properties
15063 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15064 (match-end 1))
15065 ;; file name
15066 (file-relative-name
15067 (or (car (get-text-property (point) 'speedbar-token))
15068 "?")
15069 (vhdl-default-directory)))))
15070 (t (message "")))))
15071
15072 (defun vhdl-speedbar-line-text ()
15073 "Calls `speedbar-line-text' and removes text properties."
15074 (let ((string (speedbar-line-text)))
15075 (set-text-properties 0 (length string) nil string)
15076 string))
15077
15078 (defun vhdl-speedbar-higher-text ()
15079 "Get speedbar-line-text of higher level."
15080 (let (depth string)
15081 (save-excursion
15082 (beginning-of-line)
15083 (looking-at "^\\([0-9]+\\):")
15084 (setq depth (string-to-number (match-string 1)))
15085 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15086 (setq string (match-string 1))
15087 (set-text-properties 0 (length string) nil string)
15088 string))))
15089
15090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15091 ;; Help functions
15092
15093 (defun vhdl-speedbar-line-key (&optional indent)
15094 "Get currently displayed directory of project name."
15095 (if vhdl-speedbar-show-projects
15096 (vhdl-speedbar-line-project)
15097 (abbreviate-file-name
15098 (file-name-as-directory (speedbar-line-directory indent)))))
15099
15100 (defun vhdl-speedbar-line-project (&optional indent)
15101 "Get currently displayed project name."
15102 (and vhdl-speedbar-show-projects
15103 (save-excursion
15104 (end-of-line)
15105 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15106 (match-string-no-properties 1))))
15107
15108 (defun vhdl-add-modified-file ()
15109 "Add file to `vhdl-modified-file-list'."
15110 (when vhdl-file-alist
15111 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15112 nil)
15113
15114 (defun vhdl-resolve-paths (path-list)
15115 "Resolve path wildcards in PATH-LIST."
15116 (let (path-list-1 path-list-2 path-beg path-end dir)
15117 ;; eliminate non-existent directories
15118 (while path-list
15119 (setq dir (car path-list))
15120 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15121 (if (file-directory-p (match-string 2 dir))
15122 (setq path-list-1 (cons dir path-list-1))
15123 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15124 (setq path-list (cdr path-list)))
15125 ;; resolve path wildcards
15126 (while path-list-1
15127 (setq dir (car path-list-1))
15128 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15129 (progn
15130 (setq path-beg (match-string 1 dir)
15131 path-end (match-string 5 dir))
15132 (setq path-list-1
15133 (append
15134 (mapcar
15135 (function
15136 (lambda (var) (concat path-beg var path-end)))
15137 (let ((all-list (vhdl-directory-files
15138 (match-string 2 dir) t
15139 (concat "\\<" (wildcard-to-regexp
15140 (match-string 4 dir)))))
15141 dir-list)
15142 (while all-list
15143 (when (file-directory-p (car all-list))
15144 (setq dir-list (cons (car all-list) dir-list)))
15145 (setq all-list (cdr all-list)))
15146 dir-list))
15147 (cdr path-list-1))))
15148 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15149 (when (file-directory-p (match-string 2 dir))
15150 (setq path-list-2 (cons dir path-list-2)))
15151 (setq path-list-1 (cdr path-list-1))))
15152 (nreverse path-list-2)))
15153
15154 (defun vhdl-speedbar-goto-this-unit (directory unit)
15155 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15156 (let ((dest (point)))
15157 (if (and (if vhdl-speedbar-show-projects
15158 (progn (goto-char (point-min)) t)
15159 (speedbar-goto-this-file directory))
15160 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15161 (progn (speedbar-position-cursor-on-line)
15162 t)
15163 (goto-char dest)
15164 nil)))
15165
15166 (defun vhdl-speedbar-find-file (text token indent)
15167 "When user clicks on TEXT, load file with name and position in TOKEN.
15168 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15169 is already shown in a buffer."
15170 (if (not (car token))
15171 (error "ERROR: File cannot be found")
15172 (let ((buffer (get-file-buffer (car token))))
15173 (speedbar-find-file-in-frame (car token))
15174 (when (or vhdl-speedbar-jump-to-unit buffer)
15175 (goto-line (cdr token))
15176 (recenter))
15177 (vhdl-speedbar-update-current-unit t t)
15178 (speedbar-set-timer speedbar-update-speed)
15179 (speedbar-maybee-jump-to-attached-frame))))
15180
15181 (defun vhdl-speedbar-port-copy ()
15182 "Copy the port of the entity/component or subprogram under the cursor."
15183 (interactive)
15184 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15185 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15186 (error "ERROR: No entity/component or subprogram under cursor")
15187 (beginning-of-line)
15188 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15189 (condition-case info
15190 (let ((token (get-text-property
15191 (match-beginning 3) 'speedbar-token)))
15192 (vhdl-visit-file (car token) t
15193 (progn (goto-line (cdr token))
15194 (end-of-line)
15195 (if is-entity
15196 (vhdl-port-copy)
15197 (vhdl-subprog-copy)))))
15198 (error (error "ERROR: %s not scanned successfully\n (%s)"
15199 (if is-entity "Port" "Interface") (cadr info))))
15200 (error "ERROR: No entity/component or subprogram on current line")))))
15201
15202 (defun vhdl-speedbar-place-component ()
15203 "Place the entity/component under the cursor as component."
15204 (interactive)
15205 (if (not (vhdl-speedbar-check-unit 'entity))
15206 (error "ERROR: No entity/component under cursor")
15207 (vhdl-speedbar-port-copy)
15208 (if (fboundp 'speedbar-select-attached-frame)
15209 (speedbar-select-attached-frame)
15210 (select-frame speedbar-attached-frame))
15211 (vhdl-compose-place-component)
15212 (select-frame speedbar-frame)))
15213
15214 (defun vhdl-speedbar-configuration ()
15215 "Generate configuration for the architecture under the cursor."
15216 (interactive)
15217 (if (not (vhdl-speedbar-check-unit 'architecture))
15218 (error "ERROR: No architecture under cursor")
15219 (let ((arch-name (vhdl-speedbar-line-text))
15220 (ent-name (vhdl-speedbar-higher-text)))
15221 (if (fboundp 'speedbar-select-attached-frame)
15222 (speedbar-select-attached-frame)
15223 (select-frame speedbar-attached-frame))
15224 (vhdl-compose-configuration ent-name arch-name))))
15225
15226 (defun vhdl-speedbar-select-mra ()
15227 "Select the architecture under the cursor as MRA."
15228 (interactive)
15229 (if (not (vhdl-speedbar-check-unit 'architecture))
15230 (error "ERROR: No architecture under cursor")
15231 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15232 (ent-key (downcase (vhdl-speedbar-higher-text)))
15233 (ent-alist (aget vhdl-entity-alist
15234 (or (vhdl-project-p) default-directory) t))
15235 (ent-entry (aget ent-alist ent-key t)))
15236 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15237 (speedbar-refresh))))
15238
15239 (defun vhdl-speedbar-make-design ()
15240 "Make (compile) design unit or directory/project under the cursor."
15241 (interactive)
15242 (if (not (save-excursion (beginning-of-line)
15243 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15244 (error "ERROR: No primary design unit or directory/project under cursor")
15245 (let ((is-unit (match-string 2))
15246 (unit-name (vhdl-speedbar-line-text))
15247 (vhdl-project (vhdl-speedbar-line-project))
15248 (directory (file-name-as-directory
15249 (or (speedbar-line-file) (speedbar-line-directory)))))
15250 (if (fboundp 'speedbar-select-attached-frame)
15251 (speedbar-select-attached-frame)
15252 (select-frame speedbar-attached-frame))
15253 (let ((default-directory directory))
15254 (vhdl-make (and is-unit unit-name))))))
15255
15256 (defun vhdl-speedbar-generate-makefile ()
15257 "Generate Makefile for directory/project under the cursor."
15258 (interactive)
15259 (let ((vhdl-project (vhdl-speedbar-line-project))
15260 (default-directory (file-name-as-directory
15261 (or (speedbar-line-file) (speedbar-line-directory)))))
15262 (vhdl-generate-makefile)))
15263
15264 (defun vhdl-speedbar-check-unit (design-unit)
15265 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15266 expansion function)."
15267 (save-excursion
15268 (speedbar-position-cursor-on-line)
15269 (cond ((eq design-unit 'entity)
15270 (memq (get-text-property (match-end 0) 'face)
15271 '(vhdl-speedbar-entity-face
15272 vhdl-speedbar-entity-selected-face)))
15273 ((eq design-unit 'architecture)
15274 (memq (get-text-property (match-end 0) 'face)
15275 '(vhdl-speedbar-architecture-face
15276 vhdl-speedbar-architecture-selected-face)))
15277 ((eq design-unit 'subprogram)
15278 (eq (get-text-property (match-end 0) 'face)
15279 'vhdl-speedbar-subprogram-face))
15280 (t nil))))
15281
15282 (defun vhdl-speedbar-set-depth (depth)
15283 "Set hierarchy display depth to DEPTH and refresh speedbar."
15284 (setq vhdl-speedbar-hierarchy-depth depth)
15285 (speedbar-refresh))
15286
15287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15288 ;; Fontification
15289
15290 (defface vhdl-speedbar-entity-face
15291 '((((class color) (background light)) (:foreground "ForestGreen"))
15292 (((class color) (background dark)) (:foreground "PaleGreen")))
15293 "Face used for displaying entity names."
15294 :group 'speedbar-faces)
15295
15296 (defface vhdl-speedbar-architecture-face
15297 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15298 (((class color) (background light)) (:foreground "Blue"))
15299
15300 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15301 "Face used for displaying architecture names."
15302 :group 'speedbar-faces)
15303
15304 (defface vhdl-speedbar-configuration-face
15305 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15306 (((class color) (background dark)) (:foreground "Salmon")))
15307 "Face used for displaying configuration names."
15308 :group 'speedbar-faces)
15309
15310 (defface vhdl-speedbar-package-face
15311 '((((class color) (background light)) (:foreground "Grey50"))
15312 (((class color) (background dark)) (:foreground "Grey80")))
15313 "Face used for displaying package names."
15314 :group 'speedbar-faces)
15315
15316 (defface vhdl-speedbar-library-face
15317 '((((class color) (background light)) (:foreground "Purple"))
15318 (((class color) (background dark)) (:foreground "Orchid1")))
15319 "Face used for displaying library names."
15320 :group 'speedbar-faces)
15321
15322 (defface vhdl-speedbar-instantiation-face
15323 '((((class color) (background light)) (:foreground "Brown"))
15324 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15325 (((class color) (background dark)) (:foreground "Yellow")))
15326 "Face used for displaying instantiation names."
15327 :group 'speedbar-faces)
15328
15329 (defface vhdl-speedbar-subprogram-face
15330 '((((class color) (background light)) (:foreground "Orchid4"))
15331 (((class color) (background dark)) (:foreground "BurlyWood2")))
15332 "Face used for displaying subprogram names."
15333 :group 'speedbar-faces)
15334
15335 (defface vhdl-speedbar-entity-selected-face
15336 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15337 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15338 "Face used for displaying entity names."
15339 :group 'speedbar-faces)
15340
15341 (defface vhdl-speedbar-architecture-selected-face
15342 '((((min-colors 88) (class color) (background light)) (:foreground
15343 "Blue1" :underline t))
15344 (((class color) (background light)) (:foreground "Blue" :underline t))
15345 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15346 "Face used for displaying architecture names."
15347 :group 'speedbar-faces)
15348
15349 (defface vhdl-speedbar-configuration-selected-face
15350 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15351 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15352 "Face used for displaying configuration names."
15353 :group 'speedbar-faces)
15354
15355 (defface vhdl-speedbar-package-selected-face
15356 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15357 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15358 "Face used for displaying package names."
15359 :group 'speedbar-faces)
15360
15361 (defface vhdl-speedbar-instantiation-selected-face
15362 '((((class color) (background light)) (:foreground "Brown" :underline t))
15363 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15364 "Face used for displaying instantiation names."
15365 :group 'speedbar-faces)
15366
15367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15368 ;; Initialization
15369
15370 ;; add speedbar
15371 (when (fboundp 'speedbar)
15372 (condition-case ()
15373 (when (and vhdl-speedbar-auto-open
15374 (not (and (boundp 'speedbar-frame)
15375 (frame-live-p speedbar-frame))))
15376 (speedbar-frame-mode 1)
15377 (if (fboundp 'speedbar-select-attached-frame)
15378 (speedbar-select-attached-frame)
15379 (select-frame speedbar-attached-frame)))
15380 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15381
15382 ;; initialize speedbar
15383 (if (not (boundp 'speedbar-frame))
15384 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15385 (vhdl-speedbar-initialize)
15386 (when speedbar-frame (vhdl-speedbar-refresh)))
15387
15388
15389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15390 ;;; Structural composition
15391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15392
15393 (defun vhdl-get-components-package-name ()
15394 "Return the name of the components package."
15395 (let ((project (vhdl-project-p)))
15396 (if project
15397 (vhdl-replace-string (car vhdl-components-package-name)
15398 (subst-char-in-string ? ?_ project))
15399 (cdr vhdl-components-package-name))))
15400
15401 (defun vhdl-compose-new-component ()
15402 "Create entity and architecture for new component."
15403 (interactive)
15404 (let* ((case-fold-search t)
15405 (ent-name (read-from-minibuffer "entity name: "
15406 nil vhdl-minibuffer-local-map))
15407 (arch-name
15408 (if (equal (cdr vhdl-compose-architecture-name) "")
15409 (read-from-minibuffer "architecture name: "
15410 nil vhdl-minibuffer-local-map)
15411 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15412 ent-file-name arch-file-name ent-buffer arch-buffer project)
15413 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15414 ;; open entity file
15415 (unless (eq vhdl-compose-create-files 'none)
15416 (setq ent-file-name
15417 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15418 "." (file-name-extension (buffer-file-name))))
15419 (when (and (file-exists-p ent-file-name)
15420 (not (y-or-n-p (concat "File \"" ent-file-name
15421 "\" exists; overwrite? "))))
15422 (error "ERROR: Creating component...aborted"))
15423 (find-file ent-file-name)
15424 (erase-buffer)
15425 (set-buffer-modified-p nil))
15426 ;; insert header
15427 (if vhdl-compose-include-header
15428 (progn (vhdl-template-header)
15429 (goto-char (point-max)))
15430 (vhdl-comment-display-line) (insert "\n\n"))
15431 ;; insert library clause
15432 (vhdl-template-package-std-logic-1164)
15433 (when vhdl-use-components-package
15434 (insert "\n")
15435 (vhdl-template-standard-package (vhdl-work-library)
15436 (vhdl-get-components-package-name)))
15437 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15438 ;; insert entity declaration
15439 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15440 (vhdl-insert-keyword " IS\n")
15441 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15442 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15443 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15444 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15445 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15446 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15447 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15448 (vhdl-insert-keyword "END ")
15449 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15450 (insert ent-name ";\n\n")
15451 (vhdl-comment-display-line) (insert "\n")
15452 ;; open architecture file
15453 (if (not (eq vhdl-compose-create-files 'separate))
15454 (insert "\n")
15455 (setq ent-buffer (current-buffer))
15456 (setq arch-file-name
15457 (concat (vhdl-replace-string vhdl-architecture-file-name
15458 (concat ent-name " " arch-name) t)
15459 "." (file-name-extension (buffer-file-name))))
15460 (when (and (file-exists-p arch-file-name)
15461 (not (y-or-n-p (concat "File \"" arch-file-name
15462 "\" exists; overwrite? "))))
15463 (error "ERROR: Creating component...aborted"))
15464 (find-file arch-file-name)
15465 (erase-buffer)
15466 (set-buffer-modified-p nil)
15467 ;; insert header
15468 (if vhdl-compose-include-header
15469 (progn (vhdl-template-header)
15470 (goto-char (point-max)))
15471 (vhdl-comment-display-line) (insert "\n\n")))
15472 ;; insert architecture body
15473 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15474 (vhdl-insert-keyword " OF ") (insert ent-name)
15475 (vhdl-insert-keyword " IS\n\n")
15476 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15477 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15478 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15479 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15480 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15481 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15482 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15483 (vhdl-insert-keyword "BEGIN")
15484 (when vhdl-self-insert-comments
15485 (insert " -- ")
15486 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15487 (insert arch-name))
15488 (insert "\n\n")
15489 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15490 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15491 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15492 (vhdl-insert-keyword "END ")
15493 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15494 (insert arch-name ";\n\n")
15495 ;; insert footer and save
15496 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15497 (vhdl-template-footer)
15498 (vhdl-comment-display-line) (insert "\n"))
15499 (goto-char (point-min))
15500 (setq arch-buffer (current-buffer))
15501 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15502 (set-buffer arch-buffer) (save-buffer)
15503 (message "%s"
15504 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15505 (and ent-file-name
15506 (format "\n File created: \"%s\"" ent-file-name))
15507 (and arch-file-name
15508 (format "\n File created: \"%s\"" arch-file-name))))))
15509
15510 (defun vhdl-compose-place-component ()
15511 "Place new component by pasting current port as component declaration and
15512 component instantiation."
15513 (interactive)
15514 (if (not vhdl-port-list)
15515 (error "ERROR: No port has been read")
15516 (save-excursion
15517 (vhdl-prepare-search-2
15518 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15519 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15520 (error "ERROR: No architecture found"))
15521 (let* ((ent-name (match-string 1))
15522 (ent-file-name
15523 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15524 "." (file-name-extension (buffer-file-name))))
15525 (orig-buffer (current-buffer)))
15526 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15527 ;; place component declaration
15528 (unless (or vhdl-use-components-package
15529 (vhdl-use-direct-instantiation)
15530 (save-excursion
15531 (re-search-forward
15532 (concat "^\\s-*component\\s-+"
15533 (car vhdl-port-list) "\\>") nil t)))
15534 (re-search-forward "^begin\\>" nil)
15535 (beginning-of-line)
15536 (skip-chars-backward " \t\n")
15537 (insert "\n\n") (indent-to vhdl-basic-offset)
15538 (vhdl-port-paste-component t))
15539 ;; place component instantiation
15540 (re-search-forward "^end\\>" nil)
15541 (beginning-of-line)
15542 (skip-chars-backward " \t\n")
15543 (insert "\n\n") (indent-to vhdl-basic-offset)
15544 (vhdl-port-paste-instance nil t t)
15545 ;; place use clause for used packages
15546 (when (nth 3 vhdl-port-list)
15547 ;; open entity file
15548 (when (file-exists-p ent-file-name)
15549 (find-file ent-file-name))
15550 (goto-char (point-min))
15551 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15552 (error "ERROR: Entity not found: \"%s\"" ent-name))
15553 (goto-char (match-beginning 0))
15554 (if (and (save-excursion
15555 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15556 (match-string 1))
15557 (progn (goto-char (match-end 0))
15558 (beginning-of-line 2))
15559 (insert "\n")
15560 (backward-char))
15561 (vhdl-port-paste-context-clause)
15562 (switch-to-buffer orig-buffer))
15563 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15564
15565 (defun vhdl-compose-wire-components ()
15566 "Connect components."
15567 (interactive)
15568 (save-excursion
15569 (vhdl-prepare-search-2
15570 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15571 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15572 (error "ERROR: No architecture found"))
15573 (let* ((ent-name (match-string 1))
15574 (ent-file-name
15575 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15576 "." (file-name-extension (buffer-file-name))))
15577 (arch-decl-pos (point-marker))
15578 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15579 (arch-end-pos (re-search-forward "^end\\>" nil))
15580 (pack-name (vhdl-get-components-package-name))
15581 (pack-file-name
15582 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15583 "." (file-name-extension (buffer-file-name))))
15584 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15585 port-alist generic-alist inst-alist
15586 signal-name signal-entry signal-alist local-list written-list
15587 single-in-list multi-in-list single-out-list multi-out-list
15588 constant-name constant-entry constant-alist single-list multi-list
15589 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15590 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15591 signal-beg-pos signal-pos
15592 constant-temp-pos port-temp-pos signal-temp-pos)
15593 (message "Wiring components...")
15594 ;; process all instances
15595 (goto-char arch-stat-pos)
15596 (while (re-search-forward
15597 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15598 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15599 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15600 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15601 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15602 (setq inst-name (match-string-no-properties 1)
15603 comp-name (match-string-no-properties 4)
15604 comp-ent-name (match-string-no-properties 12)
15605 has-generic (or (match-string 7) (match-string 17)))
15606 ;; get port ...
15607 (if comp-name
15608 ;; ... from component declaration
15609 (vhdl-visit-file
15610 (when vhdl-use-components-package pack-file-name) t
15611 (save-excursion
15612 (goto-char (point-min))
15613 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15614 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15615 (vhdl-port-copy)))
15616 ;; ... from entity declaration (direct instantiation)
15617 (setq comp-ent-file-name
15618 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15619 "." (file-name-extension (buffer-file-name))))
15620 (vhdl-visit-file
15621 comp-ent-file-name t
15622 (save-excursion
15623 (goto-char (point-min))
15624 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15625 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15626 (vhdl-port-copy))))
15627 (vhdl-port-flatten t)
15628 (setq generic-alist (nth 1 vhdl-port-list)
15629 port-alist (nth 2 vhdl-port-list)
15630 vhdl-port-list nil)
15631 (setq constant-alist nil
15632 signal-alist nil)
15633 (when has-generic
15634 ;; process all constants in generic map
15635 (vhdl-forward-syntactic-ws)
15636 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15637 (setq constant-name (match-string-no-properties 3))
15638 (setq constant-entry
15639 (cons constant-name
15640 (if (match-string 1)
15641 (or (aget generic-alist (match-string 2) t)
15642 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15643 (cdar generic-alist))))
15644 (setq constant-alist (cons constant-entry constant-alist))
15645 (setq constant-name (downcase constant-name))
15646 (if (or (member constant-name single-list)
15647 (member constant-name multi-list))
15648 (progn (setq single-list (delete constant-name single-list))
15649 (add-to-list 'multi-list constant-name))
15650 (add-to-list 'single-list constant-name))
15651 (unless (match-string 1)
15652 (setq generic-alist (cdr generic-alist)))
15653 (vhdl-forward-syntactic-ws))
15654 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15655 ;; process all signals in port map
15656 (vhdl-forward-syntactic-ws)
15657 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15658 (setq signal-name (match-string-no-properties 3))
15659 (setq signal-entry (cons signal-name
15660 (if (match-string 1)
15661 (or (aget port-alist (match-string 2) t)
15662 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15663 (cdar port-alist))))
15664 (setq signal-alist (cons signal-entry signal-alist))
15665 (setq signal-name (downcase signal-name))
15666 (if (equal (upcase (nth 2 signal-entry)) "IN")
15667 ;; input signal
15668 (cond
15669 ((member signal-name local-list)
15670 nil)
15671 ((or (member signal-name single-out-list)
15672 (member signal-name multi-out-list))
15673 (setq single-out-list (delete signal-name single-out-list))
15674 (setq multi-out-list (delete signal-name multi-out-list))
15675 (add-to-list 'local-list signal-name))
15676 ((member signal-name single-in-list)
15677 (setq single-in-list (delete signal-name single-in-list))
15678 (add-to-list 'multi-in-list signal-name))
15679 ((not (member signal-name multi-in-list))
15680 (add-to-list 'single-in-list signal-name)))
15681 ;; output signal
15682 (cond
15683 ((member signal-name local-list)
15684 nil)
15685 ((or (member signal-name single-in-list)
15686 (member signal-name multi-in-list))
15687 (setq single-in-list (delete signal-name single-in-list))
15688 (setq multi-in-list (delete signal-name multi-in-list))
15689 (add-to-list 'local-list signal-name))
15690 ((member signal-name single-out-list)
15691 (setq single-out-list (delete signal-name single-out-list))
15692 (add-to-list 'multi-out-list signal-name))
15693 ((not (member signal-name multi-out-list))
15694 (add-to-list 'single-out-list signal-name))))
15695 (unless (match-string 1)
15696 (setq port-alist (cdr port-alist)))
15697 (vhdl-forward-syntactic-ws))
15698 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15699 (nreverse signal-alist)) inst-alist)))
15700 ;; prepare signal insertion
15701 (vhdl-goto-marker arch-decl-pos)
15702 (forward-line 1)
15703 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15704 (setq signal-pos (point-marker))
15705 (while (progn (vhdl-forward-syntactic-ws)
15706 (looking-at "signal\\>"))
15707 (beginning-of-line 2)
15708 (delete-region signal-pos (point)))
15709 (setq signal-beg-pos signal-pos)
15710 ;; open entity file
15711 (when (file-exists-p ent-file-name)
15712 (find-file ent-file-name))
15713 (goto-char (point-min))
15714 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15715 (error "ERROR: Entity not found: \"%s\"" ent-name))
15716 ;; prepare generic clause insertion
15717 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15718 (match-string 1))
15719 (goto-char (match-beginning 0))
15720 (indent-to vhdl-basic-offset)
15721 (insert "generic ();\n\n")
15722 (backward-char 4))
15723 (backward-char)
15724 (setq generic-pos (point-marker))
15725 (forward-sexp) (end-of-line)
15726 (delete-region generic-pos (point)) (delete-char 1)
15727 (insert "(\n")
15728 (when multi-list
15729 (insert "\n")
15730 (indent-to (* 2 vhdl-basic-offset))
15731 (insert "-- global generics\n"))
15732 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15733 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15734 ;; prepare port clause insertion
15735 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15736 (match-string 1))
15737 (goto-char (match-beginning 0))
15738 (indent-to vhdl-basic-offset)
15739 (insert "port ();\n\n")
15740 (backward-char 4))
15741 (backward-char)
15742 (setq port-in-pos (point-marker))
15743 (forward-sexp) (end-of-line)
15744 (delete-region port-in-pos (point)) (delete-char 1)
15745 (insert "(\n")
15746 (when (or multi-in-list multi-out-list)
15747 (insert "\n")
15748 (indent-to (* 2 vhdl-basic-offset))
15749 (insert "-- global ports\n"))
15750 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15751 port-out-pos (point-marker) port-inst-pos (point-marker)
15752 port-end-pos (point-marker))
15753 ;; insert generics, ports and signals
15754 (setq inst-alist (nreverse inst-alist))
15755 (while inst-alist
15756 (setq inst-name (nth 0 (car inst-alist))
15757 constant-alist (nth 1 (car inst-alist))
15758 signal-alist (nth 2 (car inst-alist))
15759 constant-temp-pos generic-inst-pos
15760 port-temp-pos port-inst-pos
15761 signal-temp-pos signal-pos)
15762 ;; generics
15763 (while constant-alist
15764 (setq constant-name (downcase (caar constant-alist))
15765 constant-entry (car constant-alist))
15766 (cond ((member constant-name written-list)
15767 nil)
15768 ((member constant-name multi-list)
15769 (vhdl-goto-marker generic-pos)
15770 (setq generic-end-pos
15771 (vhdl-max-marker
15772 generic-end-pos
15773 (vhdl-compose-insert-generic constant-entry)))
15774 (setq generic-pos (point-marker))
15775 (add-to-list 'written-list constant-name))
15776 (t
15777 (vhdl-goto-marker
15778 (vhdl-max-marker generic-inst-pos generic-pos))
15779 (setq generic-end-pos
15780 (vhdl-compose-insert-generic constant-entry))
15781 (setq generic-inst-pos (point-marker))
15782 (add-to-list 'written-list constant-name)))
15783 (setq constant-alist (cdr constant-alist)))
15784 (when (/= constant-temp-pos generic-inst-pos)
15785 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15786 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15787 (insert "-- generics for \"" inst-name "\"\n")
15788 (vhdl-goto-marker generic-inst-pos))
15789 ;; ports and signals
15790 (while signal-alist
15791 (setq signal-name (downcase (caar signal-alist))
15792 signal-entry (car signal-alist))
15793 (cond ((member signal-name written-list)
15794 nil)
15795 ((member signal-name multi-in-list)
15796 (vhdl-goto-marker port-in-pos)
15797 (setq port-end-pos
15798 (vhdl-max-marker
15799 port-end-pos (vhdl-compose-insert-port signal-entry)))
15800 (setq port-in-pos (point-marker))
15801 (add-to-list 'written-list signal-name))
15802 ((member signal-name multi-out-list)
15803 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15804 (setq port-end-pos
15805 (vhdl-max-marker
15806 port-end-pos (vhdl-compose-insert-port signal-entry)))
15807 (setq port-out-pos (point-marker))
15808 (add-to-list 'written-list signal-name))
15809 ((or (member signal-name single-in-list)
15810 (member signal-name single-out-list))
15811 (vhdl-goto-marker
15812 (vhdl-max-marker
15813 port-inst-pos
15814 (vhdl-max-marker port-out-pos port-in-pos)))
15815 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15816 (setq port-inst-pos (point-marker))
15817 (add-to-list 'written-list signal-name))
15818 ((equal (upcase (nth 2 signal-entry)) "OUT")
15819 (vhdl-goto-marker signal-pos)
15820 (vhdl-compose-insert-signal signal-entry)
15821 (setq signal-pos (point-marker))
15822 (add-to-list 'written-list signal-name)))
15823 (setq signal-alist (cdr signal-alist)))
15824 (when (/= port-temp-pos port-inst-pos)
15825 (vhdl-goto-marker
15826 (vhdl-max-marker port-temp-pos
15827 (vhdl-max-marker port-in-pos port-out-pos)))
15828 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15829 (insert "-- ports to \"" inst-name "\"\n")
15830 (vhdl-goto-marker port-inst-pos))
15831 (when (/= signal-temp-pos signal-pos)
15832 (vhdl-goto-marker signal-temp-pos)
15833 (insert "\n") (indent-to vhdl-basic-offset)
15834 (insert "-- outputs of \"" inst-name "\"\n")
15835 (vhdl-goto-marker signal-pos))
15836 (setq inst-alist (cdr inst-alist)))
15837 ;; finalize generic/port clause
15838 (vhdl-goto-marker generic-end-pos) (backward-char)
15839 (when (= generic-beg-pos generic-end-pos)
15840 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15841 (insert ";") (backward-char))
15842 (insert ")")
15843 (vhdl-goto-marker port-end-pos) (backward-char)
15844 (when (= port-beg-pos port-end-pos)
15845 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15846 (insert ";") (backward-char))
15847 (insert ")")
15848 ;; align everything
15849 (when vhdl-auto-align
15850 (vhdl-goto-marker generic-beg-pos)
15851 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15852 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15853 (vhdl-goto-marker signal-beg-pos)
15854 (vhdl-align-region-groups signal-beg-pos signal-pos))
15855 (switch-to-buffer (marker-buffer signal-beg-pos))
15856 (message "Wiring components...done")))))
15857
15858 (defun vhdl-compose-insert-generic (entry)
15859 "Insert ENTRY as generic declaration."
15860 (let (pos)
15861 (indent-to (* 2 vhdl-basic-offset))
15862 (insert (nth 0 entry) " : " (nth 1 entry))
15863 (when (nth 2 entry)
15864 (insert " := " (nth 2 entry)))
15865 (insert ";")
15866 (setq pos (point-marker))
15867 (when (and vhdl-include-port-comments (nth 3 entry))
15868 (vhdl-comment-insert-inline (nth 3 entry) t))
15869 (insert "\n")
15870 pos))
15871
15872 (defun vhdl-compose-insert-port (entry)
15873 "Insert ENTRY as port declaration."
15874 (let (pos)
15875 (indent-to (* 2 vhdl-basic-offset))
15876 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15877 (setq pos (point-marker))
15878 (when (and vhdl-include-port-comments (nth 4 entry))
15879 (vhdl-comment-insert-inline (nth 4 entry) t))
15880 (insert "\n")
15881 pos))
15882
15883 (defun vhdl-compose-insert-signal (entry)
15884 "Insert ENTRY as signal declaration."
15885 (indent-to vhdl-basic-offset)
15886 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15887 (when (and vhdl-include-port-comments (nth 4 entry))
15888 (vhdl-comment-insert-inline (nth 4 entry) t))
15889 (insert "\n"))
15890
15891 (defun vhdl-compose-components-package ()
15892 "Generate a package containing component declarations for all entities in the
15893 current project/directory."
15894 (interactive)
15895 (vhdl-require-hierarchy-info)
15896 (let* ((project (vhdl-project-p))
15897 (pack-name (vhdl-get-components-package-name))
15898 (pack-file-name
15899 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15900 "." (file-name-extension (buffer-file-name))))
15901 (ent-alist (aget vhdl-entity-alist
15902 (or project default-directory) t))
15903 (lazy-lock-minimum-size 0)
15904 clause-pos component-pos)
15905 (message "Generating components package \"%s\"..." pack-name)
15906 ;; open package file
15907 (when (and (file-exists-p pack-file-name)
15908 (not (y-or-n-p (concat "File \"" pack-file-name
15909 "\" exists; overwrite? "))))
15910 (error "ERROR: Generating components package...aborted"))
15911 (find-file pack-file-name)
15912 (erase-buffer)
15913 ;; insert header
15914 (if vhdl-compose-include-header
15915 (progn (vhdl-template-header
15916 (concat "Components package (generated by Emacs VHDL Mode "
15917 vhdl-version ")"))
15918 (goto-char (point-max)))
15919 (vhdl-comment-display-line) (insert "\n\n"))
15920 ;; insert std_logic_1164 package
15921 (vhdl-template-package-std-logic-1164)
15922 (insert "\n") (setq clause-pos (point-marker))
15923 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15924 ;; insert package declaration
15925 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15926 (vhdl-insert-keyword " IS\n\n")
15927 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15928 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15929 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15930 (indent-to vhdl-basic-offset)
15931 (setq component-pos (point-marker))
15932 (insert "\n\n") (vhdl-insert-keyword "END ")
15933 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15934 (insert pack-name ";\n\n")
15935 ;; insert footer
15936 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15937 (vhdl-template-footer)
15938 (vhdl-comment-display-line) (insert "\n"))
15939 ;; insert component declarations
15940 (while ent-alist
15941 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15942 (progn (goto-line (nth 3 (car ent-alist)))
15943 (end-of-line)
15944 (vhdl-port-copy)))
15945 (goto-char component-pos)
15946 (vhdl-port-paste-component t)
15947 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15948 (setq component-pos (point-marker))
15949 (goto-char clause-pos)
15950 (vhdl-port-paste-context-clause pack-name)
15951 (setq clause-pos (point-marker))
15952 (setq ent-alist (cdr ent-alist)))
15953 (goto-char (point-min))
15954 (save-buffer)
15955 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15956 pack-name pack-file-name)))
15957
15958 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15959 &optional insert-conf)
15960 "Generate block configuration for architecture."
15961 (let ((margin (current-indentation))
15962 (beg (save-excursion (beginning-of-line) (point)))
15963 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15964 ;; insert block configuration (for architecture)
15965 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15966 (setq margin (+ margin vhdl-basic-offset))
15967 ;; process all instances
15968 (while inst-alist
15969 (setq inst-entry (car inst-alist))
15970 ;; is component?
15971 (when (nth 4 inst-entry)
15972 (setq insert-conf t)
15973 (setq inst-path (nth 9 inst-entry))
15974 ;; skip common path with previous instance
15975 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15976 (setq inst-path (cdr inst-path)
15977 inst-prev-path (cdr inst-prev-path)))
15978 ;; insert block configuration end (for previous block/generate)
15979 (while inst-prev-path
15980 (setq margin (- margin vhdl-basic-offset))
15981 (indent-to margin)
15982 (vhdl-insert-keyword "END FOR;\n")
15983 (setq inst-prev-path (cdr inst-prev-path)))
15984 ;; insert block configuration beginning (for current block/generate)
15985 (indent-to margin)
15986 (while inst-path
15987 (setq margin (+ margin vhdl-basic-offset))
15988 (vhdl-insert-keyword "FOR ")
15989 (insert (car inst-path) "\n")
15990 (indent-to margin)
15991 (setq inst-path (cdr inst-path)))
15992 ;; insert component configuration beginning
15993 (vhdl-insert-keyword "FOR ")
15994 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15995 ;; find subconfiguration
15996 (setq conf-key (nth 7 inst-entry))
15997 (setq tmp-alist conf-alist)
15998 ;; use first configuration found for instance's entity
15999 (while (and tmp-alist (null conf-key))
16000 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16001 (setq conf-key (nth 0 (car tmp-alist))))
16002 (setq tmp-alist (cdr tmp-alist)))
16003 (setq conf-entry (aget conf-alist conf-key t))
16004 ;; insert binding indication ...
16005 ;; ... with subconfiguration (if exists)
16006 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16007 (progn
16008 (indent-to (+ margin vhdl-basic-offset))
16009 (vhdl-insert-keyword "USE CONFIGURATION ")
16010 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16011 (insert ";\n"))
16012 ;; ... with entity (if exists)
16013 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16014 (when ent-entry
16015 (indent-to (+ margin vhdl-basic-offset))
16016 (vhdl-insert-keyword "USE ENTITY ")
16017 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16018 ;; insert architecture name (if architecture exists)
16019 (when (nth 3 ent-entry)
16020 (setq arch-name
16021 ;; choose architecture name a) from configuration,
16022 ;; b) from mra, or c) from first architecture
16023 (or (nth 0 (aget (nth 3 ent-entry)
16024 (or (nth 6 inst-entry)
16025 (nth 4 ent-entry)) t))
16026 (nth 1 (car (nth 3 ent-entry)))))
16027 (insert "(" arch-name ")"))
16028 (insert ";\n")
16029 ;; insert block configuration (for architecture of subcomponent)
16030 (when (and vhdl-compose-configuration-hierarchical
16031 (nth 3 ent-entry))
16032 (indent-to (+ margin vhdl-basic-offset))
16033 (vhdl-compose-configuration-architecture
16034 (nth 0 ent-entry) arch-name
16035 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16036 ;; insert component configuration end
16037 (indent-to margin)
16038 (vhdl-insert-keyword "END FOR;\n")
16039 (setq inst-prev-path (nth 9 inst-entry)))
16040 (setq inst-alist (cdr inst-alist)))
16041 ;; insert block configuration end (for block/generate)
16042 (while inst-prev-path
16043 (setq margin (- margin vhdl-basic-offset))
16044 (indent-to margin)
16045 (vhdl-insert-keyword "END FOR;\n")
16046 (setq inst-prev-path (cdr inst-prev-path)))
16047 (indent-to (- margin vhdl-basic-offset))
16048 ;; insert block configuration end or remove beginning (for architecture)
16049 (if insert-conf
16050 (vhdl-insert-keyword "END FOR;\n")
16051 (delete-region beg (point)))))
16052
16053 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16054 "Generate configuration declaration."
16055 (interactive)
16056 (vhdl-require-hierarchy-info)
16057 (let ((ent-alist (aget vhdl-entity-alist
16058 (or (vhdl-project-p) default-directory) t))
16059 (conf-alist (aget vhdl-config-alist
16060 (or (vhdl-project-p) default-directory) t))
16061 (from-speedbar ent-name)
16062 inst-alist conf-name conf-file-name pos)
16063 (vhdl-prepare-search-2
16064 ;; get entity and architecture name
16065 (unless ent-name
16066 (save-excursion
16067 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16068 (not (equal "END" (upcase (match-string 1))))
16069 (setq ent-name (match-string-no-properties 3))
16070 (setq arch-name (match-string-no-properties 2)))
16071 (error "ERROR: Not within an architecture"))))
16072 (setq conf-name (vhdl-replace-string
16073 vhdl-compose-configuration-name
16074 (concat ent-name " " arch-name)))
16075 (setq inst-alist
16076 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16077 (downcase arch-name) t))))
16078 (message "Generating configuration \"%s\"..." conf-name)
16079 (if vhdl-compose-configuration-create-file
16080 ;; open configuration file
16081 (progn
16082 (setq conf-file-name
16083 (concat (vhdl-replace-string vhdl-configuration-file-name
16084 conf-name t)
16085 "." (file-name-extension (buffer-file-name))))
16086 (when (and (file-exists-p conf-file-name)
16087 (not (y-or-n-p (concat "File \"" conf-file-name
16088 "\" exists; overwrite? "))))
16089 (error "ERROR: Creating configuration...aborted"))
16090 (find-file conf-file-name)
16091 (erase-buffer)
16092 (set-buffer-modified-p nil)
16093 ;; insert header
16094 (if vhdl-compose-include-header
16095 (progn (vhdl-template-header
16096 (concat "Configuration declaration for design \""
16097 ent-name "(" arch-name ")\""))
16098 (goto-char (point-max)))
16099 (vhdl-comment-display-line) (insert "\n\n")))
16100 ;; goto end of architecture
16101 (unless from-speedbar
16102 (re-search-forward "^end\\>" nil)
16103 (end-of-line) (insert "\n\n")
16104 (vhdl-comment-display-line) (insert "\n\n")))
16105 ;; insert library clause
16106 (setq pos (point))
16107 (vhdl-template-standard-package (vhdl-work-library) nil)
16108 (when (/= pos (point))
16109 (insert "\n\n"))
16110 ;; insert configuration
16111 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16112 (vhdl-insert-keyword " OF ") (insert ent-name)
16113 (vhdl-insert-keyword " IS\n")
16114 (indent-to vhdl-basic-offset)
16115 ;; insert block configuration (for architecture)
16116 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16117 (vhdl-insert-keyword "END ") (insert conf-name ";")
16118 (when conf-file-name
16119 ;; insert footer and save
16120 (insert "\n\n")
16121 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16122 (vhdl-template-footer)
16123 (vhdl-comment-display-line) (insert "\n"))
16124 (save-buffer))
16125 (message "%s"
16126 (concat (format "Generating configuration \"%s\"...done" conf-name)
16127 (and conf-file-name
16128 (format "\n File created: \"%s\"" conf-file-name))))))
16129
16130
16131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16132 ;;; Compilation / Makefile generation
16133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16134 ;; (using `compile.el')
16135
16136 (defun vhdl-makefile-name ()
16137 "Return the Makefile name of the current project or the current compiler if
16138 no project is defined."
16139 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16140 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16141 (vhdl-replace-string
16142 (cons "\\(.*\\)\n\\(.*\\)"
16143 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16144 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16145
16146 (defun vhdl-compile-directory ()
16147 "Return the directory where compilation/make should be run."
16148 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16149 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16150 (directory (vhdl-resolve-env-variable
16151 (if project
16152 (vhdl-replace-string
16153 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16154 (nth 6 compiler)))))
16155 (file-name-as-directory
16156 (if (file-name-absolute-p directory)
16157 directory
16158 (expand-file-name directory (vhdl-default-directory))))))
16159
16160 (defun vhdl-uniquify (in-list)
16161 "Remove duplicate elements from IN-LIST."
16162 (let (out-list)
16163 (while in-list
16164 (add-to-list 'out-list (car in-list))
16165 (setq in-list (cdr in-list)))
16166 out-list))
16167
16168 (defun vhdl-set-compiler (name)
16169 "Set current compiler to NAME."
16170 (interactive
16171 (list (let ((completion-ignore-case t))
16172 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16173 (if (assoc name vhdl-compiler-alist)
16174 (progn (setq vhdl-compiler name)
16175 (message "Current compiler: \"%s\"" vhdl-compiler))
16176 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16177
16178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16179 ;; Compilation
16180
16181 (defun vhdl-compile-init ()
16182 "Initialize for compilation."
16183 (when (or (null compilation-error-regexp-alist)
16184 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16185 compilation-error-regexp-alist)))
16186 ;; `compilation-error-regexp-alist'
16187 (let ((commands-alist vhdl-compiler-alist)
16188 regexp-alist sublist)
16189 (while commands-alist
16190 (setq sublist (nth 11 (car commands-alist)))
16191 (unless (or (equal "" (car sublist))
16192 (assoc (car sublist) regexp-alist))
16193 (setq regexp-alist (cons (list (nth 0 sublist)
16194 (if (= 0 (nth 1 sublist))
16195 (if (featurep 'xemacs) 9 nil)
16196 (nth 1 sublist))
16197 (nth 2 sublist) (nth 3 sublist))
16198 regexp-alist)))
16199 (setq commands-alist (cdr commands-alist)))
16200 (setq compilation-error-regexp-alist
16201 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16202 ;; `compilation-file-regexp-alist'
16203 (let ((commands-alist vhdl-compiler-alist)
16204 regexp-alist sublist)
16205 ;; matches vhdl-mode file name output
16206 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16207 (while commands-alist
16208 (setq sublist (nth 12 (car commands-alist)))
16209 (unless (or (equal "" (car sublist))
16210 (assoc (car sublist) regexp-alist))
16211 (setq regexp-alist (cons sublist regexp-alist)))
16212 (setq commands-alist (cdr commands-alist)))
16213 (setq compilation-file-regexp-alist
16214 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16215
16216 (defvar vhdl-compile-file-name nil
16217 "Name of file to be compiled.")
16218
16219 (defun vhdl-compile-print-file-name ()
16220 "Function called within `compile' to print out file name for compilers that
16221 do not print any file names."
16222 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16223
16224 (defun vhdl-get-compile-options (project compiler file-name
16225 &optional file-options-only)
16226 "Get compiler options. Returning nil means do not compile this file."
16227 (let* ((compiler-options (nth 1 compiler))
16228 (project-entry (aget (nth 4 project) vhdl-compiler))
16229 (project-options (nth 0 project-entry))
16230 (exception-list (and file-name (nth 2 project-entry)))
16231 (work-library (vhdl-work-library))
16232 (case-fold-search nil)
16233 file-options)
16234 (while (and exception-list
16235 (not (string-match (caar exception-list) file-name)))
16236 (setq exception-list (cdr exception-list)))
16237 (if (and exception-list (not (cdar exception-list)))
16238 nil
16239 (if (and file-options-only (not exception-list))
16240 'default
16241 (setq file-options (cdar exception-list))
16242 ;; insert library name in compiler-specific options
16243 (setq compiler-options
16244 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16245 work-library))
16246 ;; insert compiler-specific options in project-specific options
16247 (when project-options
16248 (setq project-options
16249 (vhdl-replace-string
16250 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16251 (concat work-library "\n" compiler-options))))
16252 ;; insert project-specific options in file-specific options
16253 (when file-options
16254 (setq file-options
16255 (vhdl-replace-string
16256 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16257 (concat work-library "\n" compiler-options "\n"
16258 project-options))))
16259 ;; return options
16260 (or file-options project-options compiler-options)))))
16261
16262 (defun vhdl-get-make-options (project compiler)
16263 "Get make options."
16264 (let* ((compiler-options (nth 3 compiler))
16265 (project-entry (aget (nth 4 project) vhdl-compiler))
16266 (project-options (nth 1 project-entry))
16267 (makefile-name (vhdl-makefile-name)))
16268 ;; insert Makefile name in compiler-specific options
16269 (setq compiler-options
16270 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16271 makefile-name))
16272 ;; insert compiler-specific options in project-specific options
16273 (when project-options
16274 (setq project-options
16275 (vhdl-replace-string
16276 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16277 (concat makefile-name "\n" compiler-options))))
16278 ;; return options
16279 (or project-options compiler-options)))
16280
16281 (defun vhdl-compile ()
16282 "Compile current buffer using the VHDL compiler specified in
16283 `vhdl-compiler'."
16284 (interactive)
16285 (vhdl-compile-init)
16286 (let* ((project (aget vhdl-project-alist vhdl-project))
16287 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16288 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16289 (command (nth 0 compiler))
16290 (file-name (buffer-file-name))
16291 (options (vhdl-get-compile-options project compiler file-name))
16292 (default-directory (vhdl-compile-directory))
16293 compilation-process-setup-function)
16294 (unless (file-directory-p default-directory)
16295 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16296 ;; put file name into quotes if it contains spaces
16297 (when (string-match " " file-name)
16298 (setq file-name (concat "\"" file-name "\"")))
16299 ;; print out file name if compiler does not
16300 (setq vhdl-compile-file-name (buffer-file-name))
16301 (when (and (= 0 (nth 1 (nth 10 compiler)))
16302 (= 0 (nth 1 (nth 11 compiler))))
16303 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16304 ;; run compilation
16305 (if options
16306 (when command
16307 (compile (concat command " " options " " file-name)))
16308 (vhdl-warning "Your project settings tell me not to compile this file"))))
16309
16310 (defvar vhdl-make-target "all"
16311 "Default target for `vhdl-make' command.")
16312
16313 (defun vhdl-make (&optional target)
16314 "Call make command for compilation of all updated source files (requires
16315 `Makefile'). Optional argument TARGET allows to compile the design
16316 specified by a target."
16317 (interactive)
16318 (setq vhdl-make-target
16319 (or target (read-from-minibuffer "Target: " vhdl-make-target
16320 vhdl-minibuffer-local-map)))
16321 (vhdl-compile-init)
16322 (let* ((project (aget vhdl-project-alist vhdl-project))
16323 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16324 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16325 (command (nth 2 compiler))
16326 (options (vhdl-get-make-options project compiler))
16327 (default-directory (vhdl-compile-directory)))
16328 (unless (file-directory-p default-directory)
16329 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16330 ;; run make
16331 (compile (concat (if (equal command "") "make" command)
16332 " " options " " vhdl-make-target))))
16333
16334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16335 ;; Makefile generation
16336
16337 (defun vhdl-generate-makefile ()
16338 "Generate `Makefile'."
16339 (interactive)
16340 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16341 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16342 (command (nth 4 compiler)))
16343 ;; generate makefile
16344 (if command
16345 (let ((default-directory (vhdl-compile-directory)))
16346 (compile (vhdl-replace-string
16347 (cons "\\(.*\\) \\(.*\\)" command)
16348 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16349 (vhdl-generate-makefile-1))))
16350
16351 (defun vhdl-get-packages (lib-alist work-library)
16352 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16353 (let (pack-list)
16354 (while lib-alist
16355 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16356 (setq pack-list (cons (cdar lib-alist) pack-list)))
16357 (setq lib-alist (cdr lib-alist)))
16358 pack-list))
16359
16360 (defun vhdl-generate-makefile-1 ()
16361 "Generate Makefile for current project or directory."
16362 ;; scan hierarchy if required
16363 (if (vhdl-project-p)
16364 (unless (or (assoc vhdl-project vhdl-file-alist)
16365 (vhdl-load-cache vhdl-project))
16366 (vhdl-scan-project-contents vhdl-project))
16367 (let ((directory (abbreviate-file-name default-directory)))
16368 (unless (or (assoc directory vhdl-file-alist)
16369 (vhdl-load-cache directory))
16370 (vhdl-scan-directory-contents directory))))
16371 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16372 (project (vhdl-project-p))
16373 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16374 (conf-alist (aget vhdl-config-alist (or project directory) t))
16375 (pack-alist (aget vhdl-package-alist (or project directory) t))
16376 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16377 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16378 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16379 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16380 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16381 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16382 (adjust-case (nth 5 regexp-list))
16383 (work-library (downcase (vhdl-work-library)))
16384 (compile-directory (expand-file-name (vhdl-compile-directory)
16385 default-directory))
16386 (makefile-name (vhdl-makefile-name))
16387 rule-alist arch-alist inst-alist
16388 target-list depend-list unit-list prim-list second-list subcomp-list
16389 lib-alist lib-body-alist pack-list all-pack-list
16390 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16391 conf-key conf-file-name pack-key pack-file-name
16392 ent-entry arch-entry conf-entry pack-entry inst-entry
16393 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16394 tmp-key tmp-list rule)
16395 ;; check prerequisites
16396 (unless (file-exists-p compile-directory)
16397 (make-directory compile-directory t))
16398 (unless regexp-list
16399 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16400 vhdl-compiler))
16401 (message "Generating makefile \"%s\"..." makefile-name)
16402 ;; rules for all entities
16403 (setq tmp-list ent-alist)
16404 (while ent-alist
16405 (setq ent-entry (car ent-alist)
16406 ent-key (nth 0 ent-entry))
16407 (when (nth 2 ent-entry)
16408 (setq ent-file-name (file-relative-name
16409 (nth 2 ent-entry) compile-directory)
16410 arch-alist (nth 4 ent-entry)
16411 lib-alist (nth 6 ent-entry)
16412 rule (aget rule-alist ent-file-name)
16413 target-list (nth 0 rule)
16414 depend-list (nth 1 rule)
16415 second-list nil
16416 subcomp-list nil)
16417 (setq tmp-key (vhdl-replace-string
16418 ent-regexp (funcall adjust-case ent-key)))
16419 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16420 ;; rule target for this entity
16421 (setq target-list (cons ent-key target-list))
16422 ;; rule dependencies for all used packages
16423 (setq pack-list (vhdl-get-packages lib-alist work-library))
16424 (setq depend-list (append depend-list pack-list))
16425 (setq all-pack-list pack-list)
16426 ;; add rule
16427 (aput 'rule-alist ent-file-name (list target-list depend-list))
16428 ;; rules for all corresponding architectures
16429 (while arch-alist
16430 (setq arch-entry (car arch-alist)
16431 arch-key (nth 0 arch-entry)
16432 ent-arch-key (concat ent-key "-" arch-key)
16433 arch-file-name (file-relative-name (nth 2 arch-entry)
16434 compile-directory)
16435 inst-alist (nth 4 arch-entry)
16436 lib-alist (nth 5 arch-entry)
16437 rule (aget rule-alist arch-file-name)
16438 target-list (nth 0 rule)
16439 depend-list (nth 1 rule))
16440 (setq tmp-key (vhdl-replace-string
16441 arch-regexp
16442 (funcall adjust-case (concat arch-key " " ent-key))))
16443 (setq unit-list
16444 (cons (cons ent-arch-key tmp-key) unit-list))
16445 (setq second-list (cons ent-arch-key second-list))
16446 ;; rule target for this architecture
16447 (setq target-list (cons ent-arch-key target-list))
16448 ;; rule dependency for corresponding entity
16449 (setq depend-list (cons ent-key depend-list))
16450 ;; rule dependencies for contained component instantiations
16451 (while inst-alist
16452 (setq inst-entry (car inst-alist))
16453 (when (or (null (nth 8 inst-entry))
16454 (equal (downcase (nth 8 inst-entry)) work-library))
16455 (setq inst-ent-key (or (nth 7 inst-entry)
16456 (nth 5 inst-entry)))
16457 (setq depend-list (cons inst-ent-key depend-list)
16458 subcomp-list (cons inst-ent-key subcomp-list)))
16459 (setq inst-alist (cdr inst-alist)))
16460 ;; rule dependencies for all used packages
16461 (setq pack-list (vhdl-get-packages lib-alist work-library))
16462 (setq depend-list (append depend-list pack-list))
16463 (setq all-pack-list (append all-pack-list pack-list))
16464 ;; add rule
16465 (aput 'rule-alist arch-file-name (list target-list depend-list))
16466 (setq arch-alist (cdr arch-alist)))
16467 (setq prim-list (cons (list ent-key second-list
16468 (append subcomp-list all-pack-list))
16469 prim-list)))
16470 (setq ent-alist (cdr ent-alist)))
16471 (setq ent-alist tmp-list)
16472 ;; rules for all configurations
16473 (setq tmp-list conf-alist)
16474 (while conf-alist
16475 (setq conf-entry (car conf-alist)
16476 conf-key (nth 0 conf-entry)
16477 conf-file-name (file-relative-name
16478 (nth 2 conf-entry) compile-directory)
16479 ent-key (nth 4 conf-entry)
16480 arch-key (nth 5 conf-entry)
16481 inst-alist (nth 6 conf-entry)
16482 lib-alist (nth 7 conf-entry)
16483 rule (aget rule-alist conf-file-name)
16484 target-list (nth 0 rule)
16485 depend-list (nth 1 rule)
16486 subcomp-list (list ent-key))
16487 (setq tmp-key (vhdl-replace-string
16488 conf-regexp (funcall adjust-case conf-key)))
16489 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16490 ;; rule target for this configuration
16491 (setq target-list (cons conf-key target-list))
16492 ;; rule dependency for corresponding entity and architecture
16493 (setq depend-list
16494 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16495 ;; rule dependencies for used packages
16496 (setq pack-list (vhdl-get-packages lib-alist work-library))
16497 (setq depend-list (append depend-list pack-list))
16498 ;; rule dependencies for contained component configurations
16499 (while inst-alist
16500 (setq inst-entry (car inst-alist))
16501 (setq inst-ent-key (nth 2 inst-entry)
16502 ; comp-arch-key (nth 2 inst-entry))
16503 inst-conf-key (nth 4 inst-entry))
16504 (when (equal (downcase (nth 5 inst-entry)) work-library)
16505 (when inst-ent-key
16506 (setq depend-list (cons inst-ent-key depend-list)
16507 subcomp-list (cons inst-ent-key subcomp-list)))
16508 ; (when comp-arch-key
16509 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16510 ; depend-list)))
16511 (when inst-conf-key
16512 (setq depend-list (cons inst-conf-key depend-list)
16513 subcomp-list (cons inst-conf-key subcomp-list))))
16514 (setq inst-alist (cdr inst-alist)))
16515 ;; add rule
16516 (aput 'rule-alist conf-file-name (list target-list depend-list))
16517 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16518 prim-list))
16519 (setq conf-alist (cdr conf-alist)))
16520 (setq conf-alist tmp-list)
16521 ;; rules for all packages
16522 (setq tmp-list pack-alist)
16523 (while pack-alist
16524 (setq pack-entry (car pack-alist)
16525 pack-key (nth 0 pack-entry)
16526 pack-body-key nil)
16527 (when (nth 2 pack-entry)
16528 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16529 compile-directory)
16530 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16531 rule (aget rule-alist pack-file-name)
16532 target-list (nth 0 rule) depend-list (nth 1 rule))
16533 (setq tmp-key (vhdl-replace-string
16534 pack-regexp (funcall adjust-case pack-key)))
16535 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16536 ;; rule target for this package
16537 (setq target-list (cons pack-key target-list))
16538 ;; rule dependencies for all used packages
16539 (setq pack-list (vhdl-get-packages lib-alist work-library))
16540 (setq depend-list (append depend-list pack-list))
16541 (setq all-pack-list pack-list)
16542 ;; add rule
16543 (aput 'rule-alist pack-file-name (list target-list depend-list))
16544 ;; rules for this package's body
16545 (when (nth 7 pack-entry)
16546 (setq pack-body-key (concat pack-key "-body")
16547 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16548 compile-directory)
16549 rule (aget rule-alist pack-body-file-name)
16550 target-list (nth 0 rule)
16551 depend-list (nth 1 rule))
16552 (setq tmp-key (vhdl-replace-string
16553 pack-body-regexp (funcall adjust-case pack-key)))
16554 (setq unit-list
16555 (cons (cons pack-body-key tmp-key) unit-list))
16556 ;; rule target for this package's body
16557 (setq target-list (cons pack-body-key target-list))
16558 ;; rule dependency for corresponding package declaration
16559 (setq depend-list (cons pack-key depend-list))
16560 ;; rule dependencies for all used packages
16561 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16562 (setq depend-list (append depend-list pack-list))
16563 (setq all-pack-list (append all-pack-list pack-list))
16564 ;; add rule
16565 (aput 'rule-alist pack-body-file-name
16566 (list target-list depend-list)))
16567 (setq prim-list
16568 (cons (list pack-key (when pack-body-key (list pack-body-key))
16569 all-pack-list)
16570 prim-list)))
16571 (setq pack-alist (cdr pack-alist)))
16572 (setq pack-alist tmp-list)
16573 ;; generate Makefile
16574 (let* ((project (aget vhdl-project-alist project))
16575 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16576 (compiler-id (nth 9 compiler))
16577 (library-directory
16578 (vhdl-resolve-env-variable
16579 (vhdl-replace-string
16580 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16581 compiler-id)))
16582 (makefile-path-name (expand-file-name
16583 makefile-name compile-directory))
16584 (orig-buffer (current-buffer))
16585 cell second-list subcomp-list options unit-key unit-name)
16586 ;; sort lists
16587 (setq unit-list (vhdl-sort-alist unit-list))
16588 (setq prim-list (vhdl-sort-alist prim-list))
16589 (setq tmp-list rule-alist)
16590 (while tmp-list ; pre-sort rule targets
16591 (setq cell (cdar tmp-list))
16592 (setcar cell (sort (car cell) 'string<))
16593 (setq tmp-list (cdr tmp-list)))
16594 (setq rule-alist ; sort by first rule target
16595 (sort rule-alist
16596 (function (lambda (a b)
16597 (string< (car (cadr a)) (car (cadr b)))))))
16598 ;; open and clear Makefile
16599 (set-buffer (find-file-noselect makefile-path-name t t))
16600 (erase-buffer)
16601 (insert "# -*- Makefile -*-\n"
16602 "### " (file-name-nondirectory makefile-name)
16603 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16604 "\n")
16605 (if project
16606 (insert "\n# Project : " (nth 0 project))
16607 (insert "\n# Directory : \"" directory "\""))
16608 (insert "\n# Platform : " vhdl-compiler
16609 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16610 (user-login-name) "\n")
16611 ;; insert compile and option variable settings
16612 (insert "\n\n# Define compilation command and options\n"
16613 "\nCOMPILE = " (nth 0 compiler)
16614 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16615 "\n")
16616 ;; insert library paths
16617 (setq library-directory
16618 (directory-file-name
16619 (if (file-name-absolute-p library-directory)
16620 library-directory
16621 (file-relative-name
16622 (expand-file-name library-directory directory)
16623 compile-directory))))
16624 (insert "\n\n# Define library paths\n"
16625 "\nLIBRARY-" work-library " = " library-directory "\n")
16626 ;; insert variable definitions for all library unit files
16627 (insert "\n\n# Define library unit files\n")
16628 (setq tmp-list unit-list)
16629 (while unit-list
16630 (insert "\nUNIT-" work-library "-" (caar unit-list)
16631 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16632 (setq unit-list (cdr unit-list)))
16633 ;; insert variable definition for list of all library unit files
16634 (insert "\n\n\n# Define list of all library unit files\n"
16635 "\nALL_UNITS =")
16636 (setq unit-list tmp-list)
16637 (while unit-list
16638 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16639 (setq unit-list (cdr unit-list)))
16640 (insert "\n")
16641 (setq unit-list tmp-list)
16642 ;; insert `make all' rule
16643 (insert "\n\n\n# Rule for compiling entire design\n"
16644 "\nall :"
16645 " \\\n\t\tlibrary"
16646 " \\\n\t\t$(ALL_UNITS)\n")
16647 ;; insert `make clean' rule
16648 (insert "\n\n# Rule for cleaning entire design\n"
16649 "\nclean : "
16650 "\n\t-rm -f $(ALL_UNITS)\n")
16651 ;; insert `make library' rule
16652 (insert "\n\n# Rule for creating library directory\n"
16653 "\nlibrary :"
16654 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16655 "\n$(LIBRARY-" work-library ") :"
16656 "\n\t"
16657 (vhdl-replace-string
16658 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16659 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16660 "\n")
16661 ;; insert rule for each library unit
16662 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16663 (while prim-list
16664 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16665 (setq subcomp-list
16666 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16667 (setq unit-key (caar prim-list)
16668 unit-name (or (nth 0 (aget ent-alist unit-key t))
16669 (nth 0 (aget conf-alist unit-key t))
16670 (nth 0 (aget pack-alist unit-key t))))
16671 (insert "\n" unit-key)
16672 (unless (equal unit-key unit-name)
16673 (insert " \\\n" unit-name))
16674 (insert " :"
16675 " \\\n\t\tlibrary"
16676 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16677 (while second-list
16678 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16679 (setq second-list (cdr second-list)))
16680 (while subcomp-list
16681 (when (and (assoc (car subcomp-list) unit-list)
16682 (not (equal unit-key (car subcomp-list))))
16683 (insert " \\\n\t\t" (car subcomp-list)))
16684 (setq subcomp-list (cdr subcomp-list)))
16685 (insert "\n")
16686 (setq prim-list (cdr prim-list)))
16687 ;; insert rule for each library unit file
16688 (insert "\n\n# Rules for compiling single library unit files\n")
16689 (while rule-alist
16690 (setq rule (car rule-alist))
16691 ;; get compiler options for this file
16692 (setq options
16693 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16694 ;; insert rule if file is supposed to be compiled
16695 (setq target-list (nth 1 rule)
16696 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16697 ;; insert targets
16698 (setq tmp-list target-list)
16699 (while target-list
16700 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16701 (if (cdr target-list) " \\" " :"))
16702 (setq target-list (cdr target-list)))
16703 (setq target-list tmp-list)
16704 ;; insert file name as first dependency
16705 (insert " \\\n\t\t" (nth 0 rule))
16706 ;; insert dependencies (except if also target or unit does not exist)
16707 (while depend-list
16708 (when (and (not (member (car depend-list) target-list))
16709 (assoc (car depend-list) unit-list))
16710 (insert " \\\n\t\t"
16711 "$(UNIT-" work-library "-" (car depend-list) ")"))
16712 (setq depend-list (cdr depend-list)))
16713 ;; insert compile command
16714 (if options
16715 (insert "\n\t$(COMPILE) "
16716 (if (eq options 'default) "$(OPTIONS)" options) " "
16717 (nth 0 rule) "\n")
16718 (setq tmp-list target-list)
16719 (while target-list
16720 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16721 (if (cdr target-list) " \\" "\n"))
16722 (setq target-list (cdr target-list)))
16723 (setq target-list tmp-list))
16724 (setq rule-alist (cdr rule-alist)))
16725 (insert "\n\n### " makefile-name " ends here\n")
16726 ;; run Makefile generation hook
16727 (run-hooks 'vhdl-makefile-generation-hook)
16728 (message "Generating makefile \"%s\"...done" makefile-name)
16729 ;; save and close file
16730 (if (file-writable-p makefile-path-name)
16731 (progn (save-buffer)
16732 (kill-buffer (current-buffer))
16733 (set-buffer orig-buffer)
16734 (add-to-history 'file-name-history makefile-path-name))
16735 (vhdl-warning-when-idle
16736 (format "File not writable: \"%s\""
16737 (abbreviate-file-name makefile-path-name)))
16738 (switch-to-buffer (current-buffer))))))
16739
16740
16741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16742 ;;; Bug reports
16743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16744 ;; (using `reporter.el')
16745
16746 (defconst vhdl-mode-help-address
16747 "Reto Zimmermann <reto@gnu.org>"
16748 "Address for VHDL Mode bug reports.")
16749
16750 (defun vhdl-submit-bug-report ()
16751 "Submit via mail a bug report on VHDL Mode."
16752 (interactive)
16753 ;; load in reporter
16754 (and
16755 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16756 (let ((reporter-prompt-for-summary-p t))
16757 (reporter-submit-bug-report
16758 vhdl-mode-help-address
16759 (concat "VHDL Mode " vhdl-version)
16760 (list
16761 ;; report all important user options
16762 'vhdl-offsets-alist
16763 'vhdl-comment-only-line-offset
16764 'tab-width
16765 'vhdl-electric-mode
16766 'vhdl-stutter-mode
16767 'vhdl-indent-tabs-mode
16768 'vhdl-project-alist
16769 'vhdl-project
16770 'vhdl-project-file-name
16771 'vhdl-project-auto-load
16772 'vhdl-project-sort
16773 'vhdl-compiler-alist
16774 'vhdl-compiler
16775 'vhdl-compile-use-local-error-regexp
16776 'vhdl-makefile-generation-hook
16777 'vhdl-default-library
16778 'vhdl-standard
16779 'vhdl-basic-offset
16780 'vhdl-upper-case-keywords
16781 'vhdl-upper-case-types
16782 'vhdl-upper-case-attributes
16783 'vhdl-upper-case-enum-values
16784 'vhdl-upper-case-constants
16785 'vhdl-use-direct-instantiation
16786 'vhdl-compose-configuration-name
16787 'vhdl-entity-file-name
16788 'vhdl-architecture-file-name
16789 'vhdl-configuration-file-name
16790 'vhdl-package-file-name
16791 'vhdl-file-name-case
16792 'vhdl-electric-keywords
16793 'vhdl-optional-labels
16794 'vhdl-insert-empty-lines
16795 'vhdl-argument-list-indent
16796 'vhdl-association-list-with-formals
16797 'vhdl-conditions-in-parenthesis
16798 'vhdl-zero-string
16799 'vhdl-one-string
16800 'vhdl-file-header
16801 'vhdl-file-footer
16802 'vhdl-company-name
16803 'vhdl-copyright-string
16804 'vhdl-platform-spec
16805 'vhdl-date-format
16806 'vhdl-modify-date-prefix-string
16807 'vhdl-modify-date-on-saving
16808 'vhdl-reset-kind
16809 'vhdl-reset-active-high
16810 'vhdl-clock-rising-edge
16811 'vhdl-clock-edge-condition
16812 'vhdl-clock-name
16813 'vhdl-reset-name
16814 'vhdl-model-alist
16815 'vhdl-include-port-comments
16816 'vhdl-include-direction-comments
16817 'vhdl-include-type-comments
16818 'vhdl-include-group-comments
16819 'vhdl-actual-port-name
16820 'vhdl-instance-name
16821 'vhdl-testbench-entity-name
16822 'vhdl-testbench-architecture-name
16823 'vhdl-testbench-configuration-name
16824 'vhdl-testbench-dut-name
16825 'vhdl-testbench-include-header
16826 'vhdl-testbench-declarations
16827 'vhdl-testbench-statements
16828 'vhdl-testbench-initialize-signals
16829 'vhdl-testbench-include-library
16830 'vhdl-testbench-include-configuration
16831 'vhdl-testbench-create-files
16832 'vhdl-testbench-entity-file-name
16833 'vhdl-testbench-architecture-file-name
16834 'vhdl-compose-create-files
16835 'vhdl-compose-configuration-create-file
16836 'vhdl-compose-configuration-hierarchical
16837 'vhdl-compose-configuration-use-subconfiguration
16838 'vhdl-compose-include-header
16839 'vhdl-compose-architecture-name
16840 'vhdl-components-package-name
16841 'vhdl-use-components-package
16842 'vhdl-self-insert-comments
16843 'vhdl-prompt-for-comments
16844 'vhdl-inline-comment-column
16845 'vhdl-end-comment-column
16846 'vhdl-auto-align
16847 'vhdl-align-groups
16848 'vhdl-align-group-separate
16849 'vhdl-align-same-indent
16850 'vhdl-highlight-keywords
16851 'vhdl-highlight-names
16852 'vhdl-highlight-special-words
16853 'vhdl-highlight-forbidden-words
16854 'vhdl-highlight-verilog-keywords
16855 'vhdl-highlight-translate-off
16856 'vhdl-highlight-case-sensitive
16857 'vhdl-special-syntax-alist
16858 'vhdl-forbidden-words
16859 'vhdl-forbidden-syntax
16860 'vhdl-directive-keywords
16861 'vhdl-speedbar-auto-open
16862 'vhdl-speedbar-display-mode
16863 'vhdl-speedbar-scan-limit
16864 'vhdl-speedbar-jump-to-unit
16865 'vhdl-speedbar-update-on-saving
16866 'vhdl-speedbar-save-cache
16867 'vhdl-speedbar-cache-file-name
16868 'vhdl-index-menu
16869 'vhdl-source-file-menu
16870 'vhdl-hideshow-menu
16871 'vhdl-hide-all-init
16872 'vhdl-print-two-column
16873 'vhdl-print-customize-faces
16874 'vhdl-intelligent-tab
16875 'vhdl-indent-syntax-based
16876 'vhdl-word-completion-case-sensitive
16877 'vhdl-word-completion-in-minibuffer
16878 'vhdl-underscore-is-part-of-word
16879 'vhdl-mode-hook)
16880 (function
16881 (lambda ()
16882 (insert
16883 (if vhdl-special-indent-hook
16884 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16885 "vhdl-special-indent-hook is set to '"
16886 (format "%s" vhdl-special-indent-hook)
16887 ".\nPerhaps this is your problem?\n"
16888 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16889 "\n"))))
16890 nil
16891 "Hi Reto,"))))
16892
16893
16894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16895 ;;; Documentation
16896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16897
16898 (defconst vhdl-doc-release-notes nil
16899 "\
16900 Release Notes for VHDL Mode 3.33
16901 ================================
16902
16903 - New Features
16904 - User Options
16905
16906
16907 New Features
16908 ------------
16909
16910 CONFIGURATION DECLARATION GENERATION:
16911 - Automatic generation of a configuration declaration for a design.
16912 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16913
16914
16915 User Options
16916 ------------
16917
16918 `vhdl-configuration-file-name': (new)
16919 Specify how the configuration file name is obtained.
16920 `vhdl-compose-configuration-name': (new)
16921 Specify how the configuration name is optained.
16922 `vhdl-compose-configuration-create-file': (new)
16923 Specify whether a new file should be created for a configuration.
16924 `vhdl-compose-configuration-hierarchical': (new)
16925 Specify whether hierarchical configurations should be created.
16926 `vhdl-compose-configuration-use-subconfiguration': (new)
16927 Specify whether subconfigurations should be used inside configurations.
16928 ")
16929
16930
16931 (defconst vhdl-doc-keywords nil
16932 "\
16933 Reserved words in VHDL
16934 ----------------------
16935
16936 VHDL'93 (IEEE Std 1076-1993):
16937 `vhdl-93-keywords' : keywords
16938 `vhdl-93-types' : standardized types
16939 `vhdl-93-attributes' : standardized attributes
16940 `vhdl-93-enum-values' : standardized enumeration values
16941 `vhdl-93-functions' : standardized functions
16942 `vhdl-93-packages' : standardized packages and libraries
16943
16944 VHDL-AMS (IEEE Std 1076.1):
16945 `vhdl-ams-keywords' : keywords
16946 `vhdl-ams-types' : standardized types
16947 `vhdl-ams-attributes' : standardized attributes
16948 `vhdl-ams-enum-values' : standardized enumeration values
16949 `vhdl-ams-functions' : standardized functions
16950
16951 Math Packages (IEEE Std 1076.2):
16952 `vhdl-math-types' : standardized types
16953 `vhdl-math-constants' : standardized constants
16954 `vhdl-math-functions' : standardized functions
16955 `vhdl-math-packages' : standardized packages
16956
16957 Forbidden words:
16958 `vhdl-verilog-keywords' : Verilog reserved words
16959
16960 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16961
16962
16963 (defconst vhdl-doc-coding-style nil
16964 "\
16965 For VHDL coding style and naming convention guidelines, see the following
16966 references:
16967
16968 \[1] Ben Cohen.
16969 \"VHDL Coding Styles and Methodologies\".
16970 Kluwer Academic Publishers, 1999.
16971 http://members.aol.com/vhdlcohen/vhdl/
16972
16973 \[2] Michael Keating and Pierre Bricaud.
16974 \"Reuse Methodology Manual, Second Edition\".
16975 Kluwer Academic Publishers, 1999.
16976 http://www.openmore.com/openmore/rmm2.html
16977
16978 \[3] European Space Agency.
16979 \"VHDL Modelling Guidelines\".
16980 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16981
16982 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16983 to visually support naming conventions.")
16984
16985
16986 (defun vhdl-version ()
16987 "Echo the current version of VHDL Mode in the minibuffer."
16988 (interactive)
16989 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16990 (vhdl-keep-region-active))
16991
16992 (defun vhdl-doc-variable (variable)
16993 "Display VARIABLE's documentation in *Help* buffer."
16994 (interactive)
16995 (unless (featurep 'xemacs)
16996 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16997 (with-output-to-temp-buffer
16998 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16999 (princ (documentation-property variable 'variable-documentation))
17000 (with-current-buffer standard-output
17001 (help-mode))
17002 (print-help-return-message)))
17003
17004 (defun vhdl-doc-mode ()
17005 "Display VHDL Mode documentation in *Help* buffer."
17006 (interactive)
17007 (unless (featurep 'xemacs)
17008 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17009 (with-output-to-temp-buffer
17010 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17011 (princ mode-name)
17012 (princ " mode:\n")
17013 (princ (documentation 'vhdl-mode))
17014 (with-current-buffer standard-output
17015 (help-mode))
17016 (print-help-return-message)))
17017
17018
17019 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17020
17021 (provide 'vhdl-mode)
17022
17023 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17024 ;;; vhdl-mode.el ends here