Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; Free Software Foundation, Inc.
6
7 ;; Authors: Reto Zimmermann <reto@gnu.org>
8 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
9 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
10 ;; Keywords: languages vhdl
11 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
12
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
17
18 (defconst vhdl-version "3.33.6"
19 "VHDL Mode version number.")
20
21 (defconst vhdl-time-stamp "2005-08-30"
22 "VHDL Mode time stamp for last update.")
23
24 ;; This file is part of GNU Emacs.
25
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
30
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
35
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
38
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;; Commentary:
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42
43 ;; This package provides an Emacs major mode for editing VHDL code.
44 ;; It includes the following features:
45
46 ;; - Syntax highlighting
47 ;; - Indentation
48 ;; - Template insertion (electrification)
49 ;; - Insertion of file headers
50 ;; - Insertion of user-specified models
51 ;; - Port translation / testbench generation
52 ;; - Structural composition
53 ;; - Configuration generation
54 ;; - Sensitivity list updating
55 ;; - File browser
56 ;; - Design hierarchy browser
57 ;; - Source file compilation (syntax analysis)
58 ;; - Makefile generation
59 ;; - Code hiding
60 ;; - Word/keyword completion
61 ;; - Block commenting
62 ;; - Code fixing/alignment/beautification
63 ;; - Postscript printing
64 ;; - VHDL'87/'93 and VHDL-AMS supported
65 ;; - Comprehensive menu
66 ;; - Fully customizable
67 ;; - Works under GNU Emacs (recommended) and XEmacs
68
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; Documentation
71
72 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
73
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; Emacs Versions
76
77 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
78 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
79
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;; Installation
82
83 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
84
85 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
86 ;; or into an arbitrary directory that is added to the load path by the
87 ;; following line in your Emacs start-up file `.emacs':
88
89 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
90
91 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
92 ;; directory. Otherwise, byte-compile the source file:
93 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
94 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
95
96 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
97 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
98 ;; (not required in Emacs 20.X):
99
100 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
101 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
102
103 ;; More detailed installation instructions are included in the official
104 ;; VHDL Mode distribution.
105
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;; Acknowledgements
108
109 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
110 ;; and Steve Grout.
111
112 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
113 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
114
115 ;; Many thanks to all the users who sent me bug reports and enhancement
116 ;; requests.
117 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
118 ;; enhancement suggestions and the fruitful discussions.
119 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
120 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
121
122 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
123 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
124 ;; giving me the opportunity to develop this code.
125 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
126 ;; of the Swiss Government.
127
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129
130 ;;; Code:
131
132 ;; Emacs 21+ handling
133 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 21, 22, ... is used.")
135 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
136 "Non-nil if GNU Emacs 22, ... is used.")
137
138 (defvar compilation-file-regexp-alist)
139 (defvar conf-alist)
140 (defvar conf-entry)
141 (defvar conf-key)
142 (defvar ent-alist)
143 (defvar itimer-version)
144 (defvar lazy-lock-defer-contextually)
145 (defvar lazy-lock-defer-on-scrolling)
146 (defvar lazy-lock-defer-on-the-fly)
147 (defvar speedbar-attached-frame)
148
149
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 ;;; Variables
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153
154 ;; help function for user options
155 (defun vhdl-custom-set (variable value &rest functions)
156 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
157 (if (fboundp 'custom-set-default)
158 (custom-set-default variable value)
159 (set-default variable value))
160 (while functions
161 (when (fboundp (car functions)) (funcall (car functions)))
162 (setq functions (cdr functions))))
163
164 (defun vhdl-widget-directory-validate (widget)
165 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
166 '/' or is empty)."
167 (let ((val (widget-value widget)))
168 (unless (string-match "^\\(\\|.*/\\)$" val)
169 (widget-put widget :error "Invalid directory entry: must end with '/'")
170 widget)))
171
172 ;; help string for user options
173 (defconst vhdl-name-doc-string "
174
175 FROM REGEXP is a regular expression matching the original name:
176 \".*\" matches the entire string
177 \"\\(...\\)\" matches a substring
178 TO STRING specifies the string to be inserted as new name:
179 \"\\&\" means substitute entire matched text
180 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
181 Examples:
182 \".*\" \"\\&\" inserts original string
183 \".*\" \"\\&_i\" attaches \"_i\" to original string
184 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
185 \".*\" \"foo\" inserts constant string \"foo\"
186 \".*\" \"\" inserts empty string")
187
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 ;; User variables
190
191 (defgroup vhdl nil
192 "Customizations for VHDL Mode."
193 :prefix "vhdl-"
194 :group 'languages
195 ; :version "21.2" ; comment out for XEmacs
196 )
197
198 (defgroup vhdl-mode nil
199 "Customizations for modes."
200 :group 'vhdl)
201
202 (defcustom vhdl-indent-tabs-mode nil
203 "*Non-nil means indentation can insert tabs.
204 Overrides local variable `indent-tabs-mode'."
205 :type 'boolean
206 :group 'vhdl-mode)
207
208
209 (defgroup vhdl-compile nil
210 "Customizations for compilation."
211 :group 'vhdl)
212
213 (defcustom vhdl-compiler-alist
214 '(
215 ;; Cadence Leapfrog: cv -file test.vhd
216 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
217 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
218 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
219 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
220 ("\\1/entity" "\\2/\\1" "\\1/configuration"
221 "\\1/package" "\\1/body" downcase))
222 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
223 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
224 ;; (PLL_400X_TOP) is not declared [10.3].
225 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
226 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
227 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
228 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
229 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
230 ;; Ikos Voyager: analyze test.vhd
231 ;; analyze test.vhd
232 ;; E L4/C5: this library unit is inaccessible
233 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
234 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
235 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
236 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
237 nil)
238 ;; ModelSim, Model Technology: vcom test.vhd
239 ;; ERROR: test.vhd(14): Unknown identifier: positiv
240 ;; WARNING[2]: test.vhd(85): Possible infinite loop
241 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
242 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
243 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
244 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
245 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
246 "\\1/_primary.dat" "\\1/body.dat" downcase))
247 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
248 ;; test.vhd:34: error message
249 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
250 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
251 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
252 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
253 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
254 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
255 ;; ERROR: test.vhd(24): near "dnd": expecting: END
256 ;; WARNING[4]: test.vhd(30): A space is required between ...
257 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
258 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
259 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase))
262 ;; Savant: scram -publish-cc test.vhd
263 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
264 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
265 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
268 "\\1_config.vhdl" "\\1_package.vhdl"
269 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
270 ;; Simili: vhdlp -work test.vhd
271 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
272 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
273 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
274 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
275 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
276 "\\1/prim.var" "\\1/_body.var" downcase))
277 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
278 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
279 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
280 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
281 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
282 nil)
283 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
284 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
285 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
286 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
287 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
288 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
289 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
290 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
291 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
292 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
293 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
294 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
295 ;; Synplify:
296 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
297 ("Synplify" "n/a" "n/a" "make" "-f \\1"
298 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
299 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
300 nil)
301 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
302 ;; Compiling "test.vhd" line 1...
303 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
304 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
305 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
306 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
307 ("^ *Compiling \"\\(.+\\)\" " 1)
308 nil)
309 ;; VeriBest: vc vhdl test.vhd
310 ;; (no file name printed out!)
311 ;; 32: Z <= A and BitA ;
312 ;; ^^^^
313 ;; [Error] Name BITA is unknown
314 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
316 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
317 nil)
318 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
319 ;; Compiling "test.vhd" line 1...
320 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
321 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
323 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
324 ("^ *Compiling \"\\(.+\\)\" " 1)
325 nil)
326 )
327 "*List of available VHDL compilers and their properties.
328 Each list entry specifies the following items for a compiler:
329 Compiler:
330 Compiler name : name used in option `vhdl-compiler' to choose compiler
331 Compile command : command used for source file compilation
332 Compile options : compile options (\"\\1\" inserts library name)
333 Make command : command used for compilation using a Makefile
334 Make options : make options (\"\\1\" inserts Makefile name)
335 Generate Makefile: use built-in function or command to generate a Makefile
336 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
337 Library command : command to create library directory \(\"\\1\" inserts
338 library directory, \"\\2\" inserts library name)
339 Compile directory: where compilation is run and the Makefile is placed
340 Library directory: directory of default library
341 Makefile name : name of Makefile (default is \"Makefile\")
342 ID string : compiler identification string (see `vhdl-project-alist')
343 Error message:
344 Regexp : regular expression to match error messages (*)
345 File subexp index: index of subexpression that matches the file name
346 Line subexp index: index of subexpression that matches the line number
347 Column subexp idx: index of subexpression that matches the column number
348 File message:
349 Regexp : regular expression to match a file name message
350 File subexp index: index of subexpression that matches the file name
351 Unit-to-file name mapping: mapping of library unit names to names of files
352 generated by the compiler (used for Makefile generation)
353 To string : string a name is mapped to (\"\\1\" inserts the unit name,
354 \"\\2\" inserts the entity name for architectures)
355 Case adjustment : adjust case of inserted unit names
356
357 \(*) The regular expression must match the error message starting from the
358 beginning of the line (but not necessarily to the end of the line).
359
360 Compile options allows insertion of the library name (see `vhdl-project-alist')
361 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
362
363 For Makefile generation, the built-in function can be used (requires
364 specification of the unit-to-file name mapping). Alternatively, an
365 external command can be specified. Work directory allows specification of
366 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
367 used for Makefile generation). To use another library name than \"work\",
368 customize `vhdl-project-alist'. The library command is inserted in Makefiles
369 to automatically create the library directory if not existent.
370
371 Compile options, compile directory, library directory, and Makefile name are
372 overwritten by the project settings if a project is defined (see
373 `vhdl-project-alist'). Directory paths are relative to the source file
374 directory.
375
376 Some compilers do not include the file name in the error message, but print
377 out a file name message in advance. In this case, set \"File Subexp Index\"
378 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
379 If no file name at all is printed out, set both \"File Message\" entries to 0
380 \(a default file name message will be printed out instead, does not work in
381 XEmacs).
382
383 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
384 assigning its name to option `vhdl-compiler'.
385
386 Please send any missing or erroneous compiler properties to the maintainer for
387 updating.
388
389 NOTE: Activate new error and file message regexps and reflect the new setting
390 in the choice list of option `vhdl-compiler' by restarting Emacs."
391 :type '(repeat
392 (list :tag "Compiler" :indent 2
393 (string :tag "Compiler name ")
394 (string :tag "Compile command ")
395 (string :tag "Compile options " "-work \\1")
396 (string :tag "Make command " "make")
397 (string :tag "Make options " "-f \\1")
398 (choice :tag "Generate Makefile "
399 (const :tag "Built-in function" nil)
400 (string :tag "Command" "vmake \\2 > \\1"))
401 (string :tag "Library command " "mkdir \\1")
402 (directory :tag "Compile directory "
403 :validate vhdl-widget-directory-validate "./")
404 (directory :tag "Library directory "
405 :validate vhdl-widget-directory-validate "work/")
406 (file :tag "Makefile name " "Makefile")
407 (string :tag "ID string ")
408 (list :tag "Error message" :indent 4
409 (regexp :tag "Regexp ")
410 (integer :tag "File subexp index")
411 (integer :tag "Line subexp index")
412 (integer :tag "Column subexp idx"))
413 (list :tag "File message" :indent 4
414 (regexp :tag "Regexp ")
415 (integer :tag "File subexp index"))
416 (choice :tag "Unit-to-file name mapping"
417 :format "%t: %[Value Menu%] %v\n"
418 (const :tag "Not defined" nil)
419 (list :tag "To string" :indent 4
420 (string :tag "Entity " "\\1.vhd")
421 (string :tag "Architecture " "\\2_\\1.vhd")
422 (string :tag "Configuration " "\\1.vhd")
423 (string :tag "Package " "\\1.vhd")
424 (string :tag "Package Body " "\\1_body.vhd")
425 (choice :tag "Case adjustment "
426 (const :tag "None" identity)
427 (const :tag "Upcase" upcase)
428 (const :tag "Downcase" downcase))))))
429 :set (lambda (variable value)
430 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
431 :group 'vhdl-compile)
432
433 (defcustom vhdl-compiler "ModelSim"
434 "*Specifies the VHDL compiler to be used for syntax analysis.
435 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
436 :type (let ((alist vhdl-compiler-alist) list)
437 (while alist
438 (setq list (cons (list 'const (caar alist)) list))
439 (setq alist (cdr alist)))
440 (append '(choice) (nreverse list)))
441 :group 'vhdl-compile)
442
443 (defcustom vhdl-compile-use-local-error-regexp t
444 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
445 In this case, only error message regexps for VHDL compilers are active if
446 compilation is started from a VHDL buffer. Otherwise, the error message
447 regexps are appended to the predefined global regexps, and all regexps are
448 active all the time. Note that by doing that, the predefined global regexps
449 might result in erroneous parsing of error messages for some VHDL compilers.
450
451 NOTE: Activate the new setting by restarting Emacs."
452 :type 'boolean
453 :group 'vhdl-compile)
454
455 (defcustom vhdl-makefile-generation-hook nil
456 "*Functions to run at the end of Makefile generation.
457 Allows to insert user specific parts into a Makefile.
458
459 Example:
460 \(lambda nil
461 \(re-search-backward \"^# Rule for compiling entire design\")
462 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
463 :type 'hook
464 :group 'vhdl-compile)
465
466 (defcustom vhdl-default-library "work"
467 "*Name of default library.
468 Is overwritten by project settings if a project is active."
469 :type 'string
470 :group 'vhdl-compile)
471
472
473 (defgroup vhdl-project nil
474 "Customizations for projects."
475 :group 'vhdl)
476
477 (defcustom vhdl-project-alist
478 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
479 "~/example1/" ("src/system/" "src/components/") ""
480 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
481 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
482 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
483 ("Example 2" "Individual source files, multiple compilers in different directories"
484 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
485 nil "\\1/" "work" "\\1/work/" "Makefile" "")
486 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
487 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
488 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
489 -------------------------------------------------------------------------------
490 -- This is a multi-line project description
491 -- that can be used as a project dependent part of the file header.
492 "))
493 "*List of projects and their properties.
494 Name : name used in option `vhdl-project' to choose project
495 Title : title of project (single-line string)
496 Default directory: default project directory (absolute path)
497 Sources : a) source files : path + \"/\" + file name
498 b) directory : path + \"/\"
499 c) directory tree: \"-r \" + path + \"/\"
500 Exclude regexp : matches file/directory names to be excluded as sources
501 Compile options : project-specific options for each compiler
502 Compiler name : name of compiler for which these options are valid
503 Compile options: project-specific compiler options
504 (\"\\1\" inserts library name, \"\\2\" default options)
505 Make options: project-specific make options
506 (\"\\1\" inserts Makefile name, \"\\2\" default options)
507 Exceptions : file-specific exceptions
508 File name regexp: matches file names for which exceptions are valid
509 - Options : file-specific compiler options string
510 (\"\\1\" inserts library name, \"\\2\" default options,
511 \"\\3\" project-specific options)
512 - Do not compile: do not compile this file (in Makefile)
513 Compile directory: where compilation is run and the Makefile is placed
514 \(\"\\1\" inserts compiler ID string)
515 Library name : name of library (default is \"work\")
516 Library directory: path to library (\"\\1\" inserts compiler ID string)
517 Makefile name : name of Makefile
518 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
519 Description : description of project (multi-line string)
520
521 Project title and description are used to insert into the file header (see
522 option `vhdl-file-header').
523
524 The default directory must have an absolute path (use `M-TAB' for completion).
525 All other paths can be absolute or relative to the default directory. All
526 paths must end with '/'.
527
528 The design units found in the sources (files and directories) are shown in the
529 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
530 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
531 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
532 specified, the default directory is taken as source directory. Otherwise,
533 the default directory is only taken as source directory if there is a sources
534 entry with the empty string or \"./\". Exclude regexp allows to filter out
535 specific file and directory names from the list of sources (e.g. CVS
536 directories).
537
538 Files are compiled in the compile directory. Makefiles are also placed into
539 the compile directory. Library directory specifies which directory the
540 compiler compiles into (used to generate the Makefile).
541
542 Since different compile/library directories and Makefiles may exist for
543 different compilers within one project, these paths and names allow the
544 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
545 Compile options, compile directory, library directory, and Makefile name
546 overwrite the settings of the current compiler.
547
548 File-specific compiler options (highest priority) overwrite project-specific
549 options which overwrite default options (lowest priority). Lower priority
550 options can be inserted in higher priority options. This allows to reuse
551 default options (e.g. \"-file\") in project- or file-specific options (e.g.
552 \"-93 -file\").
553
554 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
555 by restarting Emacs."
556 :type `(repeat
557 (list :tag "Project" :indent 2
558 (string :tag "Name ")
559 (string :tag "Title ")
560 (directory :tag "Default directory"
561 :validate vhdl-widget-directory-validate
562 ,(abbreviate-file-name default-directory))
563 (repeat :tag "Sources " :indent 4
564 (directory :format " %v" "./"))
565 (regexp :tag "Exclude regexp ")
566 (repeat
567 :tag "Compile options " :indent 4
568 (list :tag "Compiler" :indent 6
569 ,(let ((alist vhdl-compiler-alist) list)
570 (while alist
571 (setq list (cons (list 'const (caar alist)) list))
572 (setq alist (cdr alist)))
573 (append '(choice :tag "Compiler name")
574 (nreverse list)))
575 (string :tag "Compile options" "\\2")
576 (string :tag "Make options " "\\2")
577 (repeat
578 :tag "Exceptions " :indent 8
579 (cons :format "%v"
580 (regexp :tag "File name regexp ")
581 (choice :format "%[Value Menu%] %v"
582 (string :tag "Options" "\\3")
583 (const :tag "Do not compile" nil))))))
584 (directory :tag "Compile directory"
585 :validate vhdl-widget-directory-validate "./")
586 (string :tag "Library name " "work")
587 (directory :tag "Library directory"
588 :validate vhdl-widget-directory-validate "work/")
589 (file :tag "Makefile name " "Makefile")
590 (string :tag "Description: (type `C-j' for newline)"
591 :format "%t\n%v\n")))
592 :set (lambda (variable value)
593 (vhdl-custom-set variable value
594 'vhdl-update-mode-menu
595 'vhdl-speedbar-refresh))
596 :group 'vhdl-project)
597
598 (defcustom vhdl-project nil
599 "*Specifies the default for the current project.
600 Select a project name from the ones defined in option `vhdl-project-alist'.
601 Is used to determine the project title and description to be inserted in file
602 headers and the source files/directories to be scanned in the hierarchy
603 browser. The current project can also be changed temporarily in the menu."
604 :type (let ((alist vhdl-project-alist) list)
605 (while alist
606 (setq list (cons (list 'const (caar alist)) list))
607 (setq alist (cdr alist)))
608 (append '(choice (const :tag "None" nil) (const :tag "--"))
609 (nreverse list)))
610 :group 'vhdl-project)
611
612 (defcustom vhdl-project-file-name '("\\1.prj")
613 "*List of file names/paths for importing/exporting project setups.
614 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
615 replaced by the user name (allows to have user-specific project setups).
616 The first entry is used as file name to import/export individual project
617 setups. All entries are used to automatically import project setups at
618 startup (see option `vhdl-project-auto-load'). Projects loaded from the
619 first entry are automatically made current. Hint: specify local project
620 setups in first entry, global setups in following entries; loading a local
621 project setup will make it current, while loading the global setups
622 is done without changing the current project.
623 Names can also have an absolute path (i.e. project setups can be stored
624 in global directories)."
625 :type '(repeat (string :tag "File name" "\\1.prj"))
626 :group 'vhdl-project)
627
628 (defcustom vhdl-project-auto-load '(startup)
629 "*Automatically load project setups from files.
630 All project setup files that match the file names specified in option
631 `vhdl-project-file-name' are automatically loaded. The project of the
632 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
633 entry is activated.
634 A project setup file can be obtained by exporting a project (see menu).
635 At startup: project setup file is loaded at Emacs startup"
636 :type '(set (const :tag "At startup" startup))
637 :group 'vhdl-project)
638
639 (defcustom vhdl-project-sort t
640 "*Non-nil means projects are displayed in alphabetical order."
641 :type 'boolean
642 :group 'vhdl-project)
643
644
645 (defgroup vhdl-style nil
646 "Customizations for coding styles."
647 :group 'vhdl
648 :group 'vhdl-template
649 :group 'vhdl-port
650 :group 'vhdl-compose)
651
652 (defcustom vhdl-standard '(87 nil)
653 "*VHDL standards used.
654 Basic standard:
655 VHDL'87 : IEEE Std 1076-1987
656 VHDL'93 : IEEE Std 1076-1993
657 Additional standards:
658 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
659 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
660
661 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
662 \"Activate Options\"."
663 :type '(list (choice :tag "Basic standard"
664 (const :tag "VHDL'87" 87)
665 (const :tag "VHDL'93" 93))
666 (set :tag "Additional standards" :indent 2
667 (const :tag "VHDL-AMS" ams)
668 (const :tag "Math packages" math)))
669 :set (lambda (variable value)
670 (vhdl-custom-set variable value
671 'vhdl-template-map-init
672 'vhdl-mode-abbrev-table-init
673 'vhdl-template-construct-alist-init
674 'vhdl-template-package-alist-init
675 'vhdl-update-mode-menu
676 'vhdl-words-init 'vhdl-font-lock-init))
677 :group 'vhdl-style)
678
679 (defcustom vhdl-basic-offset 2
680 "*Amount of basic offset used for indentation.
681 This value is used by + and - symbols in `vhdl-offsets-alist'."
682 :type 'integer
683 :group 'vhdl-style)
684
685 (defcustom vhdl-upper-case-keywords nil
686 "*Non-nil means convert keywords to upper case.
687 This is done when typed or expanded or by the fix case functions."
688 :type 'boolean
689 :set (lambda (variable value)
690 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
691 :group 'vhdl-style)
692
693 (defcustom vhdl-upper-case-types nil
694 "*Non-nil means convert standardized types to upper case.
695 This is done when expanded or by the fix case functions."
696 :type 'boolean
697 :set (lambda (variable value)
698 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
699 :group 'vhdl-style)
700
701 (defcustom vhdl-upper-case-attributes nil
702 "*Non-nil means convert standardized attributes to upper case.
703 This is done when expanded or by the fix case functions."
704 :type 'boolean
705 :set (lambda (variable value)
706 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
707 :group 'vhdl-style)
708
709 (defcustom vhdl-upper-case-enum-values nil
710 "*Non-nil means convert standardized enumeration values to upper case.
711 This is done when expanded or by the fix case functions."
712 :type 'boolean
713 :set (lambda (variable value)
714 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
715 :group 'vhdl-style)
716
717 (defcustom vhdl-upper-case-constants t
718 "*Non-nil means convert standardized constants to upper case.
719 This is done when expanded."
720 :type 'boolean
721 :set (lambda (variable value)
722 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
723 :group 'vhdl-style)
724
725 (defcustom vhdl-use-direct-instantiation 'standard
726 "*Non-nil means use VHDL'93 direct component instantiation.
727 Never : never
728 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
729 Always : always"
730 :type '(choice (const :tag "Never" never)
731 (const :tag "Standard" standard)
732 (const :tag "Always" always))
733 :group 'vhdl-style)
734
735
736 (defgroup vhdl-naming nil
737 "Customizations for naming conventions."
738 :group 'vhdl)
739
740 (defcustom vhdl-entity-file-name '(".*" . "\\&")
741 (concat
742 "*Specifies how the entity file name is obtained.
743 The entity file name can be obtained by modifying the entity name (e.g.
744 attaching or stripping off a substring). The file extension is automatically
745 taken from the file name of the current buffer."
746 vhdl-name-doc-string)
747 :type '(cons (regexp :tag "From regexp")
748 (string :tag "To string "))
749 :group 'vhdl-naming
750 :group 'vhdl-compose)
751
752 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
753 (concat
754 "*Specifies how the architecture file name is obtained.
755 The architecture file name can be obtained by modifying the entity
756 and/or architecture name (e.g. attaching or stripping off a substring). The
757 file extension is automatically taken from the file name of the current
758 buffer. The string that is matched against the regexp is the concatenation
759 of the entity and the architecture name separated by a space. This gives
760 access to both names (see default setting as example)."
761 vhdl-name-doc-string)
762 :type '(cons (regexp :tag "From regexp")
763 (string :tag "To string "))
764 :group 'vhdl-naming
765 :group 'vhdl-compose)
766
767 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
768 (concat
769 "*Specifies how the configuration file name is obtained.
770 The configuration file name can be obtained by modifying the configuration
771 name (e.g. attaching or stripping off a substring). The file extension is
772 automatically taken from the file name of the current buffer."
773 vhdl-name-doc-string)
774 :type '(cons (regexp :tag "From regexp")
775 (string :tag "To string "))
776 :group 'vhdl-naming
777 :group 'vhdl-compose)
778
779 (defcustom vhdl-package-file-name '(".*" . "\\&")
780 (concat
781 "*Specifies how the package file name is obtained.
782 The package file name can be obtained by modifying the package name (e.g.
783 attaching or stripping off a substring). The file extension is automatically
784 taken from the file name of the current buffer. Package files can be created
785 in a different directory by prepending a relative or absolute path to the
786 file name."
787 vhdl-name-doc-string)
788 :type '(cons (regexp :tag "From regexp")
789 (string :tag "To string "))
790 :group 'vhdl-naming
791 :group 'vhdl-compose)
792
793 (defcustom vhdl-file-name-case 'identity
794 "*Specifies how to change case for obtaining file names.
795 When deriving a file name from a VHDL unit name, case can be changed as
796 follows:
797 As Is: case is not changed (taken as is)
798 Lower Case: whole name is changed to lower case
799 Upper Case: whole name is changed to upper case
800 Capitalize: first letter of each word in name is capitalized"
801 :type '(choice (const :tag "As Is" identity)
802 (const :tag "Lower Case" downcase)
803 (const :tag "Upper Case" upcase)
804 (const :tag "Capitalize" capitalize))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
807
808
809 (defgroup vhdl-template nil
810 "Customizations for electrification."
811 :group 'vhdl)
812
813 (defcustom vhdl-electric-keywords '(vhdl user)
814 "*Type of keywords for which electrification is enabled.
815 VHDL keywords: invoke built-in templates
816 User keywords: invoke user models (see option `vhdl-model-alist')"
817 :type '(set (const :tag "VHDL keywords" vhdl)
818 (const :tag "User model keywords" user))
819 :set (lambda (variable value)
820 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
821 :group 'vhdl-template)
822
823 (defcustom vhdl-optional-labels 'process
824 "*Constructs for which labels are to be queried.
825 Template generators prompt for optional labels for:
826 None : no constructs
827 Processes only: processes only (also procedurals in VHDL-AMS)
828 All constructs: all constructs with optional labels and keyword END"
829 :type '(choice (const :tag "None" none)
830 (const :tag "Processes only" process)
831 (const :tag "All constructs" all))
832 :group 'vhdl-template)
833
834 (defcustom vhdl-insert-empty-lines 'unit
835 "*Specifies whether to insert empty lines in some templates.
836 This improves readability of code. Empty lines are inserted in:
837 None : no constructs
838 Design units only: entities, architectures, configurations, packages only
839 All constructs : also all constructs with BEGIN...END parts
840
841 Replaces option `vhdl-additional-empty-lines'."
842 :type '(choice (const :tag "None" none)
843 (const :tag "Design units only" unit)
844 (const :tag "All constructs" all))
845 :group 'vhdl-template
846 :group 'vhdl-port
847 :group 'vhdl-compose)
848
849 (defcustom vhdl-argument-list-indent nil
850 "*Non-nil means indent argument lists relative to opening parenthesis.
851 That is, argument, association, and port lists start on the same line as the
852 opening parenthesis and subsequent lines are indented accordingly.
853 Otherwise, lists start on a new line and are indented as normal code."
854 :type 'boolean
855 :group 'vhdl-template
856 :group 'vhdl-port
857 :group 'vhdl-compose)
858
859 (defcustom vhdl-association-list-with-formals t
860 "*Non-nil means write association lists with formal parameters.
861 Templates prompt for formal and actual parameters (ports/generics).
862 When pasting component instantiations, formals are included.
863 If nil, only a list of actual parameters is entered."
864 :type 'boolean
865 :group 'vhdl-template
866 :group 'vhdl-port
867 :group 'vhdl-compose)
868
869 (defcustom vhdl-conditions-in-parenthesis nil
870 "*Non-nil means place parenthesis around condition expressions."
871 :type 'boolean
872 :group 'vhdl-template)
873
874 (defcustom vhdl-zero-string "'0'"
875 "*String to use for a logic zero."
876 :type 'string
877 :group 'vhdl-template)
878
879 (defcustom vhdl-one-string "'1'"
880 "*String to use for a logic one."
881 :type 'string
882 :group 'vhdl-template)
883
884
885 (defgroup vhdl-header nil
886 "Customizations for file header."
887 :group 'vhdl-template
888 :group 'vhdl-compose)
889
890 (defcustom vhdl-file-header "\
891 -------------------------------------------------------------------------------
892 -- Title : <title string>
893 -- Project : <project>
894 -------------------------------------------------------------------------------
895 -- File : <filename>
896 -- Author : <author>
897 -- Company : <company>
898 -- Created : <date>
899 -- Last update: <date>
900 -- Platform : <platform>
901 -- Standard : <standard>
902 <projectdesc>-------------------------------------------------------------------------------
903 -- Description: <cursor>
904 <copyright>-------------------------------------------------------------------------------
905 -- Revisions :
906 -- Date Version Author Description
907 -- <date> 1.0 <login>\tCreated
908 -------------------------------------------------------------------------------
909
910 "
911 "*String or file to insert as file header.
912 If the string specifies an existing file name, the contents of the file is
913 inserted, otherwise the string itself is inserted as file header.
914 Type `C-j' for newlines.
915 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
916 if the header needs to be version controlled.
917
918 The following keywords for template generation are supported:
919 <filename> : replaced by the name of the buffer
920 <author> : replaced by the user name and email address
921 \(`user-full-name', `mail-host-address', `user-mail-address')
922 <login> : replaced by user login name (`user-login-name')
923 <company> : replaced by contents of option `vhdl-company-name'
924 <date> : replaced by the current date
925 <year> : replaced by the current year
926 <project> : replaced by title of current project (`vhdl-project')
927 <projectdesc> : replaced by description of current project (`vhdl-project')
928 <copyright> : replaced by copyright string (`vhdl-copyright-string')
929 <platform> : replaced by contents of option `vhdl-platform-spec'
930 <standard> : replaced by the VHDL language standard(s) used
931 <... string> : replaced by a queried string (\"...\" is the prompt word)
932 <title string>: replaced by file title in automatically generated files
933 <cursor> : final cursor position
934
935 The (multi-line) project description <projectdesc> can be used as a project
936 dependent part of the file header and can also contain the above keywords."
937 :type 'string
938 :group 'vhdl-header)
939
940 (defcustom vhdl-file-footer ""
941 "*String or file to insert as file footer.
942 If the string specifies an existing file name, the contents of the file is
943 inserted, otherwise the string itself is inserted as file footer (i.e. at
944 the end of the file).
945 Type `C-j' for newlines.
946 The same keywords as in option `vhdl-file-header' can be used."
947 :type 'string
948 :group 'vhdl-header)
949
950 (defcustom vhdl-company-name ""
951 "*Name of company to insert in file header.
952 See option `vhdl-file-header'."
953 :type 'string
954 :group 'vhdl-header)
955
956 (defcustom vhdl-copyright-string "\
957 -------------------------------------------------------------------------------
958 -- Copyright (c) <year> <company>
959 "
960 "*Copyright string to insert in file header.
961 Can be multi-line string (type `C-j' for newline) and contain other file
962 header keywords (see option `vhdl-file-header')."
963 :type 'string
964 :group 'vhdl-header)
965
966 (defcustom vhdl-platform-spec ""
967 "*Specification of VHDL platform to insert in file header.
968 The platform specification should contain names and versions of the
969 simulation and synthesis tools used.
970 See option `vhdl-file-header'."
971 :type 'string
972 :group 'vhdl-header)
973
974 (defcustom vhdl-date-format "%Y-%m-%d"
975 "*Specifies the date format to use in the header.
976 This string is passed as argument to the command `format-time-string'.
977 For more information on format strings, see the documentation for the
978 `format-time-string' command (C-h f `format-time-string')."
979 :type 'string
980 :group 'vhdl-header)
981
982 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
983 "*Prefix string of modification date in VHDL file header.
984 If actualization of the modification date is called (menu,
985 `\\[vhdl-template-modify]'), this string is searched and the rest
986 of the line replaced by the current date."
987 :type 'string
988 :group 'vhdl-header)
989
990 (defcustom vhdl-modify-date-on-saving t
991 "*Non-nil means update the modification date when the buffer is saved.
992 Calls function `\\[vhdl-template-modify]').
993
994 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
995 \"Activate Options\"."
996 :type 'boolean
997 :group 'vhdl-header)
998
999
1000 (defgroup vhdl-sequential-process nil
1001 "Customizations for sequential processes."
1002 :group 'vhdl-template)
1003
1004 (defcustom vhdl-reset-kind 'async
1005 "*Specifies which kind of reset to use in sequential processes."
1006 :type '(choice (const :tag "None" none)
1007 (const :tag "Synchronous" sync)
1008 (const :tag "Asynchronous" async))
1009 :group 'vhdl-sequential-process)
1010
1011 (defcustom vhdl-reset-active-high nil
1012 "*Non-nil means reset in sequential processes is active high.
1013 Otherwise, reset is active low."
1014 :type 'boolean
1015 :group 'vhdl-sequential-process)
1016
1017 (defcustom vhdl-clock-rising-edge t
1018 "*Non-nil means rising edge of clock triggers sequential processes.
1019 Otherwise, falling edge triggers."
1020 :type 'boolean
1021 :group 'vhdl-sequential-process)
1022
1023 (defcustom vhdl-clock-edge-condition 'standard
1024 "*Syntax of the clock edge condition.
1025 Standard: \"clk'event and clk = '1'\"
1026 Function: \"rising_edge(clk)\""
1027 :type '(choice (const :tag "Standard" standard)
1028 (const :tag "Function" function))
1029 :group 'vhdl-sequential-process)
1030
1031 (defcustom vhdl-clock-name ""
1032 "*Name of clock signal to use in templates."
1033 :type 'string
1034 :group 'vhdl-sequential-process)
1035
1036 (defcustom vhdl-reset-name ""
1037 "*Name of reset signal to use in templates."
1038 :type 'string
1039 :group 'vhdl-sequential-process)
1040
1041
1042 (defgroup vhdl-model nil
1043 "Customizations for user models."
1044 :group 'vhdl)
1045
1046 (defcustom vhdl-model-alist
1047 '(("Example Model"
1048 "<label> : process (<clock>, <reset>)
1049 begin -- process <label>
1050 if <reset> = '0' then -- asynchronous reset (active low)
1051 <cursor>
1052 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1053 if <enable> = '1' then -- synchronous load
1054
1055 end if;
1056 end if;
1057 end process <label>;"
1058 "e" ""))
1059 "*List of user models.
1060 VHDL models (templates) can be specified by the user in this list. They can be
1061 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1062 electrification (i.e. overriding existing or creating new keywords, see
1063 option `vhdl-electric-keywords').
1064 Name : name of model (string of words and spaces)
1065 String : string or name of file to be inserted as model (newline: `C-j')
1066 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1067 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1068 Keyword : keyword to invoke model
1069
1070 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1071 A prompt that appears several times is queried once and replaced throughout
1072 the model. Special prompts are:
1073 <clock> : name specified in `vhdl-clock-name' (if not empty)
1074 <reset> : name specified in `vhdl-reset-name' (if not empty)
1075 <cursor>: final cursor position
1076 File header prompts (see variable `vhdl-file-header') are automatically
1077 replaced, so that user models can also be used to insert different types of
1078 headers.
1079
1080 If the string specifies an existing file name, the contents of the file is
1081 inserted, otherwise the string itself is inserted.
1082 The code within the models should be correctly indented.
1083 Type `C-j' for newlines.
1084
1085 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1086 \"Activate Options\"."
1087 :type '(repeat (list :tag "Model" :indent 2
1088 (string :tag "Name ")
1089 (string :tag "String : (type `C-j' for newline)"
1090 :format "%t\n%v")
1091 (sexp :tag "Key binding" x)
1092 (string :tag "Keyword " :format "%t: %v\n")))
1093 :set (lambda (variable value)
1094 (vhdl-custom-set variable value
1095 'vhdl-model-map-init
1096 'vhdl-model-defun
1097 'vhdl-mode-abbrev-table-init
1098 'vhdl-update-mode-menu))
1099 :group 'vhdl-model)
1100
1101
1102 (defgroup vhdl-compose nil
1103 "Customizations for structural composition."
1104 :group 'vhdl)
1105
1106 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1107 (concat
1108 "*Specifies how the component architecture name is obtained.
1109 The component architecture name can be obtained by modifying the entity name
1110 \(e.g. attaching or stripping off a substring).
1111 If TO STRING is empty, the architecture name is queried."
1112 vhdl-name-doc-string)
1113 :type '(cons (regexp :tag "From regexp")
1114 (string :tag "To string "))
1115 :group 'vhdl-compose)
1116
1117 (defcustom vhdl-compose-configuration-name
1118 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1119 (concat
1120 "*Specifies how the configuration name is obtained.
1121 The configuration name can be obtained by modifying the entity and/or
1122 architecture name (e.g. attaching or stripping off a substring). The string
1123 that is matched against the regexp is the concatenation of the entity and the
1124 architecture name separated by a space. This gives access to both names (see
1125 default setting as example)."
1126 vhdl-name-doc-string)
1127 :type '(cons (regexp :tag "From regexp")
1128 (string :tag "To string "))
1129 :group 'vhdl-compose)
1130
1131 (defcustom vhdl-components-package-name
1132 '((".*" . "\\&_components") . "components")
1133 (concat
1134 "*Specifies how the name for the components package is obtained.
1135 The components package is a package containing all component declarations for
1136 the current design. Its name can be obtained by modifying the project name
1137 \(e.g. attaching or stripping off a substring). If no project is defined, the
1138 DIRECTORY entry is chosen."
1139 vhdl-name-doc-string)
1140 :type '(cons (cons :tag "Project" :indent 2
1141 (regexp :tag "From regexp")
1142 (string :tag "To string "))
1143 (string :tag "Directory:\n String "))
1144 :group 'vhdl-compose)
1145
1146 (defcustom vhdl-use-components-package nil
1147 "*Non-nil means use a separate components package for component declarations.
1148 Otherwise, component declarations are inserted and searched for in the
1149 architecture declarative parts."
1150 :type 'boolean
1151 :group 'vhdl-compose)
1152
1153 (defcustom vhdl-compose-include-header t
1154 "*Non-nil means include a header in automatically generated files."
1155 :type 'boolean
1156 :group 'vhdl-compose)
1157
1158 (defcustom vhdl-compose-create-files 'single
1159 "*Specifies whether new files should be created for the new component.
1160 The component's entity and architecture are inserted:
1161 None : in current buffer
1162 Single file : in new single file
1163 Separate files: in two separate files
1164 The file names are obtained from variables `vhdl-entity-file-name' and
1165 `vhdl-architecture-file-name'."
1166 :type '(choice (const :tag "None" none)
1167 (const :tag "Single file" single)
1168 (const :tag "Separate files" separate))
1169 :group 'vhdl-compose)
1170
1171 (defcustom vhdl-compose-configuration-create-file nil
1172 "*Specifies whether a new file should be created for the configuration.
1173 If non-nil, a new file is created for the configuration.
1174 The file name is obtained from variable `vhdl-configuration-file-name'."
1175 :type 'boolean
1176 :group 'vhdl-compose)
1177
1178 (defcustom vhdl-compose-configuration-hierarchical t
1179 "*Specifies whether hierarchical configurations should be created.
1180 If non-nil, automatically created configurations are hierarchical and include
1181 the whole hierarchy of subcomponents. Otherwise the configuration only
1182 includes one level of subcomponents."
1183 :type 'boolean
1184 :group 'vhdl-compose)
1185
1186 (defcustom vhdl-compose-configuration-use-subconfiguration t
1187 "*Specifies whether subconfigurations should be used inside configurations.
1188 If non-nil, automatically created configurations use configurations in binding
1189 indications for subcomponents, if such configurations exist. Otherwise,
1190 entities are used in binding indications for subcomponents."
1191 :type 'boolean
1192 :group 'vhdl-compose)
1193
1194
1195 (defgroup vhdl-port nil
1196 "Customizations for port translation functions."
1197 :group 'vhdl
1198 :group 'vhdl-compose)
1199
1200 (defcustom vhdl-include-port-comments nil
1201 "*Non-nil means include port comments when a port is pasted."
1202 :type 'boolean
1203 :group 'vhdl-port)
1204
1205 (defcustom vhdl-include-direction-comments nil
1206 "*Non-nil means include port direction in instantiations as comments."
1207 :type 'boolean
1208 :group 'vhdl-port)
1209
1210 (defcustom vhdl-include-type-comments nil
1211 "*Non-nil means include generic/port type in instantiations as comments."
1212 :type 'boolean
1213 :group 'vhdl-port)
1214
1215 (defcustom vhdl-include-group-comments 'never
1216 "*Specifies whether to include group comments and spacings.
1217 The comments and empty lines between groups of ports are pasted:
1218 Never : never
1219 Declarations: in entity/component/constant/signal declarations only
1220 Always : also in generic/port maps"
1221 :type '(choice (const :tag "Never" never)
1222 (const :tag "Declarations" decl)
1223 (const :tag "Always" always))
1224 :group 'vhdl-port)
1225
1226 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1227 (concat
1228 "*Specifies how actual port names are obtained from formal port names.
1229 In a component instantiation, an actual port name can be obtained by
1230 modifying the formal port name (e.g. attaching or stripping off a substring)."
1231 vhdl-name-doc-string)
1232 :type '(cons (regexp :tag "From regexp")
1233 (string :tag "To string "))
1234 :group 'vhdl-port)
1235
1236 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1237 (concat
1238 "*Specifies how an instance name is obtained.
1239 The instance name can be obtained by modifying the name of the component to be
1240 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1241 by a unique number (starting with 1).
1242 If TO STRING is empty, the instance name is queried."
1243 vhdl-name-doc-string)
1244 :type '(cons (regexp :tag "From regexp")
1245 (string :tag "To string "))
1246 :group 'vhdl-port)
1247
1248
1249 (defgroup vhdl-testbench nil
1250 "Customizations for testbench generation."
1251 :group 'vhdl-port)
1252
1253 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1254 (concat
1255 "*Specifies how the testbench entity name is obtained.
1256 The entity name of a testbench can be obtained by modifying the name of
1257 the component to be tested (e.g. attaching or stripping off a substring)."
1258 vhdl-name-doc-string)
1259 :type '(cons (regexp :tag "From regexp")
1260 (string :tag "To string "))
1261 :group 'vhdl-testbench)
1262
1263 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1264 (concat
1265 "*Specifies how the testbench architecture name is obtained.
1266 The testbench architecture name can be obtained by modifying the name of
1267 the component to be tested (e.g. attaching or stripping off a substring).
1268 If TO STRING is empty, the architecture name is queried."
1269 vhdl-name-doc-string)
1270 :type '(cons (regexp :tag "From regexp")
1271 (string :tag "To string "))
1272 :group 'vhdl-testbench)
1273
1274 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1275 (concat
1276 "*Specifies how the testbench configuration name is obtained.
1277 The configuration name of a testbench can be obtained by modifying the entity
1278 and/or architecture name (e.g. attaching or stripping off a substring). The
1279 string that is matched against the regexp is the concatenation of the entity
1280 and the architecture name separated by a space. This gives access to both
1281 names (see default setting as example)."
1282 vhdl-name-doc-string)
1283 :type '(cons (regexp :tag "From regexp")
1284 (string :tag "To string "))
1285 :group 'vhdl-testbench)
1286
1287 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1288 (concat
1289 "*Specifies how a DUT instance name is obtained.
1290 The design-under-test instance name (i.e. the component instantiated in the
1291 testbench) can be obtained by modifying the component name (e.g. attaching
1292 or stripping off a substring)."
1293 vhdl-name-doc-string)
1294 :type '(cons (regexp :tag "From regexp")
1295 (string :tag "To string "))
1296 :group 'vhdl-testbench)
1297
1298 (defcustom vhdl-testbench-include-header t
1299 "*Non-nil means include a header in automatically generated files."
1300 :type 'boolean
1301 :group 'vhdl-testbench)
1302
1303 (defcustom vhdl-testbench-declarations "\
1304 -- clock
1305 signal Clk : std_logic := '1';
1306 "
1307 "*String or file to be inserted in the testbench declarative part.
1308 If the string specifies an existing file name, the contents of the file is
1309 inserted, otherwise the string itself is inserted in the testbench
1310 architecture before the BEGIN keyword.
1311 Type `C-j' for newlines."
1312 :type 'string
1313 :group 'vhdl-testbench)
1314
1315 (defcustom vhdl-testbench-statements "\
1316 -- clock generation
1317 Clk <= not Clk after 10 ns;
1318
1319 -- waveform generation
1320 WaveGen_Proc: process
1321 begin
1322 -- insert signal assignments here
1323
1324 wait until Clk = '1';
1325 end process WaveGen_Proc;
1326 "
1327 "*String or file to be inserted in the testbench statement part.
1328 If the string specifies an existing file name, the contents of the file is
1329 inserted, otherwise the string itself is inserted in the testbench
1330 architecture before the END keyword.
1331 Type `C-j' for newlines."
1332 :type 'string
1333 :group 'vhdl-testbench)
1334
1335 (defcustom vhdl-testbench-initialize-signals nil
1336 "*Non-nil means initialize signals with `0' when declared in testbench."
1337 :type 'boolean
1338 :group 'vhdl-testbench)
1339
1340 (defcustom vhdl-testbench-include-library t
1341 "*Non-nil means a library/use clause for std_logic_1164 is included."
1342 :type 'boolean
1343 :group 'vhdl-testbench)
1344
1345 (defcustom vhdl-testbench-include-configuration t
1346 "*Non-nil means a testbench configuration is attached at the end."
1347 :type 'boolean
1348 :group 'vhdl-testbench)
1349
1350 (defcustom vhdl-testbench-create-files 'single
1351 "*Specifies whether new files should be created for the testbench.
1352 testbench entity and architecture are inserted:
1353 None : in current buffer
1354 Single file : in new single file
1355 Separate files: in two separate files
1356 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1357 and `vhdl-testbench-architecture-file-name'."
1358 :type '(choice (const :tag "None" none)
1359 (const :tag "Single file" single)
1360 (const :tag "Separate files" separate))
1361 :group 'vhdl-testbench)
1362
1363 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1364 (concat
1365 "*Specifies how the testbench entity file name is obtained.
1366 The entity file name can be obtained by modifying the testbench entity name
1367 \(e.g. attaching or stripping off a substring). The file extension is
1368 automatically taken from the file name of the current buffer. Testbench
1369 files can be created in a different directory by prepending a relative or
1370 absolute path to the file name."
1371 vhdl-name-doc-string)
1372 :type '(cons (regexp :tag "From regexp")
1373 (string :tag "To string "))
1374 :group 'vhdl-testbench)
1375
1376 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1377 (concat
1378 "*Specifies how the testbench architecture file name is obtained.
1379 The architecture file name can be obtained by modifying the testbench entity
1380 and/or architecture name (e.g. attaching or stripping off a substring). The
1381 string that is matched against the regexp is the concatenation of the entity
1382 and the architecture name separated by a space. This gives access to both
1383 names (see default setting as example). Testbench files can be created in
1384 a different directory by prepending a relative or absolute path to the file
1385 name."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1390
1391
1392 (defgroup vhdl-comment nil
1393 "Customizations for comments."
1394 :group 'vhdl)
1395
1396 (defcustom vhdl-self-insert-comments t
1397 "*Non-nil means various templates automatically insert help comments."
1398 :type 'boolean
1399 :group 'vhdl-comment)
1400
1401 (defcustom vhdl-prompt-for-comments t
1402 "*Non-nil means various templates prompt for user definable comments."
1403 :type 'boolean
1404 :group 'vhdl-comment)
1405
1406 (defcustom vhdl-inline-comment-column 40
1407 "*Column to indent and align inline comments to.
1408 Overrides local option `comment-column'.
1409
1410 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1411 \"Activate Options\"."
1412 :type 'integer
1413 :group 'vhdl-comment)
1414
1415 (defcustom vhdl-end-comment-column 79
1416 "*End of comment column.
1417 Comments that exceed this column number are wrapped.
1418
1419 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1420 \"Activate Options\"."
1421 :type 'integer
1422 :group 'vhdl-comment)
1423
1424 (defvar end-comment-column)
1425
1426
1427 (defgroup vhdl-align nil
1428 "Customizations for alignment."
1429 :group 'vhdl)
1430
1431 (defcustom vhdl-auto-align t
1432 "*Non-nil means align some templates automatically after generation."
1433 :type 'boolean
1434 :group 'vhdl-align)
1435
1436 (defcustom vhdl-align-groups t
1437 "*Non-nil means align groups of code lines separately.
1438 A group of code lines is a region of consecutive lines between two lines that
1439 match the regexp in option `vhdl-align-group-separate'."
1440 :type 'boolean
1441 :group 'vhdl-align)
1442
1443 (defcustom vhdl-align-group-separate "^\\s-*$"
1444 "*Regexp for matching a line that separates groups of lines for alignment.
1445 Examples:
1446 \"^\\s-*$\": matches an empty line
1447 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1448 :type 'regexp
1449 :group 'vhdl-align)
1450
1451 (defcustom vhdl-align-same-indent t
1452 "*Non-nil means align blocks with same indent separately.
1453 When a region or the entire buffer is aligned, the code is divided into
1454 blocks of same indent which are aligned separately (except for argument/port
1455 lists). This gives nicer alignment in most cases.
1456 Option `vhdl-align-groups' still applies within these blocks."
1457 :type 'boolean
1458 :group 'vhdl-align)
1459
1460
1461 (defgroup vhdl-highlight nil
1462 "Customizations for highlighting."
1463 :group 'vhdl)
1464
1465 (defcustom vhdl-highlight-keywords t
1466 "*Non-nil means highlight VHDL keywords and other standardized words.
1467 The following faces are used:
1468 `font-lock-keyword-face' : keywords
1469 `font-lock-type-face' : standardized types
1470 `vhdl-font-lock-attribute-face': standardized attributes
1471 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1472 `vhdl-font-lock-function-face' : standardized function and package names
1473
1474 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1475 entry \"Fontify Buffer\")."
1476 :type 'boolean
1477 :set (lambda (variable value)
1478 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1479 :group 'vhdl-highlight)
1480
1481 (defcustom vhdl-highlight-names t
1482 "*Non-nil means highlight declaration names and construct labels.
1483 The following faces are used:
1484 `font-lock-function-name-face' : names in declarations of units,
1485 subprograms, components, as well as labels of VHDL constructs
1486 `font-lock-type-face' : names in type/nature declarations
1487 `vhdl-font-lock-attribute-face': names in attribute declarations
1488 `font-lock-variable-name-face' : names in declarations of signals,
1489 variables, constants, subprogram parameters, generics, and ports
1490
1491 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1492 entry \"Fontify Buffer\")."
1493 :type 'boolean
1494 :set (lambda (variable value)
1495 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1496 :group 'vhdl-highlight)
1497
1498 (defcustom vhdl-highlight-special-words nil
1499 "*Non-nil means highlight words with special syntax.
1500 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1501 are highlighted accordingly.
1502 Can be used for visual support of naming conventions.
1503
1504 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1505 entry \"Fontify Buffer\")."
1506 :type 'boolean
1507 :set (lambda (variable value)
1508 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1509 :group 'vhdl-highlight)
1510
1511 (defcustom vhdl-highlight-forbidden-words nil
1512 "*Non-nil means highlight forbidden words.
1513 The reserved words specified in option `vhdl-forbidden-words' or having the
1514 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1515 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1516 use them.
1517
1518 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1519 entry \"Fontify Buffer\")."
1520 :type 'boolean
1521 :set (lambda (variable value)
1522 (vhdl-custom-set variable value
1523 'vhdl-words-init 'vhdl-font-lock-init))
1524 :group 'vhdl-highlight)
1525
1526 (defcustom vhdl-highlight-verilog-keywords nil
1527 "*Non-nil means highlight Verilog keywords as reserved words.
1528 Verilog keywords are highlighted in a warning color (face
1529 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1530
1531 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1532 entry \"Fontify Buffer\")."
1533 :type 'boolean
1534 :set (lambda (variable value)
1535 (vhdl-custom-set variable value
1536 'vhdl-words-init 'vhdl-font-lock-init))
1537 :group 'vhdl-highlight)
1538
1539 (defcustom vhdl-highlight-translate-off nil
1540 "*Non-nil means background-highlight code excluded from translation.
1541 That is, all code between \"-- pragma translate_off\" and
1542 \"-- pragma translate_on\" is highlighted using a different background color
1543 \(face `vhdl-font-lock-translate-off-face').
1544 Note: this might slow down on-the-fly fontification (and thus editing).
1545
1546 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1547 entry \"Fontify Buffer\")."
1548 :type 'boolean
1549 :set (lambda (variable value)
1550 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1551 :group 'vhdl-highlight)
1552
1553 (defcustom vhdl-highlight-case-sensitive nil
1554 "*Non-nil means consider case for highlighting.
1555 Possible trade-off:
1556 non-nil also upper-case VHDL words are highlighted, but case of words with
1557 special syntax is not considered
1558 nil only lower-case VHDL words are highlighted, but case of words with
1559 special syntax is considered
1560 Overrides local option `font-lock-keywords-case-fold-search'.
1561
1562 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1563 entry \"Fontify Buffer\")."
1564 :type 'boolean
1565 :group 'vhdl-highlight)
1566
1567 (defcustom vhdl-special-syntax-alist
1568 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1569 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1570 ("variable" "\\w+_v" "Grey50" "Grey80"))
1571 "*List of special syntax to be highlighted.
1572 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1573 syntax (as regular expression) are highlighted in the corresponding color.
1574
1575 Name : string of words and spaces
1576 Regexp : regular expression describing word syntax
1577 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1578 Color (light): foreground color for light background
1579 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1580 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1581 Color (dark) : foreground color for dark background
1582 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1583 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1584
1585 Can be used for visual support of naming conventions, such as highlighting
1586 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1587 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1588 common substrings or name suffices.
1589 For each entry, a new face is generated with the specified colors and name
1590 \"vhdl-font-lock-\" + name + \"-face\".
1591
1592 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1593 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1594 :type '(repeat (list :tag "Face" :indent 2
1595 (string :tag "Name ")
1596 (regexp :tag "Regexp " "\\w+_")
1597 (string :tag "Color (light)")
1598 (string :tag "Color (dark) ")))
1599 :set (lambda (variable value)
1600 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1601 :group 'vhdl-highlight)
1602
1603 (defcustom vhdl-forbidden-words '()
1604 "*List of forbidden words to be highlighted.
1605 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1606 words are highlighted in a warning color to indicate not to use them.
1607
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type '(repeat (string :format "%v"))
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value
1613 'vhdl-words-init 'vhdl-font-lock-init))
1614 :group 'vhdl-highlight)
1615
1616 (defcustom vhdl-forbidden-syntax ""
1617 "*Syntax of forbidden words to be highlighted.
1618 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1619 syntax are highlighted in a warning color to indicate not to use them.
1620 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1621 highlights identifiers with 10 or more characters).
1622
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type 'regexp
1626 :set (lambda (variable value)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
1630
1631 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1632 "*List of compiler directive keywords recognized for highlighting.
1633
1634 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1635 entry \"Fontify Buffer\")."
1636 :type '(repeat (string :format "%v"))
1637 :set (lambda (variable value)
1638 (vhdl-custom-set variable value
1639 'vhdl-words-init 'vhdl-font-lock-init))
1640 :group 'vhdl-highlight)
1641
1642
1643 (defgroup vhdl-speedbar nil
1644 "Customizations for speedbar."
1645 :group 'vhdl)
1646
1647 (defcustom vhdl-speedbar-auto-open nil
1648 "*Non-nil means automatically open speedbar at startup.
1649 Alternatively, the speedbar can be opened from the VHDL menu."
1650 :type 'boolean
1651 :group 'vhdl-speedbar)
1652
1653 (defcustom vhdl-speedbar-display-mode 'files
1654 "*Specifies the default displaying mode when opening speedbar.
1655 Alternatively, the displaying mode can be selected from the speedbar menu or
1656 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1657 :type '(choice (const :tag "Files" files)
1658 (const :tag "Directory hierarchy" directory)
1659 (const :tag "Project hierarchy" project))
1660 :group 'vhdl-speedbar)
1661
1662 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1663 "*Limits scanning of large files and netlists.
1664 Design units: maximum file size to scan for design units
1665 Hierarchy (instances of subcomponents):
1666 File size: maximum file size to scan for instances (in bytes)
1667 Instances per arch: maximum number of instances to scan per architecture
1668
1669 \"None\" always means that there is no limit.
1670 In case of files not or incompletely scanned, a warning message and the file
1671 names are printed out.
1672 Background: scanning for instances is considerably slower than scanning for
1673 design units, especially when there are many instances. These limits should
1674 prevent the scanning of large netlists."
1675 :type '(list (choice :tag "Design units"
1676 :format "%t : %[Value Menu%] %v"
1677 (const :tag "None" nil)
1678 (integer :tag "File size"))
1679 (list :tag "Hierarchy" :indent 2
1680 (choice :tag "File size"
1681 :format "%t : %[Value Menu%] %v"
1682 (const :tag "None" nil)
1683 (integer :tag "Size "))
1684 (choice :tag "Instances per arch"
1685 (const :tag "None" nil)
1686 (integer :tag "Number "))))
1687 :group 'vhdl-speedbar)
1688
1689 (defcustom vhdl-speedbar-jump-to-unit t
1690 "*Non-nil means jump to the design unit code when opened in a buffer.
1691 The buffer cursor position is left unchanged otherwise."
1692 :type 'boolean
1693 :group 'vhdl-speedbar)
1694
1695 (defcustom vhdl-speedbar-update-on-saving t
1696 "*Automatically update design hierarchy when buffer is saved."
1697 :type 'boolean
1698 :group 'vhdl-speedbar)
1699
1700 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1701 "*Automatically save modified hierarchy caches when exiting Emacs.
1702 Hierarchy: design hierarchy information
1703 Display: displaying information (which design units to expand)"
1704 :type '(set (const :tag "Hierarchy" hierarchy)
1705 (const :tag "Display" display))
1706 :group 'vhdl-speedbar)
1707
1708 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1709 "*Name of file for saving hierarchy cache.
1710 \"\\1\" is replaced by the project name if a project is specified,
1711 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1712 different users to have cache files in the same directory). Can also have
1713 an absolute path (i.e. all caches can be stored in one global directory)."
1714 :type 'string
1715 :group 'vhdl-speedbar)
1716
1717
1718 (defgroup vhdl-menu nil
1719 "Customizations for menues."
1720 :group 'vhdl)
1721
1722 (defcustom vhdl-index-menu nil
1723 "*Non-nil means add an index menu for a source file when loading.
1724 Alternatively, the speedbar can be used. Note that the index menu scans a file
1725 when it is opened, while speedbar only scans the file upon request."
1726 :type 'boolean
1727 :group 'vhdl-menu)
1728
1729 (defcustom vhdl-source-file-menu nil
1730 "*Non-nil means add a menu of all source files in current directory.
1731 Alternatively, the speedbar can be used."
1732 :type 'boolean
1733 :group 'vhdl-menu)
1734
1735 (defcustom vhdl-hideshow-menu nil
1736 "*Non-nil means add hideshow menu and functionality at startup.
1737 Hideshow can also be enabled from the VHDL Mode menu.
1738 Hideshow allows hiding code of various VHDL constructs.
1739
1740 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1741 \"Activate Options\"."
1742 :type 'boolean
1743 :group 'vhdl-menu)
1744
1745 (defcustom vhdl-hide-all-init nil
1746 "*Non-nil means hide all design units initially after a file is loaded."
1747 :type 'boolean
1748 :group 'vhdl-menu)
1749
1750
1751 (defgroup vhdl-print nil
1752 "Customizations for printing."
1753 :group 'vhdl)
1754
1755 (defcustom vhdl-print-two-column t
1756 "*Non-nil means print code in two columns and landscape format.
1757 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1758 prints VHDL files in a nice two-column landscape style.
1759
1760 NOTE: Activate the new setting by restarting Emacs.
1761 Overrides `ps-print' settings locally."
1762 :type 'boolean
1763 :group 'vhdl-print)
1764
1765 (defcustom vhdl-print-customize-faces t
1766 "*Non-nil means use an optimized set of faces for postscript printing.
1767
1768 NOTE: Activate the new setting by restarting Emacs.
1769 Overrides `ps-print' settings locally."
1770 :type 'boolean
1771 :group 'vhdl-print)
1772
1773
1774 (defgroup vhdl-misc nil
1775 "Miscellaneous customizations."
1776 :group 'vhdl)
1777
1778 (defcustom vhdl-intelligent-tab t
1779 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1780 That is, if preceeding character is part of a word then complete word,
1781 else if not at beginning of line then insert tab,
1782 else if last command was a `TAB' or `RET' then dedent one step,
1783 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1784 If nil, TAB always indents current line (i.e. `TAB' is bound to
1785 `indent-according-to-mode').
1786
1787 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1789 :type 'boolean
1790 :group 'vhdl-misc)
1791
1792 (defcustom vhdl-indent-syntax-based t
1793 "*Non-nil means indent lines of code based on their syntactic context.
1794 Otherwise, a line is indented like the previous nonblank line. This can be
1795 useful in large files where syntax-based indentation gets very slow."
1796 :type 'boolean
1797 :group 'vhdl-misc)
1798
1799 (defcustom vhdl-word-completion-case-sensitive nil
1800 "*Non-nil means word completion using `TAB' is case sensitive.
1801 That is, `TAB' completes words that start with the same letters and case.
1802 Otherwise, case is ignored."
1803 :type 'boolean
1804 :group 'vhdl-misc)
1805
1806 (defcustom vhdl-word-completion-in-minibuffer t
1807 "*Non-nil enables word completion in minibuffer (for template prompts).
1808
1809 NOTE: Activate the new setting by restarting Emacs."
1810 :type 'boolean
1811 :group 'vhdl-misc)
1812
1813 (defcustom vhdl-underscore-is-part-of-word nil
1814 "*Non-nil means consider the underscore character `_' as part of word.
1815 An identifier containing underscores is then treated as a single word in
1816 select and move operations. All parts of an identifier separated by underscore
1817 are treated as single words otherwise.
1818
1819 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1820 \"Activate Options\"."
1821 :type 'boolean
1822 :set (lambda (variable value)
1823 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1824 :group 'vhdl-misc)
1825
1826
1827 (defgroup vhdl-related nil
1828 "Related general customizations."
1829 :group 'vhdl)
1830
1831 ;; add related general customizations
1832 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1833 (if (featurep 'xemacs)
1834 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1835 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1836 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1837 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1838 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1839 (unless (featurep 'xemacs)
1840 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1841 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1842 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1843 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1844
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846 ;; Internal variables
1847
1848 (defvar vhdl-menu-max-size 20
1849 "*Specifies the maximum size of a menu before splitting it into submenues.")
1850
1851 (defvar vhdl-progress-interval 1
1852 "*Interval used to update progress status during long operations.
1853 If a number, percentage complete gets updated after each interval of
1854 that many seconds. To inhibit all messages, set this option to nil.")
1855
1856 (defvar vhdl-inhibit-startup-warnings-p nil
1857 "*If non-nil, inhibits start up compatibility warnings.")
1858
1859 (defvar vhdl-strict-syntax-p nil
1860 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1861 If the syntactic symbol for a particular line does not match a symbol
1862 in the offsets alist, an error is generated, otherwise no error is
1863 reported and the syntactic symbol is ignored.")
1864
1865 (defvar vhdl-echo-syntactic-information-p nil
1866 "*If non-nil, syntactic info is echoed when the line is indented.")
1867
1868 (defconst vhdl-offsets-alist-default
1869 '((string . -1000)
1870 (cpp-macro . -1000)
1871 (block-open . 0)
1872 (block-close . 0)
1873 (statement . 0)
1874 (statement-cont . vhdl-lineup-statement-cont)
1875 (statement-block-intro . +)
1876 (statement-case-intro . +)
1877 (case-alternative . +)
1878 (comment . vhdl-lineup-comment)
1879 (arglist-intro . +)
1880 (arglist-cont . 0)
1881 (arglist-cont-nonempty . vhdl-lineup-arglist)
1882 (arglist-close . vhdl-lineup-arglist)
1883 (entity . 0)
1884 (configuration . 0)
1885 (package . 0)
1886 (architecture . 0)
1887 (package-body . 0)
1888 )
1889 "Default settings for offsets of syntactic elements.
1890 Do not change this constant! See the variable `vhdl-offsets-alist' for
1891 more information.")
1892
1893 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1894 "*Association list of syntactic element symbols and indentation offsets.
1895 As described below, each cons cell in this list has the form:
1896
1897 (SYNTACTIC-SYMBOL . OFFSET)
1898
1899 When a line is indented, `vhdl-mode' first determines the syntactic
1900 context of the line by generating a list of symbols called syntactic
1901 elements. This list can contain more than one syntactic element and
1902 the global variable `vhdl-syntactic-context' contains the context list
1903 for the line being indented. Each element in this list is actually a
1904 cons cell of the syntactic symbol and a buffer position. This buffer
1905 position is call the relative indent point for the line. Some
1906 syntactic symbols may not have a relative indent point associated with
1907 them.
1908
1909 After the syntactic context list for a line is generated, `vhdl-mode'
1910 calculates the absolute indentation for the line by looking at each
1911 syntactic element in the list. First, it compares the syntactic
1912 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1913 finds a match, it adds the OFFSET to the column of the relative indent
1914 point. The sum of this calculation for each element in the syntactic
1915 list is the absolute offset for line being indented.
1916
1917 If the syntactic element does not match any in the `vhdl-offsets-alist',
1918 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1919 the element is ignored.
1920
1921 Actually, OFFSET can be an integer, a function, a variable, or one of
1922 the following symbols: `+', `-', `++', or `--'. These latter
1923 designate positive or negative multiples of `vhdl-basic-offset',
1924 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1925 called with a single argument containing the cons of the syntactic
1926 element symbol and the relative indent point. The function should
1927 return an integer offset.
1928
1929 Here is the current list of valid syntactic element symbols:
1930
1931 string -- inside multi-line string
1932 block-open -- statement block open
1933 block-close -- statement block close
1934 statement -- a VHDL statement
1935 statement-cont -- a continuation of a VHDL statement
1936 statement-block-intro -- the first line in a new statement block
1937 statement-case-intro -- the first line in a case alternative block
1938 case-alternative -- a case statement alternative clause
1939 comment -- a line containing only a comment
1940 arglist-intro -- the first line in an argument list
1941 arglist-cont -- subsequent argument list lines when no
1942 arguments follow on the same line as the
1943 the arglist opening paren
1944 arglist-cont-nonempty -- subsequent argument list lines when at
1945 least one argument follows on the same
1946 line as the arglist opening paren
1947 arglist-close -- the solo close paren of an argument list
1948 entity -- inside an entity declaration
1949 configuration -- inside a configuration declaration
1950 package -- inside a package declaration
1951 architecture -- inside an architecture body
1952 package-body -- inside a package body")
1953
1954 (defvar vhdl-comment-only-line-offset 0
1955 "*Extra offset for line which contains only the start of a comment.
1956 Can contain an integer or a cons cell of the form:
1957
1958 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1959
1960 Where NON-ANCHORED-OFFSET is the amount of offset given to
1961 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1962 the amount of offset to give column-zero anchored comment-only lines.
1963 Just an integer as value is equivalent to (<val> . 0)")
1964
1965 (defvar vhdl-special-indent-hook nil
1966 "*Hook for user defined special indentation adjustments.
1967 This hook gets called after a line is indented by the mode.")
1968
1969 (defvar vhdl-style-alist
1970 '(("IEEE"
1971 (vhdl-basic-offset . 4)
1972 (vhdl-offsets-alist . ())))
1973 "Styles of Indentation.
1974 Elements of this alist are of the form:
1975
1976 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1977
1978 where STYLE-STRING is a short descriptive string used to select a
1979 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1980 value for that variable when using the selected style.
1981
1982 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1983 case, the VALUE is a list containing elements of the form:
1984
1985 (SYNTACTIC-SYMBOL . VALUE)
1986
1987 as described in `vhdl-offsets-alist'. These are passed directly to
1988 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1989 your style, only those that are different from the default.")
1990
1991 ;; dynamically append the default value of most variables
1992 (or (assoc "Default" vhdl-style-alist)
1993 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1994 vhdl-strict-syntax-p
1995 vhdl-echo-syntactic-information-p
1996 vhdl-basic-offset
1997 vhdl-offsets-alist
1998 vhdl-comment-only-line-offset))
1999 (default (cons "Default"
2000 (mapcar
2001 (function
2002 (lambda (var)
2003 (cons var (symbol-value var))))
2004 varlist))))
2005 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2006
2007 (defvar vhdl-mode-hook nil
2008 "*Hook called by `vhdl-mode'.")
2009
2010
2011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2012 ;;; Required packages
2013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2014
2015 ;; mandatory
2016 (require 'assoc)
2017 (require 'compile) ; XEmacs
2018 (require 'easymenu)
2019 (require 'hippie-exp)
2020
2021 ;; optional (minimize warning messages during compile)
2022 (eval-when-compile
2023 (require 'font-lock)
2024 (require 'ps-print)
2025 (require 'speedbar))
2026
2027
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029 ;;; Compatibility
2030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2031
2032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033 ;; XEmacs compatibility
2034
2035 ;; active regions
2036 (defun vhdl-keep-region-active ()
2037 "Do whatever is necessary to keep the region active in XEmacs.
2038 Ignore byte-compiler warnings you might see."
2039 (and (featurep 'xemacs)
2040 (setq zmacs-region-stays t)))
2041
2042 ;; `wildcard-to-regexp' is included only in XEmacs 21
2043 (unless (fboundp 'wildcard-to-regexp)
2044 (defun wildcard-to-regexp (wildcard)
2045 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2046 (let* ((i (string-match "[*?]" wildcard))
2047 (result (substring wildcard 0 i))
2048 (len (length wildcard)))
2049 (when i
2050 (while (< i len)
2051 (let ((ch (aref wildcard i)))
2052 (setq result (concat result
2053 (cond ((eq ch ?*) "[^\000]*")
2054 ((eq ch ??) "[^\000]")
2055 (t (char-to-string ch)))))
2056 (setq i (1+ i)))))
2057 (concat "\\`" result "\\'"))))
2058
2059 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2060 ;; `regexp-opt' accelerates fontification by 10-20%
2061 (unless (fboundp 'regexp-opt)
2062 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2063 (defun regexp-opt (strings &optional paren)
2064 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2065 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2066
2067 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2068 (unless (fboundp 'match-string-no-properties)
2069 (defalias 'match-string-no-properties 'match-string))
2070
2071 ;; `subst-char-in-string' undefined (XEmacs)
2072 (unless (fboundp 'subst-char-in-string)
2073 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2074 (let ((i (length string))
2075 (newstr (if inplace string (copy-sequence string))))
2076 (while (> i 0)
2077 (setq i (1- i))
2078 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2079 newstr)))
2080
2081 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2082 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2083 (not noninteractive))
2084 (load "itimer")
2085 (when (string< itimer-version "1.09")
2086 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2087 (beep) (sit-for 5)))
2088
2089 ;; `file-expand-wildcards' undefined (XEmacs)
2090 (unless (fboundp 'file-expand-wildcards)
2091 (defun file-expand-wildcards (pattern &optional full)
2092 "Taken from Emacs' `files.el'."
2093 (let* ((nondir (file-name-nondirectory pattern))
2094 (dirpart (file-name-directory pattern))
2095 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2096 (mapcar 'file-name-as-directory
2097 (file-expand-wildcards (directory-file-name dirpart)))
2098 (list dirpart)))
2099 contents)
2100 (while dirs
2101 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2102 (file-directory-p (directory-file-name (car dirs))))
2103 (let ((this-dir-contents
2104 (delq nil
2105 (mapcar #'(lambda (name)
2106 (unless (string-match "\\`\\.\\.?\\'"
2107 (file-name-nondirectory name))
2108 name))
2109 (directory-files (or (car dirs) ".") full
2110 (wildcard-to-regexp nondir))))))
2111 (setq contents
2112 (nconc
2113 (if (and (car dirs) (not full))
2114 (mapcar (function (lambda (name) (concat (car dirs) name)))
2115 this-dir-contents)
2116 this-dir-contents)
2117 contents))))
2118 (setq dirs (cdr dirs)))
2119 contents)))
2120
2121 ;; `member-ignore-case' undefined (XEmacs)
2122 (unless (fboundp 'member-ignore-case)
2123 (defalias 'member-ignore-case 'member))
2124
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2126 ;; Compatibility with older VHDL Mode versions
2127
2128 (defvar vhdl-warnings nil
2129 "Warnings to tell the user during start up.")
2130
2131 (defun vhdl-run-when-idle (secs repeat function)
2132 "Wait until idle, then run FUNCTION."
2133 (if (fboundp 'start-itimer)
2134 (start-itimer "vhdl-mode" function secs repeat t)
2135 ; (run-with-idle-timer secs repeat function)))
2136 ;; explicitely activate timer (necessary when Emacs is already idle)
2137 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2138
2139 (defun vhdl-warning-when-idle (&rest args)
2140 "Wait until idle, then print out warning STRING and beep."
2141 (if noninteractive
2142 (vhdl-warning (apply 'format args) t)
2143 (unless vhdl-warnings
2144 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2145 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2146
2147 (defun vhdl-warning (string &optional nobeep)
2148 "Print out warning STRING and beep."
2149 (message "WARNING: %s" string)
2150 (unless (or nobeep noninteractive) (beep)))
2151
2152 (defun vhdl-print-warnings ()
2153 "Print out messages in variable `vhdl-warnings'."
2154 (let ((no-warnings (length vhdl-warnings)))
2155 (setq vhdl-warnings (nreverse vhdl-warnings))
2156 (while vhdl-warnings
2157 (message "WARNING: %s" (car vhdl-warnings))
2158 (setq vhdl-warnings (cdr vhdl-warnings)))
2159 (beep)
2160 (when (> no-warnings 1)
2161 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2162
2163 ;; Backward compatibility checks and fixes
2164 ;; option `vhdl-compiler' changed format
2165 (unless (stringp vhdl-compiler)
2166 (setq vhdl-compiler "ModelSim")
2167 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2168
2169 ;; option `vhdl-standard' changed format
2170 (unless (listp vhdl-standard)
2171 (setq vhdl-standard '(87 nil))
2172 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2173
2174 ;; option `vhdl-model-alist' changed format
2175 (when (= (length (car vhdl-model-alist)) 3)
2176 (let ((old-alist vhdl-model-alist)
2177 new-alist)
2178 (while old-alist
2179 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2180 (setq old-alist (cdr old-alist)))
2181 (setq vhdl-model-alist (nreverse new-alist)))
2182 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2183
2184 ;; option `vhdl-project-alist' changed format
2185 (when (= (length (car vhdl-project-alist)) 3)
2186 (let ((old-alist vhdl-project-alist)
2187 new-alist)
2188 (while old-alist
2189 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2190 (setq old-alist (cdr old-alist)))
2191 (setq vhdl-project-alist (nreverse new-alist)))
2192 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2193
2194 ;; option `vhdl-project-alist' changed format (3.31.1)
2195 (when (= (length (car vhdl-project-alist)) 4)
2196 (let ((old-alist vhdl-project-alist)
2197 new-alist elem)
2198 (while old-alist
2199 (setq elem (car old-alist))
2200 (setq new-alist
2201 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2202 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2203 new-alist))
2204 (setq old-alist (cdr old-alist)))
2205 (setq vhdl-project-alist (nreverse new-alist)))
2206 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2207
2208 ;; option `vhdl-project-alist' changed format (3.31.12)
2209 (when (= (length (car vhdl-project-alist)) 10)
2210 (let ((tmp-alist vhdl-project-alist))
2211 (while tmp-alist
2212 (setcdr (nthcdr 3 (car tmp-alist))
2213 (cons "" (nthcdr 4 (car tmp-alist))))
2214 (setq tmp-alist (cdr tmp-alist))))
2215 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2216
2217 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2218 (when (= (length (car vhdl-compiler-alist)) 7)
2219 (let ((old-alist vhdl-compiler-alist)
2220 new-alist elem)
2221 (while old-alist
2222 (setq elem (car old-alist))
2223 (setq new-alist
2224 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2225 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2226 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2227 (nth 5 elem) (nth 6 elem) nil)
2228 new-alist))
2229 (setq old-alist (cdr old-alist)))
2230 (setq vhdl-compiler-alist (nreverse new-alist)))
2231 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2232
2233 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2234 (when (= (length (car vhdl-compiler-alist)) 12)
2235 (let ((tmp-alist vhdl-compiler-alist))
2236 (while tmp-alist
2237 (setcdr (nthcdr 4 (car tmp-alist))
2238 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2239 (setq tmp-alist (cdr tmp-alist))))
2240 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2241
2242 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2243 (when (= (length (car vhdl-compiler-alist)) 13)
2244 (let ((tmp-alist vhdl-compiler-alist))
2245 (while tmp-alist
2246 (setcdr (nthcdr 3 (car tmp-alist))
2247 (cons "" (nthcdr 4 (car tmp-alist))))
2248 (setq tmp-alist (cdr tmp-alist))))
2249 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2250
2251 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2252 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2253 (let ((tmp-alist vhdl-compiler-alist))
2254 (while tmp-alist
2255 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2256 '(0 . nil))
2257 (setq tmp-alist (cdr tmp-alist))))
2258 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2259
2260 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2261 (when (equal vhdl-project "")
2262 (setq vhdl-project nil)
2263 (customize-save-variable 'vhdl-project vhdl-project))
2264
2265 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2266 (when (stringp vhdl-project-file-name)
2267 (setq vhdl-project-file-name (list vhdl-project-file-name))
2268 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2269
2270 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2271 (if (not (boundp 'speedbar-indentation-width))
2272 (defvar speedbar-indentation-width 2)
2273 ;; set default to 2 if not already customized
2274 (unless (get 'speedbar-indentation-width 'saved-value)
2275 (setq speedbar-indentation-width 2)))
2276
2277
2278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279 ;;; Help functions / inline substitutions / macros
2280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2281
2282 (defun vhdl-standard-p (standard)
2283 "Check if STANDARD is specified as used standard."
2284 (or (eq standard (car vhdl-standard))
2285 (memq standard (cadr vhdl-standard))))
2286
2287 (defun vhdl-project-p (&optional warning)
2288 "Return non-nil if a project is displayed, i.e. directories or files are
2289 specified."
2290 (if (assoc vhdl-project vhdl-project-alist)
2291 vhdl-project
2292 (when (and vhdl-project warning)
2293 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2294 nil))
2295
2296 (defun vhdl-resolve-env-variable (string)
2297 "Resolve environment variables in STRING."
2298 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2299 (setq string (concat (match-string 1 string)
2300 (getenv (match-string 2 string))
2301 (match-string 4 string))))
2302 string)
2303
2304 (defun vhdl-default-directory ()
2305 "Return the default directory of the current project or the directory of the
2306 current buffer if no project is defined."
2307 (if (vhdl-project-p)
2308 (expand-file-name (vhdl-resolve-env-variable
2309 (nth 1 (aget vhdl-project-alist vhdl-project))))
2310 default-directory))
2311
2312 (defmacro vhdl-prepare-search-1 (&rest body)
2313 "Enable case insensitive search and switch to syntax table that includes '_',
2314 then execute BODY, and finally restore the old environment. Used for
2315 consistent searching."
2316 `(let ((case-fold-search t)) ; case insensitive search
2317 ;; use extended syntax table
2318 (with-syntax-table vhdl-mode-ext-syntax-table
2319 ,@body)))
2320
2321 (defmacro vhdl-prepare-search-2 (&rest body)
2322 "Enable case insensitive search, switch to syntax table that includes '_',
2323 and remove `intangible' overlays, then execute BODY, and finally restore the
2324 old environment. Used for consistent searching."
2325 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2326 `(let ((case-fold-search t) ; case insensitive search
2327 (current-syntax-table (syntax-table))
2328 overlay-all-list overlay-intangible-list overlay)
2329 ;; use extended syntax table
2330 (set-syntax-table vhdl-mode-ext-syntax-table)
2331 ;; remove `intangible' overlays
2332 (when (fboundp 'overlay-lists)
2333 (setq overlay-all-list (overlay-lists))
2334 (setq overlay-all-list
2335 (append (car overlay-all-list) (cdr overlay-all-list)))
2336 (while overlay-all-list
2337 (setq overlay (car overlay-all-list))
2338 (when (memq 'intangible (overlay-properties overlay))
2339 (setq overlay-intangible-list
2340 (cons overlay overlay-intangible-list))
2341 (overlay-put overlay 'intangible nil))
2342 (setq overlay-all-list (cdr overlay-all-list))))
2343 ;; execute BODY safely
2344 (unwind-protect
2345 (progn ,@body)
2346 ;; restore syntax table
2347 (set-syntax-table current-syntax-table)
2348 ;; restore `intangible' overlays
2349 (when (fboundp 'overlay-lists)
2350 (while overlay-intangible-list
2351 (overlay-put (car overlay-intangible-list) 'intangible t)
2352 (setq overlay-intangible-list
2353 (cdr overlay-intangible-list)))))))
2354
2355 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2356 "Visit file FILE-NAME and execute BODY."
2357 `(if (null ,file-name)
2358 (progn ,@body)
2359 (unless (file-directory-p ,file-name)
2360 (let ((source-buffer (current-buffer))
2361 (visiting-buffer (find-buffer-visiting ,file-name))
2362 file-opened)
2363 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2364 (condition-case ()
2365 (progn (set-buffer (create-file-buffer ,file-name))
2366 (setq file-opened t)
2367 (vhdl-insert-file-contents ,file-name)
2368 (modify-syntax-entry ?\- ". 12" (syntax-table))
2369 (modify-syntax-entry ?\n ">" (syntax-table))
2370 (modify-syntax-entry ?\^M ">" (syntax-table))
2371 (modify-syntax-entry ?_ "w" (syntax-table))
2372 t)
2373 (error
2374 (if ,issue-error
2375 (progn
2376 (when file-opened (kill-buffer (current-buffer)))
2377 (set-buffer source-buffer)
2378 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2379 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2380 nil))))
2381 (condition-case info
2382 (progn ,@body)
2383 (error
2384 (if ,issue-error
2385 (progn
2386 (when file-opened (kill-buffer (current-buffer)))
2387 (set-buffer source-buffer)
2388 (error (cadr info)))
2389 (vhdl-warning (cadr info))))))
2390 (when file-opened (kill-buffer (current-buffer)))
2391 (set-buffer source-buffer)))))
2392
2393 (defun vhdl-insert-file-contents (filename)
2394 "Nicked from `insert-file-contents-literally', but allow coding system
2395 conversion."
2396 (let ((format-alist nil)
2397 (after-insert-file-functions nil)
2398 (jka-compr-compression-info-list nil))
2399 (insert-file-contents filename t)))
2400
2401 (defun vhdl-sort-alist (alist)
2402 "Sort ALIST."
2403 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2404
2405 (defun vhdl-get-subdirs (directory)
2406 "Recursively get subdirectories of DIRECTORY."
2407 (let ((dir-list (list (file-name-as-directory directory)))
2408 file-list)
2409 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2410 (while file-list
2411 (when (file-directory-p (car file-list))
2412 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2413 (setq file-list (cdr file-list)))
2414 dir-list))
2415
2416 (defun vhdl-aput (alist-symbol key &optional value)
2417 "As `aput', but delete key-value pair if VALUE is nil."
2418 (if value
2419 (aput alist-symbol key value)
2420 (adelete alist-symbol key)))
2421
2422 (defun vhdl-delete (elt list)
2423 "Delete by side effect the first occurrence of ELT as a member of LIST."
2424 (setq list (cons nil list))
2425 (let ((list1 list))
2426 (while (and (cdr list1) (not (equal elt (cadr list1))))
2427 (setq list1 (cdr list1)))
2428 (when list
2429 (setcdr list1 (cddr list1))))
2430 (cdr list))
2431
2432 (defun vhdl-speedbar-refresh (&optional key)
2433 "Refresh directory or project with name KEY."
2434 (when (and (boundp 'speedbar-frame)
2435 (frame-live-p speedbar-frame))
2436 (let ((pos (point))
2437 (last-frame (selected-frame)))
2438 (if (null key)
2439 (speedbar-refresh)
2440 (select-frame speedbar-frame)
2441 (when (save-excursion
2442 (goto-char (point-min))
2443 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2444 (goto-char (match-end 1))
2445 (speedbar-do-function-pointer)
2446 (backward-char 2)
2447 (speedbar-do-function-pointer)
2448 (message "Refreshing speedbar...done"))
2449 (select-frame last-frame)))))
2450
2451 (defun vhdl-show-messages ()
2452 "Get *Messages* buffer to show recent messages."
2453 (interactive)
2454 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2455
2456 (defun vhdl-use-direct-instantiation ()
2457 "Return whether direct instantiation is used."
2458 (or (eq vhdl-use-direct-instantiation 'always)
2459 (and (eq vhdl-use-direct-instantiation 'standard)
2460 (not (vhdl-standard-p '87)))))
2461
2462 (defun vhdl-max-marker (marker1 marker2)
2463 "Return larger marker."
2464 (if (> marker1 marker2) marker1 marker2))
2465
2466 (defun vhdl-goto-marker (marker)
2467 "Goto marker in appropriate buffer."
2468 (when (markerp marker)
2469 (set-buffer (marker-buffer marker)))
2470 (goto-char marker))
2471
2472 (defun vhdl-menu-split (list title)
2473 "Split menu LIST into several submenues, if number of
2474 elements > `vhdl-menu-max-size'."
2475 (if (> (length list) vhdl-menu-max-size)
2476 (let ((remain list)
2477 (result '())
2478 (sublist '())
2479 (menuno 1)
2480 (i 0))
2481 (while remain
2482 (setq sublist (cons (car remain) sublist))
2483 (setq remain (cdr remain))
2484 (setq i (+ i 1))
2485 (if (= i vhdl-menu-max-size)
2486 (progn
2487 (setq result (cons (cons (format "%s %s" title menuno)
2488 (nreverse sublist)) result))
2489 (setq i 0)
2490 (setq menuno (+ menuno 1))
2491 (setq sublist '()))))
2492 (and sublist
2493 (setq result (cons (cons (format "%s %s" title menuno)
2494 (nreverse sublist)) result)))
2495 (nreverse result))
2496 list))
2497
2498
2499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2500 ;;; Bindings
2501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2502
2503 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2504 ;; Key bindings
2505
2506 (defvar vhdl-template-map nil
2507 "Keymap for VHDL templates.")
2508
2509 (defun vhdl-template-map-init ()
2510 "Initialize `vhdl-template-map'."
2511 (setq vhdl-template-map (make-sparse-keymap))
2512 ;; key bindings for VHDL templates
2513 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2514 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2515 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2516 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2517 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2518 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2519 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2520 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2521 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2522 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2523 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2524 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2525 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2526 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2527 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2528 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2529 (define-key vhdl-template-map "el" 'vhdl-template-else)
2530 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2531 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2532 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2533 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2534 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2535 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2536 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2537 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2538 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2539 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2540 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2541 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2542 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2543 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2544 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2545 (define-key vhdl-template-map "li" 'vhdl-template-library)
2546 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2547 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2548 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2549 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2550 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2551 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2552 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2553 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2554 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2555 (define-key vhdl-template-map "po" 'vhdl-template-port)
2556 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2557 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2558 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2559 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2560 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2561 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2562 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2563 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2564 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2565 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2566 (define-key vhdl-template-map "us" 'vhdl-template-use)
2567 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2568 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2569 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2570 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2571 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2572 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2573 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2574 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2575 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2576 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2577 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2578 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2579 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2580 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2581 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2582 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2583 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2584 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2585 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2586 (when (vhdl-standard-p 'ams)
2587 (define-key vhdl-template-map "br" 'vhdl-template-break)
2588 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2589 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2590 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2591 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2592 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2593 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2594 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2595 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2596 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2597 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2598 )
2599 (when (vhdl-standard-p 'math)
2600 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2601 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2602 ))
2603
2604 ;; initialize template map for VHDL Mode
2605 (vhdl-template-map-init)
2606
2607 (defun vhdl-function-name (prefix string &optional postfix)
2608 "Generate a Lisp function name.
2609 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2610 STRING are replaced by `-' and substrings are converted to lower case."
2611 (let ((name prefix))
2612 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2613 (setq name
2614 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2615 (setq string (substring string (match-beginning 2))))
2616 (when postfix (setq name (concat name "-" postfix)))
2617 (intern name)))
2618
2619 (defvar vhdl-model-map nil
2620 "Keymap for VHDL models.")
2621
2622 (defun vhdl-model-map-init ()
2623 "Initialize `vhdl-model-map'."
2624 (setq vhdl-model-map (make-sparse-keymap))
2625 ;; key bindings for VHDL models
2626 (let ((model-alist vhdl-model-alist) model)
2627 (while model-alist
2628 (setq model (car model-alist))
2629 (define-key vhdl-model-map (nth 2 model)
2630 (vhdl-function-name "vhdl-model" (nth 0 model)))
2631 (setq model-alist (cdr model-alist)))))
2632
2633 ;; initialize user model map for VHDL Mode
2634 (vhdl-model-map-init)
2635
2636 (defvar vhdl-mode-map nil
2637 "Keymap for VHDL Mode.")
2638
2639 (defun vhdl-mode-map-init ()
2640 "Initialize `vhdl-mode-map'."
2641 (setq vhdl-mode-map (make-sparse-keymap))
2642 ;; template key bindings
2643 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2644 ;; model key bindings
2645 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2646 ;; standard key bindings
2647 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2648 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2649 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2650 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2651 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2652 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2653 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2654 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2655 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2656 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2657 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2658 ;; backspace/delete key bindings
2659 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2660 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2661 (define-key vhdl-mode-map [delete] 'delete-char)
2662 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2663 ;; mode specific key bindings
2664 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2665 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2666 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2668 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2669 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2670 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2671 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2672 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2673 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2674 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2675 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2678 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2679 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2680 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2681 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2682 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2684 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2685 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2686 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2687 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2688 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2689 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2692 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2693 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2694 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2698 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2699 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2700 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2701 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2702 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2703 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2704 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2705 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2709 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2710 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2711 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2712 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2713 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2714 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2717 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2718 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2719 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2720 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2721 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2722 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2723 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2727 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2728 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2729 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2730 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2731 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2732 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2733 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2734 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2735 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2736 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2737 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2740 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2741 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2742 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2743 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2744 ;; insert commands bindings
2745 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2746 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2747 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2748 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2749 ;; electric key bindings
2750 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2751 (when vhdl-intelligent-tab
2752 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2753 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2754 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2755 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2756 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2757 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2758 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2759 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2760 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2761 (when (vhdl-standard-p 'ams)
2762 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2763
2764 ;; initialize mode map for VHDL Mode
2765 (vhdl-mode-map-init)
2766
2767 ;; define special minibuffer keymap for enabling word completion in minibuffer
2768 ;; (useful in template generator prompts)
2769 (defvar vhdl-minibuffer-local-map
2770 (let ((map (make-sparse-keymap)))
2771 (set-keymap-parent map minibuffer-local-map)
2772 (when vhdl-word-completion-in-minibuffer
2773 (define-key map "\t" 'vhdl-minibuffer-tab))
2774 map)
2775 "Keymap for minibuffer used in VHDL Mode.")
2776
2777 ;; set up electric character functions to work with
2778 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2779 (mapc
2780 (function
2781 (lambda (sym)
2782 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2783 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2784 '(vhdl-electric-space
2785 vhdl-electric-tab
2786 vhdl-electric-return
2787 vhdl-electric-dash
2788 vhdl-electric-open-bracket
2789 vhdl-electric-close-bracket
2790 vhdl-electric-quote
2791 vhdl-electric-semicolon
2792 vhdl-electric-comma
2793 vhdl-electric-period
2794 vhdl-electric-equal))
2795
2796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2797 ;; Syntax table
2798
2799 (defvar vhdl-mode-syntax-table nil
2800 "Syntax table used in `vhdl-mode' buffers.")
2801
2802 (defvar vhdl-mode-ext-syntax-table nil
2803 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2804
2805 (defun vhdl-mode-syntax-table-init ()
2806 "Initialize `vhdl-mode-syntax-table'."
2807 (setq vhdl-mode-syntax-table (make-syntax-table))
2808 ;; define punctuation
2809 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2810 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2811 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2812 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2813 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2814 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2815 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2816 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2817 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2818 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2819 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2820 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2821 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2822 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2823 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2824 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2825 ;; define string
2826 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2827 ;; define underscore
2828 (when vhdl-underscore-is-part-of-word
2829 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2830 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2831 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2832 ;; and \n and \^M end a comment
2833 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2835 ;; define parentheses to match
2836 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2839 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2840 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2841 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2842 ;; extended syntax table including '_' (for simpler search regexps)
2843 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2844 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2845
2846 ;; initialize syntax table for VHDL Mode
2847 (vhdl-mode-syntax-table-init)
2848
2849 (defvar vhdl-syntactic-context nil
2850 "Buffer local variable containing syntactic analysis list.")
2851 (make-variable-buffer-local 'vhdl-syntactic-context)
2852
2853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2854 ;; Abbrev ook bindings
2855
2856 (defvar vhdl-mode-abbrev-table nil
2857 "Abbrev table to use in `vhdl-mode' buffers.")
2858
2859 (defun vhdl-mode-abbrev-table-init ()
2860 "Initialize `vhdl-mode-abbrev-table'."
2861 (define-abbrev-table 'vhdl-mode-abbrev-table
2862 (append
2863 (when (memq 'vhdl vhdl-electric-keywords)
2864 ;; VHDL'93 keywords
2865 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2866 '(
2867 ("--" . vhdl-template-display-comment-hook)
2868 ("abs" . vhdl-template-default-hook)
2869 ("access" . vhdl-template-default-hook)
2870 ("after" . vhdl-template-default-hook)
2871 ("alias" . vhdl-template-alias-hook)
2872 ("all" . vhdl-template-default-hook)
2873 ("and" . vhdl-template-default-hook)
2874 ("arch" . vhdl-template-architecture-hook)
2875 ("architecture" . vhdl-template-architecture-hook)
2876 ("array" . vhdl-template-default-hook)
2877 ("assert" . vhdl-template-assert-hook)
2878 ("attr" . vhdl-template-attribute-hook)
2879 ("attribute" . vhdl-template-attribute-hook)
2880 ("begin" . vhdl-template-default-indent-hook)
2881 ("block" . vhdl-template-block-hook)
2882 ("body" . vhdl-template-default-hook)
2883 ("buffer" . vhdl-template-default-hook)
2884 ("bus" . vhdl-template-default-hook)
2885 ("case" . vhdl-template-case-hook)
2886 ("comp" . vhdl-template-component-hook)
2887 ("component" . vhdl-template-component-hook)
2888 ("cond" . vhdl-template-conditional-signal-asst-hook)
2889 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2890 ("conf" . vhdl-template-configuration-hook)
2891 ("configuration" . vhdl-template-configuration-hook)
2892 ("cons" . vhdl-template-constant-hook)
2893 ("constant" . vhdl-template-constant-hook)
2894 ("disconnect" . vhdl-template-disconnect-hook)
2895 ("downto" . vhdl-template-default-hook)
2896 ("else" . vhdl-template-else-hook)
2897 ("elseif" . vhdl-template-elsif-hook)
2898 ("elsif" . vhdl-template-elsif-hook)
2899 ("end" . vhdl-template-default-indent-hook)
2900 ("entity" . vhdl-template-entity-hook)
2901 ("exit" . vhdl-template-exit-hook)
2902 ("file" . vhdl-template-file-hook)
2903 ("for" . vhdl-template-for-hook)
2904 ("func" . vhdl-template-function-hook)
2905 ("function" . vhdl-template-function-hook)
2906 ("generic" . vhdl-template-generic-hook)
2907 ("group" . vhdl-template-group-hook)
2908 ("guarded" . vhdl-template-default-hook)
2909 ("if" . vhdl-template-if-hook)
2910 ("impure" . vhdl-template-default-hook)
2911 ("in" . vhdl-template-default-hook)
2912 ("inertial" . vhdl-template-default-hook)
2913 ("inout" . vhdl-template-default-hook)
2914 ("inst" . vhdl-template-instance-hook)
2915 ("instance" . vhdl-template-instance-hook)
2916 ("is" . vhdl-template-default-hook)
2917 ("label" . vhdl-template-default-hook)
2918 ("library" . vhdl-template-library-hook)
2919 ("linkage" . vhdl-template-default-hook)
2920 ("literal" . vhdl-template-default-hook)
2921 ("loop" . vhdl-template-bare-loop-hook)
2922 ("map" . vhdl-template-map-hook)
2923 ("mod" . vhdl-template-default-hook)
2924 ("nand" . vhdl-template-default-hook)
2925 ("new" . vhdl-template-default-hook)
2926 ("next" . vhdl-template-next-hook)
2927 ("nor" . vhdl-template-default-hook)
2928 ("not" . vhdl-template-default-hook)
2929 ("null" . vhdl-template-default-hook)
2930 ("of" . vhdl-template-default-hook)
2931 ("on" . vhdl-template-default-hook)
2932 ("open" . vhdl-template-default-hook)
2933 ("or" . vhdl-template-default-hook)
2934 ("others" . vhdl-template-others-hook)
2935 ("out" . vhdl-template-default-hook)
2936 ("pack" . vhdl-template-package-hook)
2937 ("package" . vhdl-template-package-hook)
2938 ("port" . vhdl-template-port-hook)
2939 ("postponed" . vhdl-template-default-hook)
2940 ("procedure" . vhdl-template-procedure-hook)
2941 ("process" . vhdl-template-process-hook)
2942 ("pure" . vhdl-template-default-hook)
2943 ("range" . vhdl-template-default-hook)
2944 ("record" . vhdl-template-default-hook)
2945 ("register" . vhdl-template-default-hook)
2946 ("reject" . vhdl-template-default-hook)
2947 ("rem" . vhdl-template-default-hook)
2948 ("report" . vhdl-template-report-hook)
2949 ("return" . vhdl-template-return-hook)
2950 ("rol" . vhdl-template-default-hook)
2951 ("ror" . vhdl-template-default-hook)
2952 ("select" . vhdl-template-selected-signal-asst-hook)
2953 ("severity" . vhdl-template-default-hook)
2954 ("shared" . vhdl-template-default-hook)
2955 ("sig" . vhdl-template-signal-hook)
2956 ("signal" . vhdl-template-signal-hook)
2957 ("sla" . vhdl-template-default-hook)
2958 ("sll" . vhdl-template-default-hook)
2959 ("sra" . vhdl-template-default-hook)
2960 ("srl" . vhdl-template-default-hook)
2961 ("subtype" . vhdl-template-subtype-hook)
2962 ("then" . vhdl-template-default-hook)
2963 ("to" . vhdl-template-default-hook)
2964 ("transport" . vhdl-template-default-hook)
2965 ("type" . vhdl-template-type-hook)
2966 ("unaffected" . vhdl-template-default-hook)
2967 ("units" . vhdl-template-default-hook)
2968 ("until" . vhdl-template-default-hook)
2969 ("use" . vhdl-template-use-hook)
2970 ("var" . vhdl-template-variable-hook)
2971 ("variable" . vhdl-template-variable-hook)
2972 ("wait" . vhdl-template-wait-hook)
2973 ("when" . vhdl-template-when-hook)
2974 ("while" . vhdl-template-while-loop-hook)
2975 ("with" . vhdl-template-with-hook)
2976 ("xnor" . vhdl-template-default-hook)
2977 ("xor" . vhdl-template-default-hook)
2978 )))
2979 ;; VHDL-AMS keywords
2980 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2981 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2982 '(
2983 ("across" . vhdl-template-default-hook)
2984 ("break" . vhdl-template-break-hook)
2985 ("limit" . vhdl-template-limit-hook)
2986 ("nature" . vhdl-template-nature-hook)
2987 ("noise" . vhdl-template-default-hook)
2988 ("procedural" . vhdl-template-procedural-hook)
2989 ("quantity" . vhdl-template-quantity-hook)
2990 ("reference" . vhdl-template-default-hook)
2991 ("spectrum" . vhdl-template-default-hook)
2992 ("subnature" . vhdl-template-subnature-hook)
2993 ("terminal" . vhdl-template-terminal-hook)
2994 ("through" . vhdl-template-default-hook)
2995 ("tolerance" . vhdl-template-default-hook)
2996 )))
2997 ;; user model keywords
2998 (when (memq 'user vhdl-electric-keywords)
2999 (let (abbrev-list keyword)
3000 (dolist (elem vhdl-model-alist)
3001 (setq keyword (nth 3 elem))
3002 (unless (equal keyword "")
3003 (push (list keyword ""
3004 (vhdl-function-name
3005 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3006 abbrev-list)))
3007 abbrev-list)))))
3008
3009 ;; initialize abbrev table for VHDL Mode
3010 (vhdl-mode-abbrev-table-init)
3011
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013 ;; Template completion lists
3014
3015 (defvar vhdl-template-construct-alist nil
3016 "List of built-in construct templates.")
3017
3018 (defun vhdl-template-construct-alist-init ()
3019 "Initialize `vhdl-template-construct-alist'."
3020 (setq
3021 vhdl-template-construct-alist
3022 (append
3023 '(
3024 ("alias declaration" vhdl-template-alias)
3025 ("architecture body" vhdl-template-architecture)
3026 ("assertion" vhdl-template-assert)
3027 ("attribute declaration" vhdl-template-attribute-decl)
3028 ("attribute specification" vhdl-template-attribute-spec)
3029 ("block configuration" vhdl-template-block-configuration)
3030 ("block statement" vhdl-template-block)
3031 ("case statement" vhdl-template-case-is)
3032 ("component configuration" vhdl-template-component-conf)
3033 ("component declaration" vhdl-template-component-decl)
3034 ("component instantiation statement" vhdl-template-component-inst)
3035 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3036 ("configuration declaration" vhdl-template-configuration-decl)
3037 ("configuration specification" vhdl-template-configuration-spec)
3038 ("constant declaration" vhdl-template-constant)
3039 ("disconnection specification" vhdl-template-disconnect)
3040 ("entity declaration" vhdl-template-entity)
3041 ("exit statement" vhdl-template-exit)
3042 ("file declaration" vhdl-template-file)
3043 ("generate statement" vhdl-template-generate)
3044 ("generic clause" vhdl-template-generic)
3045 ("group declaration" vhdl-template-group-decl)
3046 ("group template declaration" vhdl-template-group-template)
3047 ("if statement" vhdl-template-if-then)
3048 ("library clause" vhdl-template-library)
3049 ("loop statement" vhdl-template-loop)
3050 ("next statement" vhdl-template-next)
3051 ("package declaration" vhdl-template-package-decl)
3052 ("package body" vhdl-template-package-body)
3053 ("port clause" vhdl-template-port)
3054 ("process statement" vhdl-template-process)
3055 ("report statement" vhdl-template-report)
3056 ("return statement" vhdl-template-return)
3057 ("selected signal assignment" vhdl-template-selected-signal-asst)
3058 ("signal declaration" vhdl-template-signal)
3059 ("subprogram declaration" vhdl-template-subprogram-decl)
3060 ("subprogram body" vhdl-template-subprogram-body)
3061 ("subtype declaration" vhdl-template-subtype)
3062 ("type declaration" vhdl-template-type)
3063 ("use clause" vhdl-template-use)
3064 ("variable declaration" vhdl-template-variable)
3065 ("wait statement" vhdl-template-wait)
3066 )
3067 (when (vhdl-standard-p 'ams)
3068 '(
3069 ("break statement" vhdl-template-break)
3070 ("nature declaration" vhdl-template-nature)
3071 ("quantity declaration" vhdl-template-quantity)
3072 ("simultaneous case statement" vhdl-template-case-use)
3073 ("simultaneous if statement" vhdl-template-if-use)
3074 ("simultaneous procedural statement" vhdl-template-procedural)
3075 ("step limit specification" vhdl-template-limit)
3076 ("subnature declaration" vhdl-template-subnature)
3077 ("terminal declaration" vhdl-template-terminal)
3078 )))))
3079
3080 ;; initialize for VHDL Mode
3081 (vhdl-template-construct-alist-init)
3082
3083 (defvar vhdl-template-package-alist nil
3084 "List of built-in package templates.")
3085
3086 (defun vhdl-template-package-alist-init ()
3087 "Initialize `vhdl-template-package-alist'."
3088 (setq
3089 vhdl-template-package-alist
3090 (append
3091 '(
3092 ("numeric_bit" vhdl-template-package-numeric-bit)
3093 ("numeric_std" vhdl-template-package-numeric-std)
3094 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3095 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3096 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3097 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3098 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3099 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3100 ("textio" vhdl-template-package-textio)
3101 )
3102 (when (vhdl-standard-p 'math)
3103 '(
3104 ("math_complex" vhdl-template-package-math-complex)
3105 ("math_real" vhdl-template-package-math-real)
3106 )))))
3107
3108 ;; initialize for VHDL Mode
3109 (vhdl-template-package-alist-init)
3110
3111 (defvar vhdl-template-directive-alist
3112 '(
3113 ("translate_on" vhdl-template-directive-translate-on)
3114 ("translate_off" vhdl-template-directive-translate-off)
3115 ("synthesis_on" vhdl-template-directive-synthesis-on)
3116 ("synthesis_off" vhdl-template-directive-synthesis-off)
3117 )
3118 "List of built-in directive templates.")
3119
3120
3121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3122 ;;; Menues
3123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3124
3125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3126 ;; VHDL menu (using `easy-menu.el')
3127
3128 (defun vhdl-customize ()
3129 "Call the customize function with `vhdl' as argument."
3130 (interactive)
3131 (customize-browse 'vhdl))
3132
3133 (defun vhdl-create-mode-menu ()
3134 "Create VHDL Mode menu."
3135 `("VHDL"
3136 ,(append
3137 '("Project"
3138 ["None" (vhdl-set-project "")
3139 :style radio :selected (null vhdl-project)]
3140 "--")
3141 ;; add menu entries for defined projects
3142 (let ((project-alist vhdl-project-alist) menu-list name)
3143 (while project-alist
3144 (setq name (caar project-alist))
3145 (setq menu-list
3146 (cons `[,name (vhdl-set-project ,name)
3147 :style radio :selected (equal ,name vhdl-project)]
3148 menu-list))
3149 (setq project-alist (cdr project-alist)))
3150 (setq menu-list
3151 (if vhdl-project-sort
3152 (sort menu-list
3153 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3154 (nreverse menu-list)))
3155 (vhdl-menu-split menu-list "Project"))
3156 '("--" "--"
3157 ["Select Project..." vhdl-set-project t]
3158 ["Set As Default Project" vhdl-set-default-project t]
3159 "--"
3160 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3161 ["Import Project..." vhdl-import-project
3162 :keys "C-c C-p C-m" :active t]
3163 ["Export Project" vhdl-export-project vhdl-project]
3164 "--"
3165 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3166 "--"
3167 ("Compile"
3168 ["Compile Buffer" vhdl-compile t]
3169 ["Stop Compilation" kill-compilation t]
3170 "--"
3171 ["Make" vhdl-make t]
3172 ["Generate Makefile" vhdl-generate-makefile t]
3173 "--"
3174 ["Next Error" next-error t]
3175 ["Previous Error" previous-error t]
3176 ["First Error" first-error t]
3177 "--"
3178 ,(append
3179 '("Compiler")
3180 ;; add menu entries for defined compilers
3181 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3182 (while comp-alist
3183 (setq name (caar comp-alist))
3184 (setq menu-list
3185 (cons `[,name (setq vhdl-compiler ,name)
3186 :style radio :selected (equal ,name vhdl-compiler)]
3187 menu-list))
3188 (setq comp-alist (cdr comp-alist)))
3189 (setq menu-list (nreverse menu-list))
3190 (vhdl-menu-split menu-list "Compiler"))
3191 '("--" "--"
3192 ["Select Compiler..." vhdl-set-compiler t]
3193 "--"
3194 ["Customize Compiler..."
3195 (customize-option 'vhdl-compiler-alist) t])))
3196 "--"
3197 ,(append
3198 '("Template"
3199 ("VHDL Construct 1"
3200 ["Alias" vhdl-template-alias t]
3201 ["Architecture" vhdl-template-architecture t]
3202 ["Assert" vhdl-template-assert t]
3203 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3204 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3205 ["Block" vhdl-template-block t]
3206 ["Case" vhdl-template-case-is t]
3207 ["Component (Decl)" vhdl-template-component-decl t]
3208 ["(Component) Instance" vhdl-template-component-inst t]
3209 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3210 ["Configuration (Block)" vhdl-template-block-configuration t]
3211 ["Configuration (Comp)" vhdl-template-component-conf t]
3212 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3213 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3214 ["Constant" vhdl-template-constant t]
3215 ["Disconnect" vhdl-template-disconnect t]
3216 ["Else" vhdl-template-else t]
3217 ["Elsif" vhdl-template-elsif t]
3218 ["Entity" vhdl-template-entity t]
3219 ["Exit" vhdl-template-exit t]
3220 ["File" vhdl-template-file t]
3221 ["For (Generate)" vhdl-template-for-generate t]
3222 ["For (Loop)" vhdl-template-for-loop t]
3223 ["Function (Body)" vhdl-template-function-body t]
3224 ["Function (Decl)" vhdl-template-function-decl t]
3225 ["Generic" vhdl-template-generic t]
3226 ["Group (Decl)" vhdl-template-group-decl t]
3227 ["Group (Template)" vhdl-template-group-template t])
3228 ("VHDL Construct 2"
3229 ["If (Generate)" vhdl-template-if-generate t]
3230 ["If (Then)" vhdl-template-if-then t]
3231 ["Library" vhdl-template-library t]
3232 ["Loop" vhdl-template-bare-loop t]
3233 ["Map" vhdl-template-map t]
3234 ["Next" vhdl-template-next t]
3235 ["Others (Aggregate)" vhdl-template-others t]
3236 ["Package (Decl)" vhdl-template-package-decl t]
3237 ["Package (Body)" vhdl-template-package-body t]
3238 ["Port" vhdl-template-port t]
3239 ["Procedure (Body)" vhdl-template-procedure-body t]
3240 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3241 ["Process (Comb)" vhdl-template-process-comb t]
3242 ["Process (Seq)" vhdl-template-process-seq t]
3243 ["Report" vhdl-template-report t]
3244 ["Return" vhdl-template-return t]
3245 ["Select" vhdl-template-selected-signal-asst t]
3246 ["Signal" vhdl-template-signal t]
3247 ["Subtype" vhdl-template-subtype t]
3248 ["Type" vhdl-template-type t]
3249 ["Use" vhdl-template-use t]
3250 ["Variable" vhdl-template-variable t]
3251 ["Wait" vhdl-template-wait t]
3252 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3253 ["When" vhdl-template-when t]
3254 ["While (Loop)" vhdl-template-while-loop t]
3255 ["With" vhdl-template-with t]))
3256 (when (vhdl-standard-p 'ams)
3257 '(("VHDL-AMS Construct"
3258 ["Break" vhdl-template-break t]
3259 ["Case (Use)" vhdl-template-case-use t]
3260 ["If (Use)" vhdl-template-if-use t]
3261 ["Limit" vhdl-template-limit t]
3262 ["Nature" vhdl-template-nature t]
3263 ["Procedural" vhdl-template-procedural t]
3264 ["Quantity (Free)" vhdl-template-quantity-free t]
3265 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3266 ["Quantity (Source)" vhdl-template-quantity-source t]
3267 ["Subnature" vhdl-template-subnature t]
3268 ["Terminal" vhdl-template-terminal t])))
3269 '(["Insert Construct..." vhdl-template-insert-construct
3270 :keys "C-c C-i C-t"]
3271 "--")
3272 (list
3273 (append
3274 '("Package")
3275 (when (vhdl-standard-p 'math)
3276 '(["math_complex" vhdl-template-package-math-complex t]
3277 ["math_real" vhdl-template-package-math-real t]))
3278 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3279 ["numeric_std" vhdl-template-package-numeric-std t]
3280 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3281 ["textio" vhdl-template-package-textio t]
3282 "--"
3283 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3284 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3285 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3286 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3287 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3288 "--"
3289 ["Insert Package..." vhdl-template-insert-package
3290 :keys "C-c C-i C-p"])))
3291 '(("Directive"
3292 ["translate_on" vhdl-template-directive-translate-on t]
3293 ["translate_off" vhdl-template-directive-translate-off t]
3294 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3295 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3296 "--"
3297 ["Insert Directive..." vhdl-template-insert-directive
3298 :keys "C-c C-i C-d"])
3299 "--"
3300 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3301 ["Insert Footer" vhdl-template-footer t]
3302 ["Insert Date" vhdl-template-insert-date t]
3303 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3304 "--"
3305 ["Query Next Prompt" vhdl-template-search-prompt t]))
3306 ,(append
3307 '("Model")
3308 ;; add menu entries for defined models
3309 (let ((model-alist vhdl-model-alist) menu-list model)
3310 (while model-alist
3311 (setq model (car model-alist))
3312 (setq menu-list
3313 (cons
3314 (vector
3315 (nth 0 model)
3316 (vhdl-function-name "vhdl-model" (nth 0 model))
3317 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3318 menu-list))
3319 (setq model-alist (cdr model-alist)))
3320 (setq menu-list (nreverse menu-list))
3321 (vhdl-menu-split menu-list "Model"))
3322 '("--" "--"
3323 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3324 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3325 ("Port"
3326 ["Copy" vhdl-port-copy t]
3327 "--"
3328 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3329 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3330 ["Paste As Instance" vhdl-port-paste-instance
3331 :keys "C-c C-p C-i" :active vhdl-port-list]
3332 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3333 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3334 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3335 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3336 "--"
3337 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3338 "--"
3339 ["Flatten" vhdl-port-flatten
3340 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3341 ["Reverse Direction" vhdl-port-reverse-direction
3342 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3343 ("Compose"
3344 ["New Component" vhdl-compose-new-component t]
3345 ["Copy Component" vhdl-port-copy t]
3346 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3347 ["Wire Components" vhdl-compose-wire-components t]
3348 "--"
3349 ["Generate Configuration" vhdl-compose-configuration t]
3350 ["Generate Components Package" vhdl-compose-components-package t])
3351 ("Subprogram"
3352 ["Copy" vhdl-subprog-copy t]
3353 "--"
3354 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3355 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3356 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3357 "--"
3358 ["Flatten" vhdl-subprog-flatten
3359 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3360 "--"
3361 ("Comment"
3362 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3363 "--"
3364 ["Insert Inline Comment" vhdl-comment-append-inline t]
3365 ["Insert Horizontal Line" vhdl-comment-display-line t]
3366 ["Insert Display Comment" vhdl-comment-display t]
3367 "--"
3368 ["Fill Comment" fill-paragraph t]
3369 ["Fill Comment Region" fill-region (mark)]
3370 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3371 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3372 ("Line"
3373 ["Kill" vhdl-line-kill t]
3374 ["Copy" vhdl-line-copy t]
3375 ["Yank" vhdl-line-yank t]
3376 ["Expand" vhdl-line-expand t]
3377 "--"
3378 ["Transpose Next" vhdl-line-transpose-next t]
3379 ["Transpose Prev" vhdl-line-transpose-previous t]
3380 ["Open" vhdl-line-open t]
3381 ["Join" vhdl-delete-indentation t]
3382 "--"
3383 ["Goto" goto-line t]
3384 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3385 ("Move"
3386 ["Forward Statement" vhdl-end-of-statement t]
3387 ["Backward Statement" vhdl-beginning-of-statement t]
3388 ["Forward Expression" vhdl-forward-sexp t]
3389 ["Backward Expression" vhdl-backward-sexp t]
3390 ["Forward Same Indent" vhdl-forward-same-indent t]
3391 ["Backward Same Indent" vhdl-backward-same-indent t]
3392 ["Forward Function" vhdl-end-of-defun t]
3393 ["Backward Function" vhdl-beginning-of-defun t]
3394 ["Mark Function" vhdl-mark-defun t])
3395 "--"
3396 ("Indent"
3397 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3398 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3399 ["Region" vhdl-indent-region (mark)]
3400 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3401 ("Align"
3402 ["Group" vhdl-align-group t]
3403 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3404 ["List" vhdl-align-list t]
3405 ["Declarations" vhdl-align-declarations t]
3406 ["Region" vhdl-align-region (mark)]
3407 ["Buffer" vhdl-align-buffer t]
3408 "--"
3409 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3410 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3411 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3412 ("Fill"
3413 ["List" vhdl-fill-list t]
3414 ["Group" vhdl-fill-group t]
3415 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3416 ["Region" vhdl-fill-region (mark)])
3417 ("Beautify"
3418 ["Region" vhdl-beautify-region (mark)]
3419 ["Buffer" vhdl-beautify-buffer t])
3420 ("Fix"
3421 ["Generic/Port Clause" vhdl-fix-clause t]
3422 "--"
3423 ["Case Region" vhdl-fix-case-region (mark)]
3424 ["Case Buffer" vhdl-fix-case-buffer t]
3425 "--"
3426 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3427 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3428 "--"
3429 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3430 ("Update"
3431 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3432 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3433 "--"
3434 ["Fontify Buffer" vhdl-fontify-buffer t]
3435 ["Statistics Buffer" vhdl-statistics-buffer t]
3436 ["Show Messages" vhdl-show-messages t]
3437 ["Syntactic Info" vhdl-show-syntactic-information t]
3438 "--"
3439 ["Speedbar" vhdl-speedbar t]
3440 ["Hide/Show" vhdl-hs-minor-mode t]
3441 "--"
3442 ("Documentation"
3443 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3444 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3445 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3446 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3447 ["Version" vhdl-version t]
3448 ["Bug Report..." vhdl-submit-bug-report t]
3449 "--"
3450 ("Options"
3451 ("Mode"
3452 ["Electric Mode"
3453 (progn (customize-set-variable 'vhdl-electric-mode
3454 (not vhdl-electric-mode)))
3455 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3456 ["Stutter Mode"
3457 (progn (customize-set-variable 'vhdl-stutter-mode
3458 (not vhdl-stutter-mode)))
3459 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3460 ["Indent Tabs Mode"
3461 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3462 (not vhdl-indent-tabs-mode))
3463 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3464 :style toggle :selected vhdl-indent-tabs-mode]
3465 "--"
3466 ["Customize Group..." (customize-group 'vhdl-mode) t])
3467 ("Project"
3468 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3469 ,(append
3470 '("Selected Project at Startup"
3471 ["None" (progn (customize-set-variable 'vhdl-project nil)
3472 (vhdl-set-project ""))
3473 :style radio :selected (null vhdl-project)]
3474 "--")
3475 ;; add menu entries for defined projects
3476 (let ((project-alist vhdl-project-alist) menu-list name)
3477 (while project-alist
3478 (setq name (caar project-alist))
3479 (setq menu-list
3480 (cons `[,name (progn (customize-set-variable
3481 'vhdl-project ,name)
3482 (vhdl-set-project ,name))
3483 :style radio :selected (equal ,name vhdl-project)]
3484 menu-list))
3485 (setq project-alist (cdr project-alist)))
3486 (setq menu-list (nreverse menu-list))
3487 (vhdl-menu-split menu-list "Project")))
3488 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3489 ("Auto Load Setup File"
3490 ["At Startup"
3491 (customize-set-variable 'vhdl-project-auto-load
3492 (if (memq 'startup vhdl-project-auto-load)
3493 (delq 'startup vhdl-project-auto-load)
3494 (cons 'startup vhdl-project-auto-load)))
3495 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3496 ["Sort Projects"
3497 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3498 :style toggle :selected vhdl-project-sort]
3499 "--"
3500 ["Customize Group..." (customize-group 'vhdl-project) t])
3501 ("Compiler"
3502 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3503 ,(append
3504 '("Selected Compiler at Startup")
3505 ;; add menu entries for defined compilers
3506 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3507 (while comp-alist
3508 (setq name (caar comp-alist))
3509 (setq menu-list
3510 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3511 :style radio :selected (equal ,name vhdl-compiler)]
3512 menu-list))
3513 (setq comp-alist (cdr comp-alist)))
3514 (setq menu-list (nreverse menu-list))
3515 (vhdl-menu-split menu-list "Compler")))
3516 ["Use Local Error Regexp"
3517 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3518 (not vhdl-compile-use-local-error-regexp))
3519 :style toggle :selected vhdl-compile-use-local-error-regexp]
3520 ["Makefile Generation Hook..."
3521 (customize-option 'vhdl-makefile-generation-hook) t]
3522 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3523 "--"
3524 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3525 ("Style"
3526 ("VHDL Standard"
3527 ["VHDL'87"
3528 (progn (customize-set-variable 'vhdl-standard
3529 (list '87 (cadr vhdl-standard)))
3530 (vhdl-activate-customizations))
3531 :style radio :selected (eq '87 (car vhdl-standard))]
3532 ["VHDL'93"
3533 (progn (customize-set-variable 'vhdl-standard
3534 (list '93 (cadr vhdl-standard)))
3535 (vhdl-activate-customizations))
3536 :style radio :selected (eq '93 (car vhdl-standard))]
3537 "--"
3538 ["VHDL-AMS"
3539 (progn (customize-set-variable
3540 'vhdl-standard (list (car vhdl-standard)
3541 (if (memq 'ams (cadr vhdl-standard))
3542 (delq 'ams (cadr vhdl-standard))
3543 (cons 'ams (cadr vhdl-standard)))))
3544 (vhdl-activate-customizations))
3545 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3546 ["Math Packages"
3547 (progn (customize-set-variable
3548 'vhdl-standard (list (car vhdl-standard)
3549 (if (memq 'math (cadr vhdl-standard))
3550 (delq 'math (cadr vhdl-standard))
3551 (cons 'math (cadr vhdl-standard)))))
3552 (vhdl-activate-customizations))
3553 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3554 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3555 ["Upper Case Keywords"
3556 (customize-set-variable 'vhdl-upper-case-keywords
3557 (not vhdl-upper-case-keywords))
3558 :style toggle :selected vhdl-upper-case-keywords]
3559 ["Upper Case Types"
3560 (customize-set-variable 'vhdl-upper-case-types
3561 (not vhdl-upper-case-types))
3562 :style toggle :selected vhdl-upper-case-types]
3563 ["Upper Case Attributes"
3564 (customize-set-variable 'vhdl-upper-case-attributes
3565 (not vhdl-upper-case-attributes))
3566 :style toggle :selected vhdl-upper-case-attributes]
3567 ["Upper Case Enumeration Values"
3568 (customize-set-variable 'vhdl-upper-case-enum-values
3569 (not vhdl-upper-case-enum-values))
3570 :style toggle :selected vhdl-upper-case-enum-values]
3571 ["Upper Case Constants"
3572 (customize-set-variable 'vhdl-upper-case-constants
3573 (not vhdl-upper-case-constants))
3574 :style toggle :selected vhdl-upper-case-constants]
3575 ("Use Direct Instantiation"
3576 ["Never"
3577 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3578 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3579 ["Standard"
3580 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3581 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3582 ["Always"
3583 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3584 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3585 "--"
3586 ["Customize Group..." (customize-group 'vhdl-style) t])
3587 ("Naming"
3588 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3589 ["Architecture File Name..."
3590 (customize-option 'vhdl-architecture-file-name) t]
3591 ["Configuration File Name..."
3592 (customize-option 'vhdl-configuration-file-name) t]
3593 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3594 ("File Name Case"
3595 ["As Is"
3596 (customize-set-variable 'vhdl-file-name-case 'identity)
3597 :style radio :selected (eq 'identity vhdl-file-name-case)]
3598 ["Lower Case"
3599 (customize-set-variable 'vhdl-file-name-case 'downcase)
3600 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3601 ["Upper Case"
3602 (customize-set-variable 'vhdl-file-name-case 'upcase)
3603 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3604 ["Capitalize"
3605 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3606 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3607 "--"
3608 ["Customize Group..." (customize-group 'vhdl-naming) t])
3609 ("Template"
3610 ("Electric Keywords"
3611 ["VHDL Keywords"
3612 (customize-set-variable 'vhdl-electric-keywords
3613 (if (memq 'vhdl vhdl-electric-keywords)
3614 (delq 'vhdl vhdl-electric-keywords)
3615 (cons 'vhdl vhdl-electric-keywords)))
3616 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3617 ["User Model Keywords"
3618 (customize-set-variable 'vhdl-electric-keywords
3619 (if (memq 'user vhdl-electric-keywords)
3620 (delq 'user vhdl-electric-keywords)
3621 (cons 'user vhdl-electric-keywords)))
3622 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3623 ("Insert Optional Labels"
3624 ["None"
3625 (customize-set-variable 'vhdl-optional-labels 'none)
3626 :style radio :selected (eq 'none vhdl-optional-labels)]
3627 ["Processes Only"
3628 (customize-set-variable 'vhdl-optional-labels 'process)
3629 :style radio :selected (eq 'process vhdl-optional-labels)]
3630 ["All Constructs"
3631 (customize-set-variable 'vhdl-optional-labels 'all)
3632 :style radio :selected (eq 'all vhdl-optional-labels)])
3633 ("Insert Empty Lines"
3634 ["None"
3635 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3636 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3637 ["Design Units Only"
3638 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3639 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3640 ["All Constructs"
3641 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3642 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3643 ["Argument List Indent"
3644 (customize-set-variable 'vhdl-argument-list-indent
3645 (not vhdl-argument-list-indent))
3646 :style toggle :selected vhdl-argument-list-indent]
3647 ["Association List with Formals"
3648 (customize-set-variable 'vhdl-association-list-with-formals
3649 (not vhdl-association-list-with-formals))
3650 :style toggle :selected vhdl-association-list-with-formals]
3651 ["Conditions in Parenthesis"
3652 (customize-set-variable 'vhdl-conditions-in-parenthesis
3653 (not vhdl-conditions-in-parenthesis))
3654 :style toggle :selected vhdl-conditions-in-parenthesis]
3655 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3656 ["One String..." (customize-option 'vhdl-one-string) t]
3657 ("File Header"
3658 ["Header String..." (customize-option 'vhdl-file-header) t]
3659 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3660 ["Company Name..." (customize-option 'vhdl-company-name) t]
3661 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3662 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3663 ["Date Format..." (customize-option 'vhdl-date-format) t]
3664 ["Modify Date Prefix String..."
3665 (customize-option 'vhdl-modify-date-prefix-string) t]
3666 ["Modify Date on Saving"
3667 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3668 (not vhdl-modify-date-on-saving))
3669 (vhdl-activate-customizations))
3670 :style toggle :selected vhdl-modify-date-on-saving])
3671 ("Sequential Process"
3672 ("Kind of Reset"
3673 ["None"
3674 (customize-set-variable 'vhdl-reset-kind 'none)
3675 :style radio :selected (eq 'none vhdl-reset-kind)]
3676 ["Synchronous"
3677 (customize-set-variable 'vhdl-reset-kind 'sync)
3678 :style radio :selected (eq 'sync vhdl-reset-kind)]
3679 ["Asynchronous"
3680 (customize-set-variable 'vhdl-reset-kind 'async)
3681 :style radio :selected (eq 'async vhdl-reset-kind)])
3682 ["Reset is Active High"
3683 (customize-set-variable 'vhdl-reset-active-high
3684 (not vhdl-reset-active-high))
3685 :style toggle :selected vhdl-reset-active-high]
3686 ["Use Rising Clock Edge"
3687 (customize-set-variable 'vhdl-clock-rising-edge
3688 (not vhdl-clock-rising-edge))
3689 :style toggle :selected vhdl-clock-rising-edge]
3690 ("Clock Edge Condition"
3691 ["Standard"
3692 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3693 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3694 ["Function \"rising_edge\""
3695 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3696 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3697 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3698 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3699 "--"
3700 ["Customize Group..." (customize-group 'vhdl-template) t])
3701 ("Model"
3702 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3703 ("Port"
3704 ["Include Port Comments"
3705 (customize-set-variable 'vhdl-include-port-comments
3706 (not vhdl-include-port-comments))
3707 :style toggle :selected vhdl-include-port-comments]
3708 ["Include Direction Comments"
3709 (customize-set-variable 'vhdl-include-direction-comments
3710 (not vhdl-include-direction-comments))
3711 :style toggle :selected vhdl-include-direction-comments]
3712 ["Include Type Comments"
3713 (customize-set-variable 'vhdl-include-type-comments
3714 (not vhdl-include-type-comments))
3715 :style toggle :selected vhdl-include-type-comments]
3716 ("Include Group Comments"
3717 ["Never"
3718 (customize-set-variable 'vhdl-include-group-comments 'never)
3719 :style radio :selected (eq 'never vhdl-include-group-comments)]
3720 ["Declarations"
3721 (customize-set-variable 'vhdl-include-group-comments 'decl)
3722 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3723 ["Always"
3724 (customize-set-variable 'vhdl-include-group-comments 'always)
3725 :style radio :selected (eq 'always vhdl-include-group-comments)])
3726 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3727 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3728 ("Testbench"
3729 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3730 ["Architecture Name..."
3731 (customize-option 'vhdl-testbench-architecture-name) t]
3732 ["Configuration Name..."
3733 (customize-option 'vhdl-testbench-configuration-name) t]
3734 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3735 ["Include Header"
3736 (customize-set-variable 'vhdl-testbench-include-header
3737 (not vhdl-testbench-include-header))
3738 :style toggle :selected vhdl-testbench-include-header]
3739 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3740 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3741 ["Initialize Signals"
3742 (customize-set-variable 'vhdl-testbench-initialize-signals
3743 (not vhdl-testbench-initialize-signals))
3744 :style toggle :selected vhdl-testbench-initialize-signals]
3745 ["Include Library Clause"
3746 (customize-set-variable 'vhdl-testbench-include-library
3747 (not vhdl-testbench-include-library))
3748 :style toggle :selected vhdl-testbench-include-library]
3749 ["Include Configuration"
3750 (customize-set-variable 'vhdl-testbench-include-configuration
3751 (not vhdl-testbench-include-configuration))
3752 :style toggle :selected vhdl-testbench-include-configuration]
3753 ("Create Files"
3754 ["None"
3755 (customize-set-variable 'vhdl-testbench-create-files 'none)
3756 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3757 ["Single"
3758 (customize-set-variable 'vhdl-testbench-create-files 'single)
3759 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3760 ["Separate"
3761 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3762 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3763 ["Testbench Entity File Name..."
3764 (customize-option 'vhdl-testbench-entity-file-name) t]
3765 ["Testbench Architecture File Name..."
3766 (customize-option 'vhdl-testbench-architecture-file-name) t])
3767 "--"
3768 ["Customize Group..." (customize-group 'vhdl-port) t])
3769 ("Compose"
3770 ["Architecture Name..."
3771 (customize-option 'vhdl-compose-architecture-name) t]
3772 ["Configuration Name..."
3773 (customize-option 'vhdl-compose-configuration-name) t]
3774 ["Components Package Name..."
3775 (customize-option 'vhdl-components-package-name) t]
3776 ["Use Components Package"
3777 (customize-set-variable 'vhdl-use-components-package
3778 (not vhdl-use-components-package))
3779 :style toggle :selected vhdl-use-components-package]
3780 ["Include Header"
3781 (customize-set-variable 'vhdl-compose-include-header
3782 (not vhdl-compose-include-header))
3783 :style toggle :selected vhdl-compose-include-header]
3784 ("Create Entity/Architecture Files"
3785 ["None"
3786 (customize-set-variable 'vhdl-compose-create-files 'none)
3787 :style radio :selected (eq 'none vhdl-compose-create-files)]
3788 ["Single"
3789 (customize-set-variable 'vhdl-compose-create-files 'single)
3790 :style radio :selected (eq 'single vhdl-compose-create-files)]
3791 ["Separate"
3792 (customize-set-variable 'vhdl-compose-create-files 'separate)
3793 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3794 ["Create Configuration File"
3795 (customize-set-variable 'vhdl-compose-configuration-create-file
3796 (not vhdl-compose-configuration-create-file))
3797 :style toggle :selected vhdl-compose-configuration-create-file]
3798 ["Hierarchical Configuration"
3799 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3800 (not vhdl-compose-configuration-hierarchical))
3801 :style toggle :selected vhdl-compose-configuration-hierarchical]
3802 ["Use Subconfiguration"
3803 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3804 (not vhdl-compose-configuration-use-subconfiguration))
3805 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3806 "--"
3807 ["Customize Group..." (customize-group 'vhdl-compose) t])
3808 ("Comment"
3809 ["Self Insert Comments"
3810 (customize-set-variable 'vhdl-self-insert-comments
3811 (not vhdl-self-insert-comments))
3812 :style toggle :selected vhdl-self-insert-comments]
3813 ["Prompt for Comments"
3814 (customize-set-variable 'vhdl-prompt-for-comments
3815 (not vhdl-prompt-for-comments))
3816 :style toggle :selected vhdl-prompt-for-comments]
3817 ["Inline Comment Column..."
3818 (customize-option 'vhdl-inline-comment-column) t]
3819 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3820 "--"
3821 ["Customize Group..." (customize-group 'vhdl-comment) t])
3822 ("Align"
3823 ["Auto Align Templates"
3824 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3825 :style toggle :selected vhdl-auto-align]
3826 ["Align Line Groups"
3827 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3828 :style toggle :selected vhdl-align-groups]
3829 ["Group Separation String..."
3830 (customize-set-variable 'vhdl-align-group-separate) t]
3831 ["Align Lines with Same Indent"
3832 (customize-set-variable 'vhdl-align-same-indent
3833 (not vhdl-align-same-indent))
3834 :style toggle :selected vhdl-align-same-indent]
3835 "--"
3836 ["Customize Group..." (customize-group 'vhdl-align) t])
3837 ("Highlight"
3838 ["Highlighting On/Off..."
3839 (customize-option
3840 (if (fboundp 'global-font-lock-mode)
3841 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3842 ["Highlight Keywords"
3843 (progn (customize-set-variable 'vhdl-highlight-keywords
3844 (not vhdl-highlight-keywords))
3845 (vhdl-fontify-buffer))
3846 :style toggle :selected vhdl-highlight-keywords]
3847 ["Highlight Names"
3848 (progn (customize-set-variable 'vhdl-highlight-names
3849 (not vhdl-highlight-names))
3850 (vhdl-fontify-buffer))
3851 :style toggle :selected vhdl-highlight-names]
3852 ["Highlight Special Words"
3853 (progn (customize-set-variable 'vhdl-highlight-special-words
3854 (not vhdl-highlight-special-words))
3855 (vhdl-fontify-buffer))
3856 :style toggle :selected vhdl-highlight-special-words]
3857 ["Highlight Forbidden Words"
3858 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3859 (not vhdl-highlight-forbidden-words))
3860 (vhdl-fontify-buffer))
3861 :style toggle :selected vhdl-highlight-forbidden-words]
3862 ["Highlight Verilog Keywords"
3863 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3864 (not vhdl-highlight-verilog-keywords))
3865 (vhdl-fontify-buffer))
3866 :style toggle :selected vhdl-highlight-verilog-keywords]
3867 ["Highlight \"translate_off\""
3868 (progn (customize-set-variable 'vhdl-highlight-translate-off
3869 (not vhdl-highlight-translate-off))
3870 (vhdl-fontify-buffer))
3871 :style toggle :selected vhdl-highlight-translate-off]
3872 ["Case Sensitive Highlighting"
3873 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3874 (not vhdl-highlight-case-sensitive))
3875 (vhdl-fontify-buffer))
3876 :style toggle :selected vhdl-highlight-case-sensitive]
3877 ["Special Syntax Definition..."
3878 (customize-option 'vhdl-special-syntax-alist) t]
3879 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3880 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3881 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3882 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3883 "--"
3884 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3885 ("Speedbar"
3886 ["Auto Open at Startup"
3887 (customize-set-variable 'vhdl-speedbar-auto-open
3888 (not vhdl-speedbar-auto-open))
3889 :style toggle :selected vhdl-speedbar-auto-open]
3890 ("Default Displaying Mode"
3891 ["Files"
3892 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3893 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3894 ["Directory Hierarchy"
3895 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3896 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3897 ["Project Hierarchy"
3898 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3899 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3900 ["Indentation Offset..."
3901 (customize-option 'speedbar-indentation-width) t]
3902 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3903 ["Jump to Unit when Opening"
3904 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3905 (not vhdl-speedbar-jump-to-unit))
3906 :style toggle :selected vhdl-speedbar-jump-to-unit]
3907 ["Update Hierarchy on File Saving"
3908 (customize-set-variable 'vhdl-speedbar-update-on-saving
3909 (not vhdl-speedbar-update-on-saving))
3910 :style toggle :selected vhdl-speedbar-update-on-saving]
3911 ("Save in Cache File"
3912 ["Hierarchy Information"
3913 (customize-set-variable 'vhdl-speedbar-save-cache
3914 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3915 (delq 'hierarchy vhdl-speedbar-save-cache)
3916 (cons 'hierarchy vhdl-speedbar-save-cache)))
3917 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3918 ["Displaying Status"
3919 (customize-set-variable 'vhdl-speedbar-save-cache
3920 (if (memq 'display vhdl-speedbar-save-cache)
3921 (delq 'display vhdl-speedbar-save-cache)
3922 (cons 'display vhdl-speedbar-save-cache)))
3923 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3924 ["Cache File Name..."
3925 (customize-option 'vhdl-speedbar-cache-file-name) t]
3926 "--"
3927 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3928 ("Menu"
3929 ["Add Index Menu when Loading File"
3930 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3931 (vhdl-index-menu-init))
3932 :style toggle :selected vhdl-index-menu]
3933 ["Add Source File Menu when Loading File"
3934 (progn (customize-set-variable 'vhdl-source-file-menu
3935 (not vhdl-source-file-menu))
3936 (vhdl-add-source-files-menu))
3937 :style toggle :selected vhdl-source-file-menu]
3938 ["Add Hideshow Menu at Startup"
3939 (progn (customize-set-variable 'vhdl-hideshow-menu
3940 (not vhdl-hideshow-menu))
3941 (vhdl-activate-customizations))
3942 :style toggle :selected vhdl-hideshow-menu]
3943 ["Hide Everything Initially"
3944 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3945 :style toggle :selected vhdl-hide-all-init]
3946 "--"
3947 ["Customize Group..." (customize-group 'vhdl-menu) t])
3948 ("Print"
3949 ["In Two Column Format"
3950 (progn (customize-set-variable 'vhdl-print-two-column
3951 (not vhdl-print-two-column))
3952 (message "Activate new setting by saving options and restarting Emacs"))
3953 :style toggle :selected vhdl-print-two-column]
3954 ["Use Customized Faces"
3955 (progn (customize-set-variable 'vhdl-print-customize-faces
3956 (not vhdl-print-customize-faces))
3957 (message "Activate new setting by saving options and restarting Emacs"))
3958 :style toggle :selected vhdl-print-customize-faces]
3959 "--"
3960 ["Customize Group..." (customize-group 'vhdl-print) t])
3961 ("Miscellaneous"
3962 ["Use Intelligent Tab"
3963 (progn (customize-set-variable 'vhdl-intelligent-tab
3964 (not vhdl-intelligent-tab))
3965 (vhdl-activate-customizations))
3966 :style toggle :selected vhdl-intelligent-tab]
3967 ["Indent Syntax-Based"
3968 (customize-set-variable 'vhdl-indent-syntax-based
3969 (not vhdl-indent-syntax-based))
3970 :style toggle :selected vhdl-indent-syntax-based]
3971 ["Word Completion is Case Sensitive"
3972 (customize-set-variable 'vhdl-word-completion-case-sensitive
3973 (not vhdl-word-completion-case-sensitive))
3974 :style toggle :selected vhdl-word-completion-case-sensitive]
3975 ["Word Completion in Minibuffer"
3976 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3977 (not vhdl-word-completion-in-minibuffer))
3978 (message "Activate new setting by saving options and restarting Emacs"))
3979 :style toggle :selected vhdl-word-completion-in-minibuffer]
3980 ["Underscore is Part of Word"
3981 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3982 (not vhdl-underscore-is-part-of-word))
3983 (vhdl-activate-customizations))
3984 :style toggle :selected vhdl-underscore-is-part-of-word]
3985 "--"
3986 ["Customize Group..." (customize-group 'vhdl-misc) t])
3987 ["Related..." (customize-browse 'vhdl-related) t]
3988 "--"
3989 ["Save Options" customize-save-customized t]
3990 ["Activate Options" vhdl-activate-customizations t]
3991 ["Browse Options..." vhdl-customize t])))
3992
3993 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3994 "VHDL Mode menu.")
3995
3996 (defun vhdl-update-mode-menu ()
3997 "Update VHDL Mode menu."
3998 (interactive)
3999 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4000 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4001 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4002 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4003 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4004
4005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4006 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4007
4008 (defconst vhdl-imenu-generic-expression
4009 '(
4010 ("Subprogram"
4011 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4012 4)
4013 ("Instance"
4014 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4015 1)
4016 ("Component"
4017 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4018 2)
4019 ("Procedural"
4020 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4021 1)
4022 ("Process"
4023 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4024 1)
4025 ("Block"
4026 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4027 1)
4028 ("Package"
4029 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4030 3)
4031 ("Configuration"
4032 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4033 2)
4034 ("Architecture"
4035 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4036 2)
4037 ("Entity"
4038 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4039 2)
4040 )
4041 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4042
4043 (defun vhdl-index-menu-init ()
4044 "Initialize index menu."
4045 (set (make-local-variable 'imenu-case-fold-search) t)
4046 (set (make-local-variable 'imenu-generic-expression)
4047 vhdl-imenu-generic-expression)
4048 (when (and vhdl-index-menu (fboundp 'imenu))
4049 (if (or (not (boundp 'font-lock-maximum-size))
4050 (> font-lock-maximum-size (buffer-size)))
4051 (imenu-add-to-menubar "Index")
4052 (message "Scanning buffer for index...buffer too big"))))
4053
4054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4055 ;; Source file menu (using `easy-menu.el')
4056
4057 (defvar vhdl-sources-menu nil)
4058
4059 (defun vhdl-directory-files (directory &optional full match)
4060 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4061 message."
4062 (if (not (file-directory-p directory))
4063 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4064 (let ((dir (directory-files directory full match)))
4065 (setq dir (delete "." dir))
4066 (setq dir (delete ".." dir))
4067 dir)))
4068
4069 (defun vhdl-get-source-files (&optional full directory)
4070 "Get list of VHDL source files in DIRECTORY or current directory."
4071 (let ((mode-alist auto-mode-alist)
4072 filename-regexp)
4073 ;; create regular expressions for matching file names
4074 (setq filename-regexp "\\`[^.].*\\(")
4075 (while mode-alist
4076 (when (eq (cdar mode-alist) 'vhdl-mode)
4077 (setq filename-regexp
4078 (concat filename-regexp (caar mode-alist) "\\|")))
4079 (setq mode-alist (cdr mode-alist)))
4080 (setq filename-regexp
4081 (concat (substring filename-regexp 0
4082 (string-match "\\\\|$" filename-regexp)) "\\)"))
4083 ;; find files
4084 (vhdl-directory-files
4085 (or directory default-directory) full filename-regexp)))
4086
4087 (defun vhdl-add-source-files-menu ()
4088 "Scan directory for all VHDL source files and generate menu.
4089 The directory of the current source file is scanned."
4090 (interactive)
4091 (message "Scanning directory for source files ...")
4092 (let ((newmap (current-local-map))
4093 (file-list (vhdl-get-source-files))
4094 menu-list found)
4095 ;; Create list for menu
4096 (setq found nil)
4097 (while file-list
4098 (setq found t)
4099 (setq menu-list (cons (vector (car file-list)
4100 (list 'find-file (car file-list)) t)
4101 menu-list))
4102 (setq file-list (cdr file-list)))
4103 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4104 (when found (setq menu-list (cons "--" menu-list)))
4105 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4106 (setq menu-list (cons "Sources" menu-list))
4107 ;; Create menu
4108 (easy-menu-add menu-list)
4109 (easy-menu-define vhdl-sources-menu newmap
4110 "VHDL source files menu" menu-list))
4111 (message ""))
4112
4113
4114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4115 ;;; Mode definition
4116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4117 ;; performs all buffer local initializations
4118
4119 ;;;###autoload
4120 (defun vhdl-mode ()
4121 "Major mode for editing VHDL code.
4122
4123 Usage:
4124 ------
4125
4126 TEMPLATE INSERTION (electrification):
4127 After typing a VHDL keyword and entering `SPC', you are prompted for
4128 arguments while a template is generated for that VHDL construct. Typing
4129 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4130 template generation. Optional arguments are indicated by square
4131 brackets and removed if the queried string is left empty. Prompts for
4132 mandatory arguments remain in the code if the queried string is left
4133 empty. They can be queried again by `C-c C-t C-q'. Enabled
4134 electrification is indicated by `/e' in the modeline.
4135
4136 Typing `M-SPC' after a keyword inserts a space without calling the
4137 template generator. Automatic template generation (i.e.
4138 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4139 setting option `vhdl-electric-mode' (see OPTIONS).
4140
4141 Template generators can be invoked from the VHDL menu, by key
4142 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4143 the keyword (i.e. first word of menu entry not in parenthesis) and
4144 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4145 conf, comp, cons, func, inst, pack, sig, var.
4146
4147 Template styles can be customized in customization group
4148 `vhdl-template' \(see OPTIONS).
4149
4150
4151 HEADER INSERTION:
4152 A file header can be inserted by `C-c C-t C-h'. A file footer
4153 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4154 See customization group `vhdl-header'.
4155
4156
4157 STUTTERING:
4158 Double striking of some keys inserts cumbersome VHDL syntax elements.
4159 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4160 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4161 the modeline. The stuttering keys and their effects are:
4162
4163 ;; --> \" : \" [ --> ( -- --> comment
4164 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4165 .. --> \" => \" ] --> ) --- --> horizontal line
4166 ,, --> \" <= \" ]] --> ] ---- --> display comment
4167 == --> \" == \" '' --> \\\"
4168
4169
4170 WORD COMPLETION:
4171 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4172 word in the buffer that starts alike, inserts it and adjusts case.
4173 Re-typing `TAB' toggles through alternative word completions. This also
4174 works in the minibuffer (i.e. in template generator prompts).
4175
4176 Typing `TAB' after `(' looks for and inserts complete parenthesized
4177 expressions (e.g. for array index ranges). All keywords as well as
4178 standard types and subprograms of VHDL have predefined abbreviations
4179 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4180 beginning with \"std\").
4181
4182 Typing `TAB' after a non-word character indents the line if at the
4183 beginning of a line (i.e. no preceding non-blank characters), and
4184 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4185 stop.
4186
4187
4188 COMMENTS:
4189 `--' puts a single comment.
4190 `---' draws a horizontal line for separating code segments.
4191 `----' inserts a display comment, i.e. two horizontal lines
4192 with a comment in between.
4193 `--CR' comments out code on that line. Re-hitting CR comments
4194 out following lines.
4195 `C-c c' comments out a region if not commented out,
4196 uncomments a region if already commented out.
4197
4198 You are prompted for comments after object definitions (i.e. signals,
4199 variables, constants, ports) and after subprogram and process
4200 specifications if option `vhdl-prompt-for-comments' is non-nil.
4201 Comments are automatically inserted as additional labels (e.g. after
4202 begin statements) and as help comments if `vhdl-self-insert-comments' is
4203 non-nil.
4204
4205 Inline comments (i.e. comments after a piece of code on the same line)
4206 are indented at least to `vhdl-inline-comment-column'. Comments go at
4207 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4208 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4209 in a comment automatically opens a new comment line. `M-q' re-fills
4210 multi-line comments.
4211
4212
4213 INDENTATION:
4214 `TAB' indents a line if at the beginning of the line. The amount of
4215 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4216 always indents the current line (is bound to `TAB' if option
4217 `vhdl-intelligent-tab' is nil).
4218
4219 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4220 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4221 indented normally (nil) or relative to the opening parenthesis (non-nil)
4222 according to option `vhdl-argument-list-indent'.
4223
4224 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4225 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4226 and vice versa.
4227
4228 Syntax-based indentation can be very slow in large files. Option
4229 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4230
4231
4232 ALIGNMENT:
4233 The alignment functions align operators, keywords, and inline comments
4234 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4235 separated by blank lines, `C-c C-a C-i' a block of lines with same
4236 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4237 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4238 C-a C-d' all lines within the declarative part of a design unit. `C-c
4239 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4240 for a group of lines, and `C-c C-a M-c' for a region.
4241
4242 If option `vhdl-align-groups' is non-nil, groups of code lines
4243 separated by special lines (see option `vhdl-align-group-separate') are
4244 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4245 blocks of lines with same indent are aligned separately. Some templates
4246 are automatically aligned after generation if option `vhdl-auto-align'
4247 is non-nil.
4248
4249 Alignment tries to align inline comments at
4250 `vhdl-inline-comment-column' and tries inline comment not to exceed
4251 `vhdl-end-comment-column'.
4252
4253 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4254 symbols are surrounded by one space, and multiple spaces are eliminated.
4255
4256
4257 CODE FILLING:
4258 Code filling allows to condense code (e.g. sensitivity lists or port
4259 maps) by removing comments and newlines and re-wrapping so that all
4260 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4261 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4262 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4263 `C-c C-f M-f' an entire region.
4264
4265
4266 CODE BEAUTIFICATION:
4267 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4268 buffer respectively. This inludes indentation, alignment, and case
4269 fixing. Code beautification can also be run non-interactively using the
4270 command:
4271
4272 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4273
4274
4275 PORT TRANSLATION:
4276 Generic and port clauses from entity or component declarations can be
4277 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4278 as component instantiations and corresponding internal constants and
4279 signals, as a generic map with constants as actual generics, and as
4280 internal signal initializations (menu).
4281
4282 To include formals in component instantiations, see option
4283 `vhdl-association-list-with-formals'. To include comments in pasting,
4284 see options `vhdl-include-...-comments'.
4285
4286 A clause with several generic/port names on the same line can be
4287 flattened (`C-c C-p C-f') so that only one name per line exists. The
4288 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4289 outputs and vice versa, which can be useful in testbenches. (This
4290 reversion is done on the internal data structure and is only reflected
4291 in subsequent paste operations.)
4292
4293 Names for actual ports, instances, testbenches, and
4294 design-under-test instances can be derived from existing names according
4295 to options `vhdl-...-name'. See customization group `vhdl-port'.
4296
4297
4298 SUBPROGRAM TRANSLATION:
4299 Similar functionality exists for copying/pasting the interface of
4300 subprograms (function/procedure). A subprogram interface can be copied
4301 and then pasted as a subprogram declaration, body or call (uses
4302 association list with formals).
4303
4304
4305 TESTBENCH GENERATION:
4306 A copied port can also be pasted as a testbench. The generated
4307 testbench includes an entity, an architecture, and an optional
4308 configuration. The architecture contains the component declaration and
4309 instantiation of the DUT as well as internal constant and signal
4310 declarations. Additional user-defined templates can be inserted. The
4311 names used for entity/architecture/configuration/DUT as well as the file
4312 structure to be generated can be customized. See customization group
4313 `vhdl-testbench'.
4314
4315
4316 KEY BINDINGS:
4317 Key bindings (`C-c ...') exist for most commands (see in menu).
4318
4319
4320 VHDL MENU:
4321 All commands can be found in the VHDL menu including their key bindings.
4322
4323
4324 FILE BROWSER:
4325 The speedbar allows browsing of directories and file contents. It can
4326 be accessed from the VHDL menu and is automatically opened if option
4327 `vhdl-speedbar-auto-open' is non-nil.
4328
4329 In speedbar, open files and directories with `mouse-2' on the name and
4330 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4331
4332
4333 DESIGN HIERARCHY BROWSER:
4334 The speedbar can also be used for browsing the hierarchy of design units
4335 contained in the source files of the current directory or the specified
4336 projects (see option `vhdl-project-alist').
4337
4338 The speedbar can be switched between file, directory hierarchy and
4339 project hierarchy browsing mode in the speedbar menu or by typing `f',
4340 `h' or `H' in speedbar.
4341
4342 In speedbar, open design units with `mouse-2' on the name and browse
4343 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4344 from entities and components (in packages). Individual design units and
4345 complete designs can directly be compiled (\"Make\" menu entry).
4346
4347 The hierarchy is automatically updated upon saving a modified source
4348 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4349 hierarchy is only updated for projects that have been opened once in the
4350 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4351 options in group `vhdl-speedbar').
4352
4353 Simple design consistency checks are done during scanning, such as
4354 multiple declarations of the same unit or missing primary units that are
4355 required by secondary units.
4356
4357
4358 STRUCTURAL COMPOSITION:
4359 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4360 for a new component. Subcomponents (i.e. component declaration and
4361 instantiation) can be automatically placed from a previously read port
4362 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4363 all subcomponents can be automatically connected using internal signals
4364 and ports (`C-c C-c C-w') following these rules:
4365 - subcomponent actual ports with same name are considered to be
4366 connected by a signal (internal signal or port)
4367 - signals that are only inputs to subcomponents are considered as
4368 inputs to this component -> input port created
4369 - signals that are only outputs from subcomponents are considered as
4370 outputs from this component -> output port created
4371 - signals that are inputs to AND outputs from subcomponents are
4372 considered as internal connections -> internal signal created
4373
4374 Purpose: With appropriate naming conventions it is possible to
4375 create higher design levels with only a few mouse clicks or key
4376 strokes. A new design level can be created by simply generating a new
4377 component, placing the required subcomponents from the hierarchy
4378 browser, and wiring everything automatically.
4379
4380 Note: Automatic wiring only works reliably on templates of new
4381 components and component instantiations that were created by VHDL mode.
4382
4383 Component declarations can be placed in a components package (option
4384 `vhdl-use-components-package') which can be automatically generated for
4385 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4386 component instantiation is also supported (option
4387 `vhdl-use-direct-instantiation').
4388
4389 | Configuration declarations can automatically be generated either from
4390 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4391 | the speedbar menu (for the architecture under the cursor). The
4392 | configurations can optionally be hierarchical (i.e. include all
4393 | component levels of a hierarchical design, option
4394 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4395 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4396 | subcomponents in hierarchical configurations, the most-recently-analyzed
4397 | (mra) architecture is selected. If another architecture is desired, it
4398 | can be marked as most-recently-analyzed (speedbar menu) before
4399 | generating the configuration.
4400 |
4401 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4402 | declarations) are currently not considered when displaying
4403 | configurations in speedbar.
4404
4405 See the options group `vhdl-compose' for all relevant user options.
4406
4407
4408 SOURCE FILE COMPILATION:
4409 The syntax of the current buffer can be analyzed by calling a VHDL
4410 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4411 option `vhdl-compiler'. The available compilers are listed in option
4412 `vhdl-compiler-alist' including all required compilation command,
4413 command options, compilation directory, and error message syntax
4414 information. New compilers can be added.
4415
4416 All the source files of an entire design can be compiled by the `make'
4417 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4418
4419
4420 MAKEFILE GENERATION:
4421 Makefiles can be generated automatically by an internal generation
4422 routine (`C-c M-k'). The library unit dependency information is
4423 obtained from the hierarchy browser. Makefile generation can be
4424 customized for each compiler in option `vhdl-compiler-alist'.
4425
4426 Makefile generation can also be run non-interactively using the
4427 command:
4428
4429 emacs -batch -l ~/.emacs -l vhdl-mode
4430 [-compiler compilername] [-project projectname]
4431 -f vhdl-generate-makefile
4432
4433 The Makefile's default target \"all\" compiles the entire design, the
4434 target \"clean\" removes it and the target \"library\" creates the
4435 library directory if not existent. The Makefile also includes a target
4436 for each primary library unit which allows selective compilation of this
4437 unit, its secondary units and its subhierarchy (example: compilation of
4438 a design specified by a configuration). User specific parts can be
4439 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4440
4441 Limitations:
4442 - Only library units and dependencies within the current library are
4443 considered. Makefiles for designs that span multiple libraries are
4444 not (yet) supported.
4445 - Only one-level configurations are supported (also hierarchical),
4446 but configurations that go down several levels are not.
4447 - The \"others\" keyword in configurations is not supported.
4448
4449
4450 PROJECTS:
4451 Projects can be defined in option `vhdl-project-alist' and a current
4452 project be selected using option `vhdl-project' (permanently) or from
4453 the menu or speedbar (temporarily). For each project, title and
4454 description strings (for the file headers), source files/directories
4455 (for the hierarchy browser and Makefile generation), library name, and
4456 compiler-dependent options, exceptions and compilation directory can be
4457 specified. Compilation settings overwrite the settings of option
4458 `vhdl-compiler-alist'.
4459
4460 Project setups can be exported (i.e. written to a file) and imported.
4461 Imported setups are not automatically saved in `vhdl-project-alist' but
4462 can be saved afterwards in its customization buffer. When starting
4463 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4464 vhdl-mode\") in a directory with an existing project setup file, it is
4465 automatically loaded and its project activated if option
4466 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4467 files can be specified in option `vhdl-project-file-name'. Multiple
4468 project setups can be automatically loaded from global directories.
4469 This is an alternative to specifying project setups with option
4470 `vhdl-project-alist'.
4471
4472
4473 SPECIAL MENUES:
4474 As an alternative to the speedbar, an index menu can be added (set
4475 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4476 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4477 file) for browsing the file contents (is not populated if buffer is
4478 larger than `font-lock-maximum-size'). Also, a source file menu can be
4479 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4480 current directory for VHDL source files.
4481
4482
4483 VHDL STANDARDS:
4484 The VHDL standards to be used are specified in option `vhdl-standard'.
4485 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4486
4487
4488 KEYWORD CASE:
4489 Lower and upper case for keywords and standardized types, attributes,
4490 and enumeration values is supported. If the option
4491 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4492 lower case and are converted into upper case automatically (not for
4493 types, attributes, and enumeration values). The case of keywords,
4494 types, attributes,and enumeration values can be fixed for an entire
4495 region (menu) or buffer (`C-c C-x C-c') according to the options
4496 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4497
4498
4499 HIGHLIGHTING (fontification):
4500 Keywords and standardized types, attributes, enumeration values, and
4501 function names (controlled by option `vhdl-highlight-keywords'), as well
4502 as comments, strings, and template prompts are highlighted using
4503 different colors. Unit, subprogram, signal, variable, constant,
4504 parameter and generic/port names in declarations as well as labels are
4505 highlighted if option `vhdl-highlight-names' is non-nil.
4506
4507 Additional reserved words or words with a forbidden syntax (e.g. words
4508 that should be avoided) can be specified in option
4509 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4510 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4511 keywords are highlighted as forbidden words if option
4512 `vhdl-highlight-verilog-keywords' is non-nil.
4513
4514 Words with special syntax can be highlighted by specifying their
4515 syntax and color in option `vhdl-special-syntax-alist' and by setting
4516 option `vhdl-highlight-special-words' to non-nil. This allows to
4517 establish some naming conventions (e.g. to distinguish different kinds
4518 of signals or other objects by using name suffices) and to support them
4519 visually.
4520
4521 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4522 to support case-sensitive highlighting. However, keywords are then only
4523 highlighted if written in lower case.
4524
4525 Code between \"translate_off\" and \"translate_on\" pragmas is
4526 highlighted using a different background color if option
4527 `vhdl-highlight-translate-off' is non-nil.
4528
4529 For documentation and customization of the used colors see
4530 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4531 highlighting of matching parenthesis, see customization group
4532 `paren-showing'. Automatic buffer highlighting is turned on/off by
4533 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4534
4535
4536 USER MODELS:
4537 VHDL models (templates) can be specified by the user and made accessible
4538 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4539 electrification. See option `vhdl-model-alist'.
4540
4541
4542 HIDE/SHOW:
4543 The code of blocks, processes, subprograms, component declarations and
4544 instantiations, generic/port clauses, and configuration declarations can
4545 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4546 the code (see customization group `vhdl-menu'). XEmacs: limited
4547 functionality due to old `hideshow.el' package.
4548
4549
4550 CODE UPDATING:
4551 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4552 current process, `C-c C-u M-s' of all processes in the current buffer.
4553 Limitations:
4554 - Only declared local signals (ports, signals declared in
4555 architecture and blocks) are automatically inserted.
4556 - Global signals declared in packages are not automatically inserted.
4557 Insert them once manually (will be kept afterwards).
4558 - Out parameters of procedures are considered to be read.
4559 Use option `vhdl-entity-file-name' to specify the entity file name
4560 \(used to obtain the port names).
4561
4562
4563 CODE FIXING:
4564 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4565 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4566
4567
4568 PRINTING:
4569 Postscript printing with different faces (an optimized set of faces is
4570 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4571 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4572 postscript printing commands. Option `vhdl-print-two-column' defines
4573 appropriate default settings for nice landscape two-column printing.
4574 The paper format can be set by option `ps-paper-type'. Do not forget to
4575 switch `ps-print-color-p' to nil for printing on black-and-white
4576 printers.
4577
4578
4579 OPTIONS:
4580 User options allow customization of VHDL Mode. All options are
4581 accessible from the \"Options\" menu entry. Simple options (switches
4582 and choices) can directly be changed, while for complex options a
4583 customization buffer is opened. Changed options can be saved for future
4584 sessions using the \"Save Options\" menu entry.
4585
4586 Options and their detailed descriptions can also be accessed by using
4587 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4588 customize-group' for groups). Some customizations only take effect
4589 after some action (read the NOTE in the option documentation).
4590 Customization can also be done globally (i.e. site-wide, read the
4591 INSTALL file).
4592
4593 Not all options are described in this documentation, so go and see
4594 what other useful user options there are (`M-x vhdl-customize' or menu)!
4595
4596
4597 FILE EXTENSIONS:
4598 As default, files with extensions \".vhd\" and \".vhdl\" are
4599 automatically recognized as VHDL source files. To add an extension
4600 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4601
4602 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4603
4604
4605 HINTS:
4606 - To start Emacs with open VHDL hierarchy browser without having to load
4607 a VHDL file first, use the command:
4608
4609 emacs -l vhdl-mode -f speedbar-frame-mode
4610
4611 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4612
4613 - Some features only work on properly indented code.
4614
4615
4616 RELEASE NOTES:
4617 See also the release notes (menu) for added features in new releases.
4618
4619
4620 Maintenance:
4621 ------------
4622
4623 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4624 Add a description of the problem and include a reproducible test case.
4625
4626 Questions and enhancement requests can be sent to <reto@gnu.org>.
4627
4628 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4629 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4630 releases. You are kindly invited to participate in beta testing. Subscribe
4631 to above mailing lists by sending an email to <reto@gnu.org>.
4632
4633 VHDL Mode is officially distributed at
4634 URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
4635 where the latest version can be found.
4636
4637
4638 Known problems:
4639 ---------------
4640
4641 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4642 - XEmacs: Incorrect start-up when automatically opening speedbar.
4643 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4644
4645
4646 The VHDL Mode Authors
4647 Reto Zimmermann and Rod Whitby
4648
4649 Key bindings:
4650 -------------
4651
4652 \\{vhdl-mode-map}"
4653 (interactive)
4654 (kill-all-local-variables)
4655 (setq major-mode 'vhdl-mode)
4656 (setq mode-name '("VHDL"
4657 (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4658 (vhdl-electric-mode "e")
4659 (vhdl-stutter-mode "s")))
4660
4661 ;; set maps and tables
4662 (use-local-map vhdl-mode-map)
4663 (set-syntax-table vhdl-mode-syntax-table)
4664 (setq local-abbrev-table vhdl-mode-abbrev-table)
4665
4666 ;; set local variables
4667 (set (make-local-variable 'paragraph-start)
4668 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4669 (set (make-local-variable 'paragraph-separate) paragraph-start)
4670 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4671 (set (make-local-variable 'require-final-newline)
4672 (if vhdl-emacs-22 mode-require-final-newline t))
4673 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4674 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4675 (set (make-local-variable 'comment-start) "--")
4676 (set (make-local-variable 'comment-end) "")
4677 (when vhdl-emacs-21
4678 (set (make-local-variable 'comment-padding) ""))
4679 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4680 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4681 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4682 (set (make-local-variable 'comment-multi-line) nil)
4683 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4684 (set (make-local-variable 'hippie-expand-verbose) nil)
4685
4686 ;; setup the comment indent variable in a Emacs version portable way
4687 ;; ignore any byte compiler warnings you might get here
4688 (when (boundp 'comment-indent-function)
4689 (make-local-variable 'comment-indent-function)
4690 (setq comment-indent-function 'vhdl-comment-indent))
4691
4692 ;; initialize font locking
4693 (set (make-local-variable 'font-lock-defaults)
4694 (list
4695 '(nil vhdl-font-lock-keywords) nil
4696 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4697 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4698 (set (make-local-variable 'syntax-propertize-function)
4699 (syntax-propertize-rules
4700 ;; Mark single quotes as having string quote syntax in
4701 ;; 'c' instances.
4702 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4703 (set (make-local-variable 'font-lock-syntactic-keywords)
4704 vhdl-font-lock-syntactic-keywords))
4705 (unless vhdl-emacs-21
4706 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4707 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4708 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4709 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4710 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4711 ; (turn-on-font-lock)
4712
4713 ;; variables for source file compilation
4714 (when vhdl-compile-use-local-error-regexp
4715 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4716 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4717
4718 ;; add index menu
4719 (vhdl-index-menu-init)
4720 ;; add source file menu
4721 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4722 ;; add VHDL menu
4723 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4724 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4725 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4726 ;; initialize hideshow and add menu
4727 (vhdl-hideshow-init)
4728 (run-hooks 'menu-bar-update-hook)
4729
4730 ;; miscellaneous
4731 (vhdl-ps-print-init)
4732 (vhdl-write-file-hooks-init)
4733 (message "VHDL Mode %s.%s" vhdl-version
4734 (if noninteractive "" " See menu for documentation and release notes."))
4735
4736 ;; run hooks
4737 (if vhdl-emacs-22
4738 (run-mode-hooks 'vhdl-mode-hook)
4739 (run-hooks 'vhdl-mode-hook)))
4740
4741 (defun vhdl-activate-customizations ()
4742 "Activate all customizations on local variables."
4743 (interactive)
4744 (vhdl-mode-map-init)
4745 (use-local-map vhdl-mode-map)
4746 (set-syntax-table vhdl-mode-syntax-table)
4747 (setq comment-column vhdl-inline-comment-column)
4748 (setq end-comment-column vhdl-end-comment-column)
4749 (vhdl-write-file-hooks-init)
4750 (vhdl-update-mode-menu)
4751 (vhdl-hideshow-init)
4752 (run-hooks 'menu-bar-update-hook))
4753
4754 (defun vhdl-write-file-hooks-init ()
4755 "Add/remove hooks when buffer is saved."
4756 (if vhdl-modify-date-on-saving
4757 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4758 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4759 (make-local-variable 'after-save-hook)
4760 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4761
4762 (defun vhdl-process-command-line-option (option)
4763 "Process command line options for VHDL Mode."
4764 (cond
4765 ;; set compiler
4766 ((equal option "-compiler")
4767 (vhdl-set-compiler (car command-line-args-left))
4768 (setq command-line-args-left (cdr command-line-args-left)))
4769 ;; set project
4770 ((equal option "-project")
4771 (vhdl-set-project (car command-line-args-left))
4772 (setq command-line-args-left (cdr command-line-args-left)))))
4773
4774 ;; make Emacs process VHDL Mode options
4775 (setq command-switch-alist
4776 (append command-switch-alist
4777 '(("-compiler" . vhdl-process-command-line-option)
4778 ("-project" . vhdl-process-command-line-option))))
4779
4780
4781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4782 ;;; Keywords and standardized words
4783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4784
4785 (defconst vhdl-93-keywords
4786 '(
4787 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4788 "assert" "attribute"
4789 "begin" "block" "body" "buffer" "bus"
4790 "case" "component" "configuration" "constant"
4791 "disconnect" "downto"
4792 "else" "elsif" "end" "entity" "exit"
4793 "file" "for" "function"
4794 "generate" "generic" "group" "guarded"
4795 "if" "impure" "in" "inertial" "inout" "is"
4796 "label" "library" "linkage" "literal" "loop"
4797 "map" "mod"
4798 "nand" "new" "next" "nor" "not" "null"
4799 "of" "on" "open" "or" "others" "out"
4800 "package" "port" "postponed" "procedure" "process" "pure"
4801 "range" "record" "register" "reject" "rem" "report" "return"
4802 "rol" "ror"
4803 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4804 "then" "to" "transport" "type"
4805 "unaffected" "units" "until" "use"
4806 "variable"
4807 "wait" "when" "while" "with"
4808 "xnor" "xor"
4809 )
4810 "List of VHDL'93 keywords.")
4811
4812 (defconst vhdl-ams-keywords
4813 '(
4814 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4815 "reference" "spectrum" "subnature" "terminal" "through"
4816 "tolerance"
4817 )
4818 "List of VHDL-AMS keywords.")
4819
4820 (defconst vhdl-verilog-keywords
4821 '(
4822 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4823 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4824 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4825 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4826 "endprimitive" "endspecify" "endtable" "endtask" "event"
4827 "for" "force" "forever" "fork" "function"
4828 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4829 "macromodule" "makefile" "medium" "module"
4830 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4831 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4832 "pullup"
4833 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4834 "rtranif0" "rtranif1"
4835 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4836 "strong1" "supply" "supply0" "supply1"
4837 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4838 "triand" "trior" "trireg"
4839 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4840 )
4841 "List of Verilog keywords as candidate for additional reserved words.")
4842
4843 (defconst vhdl-93-types
4844 '(
4845 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4846 "real" "time" "natural" "positive" "string" "line" "text" "side"
4847 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4848 "std_logic" "std_logic_vector"
4849 "std_ulogic" "std_ulogic_vector"
4850 )
4851 "List of VHDL'93 standardized types.")
4852
4853 (defconst vhdl-ams-types
4854 '(
4855 "domain_type" "real_vector"
4856 ;; from `nature_pkg' package
4857 "voltage" "current" "electrical" "position" "velocity" "force"
4858 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4859 "pressure" "flowrate" "fluid"
4860 )
4861 "List of VHDL-AMS standardized types.")
4862
4863 (defconst vhdl-math-types
4864 '(
4865 "complex" "complex_polar"
4866 )
4867 "List of Math Packages standardized types.")
4868
4869 (defconst vhdl-93-attributes
4870 '(
4871 "base" "left" "right" "high" "low" "pos" "val" "succ"
4872 "pred" "leftof" "rightof" "range" "reverse_range"
4873 "length" "delayed" "stable" "quiet" "transaction"
4874 "event" "active" "last_event" "last_active" "last_value"
4875 "driving" "driving_value" "ascending" "value" "image"
4876 "simple_name" "instance_name" "path_name"
4877 "foreign"
4878 )
4879 "List of VHDL'93 standardized attributes.")
4880
4881 (defconst vhdl-ams-attributes
4882 '(
4883 "across" "through"
4884 "reference" "contribution" "tolerance"
4885 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4886 "ramp" "slew"
4887 )
4888 "List of VHDL-AMS standardized attributes.")
4889
4890 (defconst vhdl-93-enum-values
4891 '(
4892 "true" "false"
4893 "note" "warning" "error" "failure"
4894 "read_mode" "write_mode" "append_mode"
4895 "open_ok" "status_error" "name_error" "mode_error"
4896 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4897 "right" "left"
4898 )
4899 "List of VHDL'93 standardized enumeration values.")
4900
4901 (defconst vhdl-ams-enum-values
4902 '(
4903 "quiescent_domain" "time_domain" "frequency_domain"
4904 ;; from `nature_pkg' package
4905 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4906 )
4907 "List of VHDL-AMS standardized enumeration values.")
4908
4909 (defconst vhdl-math-constants
4910 '(
4911 "math_e" "math_1_over_e"
4912 "math_pi" "math_two_pi" "math_1_over_pi"
4913 "math_half_pi" "math_q_pi" "math_3_half_pi"
4914 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4915 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4916 "math_deg_to_rad" "math_rad_to_deg"
4917 "cbase_1" "cbase_j" "czero"
4918 )
4919 "List of Math Packages standardized constants.")
4920
4921 (defconst vhdl-93-functions
4922 '(
4923 "now" "resolved" "rising_edge" "falling_edge"
4924 "read" "readline" "write" "writeline" "endfile"
4925 "resize" "is_X" "std_match"
4926 "shift_left" "shift_right" "rotate_left" "rotate_right"
4927 "to_unsigned" "to_signed" "to_integer"
4928 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4929 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4930 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4931 "shl" "shr" "ext" "sxt"
4932 "deallocate"
4933 )
4934 "List of VHDL'93 standardized functions.")
4935
4936 (defconst vhdl-ams-functions
4937 '(
4938 "frequency"
4939 )
4940 "List of VHDL-AMS standardized functions.")
4941
4942 (defconst vhdl-math-functions
4943 '(
4944 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4945 "sqrt" "cbrt" "exp" "log"
4946 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4947 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4948 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4949 )
4950 "List of Math Packages standardized functions.")
4951
4952 (defconst vhdl-93-packages
4953 '(
4954 "std_logic_1164" "numeric_std" "numeric_bit"
4955 "standard" "textio"
4956 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4957 "std_logic_misc" "std_logic_textio"
4958 "ieee" "std" "work"
4959 )
4960 "List of VHDL'93 standardized packages and libraries.")
4961
4962 (defconst vhdl-ams-packages
4963 '(
4964 ;; from `nature_pkg' package
4965 "nature_pkg"
4966 )
4967 "List of VHDL-AMS standardized packages and libraries.")
4968
4969 (defconst vhdl-math-packages
4970 '(
4971 "math_real" "math_complex"
4972 )
4973 "List of Math Packages standardized packages and libraries.")
4974
4975 (defvar vhdl-keywords nil
4976 "List of VHDL keywords.")
4977
4978 (defvar vhdl-types nil
4979 "List of VHDL standardized types.")
4980
4981 (defvar vhdl-attributes nil
4982 "List of VHDL standardized attributes.")
4983
4984 (defvar vhdl-enum-values nil
4985 "List of VHDL standardized enumeration values.")
4986
4987 (defvar vhdl-constants nil
4988 "List of VHDL standardized constants.")
4989
4990 (defvar vhdl-functions nil
4991 "List of VHDL standardized functions.")
4992
4993 (defvar vhdl-packages nil
4994 "List of VHDL standardized packages and libraries.")
4995
4996 (defvar vhdl-reserved-words nil
4997 "List of additional reserved words.")
4998
4999 (defvar vhdl-keywords-regexp nil
5000 "Regexp for VHDL keywords.")
5001
5002 (defvar vhdl-types-regexp nil
5003 "Regexp for VHDL standardized types.")
5004
5005 (defvar vhdl-attributes-regexp nil
5006 "Regexp for VHDL standardized attributes.")
5007
5008 (defvar vhdl-enum-values-regexp nil
5009 "Regexp for VHDL standardized enumeration values.")
5010
5011 (defvar vhdl-functions-regexp nil
5012 "Regexp for VHDL standardized functions.")
5013
5014 (defvar vhdl-packages-regexp nil
5015 "Regexp for VHDL standardized packages and libraries.")
5016
5017 (defvar vhdl-reserved-words-regexp nil
5018 "Regexp for additional reserved words.")
5019
5020 (defvar vhdl-directive-keywords-regexp nil
5021 "Regexp for compiler directive keywords.")
5022
5023 (defun vhdl-words-init ()
5024 "Initialize reserved words."
5025 (setq vhdl-keywords
5026 (append vhdl-93-keywords
5027 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5028 (setq vhdl-types
5029 (append vhdl-93-types
5030 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5031 (when (vhdl-standard-p 'math) vhdl-math-types)))
5032 (setq vhdl-attributes
5033 (append vhdl-93-attributes
5034 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5035 (setq vhdl-enum-values
5036 (append vhdl-93-enum-values
5037 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5038 (setq vhdl-constants
5039 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5040 (setq vhdl-functions
5041 (append vhdl-93-functions
5042 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5043 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5044 (setq vhdl-packages
5045 (append vhdl-93-packages
5046 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5047 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5048 (setq vhdl-reserved-words
5049 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5050 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5051 '("")))
5052 (setq vhdl-keywords-regexp
5053 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5054 (setq vhdl-types-regexp
5055 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5056 (setq vhdl-attributes-regexp
5057 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5058 (setq vhdl-enum-values-regexp
5059 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5060 (setq vhdl-functions-regexp
5061 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5062 (setq vhdl-packages-regexp
5063 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5064 (setq vhdl-reserved-words-regexp
5065 (concat "\\<\\("
5066 (unless (equal vhdl-forbidden-syntax "")
5067 (concat vhdl-forbidden-syntax "\\|"))
5068 (regexp-opt vhdl-reserved-words)
5069 "\\)\\>"))
5070 (setq vhdl-directive-keywords-regexp
5071 (concat "\\<\\(" (mapconcat 'regexp-quote
5072 vhdl-directive-keywords "\\|") "\\)\\>"))
5073 (vhdl-abbrev-list-init))
5074
5075 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5076 ;; Words to expand
5077
5078 (defvar vhdl-abbrev-list nil
5079 "Predefined abbreviations for VHDL.")
5080
5081 (defun vhdl-abbrev-list-init ()
5082 (setq vhdl-abbrev-list
5083 (append
5084 (list vhdl-upper-case-keywords) vhdl-keywords
5085 (list vhdl-upper-case-types) vhdl-types
5086 (list vhdl-upper-case-attributes) vhdl-attributes
5087 (list vhdl-upper-case-enum-values) vhdl-enum-values
5088 (list vhdl-upper-case-constants) vhdl-constants
5089 (list nil) vhdl-functions
5090 (list nil) vhdl-packages)))
5091
5092 ;; initialize reserved words for VHDL Mode
5093 (vhdl-words-init)
5094
5095
5096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5097 ;;; Indentation
5098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5099
5100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5101 ;; Syntax analysis
5102
5103 ;; constant regular expressions for looking at various constructs
5104
5105 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5106 "Regexp describing a VHDL symbol.
5107 We cannot use just `word' syntax class since `_' cannot be in word
5108 class. Putting underscore in word class breaks forward word movement
5109 behavior that users are familiar with.")
5110
5111 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5112 "Regexp describing a case statement header key.")
5113
5114 (defconst vhdl-label-key
5115 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5116 "Regexp describing a VHDL label.")
5117
5118 ;; Macro definitions:
5119
5120 (defmacro vhdl-point (position)
5121 "Return the value of point at certain commonly referenced POSITIONs.
5122 POSITION can be one of the following symbols:
5123
5124 bol -- beginning of line
5125 eol -- end of line
5126 bod -- beginning of defun
5127 boi -- back to indentation
5128 eoi -- last whitespace on line
5129 ionl -- indentation of next line
5130 iopl -- indentation of previous line
5131 bonl -- beginning of next line
5132 bopl -- beginning of previous line
5133
5134 This function does not modify point or mark."
5135 (or (and (eq 'quote (car-safe position))
5136 (null (cddr position)))
5137 (error "ERROR: Bad buffer position requested: %s" position))
5138 (setq position (nth 1 position))
5139 `(let ((here (point)))
5140 ,@(cond
5141 ((eq position 'bol) '((beginning-of-line)))
5142 ((eq position 'eol) '((end-of-line)))
5143 ((eq position 'bod) '((save-match-data
5144 (vhdl-beginning-of-defun))))
5145 ((eq position 'boi) '((back-to-indentation)))
5146 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5147 ((eq position 'bonl) '((forward-line 1)))
5148 ((eq position 'bopl) '((forward-line -1)))
5149 ((eq position 'iopl)
5150 '((forward-line -1)
5151 (back-to-indentation)))
5152 ((eq position 'ionl)
5153 '((forward-line 1)
5154 (back-to-indentation)))
5155 (t (error "ERROR: Unknown buffer position requested: %s" position))
5156 )
5157 (prog1
5158 (point)
5159 (goto-char here))
5160 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5161 ;; doesn't hurt for v19
5162 ,@nil
5163 ))
5164
5165 (defmacro vhdl-safe (&rest body)
5166 "Safely execute BODY, return nil if an error occurred."
5167 `(condition-case nil
5168 (progn ,@body)
5169 (error nil)))
5170
5171 (defmacro vhdl-add-syntax (symbol &optional relpos)
5172 "A simple macro to append the syntax in SYMBOL to the syntax list.
5173 Try to increase performance by using this macro."
5174 `(setq vhdl-syntactic-context
5175 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5176
5177 (defmacro vhdl-has-syntax (symbol)
5178 "A simple macro to return check the syntax list.
5179 Try to increase performance by using this macro."
5180 `(assoc ,symbol vhdl-syntactic-context))
5181
5182 ;; Syntactic element offset manipulation:
5183
5184 (defun vhdl-read-offset (langelem)
5185 "Read new offset value for LANGELEM from minibuffer.
5186 Return a valid value only."
5187 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5188 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5189 (prompt "Offset: ")
5190 offset input interned)
5191 (while (not offset)
5192 (setq input (read-string prompt oldoff)
5193 offset (cond ((string-equal "+" input) '+)
5194 ((string-equal "-" input) '-)
5195 ((string-equal "++" input) '++)
5196 ((string-equal "--" input) '--)
5197 ((string-match "^-?[0-9]+$" input)
5198 (string-to-number input))
5199 ((fboundp (setq interned (intern input)))
5200 interned)
5201 ((boundp interned) interned)
5202 ;; error, but don't signal one, keep trying
5203 ;; to read an input value
5204 (t (ding)
5205 (setq prompt errmsg)
5206 nil))))
5207 offset))
5208
5209 (defun vhdl-set-offset (symbol offset &optional add-p)
5210 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5211 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5212 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5213 `vhdl-offsets-alist' if it doesn't already appear there."
5214 (interactive
5215 (let* ((langelem
5216 (intern (completing-read
5217 (concat "Syntactic symbol to change"
5218 (if current-prefix-arg " or add" "")
5219 ": ")
5220 (mapcar
5221 (function
5222 (lambda (langelem)
5223 (cons (format "%s" (car langelem)) nil)))
5224 vhdl-offsets-alist)
5225 nil (not current-prefix-arg)
5226 ;; initial contents tries to be the last element
5227 ;; on the syntactic analysis list for the current
5228 ;; line
5229 (let* ((syntax (vhdl-get-syntactic-context))
5230 (len (length syntax))
5231 (ic (format "%s" (car (nth (1- len) syntax)))))
5232 ic)
5233 )))
5234 (offset (vhdl-read-offset langelem)))
5235 (list langelem offset current-prefix-arg)))
5236 ;; sanity check offset
5237 (or (eq offset '+)
5238 (eq offset '-)
5239 (eq offset '++)
5240 (eq offset '--)
5241 (integerp offset)
5242 (fboundp offset)
5243 (boundp offset)
5244 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5245 offset))
5246 (let ((entry (assq symbol vhdl-offsets-alist)))
5247 (if entry
5248 (setcdr entry offset)
5249 (if add-p
5250 (setq vhdl-offsets-alist
5251 (cons (cons symbol offset) vhdl-offsets-alist))
5252 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5253 (vhdl-keep-region-active))
5254
5255 (defun vhdl-set-style (style &optional local)
5256 "Set `vhdl-mode' variables to use one of several different indentation styles.
5257 STYLE is a string representing the desired style and optional LOCAL is
5258 a flag which, if non-nil, means to make the style variables being
5259 changed buffer local, instead of the default, which is to set the
5260 global variables. Interactively, the flag comes from the prefix
5261 argument. The styles are chosen from the `vhdl-style-alist' variable."
5262 (interactive (list (completing-read "Use which VHDL indentation style? "
5263 vhdl-style-alist nil t)
5264 current-prefix-arg))
5265 (let ((vars (cdr (assoc style vhdl-style-alist))))
5266 (or vars
5267 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5268 ;; set all the variables
5269 (mapc
5270 (function
5271 (lambda (varentry)
5272 (let ((var (car varentry))
5273 (val (cdr varentry)))
5274 (and local
5275 (make-local-variable var))
5276 ;; special case for vhdl-offsets-alist
5277 (if (not (eq var 'vhdl-offsets-alist))
5278 (set var val)
5279 ;; reset vhdl-offsets-alist to the default value first
5280 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5281 ;; now set the langelems that are different
5282 (mapcar
5283 (function
5284 (lambda (langentry)
5285 (let ((langelem (car langentry))
5286 (offset (cdr langentry)))
5287 (vhdl-set-offset langelem offset)
5288 )))
5289 val))
5290 )))
5291 vars))
5292 (vhdl-keep-region-active))
5293
5294 (defun vhdl-get-offset (langelem)
5295 "Get offset from LANGELEM which is a cons cell of the form:
5296 \(SYMBOL . RELPOS). The symbol is matched against
5297 vhdl-offsets-alist and the offset found there is either returned,
5298 or added to the indentation at RELPOS. If RELPOS is nil, then
5299 the offset is simply returned."
5300 (let* ((symbol (car langelem))
5301 (relpos (cdr langelem))
5302 (match (assq symbol vhdl-offsets-alist))
5303 (offset (cdr-safe match)))
5304 ;; offset can be a number, a function, a variable, or one of the
5305 ;; symbols + or -
5306 (cond
5307 ((not match)
5308 (if vhdl-strict-syntax-p
5309 (error "ERROR: Don't know how to indent a %s" symbol)
5310 (setq offset 0
5311 relpos 0)))
5312 ((eq offset '+) (setq offset vhdl-basic-offset))
5313 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5314 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5315 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5316 ((and (not (numberp offset))
5317 (fboundp offset))
5318 (setq offset (funcall offset langelem)))
5319 ((not (numberp offset))
5320 (setq offset (eval offset)))
5321 )
5322 (+ (if (and relpos
5323 (< relpos (vhdl-point 'bol)))
5324 (save-excursion
5325 (goto-char relpos)
5326 (current-column))
5327 0)
5328 offset)))
5329
5330 ;; Syntactic support functions:
5331
5332 (defun vhdl-in-comment-p ()
5333 "Check if point is in a comment."
5334 (eq (vhdl-in-literal) 'comment))
5335
5336 (defun vhdl-in-string-p ()
5337 "Check if point is in a string."
5338 (eq (vhdl-in-literal) 'string))
5339
5340 (defun vhdl-in-literal ()
5341 "Determine if point is in a VHDL literal."
5342 (save-excursion
5343 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5344 (cond
5345 ((nth 3 state) 'string)
5346 ((nth 4 state) 'comment)
5347 ((vhdl-beginning-of-macro) 'pound)
5348 (t nil)))))
5349
5350 (defun vhdl-forward-comment (&optional direction)
5351 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5352 negative, skip forward otherwise."
5353 (interactive "p")
5354 (if (and direction (< direction 0))
5355 ;; skip backwards
5356 (progn
5357 (skip-chars-backward " \t\n")
5358 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5359 (goto-char (match-beginning 3))
5360 (skip-chars-backward " \t\n")))
5361 ;; skip forwards
5362 (skip-chars-forward " \t\n")
5363 (while (looking-at "--.*")
5364 (goto-char (match-end 0))
5365 (skip-chars-forward " \t\n"))))
5366
5367 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5368 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5369 (defalias 'vhdl-forward-comment 'forward-comment))
5370
5371 ;; This is the best we can do in Win-Emacs.
5372 (defun vhdl-win-il (&optional lim)
5373 "Determine if point is in a VHDL literal."
5374 (save-excursion
5375 (let* ((here (point))
5376 (state nil)
5377 (match nil)
5378 (lim (or lim (vhdl-point 'bod))))
5379 (goto-char lim )
5380 (while (< (point) here)
5381 (setq match
5382 (and (re-search-forward "--\\|[\"']"
5383 here 'move)
5384 (buffer-substring (match-beginning 0) (match-end 0))))
5385 (setq state
5386 (cond
5387 ;; no match
5388 ((null match) nil)
5389 ;; looking at the opening of a VHDL style comment
5390 ((string= "--" match)
5391 (if (<= here (progn (end-of-line) (point))) 'comment))
5392 ;; looking at the opening of a double quote string
5393 ((string= "\"" match)
5394 (if (not (save-restriction
5395 ;; this seems to be necessary since the
5396 ;; re-search-forward will not work without it
5397 (narrow-to-region (point) here)
5398 (re-search-forward
5399 ;; this regexp matches a double quote
5400 ;; which is preceded by an even number
5401 ;; of backslashes, including zero
5402 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5403 'string))
5404 ;; looking at the opening of a single quote string
5405 ((string= "'" match)
5406 (if (not (save-restriction
5407 ;; see comments from above
5408 (narrow-to-region (point) here)
5409 (re-search-forward
5410 ;; this matches a single quote which is
5411 ;; preceded by zero or two backslashes.
5412 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5413 here 'move)))
5414 'string))
5415 (t nil)))
5416 ) ; end-while
5417 state)))
5418
5419 (and (string-match "Win-Emacs" emacs-version)
5420 (fset 'vhdl-in-literal 'vhdl-win-il))
5421
5422 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5423 ;; defined as lexical whitespace or comments. Search no farther back
5424 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5425 ;; used for backward skipping, (point-max) is used for forward
5426 ;; skipping.
5427
5428 (defun vhdl-forward-syntactic-ws (&optional lim)
5429 "Forward skip of syntactic whitespace."
5430 (let* ((here (point-max))
5431 (hugenum (point-max)))
5432 (while (/= here (point))
5433 (setq here (point))
5434 (vhdl-forward-comment hugenum)
5435 ;; skip preprocessor directives
5436 (when (and (eq (char-after) ?#)
5437 (= (vhdl-point 'boi) (point)))
5438 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5439 (= (forward-line 1) 0)))
5440 (end-of-line)))
5441 (if lim (goto-char (min (point) lim)))))
5442
5443
5444 ;; This is the best we can do in Win-Emacs.
5445 (defun vhdl-win-fsws (&optional lim)
5446 "Forward skip syntactic whitespace for Win-Emacs."
5447 (let ((lim (or lim (point-max)))
5448 stop)
5449 (while (not stop)
5450 (skip-chars-forward " \t\n\r\f" lim)
5451 (cond
5452 ;; vhdl comment
5453 ((looking-at "--") (end-of-line))
5454 ;; none of the above
5455 (t (setq stop t))))))
5456
5457 (and (string-match "Win-Emacs" emacs-version)
5458 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5459
5460 (defun vhdl-beginning-of-macro (&optional lim)
5461 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5462 (let ((here (point)))
5463 (beginning-of-line)
5464 (while (eq (char-before (1- (point))) ?\\)
5465 (forward-line -1))
5466 (back-to-indentation)
5467 (if (and (<= (point) here)
5468 (eq (char-after) ?#))
5469 t
5470 (goto-char here)
5471 nil)))
5472
5473 (defun vhdl-backward-syntactic-ws (&optional lim)
5474 "Backward skip over syntactic whitespace."
5475 (let* ((here (point-min))
5476 (hugenum (- (point-max))))
5477 (while (/= here (point))
5478 (setq here (point))
5479 (vhdl-forward-comment hugenum)
5480 (vhdl-beginning-of-macro))
5481 (if lim (goto-char (max (point) lim)))))
5482
5483 ;; This is the best we can do in Win-Emacs.
5484 (defun vhdl-win-bsws (&optional lim)
5485 "Backward skip syntactic whitespace for Win-Emacs."
5486 (let ((lim (or lim (vhdl-point 'bod)))
5487 stop)
5488 (while (not stop)
5489 (skip-chars-backward " \t\n\r\f" lim)
5490 (cond
5491 ;; vhdl comment
5492 ((eq (vhdl-in-literal) 'comment)
5493 (skip-chars-backward "^-" lim)
5494 (skip-chars-backward "-" lim)
5495 (while (not (or (and (= (following-char) ?-)
5496 (= (char-after (1+ (point))) ?-))
5497 (<= (point) lim)))
5498 (skip-chars-backward "^-" lim)
5499 (skip-chars-backward "-" lim)))
5500 ;; none of the above
5501 (t (setq stop t))))))
5502
5503 (and (string-match "Win-Emacs" emacs-version)
5504 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5505
5506 ;; Functions to help finding the correct indentation column:
5507
5508 (defun vhdl-first-word (point)
5509 "If the keyword at POINT is at boi, then return (current-column) at
5510 that point, else nil."
5511 (save-excursion
5512 (and (goto-char point)
5513 (eq (point) (vhdl-point 'boi))
5514 (current-column))))
5515
5516 (defun vhdl-last-word (point)
5517 "If the keyword at POINT is at eoi, then return (current-column) at
5518 that point, else nil."
5519 (save-excursion
5520 (and (goto-char point)
5521 (save-excursion (or (eq (progn (forward-sexp) (point))
5522 (vhdl-point 'eoi))
5523 (looking-at "\\s-*\\(--\\)?")))
5524 (current-column))))
5525
5526 ;; Core syntactic evaluation functions:
5527
5528 (defconst vhdl-libunit-re
5529 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5530
5531 (defun vhdl-libunit-p ()
5532 (and
5533 (save-excursion
5534 (forward-sexp)
5535 (skip-chars-forward " \t\n")
5536 (not (looking-at "is\\b[^_]")))
5537 (save-excursion
5538 (backward-sexp)
5539 (and (not (looking-at "use\\b[^_]"))
5540 (progn
5541 (forward-sexp)
5542 (vhdl-forward-syntactic-ws)
5543 (/= (following-char) ?:))))
5544 ))
5545
5546 (defconst vhdl-defun-re
5547 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5548
5549 (defun vhdl-defun-p ()
5550 (save-excursion
5551 (if (looking-at "block\\|process\\|procedural")
5552 ;; "block", "process", "procedural":
5553 (save-excursion
5554 (backward-sexp)
5555 (not (looking-at "end\\s-+\\w")))
5556 ;; "architecture", "configuration", "entity",
5557 ;; "package", "procedure", "function":
5558 t)))
5559
5560 (defun vhdl-corresponding-defun ()
5561 "If the word at the current position corresponds to a \"defun\"
5562 keyword, then return a string that can be used to find the
5563 corresponding \"begin\" keyword, else return nil."
5564 (save-excursion
5565 (and (looking-at vhdl-defun-re)
5566 (vhdl-defun-p)
5567 (if (looking-at "block\\|process\\|procedural")
5568 ;; "block", "process". "procedural:
5569 (buffer-substring (match-beginning 0) (match-end 0))
5570 ;; "architecture", "configuration", "entity", "package",
5571 ;; "procedure", "function":
5572 "is"))))
5573
5574 (defconst vhdl-begin-fwd-re
5575 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5576 "A regular expression for searching forward that matches all known
5577 \"begin\" keywords.")
5578
5579 (defconst vhdl-begin-bwd-re
5580 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5581 "A regular expression for searching backward that matches all known
5582 \"begin\" keywords.")
5583
5584 (defun vhdl-begin-p (&optional lim)
5585 "Return t if we are looking at a real \"begin\" keyword.
5586 Assumes that the caller will make sure that we are looking at
5587 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5588 the middle of an identifier that just happens to contain a \"begin\"
5589 keyword."
5590 (cond
5591 ;; "[architecture|case|configuration|entity|package|
5592 ;; procedure|function] ... is":
5593 ((and (looking-at "i")
5594 (save-excursion
5595 ;; Skip backward over first sexp (needed to skip over a
5596 ;; procedure interface list, and is harmless in other
5597 ;; situations). Note that we need "return" in the
5598 ;; following search list so that we don't run into
5599 ;; semicolons in the function interface list.
5600 (backward-sexp)
5601 (let (foundp)
5602 (while (and (not foundp)
5603 (re-search-backward
5604 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5605 lim 'move))
5606 (if (or (= (preceding-char) ?_)
5607 (vhdl-in-literal))
5608 (backward-char)
5609 (setq foundp t))))
5610 (and (/= (following-char) ?\;)
5611 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5612 t)
5613 ;; "begin", "then":
5614 ((looking-at "be\\|t")
5615 t)
5616 ;; "else":
5617 ((and (looking-at "e")
5618 ;; make sure that the "else" isn't inside a
5619 ;; conditional signal assignment.
5620 (save-excursion
5621 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5622 (or (eq (following-char) ?\;)
5623 (eq (point) lim))))
5624 t)
5625 ;; "block", "generate", "loop", "process", "procedural",
5626 ;; "units", "record":
5627 ((and (looking-at "bl\\|[glpur]")
5628 (save-excursion
5629 (backward-sexp)
5630 (not (looking-at "end\\s-+\\w"))))
5631 t)
5632 ;; "component":
5633 ((and (looking-at "c")
5634 (save-excursion
5635 (backward-sexp)
5636 (not (looking-at "end\\s-+\\w")))
5637 ;; look out for the dreaded entity class in an attribute
5638 (save-excursion
5639 (vhdl-backward-syntactic-ws lim)
5640 (/= (preceding-char) ?:)))
5641 t)
5642 ;; "for" (inside configuration declaration):
5643 ((and (looking-at "f")
5644 (save-excursion
5645 (backward-sexp)
5646 (not (looking-at "end\\s-+\\w")))
5647 (vhdl-has-syntax 'configuration))
5648 t)
5649 ))
5650
5651 (defun vhdl-corresponding-mid (&optional lim)
5652 (cond
5653 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5654 "begin")
5655 ((looking-at "then")
5656 "<else>")
5657 (t
5658 "end")))
5659
5660 (defun vhdl-corresponding-end (&optional lim)
5661 "If the word at the current position corresponds to a \"begin\"
5662 keyword, then return a vector containing enough information to find
5663 the corresponding \"end\" keyword, else return nil. The keyword to
5664 search forward for is aref 0. The column in which the keyword must
5665 appear is aref 1 or nil if any column is suitable.
5666 Assumes that the caller will make sure that we are not in the middle
5667 of an identifier that just happens to contain a \"begin\" keyword."
5668 (save-excursion
5669 (and (looking-at vhdl-begin-fwd-re)
5670 (/= (preceding-char) ?_)
5671 (not (vhdl-in-literal))
5672 (vhdl-begin-p lim)
5673 (cond
5674 ;; "is", "generate", "loop":
5675 ((looking-at "[igl]")
5676 (vector "end"
5677 (and (vhdl-last-word (point))
5678 (or (vhdl-first-word (point))
5679 (save-excursion
5680 (vhdl-beginning-of-statement-1 lim)
5681 (vhdl-backward-skip-label lim)
5682 (vhdl-first-word (point)))))))
5683 ;; "begin", "else", "for":
5684 ((looking-at "be\\|[ef]")
5685 (vector "end"
5686 (and (vhdl-last-word (point))
5687 (or (vhdl-first-word (point))
5688 (save-excursion
5689 (vhdl-beginning-of-statement-1 lim)
5690 (vhdl-backward-skip-label lim)
5691 (vhdl-first-word (point)))))))
5692 ;; "component", "units", "record":
5693 ((looking-at "[cur]")
5694 ;; The first end found will close the block
5695 (vector "end" nil))
5696 ;; "block", "process", "procedural":
5697 ((looking-at "bl\\|p")
5698 (vector "end"
5699 (or (vhdl-first-word (point))
5700 (save-excursion
5701 (vhdl-beginning-of-statement-1 lim)
5702 (vhdl-backward-skip-label lim)
5703 (vhdl-first-word (point))))))
5704 ;; "then":
5705 ((looking-at "t")
5706 (vector "elsif\\|else\\|end\\s-+if"
5707 (and (vhdl-last-word (point))
5708 (or (vhdl-first-word (point))
5709 (save-excursion
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point)))))))
5713 ))))
5714
5715 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5716
5717 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5718
5719 (defun vhdl-end-p (&optional lim)
5720 "Return t if we are looking at a real \"end\" keyword.
5721 Assumes that the caller will make sure that we are looking at
5722 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5723 the middle of an identifier that just happens to contain an \"end\"
5724 keyword."
5725 (or (not (looking-at "else"))
5726 ;; make sure that the "else" isn't inside a conditional signal
5727 ;; assignment.
5728 (save-excursion
5729 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5730 (or (eq (following-char) ?\;)
5731 (eq (point) lim)
5732 (vhdl-in-literal)))))
5733
5734 (defun vhdl-corresponding-begin (&optional lim)
5735 "If the word at the current position corresponds to an \"end\"
5736 keyword, then return a vector containing enough information to find
5737 the corresponding \"begin\" keyword, else return nil. The keyword to
5738 search backward for is aref 0. The column in which the keyword must
5739 appear is aref 1 or nil if any column is suitable. The supplementary
5740 keyword to search forward for is aref 2 or nil if this is not
5741 required. If aref 3 is t, then the \"begin\" keyword may be found in
5742 the middle of a statement.
5743 Assumes that the caller will make sure that we are not in the middle
5744 of an identifier that just happens to contain an \"end\" keyword."
5745 (save-excursion
5746 (let (pos)
5747 (if (and (looking-at vhdl-end-fwd-re)
5748 (not (vhdl-in-literal))
5749 (vhdl-end-p lim))
5750 (if (looking-at "el")
5751 ;; "else", "elsif":
5752 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5753 ;; "end ...":
5754 (setq pos (point))
5755 (forward-sexp)
5756 (skip-chars-forward " \t\n")
5757 (cond
5758 ;; "end if":
5759 ((looking-at "if\\b[^_]")
5760 (vector "else\\|elsif\\|if"
5761 (vhdl-first-word pos)
5762 "else\\|then" nil))
5763 ;; "end component":
5764 ((looking-at "component\\b[^_]")
5765 (vector (buffer-substring (match-beginning 1)
5766 (match-end 1))
5767 (vhdl-first-word pos)
5768 nil nil))
5769 ;; "end units", "end record":
5770 ((looking-at "\\(units\\|record\\)\\b[^_]")
5771 (vector (buffer-substring (match-beginning 1)
5772 (match-end 1))
5773 (vhdl-first-word pos)
5774 nil t))
5775 ;; "end block", "end process", "end procedural":
5776 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5777 (vector "begin" (vhdl-first-word pos) nil nil))
5778 ;; "end case":
5779 ((looking-at "case\\b[^_]")
5780 (vector "case" (vhdl-first-word pos) "is" nil))
5781 ;; "end generate":
5782 ((looking-at "generate\\b[^_]")
5783 (vector "generate\\|for\\|if"
5784 (vhdl-first-word pos)
5785 "generate" nil))
5786 ;; "end loop":
5787 ((looking-at "loop\\b[^_]")
5788 (vector "loop\\|while\\|for"
5789 (vhdl-first-word pos)
5790 "loop" nil))
5791 ;; "end for" (inside configuration declaration):
5792 ((looking-at "for\\b[^_]")
5793 (vector "for" (vhdl-first-word pos) nil nil))
5794 ;; "end [id]":
5795 (t
5796 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5797 (vhdl-first-word pos)
5798 ;; return an alist of (statement . keyword) mappings
5799 '(
5800 ;; "begin ... end [id]":
5801 ("begin" . nil)
5802 ;; "architecture ... is ... begin ... end [id]":
5803 ("architecture" . "is")
5804 ;; "configuration ... is ... end [id]":
5805 ("configuration" . "is")
5806 ;; "entity ... is ... end [id]":
5807 ("entity" . "is")
5808 ;; "package ... is ... end [id]":
5809 ("package" . "is")
5810 ;; "procedure ... is ... begin ... end [id]":
5811 ("procedure" . "is")
5812 ;; "function ... is ... begin ... end [id]":
5813 ("function" . "is")
5814 )
5815 nil))
5816 ))) ; "end ..."
5817 )))
5818
5819 (defconst vhdl-leader-re
5820 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5821
5822 (defun vhdl-end-of-leader ()
5823 (save-excursion
5824 (cond ((looking-at "block\\|process\\|procedural")
5825 (if (save-excursion
5826 (forward-sexp)
5827 (skip-chars-forward " \t\n")
5828 (= (following-char) ?\())
5829 (forward-sexp 2)
5830 (forward-sexp))
5831 (when (looking-at "[ \t\n]*is")
5832 (goto-char (match-end 0)))
5833 (point))
5834 ((looking-at "component")
5835 (forward-sexp 2)
5836 (when (looking-at "[ \t\n]*is")
5837 (goto-char (match-end 0)))
5838 (point))
5839 ((looking-at "for")
5840 (forward-sexp 2)
5841 (skip-chars-forward " \t\n")
5842 (while (looking-at "[,:(]")
5843 (forward-sexp)
5844 (skip-chars-forward " \t\n"))
5845 (point))
5846 (t nil)
5847 )))
5848
5849 (defconst vhdl-trailer-re
5850 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5851
5852 (defconst vhdl-statement-fwd-re
5853 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5854 "A regular expression for searching forward that matches all known
5855 \"statement\" keywords.")
5856
5857 (defconst vhdl-statement-bwd-re
5858 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5859 "A regular expression for searching backward that matches all known
5860 \"statement\" keywords.")
5861
5862 (defun vhdl-statement-p (&optional lim)
5863 "Return t if we are looking at a real \"statement\" keyword.
5864 Assumes that the caller will make sure that we are looking at
5865 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5866 in the middle of an identifier that just happens to contain a
5867 \"statement\" keyword."
5868 (cond
5869 ;; "for" ... "generate":
5870 ((and (looking-at "f")
5871 ;; Make sure it's the start of a parameter specification.
5872 (save-excursion
5873 (forward-sexp 2)
5874 (skip-chars-forward " \t\n")
5875 (looking-at "in\\b[^_]"))
5876 ;; Make sure it's not an "end for".
5877 (save-excursion
5878 (backward-sexp)
5879 (not (looking-at "end\\s-+\\w"))))
5880 t)
5881 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5882 ((and (looking-at "i")
5883 ;; Make sure it's not an "end if".
5884 (save-excursion
5885 (backward-sexp)
5886 (not (looking-at "end\\s-+\\w"))))
5887 t)
5888 ;; "while" ... "loop":
5889 ((looking-at "w")
5890 t)
5891 ))
5892
5893 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5894 "Regexp describing a case statement alternative key.")
5895
5896 (defun vhdl-case-alternative-p (&optional lim)
5897 "Return t if we are looking at a real case alternative.
5898 Assumes that the caller will make sure that we are looking at
5899 vhdl-case-alternative-re, and are not inside a literal, and that
5900 we are not in the middle of an identifier that just happens to
5901 contain a \"when\" keyword."
5902 (save-excursion
5903 (let (foundp)
5904 (while (and (not foundp)
5905 (re-search-backward ";\\|<=" lim 'move))
5906 (if (or (= (preceding-char) ?_)
5907 (vhdl-in-literal))
5908 (backward-char)
5909 (setq foundp t)))
5910 (or (eq (following-char) ?\;)
5911 (eq (point) lim)))
5912 ))
5913
5914 ;; Core syntactic movement functions:
5915
5916 (defconst vhdl-b-t-b-re
5917 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5918
5919 (defun vhdl-backward-to-block (&optional lim)
5920 "Move backward to the previous \"begin\" or \"end\" keyword."
5921 (let (foundp)
5922 (while (and (not foundp)
5923 (re-search-backward vhdl-b-t-b-re lim 'move))
5924 (if (or (= (preceding-char) ?_)
5925 (vhdl-in-literal))
5926 (backward-char)
5927 (cond
5928 ;; "begin" keyword:
5929 ((and (looking-at vhdl-begin-fwd-re)
5930 (/= (preceding-char) ?_)
5931 (vhdl-begin-p lim))
5932 (setq foundp 'begin))
5933 ;; "end" keyword:
5934 ((and (looking-at vhdl-end-fwd-re)
5935 (/= (preceding-char) ?_)
5936 (vhdl-end-p lim))
5937 (setq foundp 'end))
5938 ))
5939 )
5940 foundp
5941 ))
5942
5943 (defun vhdl-forward-sexp (&optional count lim)
5944 "Move forward across one balanced expression (sexp).
5945 With COUNT, do it that many times."
5946 (interactive "p")
5947 (let ((count (or count 1))
5948 (case-fold-search t)
5949 end-vec target)
5950 (save-excursion
5951 (while (> count 0)
5952 ;; skip whitespace
5953 (skip-chars-forward " \t\n")
5954 ;; Check for an unbalanced "end" keyword
5955 (if (and (looking-at vhdl-end-fwd-re)
5956 (/= (preceding-char) ?_)
5957 (not (vhdl-in-literal))
5958 (vhdl-end-p lim)
5959 (not (looking-at "else")))
5960 (error
5961 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5962 ;; If the current keyword is a "begin" keyword, then find the
5963 ;; corresponding "end" keyword.
5964 (if (setq end-vec (vhdl-corresponding-end lim))
5965 (let (
5966 ;; end-re is the statement keyword to search for
5967 (end-re
5968 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5969 ;; column is either the statement keyword target column
5970 ;; or nil
5971 (column (aref end-vec 1))
5972 (eol (vhdl-point 'eol))
5973 foundp literal placeholder)
5974 ;; Look for the statement keyword.
5975 (while (and (not foundp)
5976 (re-search-forward end-re nil t)
5977 (setq placeholder (match-end 1))
5978 (goto-char (match-beginning 0)))
5979 ;; If we are in a literal, or not in the right target
5980 ;; column and not on the same line as the begin, then
5981 ;; try again.
5982 (if (or (and column
5983 (/= (current-indentation) column)
5984 (> (point) eol))
5985 (= (preceding-char) ?_)
5986 (setq literal (vhdl-in-literal)))
5987 (if (eq literal 'comment)
5988 (end-of-line)
5989 (forward-char))
5990 ;; An "else" keyword corresponds to both the opening brace
5991 ;; of the following sexp and the closing brace of the
5992 ;; previous sexp.
5993 (if (not (looking-at "else"))
5994 (goto-char placeholder))
5995 (setq foundp t))
5996 )
5997 (if (not foundp)
5998 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5999 )
6000 ;; If the current keyword is not a "begin" keyword, then just
6001 ;; perform the normal forward-sexp.
6002 (forward-sexp)
6003 )
6004 (setq count (1- count))
6005 )
6006 (setq target (point)))
6007 (goto-char target)
6008 nil))
6009
6010 (defun vhdl-backward-sexp (&optional count lim)
6011 "Move backward across one balanced expression (sexp).
6012 With COUNT, do it that many times. LIM bounds any required backward
6013 searches."
6014 (interactive "p")
6015 (let ((count (or count 1))
6016 (case-fold-search t)
6017 begin-vec target)
6018 (save-excursion
6019 (while (> count 0)
6020 ;; Perform the normal backward-sexp, unless we are looking at
6021 ;; "else" - an "else" keyword corresponds to both the opening brace
6022 ;; of the following sexp and the closing brace of the previous sexp.
6023 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6024 (/= (preceding-char) ?_)
6025 (not (vhdl-in-literal)))
6026 nil
6027 (backward-sexp)
6028 (if (and (looking-at vhdl-begin-fwd-re)
6029 (/= (preceding-char) ?_)
6030 (not (vhdl-in-literal))
6031 (vhdl-begin-p lim))
6032 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6033 ;; If the current keyword is an "end" keyword, then find the
6034 ;; corresponding "begin" keyword.
6035 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6036 (/= (preceding-char) ?_))
6037 (let (
6038 ;; begin-re is the statement keyword to search for
6039 (begin-re
6040 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6041 ;; column is either the statement keyword target column
6042 ;; or nil
6043 (column (aref begin-vec 1))
6044 ;; internal-p controls where the statement keyword can
6045 ;; be found.
6046 (internal-p (aref begin-vec 3))
6047 (last-backward (point)) last-forward
6048 foundp literal keyword)
6049 ;; Look for the statement keyword.
6050 (while (and (not foundp)
6051 (re-search-backward begin-re lim t)
6052 (setq keyword
6053 (buffer-substring (match-beginning 1)
6054 (match-end 1))))
6055 ;; If we are in a literal or in the wrong column,
6056 ;; then try again.
6057 (if (or (and column
6058 (and (/= (current-indentation) column)
6059 ;; possibly accept current-column as
6060 ;; well as current-indentation.
6061 (or (not internal-p)
6062 (/= (current-column) column))))
6063 (= (preceding-char) ?_)
6064 (vhdl-in-literal))
6065 (backward-char)
6066 ;; If there is a supplementary keyword, then
6067 ;; search forward for it.
6068 (if (and (setq begin-re (aref begin-vec 2))
6069 (or (not (listp begin-re))
6070 ;; If begin-re is an alist, then find the
6071 ;; element corresponding to the actual
6072 ;; keyword that we found.
6073 (progn
6074 (setq begin-re
6075 (assoc keyword begin-re))
6076 (and begin-re
6077 (setq begin-re (cdr begin-re))))))
6078 (and
6079 (setq begin-re
6080 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6081 (save-excursion
6082 (setq last-forward (point))
6083 ;; Look for the supplementary keyword
6084 ;; (bounded by the backward search start
6085 ;; point).
6086 (while (and (not foundp)
6087 (re-search-forward begin-re
6088 last-backward t)
6089 (goto-char (match-beginning 1)))
6090 ;; If we are in a literal, then try again.
6091 (if (or (= (preceding-char) ?_)
6092 (setq literal
6093 (vhdl-in-literal)))
6094 (if (eq literal 'comment)
6095 (goto-char
6096 (min (vhdl-point 'eol) last-backward))
6097 (forward-char))
6098 ;; We have found the supplementary keyword.
6099 ;; Save the position of the keyword in foundp.
6100 (setq foundp (point)))
6101 )
6102 foundp)
6103 ;; If the supplementary keyword was found, then
6104 ;; move point to the supplementary keyword.
6105 (goto-char foundp))
6106 ;; If there was no supplementary keyword, then
6107 ;; point is already at the statement keyword.
6108 (setq foundp t)))
6109 ) ; end of the search for the statement keyword
6110 (if (not foundp)
6111 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6112 ))
6113 (setq count (1- count))
6114 )
6115 (setq target (point)))
6116 (goto-char target)
6117 nil))
6118
6119 (defun vhdl-backward-up-list (&optional count limit)
6120 "Move backward out of one level of blocks.
6121 With argument, do this that many times."
6122 (interactive "p")
6123 (let ((count (or count 1))
6124 target)
6125 (save-excursion
6126 (while (> count 0)
6127 (if (looking-at vhdl-defun-re)
6128 (error "ERROR: Unbalanced blocks"))
6129 (vhdl-backward-to-block limit)
6130 (setq count (1- count)))
6131 (setq target (point)))
6132 (goto-char target)))
6133
6134 (defun vhdl-end-of-defun (&optional count)
6135 "Move forward to the end of a VHDL defun."
6136 (interactive)
6137 (let ((case-fold-search t))
6138 (vhdl-beginning-of-defun)
6139 (if (not (looking-at "block\\|process\\|procedural"))
6140 (re-search-forward "\\bis\\b"))
6141 (vhdl-forward-sexp)))
6142
6143 (defun vhdl-mark-defun ()
6144 "Put mark at end of this \"defun\", point at beginning."
6145 (interactive)
6146 (let ((case-fold-search t))
6147 (push-mark)
6148 (vhdl-beginning-of-defun)
6149 (push-mark)
6150 (if (not (looking-at "block\\|process\\|procedural"))
6151 (re-search-forward "\\bis\\b"))
6152 (vhdl-forward-sexp)
6153 (exchange-point-and-mark)))
6154
6155 (defun vhdl-beginning-of-libunit ()
6156 "Move backward to the beginning of a VHDL library unit.
6157 Returns the location of the corresponding begin keyword, unless search
6158 stops due to beginning or end of buffer.
6159 Note that if point is between the \"libunit\" keyword and the
6160 corresponding \"begin\" keyword, then that libunit will not be
6161 recognized, and the search will continue backwards. If point is
6162 at the \"begin\" keyword, then the defun will be recognized. The
6163 returned point is at the first character of the \"libunit\" keyword."
6164 (let ((last-forward (point))
6165 (last-backward
6166 ;; Just in case we are actually sitting on the "begin"
6167 ;; keyword, allow for the keyword and an extra character,
6168 ;; as this will be used when looking forward for the
6169 ;; "begin" keyword.
6170 (save-excursion (forward-word 1) (1+ (point))))
6171 foundp literal placeholder)
6172 ;; Find the "libunit" keyword.
6173 (while (and (not foundp)
6174 (re-search-backward vhdl-libunit-re nil 'move))
6175 ;; If we are in a literal, or not at a real libunit, then try again.
6176 (if (or (= (preceding-char) ?_)
6177 (vhdl-in-literal)
6178 (not (vhdl-libunit-p)))
6179 (backward-char)
6180 ;; Find the corresponding "begin" keyword.
6181 (setq last-forward (point))
6182 (while (and (not foundp)
6183 (re-search-forward "\\bis\\b[^_]" last-backward t)
6184 (setq placeholder (match-beginning 0)))
6185 (if (or (= (preceding-char) ?_)
6186 (setq literal (vhdl-in-literal)))
6187 ;; It wasn't a real keyword, so keep searching.
6188 (if (eq literal 'comment)
6189 (goto-char
6190 (min (vhdl-point 'eol) last-backward))
6191 (forward-char))
6192 ;; We have found the begin keyword, loop will exit.
6193 (setq foundp placeholder)))
6194 ;; Go back to the libunit keyword
6195 (goto-char last-forward)))
6196 foundp))
6197
6198 (defun vhdl-beginning-of-defun (&optional count)
6199 "Move backward to the beginning of a VHDL defun.
6200 With argument, do it that many times.
6201 Returns the location of the corresponding begin keyword, unless search
6202 stops due to beginning or end of buffer."
6203 ;; Note that if point is between the "defun" keyword and the
6204 ;; corresponding "begin" keyword, then that defun will not be
6205 ;; recognized, and the search will continue backwards. If point is
6206 ;; at the "begin" keyword, then the defun will be recognized. The
6207 ;; returned point is at the first character of the "defun" keyword.
6208 (interactive "p")
6209 (let ((count (or count 1))
6210 (case-fold-search t)
6211 (last-forward (point))
6212 foundp)
6213 (while (> count 0)
6214 (setq foundp nil)
6215 (goto-char last-forward)
6216 (let ((last-backward
6217 ;; Just in case we are actually sitting on the "begin"
6218 ;; keyword, allow for the keyword and an extra character,
6219 ;; as this will be used when looking forward for the
6220 ;; "begin" keyword.
6221 (save-excursion (forward-word 1) (1+ (point))))
6222 begin-string literal)
6223 (while (and (not foundp)
6224 (re-search-backward vhdl-defun-re nil 'move))
6225 ;; If we are in a literal, then try again.
6226 (if (or (= (preceding-char) ?_)
6227 (vhdl-in-literal))
6228 (backward-char)
6229 (if (setq begin-string (vhdl-corresponding-defun))
6230 ;; This is a real defun keyword.
6231 ;; Find the corresponding "begin" keyword.
6232 ;; Look for the begin keyword.
6233 (progn
6234 ;; Save the search start point.
6235 (setq last-forward (point))
6236 (while (and (not foundp)
6237 (search-forward begin-string last-backward t))
6238 (if (or (= (preceding-char) ?_)
6239 (save-match-data
6240 (setq literal (vhdl-in-literal))))
6241 ;; It wasn't a real keyword, so keep searching.
6242 (if (eq literal 'comment)
6243 (goto-char
6244 (min (vhdl-point 'eol) last-backward))
6245 (forward-char))
6246 ;; We have found the begin keyword, loop will exit.
6247 (setq foundp (match-beginning 0)))
6248 )
6249 ;; Go back to the defun keyword
6250 (goto-char last-forward)) ; end search for begin keyword
6251 ))
6252 ) ; end of the search for the defun keyword
6253 )
6254 (setq count (1- count))
6255 )
6256 (vhdl-keep-region-active)
6257 foundp))
6258
6259 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6260 "Go to the beginning of the innermost VHDL statement.
6261 With prefix arg, go back N - 1 statements. If already at the
6262 beginning of a statement then go to the beginning of the preceding
6263 one. If within a string or comment, or next to a comment (only
6264 whitespace between), move by sentences instead of statements.
6265
6266 When called from a program, this function takes 3 optional args: the
6267 prefix arg, a buffer position limit which is the farthest back to
6268 search, and an argument indicating an interactive call."
6269 (interactive "p\np")
6270 (let ((count (or count 1))
6271 (case-fold-search t)
6272 (lim (or lim (point-min)))
6273 (here (point))
6274 state)
6275 (save-excursion
6276 (goto-char lim)
6277 (setq state (parse-partial-sexp (point) here nil nil)))
6278 (if (and interactive
6279 (or (nth 3 state)
6280 (nth 4 state)
6281 (looking-at (concat "[ \t]*" comment-start-skip))))
6282 (forward-sentence (- count))
6283 (while (> count 0)
6284 (vhdl-beginning-of-statement-1 lim)
6285 (setq count (1- count))))
6286 ;; its possible we've been left up-buf of lim
6287 (goto-char (max (point) lim))
6288 )
6289 (vhdl-keep-region-active))
6290
6291 (defconst vhdl-e-o-s-re
6292 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6293
6294 (defun vhdl-end-of-statement ()
6295 "Very simple implementation."
6296 (interactive)
6297 (re-search-forward vhdl-e-o-s-re))
6298
6299 (defconst vhdl-b-o-s-re
6300 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6301 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6302
6303 (defun vhdl-beginning-of-statement-1 (&optional lim)
6304 "Move to the start of the current statement, or the previous
6305 statement if already at the beginning of one."
6306 (let ((lim (or lim (point-min)))
6307 (here (point))
6308 (pos (point))
6309 donep)
6310 ;; go backwards one balanced expression, but be careful of
6311 ;; unbalanced paren being reached
6312 (if (not (vhdl-safe (progn (backward-sexp) t)))
6313 (progn
6314 (backward-up-list 1)
6315 (forward-char)
6316 (vhdl-forward-syntactic-ws here)
6317 (setq donep t)))
6318 (while (and (not donep)
6319 (not (bobp))
6320 ;; look backwards for a statement boundary
6321 (re-search-backward vhdl-b-o-s-re lim 'move))
6322 (if (or (= (preceding-char) ?_)
6323 (vhdl-in-literal))
6324 (backward-char)
6325 (cond
6326 ;; If we are looking at an open paren, then stop after it
6327 ((eq (following-char) ?\()
6328 (forward-char)
6329 (vhdl-forward-syntactic-ws here)
6330 (setq donep t))
6331 ;; If we are looking at a close paren, then skip it
6332 ((eq (following-char) ?\))
6333 (forward-char)
6334 (setq pos (point))
6335 (backward-sexp)
6336 (if (< (point) lim)
6337 (progn (goto-char pos)
6338 (vhdl-forward-syntactic-ws here)
6339 (setq donep t))))
6340 ;; If we are looking at a semicolon, then stop
6341 ((eq (following-char) ?\;)
6342 (progn
6343 (forward-char)
6344 (vhdl-forward-syntactic-ws here)
6345 (setq donep t)))
6346 ;; If we are looking at a "begin", then stop
6347 ((and (looking-at vhdl-begin-fwd-re)
6348 (/= (preceding-char) ?_)
6349 (vhdl-begin-p nil))
6350 ;; If it's a leader "begin", then find the
6351 ;; right place
6352 (if (looking-at vhdl-leader-re)
6353 (save-excursion
6354 ;; set a default stop point at the begin
6355 (setq pos (point))
6356 ;; is the start point inside the leader area ?
6357 (goto-char (vhdl-end-of-leader))
6358 (vhdl-forward-syntactic-ws here)
6359 (if (< (point) here)
6360 ;; start point was not inside leader area
6361 ;; set stop point at word after leader
6362 (setq pos (point))))
6363 (forward-word 1)
6364 (vhdl-forward-syntactic-ws here)
6365 (setq pos (point)))
6366 (goto-char pos)
6367 (setq donep t))
6368 ;; If we are looking at a "statement", then stop
6369 ((and (looking-at vhdl-statement-fwd-re)
6370 (/= (preceding-char) ?_)
6371 (vhdl-statement-p nil))
6372 (setq donep t))
6373 ;; If we are looking at a case alternative key, then stop
6374 ((and (looking-at vhdl-case-alternative-re)
6375 (vhdl-case-alternative-p lim))
6376 (save-excursion
6377 ;; set a default stop point at the when
6378 (setq pos (point))
6379 ;; is the start point inside the case alternative key ?
6380 (looking-at vhdl-case-alternative-re)
6381 (goto-char (match-end 0))
6382 (vhdl-forward-syntactic-ws here)
6383 (if (< (point) here)
6384 ;; start point was not inside the case alternative key
6385 ;; set stop point at word after case alternative keyleader
6386 (setq pos (point))))
6387 (goto-char pos)
6388 (setq donep t))
6389 ;; Bogus find, continue
6390 (t
6391 (backward-char)))))
6392 ))
6393
6394 ;; Defuns for calculating the current syntactic state:
6395
6396 (defun vhdl-get-library-unit (bod placeholder)
6397 "If there is an enclosing library unit at BOD, with its \"begin\"
6398 keyword at PLACEHOLDER, then return the library unit type."
6399 (let ((here (vhdl-point 'bol)))
6400 (if (save-excursion
6401 (goto-char placeholder)
6402 (vhdl-safe (vhdl-forward-sexp 1 bod))
6403 (<= here (point)))
6404 (save-excursion
6405 (goto-char bod)
6406 (cond
6407 ((looking-at "e") 'entity)
6408 ((looking-at "a") 'architecture)
6409 ((looking-at "c") 'configuration)
6410 ((looking-at "p")
6411 (save-excursion
6412 (goto-char bod)
6413 (forward-sexp)
6414 (vhdl-forward-syntactic-ws here)
6415 (if (looking-at "body\\b[^_]")
6416 'package-body 'package))))))
6417 ))
6418
6419 (defun vhdl-get-block-state (&optional lim)
6420 "Finds and records all the closest opens.
6421 LIM is the furthest back we need to search (it should be the
6422 previous libunit keyword)."
6423 (let ((here (point))
6424 (lim (or lim (point-min)))
6425 keyword sexp-start sexp-mid sexp-end
6426 preceding-sexp containing-sexp
6427 containing-begin containing-mid containing-paren)
6428 (save-excursion
6429 ;; Find the containing-paren, and use that as the limit
6430 (if (setq containing-paren
6431 (save-restriction
6432 (narrow-to-region lim (point))
6433 (vhdl-safe (scan-lists (point) -1 1))))
6434 (setq lim containing-paren))
6435 ;; Look backwards for "begin" and "end" keywords.
6436 (while (and (> (point) lim)
6437 (not containing-sexp))
6438 (setq keyword (vhdl-backward-to-block lim))
6439 (cond
6440 ((eq keyword 'begin)
6441 ;; Found a "begin" keyword
6442 (setq sexp-start (point))
6443 (setq sexp-mid (vhdl-corresponding-mid lim))
6444 (setq sexp-end (vhdl-safe
6445 (save-excursion
6446 (vhdl-forward-sexp 1 lim) (point))))
6447 (if (and sexp-end (<= sexp-end here))
6448 ;; we want to record this sexp, but we only want to
6449 ;; record the last-most of any of them before here
6450 (or preceding-sexp
6451 (setq preceding-sexp sexp-start))
6452 ;; we're contained in this sexp so put sexp-start on
6453 ;; front of list
6454 (setq containing-sexp sexp-start)
6455 (setq containing-mid sexp-mid)
6456 (setq containing-begin t)))
6457 ((eq keyword 'end)
6458 ;; Found an "end" keyword
6459 (forward-sexp)
6460 (setq sexp-end (point))
6461 (setq sexp-mid nil)
6462 (setq sexp-start
6463 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6464 (progn (backward-sexp) (point))))
6465 ;; we want to record this sexp, but we only want to
6466 ;; record the last-most of any of them before here
6467 (or preceding-sexp
6468 (setq preceding-sexp sexp-start)))
6469 )))
6470 ;; Check if the containing-paren should be the containing-sexp
6471 (if (and containing-paren
6472 (or (null containing-sexp)
6473 (< containing-sexp containing-paren)))
6474 (setq containing-sexp containing-paren
6475 preceding-sexp nil
6476 containing-begin nil
6477 containing-mid nil))
6478 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6479 ))
6480
6481
6482 (defconst vhdl-s-c-a-re
6483 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6484
6485 (defun vhdl-skip-case-alternative (&optional lim)
6486 "Skip forward over case/when bodies, with optional maximal
6487 limit. If no next case alternative is found, nil is returned and
6488 point is not moved."
6489 (let ((lim (or lim (point-max)))
6490 (here (point))
6491 donep foundp)
6492 (while (and (< (point) lim)
6493 (not donep))
6494 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6495 (save-match-data
6496 (not (vhdl-in-literal)))
6497 (/= (match-beginning 0) here))
6498 (progn
6499 (goto-char (match-beginning 0))
6500 (cond
6501 ((and (looking-at "case")
6502 (re-search-forward "\\bis[^_]" lim t))
6503 (backward-sexp)
6504 (vhdl-forward-sexp))
6505 (t
6506 (setq donep t
6507 foundp t))))))
6508 (if (not foundp)
6509 (goto-char here))
6510 foundp))
6511
6512 (defun vhdl-backward-skip-label (&optional lim)
6513 "Skip backward over a label, with optional maximal
6514 limit. If label is not found, nil is returned and point
6515 is not moved."
6516 (let ((lim (or lim (point-min)))
6517 placeholder)
6518 (if (save-excursion
6519 (vhdl-backward-syntactic-ws lim)
6520 (and (eq (preceding-char) ?:)
6521 (progn
6522 (backward-sexp)
6523 (setq placeholder (point))
6524 (looking-at vhdl-label-key))))
6525 (goto-char placeholder))
6526 ))
6527
6528 (defun vhdl-forward-skip-label (&optional lim)
6529 "Skip forward over a label, with optional maximal
6530 limit. If label is not found, nil is returned and point
6531 is not moved."
6532 (let ((lim (or lim (point-max))))
6533 (if (looking-at vhdl-label-key)
6534 (progn
6535 (goto-char (match-end 0))
6536 (vhdl-forward-syntactic-ws lim)))
6537 ))
6538
6539 (defun vhdl-get-syntactic-context ()
6540 "Guess the syntactic description of the current line of VHDL code."
6541 (save-excursion
6542 (save-restriction
6543 (beginning-of-line)
6544 (let* ((indent-point (point))
6545 (case-fold-search t)
6546 vec literal containing-sexp preceding-sexp
6547 containing-begin containing-mid containing-leader
6548 char-before-ip char-after-ip begin-after-ip end-after-ip
6549 placeholder lim library-unit
6550 )
6551
6552 ;; Reset the syntactic context
6553 (setq vhdl-syntactic-context nil)
6554
6555 (save-excursion
6556 ;; Move to the start of the previous library unit, and
6557 ;; record the position of the "begin" keyword.
6558 (setq placeholder (vhdl-beginning-of-libunit))
6559 ;; The position of the "libunit" keyword gives us a gross
6560 ;; limit point.
6561 (setq lim (point))
6562 )
6563
6564 ;; If there is a previous library unit, and we are enclosed by
6565 ;; it, then set the syntax accordingly.
6566 (and placeholder
6567 (setq library-unit (vhdl-get-library-unit lim placeholder))
6568 (vhdl-add-syntax library-unit lim))
6569
6570 ;; Find the surrounding state.
6571 (if (setq vec (vhdl-get-block-state lim))
6572 (progn
6573 (setq containing-sexp (aref vec 0))
6574 (setq preceding-sexp (aref vec 1))
6575 (setq containing-begin (aref vec 2))
6576 (setq containing-mid (aref vec 3))
6577 ))
6578
6579 ;; set the limit on the farthest back we need to search
6580 (setq lim (if containing-sexp
6581 (save-excursion
6582 (goto-char containing-sexp)
6583 ;; set containing-leader if required
6584 (if (looking-at vhdl-leader-re)
6585 (setq containing-leader (vhdl-end-of-leader)))
6586 (vhdl-point 'bol))
6587 (point-min)))
6588
6589 ;; cache char before and after indent point, and move point to
6590 ;; the most likely position to perform the majority of tests
6591 (goto-char indent-point)
6592 (skip-chars-forward " \t")
6593 (setq literal (vhdl-in-literal))
6594 (setq char-after-ip (following-char))
6595 (setq begin-after-ip (and
6596 (not literal)
6597 (looking-at vhdl-begin-fwd-re)
6598 (vhdl-begin-p)))
6599 (setq end-after-ip (and
6600 (not literal)
6601 (looking-at vhdl-end-fwd-re)
6602 (vhdl-end-p)))
6603 (vhdl-backward-syntactic-ws lim)
6604 (setq char-before-ip (preceding-char))
6605 (goto-char indent-point)
6606 (skip-chars-forward " \t")
6607
6608 ;; now figure out syntactic qualities of the current line
6609 (cond
6610 ;; CASE 1: in a string or comment.
6611 ((memq literal '(string comment))
6612 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6613 ;; CASE 2: Line is at top level.
6614 ((null containing-sexp)
6615 ;; Find the point to which indentation will be relative
6616 (save-excursion
6617 (if (null preceding-sexp)
6618 ;; CASE 2X.1
6619 ;; no preceding-sexp -> use the preceding statement
6620 (vhdl-beginning-of-statement-1 lim)
6621 ;; CASE 2X.2
6622 ;; if there is a preceding-sexp then indent relative to it
6623 (goto-char preceding-sexp)
6624 ;; if not at boi, then the block-opening keyword is
6625 ;; probably following a label, so we need a different
6626 ;; relpos
6627 (if (/= (point) (vhdl-point 'boi))
6628 ;; CASE 2X.3
6629 (vhdl-beginning-of-statement-1 lim)))
6630 ;; v-b-o-s could have left us at point-min
6631 (and (bobp)
6632 ;; CASE 2X.4
6633 (vhdl-forward-syntactic-ws indent-point))
6634 (setq placeholder (point)))
6635 (cond
6636 ;; CASE 2A : we are looking at a block-open
6637 (begin-after-ip
6638 (vhdl-add-syntax 'block-open placeholder))
6639 ;; CASE 2B: we are looking at a block-close
6640 (end-after-ip
6641 (vhdl-add-syntax 'block-close placeholder))
6642 ;; CASE 2C: we are looking at a top-level statement
6643 ((progn
6644 (vhdl-backward-syntactic-ws lim)
6645 (or (bobp)
6646 (= (preceding-char) ?\;)))
6647 (vhdl-add-syntax 'statement placeholder))
6648 ;; CASE 2D: we are looking at a top-level statement-cont
6649 (t
6650 (vhdl-beginning-of-statement-1 lim)
6651 ;; v-b-o-s could have left us at point-min
6652 (and (bobp)
6653 ;; CASE 2D.1
6654 (vhdl-forward-syntactic-ws indent-point))
6655 (vhdl-add-syntax 'statement-cont (point)))
6656 )) ; end CASE 2
6657 ;; CASE 3: line is inside parentheses. Most likely we are
6658 ;; either in a subprogram argument (interface) list, or a
6659 ;; continued expression containing parentheses.
6660 ((null containing-begin)
6661 (vhdl-backward-syntactic-ws containing-sexp)
6662 (cond
6663 ;; CASE 3A: we are looking at the arglist closing paren
6664 ((eq char-after-ip ?\))
6665 (goto-char containing-sexp)
6666 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6667 ;; CASE 3B: we are looking at the first argument in an empty
6668 ;; argument list.
6669 ((eq char-before-ip ?\()
6670 (goto-char containing-sexp)
6671 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6672 ;; CASE 3C: we are looking at an arglist continuation line,
6673 ;; but the preceding argument is on the same line as the
6674 ;; opening paren. This case includes multi-line
6675 ;; expression paren groupings.
6676 ((and (save-excursion
6677 (goto-char (1+ containing-sexp))
6678 (skip-chars-forward " \t")
6679 (not (eolp))
6680 (not (looking-at "--")))
6681 (save-excursion
6682 (vhdl-beginning-of-statement-1 containing-sexp)
6683 (skip-chars-backward " \t(")
6684 (<= (point) containing-sexp)))
6685 (goto-char containing-sexp)
6686 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6687 ;; CASE 3D: we are looking at just a normal arglist
6688 ;; continuation line
6689 (t (vhdl-beginning-of-statement-1 containing-sexp)
6690 (vhdl-forward-syntactic-ws indent-point)
6691 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6692 ))
6693 ;; CASE 4: A block mid open
6694 ((and begin-after-ip
6695 (looking-at containing-mid))
6696 (goto-char containing-sexp)
6697 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6698 (if (looking-at vhdl-trailer-re)
6699 ;; CASE 4.1
6700 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6701 (vhdl-backward-skip-label (vhdl-point 'boi))
6702 (vhdl-add-syntax 'block-open (point)))
6703 ;; CASE 5: block close brace
6704 (end-after-ip
6705 (goto-char containing-sexp)
6706 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6707 (if (looking-at vhdl-trailer-re)
6708 ;; CASE 5.1
6709 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6710 (vhdl-backward-skip-label (vhdl-point 'boi))
6711 (vhdl-add-syntax 'block-close (point)))
6712 ;; CASE 6: A continued statement
6713 ((and (/= char-before-ip ?\;)
6714 ;; check it's not a trailer begin keyword, or a begin
6715 ;; keyword immediately following a label.
6716 (not (and begin-after-ip
6717 (or (looking-at vhdl-trailer-re)
6718 (save-excursion
6719 (vhdl-backward-skip-label containing-sexp)))))
6720 ;; check it's not a statement keyword
6721 (not (and (looking-at vhdl-statement-fwd-re)
6722 (vhdl-statement-p)))
6723 ;; see if the b-o-s is before the indent point
6724 (> indent-point
6725 (save-excursion
6726 (vhdl-beginning-of-statement-1 containing-sexp)
6727 ;; If we ended up after a leader, then this will
6728 ;; move us forward to the start of the first
6729 ;; statement. Note that a containing sexp here is
6730 ;; always a keyword, not a paren, so this will
6731 ;; have no effect if we hit the containing-sexp.
6732 (vhdl-forward-syntactic-ws indent-point)
6733 (setq placeholder (point))))
6734 ;; check it's not a block-intro
6735 (/= placeholder containing-sexp)
6736 ;; check it's not a case block-intro
6737 (save-excursion
6738 (goto-char placeholder)
6739 (or (not (looking-at vhdl-case-alternative-re))
6740 (> (match-end 0) indent-point))))
6741 ;; Make placeholder skip a label, but only if it puts us
6742 ;; before the indent point at the start of a line.
6743 (let ((new placeholder))
6744 (if (and (> indent-point
6745 (save-excursion
6746 (goto-char placeholder)
6747 (vhdl-forward-skip-label indent-point)
6748 (setq new (point))))
6749 (save-excursion
6750 (goto-char new)
6751 (eq new (progn (back-to-indentation) (point)))))
6752 (setq placeholder new)))
6753 (vhdl-add-syntax 'statement-cont placeholder)
6754 (if begin-after-ip
6755 (vhdl-add-syntax 'block-open)))
6756 ;; Statement. But what kind?
6757 ;; CASE 7: A case alternative key
6758 ((and (looking-at vhdl-case-alternative-re)
6759 (vhdl-case-alternative-p containing-sexp))
6760 ;; for a case alternative key, we set relpos to the first
6761 ;; non-whitespace char on the line containing the "case"
6762 ;; keyword.
6763 (goto-char containing-sexp)
6764 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6765 (if (looking-at vhdl-trailer-re)
6766 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6767 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6768 ;; CASE 8: statement catchall
6769 (t
6770 ;; we know its a statement, but we need to find out if it is
6771 ;; the first statement in a block
6772 (if containing-leader
6773 (goto-char containing-leader)
6774 (goto-char containing-sexp)
6775 ;; Note that a containing sexp here is always a keyword,
6776 ;; not a paren, so skip over the keyword.
6777 (forward-sexp))
6778 ;; move to the start of the first statement
6779 (vhdl-forward-syntactic-ws indent-point)
6780 (setq placeholder (point))
6781 ;; we want to ignore case alternatives keys when skipping forward
6782 (let (incase-p)
6783 (while (looking-at vhdl-case-alternative-re)
6784 (setq incase-p (point))
6785 ;; we also want to skip over the body of the
6786 ;; case/when statement if that doesn't put us at
6787 ;; after the indent-point
6788 (while (vhdl-skip-case-alternative indent-point))
6789 ;; set up the match end
6790 (looking-at vhdl-case-alternative-re)
6791 (goto-char (match-end 0))
6792 ;; move to the start of the first case alternative statement
6793 (vhdl-forward-syntactic-ws indent-point)
6794 (setq placeholder (point)))
6795 (cond
6796 ;; CASE 8A: we saw a case/when statement so we must be
6797 ;; in a switch statement. find out if we are at the
6798 ;; statement just after a case alternative key
6799 ((and incase-p
6800 (= (point) indent-point))
6801 ;; relpos is the "when" keyword
6802 (vhdl-add-syntax 'statement-case-intro incase-p))
6803 ;; CASE 8B: any old statement
6804 ((< (point) indent-point)
6805 ;; relpos is the first statement of the block
6806 (vhdl-add-syntax 'statement placeholder)
6807 (if begin-after-ip
6808 (vhdl-add-syntax 'block-open)))
6809 ;; CASE 8C: first statement in a block
6810 (t
6811 (goto-char containing-sexp)
6812 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6813 (if (looking-at vhdl-trailer-re)
6814 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6815 (vhdl-backward-skip-label (vhdl-point 'boi))
6816 (vhdl-add-syntax 'statement-block-intro (point))
6817 (if begin-after-ip
6818 (vhdl-add-syntax 'block-open)))
6819 )))
6820 )
6821
6822 ;; now we need to look at any modifiers
6823 (goto-char indent-point)
6824 (skip-chars-forward " \t")
6825 (if (looking-at "--")
6826 (vhdl-add-syntax 'comment))
6827 (if (eq literal 'pound)
6828 (vhdl-add-syntax 'cpp-macro))
6829 ;; return the syntax
6830 vhdl-syntactic-context))))
6831
6832 ;; Standard indentation line-ups:
6833
6834 (defun vhdl-lineup-arglist (langelem)
6835 "Lineup the current arglist line with the arglist appearing just
6836 after the containing paren which starts the arglist."
6837 (save-excursion
6838 (let* ((containing-sexp
6839 (save-excursion
6840 ;; arglist-cont-nonempty gives relpos ==
6841 ;; to boi of containing-sexp paren. This
6842 ;; is good when offset is +, but bad
6843 ;; when it is vhdl-lineup-arglist, so we
6844 ;; have to special case a kludge here.
6845 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6846 (progn
6847 (beginning-of-line)
6848 (backward-up-list 1)
6849 (skip-chars-forward " \t" (vhdl-point 'eol)))
6850 (goto-char (cdr langelem)))
6851 (point)))
6852 (cs-curcol (save-excursion
6853 (goto-char (cdr langelem))
6854 (current-column))))
6855 (if (save-excursion
6856 (beginning-of-line)
6857 (looking-at "[ \t]*)"))
6858 (progn (goto-char (match-end 0))
6859 (backward-sexp)
6860 (forward-char)
6861 (vhdl-forward-syntactic-ws)
6862 (- (current-column) cs-curcol))
6863 (goto-char containing-sexp)
6864 (or (eolp)
6865 (let ((eol (vhdl-point 'eol))
6866 (here (progn
6867 (forward-char)
6868 (skip-chars-forward " \t")
6869 (point))))
6870 (vhdl-forward-syntactic-ws)
6871 (if (< (point) eol)
6872 (goto-char here))))
6873 (- (current-column) cs-curcol)
6874 ))))
6875
6876 (defun vhdl-lineup-arglist-intro (langelem)
6877 "Lineup an arglist-intro line to just after the open paren."
6878 (save-excursion
6879 (let ((cs-curcol (save-excursion
6880 (goto-char (cdr langelem))
6881 (current-column)))
6882 (ce-curcol (save-excursion
6883 (beginning-of-line)
6884 (backward-up-list 1)
6885 (skip-chars-forward " \t" (vhdl-point 'eol))
6886 (current-column))))
6887 (- ce-curcol cs-curcol -1))))
6888
6889 (defun vhdl-lineup-comment (langelem)
6890 "Support old behavior for comment indentation. We look at
6891 vhdl-comment-only-line-offset to decide how to indent comment
6892 only-lines."
6893 (save-excursion
6894 (back-to-indentation)
6895 ;; at or to the right of comment-column
6896 (if (>= (current-column) comment-column)
6897 (vhdl-comment-indent)
6898 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6899 (if (not (bolp))
6900 (or (car-safe vhdl-comment-only-line-offset)
6901 vhdl-comment-only-line-offset)
6902 (or (cdr-safe vhdl-comment-only-line-offset)
6903 (car-safe vhdl-comment-only-line-offset)
6904 -1000 ;jam it against the left side
6905 )))))
6906
6907 (defun vhdl-lineup-statement-cont (langelem)
6908 "Line up statement-cont after the assignment operator."
6909 (save-excursion
6910 (let* ((relpos (cdr langelem))
6911 (assignp (save-excursion
6912 (goto-char (vhdl-point 'boi))
6913 (and (re-search-forward "\\(<\\|:\\)="
6914 (vhdl-point 'eol) t)
6915 (- (point) (vhdl-point 'boi)))))
6916 (curcol (progn
6917 (goto-char relpos)
6918 (current-column)))
6919 foundp)
6920 (while (and (not foundp)
6921 (< (point) (vhdl-point 'eol)))
6922 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6923 (if (vhdl-in-literal)
6924 (forward-char)
6925 (if (= (preceding-char) ?\()
6926 ;; skip over any parenthesized expressions
6927 (goto-char (min (vhdl-point 'eol)
6928 (scan-lists (point) 1 1)))
6929 ;; found an assignment operator (not at eol)
6930 (setq foundp (not (looking-at "\\s-*$"))))))
6931 (if (not foundp)
6932 ;; there's no assignment operator on the line
6933 vhdl-basic-offset
6934 ;; calculate indentation column after assign and ws, unless
6935 ;; our line contains an assignment operator
6936 (if (not assignp)
6937 (progn
6938 (forward-char)
6939 (skip-chars-forward " \t")
6940 (setq assignp 0)))
6941 (- (current-column) assignp curcol))
6942 )))
6943
6944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6945 ;; Progress reporting
6946
6947 (defvar vhdl-progress-info nil
6948 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6949
6950 (defun vhdl-update-progress-info (string pos)
6951 "Update progress information."
6952 (when (and vhdl-progress-info (not noninteractive)
6953 (< vhdl-progress-interval
6954 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6955 (let ((delta (- (aref vhdl-progress-info 1)
6956 (aref vhdl-progress-info 0))))
6957 (if (= 0 delta)
6958 (message (concat string "... (100%s)") "%")
6959 (message (concat string "... (%2d%s)")
6960 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6961 delta) "%")))
6962 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6963
6964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6965 ;; Indentation commands
6966
6967 (defun vhdl-electric-tab (&optional prefix-arg)
6968 "If preceeding character is part of a word or a paren then hippie-expand,
6969 else if right of non whitespace on line then insert tab,
6970 else if last command was a tab or return then dedent one step or if a comment
6971 toggle between normal indent and inline comment indent,
6972 else indent `correctly'."
6973 (interactive "*P")
6974 (vhdl-prepare-search-2
6975 (cond
6976 ;; indent region if region is active
6977 ((and (not (featurep 'xemacs)) (use-region-p))
6978 (vhdl-indent-region (region-beginning) (region-end) nil))
6979 ;; expand word
6980 ((= (char-syntax (preceding-char)) ?w)
6981 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6982 (case-replace nil)
6983 (hippie-expand-only-buffers
6984 (or (and (boundp 'hippie-expand-only-buffers)
6985 hippie-expand-only-buffers)
6986 '(vhdl-mode))))
6987 (vhdl-expand-abbrev prefix-arg)))
6988 ;; expand parenthesis
6989 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6990 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6991 (case-replace nil))
6992 (vhdl-expand-paren prefix-arg)))
6993 ;; insert tab
6994 ((> (current-column) (current-indentation))
6995 (insert-tab))
6996 ;; toggle comment indent
6997 ((and (looking-at "--")
6998 (or (eq last-command 'vhdl-electric-tab)
6999 (eq last-command 'vhdl-electric-return)))
7000 (cond ((= (current-indentation) 0) ; no indent
7001 (indent-to 1)
7002 (indent-according-to-mode))
7003 ((< (current-indentation) comment-column) ; normal indent
7004 (indent-to comment-column)
7005 (indent-according-to-mode))
7006 (t ; inline comment indent
7007 (delete-region (line-beginning-position) (point)))))
7008 ;; dedent
7009 ((and (>= (current-indentation) vhdl-basic-offset)
7010 (or (eq last-command 'vhdl-electric-tab)
7011 (eq last-command 'vhdl-electric-return)))
7012 (backward-delete-char-untabify vhdl-basic-offset nil))
7013 ;; indent line
7014 (t (indent-according-to-mode)))
7015 (setq this-command 'vhdl-electric-tab)))
7016
7017 (defun vhdl-electric-return ()
7018 "newline-and-indent or indent-new-comment-line if in comment and preceding
7019 character is a space."
7020 (interactive)
7021 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7022 (indent-new-comment-line)
7023 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7024 (vhdl-fix-case-word -1))
7025 (newline-and-indent)))
7026
7027 (defun vhdl-indent-line ()
7028 "Indent the current line as VHDL code. Returns the amount of
7029 indentation change."
7030 (interactive)
7031 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7032 (pos (- (point-max) (point)))
7033 (indent
7034 (if syntax
7035 ;; indent syntax-based
7036 (if (and (eq (caar syntax) 'comment)
7037 (>= (vhdl-get-offset (car syntax)) comment-column))
7038 ;; special case: comments at or right of comment-column
7039 (vhdl-get-offset (car syntax))
7040 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7041 ;; indent like previous nonblank line
7042 (save-excursion (beginning-of-line)
7043 (re-search-backward "^[^\n]" nil t)
7044 (current-indentation))))
7045 (shift-amt (- indent (current-indentation))))
7046 (and vhdl-echo-syntactic-information-p
7047 (message "syntax: %s, indent= %d" syntax indent))
7048 (unless (zerop shift-amt)
7049 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7050 (beginning-of-line)
7051 (indent-to indent))
7052 (if (< (point) (vhdl-point 'boi))
7053 (back-to-indentation)
7054 ;; If initial point was within line's indentation, position after
7055 ;; the indentation. Else stay at same point in text.
7056 (when (> (- (point-max) pos) (point))
7057 (goto-char (- (point-max) pos))))
7058 (run-hooks 'vhdl-special-indent-hook)
7059 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7060 shift-amt))
7061
7062 (defun vhdl-indent-region (beg end column)
7063 "Indent region as VHDL code.
7064 Adds progress reporting to `indent-region'."
7065 (interactive "r\nP")
7066 (when vhdl-progress-interval
7067 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7068 (count-lines (point-min) end) 0)))
7069 (indent-region beg end column)
7070 (when vhdl-progress-interval (message "Indenting...done"))
7071 (setq vhdl-progress-info nil))
7072
7073 (defun vhdl-indent-buffer ()
7074 "Indent whole buffer as VHDL code.
7075 Calls `indent-region' for whole buffer and adds progress reporting."
7076 (interactive)
7077 (vhdl-indent-region (point-min) (point-max) nil))
7078
7079 (defun vhdl-indent-group ()
7080 "Indent group of lines between empty lines."
7081 (interactive)
7082 (let ((beg (save-excursion
7083 (if (re-search-backward vhdl-align-group-separate nil t)
7084 (point-marker)
7085 (point-min-marker))))
7086 (end (save-excursion
7087 (if (re-search-forward vhdl-align-group-separate nil t)
7088 (point-marker)
7089 (point-max-marker)))))
7090 (vhdl-indent-region beg end nil)))
7091
7092 (defun vhdl-indent-sexp (&optional endpos)
7093 "Indent each line of the list starting just after point.
7094 If optional arg ENDPOS is given, indent each line, stopping when
7095 ENDPOS is encountered."
7096 (interactive)
7097 (save-excursion
7098 (let ((beg (point))
7099 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7100 (indent-region beg end nil))))
7101
7102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7103 ;; Miscellaneous commands
7104
7105 (defun vhdl-show-syntactic-information ()
7106 "Show syntactic information for current line."
7107 (interactive)
7108 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7109 (vhdl-keep-region-active))
7110
7111 ;; Verification and regression functions:
7112
7113 (defun vhdl-regress-line (&optional arg)
7114 "Check syntactic information for current line."
7115 (interactive "P")
7116 (let ((expected (save-excursion
7117 (end-of-line)
7118 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7119 (forward-char 4)
7120 (read (current-buffer)))))
7121 (actual (vhdl-get-syntactic-context))
7122 (expurgated))
7123 ;; remove the library unit symbols
7124 (mapc
7125 (function
7126 (lambda (elt)
7127 (if (memq (car elt) '(entity configuration package
7128 package-body architecture))
7129 nil
7130 (setq expurgated (append expurgated (list elt))))))
7131 actual)
7132 (if (and (not arg) expected (listp expected))
7133 (if (not (equal expected expurgated))
7134 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7135 (save-excursion
7136 (beginning-of-line)
7137 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7138 (end-of-line)
7139 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7140 (delete-region (point) (line-end-position)))
7141 (insert " -- ")
7142 (insert (format "%s" expurgated))))))
7143 (vhdl-keep-region-active))
7144
7145
7146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7147 ;;; Alignment, whitespace fixup, beautifying
7148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7149
7150 (defconst vhdl-align-alist
7151 '(
7152 ;; after some keywords
7153 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7154 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7155 ;; before ':'
7156 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7157 ;; after direction specifications
7158 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7159 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7160 ;; before "==", ":=", "=>", and "<="
7161 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7162 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7163 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7164 ;; before some keywords
7165 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7166 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7167 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7168 ;; before "=>" since "when/else ... =>" can occur
7169 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7170 )
7171 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7172 It is searched in order. If REGEXP is found anywhere in the first
7173 line of a region to be aligned, ALIGN-PATTERN will be used for that
7174 region. ALIGN-PATTERN must include the whitespace to be expanded or
7175 contracted. It may also provide regexps for the text surrounding the
7176 whitespace. SUBEXP specifies which sub-expression of
7177 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7178
7179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7180 ;; Align code
7181
7182 (defvar vhdl-align-try-all-clauses t
7183 "If REGEXP is not found on the first line of the region that clause
7184 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7185
7186 (defun vhdl-do-group (function &optional spacing)
7187 "Apply FUNCTION on group of lines between empty lines."
7188 (let
7189 ;; search for group beginning
7190 ((beg (save-excursion
7191 (if (re-search-backward vhdl-align-group-separate nil t)
7192 (progn (beginning-of-line 2) (back-to-indentation) (point))
7193 (point-min))))
7194 ;; search for group end
7195 (end (save-excursion
7196 (if (re-search-forward vhdl-align-group-separate nil t)
7197 (progn (beginning-of-line) (point))
7198 (point-max)))))
7199 ;; run FUNCTION
7200 (funcall function beg end spacing)))
7201
7202 (defun vhdl-do-list (function &optional spacing)
7203 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7204 parentheses."
7205 (let (beg end)
7206 (save-excursion
7207 ;; search for beginning of balanced group of parentheses
7208 (setq beg (vhdl-re-search-backward "[()]" nil t))
7209 (while (looking-at ")")
7210 (forward-char) (backward-sexp)
7211 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7212 ;; search for end of balanced group of parentheses
7213 (when beg
7214 (forward-list)
7215 (setq end (point))
7216 (goto-char (1+ beg))
7217 (skip-chars-forward " \t\n")
7218 (setq beg (point))))
7219 ;; run FUNCTION
7220 (if beg
7221 (funcall function beg end spacing)
7222 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7223
7224 (defun vhdl-do-same-indent (function &optional spacing)
7225 "Apply FUNCTION to block of lines with same indent."
7226 (let ((indent (current-indentation))
7227 beg end)
7228 ;; search for first line with same indent
7229 (save-excursion
7230 (while (and (not (bobp))
7231 (or (looking-at "^\\s-*\\(--.*\\)?$")
7232 (= (current-indentation) indent)))
7233 (unless (looking-at "^\\s-*$")
7234 (back-to-indentation) (setq beg (point)))
7235 (beginning-of-line -0)))
7236 ;; search for last line with same indent
7237 (save-excursion
7238 (while (and (not (eobp))
7239 (or (looking-at "^\\s-*\\(--.*\\)?$")
7240 (= (current-indentation) indent)))
7241 (if (looking-at "^\\s-*$")
7242 (beginning-of-line 2)
7243 (beginning-of-line 2)
7244 (setq end (point)))))
7245 ;; run FUNCTION
7246 (funcall function beg end spacing)))
7247
7248 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7249 "Attempt to align a range of lines based on the content of the
7250 lines. The definition of `alignment-list' determines the matching
7251 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7252 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7253 indentation is done before aligning."
7254 (interactive "r\np")
7255 (setq alignment-list (or alignment-list vhdl-align-alist))
7256 (setq spacing (or spacing 1))
7257 (save-excursion
7258 (let (bol indent)
7259 (goto-char end)
7260 (setq end (point-marker))
7261 (goto-char begin)
7262 (setq bol (setq begin (progn (beginning-of-line) (point))))
7263 ; (untabify bol end)
7264 (when indent
7265 (indent-region bol end nil))))
7266 (let ((copy (copy-alist alignment-list)))
7267 (vhdl-prepare-search-2
7268 (while copy
7269 (save-excursion
7270 (goto-char begin)
7271 (let (element
7272 (eol (point-at-eol)))
7273 (setq element (nth 0 copy))
7274 (when (and (or (and (listp (car element))
7275 (memq major-mode (car element)))
7276 (eq major-mode (car element)))
7277 (or vhdl-align-try-all-clauses
7278 (re-search-forward (car (cdr element)) eol t)))
7279 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7280 (car (cdr (cdr (cdr element)))) spacing))
7281 (setq copy (cdr copy))))))))
7282
7283 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7284 "Align a range of lines from BEGIN to END. The regular expression
7285 MATCH must match exactly one field: the whitespace to be
7286 contracted/expanded. The alignment column will equal the
7287 rightmost column of the widest whitespace block. SPACING is
7288 the amount of extra spaces to add to the calculated maximum required.
7289 SPACING defaults to 1 so that at least one space is inserted after
7290 the token in MATCH."
7291 (setq spacing (or spacing 1))
7292 (setq substr (or substr 1))
7293 (save-excursion
7294 (let (distance (max 0) (lines 0) bol eol width)
7295 ;; Determine the greatest whitespace distance to the alignment
7296 ;; character
7297 (goto-char begin)
7298 (setq eol (point-at-eol)
7299 bol (setq begin (progn (beginning-of-line) (point))))
7300 (while (< bol end)
7301 (save-excursion
7302 (when (and (re-search-forward match eol t)
7303 (not (vhdl-in-literal)))
7304 (setq distance (- (match-beginning substr) bol))
7305 (when (> distance max)
7306 (setq max distance))))
7307 (forward-line)
7308 (setq bol (point)
7309 eol (point-at-eol))
7310 (setq lines (1+ lines)))
7311 ;; Now insert enough maxs to push each assignment operator to
7312 ;; the same column. We need to use 'lines' as a counter, since
7313 ;; the location of the mark may change
7314 (goto-char (setq bol begin))
7315 (setq eol (point-at-eol))
7316 (while (> lines 0)
7317 (when (and (re-search-forward match eol t)
7318 (not (vhdl-in-literal)))
7319 (setq width (- (match-end substr) (match-beginning substr)))
7320 (setq distance (- (match-beginning substr) bol))
7321 (goto-char (match-beginning substr))
7322 (delete-char width)
7323 (insert-char ? (+ (- max distance) spacing)))
7324 (beginning-of-line)
7325 (forward-line)
7326 (setq bol (point)
7327 eol (point-at-eol))
7328 (setq lines (1- lines))))))
7329
7330 (defun vhdl-align-region-groups (beg end &optional spacing
7331 no-message no-comments)
7332 "Align region, treat groups of lines separately."
7333 (interactive "r\nP")
7334 (save-excursion
7335 (let (orig pos)
7336 (goto-char beg)
7337 (beginning-of-line)
7338 (setq orig (point-marker))
7339 (setq beg (point))
7340 (goto-char end)
7341 (setq end (point-marker))
7342 (untabify beg end)
7343 (unless no-message
7344 (when vhdl-progress-interval
7345 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7346 (count-lines (point-min) end) 0))))
7347 (vhdl-fixup-whitespace-region beg end t)
7348 (goto-char beg)
7349 (if (not vhdl-align-groups)
7350 ;; align entire region
7351 (progn (vhdl-align-region-1 beg end spacing)
7352 (unless no-comments
7353 (vhdl-align-inline-comment-region-1 beg end)))
7354 ;; align groups
7355 (while (and (< beg end)
7356 (re-search-forward vhdl-align-group-separate end t))
7357 (setq pos (point-marker))
7358 (vhdl-align-region-1 beg pos spacing)
7359 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7360 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7361 (setq beg (1+ pos))
7362 (goto-char beg))
7363 ;; align last group
7364 (when (< beg end)
7365 (vhdl-align-region-1 beg end spacing)
7366 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7367 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7368 (when vhdl-indent-tabs-mode
7369 (tabify orig end))
7370 (unless no-message
7371 (when vhdl-progress-interval (message "Aligning...done"))
7372 (setq vhdl-progress-info nil)))))
7373
7374 (defun vhdl-align-region (beg end &optional spacing)
7375 "Align region, treat blocks with same indent and argument lists separately."
7376 (interactive "r\nP")
7377 (if (not vhdl-align-same-indent)
7378 ;; align entire region
7379 (vhdl-align-region-groups beg end spacing)
7380 ;; align blocks with same indent and argument lists
7381 (save-excursion
7382 (let ((cur-beg beg)
7383 indent cur-end)
7384 (when vhdl-progress-interval
7385 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7386 (count-lines (point-min) end) 0)))
7387 (goto-char end)
7388 (setq end (point-marker))
7389 (goto-char cur-beg)
7390 (while (< (point) end)
7391 ;; is argument list opening?
7392 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7393 (point) (vhdl-point 'eol)))))
7394 ;; determine region for argument list
7395 (progn (goto-char cur-beg)
7396 (forward-sexp)
7397 (setq cur-end (point))
7398 (beginning-of-line 2))
7399 ;; determine region with same indent
7400 (setq indent (current-indentation))
7401 (setq cur-beg (point))
7402 (setq cur-end (vhdl-point 'bonl))
7403 (beginning-of-line 2)
7404 (while (and (< (point) end)
7405 (or (looking-at "^\\s-*\\(--.*\\)?$")
7406 (= (current-indentation) indent))
7407 (<= (save-excursion
7408 (nth 0 (parse-partial-sexp
7409 (point) (vhdl-point 'eol)))) 0))
7410 (unless (looking-at "^\\s-*$")
7411 (setq cur-end (vhdl-point 'bonl)))
7412 (beginning-of-line 2)))
7413 ;; align region
7414 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7415 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7416 (when vhdl-progress-interval (message "Aligning...done"))
7417 (setq vhdl-progress-info nil)))))
7418
7419 (defun vhdl-align-group (&optional spacing)
7420 "Align group of lines between empty lines."
7421 (interactive)
7422 (vhdl-do-group 'vhdl-align-region spacing))
7423
7424 (defun vhdl-align-list (&optional spacing)
7425 "Align the lines of a list surrounded by a balanced group of parentheses."
7426 (interactive)
7427 (vhdl-do-list 'vhdl-align-region-groups spacing))
7428
7429 (defun vhdl-align-same-indent (&optional spacing)
7430 "Align block of lines with same indent."
7431 (interactive)
7432 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7433
7434 (defun vhdl-align-declarations (&optional spacing)
7435 "Align the lines within the declarative part of a design unit."
7436 (interactive)
7437 (let (beg end)
7438 (vhdl-prepare-search-2
7439 (save-excursion
7440 ;; search for declarative part
7441 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7442 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7443 (setq beg (point))
7444 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7445 (setq end (point)))))
7446 (if beg
7447 (vhdl-align-region-groups beg end spacing)
7448 (error "ERROR: Not within the declarative part of a design unit"))))
7449
7450 (defun vhdl-align-buffer ()
7451 "Align buffer."
7452 (interactive)
7453 (vhdl-align-region (point-min) (point-max)))
7454
7455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7456 ;; Align inline comments
7457
7458 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7459 "Align inline comments in region."
7460 (save-excursion
7461 (let ((start-max comment-column)
7462 (length-max 0)
7463 comment-list start-list tmp-list start length
7464 cur-start prev-start no-code)
7465 (setq spacing (or spacing 2))
7466 (vhdl-prepare-search-2
7467 (goto-char beg)
7468 ;; search for comment start positions and lengths
7469 (while (< (point) end)
7470 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7471 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7472 (not (save-excursion (goto-char (match-beginning 2))
7473 (vhdl-in-literal))))
7474 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7475 (setq length (- (match-end 2) (match-beginning 2)))
7476 (setq start-max (max start start-max))
7477 (setq length-max (max length length-max))
7478 (setq comment-list (cons (cons start length) comment-list)))
7479 (beginning-of-line 2))
7480 (setq comment-list
7481 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7482 ;; reduce start positions
7483 (setq start-list (list (caar comment-list)))
7484 (setq comment-list (cdr comment-list))
7485 (while comment-list
7486 (unless (or (= (caar comment-list) (car start-list))
7487 (<= (+ (car start-list) (cdar comment-list))
7488 end-comment-column))
7489 (setq start-list (cons (caar comment-list) start-list)))
7490 (setq comment-list (cdr comment-list)))
7491 ;; align lines as nicely as possible
7492 (goto-char beg)
7493 (while (< (point) end)
7494 (setq cur-start nil)
7495 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7496 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7497 (not (save-excursion
7498 (goto-char (match-beginning 3))
7499 (vhdl-in-literal))))
7500 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7501 (>= (- (match-end 2) (match-beginning 2))
7502 comment-column))))
7503 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7504 (setq length (- (match-end 3) (match-beginning 3)))
7505 (setq no-code (= (match-beginning 1) (match-end 1)))
7506 ;; insert minimum whitespace
7507 (goto-char (match-end 2))
7508 (delete-region (match-beginning 2) (match-end 2))
7509 (insert-char ?\ spacing)
7510 (setq tmp-list start-list)
7511 ;; insert additional whitespace to align
7512 (setq cur-start
7513 (cond
7514 ;; align comment-only line to inline comment of previous line
7515 ((and no-code prev-start
7516 (<= length (- end-comment-column prev-start)))
7517 prev-start)
7518 ;; align all comments at `start-max' if this is possible
7519 ((<= (+ start-max length-max) end-comment-column)
7520 start-max)
7521 ;; align at `comment-column' if possible
7522 ((and (<= start comment-column)
7523 (<= length (- end-comment-column comment-column)))
7524 comment-column)
7525 ;; align at left-most possible start position otherwise
7526 (t
7527 (while (and tmp-list (< (car tmp-list) start))
7528 (setq tmp-list (cdr tmp-list)))
7529 (car tmp-list))))
7530 (indent-to cur-start))
7531 (setq prev-start cur-start)
7532 (beginning-of-line 2))))))
7533
7534 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7535 "Align inline comments within a region. Groups of code lines separated by
7536 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7537 (interactive "r\nP")
7538 (save-excursion
7539 (let (orig pos)
7540 (goto-char beg)
7541 (beginning-of-line)
7542 (setq orig (point-marker))
7543 (setq beg (point))
7544 (goto-char end)
7545 (setq end (point-marker))
7546 (untabify beg end)
7547 (unless no-message (message "Aligning inline comments..."))
7548 (goto-char beg)
7549 (if (not vhdl-align-groups)
7550 ;; align entire region
7551 (vhdl-align-inline-comment-region-1 beg end spacing)
7552 ;; align groups
7553 (while (and (< beg end)
7554 (re-search-forward vhdl-align-group-separate end t))
7555 (setq pos (point-marker))
7556 (vhdl-align-inline-comment-region-1 beg pos spacing)
7557 (setq beg (1+ pos))
7558 (goto-char beg))
7559 ;; align last group
7560 (when (< beg end)
7561 (vhdl-align-inline-comment-region-1 beg end spacing)))
7562 (when vhdl-indent-tabs-mode
7563 (tabify orig end))
7564 (unless no-message (message "Aligning inline comments...done")))))
7565
7566 (defun vhdl-align-inline-comment-group (&optional spacing)
7567 "Align inline comments within a group of lines between empty lines."
7568 (interactive)
7569 (save-excursion
7570 (let ((start (point))
7571 beg end)
7572 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7573 (point-marker) (point-max)))
7574 (goto-char start)
7575 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7576 (point) (point-min)))
7577 (untabify beg end)
7578 (message "Aligning inline comments...")
7579 (vhdl-align-inline-comment-region-1 beg end)
7580 (when vhdl-indent-tabs-mode
7581 (tabify beg end))
7582 (message "Aligning inline comments...done"))))
7583
7584 (defun vhdl-align-inline-comment-buffer ()
7585 "Align inline comments within buffer. Groups of code lines separated by
7586 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7587 (interactive)
7588 (vhdl-align-inline-comment-region (point-min) (point-max)))
7589
7590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7591 ;; Fixup whitespace
7592
7593 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7594 "Fixup whitespace in region. Surround operator symbols by one space,
7595 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7596 end of line, do nothing in comments and strings."
7597 (interactive "r")
7598 (unless no-message (message "Fixing up whitespace..."))
7599 (save-excursion
7600 (goto-char end)
7601 (setq end (point-marker))
7602 ;; have no space before and one space after `,' and ';'
7603 (goto-char beg)
7604 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7605 (if (match-string 1)
7606 (goto-char (match-end 1))
7607 (replace-match "\\3 " nil nil nil 3)))
7608 ;; have no space after `('
7609 (goto-char beg)
7610 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7611 (if (match-string 1)
7612 (goto-char (match-end 1))
7613 (replace-match "\\2")))
7614 ;; have no space before `)'
7615 (goto-char beg)
7616 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7617 (if (match-string 1)
7618 (goto-char (match-end 1))
7619 (replace-match "\\2")))
7620 ;; surround operator symbols by one space
7621 (goto-char beg)
7622 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7623 (if (match-string 1)
7624 (goto-char (match-end 1))
7625 (replace-match "\\3 \\4 \\5")
7626 (goto-char (match-end 2))))
7627 ;; eliminate multiple spaces and spaces at end of line
7628 (goto-char beg)
7629 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7630 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7631 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7632 (progn (replace-match "" nil nil) t))
7633 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7634 (progn (replace-match ";" nil nil) t))
7635 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7636 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7637 (progn (replace-match " " nil nil) t))
7638 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7639 (progn (replace-match " " nil nil) t))
7640 ; (re-search-forward "[^ \t-]+" end t))))
7641 (re-search-forward "[^ \t\"-]+" end t))))
7642 (unless no-message (message "Fixing up whitespace...done")))
7643
7644 (defun vhdl-fixup-whitespace-buffer ()
7645 "Fixup whitespace in buffer. Surround operator symbols by one space,
7646 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7647 end of line, do nothing in comments."
7648 (interactive)
7649 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7650
7651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7652 ;; Beautify
7653
7654 (defun vhdl-beautify-region (beg end)
7655 "Beautify region by applying indentation, whitespace fixup, alignment, and
7656 case fixing to a region. Calls functions `vhdl-indent-buffer',
7657 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7658 `vhdl-fix-case-buffer'."
7659 (interactive "r")
7660 (setq end (save-excursion (goto-char end) (point-marker)))
7661 (vhdl-indent-region beg end nil)
7662 (let ((vhdl-align-groups t))
7663 (vhdl-align-region beg end))
7664 (vhdl-fix-case-region beg end))
7665
7666 (defun vhdl-beautify-buffer ()
7667 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7668 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7669 buffer."
7670 (interactive)
7671 (vhdl-beautify-region (point-min) (point-max))
7672 (when noninteractive (save-buffer)))
7673
7674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7675 ;; Code filling
7676
7677 (defun vhdl-fill-region (beg end &optional arg)
7678 "Fill lines for a region of code."
7679 (interactive "r\np")
7680 (save-excursion
7681 (goto-char beg)
7682 (let ((margin (if arg (current-indentation) (current-column))))
7683 (goto-char end)
7684 (setq end (point-marker))
7685 ;; remove inline comments, newlines and whitespace
7686 (vhdl-comment-kill-region beg end)
7687 (vhdl-comment-kill-inline-region beg end)
7688 (subst-char-in-region beg (1- end) ?\n ?\ )
7689 (vhdl-fixup-whitespace-region beg end)
7690 ;; wrap and end-comment-column
7691 (goto-char beg)
7692 (while (re-search-forward "\\s-" end t)
7693 (when(> (current-column) vhdl-end-comment-column)
7694 (backward-char)
7695 (when (re-search-backward "\\s-" beg t)
7696 (replace-match "\n")
7697 (indent-to margin)))))))
7698
7699 (defun vhdl-fill-group ()
7700 "Fill group of lines between empty lines."
7701 (interactive)
7702 (vhdl-do-group 'vhdl-fill-region))
7703
7704 (defun vhdl-fill-list ()
7705 "Fill the lines of a list surrounded by a balanced group of parentheses."
7706 (interactive)
7707 (vhdl-do-list 'vhdl-fill-region))
7708
7709 (defun vhdl-fill-same-indent ()
7710 "Fill the lines of block of lines with same indent."
7711 (interactive)
7712 (vhdl-do-same-indent 'vhdl-fill-region))
7713
7714
7715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7716 ;;; Code updating/fixing
7717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7718
7719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7720 ;; Sensitivity list update
7721
7722 ;; Strategy:
7723 ;; - no sensitivity list is generated for processes with wait statements
7724 ;; - otherwise, do the following:
7725 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7726 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7727 ;; manually entered global signals)
7728 ;; 3. signals from 1. and 2. form the list of visible signals
7729 ;; 4. search for if/elsif conditions containing an event (sequential code)
7730 ;; 5. scan for strings that are within syntactical regions where signals are
7731 ;; read but not within sequential code, and that correspond to visible
7732 ;; signals
7733 ;; 6. replace sensitivity list by list of signals from 5.
7734
7735 (defun vhdl-update-sensitivity-list-process ()
7736 "Update sensitivity list of current process."
7737 (interactive)
7738 (save-excursion
7739 (vhdl-prepare-search-2
7740 (end-of-line)
7741 ;; look whether in process
7742 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7743 (equal (upcase (match-string 2)) "PROCESS")
7744 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7745 (error "ERROR: Not within a process")
7746 (message "Updating sensitivity list...")
7747 (vhdl-update-sensitivity-list)
7748 (message "Updating sensitivity list...done")))))
7749
7750 (defun vhdl-update-sensitivity-list-buffer ()
7751 "Update sensitivity list of all processes in current buffer."
7752 (interactive)
7753 (save-excursion
7754 (vhdl-prepare-search-2
7755 (goto-char (point-min))
7756 (message "Updating sensitivity lists...")
7757 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7758 (goto-char (match-beginning 0))
7759 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7760 (message "Updating sensitivity lists...done"))))
7761
7762 (defun vhdl-update-sensitivity-list ()
7763 "Update sensitivity list."
7764 (let ((proc-beg (point))
7765 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7766 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7767 seq-region-list)
7768 (cond
7769 ;; search for wait statement (no sensitivity list allowed)
7770 ((progn (goto-char proc-mid)
7771 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7772 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7773 ;; combinational process (update sensitivity list)
7774 (t
7775 (let
7776 ;; scan for visible signals
7777 ((visible-list (vhdl-get-visible-signals))
7778 ;; define syntactic regions where signals are read
7779 (scan-regions-list
7780 '(;; right-hand side of signal/variable assignment
7781 ;; (special case: "<=" is relational operator in a condition)
7782 ((re-search-forward "[<:]=" proc-end t)
7783 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7784 ;; if condition
7785 ((re-search-forward "^\\s-*if\\>" proc-end t)
7786 (re-search-forward "\\<then\\>" proc-end t))
7787 ;; elsif condition
7788 ((re-search-forward "\\<elsif\\>" proc-end t)
7789 (re-search-forward "\\<then\\>" proc-end t))
7790 ;; while loop condition
7791 ((re-search-forward "^\\s-*while\\>" proc-end t)
7792 (re-search-forward "\\<loop\\>" proc-end t))
7793 ;; exit/next condition
7794 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7795 (re-search-forward ";" proc-end t))
7796 ;; assert condition
7797 ((re-search-forward "\\<assert\\>" proc-end t)
7798 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7799 ;; case expression
7800 ((re-search-forward "^\\s-*case\\>" proc-end t)
7801 (re-search-forward "\\<is\\>" proc-end t))
7802 ;; parameter list of procedure call
7803 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7804 (1- (point)))
7805 (progn (backward-char) (forward-sexp)
7806 (while (looking-at "(") (forward-sexp)) (point)))))
7807 name read-list sens-list signal-list
7808 sens-beg sens-end beg end margin)
7809 ;; scan for signals in old sensitivity list
7810 (goto-char proc-beg)
7811 (re-search-forward "\\<process\\>" proc-mid t)
7812 (if (not (looking-at "[ \t\n]*("))
7813 (setq sens-beg (point))
7814 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7815 (goto-char (match-end 1))
7816 (forward-sexp)
7817 (setq sens-end (1- (point)))
7818 (goto-char sens-beg)
7819 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7820 (setq sens-list
7821 (cons (downcase (match-string 0)) sens-list))
7822 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7823 (setq signal-list (append visible-list sens-list))
7824 ;; search for sequential parts
7825 (goto-char proc-mid)
7826 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7827 (setq end (re-search-forward "\\<then\\>" proc-end t))
7828 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7829 (goto-char end)
7830 (backward-word 1)
7831 (vhdl-forward-sexp)
7832 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7833 (beginning-of-line)))
7834 ;; scan for signals read in process
7835 (while scan-regions-list
7836 (goto-char proc-mid)
7837 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7838 (setq end (eval (nth 1 (car scan-regions-list)))))
7839 (goto-char beg)
7840 (unless (or (vhdl-in-literal)
7841 (and seq-region-list
7842 (let ((tmp-list seq-region-list))
7843 (while (and tmp-list
7844 (< (point) (caar tmp-list)))
7845 (setq tmp-list (cdr tmp-list)))
7846 (and tmp-list (< (point) (cdar tmp-list))))))
7847 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7848 (setq name (match-string 1))
7849 (when (and (not (match-string 4)) ; not when formal parameter
7850 (not (and (match-string 3) ; not event attribute
7851 (not (member (downcase (match-string 3))
7852 '("event" "last_event" "transaction")))))
7853 (member (downcase name) signal-list))
7854 (unless (member-ignore-case name read-list)
7855 (setq read-list (cons name read-list))))
7856 (goto-char (match-end 1)))))
7857 (setq scan-regions-list (cdr scan-regions-list)))
7858 ;; update sensitivity list
7859 (goto-char sens-beg)
7860 (if sens-end
7861 (delete-region sens-beg sens-end)
7862 (when read-list
7863 (insert " ()") (backward-char)))
7864 (setq read-list (sort read-list 'string<))
7865 (when read-list
7866 (setq margin (current-column))
7867 (insert (car read-list))
7868 (setq read-list (cdr read-list))
7869 (while read-list
7870 (insert ",")
7871 (if (<= (+ (current-column) (length (car read-list)) 2)
7872 end-comment-column)
7873 (insert " ")
7874 (insert "\n") (indent-to margin))
7875 (insert (car read-list))
7876 (setq read-list (cdr read-list)))))))))
7877
7878 (defun vhdl-get-visible-signals ()
7879 "Get all signals visible in the current block."
7880 (let (beg end signal-list entity-name file-name)
7881 (vhdl-prepare-search-2
7882 ;; get entity name
7883 (save-excursion
7884 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7885 (not (equal "END" (upcase (match-string 1))))
7886 (setq entity-name (match-string 2)))
7887 (error "ERROR: Not within an architecture")))
7888 ;; search for signals declared in entity port clause
7889 (save-excursion
7890 (goto-char (point-min))
7891 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7892 (setq file-name
7893 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7894 "." (file-name-extension (buffer-file-name)))))
7895 (vhdl-visit-file
7896 file-name t
7897 (vhdl-prepare-search-2
7898 (goto-char (point-min))
7899 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7900 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7901 (when (setq beg (re-search-forward
7902 "^\\s-*port[ \t\n]*("
7903 (save-excursion
7904 (re-search-forward "^end\\>" nil t)) t))
7905 (setq end (save-excursion
7906 (backward-char) (forward-sexp) (point)))
7907 (vhdl-forward-syntactic-ws)
7908 (while (< (point) end)
7909 (when (looking-at "signal[ \t\n]+")
7910 (goto-char (match-end 0)))
7911 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7912 (setq signal-list
7913 (cons (downcase (match-string 1)) signal-list))
7914 (goto-char (match-end 0))
7915 (vhdl-forward-syntactic-ws))
7916 (re-search-forward ";" end 1)
7917 (vhdl-forward-syntactic-ws)))))))
7918 ;; search for signals declared in architecture declarative part
7919 (save-excursion
7920 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7921 (not (equal "END" (upcase (match-string 1))))
7922 (setq end (re-search-forward "^begin\\>" nil t))))
7923 (error "ERROR: No architecture declarative part found")
7924 ;; scan for all declared signal and alias names
7925 (goto-char beg)
7926 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7927 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7928 (if (match-string 2)
7929 ;; scan signal name
7930 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7931 (setq signal-list
7932 (cons (downcase (match-string 1)) signal-list))
7933 (goto-char (match-end 0)))
7934 ;; scan alias name, check is alias of (declared) signal
7935 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7936 (member (downcase (match-string 2)) signal-list))
7937 (setq signal-list
7938 (cons (downcase (match-string 1)) signal-list))
7939 (goto-char (match-end 0))))
7940 (setq beg (point))))))
7941 ;; search for signals declared in surrounding block declarative parts
7942 (save-excursion
7943 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7944 (match-string 2))
7945 (goto-char (match-end 2))
7946 (vhdl-backward-sexp)
7947 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7948 beg)
7949 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7950 ;; scan for all declared signal names
7951 (goto-char beg)
7952 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7953 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7954 (if (match-string 2)
7955 ;; scan signal name
7956 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7957 (setq signal-list
7958 (cons (downcase (match-string 1)) signal-list))
7959 (goto-char (match-end 0)))
7960 ;; scan alias name, check is alias of (declared) signal
7961 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7962 (member (downcase (match-string 2)) signal-list))
7963 (setq signal-list
7964 (cons (downcase (match-string 1)) signal-list))
7965 (goto-char (match-end 0))))))
7966 (goto-char beg)))
7967 signal-list)))
7968
7969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7970 ;; Generic/port clause fixing
7971
7972 (defun vhdl-fix-clause ()
7973 "Fix closing parenthesis within generic/port clause."
7974 (interactive)
7975 (save-excursion
7976 (vhdl-prepare-search-2
7977 (let ((pos (point))
7978 beg end)
7979 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7980 (error "ERROR: Not within a generic/port clause")
7981 ;; search for end of clause
7982 (goto-char (match-end 0))
7983 (setq beg (1- (point)))
7984 (vhdl-forward-syntactic-ws)
7985 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7986 (goto-char (1- (match-end 0)))
7987 (setq end (point-marker))
7988 (forward-char)
7989 (vhdl-forward-syntactic-ws))
7990 (goto-char end)
7991 (when (> pos (point-at-eol))
7992 (error "ERROR: Not within a generic/port clause"))
7993 ;; delete closing parenthesis on separate line (not supported style)
7994 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7995 (vhdl-line-kill)
7996 (vhdl-backward-syntactic-ws)
7997 (setq end (point-marker))
7998 (insert ";"))
7999 ;; delete superfluous parentheses
8000 (while (progn (goto-char beg)
8001 (condition-case () (forward-sexp)
8002 (error (goto-char (point-max))))
8003 (< (point) end))
8004 (delete-char -1))
8005 ;; add closing parenthesis
8006 (when (> (point) end)
8007 (goto-char end)
8008 (insert ")")))))))
8009
8010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8011 ;; Miscellaneous
8012
8013 (defun vhdl-remove-trailing-spaces ()
8014 "Remove trailing spaces in the whole buffer."
8015 (interactive)
8016 (save-match-data
8017 (save-excursion
8018 (goto-char (point-min))
8019 (while (re-search-forward "[ \t]+$" (point-max) t)
8020 (unless (vhdl-in-literal)
8021 (replace-match "" nil nil))))))
8022
8023
8024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8025 ;;; Electrification
8026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8027
8028 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8029 "Syntax of prompt inserted by template generators.")
8030
8031 (defvar vhdl-template-invoked-by-hook nil
8032 "Indicates whether a template has been invoked by a hook or by key or menu.
8033 Used for undoing after template abortion.")
8034
8035 ;; correct different behavior of function `unread-command-events' in XEmacs
8036 (defun vhdl-character-to-event (arg))
8037 (defalias 'vhdl-character-to-event
8038 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8039
8040 (defun vhdl-work-library ()
8041 "Return the working library name of the current project or \"work\" if no
8042 project is defined."
8043 (vhdl-resolve-env-variable
8044 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8045
8046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8047 ;; Enabling/disabling
8048
8049 (define-minor-mode vhdl-electric-mode
8050 "Toggle VHDL electric mode.
8051 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8052 :global t)
8053
8054 (define-minor-mode vhdl-stutter-mode
8055 "Toggle VHDL stuttering mode.
8056 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8057 :global t)
8058
8059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8060 ;; Stuttering
8061
8062 (defun vhdl-electric-dash (count)
8063 "-- starts a comment, --- draws a horizontal line,
8064 ---- starts a display comment."
8065 (interactive "p")
8066 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8067 (cond
8068 ((and abbrev-start-location (= abbrev-start-location (point)))
8069 (setq abbrev-start-location nil)
8070 (goto-char last-abbrev-location)
8071 (beginning-of-line nil)
8072 (vhdl-comment-display))
8073 ((/= (preceding-char) ?-) ; standard dash (minus)
8074 (self-insert-command count))
8075 (t (self-insert-command count)
8076 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8077 (let ((next-input (read-char)))
8078 (if (= next-input ?-) ; triple dash
8079 (progn
8080 (vhdl-comment-display-line)
8081 (message
8082 "Enter '-' for display comment, else continue coding")
8083 (let ((next-input (read-char)))
8084 (if (= next-input ?-) ; four dashes
8085 (vhdl-comment-display t)
8086 (setq unread-command-events ; pushback the char
8087 (list (vhdl-character-to-event next-input))))))
8088 (setq unread-command-events ; pushback the char
8089 (list (vhdl-character-to-event next-input)))
8090 (vhdl-comment-insert)))))
8091 (self-insert-command count)))
8092
8093 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8094 (interactive "p")
8095 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8096 (if (= (preceding-char) ?\()
8097 (progn (delete-char -1) (insert-char ?\[ 1))
8098 (insert-char ?\( 1))
8099 (self-insert-command count)))
8100
8101 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8102 (interactive "p")
8103 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8104 (progn
8105 (if (= (preceding-char) ?\))
8106 (progn (delete-char -1) (insert-char ?\] 1))
8107 (insert-char ?\) 1))
8108 (blink-matching-open))
8109 (self-insert-command count)))
8110
8111 (defun vhdl-electric-quote (count) "'' --> \""
8112 (interactive "p")
8113 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8114 (if (= (preceding-char) last-input-event)
8115 (progn (delete-char -1) (insert-char ?\" 1))
8116 (insert-char ?\' 1))
8117 (self-insert-command count)))
8118
8119 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8120 (interactive "p")
8121 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8122 (cond ((= (preceding-char) last-input-event)
8123 (progn (delete-char -1)
8124 (unless (eq (preceding-char) ? ) (insert " "))
8125 (insert ": ")
8126 (setq this-command 'vhdl-electric-colon)))
8127 ((and
8128 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8129 (progn (delete-char -1) (insert "= ")))
8130 (t (insert-char ?\; 1)))
8131 (self-insert-command count)))
8132
8133 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8134 (interactive "p")
8135 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8136 (cond ((= (preceding-char) last-input-event)
8137 (progn (delete-char -1)
8138 (unless (eq (preceding-char) ? ) (insert " "))
8139 (insert "<= ")))
8140 (t (insert-char ?\, 1)))
8141 (self-insert-command count)))
8142
8143 (defun vhdl-electric-period (count) "'..' --> ' => '"
8144 (interactive "p")
8145 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8146 (cond ((= (preceding-char) last-input-event)
8147 (progn (delete-char -1)
8148 (unless (eq (preceding-char) ? ) (insert " "))
8149 (insert "=> ")))
8150 (t (insert-char ?\. 1)))
8151 (self-insert-command count)))
8152
8153 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8154 (interactive "p")
8155 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8156 (cond ((= (preceding-char) last-input-event)
8157 (progn (delete-char -1)
8158 (unless (eq (preceding-char) ? ) (insert " "))
8159 (insert "== ")))
8160 (t (insert-char ?\= 1)))
8161 (self-insert-command count)))
8162
8163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8164 ;; VHDL templates
8165
8166 (defun vhdl-template-paired-parens ()
8167 "Insert a pair of round parentheses, placing point between them."
8168 (interactive)
8169 (insert "()")
8170 (backward-char))
8171
8172 (defun vhdl-template-alias ()
8173 "Insert alias declaration."
8174 (interactive)
8175 (let ((start (point)))
8176 (vhdl-insert-keyword "ALIAS ")
8177 (when (vhdl-template-field "name" nil t start (point))
8178 (insert " : ")
8179 (unless (vhdl-template-field
8180 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8181 nil t)
8182 (delete-char -3))
8183 (vhdl-insert-keyword " IS ")
8184 (vhdl-template-field "name" ";")
8185 (vhdl-comment-insert-inline))))
8186
8187 (defun vhdl-template-architecture ()
8188 "Insert architecture."
8189 (interactive)
8190 (let ((margin (current-indentation))
8191 (start (point))
8192 arch-name)
8193 (vhdl-insert-keyword "ARCHITECTURE ")
8194 (when (setq arch-name
8195 (vhdl-template-field "name" nil t start (point)))
8196 (vhdl-insert-keyword " OF ")
8197 (if (save-excursion
8198 (vhdl-prepare-search-1
8199 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8200 (insert (match-string 1))
8201 (vhdl-template-field "entity name"))
8202 (vhdl-insert-keyword " IS\n")
8203 (vhdl-template-begin-end
8204 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8205 (memq vhdl-insert-empty-lines '(unit all))))))
8206
8207 (defun vhdl-template-array (kind &optional secondary)
8208 "Insert array type definition."
8209 (interactive)
8210 (let ((start (point)))
8211 (vhdl-insert-keyword "ARRAY (")
8212 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8213 secondary)
8214 (vhdl-insert-keyword ") OF ")
8215 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8216 (vhdl-insert-keyword ";"))))
8217
8218 (defun vhdl-template-assert ()
8219 "Insert an assertion statement."
8220 (interactive)
8221 (let ((start (point)))
8222 (vhdl-insert-keyword "ASSERT ")
8223 (when vhdl-conditions-in-parenthesis (insert "("))
8224 (when (vhdl-template-field "condition (negated)" nil t start (point))
8225 (when vhdl-conditions-in-parenthesis (insert ")"))
8226 (setq start (point))
8227 (vhdl-insert-keyword " REPORT ")
8228 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8229 (delete-region start (point)))
8230 (setq start (point))
8231 (vhdl-insert-keyword " SEVERITY ")
8232 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8233 (delete-region start (point)))
8234 (insert ";"))))
8235
8236 (defun vhdl-template-attribute ()
8237 "Insert an attribute declaration or specification."
8238 (interactive)
8239 (if (eq (vhdl-decision-query
8240 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8241 (vhdl-template-attribute-spec)
8242 (vhdl-template-attribute-decl)))
8243
8244 (defun vhdl-template-attribute-decl ()
8245 "Insert an attribute declaration."
8246 (interactive)
8247 (let ((start (point)))
8248 (vhdl-insert-keyword "ATTRIBUTE ")
8249 (when (vhdl-template-field "name" " : " t start (point))
8250 (vhdl-template-field "type" ";")
8251 (vhdl-comment-insert-inline))))
8252
8253 (defun vhdl-template-attribute-spec ()
8254 "Insert an attribute specification."
8255 (interactive)
8256 (let ((start (point)))
8257 (vhdl-insert-keyword "ATTRIBUTE ")
8258 (when (vhdl-template-field "name" nil t start (point))
8259 (vhdl-insert-keyword " OF ")
8260 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8261 (vhdl-template-field "entity class")
8262 (vhdl-insert-keyword " IS ")
8263 (vhdl-template-field "expression" ";"))))
8264
8265 (defun vhdl-template-block ()
8266 "Insert a block."
8267 (interactive)
8268 (let ((margin (current-indentation))
8269 (start (point))
8270 label)
8271 (vhdl-insert-keyword ": BLOCK ")
8272 (goto-char start)
8273 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8274 (forward-word 1)
8275 (forward-char 1)
8276 (insert "(")
8277 (if (vhdl-template-field "[guard expression]" nil t)
8278 (insert ")")
8279 (delete-char -2))
8280 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8281 (insert "\n")
8282 (vhdl-template-begin-end "BLOCK" label margin)
8283 (vhdl-comment-block))))
8284
8285 (defun vhdl-template-block-configuration ()
8286 "Insert a block configuration statement."
8287 (interactive)
8288 (let ((margin (current-indentation))
8289 (start (point)))
8290 (vhdl-insert-keyword "FOR ")
8291 (when (vhdl-template-field "block name" nil t start (point))
8292 (vhdl-insert-keyword "\n\n")
8293 (indent-to margin)
8294 (vhdl-insert-keyword "END FOR;")
8295 (end-of-line 0)
8296 (indent-to (+ margin vhdl-basic-offset)))))
8297
8298 (defun vhdl-template-break ()
8299 "Insert a break statement."
8300 (interactive)
8301 (let (position)
8302 (vhdl-insert-keyword "BREAK")
8303 (setq position (point))
8304 (insert " ")
8305 (while (or
8306 (progn (vhdl-insert-keyword "FOR ")
8307 (if (vhdl-template-field "[quantity name]" " USE " t)
8308 (progn (vhdl-template-field "quantity name" " => ") t)
8309 (delete-region (point)
8310 (progn (forward-word -1) (point)))
8311 nil))
8312 (vhdl-template-field "[quantity name]" " => " t))
8313 (vhdl-template-field "expression")
8314 (setq position (point))
8315 (insert ", "))
8316 (delete-region position (point))
8317 (unless (vhdl-sequential-statement-p)
8318 (vhdl-insert-keyword " ON ")
8319 (if (vhdl-template-field "[sensitivity list]" nil t)
8320 (setq position (point))
8321 (delete-region position (point))))
8322 (vhdl-insert-keyword " WHEN ")
8323 (when vhdl-conditions-in-parenthesis (insert "("))
8324 (if (vhdl-template-field "[condition]" nil t)
8325 (when vhdl-conditions-in-parenthesis (insert ")"))
8326 (delete-region position (point)))
8327 (insert ";")))
8328
8329 (defun vhdl-template-case (&optional kind)
8330 "Insert a case statement."
8331 (interactive)
8332 (let ((margin (current-indentation))
8333 (start (point))
8334 label)
8335 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8336 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8337 (vhdl-insert-keyword "CASE ")
8338 (vhdl-insert-keyword ": CASE ")
8339 (goto-char start)
8340 (setq label (vhdl-template-field "[label]" nil t))
8341 (unless label (delete-char 2))
8342 (forward-word 1)
8343 (forward-char 1))
8344 (when (vhdl-template-field "expression" nil t start (point))
8345 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8346 (indent-to margin)
8347 (vhdl-insert-keyword "END CASE")
8348 (when label (insert " " label))
8349 (insert ";")
8350 (forward-line -1)
8351 (indent-to (+ margin vhdl-basic-offset))
8352 (vhdl-insert-keyword "WHEN ")
8353 (let ((position (point)))
8354 (insert " => ;\n")
8355 (indent-to (+ margin vhdl-basic-offset))
8356 (vhdl-insert-keyword "WHEN OTHERS => null;")
8357 (goto-char position)))))
8358
8359 (defun vhdl-template-case-is ()
8360 "Insert a sequential case statement."
8361 (interactive)
8362 (vhdl-template-case 'is))
8363
8364 (defun vhdl-template-case-use ()
8365 "Insert a simultaneous case statement."
8366 (interactive)
8367 (vhdl-template-case 'use))
8368
8369 (defun vhdl-template-component ()
8370 "Insert a component declaration."
8371 (interactive)
8372 (vhdl-template-component-decl))
8373
8374 (defun vhdl-template-component-conf ()
8375 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8376 since these are almost equivalent)."
8377 (interactive)
8378 (let ((margin (current-indentation))
8379 (result (vhdl-template-configuration-spec t)))
8380 (when result
8381 (insert "\n")
8382 (indent-to margin)
8383 (vhdl-insert-keyword "END FOR;")
8384 (when (eq result 'no-use)
8385 (end-of-line -0)))))
8386
8387 (defun vhdl-template-component-decl ()
8388 "Insert a component declaration."
8389 (interactive)
8390 (let ((margin (current-indentation))
8391 (start (point))
8392 name end-column)
8393 (vhdl-insert-keyword "COMPONENT ")
8394 (when (setq name (vhdl-template-field "name" nil t start (point)))
8395 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8396 (insert "\n\n")
8397 (indent-to margin)
8398 (vhdl-insert-keyword "END COMPONENT")
8399 (unless (vhdl-standard-p '87) (insert " " name))
8400 (insert ";")
8401 (setq end-column (current-column))
8402 (end-of-line -0)
8403 (indent-to (+ margin vhdl-basic-offset))
8404 (vhdl-template-generic-list t t)
8405 (insert "\n")
8406 (indent-to (+ margin vhdl-basic-offset))
8407 (vhdl-template-port-list t)
8408 (beginning-of-line 2)
8409 (forward-char end-column))))
8410
8411 (defun vhdl-template-component-inst ()
8412 "Insert a component instantiation statement."
8413 (interactive)
8414 (let ((margin (current-indentation))
8415 (start (point))
8416 unit position)
8417 (when (vhdl-template-field "instance label" nil t start (point))
8418 (insert ": ")
8419 (if (not (vhdl-use-direct-instantiation))
8420 (vhdl-template-field "component name")
8421 ;; direct instantiation
8422 (setq unit (vhdl-template-field
8423 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8424 (setq unit (upcase (or unit "")))
8425 (cond ((equal unit "ENTITY")
8426 (vhdl-template-field "library name" "." nil nil nil nil
8427 (vhdl-work-library))
8428 (vhdl-template-field "entity name" "(")
8429 (if (vhdl-template-field "[architecture name]" nil t)
8430 (insert ")")
8431 (delete-char -1)))
8432 ((equal unit "CONFIGURATION")
8433 (vhdl-template-field "library name" "." nil nil nil nil
8434 (vhdl-work-library))
8435 (vhdl-template-field "configuration name"))
8436 (t (vhdl-template-field "component name"))))
8437 (insert "\n")
8438 (indent-to (+ margin vhdl-basic-offset))
8439 (setq position (point))
8440 (vhdl-insert-keyword "GENERIC ")
8441 (when (vhdl-template-map position t t)
8442 (insert "\n")
8443 (indent-to (+ margin vhdl-basic-offset)))
8444 (setq position (point))
8445 (vhdl-insert-keyword "PORT ")
8446 (unless (vhdl-template-map position t t)
8447 (delete-region (line-beginning-position) (point))
8448 (delete-char -1))
8449 (insert ";"))))
8450
8451 (defun vhdl-template-conditional-signal-asst ()
8452 "Insert a conditional signal assignment."
8453 (interactive)
8454 (when (vhdl-template-field "target signal")
8455 (insert " <= ")
8456 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8457 ; (insert " "))
8458 (let ((margin (current-column))
8459 (start (point))
8460 position)
8461 (vhdl-template-field "waveform")
8462 (setq position (point))
8463 (vhdl-insert-keyword " WHEN ")
8464 (when vhdl-conditions-in-parenthesis (insert "("))
8465 (while (and (vhdl-template-field "[condition]" nil t)
8466 (progn
8467 (when vhdl-conditions-in-parenthesis (insert ")"))
8468 (setq position (point))
8469 (vhdl-insert-keyword " ELSE")
8470 (insert "\n")
8471 (indent-to margin)
8472 (vhdl-template-field "[waveform]" nil t)))
8473 (setq position (point))
8474 (vhdl-insert-keyword " WHEN ")
8475 (when vhdl-conditions-in-parenthesis (insert "(")))
8476 (delete-region position (point))
8477 (insert ";")
8478 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8479
8480 (defun vhdl-template-configuration ()
8481 "Insert a configuration specification if within an architecture,
8482 a block or component configuration if within a configuration declaration,
8483 a configuration declaration if not within a design unit."
8484 (interactive)
8485 (vhdl-prepare-search-1
8486 (cond
8487 ((and (save-excursion ; architecture body
8488 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8489 (equal "ARCHITECTURE" (upcase (match-string 1))))
8490 (vhdl-template-configuration-spec))
8491 ((and (save-excursion ; configuration declaration
8492 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8493 (equal "CONFIGURATION" (upcase (match-string 1))))
8494 (if (eq (vhdl-decision-query
8495 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8496 (vhdl-template-component-conf)
8497 (vhdl-template-block-configuration)))
8498 (t (vhdl-template-configuration-decl))))) ; otherwise
8499
8500 (defun vhdl-template-configuration-spec (&optional optional-use)
8501 "Insert a configuration specification."
8502 (interactive)
8503 (let ((margin (current-indentation))
8504 (start (point))
8505 aspect position)
8506 (vhdl-insert-keyword "FOR ")
8507 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8508 t start (point))
8509 (vhdl-template-field "component name" "\n")
8510 (indent-to (+ margin vhdl-basic-offset))
8511 (setq start (point))
8512 (vhdl-insert-keyword "USE ")
8513 (if (and optional-use
8514 (not (setq aspect (vhdl-template-field
8515 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8516 (progn (delete-region start (point)) 'no-use)
8517 (unless optional-use
8518 (setq aspect (vhdl-template-field
8519 "ENTITY | CONFIGURATION | OPEN" " ")))
8520 (setq aspect (upcase (or aspect "")))
8521 (cond ((equal aspect "ENTITY")
8522 (vhdl-template-field "library name" "." nil nil nil nil
8523 (vhdl-work-library))
8524 (vhdl-template-field "entity name" "(")
8525 (if (vhdl-template-field "[architecture name]" nil t)
8526 (insert ")")
8527 (delete-char -1))
8528 (insert "\n")
8529 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8530 (setq position (point))
8531 (vhdl-insert-keyword "GENERIC ")
8532 (when (vhdl-template-map position t t)
8533 (insert "\n")
8534 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8535 (setq position (point))
8536 (vhdl-insert-keyword "PORT ")
8537 (unless (vhdl-template-map position t t)
8538 (delete-region (line-beginning-position) (point))
8539 (delete-char -1))
8540 (insert ";")
8541 t)
8542 ((equal aspect "CONFIGURATION")
8543 (vhdl-template-field "library name" "." nil nil nil nil
8544 (vhdl-work-library))
8545 (vhdl-template-field "configuration name" ";"))
8546 (t (delete-char -1) (insert ";") t))))))
8547
8548
8549 (defun vhdl-template-configuration-decl ()
8550 "Insert a configuration declaration."
8551 (interactive)
8552 (let ((margin (current-indentation))
8553 (start (point))
8554 entity-exists string name position)
8555 (vhdl-insert-keyword "CONFIGURATION ")
8556 (when (setq name (vhdl-template-field "name" nil t start (point)))
8557 (vhdl-insert-keyword " OF ")
8558 (save-excursion
8559 (vhdl-prepare-search-1
8560 (setq entity-exists (vhdl-re-search-backward
8561 "\\<entity \\(\\w*\\) is\\>" nil t))
8562 (setq string (match-string 1))))
8563 (if (and entity-exists (not (equal string "")))
8564 (insert string)
8565 (vhdl-template-field "entity name"))
8566 (vhdl-insert-keyword " IS\n")
8567 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8568 (indent-to (+ margin vhdl-basic-offset))
8569 (setq position (point))
8570 (insert "\n")
8571 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8572 (indent-to margin)
8573 (vhdl-insert-keyword "END ")
8574 (unless (vhdl-standard-p '87)
8575 (vhdl-insert-keyword "CONFIGURATION "))
8576 (insert name ";")
8577 (goto-char position))))
8578
8579 (defun vhdl-template-constant ()
8580 "Insert a constant declaration."
8581 (interactive)
8582 (let ((start (point))
8583 (in-arglist (vhdl-in-argument-list-p)))
8584 (vhdl-insert-keyword "CONSTANT ")
8585 (when (vhdl-template-field "name" nil t start (point))
8586 (insert " : ")
8587 (when in-arglist (vhdl-insert-keyword "IN "))
8588 (vhdl-template-field "type")
8589 (if in-arglist
8590 (progn (insert ";")
8591 (vhdl-comment-insert-inline))
8592 (let ((position (point)))
8593 (insert " := ")
8594 (unless (vhdl-template-field "[initialization]" nil t)
8595 (delete-region position (point)))
8596 (insert ";")
8597 (vhdl-comment-insert-inline))))))
8598
8599 (defun vhdl-template-default ()
8600 "Insert nothing."
8601 (interactive)
8602 (insert " ")
8603 (unexpand-abbrev)
8604 (backward-word 1)
8605 (vhdl-case-word 1)
8606 (forward-char 1))
8607
8608 (defun vhdl-template-default-indent ()
8609 "Insert nothing and indent."
8610 (interactive)
8611 (insert " ")
8612 (unexpand-abbrev)
8613 (backward-word 1)
8614 (vhdl-case-word 1)
8615 (forward-char 1)
8616 (indent-according-to-mode))
8617
8618 (defun vhdl-template-disconnect ()
8619 "Insert a disconnect statement."
8620 (interactive)
8621 (let ((start (point)))
8622 (vhdl-insert-keyword "DISCONNECT ")
8623 (when (vhdl-template-field "signal names | OTHERS | ALL"
8624 " : " t start (point))
8625 (vhdl-template-field "type")
8626 (vhdl-insert-keyword " AFTER ")
8627 (vhdl-template-field "time expression" ";"))))
8628
8629 (defun vhdl-template-else ()
8630 "Insert an else statement."
8631 (interactive)
8632 (let (margin)
8633 (vhdl-prepare-search-1
8634 (vhdl-insert-keyword "ELSE")
8635 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8636 (equal "WHEN" (upcase (match-string 1))))
8637 (insert " ")
8638 (indent-according-to-mode)
8639 (setq margin (current-indentation))
8640 (insert "\n")
8641 (indent-to (+ margin vhdl-basic-offset))))))
8642
8643 (defun vhdl-template-elsif ()
8644 "Insert an elsif statement."
8645 (interactive)
8646 (let ((start (point))
8647 margin)
8648 (vhdl-insert-keyword "ELSIF ")
8649 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8650 (when vhdl-conditions-in-parenthesis (insert "("))
8651 (when (vhdl-template-field "condition" nil t start (point))
8652 (when vhdl-conditions-in-parenthesis (insert ")"))
8653 (indent-according-to-mode)
8654 (setq margin (current-indentation))
8655 (vhdl-insert-keyword
8656 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8657 (indent-to (+ margin vhdl-basic-offset))))))
8658
8659 (defun vhdl-template-entity ()
8660 "Insert an entity."
8661 (interactive)
8662 (let ((margin (current-indentation))
8663 (start (point))
8664 name end-column)
8665 (vhdl-insert-keyword "ENTITY ")
8666 (when (setq name (vhdl-template-field "name" nil t start (point)))
8667 (vhdl-insert-keyword " IS\n\n")
8668 (indent-to margin)
8669 (vhdl-insert-keyword "END ")
8670 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8671 (insert name ";")
8672 (setq end-column (current-column))
8673 (end-of-line -0)
8674 (indent-to (+ margin vhdl-basic-offset))
8675 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8676 (indent-to (+ margin vhdl-basic-offset))
8677 (when (vhdl-template-generic-list t)
8678 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8679 (insert "\n")
8680 (indent-to (+ margin vhdl-basic-offset))
8681 (when (vhdl-template-port-list t)
8682 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8683 (beginning-of-line 2)
8684 (forward-char end-column))))
8685
8686 (defun vhdl-template-exit ()
8687 "Insert an exit statement."
8688 (interactive)
8689 (let ((start (point)))
8690 (vhdl-insert-keyword "EXIT ")
8691 (if (vhdl-template-field "[loop label]" nil t start (point))
8692 (let ((position (point)))
8693 (vhdl-insert-keyword " WHEN ")
8694 (when vhdl-conditions-in-parenthesis (insert "("))
8695 (if (vhdl-template-field "[condition]" nil t)
8696 (when vhdl-conditions-in-parenthesis (insert ")"))
8697 (delete-region position (point))))
8698 (delete-char -1))
8699 (insert ";")))
8700
8701 (defun vhdl-template-file ()
8702 "Insert a file declaration."
8703 (interactive)
8704 (let ((start (point)))
8705 (vhdl-insert-keyword "FILE ")
8706 (when (vhdl-template-field "name" nil t start (point))
8707 (insert " : ")
8708 (vhdl-template-field "type")
8709 (unless (vhdl-standard-p '87)
8710 (vhdl-insert-keyword " OPEN ")
8711 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8712 nil t)
8713 (delete-char -6)))
8714 (vhdl-insert-keyword " IS ")
8715 (when (vhdl-standard-p '87)
8716 (vhdl-template-field "[IN | OUT]" " " t))
8717 (vhdl-template-field "filename-string" nil nil nil nil t)
8718 (insert ";")
8719 (vhdl-comment-insert-inline))))
8720
8721 (defun vhdl-template-for ()
8722 "Insert a block or component configuration if within a configuration
8723 declaration, a configuration specification if within an architecture
8724 declarative part (and not within a subprogram), a for-loop if within a
8725 sequential statement part (subprogram or process), and a for-generate
8726 otherwise."
8727 (interactive)
8728 (vhdl-prepare-search-1
8729 (cond
8730 ((vhdl-sequential-statement-p) ; sequential statement
8731 (vhdl-template-for-loop))
8732 ((and (save-excursion ; configuration declaration
8733 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8734 (equal "CONFIGURATION" (upcase (match-string 1))))
8735 (if (eq (vhdl-decision-query
8736 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8737 (vhdl-template-component-conf)
8738 (vhdl-template-block-configuration)))
8739 ((and (save-excursion
8740 (re-search-backward ; architecture declarative part
8741 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8742 (equal "ARCHITECTURE" (upcase (match-string 1))))
8743 (vhdl-template-configuration-spec))
8744 (t (vhdl-template-for-generate))))) ; concurrent statement
8745
8746 (defun vhdl-template-for-generate ()
8747 "Insert a for-generate."
8748 (interactive)
8749 (let ((margin (current-indentation))
8750 (start (point))
8751 label position)
8752 (vhdl-insert-keyword ": FOR ")
8753 (setq position (point-marker))
8754 (goto-char start)
8755 (when (setq label (vhdl-template-field "label" nil t start position))
8756 (goto-char position)
8757 (vhdl-template-field "loop variable")
8758 (vhdl-insert-keyword " IN ")
8759 (vhdl-template-field "range")
8760 (vhdl-template-generate-body margin label))))
8761
8762 (defun vhdl-template-for-loop ()
8763 "Insert a for loop."
8764 (interactive)
8765 (let ((margin (current-indentation))
8766 (start (point))
8767 label index)
8768 (if (not (eq vhdl-optional-labels 'all))
8769 (vhdl-insert-keyword "FOR ")
8770 (vhdl-insert-keyword ": FOR ")
8771 (goto-char start)
8772 (setq label (vhdl-template-field "[label]" nil t))
8773 (unless label (delete-char 2))
8774 (forward-word 1)
8775 (forward-char 1))
8776 (when (setq index (vhdl-template-field "loop variable"
8777 nil t start (point)))
8778 (vhdl-insert-keyword " IN ")
8779 (vhdl-template-field "range")
8780 (vhdl-insert-keyword " LOOP\n\n")
8781 (indent-to margin)
8782 (vhdl-insert-keyword "END LOOP")
8783 (if label
8784 (insert " " label ";")
8785 (insert ";")
8786 (when vhdl-self-insert-comments (insert " -- " index)))
8787 (forward-line -1)
8788 (indent-to (+ margin vhdl-basic-offset)))))
8789
8790 (defun vhdl-template-function (&optional kind)
8791 "Insert a function declaration or body."
8792 (interactive)
8793 (let ((margin (current-indentation))
8794 (start (point))
8795 name)
8796 (vhdl-insert-keyword "FUNCTION ")
8797 (when (setq name (vhdl-template-field "name" nil t start (point)))
8798 (vhdl-template-argument-list t)
8799 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8800 (end-of-line)
8801 (insert "\n")
8802 (indent-to (+ margin vhdl-basic-offset))
8803 (vhdl-insert-keyword "RETURN ")
8804 (vhdl-template-field "type")
8805 (if (if kind (eq kind 'body)
8806 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8807 (progn (vhdl-insert-keyword " IS\n")
8808 (vhdl-template-begin-end
8809 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8810 (vhdl-comment-block))
8811 (insert ";")))))
8812
8813 (defun vhdl-template-function-decl ()
8814 "Insert a function declaration."
8815 (interactive)
8816 (vhdl-template-function 'decl))
8817
8818 (defun vhdl-template-function-body ()
8819 "Insert a function declaration."
8820 (interactive)
8821 (vhdl-template-function 'body))
8822
8823 (defun vhdl-template-generate ()
8824 "Insert a generation scheme."
8825 (interactive)
8826 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8827 (vhdl-template-if-generate)
8828 (vhdl-template-for-generate)))
8829
8830 (defun vhdl-template-generic ()
8831 "Insert generic declaration, or generic map in instantiation statements."
8832 (interactive)
8833 (let ((start (point)))
8834 (vhdl-prepare-search-1
8835 (cond
8836 ((and (save-excursion ; entity declaration
8837 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8838 (equal "ENTITY" (upcase (match-string 1))))
8839 (vhdl-template-generic-list nil))
8840 ((or (save-excursion
8841 (or (beginning-of-line)
8842 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8843 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8844 (vhdl-insert-keyword "GENERIC ")
8845 (vhdl-template-map start))
8846 (t (vhdl-template-generic-list nil t))))))
8847
8848 (defun vhdl-template-group ()
8849 "Insert group or group template declaration."
8850 (interactive)
8851 (let ((start (point)))
8852 (if (eq (vhdl-decision-query
8853 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8854 (vhdl-template-group-template)
8855 (vhdl-template-group-decl))))
8856
8857 (defun vhdl-template-group-decl ()
8858 "Insert group declaration."
8859 (interactive)
8860 (let ((start (point)))
8861 (vhdl-insert-keyword "GROUP ")
8862 (when (vhdl-template-field "name" " : " t start (point))
8863 (vhdl-template-field "template name" " (")
8864 (vhdl-template-field "constituent list" ");")
8865 (vhdl-comment-insert-inline))))
8866
8867 (defun vhdl-template-group-template ()
8868 "Insert group template declaration."
8869 (interactive)
8870 (let ((start (point)))
8871 (vhdl-insert-keyword "GROUP ")
8872 (when (vhdl-template-field "template name" nil t start (point))
8873 (vhdl-insert-keyword " IS (")
8874 (vhdl-template-field "entity class list" ");")
8875 (vhdl-comment-insert-inline))))
8876
8877 (defun vhdl-template-if ()
8878 "Insert a sequential if statement or an if-generate statement."
8879 (interactive)
8880 (if (vhdl-sequential-statement-p)
8881 (vhdl-template-if-then)
8882 (if (and (vhdl-standard-p 'ams)
8883 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8884 (vhdl-template-if-use)
8885 (vhdl-template-if-generate))))
8886
8887 (defun vhdl-template-if-generate ()
8888 "Insert an if-generate."
8889 (interactive)
8890 (let ((margin (current-indentation))
8891 (start (point))
8892 label position)
8893 (vhdl-insert-keyword ": IF ")
8894 (setq position (point-marker))
8895 (goto-char start)
8896 (when (setq label (vhdl-template-field "label" nil t start position))
8897 (goto-char position)
8898 (when vhdl-conditions-in-parenthesis (insert "("))
8899 (vhdl-template-field "condition")
8900 (when vhdl-conditions-in-parenthesis (insert ")"))
8901 (vhdl-template-generate-body margin label))))
8902
8903 (defun vhdl-template-if-then-use (kind)
8904 "Insert a sequential if statement."
8905 (interactive)
8906 (let ((margin (current-indentation))
8907 (start (point))
8908 label)
8909 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8910 (vhdl-insert-keyword "IF ")
8911 (vhdl-insert-keyword ": IF ")
8912 (goto-char start)
8913 (setq label (vhdl-template-field "[label]" nil t))
8914 (unless label (delete-char 2))
8915 (forward-word 1)
8916 (forward-char 1))
8917 (when vhdl-conditions-in-parenthesis (insert "("))
8918 (when (vhdl-template-field "condition" nil t start (point))
8919 (when vhdl-conditions-in-parenthesis (insert ")"))
8920 (vhdl-insert-keyword
8921 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8922 (indent-to margin)
8923 (vhdl-insert-keyword "END IF")
8924 (when label (insert " " label))
8925 (insert ";")
8926 (forward-line -1)
8927 (indent-to (+ margin vhdl-basic-offset)))))
8928
8929 (defun vhdl-template-if-then ()
8930 "Insert a sequential if statement."
8931 (interactive)
8932 (vhdl-template-if-then-use 'then))
8933
8934 (defun vhdl-template-if-use ()
8935 "Insert a simultaneous if statement."
8936 (interactive)
8937 (vhdl-template-if-then-use 'use))
8938
8939 (defun vhdl-template-instance ()
8940 "Insert a component instantiation statement."
8941 (interactive)
8942 (vhdl-template-component-inst))
8943
8944 (defun vhdl-template-library ()
8945 "Insert a library specification."
8946 (interactive)
8947 (let ((margin (current-indentation))
8948 (start (point))
8949 name end-pos)
8950 (vhdl-insert-keyword "LIBRARY ")
8951 (when (setq name (vhdl-template-field "names" nil t start (point)))
8952 (insert ";")
8953 (unless (string-match "," name)
8954 (setq end-pos (point))
8955 (insert "\n")
8956 (indent-to margin)
8957 (vhdl-insert-keyword "USE ")
8958 (insert name)
8959 (vhdl-insert-keyword "..ALL;")
8960 (backward-char 5)
8961 (if (vhdl-template-field "package name")
8962 (forward-char 5)
8963 (delete-region end-pos (+ (point) 5)))))))
8964
8965 (defun vhdl-template-limit ()
8966 "Insert a limit."
8967 (interactive)
8968 (let ((start (point)))
8969 (vhdl-insert-keyword "LIMIT ")
8970 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8971 t start (point))
8972 (vhdl-template-field "type")
8973 (vhdl-insert-keyword " WITH ")
8974 (vhdl-template-field "real expression" ";"))))
8975
8976 (defun vhdl-template-loop ()
8977 "Insert a loop."
8978 (interactive)
8979 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8980 (cond ((eq char ?w)
8981 (vhdl-template-while-loop))
8982 ((eq char ?f)
8983 (vhdl-template-for-loop))
8984 (t (vhdl-template-bare-loop)))))
8985
8986 (defun vhdl-template-bare-loop ()
8987 "Insert a loop."
8988 (interactive)
8989 (let ((margin (current-indentation))
8990 (start (point))
8991 label)
8992 (if (not (eq vhdl-optional-labels 'all))
8993 (vhdl-insert-keyword "LOOP ")
8994 (vhdl-insert-keyword ": LOOP ")
8995 (goto-char start)
8996 (setq label (vhdl-template-field "[label]" nil t))
8997 (unless label (delete-char 2))
8998 (forward-word 1)
8999 (delete-char 1))
9000 (insert "\n\n")
9001 (indent-to margin)
9002 (vhdl-insert-keyword "END LOOP")
9003 (insert (if label (concat " " label ";") ";"))
9004 (forward-line -1)
9005 (indent-to (+ margin vhdl-basic-offset))))
9006
9007 (defun vhdl-template-map (&optional start optional secondary)
9008 "Insert a map specification with association list."
9009 (interactive)
9010 (let ((start (or start (point)))
9011 margin end-pos)
9012 (vhdl-insert-keyword "MAP (")
9013 (if (not vhdl-association-list-with-formals)
9014 (if (vhdl-template-field
9015 (concat (and optional "[") "association list" (and optional "]"))
9016 ")" (or (not secondary) optional)
9017 (and (not secondary) start) (point))
9018 t
9019 (if (and optional secondary) (delete-region start (point)))
9020 nil)
9021 (if vhdl-argument-list-indent
9022 (setq margin (current-column))
9023 (setq margin (+ (current-indentation) vhdl-basic-offset))
9024 (insert "\n")
9025 (indent-to margin))
9026 (if (vhdl-template-field
9027 (concat (and optional "[") "formal" (and optional "]"))
9028 " => " (or (not secondary) optional)
9029 (and (not secondary) start) (point))
9030 (progn
9031 (vhdl-template-field "actual" ",")
9032 (setq end-pos (point))
9033 (insert "\n")
9034 (indent-to margin)
9035 (while (vhdl-template-field "[formal]" " => " t)
9036 (vhdl-template-field "actual" ",")
9037 (setq end-pos (point))
9038 (insert "\n")
9039 (indent-to margin))
9040 (delete-region end-pos (point))
9041 (delete-char -1)
9042 (insert ")")
9043 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9044 t)
9045 (when (and optional secondary) (delete-region start (point)))
9046 nil))))
9047
9048 (defun vhdl-template-modify (&optional noerror)
9049 "Actualize modification date."
9050 (interactive)
9051 (vhdl-prepare-search-2
9052 (save-excursion
9053 (goto-char (point-min))
9054 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9055 (progn (delete-region (point) (progn (end-of-line) (point)))
9056 (vhdl-template-insert-date))
9057 (unless noerror
9058 (error "ERROR: Modification date prefix string \"%s\" not found"
9059 vhdl-modify-date-prefix-string))))))
9060
9061
9062 (defun vhdl-template-modify-noerror ()
9063 "Call `vhdl-template-modify' with NOERROR non-nil."
9064 (vhdl-template-modify t))
9065
9066 (defun vhdl-template-nature ()
9067 "Insert a nature declaration."
9068 (interactive)
9069 (let ((start (point))
9070 name mid-pos end-pos)
9071 (vhdl-insert-keyword "NATURE ")
9072 (when (setq name (vhdl-template-field "name" nil t start (point)))
9073 (vhdl-insert-keyword " IS ")
9074 (let ((definition
9075 (upcase
9076 (or (vhdl-template-field
9077 "across type | ARRAY | RECORD")
9078 ""))))
9079 (cond ((equal definition "")
9080 (insert ";"))
9081 ((equal definition "ARRAY")
9082 (delete-region (point) (progn (forward-word -1) (point)))
9083 (vhdl-template-array 'nature t))
9084 ((equal definition "RECORD")
9085 (setq mid-pos (point-marker))
9086 (delete-region (point) (progn (forward-word -1) (point)))
9087 (vhdl-template-record 'nature name t))
9088 (t
9089 (vhdl-insert-keyword " ACROSS ")
9090 (vhdl-template-field "through type")
9091 (vhdl-insert-keyword " THROUGH ")
9092 (vhdl-template-field "reference name")
9093 (vhdl-insert-keyword " REFERENCE;")))
9094 (when mid-pos
9095 (setq end-pos (point-marker))
9096 (goto-char mid-pos)
9097 (end-of-line))
9098 (vhdl-comment-insert-inline)
9099 (when end-pos (goto-char end-pos))))))
9100
9101 (defun vhdl-template-next ()
9102 "Insert a next statement."
9103 (interactive)
9104 (let ((start (point)))
9105 (vhdl-insert-keyword "NEXT ")
9106 (if (vhdl-template-field "[loop label]" nil t start (point))
9107 (let ((position (point)))
9108 (vhdl-insert-keyword " WHEN ")
9109 (when vhdl-conditions-in-parenthesis (insert "("))
9110 (if (vhdl-template-field "[condition]" nil t)
9111 (when vhdl-conditions-in-parenthesis (insert ")"))
9112 (delete-region position (point))))
9113 (delete-char -1))
9114 (insert ";")))
9115
9116 (defun vhdl-template-others ()
9117 "Insert an others aggregate."
9118 (interactive)
9119 (let ((start (point)))
9120 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9121 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9122 (vhdl-insert-keyword "OTHERS => '")
9123 (when (vhdl-template-field "value" nil t start (point))
9124 (insert "')")))
9125 (vhdl-insert-keyword "OTHERS "))))
9126
9127 (defun vhdl-template-package (&optional kind)
9128 "Insert a package specification or body."
9129 (interactive)
9130 (let ((margin (current-indentation))
9131 (start (point))
9132 name body position)
9133 (vhdl-insert-keyword "PACKAGE ")
9134 (setq body (if kind (eq kind 'body)
9135 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9136 (when body
9137 (vhdl-insert-keyword "BODY ")
9138 (when (save-excursion
9139 (vhdl-prepare-search-1
9140 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9141 (insert (setq name (match-string 1)))))
9142 (when (or name
9143 (setq name (vhdl-template-field "name" nil t start (point))))
9144 (vhdl-insert-keyword " IS\n")
9145 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9146 (indent-to (+ margin vhdl-basic-offset))
9147 (setq position (point))
9148 (insert "\n")
9149 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9150 (indent-to margin)
9151 (vhdl-insert-keyword "END ")
9152 (unless (vhdl-standard-p '87)
9153 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9154 (insert (or name "") ";")
9155 (goto-char position))))
9156
9157 (defun vhdl-template-package-decl ()
9158 "Insert a package specification."
9159 (interactive)
9160 (vhdl-template-package 'decl))
9161
9162 (defun vhdl-template-package-body ()
9163 "Insert a package body."
9164 (interactive)
9165 (vhdl-template-package 'body))
9166
9167 (defun vhdl-template-port ()
9168 "Insert a port declaration, or port map in instantiation statements."
9169 (interactive)
9170 (let ((start (point)))
9171 (vhdl-prepare-search-1
9172 (cond
9173 ((and (save-excursion ; entity declaration
9174 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9175 (equal "ENTITY" (upcase (match-string 1))))
9176 (vhdl-template-port-list nil))
9177 ((or (save-excursion
9178 (or (beginning-of-line)
9179 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9180 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9181 (vhdl-insert-keyword "PORT ")
9182 (vhdl-template-map start))
9183 (t (vhdl-template-port-list nil))))))
9184
9185 (defun vhdl-template-procedural ()
9186 "Insert a procedural."
9187 (interactive)
9188 (let ((margin (current-indentation))
9189 (start (point))
9190 (case-fold-search t)
9191 label)
9192 (vhdl-insert-keyword "PROCEDURAL ")
9193 (when (memq vhdl-optional-labels '(process all))
9194 (goto-char start)
9195 (insert ": ")
9196 (goto-char start)
9197 (setq label (vhdl-template-field "[label]" nil t))
9198 (unless label (delete-char 2))
9199 (forward-word 1)
9200 (forward-char 1))
9201 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9202 (insert "\n")
9203 (vhdl-template-begin-end "PROCEDURAL" label margin)
9204 (vhdl-comment-block)))
9205
9206 (defun vhdl-template-procedure (&optional kind)
9207 "Insert a procedure declaration or body."
9208 (interactive)
9209 (let ((margin (current-indentation))
9210 (start (point))
9211 name)
9212 (vhdl-insert-keyword "PROCEDURE ")
9213 (when (setq name (vhdl-template-field "name" nil t start (point)))
9214 (vhdl-template-argument-list)
9215 (if (if kind (eq kind 'body)
9216 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9217 (progn (vhdl-insert-keyword " IS")
9218 (when vhdl-auto-align
9219 (vhdl-align-region-groups start (point) 1))
9220 (end-of-line) (insert "\n")
9221 (vhdl-template-begin-end
9222 (unless (vhdl-standard-p '87) "PROCEDURE")
9223 name margin)
9224 (vhdl-comment-block))
9225 (insert ";")
9226 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9227 (end-of-line)))))
9228
9229 (defun vhdl-template-procedure-decl ()
9230 "Insert a procedure declaration."
9231 (interactive)
9232 (vhdl-template-procedure 'decl))
9233
9234 (defun vhdl-template-procedure-body ()
9235 "Insert a procedure body."
9236 (interactive)
9237 (vhdl-template-procedure 'body))
9238
9239 (defun vhdl-template-process (&optional kind)
9240 "Insert a process."
9241 (interactive)
9242 (let ((margin (current-indentation))
9243 (start (point))
9244 label seq input-signals clock reset final-pos)
9245 (setq seq (if kind (eq kind 'seq)
9246 (eq (vhdl-decision-query
9247 "process" "(c)ombinational or (s)equential?" t) ?s)))
9248 (vhdl-insert-keyword "PROCESS ")
9249 (when (memq vhdl-optional-labels '(process all))
9250 (goto-char start)
9251 (insert ": ")
9252 (goto-char start)
9253 (setq label (vhdl-template-field "[label]" nil t))
9254 (unless label (delete-char 2))
9255 (forward-word 1)
9256 (forward-char 1))
9257 (insert "(")
9258 (if (not seq)
9259 (unless (setq input-signals
9260 (vhdl-template-field "[sensitivity list]" ")" t))
9261 (setq input-signals "")
9262 (delete-char -2))
9263 (setq clock (or (and (not (equal "" vhdl-clock-name))
9264 (progn (insert vhdl-clock-name) vhdl-clock-name))
9265 (vhdl-template-field "clock name") "<clock>"))
9266 (when (eq vhdl-reset-kind 'async)
9267 (insert ", ")
9268 (setq reset (or (and (not (equal "" vhdl-reset-name))
9269 (progn (insert vhdl-reset-name) vhdl-reset-name))
9270 (vhdl-template-field "reset name") "<reset>")))
9271 (insert ")"))
9272 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9273 (insert "\n")
9274 (vhdl-template-begin-end "PROCESS" label margin)
9275 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9276 (when vhdl-prompt-for-comments
9277 (setq final-pos (point-marker))
9278 (vhdl-prepare-search-2
9279 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9280 (vhdl-re-search-backward "\\<process\\>" nil t))
9281 (end-of-line -0)
9282 (if (bobp)
9283 (progn (insert "\n") (forward-line -1))
9284 (insert "\n"))
9285 (indent-to margin)
9286 (insert "-- purpose: ")
9287 (if (not (vhdl-template-field "[description]" nil t))
9288 (vhdl-line-kill-entire)
9289 (insert "\n")
9290 (indent-to margin)
9291 (insert "-- type : ")
9292 (insert (if seq "sequential" "combinational") "\n")
9293 (indent-to margin)
9294 (insert "-- inputs : ")
9295 (if (not seq)
9296 (insert input-signals)
9297 (insert clock ", ")
9298 (when reset (insert reset ", "))
9299 (unless (vhdl-template-field "[signal names]" nil t)
9300 (delete-char -2)))
9301 (insert "\n")
9302 (indent-to margin)
9303 (insert "-- outputs: ")
9304 (vhdl-template-field "[signal names]" nil t))))
9305 (goto-char final-pos))))
9306
9307 (defun vhdl-template-process-comb ()
9308 "Insert a combinational process."
9309 (interactive)
9310 (vhdl-template-process 'comb))
9311
9312 (defun vhdl-template-process-seq ()
9313 "Insert a sequential process."
9314 (interactive)
9315 (vhdl-template-process 'seq))
9316
9317 (defun vhdl-template-quantity ()
9318 "Insert a quantity declaration."
9319 (interactive)
9320 (if (vhdl-in-argument-list-p)
9321 (let ((start (point)))
9322 (vhdl-insert-keyword "QUANTITY ")
9323 (when (vhdl-template-field "names" nil t start (point))
9324 (insert " : ")
9325 (vhdl-template-field "[IN | OUT]" " " t)
9326 (vhdl-template-field "type")
9327 (insert ";")
9328 (vhdl-comment-insert-inline)))
9329 (let ((char (vhdl-decision-query
9330 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9331 (cond ((eq char ?f) (vhdl-template-quantity-free))
9332 ((eq char ?b) (vhdl-template-quantity-branch))
9333 ((eq char ?s) (vhdl-template-quantity-source))
9334 (t (vhdl-template-undo (point) (point)))))))
9335
9336 (defun vhdl-template-quantity-free ()
9337 "Insert a free quantity declaration."
9338 (interactive)
9339 (vhdl-insert-keyword "QUANTITY ")
9340 (vhdl-template-field "names")
9341 (insert " : ")
9342 (vhdl-template-field "type")
9343 (let ((position (point)))
9344 (insert " := ")
9345 (unless (vhdl-template-field "[initialization]" nil t)
9346 (delete-region position (point)))
9347 (insert ";")
9348 (vhdl-comment-insert-inline)))
9349
9350 (defun vhdl-template-quantity-branch ()
9351 "Insert a branch quantity declaration."
9352 (interactive)
9353 (let (position)
9354 (vhdl-insert-keyword "QUANTITY ")
9355 (when (vhdl-template-field "[across names]" " " t)
9356 (vhdl-insert-keyword "ACROSS "))
9357 (when (vhdl-template-field "[through names]" " " t)
9358 (vhdl-insert-keyword "THROUGH "))
9359 (vhdl-template-field "plus terminal name")
9360 (setq position (point))
9361 (vhdl-insert-keyword " TO ")
9362 (unless (vhdl-template-field "[minus terminal name]" nil t)
9363 (delete-region position (point)))
9364 (insert ";")
9365 (vhdl-comment-insert-inline)))
9366
9367 (defun vhdl-template-quantity-source ()
9368 "Insert a source quantity declaration."
9369 (interactive)
9370 (vhdl-insert-keyword "QUANTITY ")
9371 (vhdl-template-field "names")
9372 (insert " : ")
9373 (vhdl-template-field "type" " ")
9374 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9375 (progn (vhdl-insert-keyword "NOISE ")
9376 (vhdl-template-field "power expression"))
9377 (vhdl-insert-keyword "SPECTRUM ")
9378 (vhdl-template-field "magnitude expression" ", ")
9379 (vhdl-template-field "phase expression"))
9380 (insert ";")
9381 (vhdl-comment-insert-inline))
9382
9383 (defun vhdl-template-record (kind &optional name secondary)
9384 "Insert a record type declaration."
9385 (interactive)
9386 (let ((margin (current-column))
9387 (start (point))
9388 (first t))
9389 (vhdl-insert-keyword "RECORD\n")
9390 (indent-to (+ margin vhdl-basic-offset))
9391 (when (or (vhdl-template-field "element names"
9392 nil (not secondary) start (point))
9393 secondary)
9394 (while (or first (vhdl-template-field "[element names]" nil t))
9395 (insert " : ")
9396 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9397 (vhdl-comment-insert-inline)
9398 (insert "\n")
9399 (indent-to (+ margin vhdl-basic-offset))
9400 (setq first nil))
9401 (delete-region (line-beginning-position) (point))
9402 (indent-to margin)
9403 (vhdl-insert-keyword "END RECORD")
9404 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9405 (insert ";")
9406 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9407
9408 (defun vhdl-template-report ()
9409 "Insert a report statement."
9410 (interactive)
9411 (let ((start (point)))
9412 (vhdl-insert-keyword "REPORT ")
9413 (if (equal "\"\"" (vhdl-template-field
9414 "string expression" nil t start (point) t))
9415 (delete-char -2)
9416 (setq start (point))
9417 (vhdl-insert-keyword " SEVERITY ")
9418 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9419 (delete-region start (point)))
9420 (insert ";"))))
9421
9422 (defun vhdl-template-return ()
9423 "Insert a return statement."
9424 (interactive)
9425 (let ((start (point)))
9426 (vhdl-insert-keyword "RETURN ")
9427 (unless (vhdl-template-field "[expression]" nil t start (point))
9428 (delete-char -1))
9429 (insert ";")))
9430
9431 (defun vhdl-template-selected-signal-asst ()
9432 "Insert a selected signal assignment."
9433 (interactive)
9434 (let ((margin (current-indentation))
9435 (start (point))
9436 (choices t))
9437 (let ((position (point)))
9438 (vhdl-insert-keyword " SELECT ")
9439 (goto-char position))
9440 (vhdl-insert-keyword "WITH ")
9441 (when (vhdl-template-field "selector expression"
9442 nil t start (+ (point) 7))
9443 (forward-word 1)
9444 (delete-char 1)
9445 (insert "\n")
9446 (indent-to (+ margin vhdl-basic-offset))
9447 (vhdl-template-field "target signal" " <= ")
9448 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9449 (insert "\n")
9450 (indent-to (+ margin vhdl-basic-offset))
9451 (vhdl-template-field "waveform")
9452 (vhdl-insert-keyword " WHEN ")
9453 (vhdl-template-field "choices" ",")
9454 (insert "\n")
9455 (indent-to (+ margin vhdl-basic-offset))
9456 (while (and choices (vhdl-template-field "[waveform]" nil t))
9457 (vhdl-insert-keyword " WHEN ")
9458 (if (setq choices (vhdl-template-field "[choices]" "," t))
9459 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9460 (vhdl-insert-keyword "OTHERS")))
9461 (when choices
9462 (fixup-whitespace)
9463 (delete-char -2))
9464 (insert ";")
9465 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9466
9467 (defun vhdl-template-signal ()
9468 "Insert a signal declaration."
9469 (interactive)
9470 (let ((start (point))
9471 (in-arglist (vhdl-in-argument-list-p)))
9472 (vhdl-insert-keyword "SIGNAL ")
9473 (when (vhdl-template-field "names" nil t start (point))
9474 (insert " : ")
9475 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9476 (vhdl-template-field "type")
9477 (if in-arglist
9478 (progn (insert ";")
9479 (vhdl-comment-insert-inline))
9480 (let ((position (point)))
9481 (insert " := ")
9482 (unless (vhdl-template-field "[initialization]" nil t)
9483 (delete-region position (point)))
9484 (insert ";")
9485 (vhdl-comment-insert-inline))))))
9486
9487 (defun vhdl-template-subnature ()
9488 "Insert a subnature declaration."
9489 (interactive)
9490 (let ((start (point))
9491 position)
9492 (vhdl-insert-keyword "SUBNATURE ")
9493 (when (vhdl-template-field "name" nil t start (point))
9494 (vhdl-insert-keyword " IS ")
9495 (vhdl-template-field "nature" " (")
9496 (if (vhdl-template-field "[index range]" nil t)
9497 (insert ")")
9498 (delete-char -2))
9499 (setq position (point))
9500 (vhdl-insert-keyword " TOLERANCE ")
9501 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9502 nil t nil nil t))
9503 (delete-region position (point))
9504 (vhdl-insert-keyword " ACROSS ")
9505 (vhdl-template-field "string expression" nil nil nil nil t)
9506 (vhdl-insert-keyword " THROUGH"))
9507 (insert ";")
9508 (vhdl-comment-insert-inline))))
9509
9510 (defun vhdl-template-subprogram-body ()
9511 "Insert a subprogram body."
9512 (interactive)
9513 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9514 (vhdl-template-function-body)
9515 (vhdl-template-procedure-body)))
9516
9517 (defun vhdl-template-subprogram-decl ()
9518 "Insert a subprogram declaration."
9519 (interactive)
9520 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9521 (vhdl-template-function-decl)
9522 (vhdl-template-procedure-decl)))
9523
9524 (defun vhdl-template-subtype ()
9525 "Insert a subtype declaration."
9526 (interactive)
9527 (let ((start (point)))
9528 (vhdl-insert-keyword "SUBTYPE ")
9529 (when (vhdl-template-field "name" nil t start (point))
9530 (vhdl-insert-keyword " IS ")
9531 (vhdl-template-field "type" " ")
9532 (unless
9533 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9534 (delete-char -1))
9535 (insert ";")
9536 (vhdl-comment-insert-inline))))
9537
9538 (defun vhdl-template-terminal ()
9539 "Insert a terminal declaration."
9540 (interactive)
9541 (let ((start (point)))
9542 (vhdl-insert-keyword "TERMINAL ")
9543 (when (vhdl-template-field "names" nil t start (point))
9544 (insert " : ")
9545 (vhdl-template-field "nature")
9546 (insert ";")
9547 (vhdl-comment-insert-inline))))
9548
9549 (defun vhdl-template-type ()
9550 "Insert a type declaration."
9551 (interactive)
9552 (let ((start (point))
9553 name mid-pos end-pos)
9554 (vhdl-insert-keyword "TYPE ")
9555 (when (setq name (vhdl-template-field "name" nil t start (point)))
9556 (vhdl-insert-keyword " IS ")
9557 (let ((definition
9558 (upcase
9559 (or (vhdl-template-field
9560 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9561 ""))))
9562 (cond ((equal definition "")
9563 (delete-char -4)
9564 (insert ";"))
9565 ((equal definition "ARRAY")
9566 (delete-region (point) (progn (forward-word -1) (point)))
9567 (vhdl-template-array 'type t))
9568 ((equal definition "RECORD")
9569 (setq mid-pos (point-marker))
9570 (delete-region (point) (progn (forward-word -1) (point)))
9571 (vhdl-template-record 'type name t))
9572 ((equal definition "ACCESS")
9573 (insert " ")
9574 (vhdl-template-field "type" ";"))
9575 ((equal definition "FILE")
9576 (vhdl-insert-keyword " OF ")
9577 (vhdl-template-field "type" ";"))
9578 (t (insert ";")))
9579 (when mid-pos
9580 (setq end-pos (point-marker))
9581 (goto-char mid-pos)
9582 (end-of-line))
9583 (vhdl-comment-insert-inline)
9584 (when end-pos (goto-char end-pos))))))
9585
9586 (defun vhdl-template-use ()
9587 "Insert a use clause."
9588 (interactive)
9589 (let ((start (point)))
9590 (vhdl-prepare-search-1
9591 (vhdl-insert-keyword "USE ")
9592 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9593 (vhdl-insert-keyword "..ALL;")
9594 (backward-char 6)
9595 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9596 (forward-char 1)
9597 (vhdl-template-field "package name")
9598 (forward-char 5))))))
9599
9600 (defun vhdl-template-variable ()
9601 "Insert a variable declaration."
9602 (interactive)
9603 (let ((start (point))
9604 (in-arglist (vhdl-in-argument-list-p)))
9605 (vhdl-prepare-search-2
9606 (if (or (save-excursion
9607 (and (vhdl-re-search-backward
9608 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9609 nil t)
9610 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9611 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9612 (vhdl-insert-keyword "VARIABLE ")
9613 (vhdl-insert-keyword "SHARED VARIABLE ")))
9614 (when (vhdl-template-field "names" nil t start (point))
9615 (insert " : ")
9616 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9617 (vhdl-template-field "type")
9618 (if in-arglist
9619 (progn (insert ";")
9620 (vhdl-comment-insert-inline))
9621 (let ((position (point)))
9622 (insert " := ")
9623 (unless (vhdl-template-field "[initialization]" nil t)
9624 (delete-region position (point)))
9625 (insert ";")
9626 (vhdl-comment-insert-inline))))))
9627
9628 (defun vhdl-template-wait ()
9629 "Insert a wait statement."
9630 (interactive)
9631 (vhdl-insert-keyword "WAIT ")
9632 (unless (vhdl-template-field
9633 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9634 nil t)
9635 (delete-char -1))
9636 (insert ";"))
9637
9638 (defun vhdl-template-when ()
9639 "Indent correctly if within a case statement."
9640 (interactive)
9641 (let ((position (point))
9642 margin)
9643 (vhdl-prepare-search-2
9644 (if (and (= (current-column) (current-indentation))
9645 (vhdl-re-search-forward "\\<end\\>" nil t)
9646 (looking-at "\\s-*\\<case\\>"))
9647 (progn
9648 (setq margin (current-indentation))
9649 (goto-char position)
9650 (delete-horizontal-space)
9651 (indent-to (+ margin vhdl-basic-offset)))
9652 (goto-char position)))
9653 (vhdl-insert-keyword "WHEN ")))
9654
9655 (defun vhdl-template-while-loop ()
9656 "Insert a while loop."
9657 (interactive)
9658 (let* ((margin (current-indentation))
9659 (start (point))
9660 label)
9661 (if (not (eq vhdl-optional-labels 'all))
9662 (vhdl-insert-keyword "WHILE ")
9663 (vhdl-insert-keyword ": WHILE ")
9664 (goto-char start)
9665 (setq label (vhdl-template-field "[label]" nil t))
9666 (unless label (delete-char 2))
9667 (forward-word 1)
9668 (forward-char 1))
9669 (when vhdl-conditions-in-parenthesis (insert "("))
9670 (when (vhdl-template-field "condition" nil t start (point))
9671 (when vhdl-conditions-in-parenthesis (insert ")"))
9672 (vhdl-insert-keyword " LOOP\n\n")
9673 (indent-to margin)
9674 (vhdl-insert-keyword "END LOOP")
9675 (insert (if label (concat " " label ";") ";"))
9676 (forward-line -1)
9677 (indent-to (+ margin vhdl-basic-offset)))))
9678
9679 (defun vhdl-template-with ()
9680 "Insert a with statement (i.e. selected signal assignment)."
9681 (interactive)
9682 (vhdl-prepare-search-1
9683 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9684 (equal ";" (match-string 1)))
9685 (vhdl-template-selected-signal-asst)
9686 (vhdl-insert-keyword "WITH "))))
9687
9688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9689 ;; Special templates
9690
9691 (defun vhdl-template-clocked-wait ()
9692 "Insert a wait statement for rising/falling clock edge."
9693 (interactive)
9694 (let ((start (point))
9695 clock)
9696 (vhdl-insert-keyword "WAIT UNTIL ")
9697 (when (setq clock
9698 (or (and (not (equal "" vhdl-clock-name))
9699 (progn (insert vhdl-clock-name) vhdl-clock-name))
9700 (vhdl-template-field "clock name" nil t start (point))))
9701 (insert "'event")
9702 (vhdl-insert-keyword " AND ")
9703 (insert clock)
9704 (insert
9705 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9706 (vhdl-comment-insert-inline
9707 (concat (if vhdl-clock-rising-edge "rising" "falling")
9708 " clock edge")))))
9709
9710 (defun vhdl-template-seq-process (clock reset)
9711 "Insert a template for the body of a sequential process."
9712 (let ((margin (current-indentation))
9713 position)
9714 (vhdl-insert-keyword "IF ")
9715 (when (eq vhdl-reset-kind 'async)
9716 (insert reset " = "
9717 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9718 (vhdl-insert-keyword " THEN")
9719 (vhdl-comment-insert-inline
9720 (concat "asynchronous reset (active "
9721 (if vhdl-reset-active-high "high" "low") ")"))
9722 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9723 (setq position (point))
9724 (insert "\n") (indent-to margin)
9725 (vhdl-insert-keyword "ELSIF "))
9726 (if (eq vhdl-clock-edge-condition 'function)
9727 (insert (if vhdl-clock-rising-edge "rising" "falling")
9728 "_edge(" clock ")")
9729 (insert clock "'event")
9730 (vhdl-insert-keyword " AND ")
9731 (insert clock " = "
9732 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9733 (vhdl-insert-keyword " THEN")
9734 (vhdl-comment-insert-inline
9735 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9736 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9737 (when (eq vhdl-reset-kind 'sync)
9738 (vhdl-insert-keyword "IF ")
9739 (setq reset (or (and (not (equal "" vhdl-reset-name))
9740 (progn (insert vhdl-reset-name) vhdl-reset-name))
9741 (vhdl-template-field "reset name") "<reset>"))
9742 (insert " = "
9743 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9744 (vhdl-insert-keyword " THEN")
9745 (vhdl-comment-insert-inline
9746 (concat "synchronous reset (active "
9747 (if vhdl-reset-active-high "high" "low") ")"))
9748 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9749 (setq position (point))
9750 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9751 (vhdl-insert-keyword "ELSE")
9752 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9753 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9754 (vhdl-insert-keyword "END IF;"))
9755 (when (eq vhdl-reset-kind 'none)
9756 (setq position (point)))
9757 (insert "\n") (indent-to margin)
9758 (vhdl-insert-keyword "END IF;")
9759 (goto-char position)
9760 reset))
9761
9762 (defun vhdl-template-standard-package (library package)
9763 "Insert specification of a standard package. Include a library
9764 specification, if not already there."
9765 (let ((margin (current-indentation)))
9766 (unless (equal library "std")
9767 (unless (or (save-excursion
9768 (vhdl-prepare-search-1
9769 (and (not (bobp))
9770 (re-search-backward
9771 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9772 library "\\|end\\)\\>") nil t)
9773 (match-string 2))))
9774 (equal (downcase library) "work"))
9775 (vhdl-insert-keyword "LIBRARY ")
9776 (insert library ";")
9777 (when package
9778 (insert "\n")
9779 (indent-to margin)))
9780 (when package
9781 (vhdl-insert-keyword "USE ")
9782 (insert library "." package)
9783 (vhdl-insert-keyword ".ALL;")))))
9784
9785 (defun vhdl-template-package-math-complex ()
9786 "Insert specification of `math_complex' package."
9787 (interactive)
9788 (vhdl-template-standard-package "ieee" "math_complex"))
9789
9790 (defun vhdl-template-package-math-real ()
9791 "Insert specification of `math_real' package."
9792 (interactive)
9793 (vhdl-template-standard-package "ieee" "math_real"))
9794
9795 (defun vhdl-template-package-numeric-bit ()
9796 "Insert specification of `numeric_bit' package."
9797 (interactive)
9798 (vhdl-template-standard-package "ieee" "numeric_bit"))
9799
9800 (defun vhdl-template-package-numeric-std ()
9801 "Insert specification of `numeric_std' package."
9802 (interactive)
9803 (vhdl-template-standard-package "ieee" "numeric_std"))
9804
9805 (defun vhdl-template-package-std-logic-1164 ()
9806 "Insert specification of `std_logic_1164' package."
9807 (interactive)
9808 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9809
9810 (defun vhdl-template-package-std-logic-arith ()
9811 "Insert specification of `std_logic_arith' package."
9812 (interactive)
9813 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9814
9815 (defun vhdl-template-package-std-logic-misc ()
9816 "Insert specification of `std_logic_misc' package."
9817 (interactive)
9818 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9819
9820 (defun vhdl-template-package-std-logic-signed ()
9821 "Insert specification of `std_logic_signed' package."
9822 (interactive)
9823 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9824
9825 (defun vhdl-template-package-std-logic-textio ()
9826 "Insert specification of `std_logic_textio' package."
9827 (interactive)
9828 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9829
9830 (defun vhdl-template-package-std-logic-unsigned ()
9831 "Insert specification of `std_logic_unsigned' package."
9832 (interactive)
9833 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9834
9835 (defun vhdl-template-package-textio ()
9836 "Insert specification of `textio' package."
9837 (interactive)
9838 (vhdl-template-standard-package "std" "textio"))
9839
9840 (defun vhdl-template-directive (directive)
9841 "Insert directive."
9842 (unless (= (current-indentation) (current-column))
9843 (delete-horizontal-space)
9844 (insert " "))
9845 (insert "-- pragma " directive))
9846
9847 (defun vhdl-template-directive-translate-on ()
9848 "Insert directive 'translate_on'."
9849 (interactive)
9850 (vhdl-template-directive "translate_on"))
9851
9852 (defun vhdl-template-directive-translate-off ()
9853 "Insert directive 'translate_off'."
9854 (interactive)
9855 (vhdl-template-directive "translate_off"))
9856
9857 (defun vhdl-template-directive-synthesis-on ()
9858 "Insert directive 'synthesis_on'."
9859 (interactive)
9860 (vhdl-template-directive "synthesis_on"))
9861
9862 (defun vhdl-template-directive-synthesis-off ()
9863 "Insert directive 'synthesis_off'."
9864 (interactive)
9865 (vhdl-template-directive "synthesis_off"))
9866
9867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9868 ;; Header and footer templates
9869
9870 (defun vhdl-template-header (&optional file-title)
9871 "Insert a VHDL file header."
9872 (interactive)
9873 (unless (equal vhdl-file-header "")
9874 (let (pos)
9875 (save-excursion
9876 (goto-char (point-min))
9877 (vhdl-insert-string-or-file vhdl-file-header)
9878 (setq pos (point-marker)))
9879 (vhdl-template-replace-header-keywords
9880 (point-min-marker) pos file-title))))
9881
9882 (defun vhdl-template-footer ()
9883 "Insert a VHDL file footer."
9884 (interactive)
9885 (unless (equal vhdl-file-footer "")
9886 (let (pos)
9887 (save-excursion
9888 (goto-char (point-max))
9889 (setq pos (point-marker))
9890 (vhdl-insert-string-or-file vhdl-file-footer)
9891 (unless (= (preceding-char) ?\n)
9892 (insert "\n")))
9893 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9894
9895 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9896 is-model)
9897 "Replace keywords in header and footer."
9898 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9899 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9900 pos)
9901 (vhdl-prepare-search-2
9902 (save-excursion
9903 (goto-char beg)
9904 (while (search-forward "<projectdesc>" end t)
9905 (replace-match project-desc t t))
9906 (goto-char beg)
9907 (while (search-forward "<filename>" end t)
9908 (replace-match (buffer-name) t t))
9909 (goto-char beg)
9910 (while (search-forward "<copyright>" end t)
9911 (replace-match vhdl-copyright-string t t))
9912 (goto-char beg)
9913 (while (search-forward "<author>" end t)
9914 (replace-match "" t t)
9915 (insert (user-full-name))
9916 (when user-mail-address (insert " <" user-mail-address ">")))
9917 (goto-char beg)
9918 (while (search-forward "<login>" end t)
9919 (replace-match (user-login-name) t t))
9920 (goto-char beg)
9921 (while (search-forward "<project>" end t)
9922 (replace-match project-title t t))
9923 (goto-char beg)
9924 (while (search-forward "<company>" end t)
9925 (replace-match vhdl-company-name t t))
9926 (goto-char beg)
9927 (while (search-forward "<platform>" end t)
9928 (replace-match vhdl-platform-spec t t))
9929 (goto-char beg)
9930 (while (search-forward "<standard>" end t)
9931 (replace-match
9932 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9933 ((vhdl-standard-p '93) "'93"))
9934 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9935 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9936 (goto-char beg)
9937 ;; Replace <RCS> with $, so that RCS for the source is
9938 ;; not over-enthusiastic with replacements
9939 (while (search-forward "<RCS>" end t)
9940 (replace-match "$" nil t))
9941 (goto-char beg)
9942 (while (search-forward "<date>" end t)
9943 (replace-match "" t t)
9944 (vhdl-template-insert-date))
9945 (goto-char beg)
9946 (while (search-forward "<year>" end t)
9947 (replace-match (format-time-string "%Y" nil) t t))
9948 (goto-char beg)
9949 (when file-title
9950 (while (search-forward "<title string>" end t)
9951 (replace-match file-title t t))
9952 (goto-char beg))
9953 (let (string)
9954 (while
9955 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9956 (setq string (read-string (concat (match-string 1) ": ")))
9957 (replace-match string t t)))
9958 (goto-char beg)
9959 (when (and (not is-model) (search-forward "<cursor>" end t))
9960 (replace-match "" t t)
9961 (setq pos (point))))
9962 (when pos (goto-char pos))
9963 (unless is-model
9964 (when (or (not project-title) (equal project-title ""))
9965 (message "You can specify a project title in user option `vhdl-project-alist'"))
9966 (when (or (not project-desc) (equal project-desc ""))
9967 (message "You can specify a project description in user option `vhdl-project-alist'"))
9968 (when (equal vhdl-platform-spec "")
9969 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9970 (when (equal vhdl-company-name "")
9971 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9972
9973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9974 ;; Comment templates and functions
9975
9976 (defun vhdl-comment-indent ()
9977 "Indent comments."
9978 (let* ((position (point))
9979 (col
9980 (progn
9981 (forward-line -1)
9982 (if (re-search-forward "--" position t)
9983 (- (current-column) 2) ; existing comment at bol stays there
9984 (goto-char position)
9985 (skip-chars-backward " \t")
9986 (max comment-column ; else indent to comment column
9987 (1+ (current-column))))))) ; except leave at least one space
9988 (goto-char position)
9989 col))
9990
9991 (defun vhdl-comment-insert ()
9992 "Start a comment at the end of the line.
9993 If on line with code, indent at least `comment-column'.
9994 If starting after end-comment-column, start a new line."
9995 (interactive)
9996 (when (> (current-column) end-comment-column) (newline-and-indent))
9997 (if (or (looking-at "\\s-*$") ; end of line
9998 (and (not unread-command-events) ; called with key binding or menu
9999 (not (end-of-line))))
10000 (let (margin)
10001 (while (= (preceding-char) ?-) (delete-char -1))
10002 (setq margin (current-column))
10003 (delete-horizontal-space)
10004 (if (bolp)
10005 (progn (indent-to margin) (insert "--"))
10006 (insert " ")
10007 (indent-to comment-column)
10008 (insert "--"))
10009 (if (not unread-command-events) (insert " ")))
10010 ;; else code following current point implies commenting out code
10011 (let (next-input code)
10012 (while (= (preceding-char) ?-) (delete-char -2))
10013 (while (= (setq next-input (read-char)) 13) ; CR
10014 (insert "--") ; or have a space after it?
10015 (forward-char -2)
10016 (forward-line 1)
10017 (message "Enter CR if commenting out a line of code.")
10018 (setq code t))
10019 (unless code
10020 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10021 (setq unread-command-events
10022 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10023
10024 (defun vhdl-comment-display (&optional line-exists)
10025 "Add 2 comment lines at the current indent, making a display comment."
10026 (interactive)
10027 (let ((margin (current-indentation)))
10028 (unless line-exists (vhdl-comment-display-line))
10029 (insert "\n") (indent-to margin)
10030 (insert "\n") (indent-to margin)
10031 (vhdl-comment-display-line)
10032 (end-of-line -0)
10033 (insert "-- ")))
10034
10035 (defun vhdl-comment-display-line ()
10036 "Displays one line of dashes."
10037 (interactive)
10038 (while (= (preceding-char) ?-) (delete-char -2))
10039 (let* ((col (current-column))
10040 (len (- end-comment-column col)))
10041 (insert-char ?- len)))
10042
10043 (defun vhdl-comment-append-inline ()
10044 "Append empty inline comment to current line."
10045 (interactive)
10046 (end-of-line)
10047 (delete-horizontal-space)
10048 (insert " ")
10049 (indent-to comment-column)
10050 (insert "-- "))
10051
10052 (defun vhdl-comment-insert-inline (&optional string always-insert)
10053 "Insert inline comment."
10054 (when (or (and string (or vhdl-self-insert-comments always-insert))
10055 (and (not string) vhdl-prompt-for-comments))
10056 (let ((position (point)))
10057 (insert " ")
10058 (indent-to comment-column)
10059 (insert "-- ")
10060 (if (not (or (and string (progn (insert string) t))
10061 (vhdl-template-field "[comment]" nil t)))
10062 (delete-region position (point))
10063 (while (= (preceding-char) ?\ ) (delete-char -1))
10064 ;; (when (> (current-column) end-comment-column)
10065 ;; (setq position (point-marker))
10066 ;; (re-search-backward "-- ")
10067 ;; (insert "\n")
10068 ;; (indent-to comment-column)
10069 ;; (goto-char position))
10070 ))))
10071
10072 (defun vhdl-comment-block ()
10073 "Insert comment for code block."
10074 (when vhdl-prompt-for-comments
10075 (let ((final-pos (point-marker)))
10076 (vhdl-prepare-search-2
10077 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10078 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10079 (let (margin)
10080 (back-to-indentation)
10081 (setq margin (current-column))
10082 (end-of-line -0)
10083 (if (bobp)
10084 (progn (insert "\n") (forward-line -1))
10085 (insert "\n"))
10086 (indent-to margin)
10087 (insert "-- purpose: ")
10088 (unless (vhdl-template-field "[description]" nil t)
10089 (vhdl-line-kill-entire)))))
10090 (goto-char final-pos))))
10091
10092 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10093 "Comment out region if not commented out, uncomment otherwise."
10094 (interactive "r\nP")
10095 (save-excursion
10096 (goto-char (1- end))
10097 (end-of-line)
10098 (setq end (point-marker))
10099 (goto-char beg)
10100 (beginning-of-line)
10101 (setq beg (point))
10102 (if (looking-at comment-start)
10103 (comment-region beg end '(4))
10104 (comment-region beg end))))
10105
10106 (defun vhdl-comment-uncomment-line (&optional arg)
10107 "Comment out line if not commented out, uncomment otherwise."
10108 (interactive "p")
10109 (save-excursion
10110 (beginning-of-line)
10111 (let ((position (point)))
10112 (forward-line (or arg 1))
10113 (vhdl-comment-uncomment-region position (point)))))
10114
10115 (defun vhdl-comment-kill-region (beg end)
10116 "Kill comments in region."
10117 (interactive "r")
10118 (save-excursion
10119 (goto-char end)
10120 (setq end (point-marker))
10121 (goto-char beg)
10122 (beginning-of-line)
10123 (while (< (point) end)
10124 (if (looking-at "^\\(\\s-*--.*\n\\)")
10125 (progn (delete-region (match-beginning 1) (match-end 1)))
10126 (beginning-of-line 2)))))
10127
10128 (defun vhdl-comment-kill-inline-region (beg end)
10129 "Kill inline comments in region."
10130 (interactive "r")
10131 (save-excursion
10132 (goto-char end)
10133 (setq end (point-marker))
10134 (goto-char beg)
10135 (beginning-of-line)
10136 (while (< (point) end)
10137 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10138 (delete-region (match-beginning 1) (match-end 1)))
10139 (beginning-of-line 2))))
10140
10141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10142 ;; Subtemplates
10143
10144 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10145 "Insert a begin ... end pair with optional name after the end.
10146 Point is left between them."
10147 (let (position)
10148 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10149 (indent-to margin)
10150 (vhdl-insert-keyword "BEGIN")
10151 (when (and (or construct name) vhdl-self-insert-comments)
10152 (insert " --")
10153 (when construct (insert " ") (vhdl-insert-keyword construct))
10154 (when name (insert " " name)))
10155 (insert "\n")
10156 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10157 (indent-to (+ margin vhdl-basic-offset))
10158 (setq position (point))
10159 (insert "\n")
10160 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10161 (indent-to margin)
10162 (vhdl-insert-keyword "END")
10163 (when construct (insert " ") (vhdl-insert-keyword construct))
10164 (insert (if name (concat " " name) "") ";")
10165 (goto-char position)))
10166
10167 (defun vhdl-template-argument-list (&optional is-function)
10168 "Read from user a procedure or function argument list."
10169 (insert " (")
10170 (let ((margin (current-column))
10171 (start (point))
10172 (end-pos (point))
10173 not-empty interface semicolon-pos)
10174 (unless vhdl-argument-list-indent
10175 (setq margin (+ (current-indentation) vhdl-basic-offset))
10176 (insert "\n")
10177 (indent-to margin))
10178 (setq interface (vhdl-template-field
10179 (concat "[CONSTANT | SIGNAL"
10180 (unless is-function " | VARIABLE") "]") " " t))
10181 (while (vhdl-template-field "[names]" nil t)
10182 (setq not-empty t)
10183 (insert " : ")
10184 (unless is-function
10185 (if (and interface (equal (upcase interface) "CONSTANT"))
10186 (vhdl-insert-keyword "IN ")
10187 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10188 (vhdl-template-field "type")
10189 (setq semicolon-pos (point))
10190 (insert ";")
10191 (vhdl-comment-insert-inline)
10192 (setq end-pos (point))
10193 (insert "\n")
10194 (indent-to margin)
10195 (setq interface (vhdl-template-field
10196 (concat "[CONSTANT | SIGNAL"
10197 (unless is-function " | VARIABLE") "]") " " t)))
10198 (delete-region end-pos (point))
10199 (when semicolon-pos (goto-char semicolon-pos))
10200 (if not-empty
10201 (progn (delete-char 1) (insert ")"))
10202 (delete-char -2))))
10203
10204 (defun vhdl-template-generic-list (optional &optional no-value)
10205 "Read from user a generic spec argument list."
10206 (let (margin
10207 (start (point)))
10208 (vhdl-insert-keyword "GENERIC (")
10209 (setq margin (current-column))
10210 (unless vhdl-argument-list-indent
10211 (let ((position (point)))
10212 (back-to-indentation)
10213 (setq margin (+ (current-column) vhdl-basic-offset))
10214 (goto-char position)
10215 (insert "\n")
10216 (indent-to margin)))
10217 (let ((vhdl-generics (vhdl-template-field
10218 (concat (and optional "[") "name"
10219 (and no-value "s") (and optional "]"))
10220 nil optional)))
10221 (if (not vhdl-generics)
10222 (if optional
10223 (progn (vhdl-line-kill-entire) (end-of-line -0)
10224 (unless vhdl-argument-list-indent
10225 (vhdl-line-kill-entire) (end-of-line -0)))
10226 (vhdl-template-undo start (point))
10227 nil )
10228 (insert " : ")
10229 (let (semicolon-pos end-pos)
10230 (while vhdl-generics
10231 (vhdl-template-field "type")
10232 (if no-value
10233 (progn (setq semicolon-pos (point))
10234 (insert ";"))
10235 (insert " := ")
10236 (unless (vhdl-template-field "[value]" nil t)
10237 (delete-char -4))
10238 (setq semicolon-pos (point))
10239 (insert ";"))
10240 (vhdl-comment-insert-inline)
10241 (setq end-pos (point))
10242 (insert "\n")
10243 (indent-to margin)
10244 (setq vhdl-generics (vhdl-template-field
10245 (concat "[name" (and no-value "s") "]")
10246 " : " t)))
10247 (delete-region end-pos (point))
10248 (goto-char semicolon-pos)
10249 (insert ")")
10250 (end-of-line)
10251 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10252 t)))))
10253
10254 (defun vhdl-template-port-list (optional)
10255 "Read from user a port spec argument list."
10256 (let ((start (point))
10257 margin vhdl-ports object)
10258 (vhdl-insert-keyword "PORT (")
10259 (setq margin (current-column))
10260 (unless vhdl-argument-list-indent
10261 (let ((position (point)))
10262 (back-to-indentation)
10263 (setq margin (+ (current-column) vhdl-basic-offset))
10264 (goto-char position)
10265 (insert "\n")
10266 (indent-to margin)))
10267 (when (vhdl-standard-p 'ams)
10268 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10269 " " t)))
10270 (setq vhdl-ports (vhdl-template-field
10271 (concat (and optional "[") "names" (and optional "]"))
10272 nil optional))
10273 (if (not vhdl-ports)
10274 (if optional
10275 (progn (vhdl-line-kill-entire) (end-of-line -0)
10276 (unless vhdl-argument-list-indent
10277 (vhdl-line-kill-entire) (end-of-line -0)))
10278 (vhdl-template-undo start (point))
10279 nil)
10280 (insert " : ")
10281 (let (semicolon-pos end-pos)
10282 (while vhdl-ports
10283 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10284 (vhdl-template-field "IN | OUT | INOUT" " "))
10285 ((equal "QUANTITY" (upcase object))
10286 (vhdl-template-field "[IN | OUT]" " " t)))
10287 (vhdl-template-field
10288 (if (and object (equal "TERMINAL" (upcase object)))
10289 "nature" "type"))
10290 (setq semicolon-pos (point))
10291 (insert ";")
10292 (vhdl-comment-insert-inline)
10293 (setq end-pos (point))
10294 (insert "\n")
10295 (indent-to margin)
10296 (when (vhdl-standard-p 'ams)
10297 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10298 " " t)))
10299 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10300 (delete-region end-pos (point))
10301 (goto-char semicolon-pos)
10302 (insert ")")
10303 (end-of-line)
10304 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10305 t))))
10306
10307 (defun vhdl-template-generate-body (margin label)
10308 "Insert body for generate template."
10309 (vhdl-insert-keyword " GENERATE")
10310 ; (if (not (vhdl-standard-p '87))
10311 ; (vhdl-template-begin-end "GENERATE" label margin)
10312 (insert "\n\n")
10313 (indent-to margin)
10314 (vhdl-insert-keyword "END GENERATE ")
10315 (insert label ";")
10316 (end-of-line 0)
10317 (indent-to (+ margin vhdl-basic-offset)))
10318
10319 (defun vhdl-template-insert-date ()
10320 "Insert date in appropriate format."
10321 (interactive)
10322 (insert
10323 (cond
10324 ;; 'american, 'european, 'scientific kept for backward compatibility
10325 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10326 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10327 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10328 (t (format-time-string vhdl-date-format nil)))))
10329
10330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10331 ;; Help functions
10332
10333 (defun vhdl-electric-space (count)
10334 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10335 if in comment and past end-comment-column."
10336 (interactive "p")
10337 (cond ((vhdl-in-comment-p)
10338 (self-insert-command count)
10339 (cond ((>= (current-column) (+ 2 end-comment-column))
10340 (backward-char 1)
10341 (skip-chars-backward "^ \t\n")
10342 (indent-new-comment-line)
10343 (skip-chars-forward "^ \t\n")
10344 (forward-char 1))
10345 ((>= (current-column) end-comment-column)
10346 (indent-new-comment-line))
10347 (t nil)))
10348 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10349 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10350 (vhdl-prepare-search-1
10351 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10352 (self-insert-command count))
10353 (t (self-insert-command count))))
10354
10355 (defun vhdl-template-field (prompt &optional follow-string optional
10356 begin end is-string default)
10357 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10358 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10359 an empty string is inserted, return nil and call `vhdl-template-undo' for
10360 the region between BEGIN and END. IS-STRING indicates whether a string
10361 with double-quotes is to be inserted. DEFAULT specifies a default string."
10362 (let ((position (point))
10363 string)
10364 (insert "<" prompt ">")
10365 (setq string
10366 (condition-case ()
10367 (read-from-minibuffer (concat prompt ": ")
10368 (or (and is-string '("\"\"" . 2)) default)
10369 vhdl-minibuffer-local-map)
10370 (quit (if (and optional begin end)
10371 (progn (beep) "")
10372 (keyboard-quit)))))
10373 (when (or (not (equal string "")) optional)
10374 (delete-region position (point)))
10375 (when (and (equal string "") optional begin end)
10376 (vhdl-template-undo begin end)
10377 (message "Template aborted"))
10378 (unless (equal string "")
10379 (insert string)
10380 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10381 vhdl-keywords-regexp)
10382 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10383 vhdl-types-regexp)
10384 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10385 (concat "'" vhdl-attributes-regexp))
10386 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10387 vhdl-enum-values-regexp))
10388 (when (or (not (equal string "")) (not optional))
10389 (insert (or follow-string "")))
10390 (if (equal string "") nil string)))
10391
10392 (defun vhdl-decision-query (string prompt &optional optional)
10393 "Query a decision from the user."
10394 (let ((start (point)))
10395 (when string (vhdl-insert-keyword (concat string " ")))
10396 (message "%s" (or prompt ""))
10397 (let ((char (read-char)))
10398 (delete-region start (point))
10399 (if (and optional (eq char ?\r))
10400 (progn (insert " ")
10401 (unexpand-abbrev)
10402 (throw 'abort "ERROR: Template aborted"))
10403 char))))
10404
10405 (defun vhdl-insert-keyword (keyword)
10406 "Insert KEYWORD and adjust case."
10407 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10408
10409 (defun vhdl-case-keyword (keyword)
10410 "Adjust case of KEYWORD."
10411 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10412
10413 (defun vhdl-case-word (num)
10414 "Adjust case of following NUM words."
10415 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10416
10417 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10418 "If preceeding character is part of a word or a paren then hippie-expand,
10419 else insert tab (used for word completion in VHDL minibuffer)."
10420 (interactive "P")
10421 (cond
10422 ;; expand word
10423 ((= (char-syntax (preceding-char)) ?w)
10424 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10425 (case-replace nil)
10426 (hippie-expand-only-buffers
10427 (or (and (boundp 'hippie-expand-only-buffers)
10428 hippie-expand-only-buffers)
10429 '(vhdl-mode))))
10430 (vhdl-expand-abbrev prefix-arg)))
10431 ;; expand parenthesis
10432 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10433 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10434 (case-replace nil))
10435 (vhdl-expand-paren prefix-arg)))
10436 ;; insert tab
10437 (t (insert-tab))))
10438
10439 (defun vhdl-template-search-prompt ()
10440 "Search for left out template prompts and query again."
10441 (interactive)
10442 (vhdl-prepare-search-2
10443 (when (or (re-search-forward
10444 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10445 (re-search-backward
10446 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10447 (let ((string (match-string 1)))
10448 (replace-match "")
10449 (vhdl-template-field string)))))
10450
10451 (defun vhdl-template-undo (begin end)
10452 "Undo aborted template by deleting region and unexpanding the keyword."
10453 (cond (vhdl-template-invoked-by-hook
10454 (goto-char end)
10455 (insert " ")
10456 (delete-region begin end)
10457 (unexpand-abbrev))
10458 (t (delete-region begin end))))
10459
10460 (defun vhdl-insert-string-or-file (string)
10461 "Insert STRING or file contents if STRING is an existing file name."
10462 (unless (equal string "")
10463 (let ((file-name
10464 (progn (string-match "^\\([^\n]+\\)" string)
10465 (vhdl-resolve-env-variable (match-string 1 string)))))
10466 (if (file-exists-p file-name)
10467 (forward-char (cadr (insert-file-contents file-name)))
10468 (insert string)))))
10469
10470 (defun vhdl-beginning-of-block ()
10471 "Move cursor to the beginning of the enclosing block."
10472 (let (pos)
10473 (save-excursion
10474 (beginning-of-line)
10475 ;; search backward for block beginning or end
10476 (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))
10477 ;; not consider subprogram declarations
10478 (or (and (match-string 5)
10479 (save-match-data
10480 (save-excursion
10481 (goto-char (match-end 5))
10482 (forward-word 1)
10483 (vhdl-forward-syntactic-ws)
10484 (when (looking-at "(")
10485 (forward-sexp))
10486 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10487 (match-string 1)))
10488 ;; not consider configuration specifications
10489 (and (match-string 6)
10490 (save-match-data
10491 (save-excursion
10492 (vhdl-end-of-block)
10493 (beginning-of-line)
10494 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10495 (match-string 2))
10496 ;; skip subblock if block end found
10497 (vhdl-beginning-of-block)))
10498 (when pos (goto-char pos))))
10499
10500 (defun vhdl-end-of-block ()
10501 "Move cursor to the end of the enclosing block."
10502 (let (pos)
10503 (save-excursion
10504 (end-of-line)
10505 ;; search forward for block beginning or end
10506 (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))
10507 ;; not consider subprogram declarations
10508 (or (and (match-string 5)
10509 (save-match-data
10510 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10511 (match-string 1)))
10512 ;; not consider configuration specifications
10513 (and (match-string 6)
10514 (save-match-data
10515 (save-excursion
10516 (vhdl-end-of-block)
10517 (beginning-of-line)
10518 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10519 (not (match-string 2)))
10520 ;; skip subblock if block beginning found
10521 (vhdl-end-of-block)))
10522 (when pos (goto-char pos))))
10523
10524 (defun vhdl-sequential-statement-p ()
10525 "Check if point is within sequential statement part."
10526 (let ((start (point)))
10527 (save-excursion
10528 (vhdl-prepare-search-2
10529 ;; is sequential statement if ...
10530 (and (re-search-backward "^\\s-*begin\\>" nil t)
10531 ;; ... point is between "begin" and "end" of ...
10532 (progn (vhdl-end-of-block)
10533 (< start (point)))
10534 ;; ... a sequential block
10535 (progn (vhdl-beginning-of-block)
10536 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10537
10538 (defun vhdl-in-argument-list-p ()
10539 "Check if within an argument list."
10540 (save-excursion
10541 (vhdl-prepare-search-2
10542 (or (string-match "arglist"
10543 (format "%s" (caar (vhdl-get-syntactic-context))))
10544 (progn (beginning-of-line)
10545 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10546
10547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10548 ;; Abbrev hooks
10549
10550 (defun vhdl-hooked-abbrev (func)
10551 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10552 but not if inside a comment or quote."
10553 (if (or (vhdl-in-literal)
10554 (save-excursion
10555 (forward-word -1)
10556 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10557 (progn
10558 (insert " ")
10559 (unexpand-abbrev)
10560 (delete-char -1))
10561 (if (not vhdl-electric-mode)
10562 (progn
10563 (insert " ")
10564 (unexpand-abbrev)
10565 (backward-word 1)
10566 (vhdl-case-word 1)
10567 (delete-char 1))
10568 (let ((invoke-char last-command-event)
10569 (abbrev-mode -1)
10570 (vhdl-template-invoked-by-hook t))
10571 (let ((caught (catch 'abort
10572 (funcall func))))
10573 (when (stringp caught) (message "%s" caught)))
10574 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10575 ;; delete CR which is still in event queue
10576 (if (fboundp 'enqueue-eval-event)
10577 (enqueue-eval-event 'delete-char -1)
10578 (setq unread-command-events ; push back a delete char
10579 (list (vhdl-character-to-event ?\177))))))))
10580
10581 (defun vhdl-template-alias-hook ()
10582 (vhdl-hooked-abbrev 'vhdl-template-alias))
10583 (defun vhdl-template-architecture-hook ()
10584 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10585 (defun vhdl-template-assert-hook ()
10586 (vhdl-hooked-abbrev 'vhdl-template-assert))
10587 (defun vhdl-template-attribute-hook ()
10588 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10589 (defun vhdl-template-block-hook ()
10590 (vhdl-hooked-abbrev 'vhdl-template-block))
10591 (defun vhdl-template-break-hook ()
10592 (vhdl-hooked-abbrev 'vhdl-template-break))
10593 (defun vhdl-template-case-hook ()
10594 (vhdl-hooked-abbrev 'vhdl-template-case))
10595 (defun vhdl-template-component-hook ()
10596 (vhdl-hooked-abbrev 'vhdl-template-component))
10597 (defun vhdl-template-instance-hook ()
10598 (vhdl-hooked-abbrev 'vhdl-template-instance))
10599 (defun vhdl-template-conditional-signal-asst-hook ()
10600 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10601 (defun vhdl-template-configuration-hook ()
10602 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10603 (defun vhdl-template-constant-hook ()
10604 (vhdl-hooked-abbrev 'vhdl-template-constant))
10605 (defun vhdl-template-disconnect-hook ()
10606 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10607 (defun vhdl-template-display-comment-hook ()
10608 (vhdl-hooked-abbrev 'vhdl-comment-display))
10609 (defun vhdl-template-else-hook ()
10610 (vhdl-hooked-abbrev 'vhdl-template-else))
10611 (defun vhdl-template-elsif-hook ()
10612 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10613 (defun vhdl-template-entity-hook ()
10614 (vhdl-hooked-abbrev 'vhdl-template-entity))
10615 (defun vhdl-template-exit-hook ()
10616 (vhdl-hooked-abbrev 'vhdl-template-exit))
10617 (defun vhdl-template-file-hook ()
10618 (vhdl-hooked-abbrev 'vhdl-template-file))
10619 (defun vhdl-template-for-hook ()
10620 (vhdl-hooked-abbrev 'vhdl-template-for))
10621 (defun vhdl-template-function-hook ()
10622 (vhdl-hooked-abbrev 'vhdl-template-function))
10623 (defun vhdl-template-generic-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-generic))
10625 (defun vhdl-template-group-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-group))
10627 (defun vhdl-template-library-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-library))
10629 (defun vhdl-template-limit-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-limit))
10631 (defun vhdl-template-if-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-if))
10633 (defun vhdl-template-bare-loop-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10635 (defun vhdl-template-map-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-map))
10637 (defun vhdl-template-nature-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-nature))
10639 (defun vhdl-template-next-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-next))
10641 (defun vhdl-template-others-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-others))
10643 (defun vhdl-template-package-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-package))
10645 (defun vhdl-template-port-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-port))
10647 (defun vhdl-template-procedural-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10649 (defun vhdl-template-procedure-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10651 (defun vhdl-template-process-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-process))
10653 (defun vhdl-template-quantity-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10655 (defun vhdl-template-report-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-report))
10657 (defun vhdl-template-return-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-return))
10659 (defun vhdl-template-selected-signal-asst-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10661 (defun vhdl-template-signal-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-signal))
10663 (defun vhdl-template-subnature-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10665 (defun vhdl-template-subtype-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10667 (defun vhdl-template-terminal-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10669 (defun vhdl-template-type-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-type))
10671 (defun vhdl-template-use-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-use))
10673 (defun vhdl-template-variable-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-variable))
10675 (defun vhdl-template-wait-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-wait))
10677 (defun vhdl-template-when-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-when))
10679 (defun vhdl-template-while-loop-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10681 (defun vhdl-template-with-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-with))
10683 (defun vhdl-template-and-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-and))
10685 (defun vhdl-template-or-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-or))
10687 (defun vhdl-template-nand-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-nand))
10689 (defun vhdl-template-nor-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-nor))
10691 (defun vhdl-template-xor-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-xor))
10693 (defun vhdl-template-xnor-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10695 (defun vhdl-template-not-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-not))
10697
10698 (defun vhdl-template-default-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-default))
10700 (defun vhdl-template-default-indent-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10702
10703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10704 ;; Template insertion from completion list
10705
10706 (defun vhdl-template-insert-construct (name)
10707 "Insert the built-in construct template with NAME."
10708 (interactive
10709 (list (let ((completion-ignore-case t))
10710 (completing-read "Construct name: "
10711 vhdl-template-construct-alist nil t))))
10712 (vhdl-template-insert-fun
10713 (cadr (assoc name vhdl-template-construct-alist))))
10714
10715 (defun vhdl-template-insert-package (name)
10716 "Insert the built-in package template with NAME."
10717 (interactive
10718 (list (let ((completion-ignore-case t))
10719 (completing-read "Package name: "
10720 vhdl-template-package-alist nil t))))
10721 (vhdl-template-insert-fun
10722 (cadr (assoc name vhdl-template-package-alist))))
10723
10724 (defun vhdl-template-insert-directive (name)
10725 "Insert the built-in directive template with NAME."
10726 (interactive
10727 (list (let ((completion-ignore-case t))
10728 (completing-read "Directive name: "
10729 vhdl-template-directive-alist nil t))))
10730 (vhdl-template-insert-fun
10731 (cadr (assoc name vhdl-template-directive-alist))))
10732
10733 (defun vhdl-template-insert-fun (fun)
10734 "Call FUN to insert a built-in template."
10735 (let ((caught (catch 'abort (when fun (funcall fun)))))
10736 (when (stringp caught) (message "%s" caught))))
10737
10738
10739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10740 ;;; Models
10741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10742
10743 (defun vhdl-model-insert (model-name)
10744 "Insert the user model with name MODEL-NAME."
10745 (interactive
10746 (let ((completion-ignore-case t))
10747 (list (completing-read "Model name: " vhdl-model-alist))))
10748 (indent-according-to-mode)
10749 (let ((start (point-marker))
10750 (margin (current-indentation))
10751 model position prompt string end)
10752 (vhdl-prepare-search-2
10753 (when (setq model (assoc model-name vhdl-model-alist))
10754 ;; insert model
10755 (beginning-of-line)
10756 (delete-horizontal-space)
10757 (goto-char start)
10758 (vhdl-insert-string-or-file (nth 1 model))
10759 (setq end (point-marker))
10760 ;; indent code
10761 (goto-char start)
10762 (beginning-of-line)
10763 (while (< (point) end)
10764 (unless (looking-at "^$")
10765 (insert-char ? margin))
10766 (beginning-of-line 2))
10767 (goto-char start)
10768 ;; insert clock
10769 (unless (equal "" vhdl-clock-name)
10770 (while (re-search-forward "<clock>" end t)
10771 (replace-match vhdl-clock-name)))
10772 (goto-char start)
10773 ;; insert reset
10774 (unless (equal "" vhdl-reset-name)
10775 (while (re-search-forward "<reset>" end t)
10776 (replace-match vhdl-reset-name)))
10777 ;; replace header prompts
10778 (vhdl-template-replace-header-keywords start end nil t)
10779 (goto-char start)
10780 ;; query other prompts
10781 (while (re-search-forward
10782 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10783 (unless (equal "cursor" (match-string 1))
10784 (setq position (match-beginning 1))
10785 (setq prompt (match-string 1))
10786 (replace-match "")
10787 (setq string (vhdl-template-field prompt nil t))
10788 ;; replace occurrences of same prompt
10789 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10790 (replace-match (or string "")))
10791 (goto-char position)))
10792 (goto-char start)
10793 ;; goto final position
10794 (if (re-search-forward "<cursor>" end t)
10795 (replace-match "")
10796 (goto-char end))))))
10797
10798 (defun vhdl-model-defun ()
10799 "Define help and hook functions for user models."
10800 (let ((model-alist vhdl-model-alist)
10801 model-name model-keyword)
10802 (while model-alist
10803 ;; define functions for user models that can be invoked from menu and key
10804 ;; bindings and which themselves call `vhdl-model-insert' with the model
10805 ;; name as argument
10806 (setq model-name (nth 0 (car model-alist)))
10807 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10808 ,(concat "Insert model for \"" model-name "\".")
10809 (interactive)
10810 (vhdl-model-insert ,model-name)))
10811 ;; define hooks for user models that are invoked from keyword abbrevs
10812 (setq model-keyword (nth 3 (car model-alist)))
10813 (unless (equal model-keyword "")
10814 (eval `(defun
10815 ,(vhdl-function-name
10816 "vhdl-model" model-name "hook") ()
10817 (vhdl-hooked-abbrev
10818 ',(vhdl-function-name "vhdl-model" model-name)))))
10819 (setq model-alist (cdr model-alist)))))
10820
10821 (vhdl-model-defun)
10822
10823
10824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10825 ;;; Port translation
10826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10827
10828 (defvar vhdl-port-list nil
10829 "Variable to hold last port map parsed.")
10830 ;; structure: (parenthesised expression means list of such entries)
10831 ;; (ent-name
10832 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10833 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10834 ;; (lib-name pack-key))
10835
10836 (defun vhdl-parse-string (string &optional optional)
10837 "Check that the text following point matches the regexp in STRING."
10838 (if (looking-at string)
10839 (goto-char (match-end 0))
10840 (unless optional
10841 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10842 (vhdl-current-line) string)))
10843 nil))
10844
10845 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10846 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10847 (vhdl-prepare-search-1
10848 (if (string-match (car regexp-cons) string)
10849 (if adjust-case
10850 (funcall vhdl-file-name-case
10851 (replace-match (cdr regexp-cons) t nil string))
10852 (replace-match (cdr regexp-cons) t nil string))
10853 string)))
10854
10855 (defun vhdl-parse-group-comment ()
10856 "Parse comment and empty lines between groups of lines."
10857 (let ((start (point))
10858 string)
10859 (vhdl-forward-comment (point-max))
10860 (setq string (buffer-substring-no-properties start (point)))
10861 (vhdl-forward-syntactic-ws)
10862 ;; strip off leading blanks and first newline
10863 (while (string-match "^\\(\\s-+\\)" string)
10864 (setq string (concat (substring string 0 (match-beginning 1))
10865 (substring string (match-end 1)))))
10866 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10867 (substring string 1)
10868 string)))
10869
10870 (defun vhdl-paste-group-comment (string indent)
10871 "Paste comment and empty lines from STRING between groups of lines
10872 with INDENT."
10873 (let ((pos (point-marker)))
10874 (when (> indent 0)
10875 (while (string-match "^\\(--\\)" string)
10876 (setq string (concat (substring string 0 (match-beginning 1))
10877 (make-string indent ? )
10878 (substring string (match-beginning 1))))))
10879 (beginning-of-line)
10880 (insert string)
10881 (goto-char pos)))
10882
10883 (defvar vhdl-port-flattened nil
10884 "Indicates whether a port has been flattened.")
10885
10886 (defun vhdl-port-flatten (&optional as-alist)
10887 "Flatten port list so that only one generic/port exists per line.
10888 This operation is performed on an internally stored port and is only
10889 reflected in a subsequent paste operation."
10890 (interactive)
10891 (if (not vhdl-port-list)
10892 (error "ERROR: No port has been read")
10893 (message "Flattening port for next paste...")
10894 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10895 (old-vhdl-port-list (cdr vhdl-port-list))
10896 old-port-list new-port-list old-port new-port names)
10897 ;; traverse port list and flatten entries
10898 (while (cdr old-vhdl-port-list)
10899 (setq old-port-list (car old-vhdl-port-list))
10900 (setq new-port-list nil)
10901 (while old-port-list
10902 (setq old-port (car old-port-list))
10903 (setq names (car old-port))
10904 (while names
10905 (setq new-port (cons (if as-alist (car names) (list (car names)))
10906 (cdr old-port)))
10907 (setq new-port-list (append new-port-list (list new-port)))
10908 (setq names (cdr names)))
10909 (setq old-port-list (cdr old-port-list)))
10910 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10911 (setq new-vhdl-port-list (append new-vhdl-port-list
10912 (list new-port-list))))
10913 (setq vhdl-port-list
10914 (append new-vhdl-port-list (list old-vhdl-port-list))
10915 vhdl-port-flattened t)
10916 (message "Flattening port for next paste...done"))))
10917
10918 (defvar vhdl-port-reversed-direction nil
10919 "Indicates whether port directions are reversed.")
10920
10921 (defun vhdl-port-reverse-direction ()
10922 "Reverse direction for all ports (useful in testbenches).
10923 This operation is performed on an internally stored port and is only
10924 reflected in a subsequent paste operation."
10925 (interactive)
10926 (if (not vhdl-port-list)
10927 (error "ERROR: No port has been read")
10928 (message "Reversing port directions for next paste...")
10929 (let ((port-list (nth 2 vhdl-port-list))
10930 port-dir-car port-dir)
10931 ;; traverse port list and reverse directions
10932 (while port-list
10933 (setq port-dir-car (cddr (car port-list))
10934 port-dir (car port-dir-car))
10935 (setcar port-dir-car
10936 (cond ((equal port-dir "in") "out")
10937 ((equal port-dir "out") "in")
10938 (t port-dir)))
10939 (setq port-list (cdr port-list)))
10940 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10941 (message "Reversing port directions for next paste...done"))))
10942
10943 (defun vhdl-port-copy ()
10944 "Get generic and port information from an entity or component declaration."
10945 (interactive)
10946 (save-excursion
10947 (let (parse-error end-of-list
10948 decl-type name generic-list port-list context-clause
10949 object names direct type init comment group-comment)
10950 (vhdl-prepare-search-2
10951 (setq
10952 parse-error
10953 (catch 'parse
10954 ;; check if within entity or component declaration
10955 (end-of-line)
10956 (when (or (not (re-search-backward
10957 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10958 (equal "END" (upcase (match-string 1))))
10959 (throw 'parse "ERROR: Not within an entity or component declaration"))
10960 (setq decl-type (downcase (match-string-no-properties 1)))
10961 (forward-word 1)
10962 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10963 (setq name (match-string-no-properties 1))
10964 (message "Reading port of %s \"%s\"..." decl-type name)
10965 (vhdl-forward-syntactic-ws)
10966 ;; parse generic clause
10967 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10968 ;; parse group comment and spacing
10969 (setq group-comment (vhdl-parse-group-comment))
10970 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10971 (while (not end-of-list)
10972 ;; parse names (accept extended identifiers)
10973 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10974 (setq names (list (match-string-no-properties 1)))
10975 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10976 (setq names
10977 (append names (list (match-string-no-properties 1)))))
10978 ;; parse type
10979 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10980 (setq type (match-string-no-properties 1))
10981 (setq comment nil)
10982 (while (looking-at "(")
10983 (setq type
10984 (concat type
10985 (buffer-substring-no-properties
10986 (point) (progn (forward-sexp) (point)))
10987 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10988 (match-string-no-properties 1)))))
10989 ;; special case: closing parenthesis is on separate line
10990 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10991 (setq comment (substring type (match-beginning 2)))
10992 (setq type (substring type 0 (match-beginning 1))))
10993 ;; strip of trailing group-comment
10994 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10995 (setq type (substring type 0 (match-end 1)))
10996 ;; parse initialization expression
10997 (setq init nil)
10998 (when (vhdl-parse-string ":=[ \t\n]*" t)
10999 (vhdl-parse-string "\\([^();\n]*\\)")
11000 (setq init (match-string-no-properties 1))
11001 (while (looking-at "(")
11002 (setq init
11003 (concat init
11004 (buffer-substring-no-properties
11005 (point) (progn (forward-sexp) (point)))
11006 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11007 (match-string-no-properties 1))))))
11008 ;; special case: closing parenthesis is on separate line
11009 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11010 (setq comment (substring init (match-beginning 2)))
11011 (setq init (substring init 0 (match-beginning 1)))
11012 (vhdl-forward-syntactic-ws))
11013 (skip-chars-forward " \t")
11014 ;; parse inline comment, special case: as above, no initial.
11015 (unless comment
11016 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11017 (match-string-no-properties 1))))
11018 (vhdl-forward-syntactic-ws)
11019 (setq end-of-list (vhdl-parse-string ")" t))
11020 (vhdl-parse-string "\\s-*;\\s-*")
11021 ;; parse inline comment
11022 (unless comment
11023 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11024 (match-string-no-properties 1))))
11025 ;; save everything in list
11026 (setq generic-list (append generic-list
11027 (list (list names type init
11028 comment group-comment))))
11029 ;; parse group comment and spacing
11030 (setq group-comment (vhdl-parse-group-comment))))
11031 ;; parse port clause
11032 (when (vhdl-parse-string "port[ \t\n]*(" t)
11033 ;; parse group comment and spacing
11034 (setq group-comment (vhdl-parse-group-comment))
11035 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11036 (while (not end-of-list)
11037 ;; parse object
11038 (setq object
11039 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11040 (match-string-no-properties 1)))
11041 ;; parse names (accept extended identifiers)
11042 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11043 (setq names (list (match-string-no-properties 1)))
11044 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11045 (setq names (append names (list (match-string-no-properties 1)))))
11046 ;; parse direction
11047 (vhdl-parse-string ":[ \t\n]*")
11048 (setq direct
11049 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11050 (match-string-no-properties 1)))
11051 ;; parse type
11052 (vhdl-parse-string "\\([^();\n]+\\)")
11053 (setq type (match-string-no-properties 1))
11054 (setq comment nil)
11055 (while (looking-at "(")
11056 (setq type (concat type
11057 (buffer-substring-no-properties
11058 (point) (progn (forward-sexp) (point)))
11059 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11060 (match-string-no-properties 1)))))
11061 ;; special case: closing parenthesis is on separate line
11062 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11063 (setq comment (substring type (match-beginning 2)))
11064 (setq type (substring type 0 (match-beginning 1))))
11065 ;; strip of trailing group-comment
11066 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11067 (setq type (substring type 0 (match-end 1)))
11068 (vhdl-forward-syntactic-ws)
11069 (setq end-of-list (vhdl-parse-string ")" t))
11070 (vhdl-parse-string "\\s-*;\\s-*")
11071 ;; parse inline comment
11072 (unless comment
11073 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11074 (match-string-no-properties 1))))
11075 ;; save everything in list
11076 (setq port-list (append port-list
11077 (list (list names object direct type
11078 comment group-comment))))
11079 ;; parse group comment and spacing
11080 (setq group-comment (vhdl-parse-group-comment))))
11081 ; (vhdl-parse-string "end\\>")
11082 ;; parse context clause
11083 (setq context-clause (vhdl-scan-context-clause))
11084 ; ;; add surrounding package to context clause
11085 ; (when (and (equal decl-type "component")
11086 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11087 ; (setq context-clause
11088 ; (append context-clause
11089 ; (list (cons (vhdl-work-library)
11090 ; (match-string-no-properties 1))))))
11091 (message "Reading port of %s \"%s\"...done" decl-type name)
11092 nil)))
11093 ;; finish parsing
11094 (if parse-error
11095 (error parse-error)
11096 (setq vhdl-port-list (list name generic-list port-list context-clause)
11097 vhdl-port-reversed-direction nil
11098 vhdl-port-flattened nil)))))
11099
11100 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11101 "Paste a context clause."
11102 (let ((margin (current-indentation))
11103 (clause-list (nth 3 vhdl-port-list))
11104 clause)
11105 (while clause-list
11106 (setq clause (car clause-list))
11107 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11108 (downcase exclude-pack-name)))
11109 (save-excursion
11110 (re-search-backward
11111 (concat "^\\s-*use\\s-+" (car clause)
11112 "\." (cdr clause) "\\>") nil t)))
11113 (vhdl-template-standard-package (car clause) (cdr clause))
11114 (insert "\n"))
11115 (setq clause-list (cdr clause-list)))))
11116
11117 (defun vhdl-port-paste-generic (&optional no-init)
11118 "Paste a generic clause."
11119 (let ((margin (current-indentation))
11120 (generic-list (nth 1 vhdl-port-list))
11121 list-margin start names generic)
11122 ;; paste generic clause
11123 (when generic-list
11124 (setq start (point))
11125 (vhdl-insert-keyword "GENERIC (")
11126 (unless vhdl-argument-list-indent
11127 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11128 (setq list-margin (current-column))
11129 (while generic-list
11130 (setq generic (car generic-list))
11131 ;; paste group comment and spacing
11132 (when (memq vhdl-include-group-comments '(decl always))
11133 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11134 ;; paste names
11135 (setq names (nth 0 generic))
11136 (while names
11137 (insert (car names))
11138 (setq names (cdr names))
11139 (when names (insert ", ")))
11140 ;; paste type
11141 (insert " : " (nth 1 generic))
11142 ;; paste initialization
11143 (when (and (not no-init) (nth 2 generic))
11144 (insert " := " (nth 2 generic)))
11145 (unless (cdr generic-list) (insert ")"))
11146 (insert ";")
11147 ;; paste comment
11148 (when (and vhdl-include-port-comments (nth 3 generic))
11149 (vhdl-comment-insert-inline (nth 3 generic) t))
11150 (setq generic-list (cdr generic-list))
11151 (when generic-list (insert "\n") (indent-to list-margin)))
11152 ;; align generic clause
11153 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11154
11155 (defun vhdl-port-paste-port ()
11156 "Paste a port clause."
11157 (let ((margin (current-indentation))
11158 (port-list (nth 2 vhdl-port-list))
11159 list-margin start names port)
11160 ;; paste port clause
11161 (when port-list
11162 (setq start (point))
11163 (vhdl-insert-keyword "PORT (")
11164 (unless vhdl-argument-list-indent
11165 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11166 (setq list-margin (current-column))
11167 (while port-list
11168 (setq port (car port-list))
11169 ;; paste group comment and spacing
11170 (when (memq vhdl-include-group-comments '(decl always))
11171 (vhdl-paste-group-comment (nth 5 port) list-margin))
11172 ;; paste object
11173 (when (nth 1 port) (insert (nth 1 port) " "))
11174 ;; paste names
11175 (setq names (nth 0 port))
11176 (while names
11177 (insert (car names))
11178 (setq names (cdr names))
11179 (when names (insert ", ")))
11180 ;; paste direction
11181 (insert " : ")
11182 (when (nth 2 port) (insert (nth 2 port) " "))
11183 ;; paste type
11184 (insert (nth 3 port))
11185 (unless (cdr port-list) (insert ")"))
11186 (insert ";")
11187 ;; paste comment
11188 (when (and vhdl-include-port-comments (nth 4 port))
11189 (vhdl-comment-insert-inline (nth 4 port) t))
11190 (setq port-list (cdr port-list))
11191 (when port-list (insert "\n") (indent-to list-margin)))
11192 ;; align port clause
11193 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11194
11195 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11196 "Paste as an entity or component declaration."
11197 (unless no-indent (indent-according-to-mode))
11198 (let ((margin (current-indentation))
11199 (name (nth 0 vhdl-port-list)))
11200 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11201 (insert name)
11202 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11203 (vhdl-insert-keyword " IS"))
11204 ;; paste generic and port clause
11205 (when (nth 1 vhdl-port-list)
11206 (insert "\n")
11207 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11208 (insert "\n"))
11209 (indent-to (+ margin vhdl-basic-offset))
11210 (vhdl-port-paste-generic (eq kind 'component)))
11211 (when (nth 2 vhdl-port-list)
11212 (insert "\n")
11213 (when (and (memq vhdl-insert-empty-lines '(unit all))
11214 (eq kind 'entity))
11215 (insert "\n"))
11216 (indent-to (+ margin vhdl-basic-offset)))
11217 (vhdl-port-paste-port)
11218 (insert "\n")
11219 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11220 (insert "\n"))
11221 (indent-to margin)
11222 (vhdl-insert-keyword "END")
11223 (if (eq kind 'entity)
11224 (progn
11225 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11226 (insert " " name))
11227 (vhdl-insert-keyword " COMPONENT")
11228 (unless (vhdl-standard-p '87) (insert " " name)))
11229 (insert ";")))
11230
11231 (defun vhdl-port-paste-entity (&optional no-indent)
11232 "Paste as an entity declaration."
11233 (interactive)
11234 (if (not vhdl-port-list)
11235 (error "ERROR: No port read")
11236 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11237 (vhdl-port-paste-declaration 'entity no-indent)
11238 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11239
11240 (defun vhdl-port-paste-component (&optional no-indent)
11241 "Paste as a component declaration."
11242 (interactive)
11243 (if (not vhdl-port-list)
11244 (error "ERROR: No port read")
11245 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11246 (vhdl-port-paste-declaration 'component no-indent)
11247 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11248
11249 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11250 "Paste as a generic map."
11251 (interactive)
11252 (unless secondary (indent-according-to-mode))
11253 (let ((margin (current-indentation))
11254 list-margin start generic
11255 (generic-list (nth 1 vhdl-port-list)))
11256 (when generic-list
11257 (setq start (point))
11258 (vhdl-insert-keyword "GENERIC MAP (")
11259 (if (not vhdl-association-list-with-formals)
11260 ;; paste list of actual generics
11261 (while generic-list
11262 (insert (if no-constants
11263 (car (nth 0 (car generic-list)))
11264 (or (nth 2 (car generic-list)) " ")))
11265 (setq generic-list (cdr generic-list))
11266 (insert (if generic-list ", " ")"))
11267 (when (and (not generic-list) secondary
11268 (null (nth 2 vhdl-port-list)))
11269 (insert ";")))
11270 (unless vhdl-argument-list-indent
11271 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11272 (setq list-margin (current-column))
11273 (while generic-list
11274 (setq generic (car generic-list))
11275 ;; paste group comment and spacing
11276 (when (eq vhdl-include-group-comments 'always)
11277 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11278 ;; paste formal and actual generic
11279 (insert (car (nth 0 generic)) " => "
11280 (if no-constants
11281 (car (nth 0 generic))
11282 (or (nth 2 generic) "")))
11283 (setq generic-list (cdr generic-list))
11284 (insert (if generic-list "," ")"))
11285 (when (and (not generic-list) secondary
11286 (null (nth 2 vhdl-port-list)))
11287 (insert ";"))
11288 ;; paste comment
11289 (when (or vhdl-include-type-comments
11290 (and vhdl-include-port-comments (nth 3 generic)))
11291 (vhdl-comment-insert-inline
11292 (concat
11293 (when vhdl-include-type-comments
11294 (concat "[" (nth 1 generic) "] "))
11295 (when vhdl-include-port-comments (nth 3 generic))) t))
11296 (when generic-list (insert "\n") (indent-to list-margin)))
11297 ;; align generic map
11298 (when vhdl-auto-align
11299 (vhdl-align-region-groups start (point) 1 t))))))
11300
11301 (defun vhdl-port-paste-port-map ()
11302 "Paste as a port map."
11303 (let ((margin (current-indentation))
11304 list-margin start port
11305 (port-list (nth 2 vhdl-port-list)))
11306 (when port-list
11307 (setq start (point))
11308 (vhdl-insert-keyword "PORT MAP (")
11309 (if (not vhdl-association-list-with-formals)
11310 ;; paste list of actual ports
11311 (while port-list
11312 (insert (vhdl-replace-string vhdl-actual-port-name
11313 (car (nth 0 (car port-list)))))
11314 (setq port-list (cdr port-list))
11315 (insert (if port-list ", " ")")))
11316 (unless vhdl-argument-list-indent
11317 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11318 (setq list-margin (current-column))
11319 (while port-list
11320 (setq port (car port-list))
11321 ;; paste group comment and spacing
11322 (when (eq vhdl-include-group-comments 'always)
11323 (vhdl-paste-group-comment (nth 5 port) list-margin))
11324 ;; paste formal and actual port
11325 (insert (car (nth 0 port)) " => ")
11326 (insert (vhdl-replace-string vhdl-actual-port-name
11327 (car (nth 0 port))))
11328 (setq port-list (cdr port-list))
11329 (insert (if port-list "," ");"))
11330 ;; paste comment
11331 (when (or vhdl-include-direction-comments
11332 vhdl-include-type-comments
11333 (and vhdl-include-port-comments (nth 4 port)))
11334 (vhdl-comment-insert-inline
11335 (concat
11336 (cond ((and vhdl-include-direction-comments
11337 vhdl-include-type-comments)
11338 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11339 (nth 3 port) "] "))
11340 ((and vhdl-include-direction-comments (nth 2 port))
11341 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11342 (vhdl-include-direction-comments " ")
11343 (vhdl-include-type-comments
11344 (concat "[" (nth 3 port) "] ")))
11345 (when vhdl-include-port-comments (nth 4 port))) t))
11346 (when port-list (insert "\n") (indent-to list-margin)))
11347 ;; align port clause
11348 (when vhdl-auto-align
11349 (vhdl-align-region-groups start (point) 1))))))
11350
11351 (defun vhdl-port-paste-instance (&optional name no-indent title)
11352 "Paste as an instantiation."
11353 (interactive)
11354 (if (not vhdl-port-list)
11355 (error "ERROR: No port read")
11356 (let ((orig-vhdl-port-list vhdl-port-list))
11357 ;; flatten local copy of port list (must be flat for port mapping)
11358 (vhdl-port-flatten)
11359 (unless no-indent (indent-according-to-mode))
11360 (let ((margin (current-indentation)))
11361 ;; paste instantiation
11362 (cond (name
11363 (insert name))
11364 ((equal (cdr vhdl-instance-name) "")
11365 (setq name (vhdl-template-field "instance name")))
11366 ((string-match "\%d" (cdr vhdl-instance-name))
11367 (let ((n 1))
11368 (while (save-excursion
11369 (setq name (format (vhdl-replace-string
11370 vhdl-instance-name
11371 (nth 0 vhdl-port-list)) n))
11372 (goto-char (point-min))
11373 (vhdl-re-search-forward name nil t))
11374 (setq n (1+ n)))
11375 (insert name)))
11376 (t (insert (vhdl-replace-string vhdl-instance-name
11377 (nth 0 vhdl-port-list)))))
11378 (message "Pasting port as instantiation \"%s\"..." name)
11379 (insert ": ")
11380 (when title
11381 (save-excursion
11382 (beginning-of-line)
11383 (indent-to vhdl-basic-offset)
11384 (insert "-- instance \"" name "\"\n")))
11385 (if (not (vhdl-use-direct-instantiation))
11386 (insert (nth 0 vhdl-port-list))
11387 (vhdl-insert-keyword "ENTITY ")
11388 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11389 (when (nth 1 vhdl-port-list)
11390 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11391 (vhdl-port-paste-generic-map t t))
11392 (when (nth 2 vhdl-port-list)
11393 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11394 (vhdl-port-paste-port-map))
11395 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11396 (insert ";"))
11397 (message "Pasting port as instantiation \"%s\"...done" name))
11398 (setq vhdl-port-list orig-vhdl-port-list))))
11399
11400 (defun vhdl-port-paste-constants (&optional no-indent)
11401 "Paste generics as constants."
11402 (interactive)
11403 (if (not vhdl-port-list)
11404 (error "ERROR: No port read")
11405 (let ((orig-vhdl-port-list vhdl-port-list))
11406 (message "Pasting port as constants...")
11407 ;; flatten local copy of port list (must be flat for constant initial.)
11408 (vhdl-port-flatten)
11409 (unless no-indent (indent-according-to-mode))
11410 (let ((margin (current-indentation))
11411 start generic name
11412 (generic-list (nth 1 vhdl-port-list)))
11413 (when generic-list
11414 (setq start (point))
11415 (while generic-list
11416 (setq generic (car generic-list))
11417 ;; paste group comment and spacing
11418 (when (memq vhdl-include-group-comments '(decl always))
11419 (vhdl-paste-group-comment (nth 4 generic) margin))
11420 (vhdl-insert-keyword "CONSTANT ")
11421 ;; paste generic constants
11422 (setq name (nth 0 generic))
11423 (when name
11424 (insert (car name))
11425 ;; paste type
11426 (insert " : " (nth 1 generic))
11427 ;; paste initialization
11428 (when (nth 2 generic)
11429 (insert " := " (nth 2 generic)))
11430 (insert ";")
11431 ;; paste comment
11432 (when (and vhdl-include-port-comments (nth 3 generic))
11433 (vhdl-comment-insert-inline (nth 3 generic) t))
11434 (setq generic-list (cdr generic-list))
11435 (when generic-list (insert "\n") (indent-to margin))))
11436 ;; align signal list
11437 (when vhdl-auto-align
11438 (vhdl-align-region-groups start (point) 1))))
11439 (message "Pasting port as constants...done")
11440 (setq vhdl-port-list orig-vhdl-port-list))))
11441
11442 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11443 "Paste ports as internal signals."
11444 (interactive)
11445 (if (not vhdl-port-list)
11446 (error "ERROR: No port read")
11447 (message "Pasting port as signals...")
11448 (unless no-indent (indent-according-to-mode))
11449 (let ((margin (current-indentation))
11450 start port names
11451 (port-list (nth 2 vhdl-port-list)))
11452 (when port-list
11453 (setq start (point))
11454 (while port-list
11455 (setq port (car port-list))
11456 ;; paste group comment and spacing
11457 (when (memq vhdl-include-group-comments '(decl always))
11458 (vhdl-paste-group-comment (nth 5 port) margin))
11459 ;; paste object
11460 (if (nth 1 port)
11461 (insert (nth 1 port) " ")
11462 (vhdl-insert-keyword "SIGNAL "))
11463 ;; paste actual port signals
11464 (setq names (nth 0 port))
11465 (while names
11466 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11467 (setq names (cdr names))
11468 (when names (insert ", ")))
11469 ;; paste type
11470 (insert " : " (nth 3 port))
11471 ;; paste initialization (inputs only)
11472 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11473 (insert " := " (if (string-match "(.+)" (nth 3 port))
11474 "(others => '0')" "'0'")))
11475 (insert ";")
11476 ;; paste comment
11477 (when (or vhdl-include-direction-comments
11478 (and vhdl-include-port-comments (nth 4 port)))
11479 (vhdl-comment-insert-inline
11480 (concat
11481 (cond ((and vhdl-include-direction-comments (nth 2 port))
11482 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11483 (vhdl-include-direction-comments " "))
11484 (when vhdl-include-port-comments (nth 4 port))) t))
11485 (setq port-list (cdr port-list))
11486 (when port-list (insert "\n") (indent-to margin)))
11487 ;; align signal list
11488 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11489 (message "Pasting port as signals...done")))
11490
11491 (defun vhdl-port-paste-initializations (&optional no-indent)
11492 "Paste ports as signal initializations."
11493 (interactive)
11494 (if (not vhdl-port-list)
11495 (error "ERROR: No port read")
11496 (let ((orig-vhdl-port-list vhdl-port-list))
11497 (message "Pasting port as initializations...")
11498 ;; flatten local copy of port list (must be flat for signal initial.)
11499 (vhdl-port-flatten)
11500 (unless no-indent (indent-according-to-mode))
11501 (let ((margin (current-indentation))
11502 start port name
11503 (port-list (nth 2 vhdl-port-list)))
11504 (when port-list
11505 (setq start (point))
11506 (while port-list
11507 (setq port (car port-list))
11508 ;; paste actual port signal (inputs only)
11509 (when (equal "IN" (upcase (nth 2 port)))
11510 (setq name (car (nth 0 port)))
11511 (insert (vhdl-replace-string vhdl-actual-port-name name))
11512 ;; paste initialization
11513 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11514 "(others => '0')" "'0'") ";"))
11515 (setq port-list (cdr port-list))
11516 (when (and port-list
11517 (equal "IN" (upcase (nth 2 (car port-list)))))
11518 (insert "\n") (indent-to margin)))
11519 ;; align signal list
11520 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11521 (message "Pasting port as initializations...done")
11522 (setq vhdl-port-list orig-vhdl-port-list))))
11523
11524 (defun vhdl-port-paste-testbench ()
11525 "Paste as a bare-bones testbench."
11526 (interactive)
11527 (if (not vhdl-port-list)
11528 (error "ERROR: No port read")
11529 (let ((case-fold-search t)
11530 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11531 (nth 0 vhdl-port-list)))
11532 (source-buffer (current-buffer))
11533 arch-name config-name ent-file-name arch-file-name
11534 ent-buffer arch-buffer position)
11535 ;; open entity file
11536 (unless (eq vhdl-testbench-create-files 'none)
11537 (setq ent-file-name
11538 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11539 ent-name t)
11540 "." (file-name-extension (buffer-file-name))))
11541 (if (file-exists-p ent-file-name)
11542 (if (y-or-n-p
11543 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11544 (progn (find-file ent-file-name)
11545 (erase-buffer)
11546 (set-buffer-modified-p nil))
11547 (if (eq vhdl-testbench-create-files 'separate)
11548 (setq ent-file-name nil)
11549 (error "ERROR: Pasting port as testbench...aborted")))
11550 (find-file ent-file-name)))
11551 (unless (and (eq vhdl-testbench-create-files 'separate)
11552 (null ent-file-name))
11553 ;; paste entity header
11554 (if vhdl-testbench-include-header
11555 (progn (vhdl-template-header
11556 (concat "Testbench for design \""
11557 (nth 0 vhdl-port-list) "\""))
11558 (goto-char (point-max)))
11559 (vhdl-comment-display-line) (insert "\n\n"))
11560 ;; paste std_logic_1164 package
11561 (when vhdl-testbench-include-library
11562 (vhdl-template-package-std-logic-1164)
11563 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11564 ;; paste entity declaration
11565 (vhdl-insert-keyword "ENTITY ")
11566 (insert ent-name)
11567 (vhdl-insert-keyword " IS")
11568 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11569 (insert "\n")
11570 (vhdl-insert-keyword "END ")
11571 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11572 (insert ent-name ";")
11573 (insert "\n\n")
11574 (vhdl-comment-display-line) (insert "\n"))
11575 ;; get architecture name
11576 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11577 (read-from-minibuffer "architecture name: "
11578 nil vhdl-minibuffer-local-map)
11579 (vhdl-replace-string vhdl-testbench-architecture-name
11580 (nth 0 vhdl-port-list))))
11581 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11582 ;; open architecture file
11583 (if (not (eq vhdl-testbench-create-files 'separate))
11584 (insert "\n")
11585 (setq ent-buffer (current-buffer))
11586 (setq arch-file-name
11587 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11588 (concat ent-name " " arch-name) t)
11589 "." (file-name-extension (buffer-file-name))))
11590 (when (and (file-exists-p arch-file-name)
11591 (not (y-or-n-p (concat "File \"" arch-file-name
11592 "\" exists; overwrite? "))))
11593 (error "ERROR: Pasting port as testbench...aborted"))
11594 (find-file arch-file-name)
11595 (erase-buffer)
11596 (set-buffer-modified-p nil)
11597 ;; paste architecture header
11598 (if vhdl-testbench-include-header
11599 (progn (vhdl-template-header
11600 (concat "Testbench architecture for design \""
11601 (nth 0 vhdl-port-list) "\""))
11602 (goto-char (point-max)))
11603 (vhdl-comment-display-line) (insert "\n\n")))
11604 ;; paste architecture body
11605 (vhdl-insert-keyword "ARCHITECTURE ")
11606 (insert arch-name)
11607 (vhdl-insert-keyword " OF ")
11608 (insert ent-name)
11609 (vhdl-insert-keyword " IS")
11610 (insert "\n\n") (indent-to vhdl-basic-offset)
11611 ;; paste component declaration
11612 (unless (vhdl-use-direct-instantiation)
11613 (vhdl-port-paste-component t)
11614 (insert "\n\n") (indent-to vhdl-basic-offset))
11615 ;; paste constants
11616 (when (nth 1 vhdl-port-list)
11617 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11618 (vhdl-port-paste-constants t)
11619 (insert "\n\n") (indent-to vhdl-basic-offset))
11620 ;; paste internal signals
11621 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11622 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11623 (insert "\n")
11624 ;; paste custom declarations
11625 (unless (equal "" vhdl-testbench-declarations)
11626 (insert "\n")
11627 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11628 (setq position (point))
11629 (insert "\n\n")
11630 (vhdl-comment-display-line) (insert "\n")
11631 (when vhdl-testbench-include-configuration
11632 (setq config-name (vhdl-replace-string
11633 vhdl-testbench-configuration-name
11634 (concat ent-name " " arch-name)))
11635 (insert "\n")
11636 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11637 (vhdl-insert-keyword " OF ") (insert ent-name)
11638 (vhdl-insert-keyword " IS\n")
11639 (indent-to vhdl-basic-offset)
11640 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11641 (indent-to vhdl-basic-offset)
11642 (vhdl-insert-keyword "END FOR;\n")
11643 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11644 (vhdl-comment-display-line) (insert "\n"))
11645 (goto-char position)
11646 (vhdl-template-begin-end
11647 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11648 ;; paste instantiation
11649 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11650 (vhdl-port-paste-instance
11651 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11652 (insert "\n")
11653 ;; paste custom statements
11654 (unless (equal "" vhdl-testbench-statements)
11655 (insert "\n")
11656 (vhdl-insert-string-or-file vhdl-testbench-statements))
11657 (insert "\n")
11658 (indent-to vhdl-basic-offset)
11659 (unless (eq vhdl-testbench-create-files 'none)
11660 (setq arch-buffer (current-buffer))
11661 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11662 (set-buffer arch-buffer) (save-buffer))
11663 (message "%s"
11664 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11665 ent-name arch-name)
11666 (and ent-file-name
11667 (format "\n File created: \"%s\"" ent-file-name))
11668 (and arch-file-name
11669 (format "\n File created: \"%s\"" arch-file-name)))))))
11670
11671
11672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11673 ;;; Subprogram interface translation
11674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11675
11676 (defvar vhdl-subprog-list nil
11677 "Variable to hold last subprogram interface parsed.")
11678 ;; structure: (parenthesised expression means list of such entries)
11679 ;; (subprog-name kind
11680 ;; ((names) object direct type init comment group-comment)
11681 ;; return-type return-comment group-comment)
11682
11683 (defvar vhdl-subprog-flattened nil
11684 "Indicates whether an subprogram interface has been flattened.")
11685
11686 (defun vhdl-subprog-flatten ()
11687 "Flatten interface list so that only one parameter exists per line."
11688 (interactive)
11689 (if (not vhdl-subprog-list)
11690 (error "ERROR: No subprogram interface has been read")
11691 (message "Flattening subprogram interface...")
11692 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11693 new-subprog-list old-subprog new-subprog names)
11694 ;; traverse parameter list and flatten entries
11695 (while old-subprog-list
11696 (setq old-subprog (car old-subprog-list))
11697 (setq names (car old-subprog))
11698 (while names
11699 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11700 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11701 (setq names (cdr names)))
11702 (setq old-subprog-list (cdr old-subprog-list)))
11703 (setq vhdl-subprog-list
11704 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11705 new-subprog-list (nth 3 vhdl-subprog-list)
11706 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11707 vhdl-subprog-flattened t)
11708 (message "Flattening subprogram interface...done"))))
11709
11710 (defun vhdl-subprog-copy ()
11711 "Get interface information from a subprogram specification."
11712 (interactive)
11713 (save-excursion
11714 (let (parse-error pos end-of-list
11715 name kind param-list object names direct type init
11716 comment group-comment
11717 return-type return-comment return-group-comment)
11718 (vhdl-prepare-search-2
11719 (setq
11720 parse-error
11721 (catch 'parse
11722 ;; check if within function declaration
11723 (setq pos (point))
11724 (end-of-line)
11725 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11726 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11727 (goto-char (match-end 0))
11728 (save-excursion (backward-char)
11729 (forward-sexp)
11730 (<= pos (point))))
11731 (throw 'parse "ERROR: Not within a subprogram specification"))
11732 (setq name (match-string-no-properties 5))
11733 (setq kind (if (match-string 2) 'procedure 'function))
11734 (setq end-of-list (not (match-string 7)))
11735 (message "Reading interface of subprogram \"%s\"..." name)
11736 ;; parse parameter list
11737 (setq group-comment (vhdl-parse-group-comment))
11738 (setq end-of-list (or end-of-list
11739 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11740 (while (not end-of-list)
11741 ;; parse object
11742 (setq object
11743 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11744 (match-string-no-properties 1)))
11745 ;; parse names (accept extended identifiers)
11746 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11747 (setq names (list (match-string-no-properties 1)))
11748 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11749 (setq names (append names (list (match-string-no-properties 1)))))
11750 ;; parse direction
11751 (vhdl-parse-string ":[ \t\n]*")
11752 (setq direct
11753 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11754 (match-string-no-properties 1)))
11755 ;; parse type
11756 (vhdl-parse-string "\\([^():;\n]+\\)")
11757 (setq type (match-string-no-properties 1))
11758 (setq comment nil)
11759 (while (looking-at "(")
11760 (setq type
11761 (concat type
11762 (buffer-substring-no-properties
11763 (point) (progn (forward-sexp) (point)))
11764 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11765 (match-string-no-properties 1)))))
11766 ;; special case: closing parenthesis is on separate line
11767 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11768 (setq comment (substring type (match-beginning 2)))
11769 (setq type (substring type 0 (match-beginning 1))))
11770 ;; strip off trailing group-comment
11771 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11772 (setq type (substring type 0 (match-end 1)))
11773 ;; parse initialization expression
11774 (setq init nil)
11775 (when (vhdl-parse-string ":=[ \t\n]*" t)
11776 (vhdl-parse-string "\\([^();\n]*\\)")
11777 (setq init (match-string-no-properties 1))
11778 (while (looking-at "(")
11779 (setq init
11780 (concat init
11781 (buffer-substring-no-properties
11782 (point) (progn (forward-sexp) (point)))
11783 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11784 (match-string-no-properties 1))))))
11785 ;; special case: closing parenthesis is on separate line
11786 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11787 (setq comment (substring init (match-beginning 2)))
11788 (setq init (substring init 0 (match-beginning 1)))
11789 (vhdl-forward-syntactic-ws))
11790 (skip-chars-forward " \t")
11791 ;; parse inline comment, special case: as above, no initial.
11792 (unless comment
11793 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11794 (match-string-no-properties 1))))
11795 (vhdl-forward-syntactic-ws)
11796 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11797 ;; parse inline comment
11798 (unless comment
11799 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11800 (match-string-no-properties 1))))
11801 (setq return-group-comment (vhdl-parse-group-comment))
11802 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11803 ;; parse return type
11804 (when (match-string 3)
11805 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11806 (setq return-type (match-string-no-properties 1))
11807 (when (and return-type
11808 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11809 (setq return-comment (substring return-type (match-beginning 2)))
11810 (setq return-type (substring return-type 0 (match-beginning 1))))
11811 ;; strip of trailing group-comment
11812 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11813 (setq return-type (substring return-type 0 (match-end 1)))
11814 ;; parse return comment
11815 (unless return-comment
11816 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11817 (match-string-no-properties 1)))))
11818 ;; parse inline comment
11819 (unless comment
11820 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11821 (match-string-no-properties 1))))
11822 ;; save everything in list
11823 (setq param-list (append param-list
11824 (list (list names object direct type init
11825 comment group-comment))))
11826 ;; parse group comment and spacing
11827 (setq group-comment (vhdl-parse-group-comment)))
11828 (message "Reading interface of subprogram \"%s\"...done" name)
11829 nil)))
11830 ;; finish parsing
11831 (if parse-error
11832 (error parse-error)
11833 (setq vhdl-subprog-list
11834 (list name kind param-list return-type return-comment
11835 return-group-comment)
11836 vhdl-subprog-flattened nil)))))
11837
11838 (defun vhdl-subprog-paste-specification (kind)
11839 "Paste as a subprogram specification."
11840 (indent-according-to-mode)
11841 (let ((margin (current-column))
11842 (param-list (nth 2 vhdl-subprog-list))
11843 list-margin start names param)
11844 ;; paste keyword and name
11845 (vhdl-insert-keyword
11846 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11847 (insert (nth 0 vhdl-subprog-list))
11848 (if (not param-list)
11849 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11850 (setq start (point))
11851 ;; paste parameter list
11852 (insert " (")
11853 (unless vhdl-argument-list-indent
11854 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11855 (setq list-margin (current-column))
11856 (while param-list
11857 (setq param (car param-list))
11858 ;; paste group comment and spacing
11859 (when (memq vhdl-include-group-comments (list kind 'always))
11860 (vhdl-paste-group-comment (nth 6 param) list-margin))
11861 ;; paste object
11862 (when (nth 1 param) (insert (nth 1 param) " "))
11863 ;; paste names
11864 (setq names (nth 0 param))
11865 (while names
11866 (insert (car names))
11867 (setq names (cdr names))
11868 (when names (insert ", ")))
11869 ;; paste direction
11870 (insert " : ")
11871 (when (nth 2 param) (insert (nth 2 param) " "))
11872 ;; paste type
11873 (insert (nth 3 param))
11874 ;; paste initialization
11875 (when (nth 4 param) (insert " := " (nth 4 param)))
11876 ;; terminate line
11877 (if (cdr param-list)
11878 (insert ";")
11879 (insert ")")
11880 (when (null (nth 3 vhdl-subprog-list))
11881 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11882 ;; paste comment
11883 (when (and vhdl-include-port-comments (nth 5 param))
11884 (vhdl-comment-insert-inline (nth 5 param) t))
11885 (setq param-list (cdr param-list))
11886 (when param-list (insert "\n") (indent-to list-margin)))
11887 (when (nth 3 vhdl-subprog-list)
11888 (insert "\n") (indent-to list-margin)
11889 ;; paste group comment and spacing
11890 (when (memq vhdl-include-group-comments (list kind 'always))
11891 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11892 ;; paste return type
11893 (insert "return " (nth 3 vhdl-subprog-list))
11894 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11895 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11896 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11897 ;; align parameter list
11898 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11899 ;; paste body
11900 (when (eq kind 'body)
11901 (insert "\n")
11902 (vhdl-template-begin-end
11903 (unless (vhdl-standard-p '87)
11904 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11905 (nth 0 vhdl-subprog-list) margin))))
11906
11907 (defun vhdl-subprog-paste-declaration ()
11908 "Paste as a subprogram declaration."
11909 (interactive)
11910 (if (not vhdl-subprog-list)
11911 (error "ERROR: No subprogram interface read")
11912 (message "Pasting interface as subprogram declaration \"%s\"..."
11913 (car vhdl-subprog-list))
11914 ;; paste specification
11915 (vhdl-subprog-paste-specification 'decl)
11916 (message "Pasting interface as subprogram declaration \"%s\"...done"
11917 (car vhdl-subprog-list))))
11918
11919 (defun vhdl-subprog-paste-body ()
11920 "Paste as a subprogram body."
11921 (interactive)
11922 (if (not vhdl-subprog-list)
11923 (error "ERROR: No subprogram interface read")
11924 (message "Pasting interface as subprogram body \"%s\"..."
11925 (car vhdl-subprog-list))
11926 ;; paste specification and body
11927 (vhdl-subprog-paste-specification 'body)
11928 (message "Pasting interface as subprogram body \"%s\"...done"
11929 (car vhdl-subprog-list))))
11930
11931 (defun vhdl-subprog-paste-call ()
11932 "Paste as a subprogram call."
11933 (interactive)
11934 (if (not vhdl-subprog-list)
11935 (error "ERROR: No subprogram interface read")
11936 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11937 param-list margin list-margin param start)
11938 ;; flatten local copy of interface list (must be flat for parameter mapping)
11939 (vhdl-subprog-flatten)
11940 (setq param-list (nth 2 vhdl-subprog-list))
11941 (indent-according-to-mode)
11942 (setq margin (current-indentation))
11943 (message "Pasting interface as subprogram call \"%s\"..."
11944 (car vhdl-subprog-list))
11945 ;; paste name
11946 (insert (nth 0 vhdl-subprog-list))
11947 (if (not param-list)
11948 (insert ";")
11949 (setq start (point))
11950 ;; paste parameter list
11951 (insert " (")
11952 (unless vhdl-argument-list-indent
11953 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11954 (setq list-margin (current-column))
11955 (while param-list
11956 (setq param (car param-list))
11957 ;; paste group comment and spacing
11958 (when (eq vhdl-include-group-comments 'always)
11959 (vhdl-paste-group-comment (nth 6 param) list-margin))
11960 ;; paste formal port
11961 (insert (car (nth 0 param)) " => ")
11962 (setq param-list (cdr param-list))
11963 (insert (if param-list "," ");"))
11964 ;; paste comment
11965 (when (and vhdl-include-port-comments (nth 5 param))
11966 (vhdl-comment-insert-inline (nth 5 param)))
11967 (when param-list (insert "\n") (indent-to list-margin)))
11968 ;; align parameter list
11969 (when vhdl-auto-align
11970 (vhdl-align-region-groups start (point) 1)))
11971 (message "Pasting interface as subprogram call \"%s\"...done"
11972 (car vhdl-subprog-list))
11973 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11974
11975
11976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11977 ;;; Miscellaneous
11978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11979
11980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11981 ;; Hippie expand customization
11982
11983 (defvar vhdl-expand-upper-case nil)
11984
11985 (defun vhdl-try-expand-abbrev (old)
11986 "Try expanding abbreviations from `vhdl-abbrev-list'."
11987 (unless old
11988 (he-init-string (he-dabbrev-beg) (point))
11989 (setq he-expand-list
11990 (let ((abbrev-list vhdl-abbrev-list)
11991 (sel-abbrev-list '()))
11992 (while abbrev-list
11993 (when (or (not (stringp (car abbrev-list)))
11994 (string-match
11995 (concat "^" he-search-string) (car abbrev-list)))
11996 (setq sel-abbrev-list
11997 (cons (car abbrev-list) sel-abbrev-list)))
11998 (setq abbrev-list (cdr abbrev-list)))
11999 (nreverse sel-abbrev-list))))
12000 (while (and he-expand-list
12001 (or (not (stringp (car he-expand-list)))
12002 (he-string-member (car he-expand-list) he-tried-table t)))
12003 ; (equal (car he-expand-list) he-search-string)))
12004 (unless (stringp (car he-expand-list))
12005 (setq vhdl-expand-upper-case (car he-expand-list)))
12006 (setq he-expand-list (cdr he-expand-list)))
12007 (if (null he-expand-list)
12008 (progn (when old (he-reset-string))
12009 nil)
12010 (he-substitute-string
12011 (if vhdl-expand-upper-case
12012 (upcase (car he-expand-list))
12013 (car he-expand-list))
12014 t)
12015 (setq he-expand-list (cdr he-expand-list))
12016 t))
12017
12018 (defun vhdl-he-list-beg ()
12019 "Also looks at the word before `(' in order to better match parenthesized
12020 expressions (e.g. for index ranges of types and signals)."
12021 (save-excursion
12022 (condition-case ()
12023 (progn (backward-up-list 1)
12024 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12025 (error ()))
12026 (point)))
12027
12028 ;; override `he-list-beg' from `hippie-exp'
12029 (unless (and (boundp 'viper-mode) viper-mode)
12030 (defalias 'he-list-beg 'vhdl-he-list-beg))
12031
12032 ;; function for expanding abbrevs and dabbrevs
12033 (defun vhdl-expand-abbrev (arg))
12034 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12035 '(try-expand-dabbrev
12036 try-expand-dabbrev-all-buffers
12037 vhdl-try-expand-abbrev)))
12038
12039 ;; function for expanding parenthesis
12040 (defun vhdl-expand-paren (arg))
12041 (fset 'vhdl-expand-paren (make-hippie-expand-function
12042 '(try-expand-list
12043 try-expand-list-all-buffers)))
12044
12045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12046 ;; Case fixing
12047
12048 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12049 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12050 depending on parameter UPPER-CASE."
12051 (let ((case-replace nil)
12052 (last-update 0))
12053 (vhdl-prepare-search-2
12054 (save-excursion
12055 (goto-char end)
12056 (setq end (point-marker))
12057 (goto-char beg)
12058 (while (re-search-forward word-regexp end t)
12059 (or (vhdl-in-literal)
12060 (if upper-case
12061 (upcase-word -1)
12062 (downcase-word -1)))
12063 (when (and count vhdl-progress-interval (not noninteractive)
12064 (< vhdl-progress-interval
12065 (- (nth 1 (current-time)) last-update)))
12066 (message "Fixing case... (%2d%s)"
12067 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12068 "%")
12069 (setq last-update (nth 1 (current-time)))))
12070 (goto-char end)))))
12071
12072 (defun vhdl-fix-case-region (beg end &optional arg)
12073 "Convert all VHDL words in region to lower or upper case, depending on
12074 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12075 (interactive "r\nP")
12076 (vhdl-fix-case-region-1
12077 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12078 (vhdl-fix-case-region-1
12079 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12080 (vhdl-fix-case-region-1
12081 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12082 (vhdl-fix-case-region-1
12083 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12084 (when vhdl-progress-interval (message "Fixing case...done")))
12085
12086 (defun vhdl-fix-case-buffer ()
12087 "Convert all VHDL words in buffer to lower or upper case, depending on
12088 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12089 (interactive)
12090 (vhdl-fix-case-region (point-min) (point-max)))
12091
12092 (defun vhdl-fix-case-word (&optional arg)
12093 "Convert word after cursor to upper case if necessary."
12094 (interactive "p")
12095 (save-excursion
12096 (when arg (backward-word 1))
12097 (vhdl-prepare-search-1
12098 (when (and vhdl-upper-case-keywords
12099 (looking-at vhdl-keywords-regexp))
12100 (upcase-word 1))
12101 (when (and vhdl-upper-case-types
12102 (looking-at vhdl-types-regexp))
12103 (upcase-word 1))
12104 (when (and vhdl-upper-case-attributes
12105 (looking-at vhdl-attributes-regexp))
12106 (upcase-word 1))
12107 (when (and vhdl-upper-case-enum-values
12108 (looking-at vhdl-enum-values-regexp))
12109 (upcase-word 1)))))
12110
12111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12112 ;; Line handling functions
12113
12114 (defun vhdl-current-line ()
12115 "Return the line number of the line containing point."
12116 (save-restriction
12117 (widen)
12118 (save-excursion
12119 (beginning-of-line)
12120 (1+ (count-lines (point-min) (point))))))
12121
12122 (defun vhdl-line-kill-entire (&optional arg)
12123 "Delete entire line."
12124 (interactive "p")
12125 (beginning-of-line)
12126 (kill-line (or arg 1)))
12127
12128 (defun vhdl-line-kill (&optional arg)
12129 "Kill current line."
12130 (interactive "p")
12131 (vhdl-line-kill-entire arg))
12132
12133 (defun vhdl-line-copy (&optional arg)
12134 "Copy current line."
12135 (interactive "p")
12136 (save-excursion
12137 (beginning-of-line)
12138 (let ((position (point)))
12139 (forward-line (or arg 1))
12140 (copy-region-as-kill position (point)))))
12141
12142 (defun vhdl-line-yank ()
12143 "Yank entire line."
12144 (interactive)
12145 (beginning-of-line)
12146 (yank))
12147
12148 (defun vhdl-line-expand (&optional prefix-arg)
12149 "Hippie-expand current line."
12150 (interactive "P")
12151 (let ((case-fold-search t) (case-replace nil)
12152 (hippie-expand-try-functions-list
12153 '(try-expand-line try-expand-line-all-buffers)))
12154 (hippie-expand prefix-arg)))
12155
12156 (defun vhdl-line-transpose-next (&optional arg)
12157 "Interchange this line with next line."
12158 (interactive "p")
12159 (forward-line 1)
12160 (transpose-lines (or arg 1))
12161 (forward-line -1))
12162
12163 (defun vhdl-line-transpose-previous (&optional arg)
12164 "Interchange this line with previous line."
12165 (interactive "p")
12166 (forward-line 1)
12167 (transpose-lines (- 0 (or arg 0)))
12168 (forward-line -1))
12169
12170 (defun vhdl-line-open ()
12171 "Open a new line and indent."
12172 (interactive)
12173 (end-of-line -0)
12174 (newline-and-indent))
12175
12176 (defun vhdl-delete-indentation ()
12177 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12178 it works within comments too."
12179 (interactive)
12180 (let ((fill-prefix "-- "))
12181 (delete-indentation)))
12182
12183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12184 ;; Move functions
12185
12186 (defun vhdl-forward-same-indent ()
12187 "Move forward to next line with same indent."
12188 (interactive)
12189 (let ((pos (point))
12190 (indent (current-indentation)))
12191 (beginning-of-line 2)
12192 (while (and (not (eobp))
12193 (or (looking-at "^\\s-*\\(--.*\\)?$")
12194 (> (current-indentation) indent)))
12195 (beginning-of-line 2))
12196 (if (= (current-indentation) indent)
12197 (back-to-indentation)
12198 (message "No following line with same indent found in this block")
12199 (goto-char pos)
12200 nil)))
12201
12202 (defun vhdl-backward-same-indent ()
12203 "Move backward to previous line with same indent."
12204 (interactive)
12205 (let ((pos (point))
12206 (indent (current-indentation)))
12207 (beginning-of-line -0)
12208 (while (and (not (bobp))
12209 (or (looking-at "^\\s-*\\(--.*\\)?$")
12210 (> (current-indentation) indent)))
12211 (beginning-of-line -0))
12212 (if (= (current-indentation) indent)
12213 (back-to-indentation)
12214 (message "No preceding line with same indent found in this block")
12215 (goto-char pos)
12216 nil)))
12217
12218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12219 ;; Statistics
12220
12221 (defun vhdl-statistics-buffer ()
12222 "Get some file statistics."
12223 (interactive)
12224 (let ((no-stats 0)
12225 (no-code-lines 0)
12226 (no-lines (count-lines (point-min) (point-max))))
12227 (save-excursion
12228 ;; count statements
12229 (goto-char (point-min))
12230 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12231 (if (match-string 1)
12232 (goto-char (match-end 1))
12233 (setq no-stats (1+ no-stats))))
12234 ;; count code lines
12235 (goto-char (point-min))
12236 (while (not (eobp))
12237 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12238 (setq no-code-lines (1+ no-code-lines)))
12239 (beginning-of-line 2)))
12240 ;; print results
12241 (message "\n\
12242 File statistics: \"%s\"\n\
12243 ---------------------\n\
12244 # statements : %5d\n\
12245 # code lines : %5d\n\
12246 # total lines : %5d\n\ "
12247 (buffer-file-name) no-stats no-code-lines no-lines)
12248 (unless vhdl-emacs-21 (vhdl-show-messages))))
12249
12250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12251 ;; Help functions
12252
12253 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12254 "Like `re-search-forward', but does not match within literals."
12255 (let (pos)
12256 (save-excursion
12257 (while (and (setq pos (re-search-forward regexp bound noerror count))
12258 (vhdl-in-literal))))
12259 (when pos (goto-char pos))
12260 pos))
12261
12262 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12263 "Like `re-search-backward', but does not match within literals."
12264 (let (pos)
12265 (save-excursion
12266 (while (and (setq pos (re-search-backward regexp bound noerror count))
12267 (vhdl-in-literal))))
12268 (when pos (goto-char pos))
12269 pos))
12270
12271
12272 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12273 ;;; Project
12274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12275
12276 (defun vhdl-set-project (name)
12277 "Set current project to NAME."
12278 (interactive
12279 (list (let ((completion-ignore-case t))
12280 (completing-read "Project name: " vhdl-project-alist nil t))))
12281 (cond ((equal name "")
12282 (setq vhdl-project nil)
12283 (message "Current VHDL project: None"))
12284 ((assoc name vhdl-project-alist)
12285 (setq vhdl-project name)
12286 (message "Current VHDL project: \"%s\"" name))
12287 (t
12288 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12289 (vhdl-speedbar-update-current-project))
12290
12291 (defun vhdl-set-default-project ()
12292 "Set current project as default on startup."
12293 (interactive)
12294 (customize-set-variable 'vhdl-project vhdl-project)
12295 (customize-save-customized))
12296
12297 (defun vhdl-toggle-project (name token indent)
12298 "Set current project to NAME or unset if NAME is current project."
12299 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12300
12301 (defun vhdl-export-project (file-name)
12302 "Write project setup for current project."
12303 (interactive
12304 (let ((name (vhdl-resolve-env-variable
12305 (vhdl-replace-string
12306 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12307 (concat (subst-char-in-string
12308 ? ?_ (or (vhdl-project-p)
12309 (error "ERROR: No current project")))
12310 " " (user-login-name))))))
12311 (list (read-file-name
12312 "Write project file: "
12313 (when (file-name-absolute-p name) "") nil nil name))))
12314 (setq file-name (abbreviate-file-name file-name))
12315 (let ((orig-buffer (current-buffer)))
12316 (unless (file-exists-p (file-name-directory file-name))
12317 (make-directory (file-name-directory file-name) t))
12318 (if (not (file-writable-p file-name))
12319 (error "ERROR: File not writable: \"%s\"" file-name)
12320 (set-buffer (find-file-noselect file-name t t))
12321 (erase-buffer)
12322 (insert ";; -*- Emacs-Lisp -*-\n\n"
12323 ";;; " (file-name-nondirectory file-name)
12324 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12325 ";; Project : " vhdl-project "\n"
12326 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12327 (user-login-name) "\n\n\n"
12328 ";; project name\n"
12329 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12330 ";; project setup\n"
12331 "(aput 'vhdl-project-alist vhdl-project\n'")
12332 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12333 (insert ")\n")
12334 (save-buffer)
12335 (kill-buffer (current-buffer))
12336 (set-buffer orig-buffer))))
12337
12338 (defun vhdl-import-project (file-name &optional auto not-make-current)
12339 "Read project setup and set current project."
12340 (interactive
12341 (let ((name (vhdl-resolve-env-variable
12342 (vhdl-replace-string
12343 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12344 (concat "" " " (user-login-name))))))
12345 (list (read-file-name
12346 "Read project file: " (when (file-name-absolute-p name) "") nil t
12347 (file-name-directory name)))))
12348 (when (file-exists-p file-name)
12349 (condition-case ()
12350 (let ((current-project vhdl-project))
12351 (load-file file-name)
12352 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12353 (adelete 'vhdl-project-alist vhdl-project)
12354 (error ""))
12355 (when not-make-current
12356 (setq vhdl-project current-project))
12357 (vhdl-update-mode-menu)
12358 (vhdl-speedbar-refresh)
12359 (unless not-make-current
12360 (message "Current VHDL project: \"%s\"%s"
12361 vhdl-project (if auto " (auto-loaded)" ""))))
12362 (error (vhdl-warning
12363 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12364
12365 (defun vhdl-duplicate-project ()
12366 "Duplicate setup of current project."
12367 (interactive)
12368 (let ((new-name (read-from-minibuffer "New project name: "))
12369 (project-entry (aget vhdl-project-alist vhdl-project t)))
12370 (setq vhdl-project-alist
12371 (append vhdl-project-alist
12372 (list (cons new-name project-entry))))
12373 (vhdl-update-mode-menu)))
12374
12375 (defun vhdl-auto-load-project ()
12376 "Automatically load project setup at startup."
12377 (let ((file-name-list vhdl-project-file-name)
12378 file-list list-length)
12379 (while file-name-list
12380 (setq file-list
12381 (append file-list
12382 (file-expand-wildcards
12383 (vhdl-resolve-env-variable
12384 (vhdl-replace-string
12385 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12386 (concat "\*" " " (user-login-name)))))))
12387 (setq list-length (or list-length (length file-list)))
12388 (setq file-name-list (cdr file-name-list)))
12389 (while file-list
12390 (vhdl-import-project (expand-file-name (car file-list)) t
12391 (not (> list-length 0)))
12392 (setq list-length (1- list-length))
12393 (setq file-list (cdr file-list)))))
12394
12395 ;; automatically load project setup when idle after startup
12396 (when (memq 'startup vhdl-project-auto-load)
12397 (if noninteractive
12398 (vhdl-auto-load-project)
12399 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12400
12401
12402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12403 ;;; Hideshow
12404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12405 ;; (using `hideshow.el')
12406
12407 (defconst vhdl-hs-start-regexp
12408 (concat
12409 "\\(^\\)\\s-*\\("
12410 ;; generic/port clause
12411 "\\(generic\\|port\\)[ \t\n]*(\\|"
12412 ;; component
12413 "component\\>\\|"
12414 ;; component instantiation
12415 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12416 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12417 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12418 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12419 ;; subprogram
12420 "\\(function\\|procedure\\)\\>\\|"
12421 ;; process, block
12422 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12423 ;; configuration declaration
12424 "configuration\\>"
12425 "\\)")
12426 "Regexp to match start of construct to hide.")
12427
12428 (defun vhdl-hs-forward-sexp-func (count)
12429 "Find end of construct to hide (for hideshow). Only searches forward."
12430 (let ((pos (point)))
12431 (vhdl-prepare-search-2
12432 (beginning-of-line)
12433 (cond
12434 ;; generic/port clause
12435 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12436 (goto-char (match-end 0))
12437 (backward-char)
12438 (forward-sexp))
12439 ;; component declaration
12440 ((looking-at "^\\s-*component\\>")
12441 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12442 ;; component instantiation
12443 ((looking-at
12444 (concat
12445 "^\\s-*\\w+\\s-*:[ \t\n]*"
12446 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12447 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12448 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12449 (goto-char (match-end 0))
12450 (backward-char)
12451 (forward-sexp)
12452 (setq pos (point))
12453 (vhdl-forward-syntactic-ws)
12454 (when (looking-at "port\\s-+map[ \t\n]*(")
12455 (goto-char (match-end 0))
12456 (backward-char)
12457 (forward-sexp)
12458 (setq pos (point)))
12459 (goto-char pos))
12460 ;; subprogram declaration/body
12461 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12462 (goto-char (match-end 0))
12463 (vhdl-forward-syntactic-ws)
12464 (when (looking-at "(")
12465 (forward-sexp))
12466 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12467 (vhdl-in-literal)))
12468 ;; subprogram body
12469 (when (match-string 2)
12470 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12471 (backward-word 1)
12472 (vhdl-forward-sexp)))
12473 ;; block (recursive)
12474 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12475 (goto-char (match-end 0))
12476 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12477 (match-beginning 2))
12478 (vhdl-hs-forward-sexp-func count)))
12479 ;; process
12480 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12481 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12482 ;; configuration declaration
12483 ((looking-at "^\\s-*configuration\\>")
12484 (forward-word 4)
12485 (vhdl-forward-sexp))
12486 (t (goto-char pos))))))
12487
12488 (defun vhdl-hideshow-init ()
12489 "Initialize `hideshow'."
12490 (when vhdl-hideshow-menu
12491 (vhdl-hs-minor-mode 1)))
12492
12493 (defun vhdl-hs-minor-mode (&optional arg)
12494 "Toggle hideshow minor mode and update menu bar."
12495 (interactive "P")
12496 (require 'hideshow)
12497 ;; check for hideshow version 5.x
12498 (if (not (boundp 'hs-block-start-mdata-select))
12499 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12500 ;; initialize hideshow
12501 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12502 (setq hs-special-modes-alist
12503 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12504 'vhdl-hs-forward-sexp-func nil)
12505 hs-special-modes-alist)))
12506 (make-local-variable 'hs-minor-mode-hook)
12507 (if vhdl-hide-all-init
12508 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12509 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12510 (hs-minor-mode arg)
12511 (force-mode-line-update))) ; hack to update menu bar
12512
12513
12514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12515 ;;; Font locking
12516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12517 ;; (using `font-lock.el')
12518
12519 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12520 ;; Help functions
12521
12522 (defun vhdl-within-translate-off ()
12523 "Return point if within translate-off region, else nil."
12524 (and (save-excursion
12525 (re-search-backward
12526 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12527 (equal "off" (match-string 1))
12528 (point)))
12529
12530 (defun vhdl-start-translate-off (limit)
12531 "Return point before translate-off pragma if before LIMIT, else nil."
12532 (when (re-search-forward
12533 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12534 (match-beginning 0)))
12535
12536 (defun vhdl-end-translate-off (limit)
12537 "Return point after translate-on pragma if before LIMIT, else nil."
12538 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12539
12540 (defun vhdl-match-translate-off (limit)
12541 "Match a translate-off block, setting match-data and returning t, else nil."
12542 (when (< (point) limit)
12543 (let ((start (or (vhdl-within-translate-off)
12544 (vhdl-start-translate-off limit)))
12545 (case-fold-search t))
12546 (when start
12547 (let ((end (or (vhdl-end-translate-off limit) limit)))
12548 (set-match-data (list start end))
12549 (goto-char end))))))
12550
12551 (defun vhdl-font-lock-match-item (limit)
12552 "Match, and move over, any declaration item after point. Adapted from
12553 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12554 (condition-case nil
12555 (save-restriction
12556 (narrow-to-region (point-min) limit)
12557 ;; match item
12558 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12559 (save-match-data
12560 (goto-char (match-end 1))
12561 ;; move to next item
12562 (if (looking-at "\\(\\s-*,\\)")
12563 (goto-char (match-end 1))
12564 (end-of-line) t))))
12565 (error t)))
12566
12567 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12568 ;; Syntax definitions
12569
12570 (defconst vhdl-font-lock-syntactic-keywords
12571 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12572 "Mark single quotes as having string quote syntax in 'c' instances.")
12573
12574 (defvar vhdl-font-lock-keywords nil
12575 "Regular expressions to highlight in VHDL Mode.")
12576
12577 (defvar vhdl-font-lock-keywords-0
12578 ;; set in `vhdl-font-lock-init' because dependent on user options
12579 "For consideration as a value of `vhdl-font-lock-keywords'.
12580 This does highlighting of template prompts and directives (pragmas).")
12581
12582 (defvar vhdl-font-lock-keywords-1 nil
12583 ;; set in `vhdl-font-lock-init' because dependent on user options
12584 "For consideration as a value of `vhdl-font-lock-keywords'.
12585 This does highlighting of keywords and standard identifiers.")
12586
12587 (defconst vhdl-font-lock-keywords-2
12588 (list
12589 ;; highlight names of units, subprograms, and components when declared
12590 (list
12591 (concat
12592 "^\\s-*\\("
12593 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12594 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12595 "\\)\\s-+\\(\\w+\\)")
12596 5 'font-lock-function-name-face)
12597
12598 ;; highlight entity names of architectures and configurations
12599 (list
12600 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12601 2 'font-lock-function-name-face)
12602
12603 ;; highlight labels of common constructs
12604 (list
12605 (concat
12606 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12607 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12608 "postponed\\|process\\|"
12609 (when (vhdl-standard-p 'ams) "procedural\\|")
12610 "with\\|while"
12611 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12612 1 'font-lock-function-name-face)
12613
12614 ;; highlight label and component name of component instantiations
12615 (list
12616 (concat
12617 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12618 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12619 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12620
12621 ;; highlight label and instantiated unit of component instantiations
12622 (list
12623 (concat
12624 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12625 "\\(component\\|configuration\\|entity\\)\\s-+"
12626 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12627 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12628 '(5 font-lock-function-name-face nil t)
12629 '(7 font-lock-function-name-face nil t))
12630
12631 ;; highlight names and labels at end of constructs
12632 (list
12633 (concat
12634 "^\\s-*end\\s-+\\(\\("
12635 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12636 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12637 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12638 (when (vhdl-standard-p 'ams) "procedural\\|")
12639 "units"
12640 "\\)\\s-+\\)?\\(\\w*\\)")
12641 5 'font-lock-function-name-face)
12642
12643 ;; highlight labels in exit and next statements
12644 (list
12645 (concat
12646 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12647 3 'font-lock-function-name-face)
12648
12649 ;; highlight entity name in attribute specifications
12650 (list
12651 (concat
12652 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12653 1 'font-lock-function-name-face)
12654
12655 ;; highlight labels in block and component specifications
12656 (list
12657 (concat
12658 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12659 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12660 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12661
12662 ;; highlight names in library clauses
12663 (list "^\\s-*library\\>"
12664 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12665
12666 ;; highlight names in use clauses
12667 (list
12668 (concat
12669 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12670 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12671 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12672 '(7 font-lock-function-name-face nil t))
12673
12674 ;; highlight attribute name in attribute declarations/specifications
12675 (list
12676 (concat
12677 "^\\s-*attribute\\s-+\\(\\w+\\)")
12678 1 'vhdl-font-lock-attribute-face)
12679
12680 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12681 (list
12682 (concat
12683 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12684 3 'font-lock-type-face)
12685
12686 ;; highlight signal/variable/constant declaration names
12687 (list "\\(:[^=]\\)"
12688 '(vhdl-font-lock-match-item
12689 (progn (goto-char (match-beginning 1))
12690 (skip-syntax-backward " ")
12691 (skip-syntax-backward "w_")
12692 (skip-syntax-backward " ")
12693 (while (= (preceding-char) ?,)
12694 (backward-char 1)
12695 (skip-syntax-backward " ")
12696 (skip-syntax-backward "w_")
12697 (skip-syntax-backward " ")))
12698 ; (skip-chars-backward "^-(\n\";")
12699 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12700
12701 ;; highlight formal parameters in component instantiations and subprogram
12702 ;; calls
12703 (list "\\(=>\\)"
12704 '(vhdl-font-lock-match-item
12705 (progn (goto-char (match-beginning 1))
12706 (skip-syntax-backward " ")
12707 (while (= (preceding-char) ?\)) (backward-sexp))
12708 (skip-syntax-backward "w_")
12709 (skip-syntax-backward " ")
12710 (when (memq (preceding-char) '(?n ?N ?|))
12711 (goto-char (point-max))))
12712 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12713
12714 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12715 ;; variables
12716 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12717 '(vhdl-font-lock-match-item
12718 (progn (goto-char (match-end 1)) (match-beginning 2))
12719 nil (1 font-lock-variable-name-face)))
12720 )
12721 "For consideration as a value of `vhdl-font-lock-keywords'.
12722 This does context sensitive highlighting of names and labels.")
12723
12724 (defvar vhdl-font-lock-keywords-3 nil
12725 ;; set in `vhdl-font-lock-init' because dependent on user options
12726 "For consideration as a value of `vhdl-font-lock-keywords'.
12727 This does highlighting of words with special syntax.")
12728
12729 (defvar vhdl-font-lock-keywords-4 nil
12730 ;; set in `vhdl-font-lock-init' because dependent on user options
12731 "For consideration as a value of `vhdl-font-lock-keywords'.
12732 This does highlighting of additional reserved words.")
12733
12734 (defconst vhdl-font-lock-keywords-5
12735 ;; background highlight translate-off regions
12736 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12737 "For consideration as a value of `vhdl-font-lock-keywords'.
12738 This does background highlighting of translate-off regions.")
12739
12740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12741 ;; Font and color definitions
12742
12743 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12744 "Face name to use for prompts.")
12745
12746 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12747 "Face name to use for standardized attributes.")
12748
12749 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12750 "Face name to use for standardized enumeration values.")
12751
12752 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12753 "Face name to use for standardized functions and packages.")
12754
12755 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12756 "Face name to use for directives.")
12757
12758 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12759 "Face name to use for additional reserved words.")
12760
12761 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12762 "Face name to use for translate-off regions.")
12763
12764 ;; face names to use for words with special syntax.
12765 (let ((syntax-alist vhdl-special-syntax-alist)
12766 name)
12767 (while syntax-alist
12768 (setq name (vhdl-function-name
12769 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12770 (eval `(defvar ,name ',name
12771 ,(concat "Face name to use for "
12772 (nth 0 (car syntax-alist)) ".")))
12773 (setq syntax-alist (cdr syntax-alist))))
12774
12775 (defgroup vhdl-highlight-faces nil
12776 "Faces for highlighting."
12777 :group 'vhdl-highlight)
12778
12779 ;; add faces used from `font-lock'
12780 (custom-add-to-group
12781 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12782 (custom-add-to-group
12783 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12784 (custom-add-to-group
12785 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12786 (custom-add-to-group
12787 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12788 (custom-add-to-group
12789 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12790 (custom-add-to-group
12791 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12792
12793 (defface vhdl-font-lock-prompt-face
12794 '((((min-colors 88) (class color) (background light))
12795 (:foreground "Red1" :bold t))
12796 (((class color) (background light)) (:foreground "Red" :bold t))
12797 (((class color) (background dark)) (:foreground "Pink" :bold t))
12798 (t (:inverse-video t)))
12799 "Font lock mode face used to highlight prompts."
12800 :group 'vhdl-highlight-faces)
12801
12802 (defface vhdl-font-lock-attribute-face
12803 '((((class color) (background light)) (:foreground "Orchid"))
12804 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12805 (t (:italic t :bold t)))
12806 "Font lock mode face used to highlight standardized attributes."
12807 :group 'vhdl-highlight-faces)
12808
12809 (defface vhdl-font-lock-enumvalue-face
12810 '((((class color) (background light)) (:foreground "SaddleBrown"))
12811 (((class color) (background dark)) (:foreground "BurlyWood"))
12812 (t (:italic t :bold t)))
12813 "Font lock mode face used to highlight standardized enumeration values."
12814 :group 'vhdl-highlight-faces)
12815
12816 (defface vhdl-font-lock-function-face
12817 '((((class color) (background light)) (:foreground "Cyan4"))
12818 (((class color) (background dark)) (:foreground "Orchid1"))
12819 (t (:italic t :bold t)))
12820 "Font lock mode face used to highlight standardized functions and packages."
12821 :group 'vhdl-highlight-faces)
12822
12823 (defface vhdl-font-lock-directive-face
12824 '((((class color) (background light)) (:foreground "CadetBlue"))
12825 (((class color) (background dark)) (:foreground "Aquamarine"))
12826 (t (:italic t :bold t)))
12827 "Font lock mode face used to highlight directives."
12828 :group 'vhdl-highlight-faces)
12829
12830 (defface vhdl-font-lock-reserved-words-face
12831 '((((class color) (background light)) (:foreground "Orange" :bold t))
12832 (((min-colors 88) (class color) (background dark))
12833 (:foreground "Yellow1" :bold t))
12834 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12835 (t ()))
12836 "Font lock mode face used to highlight additional reserved words."
12837 :group 'vhdl-highlight-faces)
12838
12839 (defface vhdl-font-lock-translate-off-face
12840 '((((class color) (background light)) (:background "LightGray"))
12841 (((class color) (background dark)) (:background "DimGray"))
12842 (t ()))
12843 "Font lock mode face used to background highlight translate-off regions."
12844 :group 'vhdl-highlight-faces)
12845
12846 ;; font lock mode faces used to highlight words with special syntax.
12847 (let ((syntax-alist vhdl-special-syntax-alist))
12848 (while syntax-alist
12849 (eval `(defface ,(vhdl-function-name
12850 "vhdl-font-lock" (caar syntax-alist) "face")
12851 '((((class color) (background light))
12852 (:foreground ,(nth 2 (car syntax-alist))))
12853 (((class color) (background dark))
12854 (:foreground ,(nth 3 (car syntax-alist))))
12855 (t ()))
12856 ,(concat "Font lock mode face used to highlight "
12857 (nth 0 (car syntax-alist)) ".")
12858 :group 'vhdl-highlight-faces))
12859 (setq syntax-alist (cdr syntax-alist))))
12860
12861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12862 ;; Font lock initialization
12863
12864 (defun vhdl-font-lock-init ()
12865 "Initialize fontification."
12866 ;; highlight template prompts and directives
12867 (setq vhdl-font-lock-keywords-0
12868 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12869 vhdl-template-prompt-syntax ">\\)")
12870 2 'vhdl-font-lock-prompt-face t)
12871 (list (concat "--\\s-*"
12872 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12873 2 'vhdl-font-lock-directive-face t)
12874 ;; highlight c-preprocessor directives
12875 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12876 '(1 font-lock-builtin-face)
12877 '(3 font-lock-variable-name-face nil t))))
12878 ;; highlight keywords and standardized types, attributes, enumeration
12879 ;; values, and subprograms
12880 (setq vhdl-font-lock-keywords-1
12881 (list
12882 (list (concat "'" vhdl-attributes-regexp)
12883 1 'vhdl-font-lock-attribute-face)
12884 (list vhdl-types-regexp 1 'font-lock-type-face)
12885 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12886 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12887 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12888 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12889 ;; highlight words with special syntax.
12890 (setq vhdl-font-lock-keywords-3
12891 (let ((syntax-alist vhdl-special-syntax-alist)
12892 keywords)
12893 (while syntax-alist
12894 (setq keywords
12895 (cons
12896 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12897 (vhdl-function-name
12898 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12899 keywords))
12900 (setq syntax-alist (cdr syntax-alist)))
12901 keywords))
12902 ;; highlight additional reserved words
12903 (setq vhdl-font-lock-keywords-4
12904 (list (list vhdl-reserved-words-regexp 1
12905 'vhdl-font-lock-reserved-words-face)))
12906 ;; highlight everything together
12907 (setq vhdl-font-lock-keywords
12908 (append
12909 vhdl-font-lock-keywords-0
12910 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12911 (when (or vhdl-highlight-forbidden-words
12912 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12913 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12914 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12915 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12916
12917 ;; initialize fontification for VHDL Mode
12918 (vhdl-font-lock-init)
12919
12920 (defun vhdl-fontify-buffer ()
12921 "Re-initialize fontification and fontify buffer."
12922 (interactive)
12923 (setq font-lock-defaults
12924 `(vhdl-font-lock-keywords
12925 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12926 beginning-of-line))
12927 (when (fboundp 'font-lock-unset-defaults)
12928 (font-lock-unset-defaults)) ; not implemented in XEmacs
12929 (font-lock-set-defaults)
12930 (font-lock-mode nil)
12931 (font-lock-mode t))
12932
12933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12934 ;; Initialization for postscript printing
12935
12936 (defun vhdl-ps-print-settings ()
12937 "Initialize custom face and page settings for postscript printing."
12938 ;; define custom face settings
12939 (unless (or (not vhdl-print-customize-faces)
12940 ps-print-color-p)
12941 (set (make-local-variable 'ps-bold-faces)
12942 '(font-lock-keyword-face
12943 font-lock-type-face
12944 vhdl-font-lock-attribute-face
12945 vhdl-font-lock-enumvalue-face
12946 vhdl-font-lock-directive-face))
12947 (set (make-local-variable 'ps-italic-faces)
12948 '(font-lock-comment-face
12949 font-lock-function-name-face
12950 font-lock-type-face
12951 vhdl-font-lock-attribute-face
12952 vhdl-font-lock-enumvalue-face
12953 vhdl-font-lock-directive-face))
12954 (set (make-local-variable 'ps-underlined-faces)
12955 '(font-lock-string-face))
12956 (setq ps-always-build-face-reference t))
12957 ;; define page settings, so that a line containing 79 characters (default)
12958 ;; fits into one column
12959 (when vhdl-print-two-column
12960 (set (make-local-variable 'ps-landscape-mode) t)
12961 (set (make-local-variable 'ps-number-of-columns) 2)
12962 (set (make-local-variable 'ps-font-size) 7.0)
12963 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12964 (set (make-local-variable 'ps-header-font-size) 9.0)
12965 (set (make-local-variable 'ps-header-offset) 12.0)
12966 (when (eq ps-paper-type 'letter)
12967 (set (make-local-variable 'ps-inter-column) 40.0)
12968 (set (make-local-variable 'ps-left-margin) 40.0)
12969 (set (make-local-variable 'ps-right-margin) 40.0))))
12970
12971 (defun vhdl-ps-print-init ()
12972 "Initialize postscript printing."
12973 (if (featurep 'xemacs)
12974 (when (boundp 'ps-print-color-p)
12975 (vhdl-ps-print-settings))
12976 (make-local-variable 'ps-print-hook)
12977 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12978
12979
12980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12981 ;;; Hierarchy browser (using `speedbar.el')
12982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12983 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12984 ;; directory by using the speedbar.
12985
12986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12987 ;; Variables
12988
12989 (defvar vhdl-entity-alist nil
12990 "Cache with entities and corresponding architectures for each
12991 project/directory.")
12992 ;; structure: (parenthesised expression means list of such entries)
12993 ;; (cache-key
12994 ;; (ent-key ent-name ent-file ent-line
12995 ;; (arch-key arch-name arch-file arch-line
12996 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12997 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12998 ;; (lib-name pack-key))
12999 ;; mra-key (lib-name pack-key))
13000
13001 (defvar vhdl-config-alist nil
13002 "Cache with configurations for each project/directory.")
13003 ;; structure: (parenthesised expression means list of such entries)
13004 ;; (cache-key
13005 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13006 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13007 ;; inst-conf-key inst-lib-key)
13008 ;; (lib-name pack-key)))
13009
13010 (defvar vhdl-package-alist nil
13011 "Cache with packages for each project/directory.")
13012 ;; structure: (parenthesised expression means list of such entries)
13013 ;; (cache-key
13014 ;; (pack-key pack-name pack-file pack-line
13015 ;; (comp-key comp-name comp-file comp-line)
13016 ;; (func-key func-name func-file func-line)
13017 ;; (lib-name pack-key)
13018 ;; pack-body-file pack-body-line
13019 ;; (func-key func-name func-body-file func-body-line)
13020 ;; (lib-name pack-key)))
13021
13022 (defvar vhdl-ent-inst-alist nil
13023 "Cache with instantiated entities for each project/directory.")
13024 ;; structure: (parenthesised expression means list of such entries)
13025 ;; (cache-key (inst-ent-key))
13026
13027 (defvar vhdl-file-alist nil
13028 "Cache with design units in each file for each project/directory.")
13029 ;; structure: (parenthesised expression means list of such entries)
13030 ;; (cache-key
13031 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13032 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13033
13034 (defvar vhdl-directory-alist nil
13035 "Cache with source directories for each project.")
13036 ;; structure: (parenthesised expression means list of such entries)
13037 ;; (cache-key (directory))
13038
13039 (defvar vhdl-speedbar-shown-unit-alist nil
13040 "Alist of design units simultaneously open in the current speedbar for each
13041 directory and project.")
13042
13043 (defvar vhdl-speedbar-shown-project-list nil
13044 "List of projects simultaneously open in the current speedbar.")
13045
13046 (defvar vhdl-updated-project-list nil
13047 "List of projects and directories with updated files.")
13048
13049 (defvar vhdl-modified-file-list nil
13050 "List of modified files to be rescanned for hierarchy updating.")
13051
13052 (defvar vhdl-speedbar-hierarchy-depth 0
13053 "Depth of instantiation hierarchy to display.")
13054
13055 (defvar vhdl-speedbar-show-projects nil
13056 "Non-nil means project hierarchy is displayed in speedbar, directory
13057 hierarchy otherwise.")
13058
13059 (defun vhdl-get-end-of-unit ()
13060 "Return position of end of current unit."
13061 (let ((pos (point)))
13062 (save-excursion
13063 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13064 (save-excursion
13065 (goto-char (match-beginning 0))
13066 (vhdl-backward-syntactic-ws)
13067 (and (/= (preceding-char) ?\;) (not (bobp))))))
13068 (re-search-backward "^[ \t]*end\\>" pos 1)
13069 (point))))
13070
13071 (defun vhdl-match-string-downcase (num &optional string)
13072 "Like `match-string-no-properties' with down-casing."
13073 (let ((match (match-string-no-properties num string)))
13074 (and match (downcase match))))
13075
13076
13077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13078 ;; Scan functions
13079
13080 (defun vhdl-scan-context-clause ()
13081 "Scan the context clause that preceeds a design unit."
13082 (let (lib-alist)
13083 (save-excursion
13084 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13085 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13086 (equal "USE" (upcase (match-string 1))))
13087 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13088 (setq lib-alist (cons (cons (match-string-no-properties 1)
13089 (vhdl-match-string-downcase 2))
13090 lib-alist))))))
13091 lib-alist))
13092
13093 (defun vhdl-scan-directory-contents (name &optional project update num-string
13094 non-final)
13095 "Scan contents of VHDL files in directory or file pattern NAME."
13096 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13097 ; (unless (file-directory-p (match-string 1 name))
13098 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13099 (let* ((dir-name (match-string 1 name))
13100 (file-pattern (match-string 2 name))
13101 (is-directory (= 0 (length file-pattern)))
13102 (file-list
13103 (if update
13104 (list name)
13105 (if is-directory
13106 (vhdl-get-source-files t dir-name)
13107 (vhdl-directory-files
13108 dir-name t (wildcard-to-regexp file-pattern)))))
13109 (key (or project dir-name))
13110 (file-exclude-regexp
13111 (or (nth 3 (aget vhdl-project-alist project)) ""))
13112 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13113 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13114 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13115 ent-alist conf-alist pack-alist ent-inst-list file-alist
13116 tmp-list tmp-entry no-files files-exist big-files)
13117 (when (or project update)
13118 (setq ent-alist (aget vhdl-entity-alist key t)
13119 conf-alist (aget vhdl-config-alist key t)
13120 pack-alist (aget vhdl-package-alist key t)
13121 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13122 file-alist (aget vhdl-file-alist key t)))
13123 (when (and (not is-directory) (null file-list))
13124 (message "No such file: \"%s\"" name))
13125 (setq files-exist file-list)
13126 (when file-list
13127 (setq no-files (length file-list))
13128 (message "Scanning %s %s\"%s\"..."
13129 (if is-directory "directory" "files") (or num-string "") name)
13130 ;; exclude files
13131 (unless (equal file-exclude-regexp "")
13132 (let ((case-fold-search nil)
13133 file-tmp-list)
13134 (while file-list
13135 (unless (string-match file-exclude-regexp (car file-list))
13136 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13137 (setq file-list (cdr file-list)))
13138 (setq file-list (nreverse file-tmp-list))))
13139 ;; do for all files
13140 (while file-list
13141 (unless noninteractive
13142 (message "Scanning %s %s\"%s\"... (%2d%s)"
13143 (if is-directory "directory" "files")
13144 (or num-string "") name
13145 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13146 (let ((file-name (abbreviate-file-name (car file-list)))
13147 ent-list arch-list arch-ent-list conf-list
13148 pack-list pack-body-list inst-list inst-ent-list)
13149 ;; scan file
13150 (vhdl-visit-file
13151 file-name nil
13152 (vhdl-prepare-search-2
13153 (save-excursion
13154 ;; scan for design units
13155 (if (and limit-design-file-size
13156 (< limit-design-file-size (buffer-size)))
13157 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13158 (setq big-files t))
13159 ;; scan for entities
13160 (goto-char (point-min))
13161 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13162 (let* ((ent-name (match-string-no-properties 1))
13163 (ent-key (downcase ent-name))
13164 (ent-entry (aget ent-alist ent-key t))
13165 (lib-alist (vhdl-scan-context-clause)))
13166 (if (nth 1 ent-entry)
13167 (vhdl-warning-when-idle
13168 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13169 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13170 file-name (vhdl-current-line))
13171 (setq ent-list (cons ent-key ent-list))
13172 (aput 'ent-alist ent-key
13173 (list ent-name file-name (vhdl-current-line)
13174 (nth 3 ent-entry) (nth 4 ent-entry)
13175 lib-alist)))))
13176 ;; scan for architectures
13177 (goto-char (point-min))
13178 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13179 (let* ((arch-name (match-string-no-properties 1))
13180 (arch-key (downcase arch-name))
13181 (ent-name (match-string-no-properties 2))
13182 (ent-key (downcase ent-name))
13183 (ent-entry (aget ent-alist ent-key t))
13184 (arch-alist (nth 3 ent-entry))
13185 (arch-entry (aget arch-alist arch-key t))
13186 (lib-arch-alist (vhdl-scan-context-clause)))
13187 (if arch-entry
13188 (vhdl-warning-when-idle
13189 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13190 arch-name ent-name (nth 1 arch-entry)
13191 (nth 2 arch-entry) file-name (vhdl-current-line))
13192 (setq arch-list (cons arch-key arch-list)
13193 arch-ent-list (cons ent-key arch-ent-list))
13194 (aput 'arch-alist arch-key
13195 (list arch-name file-name (vhdl-current-line) nil
13196 lib-arch-alist))
13197 (aput 'ent-alist ent-key
13198 (list (or (nth 0 ent-entry) ent-name)
13199 (nth 1 ent-entry) (nth 2 ent-entry)
13200 (vhdl-sort-alist arch-alist)
13201 arch-key (nth 5 ent-entry))))))
13202 ;; scan for configurations
13203 (goto-char (point-min))
13204 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13205 (let* ((conf-name (match-string-no-properties 1))
13206 (conf-key (downcase conf-name))
13207 (conf-entry (aget conf-alist conf-key t))
13208 (ent-name (match-string-no-properties 2))
13209 (ent-key (downcase ent-name))
13210 (lib-alist (vhdl-scan-context-clause))
13211 (conf-line (vhdl-current-line))
13212 (end-of-unit (vhdl-get-end-of-unit))
13213 arch-key comp-conf-list inst-key-list
13214 inst-comp-key inst-ent-key inst-arch-key
13215 inst-conf-key inst-lib-key)
13216 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13217 (setq arch-key (vhdl-match-string-downcase 1)))
13218 (if conf-entry
13219 (vhdl-warning-when-idle
13220 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13221 conf-name ent-name (nth 1 conf-entry)
13222 (nth 2 conf-entry) file-name conf-line)
13223 (setq conf-list (cons conf-key conf-list))
13224 ;; scan for subconfigurations and subentities
13225 (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)
13226 (setq inst-comp-key (vhdl-match-string-downcase 3)
13227 inst-key-list (split-string
13228 (vhdl-match-string-downcase 1)
13229 "[ \t\n]*,[ \t\n]*"))
13230 (vhdl-forward-syntactic-ws)
13231 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13232 (setq
13233 inst-lib-key (vhdl-match-string-downcase 3)
13234 inst-ent-key (and (match-string 2)
13235 (vhdl-match-string-downcase 4))
13236 inst-arch-key (and (match-string 2)
13237 (vhdl-match-string-downcase 6))
13238 inst-conf-key (and (not (match-string 2))
13239 (vhdl-match-string-downcase 4)))
13240 (while inst-key-list
13241 (setq comp-conf-list
13242 (cons (list (car inst-key-list)
13243 inst-comp-key inst-ent-key
13244 inst-arch-key inst-conf-key
13245 inst-lib-key)
13246 comp-conf-list))
13247 (setq inst-key-list (cdr inst-key-list)))))
13248 (aput 'conf-alist conf-key
13249 (list conf-name file-name conf-line ent-key
13250 arch-key comp-conf-list lib-alist)))))
13251 ;; scan for packages
13252 (goto-char (point-min))
13253 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13254 (let* ((pack-name (match-string-no-properties 2))
13255 (pack-key (downcase pack-name))
13256 (is-body (match-string-no-properties 1))
13257 (pack-entry (aget pack-alist pack-key t))
13258 (pack-line (vhdl-current-line))
13259 (end-of-unit (vhdl-get-end-of-unit))
13260 comp-name func-name comp-alist func-alist lib-alist)
13261 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13262 (vhdl-warning-when-idle
13263 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13264 (if is-body " body" "") pack-name
13265 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13266 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13267 file-name (vhdl-current-line))
13268 ;; scan for context clauses
13269 (setq lib-alist (vhdl-scan-context-clause))
13270 ;; scan for component and subprogram declarations/bodies
13271 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13272 (if (equal (upcase (match-string 1)) "COMPONENT")
13273 (setq comp-name (match-string-no-properties 2)
13274 comp-alist
13275 (cons (list (downcase comp-name) comp-name
13276 file-name (vhdl-current-line))
13277 comp-alist))
13278 (setq func-name (match-string-no-properties 2)
13279 func-alist
13280 (cons (list (downcase func-name) func-name
13281 file-name (vhdl-current-line))
13282 func-alist))))
13283 (setq func-alist (nreverse func-alist))
13284 (setq comp-alist (nreverse comp-alist))
13285 (if is-body
13286 (setq pack-body-list (cons pack-key pack-body-list))
13287 (setq pack-list (cons pack-key pack-list)))
13288 (aput
13289 'pack-alist pack-key
13290 (if is-body
13291 (list (or (nth 0 pack-entry) pack-name)
13292 (nth 1 pack-entry) (nth 2 pack-entry)
13293 (nth 3 pack-entry) (nth 4 pack-entry)
13294 (nth 5 pack-entry)
13295 file-name pack-line func-alist lib-alist)
13296 (list pack-name file-name pack-line
13297 comp-alist func-alist lib-alist
13298 (nth 6 pack-entry) (nth 7 pack-entry)
13299 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13300 ;; scan for hierarchy
13301 (if (and limit-hier-file-size
13302 (< limit-hier-file-size (buffer-size)))
13303 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13304 (setq big-files t))
13305 ;; scan for architectures
13306 (goto-char (point-min))
13307 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13308 (let* ((ent-name (match-string-no-properties 2))
13309 (ent-key (downcase ent-name))
13310 (arch-name (match-string-no-properties 1))
13311 (arch-key (downcase arch-name))
13312 (ent-entry (aget ent-alist ent-key t))
13313 (arch-alist (nth 3 ent-entry))
13314 (arch-entry (aget arch-alist arch-key t))
13315 (beg-of-unit (point))
13316 (end-of-unit (vhdl-get-end-of-unit))
13317 (inst-no 0)
13318 inst-alist inst-path)
13319 ;; scan for contained instantiations
13320 (while (and (re-search-forward
13321 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13322 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13323 "component[ \t\n]+\\(\\w+\\)\\|"
13324 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13325 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13326 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13327 (or (not limit-hier-inst-no)
13328 (<= (setq inst-no (1+ inst-no))
13329 limit-hier-inst-no)))
13330 (cond
13331 ;; block/generate beginning found
13332 ((match-string 14)
13333 (setq inst-path
13334 (cons (match-string-no-properties 1) inst-path)))
13335 ;; block/generate end found
13336 ((match-string 16)
13337 (setq inst-path (cdr inst-path)))
13338 ;; instantiation found
13339 (t
13340 (let* ((inst-name (match-string-no-properties 1))
13341 (inst-key (downcase inst-name))
13342 (inst-comp-name
13343 (or (match-string-no-properties 3)
13344 (match-string-no-properties 6)))
13345 (inst-ent-key
13346 (or (and (match-string 8)
13347 (vhdl-match-string-downcase 11))
13348 (and inst-comp-name
13349 (downcase inst-comp-name))))
13350 (inst-arch-key (vhdl-match-string-downcase 13))
13351 (inst-conf-key
13352 (and (not (match-string 8))
13353 (vhdl-match-string-downcase 11)))
13354 (inst-lib-key (vhdl-match-string-downcase 10)))
13355 (goto-char (match-end 1))
13356 (setq inst-list (cons inst-key inst-list)
13357 inst-ent-list
13358 (cons inst-ent-key inst-ent-list))
13359 (setq inst-alist
13360 (append
13361 inst-alist
13362 (list (list inst-key inst-name file-name
13363 (vhdl-current-line) inst-comp-name
13364 inst-ent-key inst-arch-key
13365 inst-conf-key inst-lib-key
13366 (reverse inst-path)))))))))
13367 ;; scan for contained configuration specifications
13368 (goto-char beg-of-unit)
13369 (while (re-search-forward
13370 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13371 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13372 (let* ((inst-comp-name (match-string-no-properties 3))
13373 (inst-ent-key
13374 (and (match-string 6)
13375 (vhdl-match-string-downcase 9)))
13376 (inst-arch-key (vhdl-match-string-downcase 11))
13377 (inst-conf-key
13378 (and (not (match-string 6))
13379 (vhdl-match-string-downcase 9)))
13380 (inst-lib-key (vhdl-match-string-downcase 8))
13381 (inst-key-list
13382 (split-string (vhdl-match-string-downcase 1)
13383 "[ \t\n]*,[ \t\n]*"))
13384 (tmp-inst-alist inst-alist)
13385 inst-entry)
13386 (while tmp-inst-alist
13387 (when (and (or (equal "all" (car inst-key-list))
13388 (member (nth 0 (car tmp-inst-alist))
13389 inst-key-list))
13390 (equal
13391 (downcase
13392 (or (nth 4 (car tmp-inst-alist)) ""))
13393 (downcase inst-comp-name)))
13394 (setq inst-entry (car tmp-inst-alist))
13395 (setq inst-ent-list
13396 (cons (or inst-ent-key (nth 5 inst-entry))
13397 (vhdl-delete
13398 (nth 5 inst-entry) inst-ent-list)))
13399 (setq inst-entry
13400 (list (nth 0 inst-entry) (nth 1 inst-entry)
13401 (nth 2 inst-entry) (nth 3 inst-entry)
13402 (nth 4 inst-entry)
13403 (or inst-ent-key (nth 5 inst-entry))
13404 (or inst-arch-key (nth 6 inst-entry))
13405 inst-conf-key inst-lib-key))
13406 (setcar tmp-inst-alist inst-entry))
13407 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13408 ;; save in cache
13409 (aput 'arch-alist arch-key
13410 (list (nth 0 arch-entry) (nth 1 arch-entry)
13411 (nth 2 arch-entry) inst-alist
13412 (nth 4 arch-entry)))
13413 (aput 'ent-alist ent-key
13414 (list (nth 0 ent-entry) (nth 1 ent-entry)
13415 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13416 (nth 4 ent-entry) (nth 5 ent-entry)))
13417 (when (and limit-hier-inst-no
13418 (> inst-no limit-hier-inst-no))
13419 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13420 (setq big-files t))
13421 (goto-char end-of-unit))))
13422 ;; remember design units for this file
13423 (aput 'file-alist file-name
13424 (list ent-list arch-list arch-ent-list conf-list
13425 pack-list pack-body-list inst-list inst-ent-list))
13426 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13427 (setq file-list (cdr file-list))))
13428 (when (or (and (not project) files-exist)
13429 (and project (not non-final)))
13430 ;; consistency checks:
13431 ;; check whether each architecture has a corresponding entity
13432 (setq tmp-list ent-alist)
13433 (while tmp-list
13434 (when (null (nth 2 (car tmp-list)))
13435 (setq tmp-entry (car (nth 4 (car tmp-list))))
13436 (vhdl-warning-when-idle
13437 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13438 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13439 (nth 3 tmp-entry)))
13440 (setq tmp-list (cdr tmp-list)))
13441 ;; check whether configuration has a corresponding entity/architecture
13442 (setq tmp-list conf-alist)
13443 (while tmp-list
13444 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13445 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13446 (setq tmp-entry (car tmp-list))
13447 (vhdl-warning-when-idle
13448 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13449 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13450 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13451 (setq tmp-entry (car tmp-list))
13452 (vhdl-warning-when-idle
13453 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13454 (nth 1 tmp-entry) (nth 4 tmp-entry)
13455 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13456 (setq tmp-list (cdr tmp-list)))
13457 ;; check whether each package body has a package declaration
13458 (setq tmp-list pack-alist)
13459 (while tmp-list
13460 (when (null (nth 2 (car tmp-list)))
13461 (setq tmp-entry (car tmp-list))
13462 (vhdl-warning-when-idle
13463 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13464 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13465 (setq tmp-list (cdr tmp-list)))
13466 ;; sort lists
13467 (setq ent-alist (vhdl-sort-alist ent-alist))
13468 (setq conf-alist (vhdl-sort-alist conf-alist))
13469 (setq pack-alist (vhdl-sort-alist pack-alist))
13470 ;; remember updated directory/project
13471 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13472 ;; clear directory alists
13473 (unless project
13474 (adelete 'vhdl-entity-alist key)
13475 (adelete 'vhdl-config-alist key)
13476 (adelete 'vhdl-package-alist key)
13477 (adelete 'vhdl-ent-inst-alist key)
13478 (adelete 'vhdl-file-alist key))
13479 ;; put directory contents into cache
13480 (aput 'vhdl-entity-alist key ent-alist)
13481 (aput 'vhdl-config-alist key conf-alist)
13482 (aput 'vhdl-package-alist key pack-alist)
13483 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13484 (aput 'vhdl-file-alist key file-alist)
13485 ;; final messages
13486 (message "Scanning %s %s\"%s\"...done"
13487 (if is-directory "directory" "files") (or num-string "") name)
13488 (unless project (message "Scanning directory...done"))
13489 (when big-files
13490 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13491 ;; save cache when scanned non-interactively
13492 (when (or (not project) (not non-final))
13493 (when (and noninteractive vhdl-speedbar-save-cache)
13494 (vhdl-save-cache key)))
13495 t))
13496
13497 (defun vhdl-scan-project-contents (project)
13498 "Scan the contents of all VHDL files found in the directories and files
13499 of PROJECT."
13500 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13501 (default-dir (vhdl-resolve-env-variable
13502 (nth 1 (aget vhdl-project-alist project))))
13503 (file-exclude-regexp
13504 (or (nth 3 (aget vhdl-project-alist project)) ""))
13505 dir-list-tmp dir dir-name num-dir act-dir recursive)
13506 ;; clear project alists
13507 (adelete 'vhdl-entity-alist project)
13508 (adelete 'vhdl-config-alist project)
13509 (adelete 'vhdl-package-alist project)
13510 (adelete 'vhdl-ent-inst-alist project)
13511 (adelete 'vhdl-file-alist project)
13512 ;; expand directory names by default-directory
13513 (message "Collecting source files...")
13514 (while dir-list
13515 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13516 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13517 (setq recursive (match-string 1 dir)
13518 dir-name (match-string 3 dir))
13519 (setq dir-list-tmp
13520 (cons (concat recursive
13521 (if (file-name-absolute-p dir-name) "" default-dir)
13522 dir-name)
13523 dir-list-tmp))
13524 (setq dir-list (cdr dir-list)))
13525 ;; resolve path wildcards
13526 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13527 ;; expand directories
13528 (while dir-list-tmp
13529 (setq dir (car dir-list-tmp))
13530 ;; get subdirectories
13531 (if (string-match "-r \\(.*[/\\]\\)" dir)
13532 (setq dir-list (append dir-list (vhdl-get-subdirs
13533 (match-string 1 dir))))
13534 (setq dir-list (append dir-list (list dir))))
13535 (setq dir-list-tmp (cdr dir-list-tmp)))
13536 ;; exclude files
13537 (unless (equal file-exclude-regexp "")
13538 (let ((case-fold-search nil))
13539 (while dir-list
13540 (unless (string-match file-exclude-regexp (car dir-list))
13541 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13542 (setq dir-list (cdr dir-list)))
13543 (setq dir-list (nreverse dir-list-tmp))))
13544 (message "Collecting source files...done")
13545 ;; scan for design units for each directory in DIR-LIST
13546 (setq dir-list-tmp nil
13547 num-dir (length dir-list)
13548 act-dir 1)
13549 (while dir-list
13550 (setq dir-name (abbreviate-file-name
13551 (expand-file-name (car dir-list))))
13552 (vhdl-scan-directory-contents dir-name project nil
13553 (format "(%s/%s) " act-dir num-dir)
13554 (cdr dir-list))
13555 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13556 (setq dir-list (cdr dir-list)
13557 act-dir (1+ act-dir)))
13558 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13559 (message "Scanning project \"%s\"...done" project)))
13560
13561 (defun vhdl-update-file-contents (file-name)
13562 "Update hierarchy information by contents of current buffer."
13563 (setq file-name (abbreviate-file-name file-name))
13564 (let* ((dir-name (file-name-directory file-name))
13565 (directory-alist vhdl-directory-alist)
13566 updated)
13567 (while directory-alist
13568 (when (member dir-name (nth 1 (car directory-alist)))
13569 (let* ((vhdl-project (nth 0 (car directory-alist)))
13570 (project (vhdl-project-p))
13571 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13572 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13573 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13574 (ent-inst-list (car (aget vhdl-ent-inst-alist
13575 (or project dir-name) t)))
13576 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13577 (file-entry (aget file-alist file-name t))
13578 (ent-list (nth 0 file-entry))
13579 (arch-list (nth 1 file-entry))
13580 (arch-ent-list (nth 2 file-entry))
13581 (conf-list (nth 3 file-entry))
13582 (pack-list (nth 4 file-entry))
13583 (pack-body-list (nth 5 file-entry))
13584 (inst-ent-list (nth 7 file-entry))
13585 (cache-key (or project dir-name))
13586 arch-alist key ent-key entry)
13587 ;; delete design units previously contained in this file:
13588 ;; entities
13589 (while ent-list
13590 (setq key (car ent-list)
13591 entry (aget ent-alist key t))
13592 (when (equal file-name (nth 1 entry))
13593 (if (nth 3 entry)
13594 (aput 'ent-alist key
13595 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13596 (adelete 'ent-alist key)))
13597 (setq ent-list (cdr ent-list)))
13598 ;; architectures
13599 (while arch-list
13600 (setq key (car arch-list)
13601 ent-key (car arch-ent-list)
13602 entry (aget ent-alist ent-key t)
13603 arch-alist (nth 3 entry))
13604 (when (equal file-name (nth 1 (aget arch-alist key t)))
13605 (adelete 'arch-alist key)
13606 (if (or (nth 1 entry) arch-alist)
13607 (aput 'ent-alist ent-key
13608 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13609 arch-alist (nth 4 entry) (nth 5 entry)))
13610 (adelete 'ent-alist ent-key)))
13611 (setq arch-list (cdr arch-list)
13612 arch-ent-list (cdr arch-ent-list)))
13613 ;; configurations
13614 (while conf-list
13615 (setq key (car conf-list))
13616 (when (equal file-name (nth 1 (aget conf-alist key t)))
13617 (adelete 'conf-alist key))
13618 (setq conf-list (cdr conf-list)))
13619 ;; package declarations
13620 (while pack-list
13621 (setq key (car pack-list)
13622 entry (aget pack-alist key t))
13623 (when (equal file-name (nth 1 entry))
13624 (if (nth 6 entry)
13625 (aput 'pack-alist key
13626 (list (nth 0 entry) nil nil nil nil nil
13627 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13628 (nth 9 entry)))
13629 (adelete 'pack-alist key)))
13630 (setq pack-list (cdr pack-list)))
13631 ;; package bodies
13632 (while pack-body-list
13633 (setq key (car pack-body-list)
13634 entry (aget pack-alist key t))
13635 (when (equal file-name (nth 6 entry))
13636 (if (nth 1 entry)
13637 (aput 'pack-alist key
13638 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13639 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13640 nil nil nil nil))
13641 (adelete 'pack-alist key)))
13642 (setq pack-body-list (cdr pack-body-list)))
13643 ;; instantiated entities
13644 (while inst-ent-list
13645 (setq ent-inst-list
13646 (vhdl-delete (car inst-ent-list) ent-inst-list))
13647 (setq inst-ent-list (cdr inst-ent-list)))
13648 ;; update caches
13649 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13650 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13651 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13652 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13653 ;; scan file
13654 (vhdl-scan-directory-contents file-name project t)
13655 (when (or (and vhdl-speedbar-show-projects project)
13656 (and (not vhdl-speedbar-show-projects) (not project)))
13657 (vhdl-speedbar-refresh project))
13658 (setq updated t)))
13659 (setq directory-alist (cdr directory-alist)))
13660 updated))
13661
13662 (defun vhdl-update-hierarchy ()
13663 "Update directory and hierarchy information in speedbar."
13664 (let ((file-list (reverse vhdl-modified-file-list))
13665 updated)
13666 (when (and vhdl-speedbar-update-on-saving file-list)
13667 (while file-list
13668 (setq updated
13669 (or (vhdl-update-file-contents (car file-list))
13670 updated))
13671 (setq file-list (cdr file-list)))
13672 (setq vhdl-modified-file-list nil)
13673 (vhdl-speedbar-update-current-unit)
13674 (when updated (message "Updating hierarchy...done")))))
13675
13676 ;; structure (parenthesised expression means list of such entries)
13677 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13678 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13679 ;; comp-lib-name level)
13680 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13681 conf-inst-alist level indent
13682 &optional include-top ent-hier)
13683 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13684 entity ENT-KEY."
13685 (let* ((ent-entry (aget ent-alist ent-key t))
13686 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13687 (cdar (last (nth 3 ent-entry)))))
13688 (inst-alist (nth 3 arch-entry))
13689 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13690 hier-list subcomp-list tmp-list inst-key inst-comp-name
13691 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13692 (when (= level 0) (message "Extract design hierarchy..."))
13693 (when include-top
13694 (setq level (1+ level)))
13695 (when (member ent-key ent-hier)
13696 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13697 ;; check configured architecture (already checked during scanning)
13698 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13699 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13700 ;; process all instances
13701 (while inst-alist
13702 (setq inst-entry (car inst-alist)
13703 inst-key (nth 0 inst-entry)
13704 inst-comp-name (nth 4 inst-entry)
13705 inst-conf-key (nth 7 inst-entry))
13706 ;; search entry in configuration's instantiations list
13707 (setq tmp-list conf-inst-alist)
13708 (while (and tmp-list
13709 (not (and (member (nth 0 (car tmp-list))
13710 (list "all" inst-key))
13711 (equal (nth 1 (car tmp-list))
13712 (downcase (or inst-comp-name ""))))))
13713 (setq tmp-list (cdr tmp-list)))
13714 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13715 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13716 (when (and inst-conf-key (not inst-conf-entry))
13717 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13718 ;; determine entity
13719 (setq inst-ent-key
13720 (or (nth 2 (car tmp-list)) ; from configuration
13721 (nth 3 inst-conf-entry) ; from subconfiguration
13722 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13723 ; from configuration spec.
13724 (nth 5 inst-entry))) ; from direct instantiation
13725 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13726 ;; determine architecture
13727 (setq inst-arch-key
13728 (or (nth 3 (car tmp-list)) ; from configuration
13729 (nth 4 inst-conf-entry) ; from subconfiguration
13730 (nth 6 inst-entry) ; from direct instantiation
13731 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13732 ; from configuration spec.
13733 (nth 4 inst-ent-entry) ; MRA
13734 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13735 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13736 ;; set library
13737 (setq inst-lib-key
13738 (or (nth 5 (car tmp-list)) ; from configuration
13739 (nth 8 inst-entry))) ; from direct instantiation
13740 ;; gather information for this instance
13741 (setq comp-entry
13742 (list (nth 1 inst-entry)
13743 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13744 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13745 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13746 (or (nth 0 inst-arch-entry) inst-arch-key)
13747 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13748 (or (nth 0 inst-conf-entry) inst-conf-key)
13749 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13750 inst-lib-key level))
13751 ;; get subcomponent hierarchy
13752 (setq subcomp-list (vhdl-get-hierarchy
13753 ent-alist conf-alist
13754 inst-ent-key inst-arch-key inst-conf-key
13755 (nth 5 inst-conf-entry)
13756 (1+ level) indent nil (cons ent-key ent-hier)))
13757 ;; add to list
13758 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13759 (setq inst-alist (cdr inst-alist)))
13760 (when include-top
13761 (setq hier-list
13762 (cons (list nil nil (nth 0 ent-entry)
13763 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13764 (nth 0 arch-entry)
13765 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13766 nil nil
13767 nil (1- level))
13768 hier-list)))
13769 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13770 hier-list))
13771
13772 (defun vhdl-get-instantiations (ent-key indent)
13773 "Get all instantiations of entity ENT-KEY."
13774 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13775 arch-alist inst-alist ent-inst-list
13776 ent-entry arch-entry inst-entry)
13777 (while ent-alist
13778 (setq ent-entry (car ent-alist))
13779 (setq arch-alist (nth 4 ent-entry))
13780 (while arch-alist
13781 (setq arch-entry (car arch-alist))
13782 (setq inst-alist (nth 4 arch-entry))
13783 (while inst-alist
13784 (setq inst-entry (car inst-alist))
13785 (when (equal ent-key (nth 5 inst-entry))
13786 (setq ent-inst-list
13787 (cons (list (nth 1 inst-entry)
13788 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13789 (nth 1 ent-entry)
13790 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13791 (nth 1 arch-entry)
13792 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13793 ent-inst-list)))
13794 (setq inst-alist (cdr inst-alist)))
13795 (setq arch-alist (cdr arch-alist)))
13796 (setq ent-alist (cdr ent-alist)))
13797 (nreverse ent-inst-list)))
13798
13799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13800 ;; Caching in file
13801
13802 (defun vhdl-save-caches ()
13803 "Save all updated hierarchy caches to file."
13804 (interactive)
13805 (condition-case nil
13806 (when vhdl-speedbar-save-cache
13807 ;; update hierarchy
13808 (vhdl-update-hierarchy)
13809 (let ((project-list vhdl-updated-project-list))
13810 (message "Saving hierarchy caches...")
13811 ;; write updated project caches
13812 (while project-list
13813 (vhdl-save-cache (car project-list))
13814 (setq project-list (cdr project-list)))
13815 (message "Saving hierarchy caches...done")))
13816 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13817 (sit-for 2)))))
13818
13819 (defun vhdl-save-cache (key)
13820 "Save current hierarchy cache to file."
13821 (let* ((orig-buffer (current-buffer))
13822 (vhdl-project key)
13823 (project (vhdl-project-p))
13824 (default-directory key)
13825 (directory (abbreviate-file-name (vhdl-default-directory)))
13826 (file-name (vhdl-resolve-env-variable
13827 (vhdl-replace-string
13828 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13829 (concat
13830 (subst-char-in-string ? ?_ (or project "dir"))
13831 " " (user-login-name)))))
13832 (file-dir-name (expand-file-name file-name directory))
13833 (cache-key (or project directory))
13834 (key (if project "project" "directory")))
13835 (unless (file-exists-p (file-name-directory file-dir-name))
13836 (make-directory (file-name-directory file-dir-name) t))
13837 (if (not (file-writable-p file-dir-name))
13838 (progn (vhdl-warning (format "File not writable: \"%s\""
13839 (abbreviate-file-name file-dir-name)))
13840 (sit-for 2))
13841 (message "Saving cache: \"%s\"" file-dir-name)
13842 (set-buffer (find-file-noselect file-dir-name t t))
13843 (erase-buffer)
13844 (insert ";; -*- Emacs-Lisp -*-\n\n"
13845 ";;; " (file-name-nondirectory file-name)
13846 " - design hierarchy cache file for Emacs VHDL Mode "
13847 vhdl-version "\n")
13848 (insert "\n;; " (if project "Project " "Directory") " : ")
13849 (if project (insert project) (prin1 directory (current-buffer)))
13850 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13851 (user-login-name) "\n\n"
13852 "\n;; version number\n"
13853 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13854 "\n;; " (if project "project" "directory") " name"
13855 "\n(setq " key " ")
13856 (prin1 (or project directory) (current-buffer))
13857 (insert ")\n")
13858 (when (member 'hierarchy vhdl-speedbar-save-cache)
13859 (insert "\n;; entity and architecture cache\n"
13860 "(aput 'vhdl-entity-alist " key " '")
13861 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13862 (insert ")\n\n;; configuration cache\n"
13863 "(aput 'vhdl-config-alist " key " '")
13864 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13865 (insert ")\n\n;; package cache\n"
13866 "(aput 'vhdl-package-alist " key " '")
13867 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13868 (insert ")\n\n;; instantiated entities cache\n"
13869 "(aput 'vhdl-ent-inst-alist " key " '")
13870 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13871 (insert ")\n\n;; design units per file cache\n"
13872 "(aput 'vhdl-file-alist " key " '")
13873 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13874 (when project
13875 (insert ")\n\n;; source directories in project cache\n"
13876 "(aput 'vhdl-directory-alist " key " '")
13877 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13878 (insert ")\n"))
13879 (when (member 'display vhdl-speedbar-save-cache)
13880 (insert "\n;; shown design units cache\n"
13881 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13882 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13883 (current-buffer))
13884 (insert ")\n"))
13885 (setq vhdl-updated-project-list
13886 (delete cache-key vhdl-updated-project-list))
13887 (save-buffer)
13888 (kill-buffer (current-buffer))
13889 (set-buffer orig-buffer))))
13890
13891 (defun vhdl-load-cache (key)
13892 "Load hierarchy cache information from file."
13893 (let* ((vhdl-project key)
13894 (default-directory key)
13895 (directory (vhdl-default-directory))
13896 (file-name (vhdl-resolve-env-variable
13897 (vhdl-replace-string
13898 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13899 (concat
13900 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13901 " " (user-login-name)))))
13902 (file-dir-name (expand-file-name file-name directory))
13903 vhdl-cache-version)
13904 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13905 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13906 (when (file-exists-p file-dir-name)
13907 (condition-case ()
13908 (progn (load-file file-dir-name)
13909 (string< (mapconcat
13910 (lambda (a) (format "%3d" (string-to-number a)))
13911 (split-string "3.33" "\\.") "")
13912 (mapconcat
13913 (lambda (a) (format "%3d" (string-to-number a)))
13914 (split-string vhdl-cache-version "\\.") "")))
13915 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13916 nil))))))
13917
13918 (defun vhdl-require-hierarchy-info ()
13919 "Make sure that hierarchy information is available. Load cache or scan files
13920 if required."
13921 (if (vhdl-project-p)
13922 (unless (or (assoc vhdl-project vhdl-file-alist)
13923 (vhdl-load-cache vhdl-project))
13924 (vhdl-scan-project-contents vhdl-project))
13925 (let ((directory (abbreviate-file-name default-directory)))
13926 (unless (or (assoc directory vhdl-file-alist)
13927 (vhdl-load-cache directory))
13928 (vhdl-scan-directory-contents directory)))))
13929
13930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13931 ;; Add hierarchy browser functionality to speedbar
13932
13933 (defvar vhdl-speedbar-key-map nil
13934 "Keymap used when in the VHDL hierarchy browser mode.")
13935
13936 (defvar vhdl-speedbar-menu-items nil
13937 "Additional menu-items to add to speedbar frame.")
13938
13939 (defun vhdl-speedbar-initialize ()
13940 "Initialize speedbar."
13941 ;; general settings
13942 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13943 ;; VHDL file extensions (extracted from `auto-mode-alist')
13944 (let ((mode-alist auto-mode-alist))
13945 (while mode-alist
13946 (when (eq (cdar mode-alist) 'vhdl-mode)
13947 (speedbar-add-supported-extension (caar mode-alist)))
13948 (setq mode-alist (cdr mode-alist))))
13949 ;; hierarchy browser settings
13950 (when (boundp 'speedbar-mode-functions-list)
13951 ;; special functions
13952 (speedbar-add-mode-functions-list
13953 '("vhdl directory"
13954 (speedbar-item-info . vhdl-speedbar-item-info)
13955 (speedbar-line-directory . speedbar-files-line-path)))
13956 (speedbar-add-mode-functions-list
13957 '("vhdl project"
13958 (speedbar-item-info . vhdl-speedbar-item-info)
13959 (speedbar-line-directory . vhdl-speedbar-line-project)))
13960 ;; keymap
13961 (unless vhdl-speedbar-key-map
13962 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13963 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13964 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13965 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13966 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13967 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13968 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13969 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13970 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13971 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13972 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
13973 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13974 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13975 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13976 (let ((key 0))
13977 (while (<= key 9)
13978 (define-key vhdl-speedbar-key-map (int-to-string key)
13979 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13980 (setq key (1+ key)))))
13981 (define-key speedbar-key-map "h"
13982 (lambda () (interactive)
13983 (speedbar-change-initial-expansion-list "vhdl directory")))
13984 (define-key speedbar-key-map "H"
13985 (lambda () (interactive)
13986 (speedbar-change-initial-expansion-list "vhdl project")))
13987 ;; menu
13988 (unless vhdl-speedbar-menu-items
13989 (setq
13990 vhdl-speedbar-menu-items
13991 `(["Edit" speedbar-edit-line t]
13992 ["Expand" speedbar-expand-line
13993 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13994 ["Contract" vhdl-speedbar-contract-level t]
13995 ["Expand All" vhdl-speedbar-expand-all t]
13996 ["Contract All" vhdl-speedbar-contract-all t]
13997 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13998 (while (<= key 9)
13999 (setq menu-list
14000 (cons `[,(if (= key 0) "All" (int-to-string key))
14001 (vhdl-speedbar-set-depth ,key)
14002 :style radio
14003 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14004 :keys ,(int-to-string key)]
14005 menu-list))
14006 (setq key (1+ key)))
14007 (nreverse menu-list))
14008 "--"
14009 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14010 (or (vhdl-speedbar-check-unit 'entity)
14011 (vhdl-speedbar-check-unit 'subprogram))]
14012 ["Place Component" vhdl-speedbar-place-component
14013 (vhdl-speedbar-check-unit 'entity)]
14014 ["Generate Configuration" vhdl-speedbar-configuration
14015 (vhdl-speedbar-check-unit 'architecture)]
14016 ["Select as MRA" vhdl-speedbar-select-mra
14017 (vhdl-speedbar-check-unit 'architecture)]
14018 ["Make" vhdl-speedbar-make-design
14019 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14020 ["Generate Makefile" vhdl-speedbar-generate-makefile
14021 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14022 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14023 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14024 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14025 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14026 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14027 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14028 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14029 ;; hook-ups
14030 (speedbar-add-expansion-list
14031 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14032 vhdl-speedbar-display-directory))
14033 (speedbar-add-expansion-list
14034 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14035 vhdl-speedbar-display-projects))
14036 (setq speedbar-stealthy-function-list
14037 (append
14038 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14039 ("vhdl project" vhdl-speedbar-update-current-project
14040 vhdl-speedbar-update-current-unit)
14041 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14042 ; (speedbar-extension-list-to-regex
14043 ; speedbar-ignored-path-expressions))))
14044 )
14045 speedbar-stealthy-function-list))
14046 (when (eq vhdl-speedbar-display-mode 'directory)
14047 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14048 (when (eq vhdl-speedbar-display-mode 'project)
14049 (setq speedbar-initial-expansion-list-name "vhdl project"))
14050 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14051
14052 (defun vhdl-speedbar (&optional arg)
14053 "Open/close speedbar."
14054 (interactive)
14055 (if (not (fboundp 'speedbar))
14056 (error "WARNING: Speedbar is not available or not installed")
14057 (condition-case ()
14058 (speedbar-frame-mode arg)
14059 (error (error "WARNING: An error occurred while opening speedbar")))))
14060
14061 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14062 ;; Display functions
14063
14064 (defvar vhdl-speedbar-last-selected-project nil
14065 "Name of last selected project.")
14066
14067 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14068 (defmacro speedbar-with-writable (&rest forms)
14069 "Allow the buffer to be writable and evaluate FORMS."
14070 (list 'let '((inhibit-read-only t))
14071 (cons 'progn forms)))
14072 (put 'speedbar-with-writable 'lisp-indent-function 0)
14073
14074 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14075 "Display directory and hierarchy information in speedbar."
14076 (setq vhdl-speedbar-show-projects nil)
14077 (setq speedbar-ignored-directory-regexp
14078 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14079 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14080 (setq speedbar-last-selected-file nil)
14081 (speedbar-with-writable
14082 (condition-case nil
14083 (progn
14084 ;; insert directory path
14085 (speedbar-directory-buttons directory depth)
14086 ;; insert subdirectories
14087 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14088 ;; scan and insert hierarchy of current directory
14089 (vhdl-speedbar-insert-dir-hierarchy directory depth
14090 speedbar-power-click)
14091 ;; expand subdirectories
14092 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14093 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14094
14095 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14096 "Display projects and hierarchy information in speedbar."
14097 (setq vhdl-speedbar-show-projects t)
14098 (setq speedbar-ignored-directory-regexp ".")
14099 (setq speedbar-last-selected-file nil)
14100 (setq vhdl-speedbar-last-selected-project nil)
14101 (speedbar-with-writable
14102 (condition-case nil
14103 ;; insert projects
14104 (vhdl-speedbar-insert-projects)
14105 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14106 (setq speedbar-full-text-cache nil)) ; prevent caching
14107
14108 (defun vhdl-speedbar-insert-projects ()
14109 "Insert all projects in speedbar."
14110 (vhdl-speedbar-make-title-line "Projects:")
14111 (let ((project-alist (if vhdl-project-sort
14112 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14113 vhdl-project-alist))
14114 (vhdl-speedbar-update-current-unit nil))
14115 ;; insert projects
14116 (while project-alist
14117 (speedbar-make-tag-line
14118 'angle ?+ 'vhdl-speedbar-expand-project
14119 (caar project-alist) (caar project-alist)
14120 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14121 (setq project-alist (cdr project-alist)))
14122 (setq project-alist vhdl-project-alist)
14123 ;; expand projects
14124 (while project-alist
14125 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14126 (goto-char (point-min))
14127 (when (re-search-forward
14128 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14129 (goto-char (match-end 1))
14130 (speedbar-do-function-pointer)))
14131 (setq project-alist (cdr project-alist))))
14132 ; (vhdl-speedbar-update-current-project)
14133 ; (vhdl-speedbar-update-current-unit nil t)
14134 )
14135
14136 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14137 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14138 otherwise use cached data."
14139 (when (or rescan (and (not (assoc project vhdl-file-alist))
14140 (not (vhdl-load-cache project))))
14141 (vhdl-scan-project-contents project))
14142 ;; insert design hierarchy
14143 (vhdl-speedbar-insert-hierarchy
14144 (aget vhdl-entity-alist project t)
14145 (aget vhdl-config-alist project t)
14146 (aget vhdl-package-alist project t)
14147 (car (aget vhdl-ent-inst-alist project t)) indent)
14148 (insert (int-to-string indent) ":\n")
14149 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14150 (put-text-property (1- (point)) (point) 'invisible nil)
14151 ;; expand design units
14152 (vhdl-speedbar-expand-units project))
14153
14154 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14155 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14156 otherwise use cached data."
14157 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14158 (not (vhdl-load-cache directory))))
14159 (vhdl-scan-directory-contents directory))
14160 ;; insert design hierarchy
14161 (vhdl-speedbar-insert-hierarchy
14162 (aget vhdl-entity-alist directory t)
14163 (aget vhdl-config-alist directory t)
14164 (aget vhdl-package-alist directory t)
14165 (car (aget vhdl-ent-inst-alist directory t)) depth)
14166 ;; expand design units
14167 (vhdl-speedbar-expand-units directory)
14168 (aput 'vhdl-directory-alist directory (list (list directory))))
14169
14170 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14171 ent-inst-list depth)
14172 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14173 (if (not (or ent-alist conf-alist pack-alist))
14174 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14175 (let (ent-entry conf-entry pack-entry)
14176 ;; insert entities
14177 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14178 (while ent-alist
14179 (setq ent-entry (car ent-alist))
14180 (speedbar-make-tag-line
14181 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14182 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14183 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14184 'vhdl-speedbar-entity-face depth)
14185 (unless (nth 2 ent-entry)
14186 (end-of-line 0) (insert "!") (forward-char 1))
14187 (unless (member (nth 0 ent-entry) ent-inst-list)
14188 (end-of-line 0) (insert " (top)") (forward-char 1))
14189 (setq ent-alist (cdr ent-alist)))
14190 ;; insert configurations
14191 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14192 (while conf-alist
14193 (setq conf-entry (car conf-alist))
14194 (speedbar-make-tag-line
14195 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14196 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14197 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14198 'vhdl-speedbar-configuration-face depth)
14199 (setq conf-alist (cdr conf-alist)))
14200 ;; insert packages
14201 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14202 (while pack-alist
14203 (setq pack-entry (car pack-alist))
14204 (vhdl-speedbar-make-pack-line
14205 (nth 0 pack-entry) (nth 1 pack-entry)
14206 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14207 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14208 depth)
14209 (setq pack-alist (cdr pack-alist))))))
14210
14211 (defun vhdl-speedbar-rescan-hierarchy ()
14212 "Rescan hierarchy for the directory or project under the cursor."
14213 (interactive)
14214 (let (key path)
14215 (cond
14216 ;; current project
14217 (vhdl-speedbar-show-projects
14218 (setq key (vhdl-speedbar-line-project))
14219 (vhdl-scan-project-contents key))
14220 ;; top-level directory
14221 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14222 (re-search-forward "[0-9]+:" nil t)
14223 (vhdl-scan-directory-contents
14224 (abbreviate-file-name (speedbar-line-directory))))
14225 ;; current directory
14226 (t (setq path (speedbar-line-directory))
14227 (string-match "^\\(.+[/\\]\\)" path)
14228 (vhdl-scan-directory-contents
14229 (abbreviate-file-name (match-string 1 path)))))
14230 (vhdl-speedbar-refresh key)))
14231
14232 (defun vhdl-speedbar-expand-dirs (directory)
14233 "Expand subdirectories in DIRECTORY according to
14234 `speedbar-shown-directories'."
14235 ;; (nicked from `speedbar-default-directory-list')
14236 (let ((sf (cdr (reverse speedbar-shown-directories)))
14237 (vhdl-speedbar-update-current-unit nil))
14238 (setq speedbar-shown-directories
14239 (list (expand-file-name default-directory)))
14240 (while sf
14241 (when (speedbar-goto-this-file (car sf))
14242 (beginning-of-line)
14243 (when (looking-at "[0-9]+:\\s-*<")
14244 (goto-char (match-end 0))
14245 (speedbar-do-function-pointer)))
14246 (setq sf (cdr sf))))
14247 (vhdl-speedbar-update-current-unit nil t))
14248
14249 (defun vhdl-speedbar-expand-units (key)
14250 "Expand design units in directory/project KEY according to
14251 `vhdl-speedbar-shown-unit-alist'."
14252 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14253 (vhdl-speedbar-update-current-unit nil)
14254 vhdl-updated-project-list)
14255 (adelete 'vhdl-speedbar-shown-unit-alist key)
14256 (vhdl-prepare-search-1
14257 (while unit-alist ; expand units
14258 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14259 (beginning-of-line)
14260 (let ((arch-alist (nth 1 (car unit-alist)))
14261 position)
14262 (when (looking-at "^[0-9]+:\\s-*\\[")
14263 (goto-char (match-end 0))
14264 (setq position (point))
14265 (speedbar-do-function-pointer)
14266 (select-frame speedbar-frame)
14267 (while arch-alist ; expand architectures
14268 (goto-char position)
14269 (when (re-search-forward
14270 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14271 (car arch-alist) "\\>\\)") nil t)
14272 (beginning-of-line)
14273 (when (looking-at "^[0-9]+:\\s-*{")
14274 (goto-char (match-end 0))
14275 (speedbar-do-function-pointer)
14276 (select-frame speedbar-frame)))
14277 (setq arch-alist (cdr arch-alist))))
14278 (setq unit-alist (cdr unit-alist))))))
14279 (vhdl-speedbar-update-current-unit nil t))
14280
14281 (defun vhdl-speedbar-contract-level ()
14282 "Contract current level in current directory/project."
14283 (interactive)
14284 (when (or (save-excursion
14285 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14286 (and (save-excursion
14287 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14288 (re-search-backward
14289 (format "^[0-%d]:\\s-*[[{<]-"
14290 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14291 (goto-char (match-end 0))
14292 (speedbar-do-function-pointer)
14293 (speedbar-center-buffer-smartly)))
14294
14295 (defun vhdl-speedbar-contract-all ()
14296 "Contract all expanded design units in current directory/project."
14297 (interactive)
14298 (if (and vhdl-speedbar-show-projects
14299 (save-excursion (beginning-of-line) (looking-at "^0:")))
14300 (progn (setq vhdl-speedbar-shown-project-list nil)
14301 (vhdl-speedbar-refresh))
14302 (let ((key (vhdl-speedbar-line-key)))
14303 (adelete 'vhdl-speedbar-shown-unit-alist key)
14304 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14305 (when (memq 'display vhdl-speedbar-save-cache)
14306 (add-to-list 'vhdl-updated-project-list key)))))
14307
14308 (defun vhdl-speedbar-expand-all ()
14309 "Expand all design units in current directory/project."
14310 (interactive)
14311 (let* ((key (vhdl-speedbar-line-key))
14312 (ent-alist (aget vhdl-entity-alist key t))
14313 (conf-alist (aget vhdl-config-alist key t))
14314 (pack-alist (aget vhdl-package-alist key t))
14315 arch-alist unit-alist subunit-alist)
14316 (add-to-list 'vhdl-speedbar-shown-project-list key)
14317 (while ent-alist
14318 (setq arch-alist (nth 4 (car ent-alist)))
14319 (setq subunit-alist nil)
14320 (while arch-alist
14321 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14322 (setq arch-alist (cdr arch-alist)))
14323 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14324 (setq ent-alist (cdr ent-alist)))
14325 (while conf-alist
14326 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14327 (setq conf-alist (cdr conf-alist)))
14328 (while pack-alist
14329 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14330 (setq pack-alist (cdr pack-alist)))
14331 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14332 (vhdl-speedbar-refresh)
14333 (when (memq 'display vhdl-speedbar-save-cache)
14334 (add-to-list 'vhdl-updated-project-list key))))
14335
14336 (defun vhdl-speedbar-expand-project (text token indent)
14337 "Expand/contract the project under the cursor."
14338 (cond
14339 ((string-match "+" text) ; expand project
14340 (speedbar-change-expand-button-char ?-)
14341 (unless (member token vhdl-speedbar-shown-project-list)
14342 (setq vhdl-speedbar-shown-project-list
14343 (cons token vhdl-speedbar-shown-project-list)))
14344 (speedbar-with-writable
14345 (save-excursion
14346 (end-of-line) (forward-char 1)
14347 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14348 speedbar-power-click))))
14349 ((string-match "-" text) ; contract project
14350 (speedbar-change-expand-button-char ?+)
14351 (setq vhdl-speedbar-shown-project-list
14352 (delete token vhdl-speedbar-shown-project-list))
14353 (speedbar-delete-subblock indent))
14354 (t (error "Nothing to display")))
14355 (when (equal (selected-frame) speedbar-frame)
14356 (speedbar-center-buffer-smartly)))
14357
14358 (defun vhdl-speedbar-expand-entity (text token indent)
14359 "Expand/contract the entity under the cursor."
14360 (cond
14361 ((string-match "+" text) ; expand entity
14362 (let* ((key (vhdl-speedbar-line-key indent))
14363 (ent-alist (aget vhdl-entity-alist key t))
14364 (ent-entry (aget ent-alist token t))
14365 (arch-alist (nth 3 ent-entry))
14366 (inst-alist (vhdl-get-instantiations token indent))
14367 (subpack-alist (nth 5 ent-entry))
14368 (multiple-arch (> (length arch-alist) 1))
14369 arch-entry inst-entry)
14370 (if (not (or arch-alist inst-alist subpack-alist))
14371 (speedbar-change-expand-button-char ??)
14372 (speedbar-change-expand-button-char ?-)
14373 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14374 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14375 (aput 'unit-alist token nil)
14376 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14377 (speedbar-with-writable
14378 (save-excursion
14379 (end-of-line) (forward-char 1)
14380 ;; insert architectures
14381 (when arch-alist
14382 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14383 (while arch-alist
14384 (setq arch-entry (car arch-alist))
14385 (speedbar-make-tag-line
14386 'curly ?+ 'vhdl-speedbar-expand-architecture
14387 (cons token (nth 0 arch-entry))
14388 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14389 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14390 'vhdl-speedbar-architecture-face (1+ indent))
14391 (when (and multiple-arch
14392 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14393 (end-of-line 0) (insert " (mra)") (forward-char 1))
14394 (setq arch-alist (cdr arch-alist)))
14395 ;; insert instantiations
14396 (when inst-alist
14397 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14398 (while inst-alist
14399 (setq inst-entry (car inst-alist))
14400 (vhdl-speedbar-make-inst-line
14401 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14402 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14403 nil nil nil (1+ indent) 0 " in ")
14404 (setq inst-alist (cdr inst-alist)))
14405 ;; insert required packages
14406 (vhdl-speedbar-insert-subpackages
14407 subpack-alist (1+ indent) indent)))
14408 (when (memq 'display vhdl-speedbar-save-cache)
14409 (add-to-list 'vhdl-updated-project-list key))
14410 (vhdl-speedbar-update-current-unit t t))))
14411 ((string-match "-" text) ; contract entity
14412 (speedbar-change-expand-button-char ?+)
14413 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14414 (let* ((key (vhdl-speedbar-line-key indent))
14415 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14416 (adelete 'unit-alist token)
14417 (if unit-alist
14418 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14419 (adelete 'vhdl-speedbar-shown-unit-alist key))
14420 (speedbar-delete-subblock indent)
14421 (when (memq 'display vhdl-speedbar-save-cache)
14422 (add-to-list 'vhdl-updated-project-list key))))
14423 (t (error "Nothing to display")))
14424 (when (equal (selected-frame) speedbar-frame)
14425 (speedbar-center-buffer-smartly)))
14426
14427 (defun vhdl-speedbar-expand-architecture (text token indent)
14428 "Expand/contract the architecture under the cursor."
14429 (cond
14430 ((string-match "+" text) ; expand architecture
14431 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14432 (ent-alist (aget vhdl-entity-alist key t))
14433 (conf-alist (aget vhdl-config-alist key t))
14434 (hier-alist (vhdl-get-hierarchy
14435 ent-alist conf-alist (car token) (cdr token) nil nil
14436 0 (1- indent)))
14437 (ent-entry (aget ent-alist (car token) t))
14438 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14439 (subpack-alist (nth 4 arch-entry))
14440 entry)
14441 (if (not (or hier-alist subpack-alist))
14442 (speedbar-change-expand-button-char ??)
14443 (speedbar-change-expand-button-char ?-)
14444 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14445 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14446 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14447 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14448 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14449 (speedbar-with-writable
14450 (save-excursion
14451 (end-of-line) (forward-char 1)
14452 ;; insert instance hierarchy
14453 (when hier-alist
14454 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14455 (1+ indent)))
14456 (while hier-alist
14457 (setq entry (car hier-alist))
14458 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14459 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14460 (vhdl-speedbar-make-inst-line
14461 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14462 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14463 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14464 (setq hier-alist (cdr hier-alist)))
14465 ;; insert required packages
14466 (vhdl-speedbar-insert-subpackages
14467 subpack-alist (1+ indent) (1- indent))))
14468 (when (memq 'display vhdl-speedbar-save-cache)
14469 (add-to-list 'vhdl-updated-project-list key))
14470 (vhdl-speedbar-update-current-unit t t))))
14471 ((string-match "-" text) ; contract architecture
14472 (speedbar-change-expand-button-char ?+)
14473 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14474 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14475 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14476 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14477 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14478 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14479 (speedbar-delete-subblock indent)
14480 (when (memq 'display vhdl-speedbar-save-cache)
14481 (add-to-list 'vhdl-updated-project-list key))))
14482 (t (error "Nothing to display")))
14483 (when (equal (selected-frame) speedbar-frame)
14484 (speedbar-center-buffer-smartly)))
14485
14486 (defun vhdl-speedbar-expand-config (text token indent)
14487 "Expand/contract the configuration under the cursor."
14488 (cond
14489 ((string-match "+" text) ; expand configuration
14490 (let* ((key (vhdl-speedbar-line-key indent))
14491 (conf-alist (aget vhdl-config-alist key t))
14492 (conf-entry (aget conf-alist token))
14493 (ent-alist (aget vhdl-entity-alist key t))
14494 (hier-alist (vhdl-get-hierarchy
14495 ent-alist conf-alist (nth 3 conf-entry)
14496 (nth 4 conf-entry) token (nth 5 conf-entry)
14497 0 indent t))
14498 (subpack-alist (nth 6 conf-entry))
14499 entry)
14500 (if (not (or hier-alist subpack-alist))
14501 (speedbar-change-expand-button-char ??)
14502 (speedbar-change-expand-button-char ?-)
14503 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14504 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14505 (aput 'unit-alist token nil)
14506 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14507 (speedbar-with-writable
14508 (save-excursion
14509 (end-of-line) (forward-char 1)
14510 ;; insert instance hierarchy
14511 (when hier-alist
14512 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14513 (while hier-alist
14514 (setq entry (car hier-alist))
14515 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14516 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14517 (vhdl-speedbar-make-inst-line
14518 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14519 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14520 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14521 (setq hier-alist (cdr hier-alist)))
14522 ;; insert required packages
14523 (vhdl-speedbar-insert-subpackages
14524 subpack-alist (1+ indent) indent)))
14525 (when (memq 'display vhdl-speedbar-save-cache)
14526 (add-to-list 'vhdl-updated-project-list key))
14527 (vhdl-speedbar-update-current-unit t t))))
14528 ((string-match "-" text) ; contract configuration
14529 (speedbar-change-expand-button-char ?+)
14530 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14531 (let* ((key (vhdl-speedbar-line-key indent))
14532 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14533 (adelete 'unit-alist token)
14534 (if unit-alist
14535 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14536 (adelete 'vhdl-speedbar-shown-unit-alist key))
14537 (speedbar-delete-subblock indent)
14538 (when (memq 'display vhdl-speedbar-save-cache)
14539 (add-to-list 'vhdl-updated-project-list key))))
14540 (t (error "Nothing to display")))
14541 (when (equal (selected-frame) speedbar-frame)
14542 (speedbar-center-buffer-smartly)))
14543
14544 (defun vhdl-speedbar-expand-package (text token indent)
14545 "Expand/contract the package under the cursor."
14546 (cond
14547 ((string-match "+" text) ; expand package
14548 (let* ((key (vhdl-speedbar-line-key indent))
14549 (pack-alist (aget vhdl-package-alist key t))
14550 (pack-entry (aget pack-alist token t))
14551 (comp-alist (nth 3 pack-entry))
14552 (func-alist (nth 4 pack-entry))
14553 (func-body-alist (nth 8 pack-entry))
14554 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14555 comp-entry func-entry func-body-entry)
14556 (if (not (or comp-alist func-alist subpack-alist))
14557 (speedbar-change-expand-button-char ??)
14558 (speedbar-change-expand-button-char ?-)
14559 ;; add package to `vhdl-speedbar-shown-unit-alist'
14560 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14561 (aput 'unit-alist token nil)
14562 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14563 (speedbar-with-writable
14564 (save-excursion
14565 (end-of-line) (forward-char 1)
14566 ;; insert components
14567 (when comp-alist
14568 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14569 (while comp-alist
14570 (setq comp-entry (car comp-alist))
14571 (speedbar-make-tag-line
14572 nil nil nil
14573 (cons token (nth 0 comp-entry))
14574 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14575 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14576 'vhdl-speedbar-entity-face (1+ indent))
14577 (setq comp-alist (cdr comp-alist)))
14578 ;; insert subprograms
14579 (when func-alist
14580 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14581 (while func-alist
14582 (setq func-entry (car func-alist)
14583 func-body-entry (aget func-body-alist (car func-entry) t))
14584 (when (nth 2 func-entry)
14585 (vhdl-speedbar-make-subprogram-line
14586 (nth 1 func-entry)
14587 (cons (nth 2 func-entry) (nth 3 func-entry))
14588 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14589 (1+ indent)))
14590 (setq func-alist (cdr func-alist)))
14591 ;; insert required packages
14592 (vhdl-speedbar-insert-subpackages
14593 subpack-alist (1+ indent) indent)))
14594 (when (memq 'display vhdl-speedbar-save-cache)
14595 (add-to-list 'vhdl-updated-project-list key))
14596 (vhdl-speedbar-update-current-unit t t))))
14597 ((string-match "-" text) ; contract package
14598 (speedbar-change-expand-button-char ?+)
14599 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14600 (let* ((key (vhdl-speedbar-line-key indent))
14601 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14602 (adelete 'unit-alist token)
14603 (if unit-alist
14604 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14605 (adelete 'vhdl-speedbar-shown-unit-alist key))
14606 (speedbar-delete-subblock indent)
14607 (when (memq 'display vhdl-speedbar-save-cache)
14608 (add-to-list 'vhdl-updated-project-list key))))
14609 (t (error "Nothing to display")))
14610 (when (equal (selected-frame) speedbar-frame)
14611 (speedbar-center-buffer-smartly)))
14612
14613 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14614 "Insert required packages."
14615 (let* ((pack-alist (aget vhdl-package-alist
14616 (vhdl-speedbar-line-key dir-indent) t))
14617 pack-key lib-name pack-entry)
14618 (when subpack-alist
14619 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14620 (while subpack-alist
14621 (setq pack-key (cdar subpack-alist)
14622 lib-name (caar subpack-alist))
14623 (setq pack-entry (aget pack-alist pack-key t))
14624 (vhdl-speedbar-make-subpack-line
14625 (or (nth 0 pack-entry) pack-key) lib-name
14626 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14627 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14628 (setq subpack-alist (cdr subpack-alist)))))
14629
14630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14631 ;; Display help functions
14632
14633 (defvar vhdl-speedbar-update-current-unit t
14634 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14635
14636 (defun vhdl-speedbar-update-current-project ()
14637 "Highlight project that is currently active."
14638 (when (and vhdl-speedbar-show-projects
14639 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14640 (and (boundp 'speedbar-frame)
14641 (frame-live-p speedbar-frame)))
14642 (let ((last-frame (selected-frame))
14643 (project-alist vhdl-project-alist)
14644 pos)
14645 (select-frame speedbar-frame)
14646 (speedbar-with-writable
14647 (save-excursion
14648 (while project-alist
14649 (goto-char (point-min))
14650 (when (re-search-forward
14651 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14652 (put-text-property (match-beginning 1) (match-end 1) 'face
14653 (if (equal (caar project-alist) vhdl-project)
14654 'speedbar-selected-face
14655 'speedbar-directory-face))
14656 (when (equal (caar project-alist) vhdl-project)
14657 (setq pos (1- (match-beginning 1)))))
14658 (setq project-alist (cdr project-alist))))
14659 (when pos (goto-char pos)))
14660 (select-frame last-frame)
14661 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14662 t)
14663
14664 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14665 "Highlight all design units that are contained in the current file.
14666 NO-POSITION non-nil means do not re-position cursor."
14667 (let ((last-frame (selected-frame))
14668 (project-list vhdl-speedbar-shown-project-list)
14669 file-alist pos file-name)
14670 ;; get current file name
14671 (if (fboundp 'speedbar-select-attached-frame)
14672 (speedbar-select-attached-frame)
14673 (select-frame speedbar-attached-frame))
14674 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14675 (when (and vhdl-speedbar-update-current-unit
14676 (or always (not (equal file-name speedbar-last-selected-file))))
14677 (if vhdl-speedbar-show-projects
14678 (while project-list
14679 (setq file-alist (append file-alist (aget vhdl-file-alist
14680 (car project-list) t)))
14681 (setq project-list (cdr project-list)))
14682 (setq file-alist (aget vhdl-file-alist
14683 (abbreviate-file-name default-directory) t)))
14684 (select-frame speedbar-frame)
14685 (set-buffer speedbar-buffer)
14686 (speedbar-with-writable
14687 (vhdl-prepare-search-1
14688 (save-excursion
14689 ;; unhighlight last units
14690 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14691 (vhdl-speedbar-update-units
14692 "\\[.\\] " (nth 0 file-entry)
14693 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14694 (vhdl-speedbar-update-units
14695 "{.} " (nth 1 file-entry)
14696 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14697 (vhdl-speedbar-update-units
14698 "\\[.\\] " (nth 3 file-entry)
14699 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14700 (vhdl-speedbar-update-units
14701 "[]>] " (nth 4 file-entry)
14702 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14703 (vhdl-speedbar-update-units
14704 "\\[.\\].+(" '("body")
14705 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14706 (vhdl-speedbar-update-units
14707 "> " (nth 6 file-entry)
14708 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14709 ;; highlight current units
14710 (let* ((file-entry (aget file-alist file-name t)))
14711 (setq
14712 pos (vhdl-speedbar-update-units
14713 "\\[.\\] " (nth 0 file-entry)
14714 file-name 'vhdl-speedbar-entity-selected-face pos)
14715 pos (vhdl-speedbar-update-units
14716 "{.} " (nth 1 file-entry)
14717 file-name 'vhdl-speedbar-architecture-selected-face pos)
14718 pos (vhdl-speedbar-update-units
14719 "\\[.\\] " (nth 3 file-entry)
14720 file-name 'vhdl-speedbar-configuration-selected-face pos)
14721 pos (vhdl-speedbar-update-units
14722 "[]>] " (nth 4 file-entry)
14723 file-name 'vhdl-speedbar-package-selected-face pos)
14724 pos (vhdl-speedbar-update-units
14725 "\\[.\\].+(" '("body")
14726 file-name 'vhdl-speedbar-package-selected-face pos)
14727 pos (vhdl-speedbar-update-units
14728 "> " (nth 6 file-entry)
14729 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14730 ;; move speedbar so the first highlighted unit is visible
14731 (when (and pos (not no-position))
14732 (goto-char pos)
14733 (speedbar-center-buffer-smartly)
14734 (speedbar-position-cursor-on-line))
14735 (setq speedbar-last-selected-file file-name))
14736 (select-frame last-frame)
14737 t))
14738
14739 (defun vhdl-speedbar-update-units (text unit-list file-name face
14740 &optional pos)
14741 "Help function to highlight design units."
14742 (while unit-list
14743 (goto-char (point-min))
14744 (while (re-search-forward
14745 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14746 (when (equal file-name (car (get-text-property
14747 (match-beginning 1) 'speedbar-token)))
14748 (setq pos (or pos (point-marker)))
14749 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14750 (setq unit-list (cdr unit-list)))
14751 pos)
14752
14753 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14754 ent-name ent-file-marker
14755 arch-name arch-file-marker
14756 conf-name conf-file-marker
14757 lib-name depth offset delimiter)
14758 "Insert instantiation entry."
14759 (let ((start (point))
14760 visible-start)
14761 (insert (int-to-string depth) ":")
14762 (put-text-property start (point) 'invisible t)
14763 (setq visible-start (point))
14764 (insert-char ? (* depth speedbar-indentation-width))
14765 (while (> offset 0)
14766 (insert "|")
14767 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14768 (setq offset (1- offset)))
14769 (put-text-property visible-start (point) 'invisible nil)
14770 (setq start (point))
14771 (insert ">")
14772 (speedbar-make-button start (point) nil nil nil)
14773 (setq visible-start (point))
14774 (insert " ")
14775 (setq start (point))
14776 (if (not inst-name)
14777 (insert "(top)")
14778 (insert inst-name)
14779 (speedbar-make-button
14780 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14781 'vhdl-speedbar-find-file inst-file-marker))
14782 (insert delimiter)
14783 (when ent-name
14784 (setq start (point))
14785 (insert ent-name)
14786 (speedbar-make-button
14787 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14788 'vhdl-speedbar-find-file ent-file-marker)
14789 (when arch-name
14790 (insert " (")
14791 (setq start (point))
14792 (insert arch-name)
14793 (speedbar-make-button
14794 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14795 'vhdl-speedbar-find-file arch-file-marker)
14796 (insert ")"))
14797 (when conf-name
14798 (insert " (")
14799 (setq start (point))
14800 (insert conf-name)
14801 (speedbar-make-button
14802 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14803 'vhdl-speedbar-find-file conf-file-marker)
14804 (insert ")")))
14805 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14806 (setq start (point))
14807 (insert " (" lib-name ")")
14808 (put-text-property (+ 2 start) (1- (point)) 'face
14809 'vhdl-speedbar-library-face))
14810 (insert-char ?\n 1)
14811 (put-text-property visible-start (point) 'invisible nil)))
14812
14813 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14814 body-file-marker depth)
14815 "Insert package entry."
14816 (let ((start (point))
14817 visible-start)
14818 (insert (int-to-string depth) ":")
14819 (put-text-property start (point) 'invisible t)
14820 (setq visible-start (point))
14821 (insert-char ? (* depth speedbar-indentation-width))
14822 (put-text-property visible-start (point) 'invisible nil)
14823 (setq start (point))
14824 (insert "[+]")
14825 (speedbar-make-button
14826 start (point) 'speedbar-button-face 'speedbar-highlight-face
14827 'vhdl-speedbar-expand-package pack-key)
14828 (setq visible-start (point))
14829 (insert-char ? 1 nil)
14830 (setq start (point))
14831 (insert pack-name)
14832 (speedbar-make-button
14833 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14834 'vhdl-speedbar-find-file pack-file-marker)
14835 (unless (car pack-file-marker)
14836 (insert "!"))
14837 (when (car body-file-marker)
14838 (insert " (")
14839 (setq start (point))
14840 (insert "body")
14841 (speedbar-make-button
14842 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14843 'vhdl-speedbar-find-file body-file-marker)
14844 (insert ")"))
14845 (insert-char ?\n 1)
14846 (put-text-property visible-start (point) 'invisible nil)))
14847
14848 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14849 pack-body-file-marker depth)
14850 "Insert used package entry."
14851 (let ((start (point))
14852 visible-start)
14853 (insert (int-to-string depth) ":")
14854 (put-text-property start (point) 'invisible t)
14855 (setq visible-start (point))
14856 (insert-char ? (* depth speedbar-indentation-width))
14857 (put-text-property visible-start (point) 'invisible nil)
14858 (setq start (point))
14859 (insert ">")
14860 (speedbar-make-button start (point) nil nil nil)
14861 (setq visible-start (point))
14862 (insert " ")
14863 (setq start (point))
14864 (insert pack-name)
14865 (speedbar-make-button
14866 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14867 'vhdl-speedbar-find-file pack-file-marker)
14868 (when (car pack-body-file-marker)
14869 (insert " (")
14870 (setq start (point))
14871 (insert "body")
14872 (speedbar-make-button
14873 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14874 'vhdl-speedbar-find-file pack-body-file-marker)
14875 (insert ")"))
14876 (setq start (point))
14877 (insert " (" lib-name ")")
14878 (put-text-property (+ 2 start) (1- (point)) 'face
14879 'vhdl-speedbar-library-face)
14880 (insert-char ?\n 1)
14881 (put-text-property visible-start (point) 'invisible nil)))
14882
14883 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14884 func-body-file-marker
14885 depth)
14886 "Insert subprogram entry."
14887 (let ((start (point))
14888 visible-start)
14889 (insert (int-to-string depth) ":")
14890 (put-text-property start (point) 'invisible t)
14891 (setq visible-start (point))
14892 (insert-char ? (* depth speedbar-indentation-width))
14893 (put-text-property visible-start (point) 'invisible nil)
14894 (setq start (point))
14895 (insert ">")
14896 (speedbar-make-button start (point) nil nil nil)
14897 (setq visible-start (point))
14898 (insert " ")
14899 (setq start (point))
14900 (insert func-name)
14901 (speedbar-make-button
14902 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14903 'vhdl-speedbar-find-file func-file-marker)
14904 (when (car func-body-file-marker)
14905 (insert " (")
14906 (setq start (point))
14907 (insert "body")
14908 (speedbar-make-button
14909 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14910 'vhdl-speedbar-find-file func-body-file-marker)
14911 (insert ")"))
14912 (insert-char ?\n 1)
14913 (put-text-property visible-start (point) 'invisible nil)))
14914
14915 (defun vhdl-speedbar-make-title-line (text &optional depth)
14916 "Insert design unit title entry."
14917 (let ((start (point))
14918 visible-start)
14919 (when depth
14920 (insert (int-to-string depth) ":")
14921 (put-text-property start (point) 'invisible t))
14922 (setq visible-start (point))
14923 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14924 (setq start (point))
14925 (insert text)
14926 (speedbar-make-button start (point) nil nil nil nil)
14927 (insert-char ?\n 1)
14928 (put-text-property visible-start (point) 'invisible nil)))
14929
14930 (defun vhdl-speedbar-insert-dirs (files level)
14931 "Insert subdirectories."
14932 (let ((dirs (car files)))
14933 (while dirs
14934 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14935 (car dirs) 'speedbar-dir-follow nil
14936 'speedbar-directory-face level)
14937 (setq dirs (cdr dirs)))))
14938
14939 (defun vhdl-speedbar-dired (text token indent)
14940 "Speedbar click handler for directory expand button in hierarchy mode."
14941 (cond ((string-match "+" text) ; we have to expand this dir
14942 (setq speedbar-shown-directories
14943 (cons (expand-file-name
14944 (concat (speedbar-line-directory indent) token "/"))
14945 speedbar-shown-directories))
14946 (speedbar-change-expand-button-char ?-)
14947 (speedbar-reset-scanners)
14948 (speedbar-with-writable
14949 (save-excursion
14950 (end-of-line) (forward-char 1)
14951 (vhdl-speedbar-insert-dirs
14952 (speedbar-file-lists
14953 (concat (speedbar-line-directory indent) token "/"))
14954 (1+ indent))
14955 (speedbar-reset-scanners)
14956 (vhdl-speedbar-insert-dir-hierarchy
14957 (abbreviate-file-name
14958 (concat (speedbar-line-directory indent) token "/"))
14959 (1+ indent) speedbar-power-click)))
14960 (vhdl-speedbar-update-current-unit t t))
14961 ((string-match "-" text) ; we have to contract this node
14962 (speedbar-reset-scanners)
14963 (let ((oldl speedbar-shown-directories)
14964 (newl nil)
14965 (td (expand-file-name
14966 (concat (speedbar-line-directory indent) token))))
14967 (while oldl
14968 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14969 (setq newl (cons (car oldl) newl)))
14970 (setq oldl (cdr oldl)))
14971 (setq speedbar-shown-directories (nreverse newl)))
14972 (speedbar-change-expand-button-char ?+)
14973 (speedbar-delete-subblock indent))
14974 (t (error "Nothing to display")))
14975 (when (equal (selected-frame) speedbar-frame)
14976 (speedbar-center-buffer-smartly)))
14977
14978 (defun vhdl-speedbar-item-info ()
14979 "Derive and display information about this line item."
14980 (save-excursion
14981 (beginning-of-line)
14982 ;; skip invisible number info
14983 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14984 (cond
14985 ;; project/directory entry
14986 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14987 (if vhdl-speedbar-show-projects
14988 (message "Project \"%s\"" (match-string-no-properties 1))
14989 (speedbar-files-item-info)))
14990 ;; design unit entry
14991 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14992 (goto-char (match-end 1))
14993 (let ((face (get-text-property (point) 'face)))
14994 (message
14995 "%s \"%s\" in \"%s\""
14996 ;; design unit kind
14997 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14998 (eq face 'vhdl-speedbar-entity-selected-face))
14999 (if (equal (match-string 2) ">") "Component" "Entity"))
15000 ((or (eq face 'vhdl-speedbar-architecture-face)
15001 (eq face 'vhdl-speedbar-architecture-selected-face))
15002 "Architecture")
15003 ((or (eq face 'vhdl-speedbar-configuration-face)
15004 (eq face 'vhdl-speedbar-configuration-selected-face))
15005 "Configuration")
15006 ((or (eq face 'vhdl-speedbar-package-face)
15007 (eq face 'vhdl-speedbar-package-selected-face))
15008 "Package")
15009 ((or (eq face 'vhdl-speedbar-instantiation-face)
15010 (eq face 'vhdl-speedbar-instantiation-selected-face))
15011 "Instantiation")
15012 ((eq face 'vhdl-speedbar-subprogram-face)
15013 "Subprogram")
15014 (t ""))
15015 ;; design unit name
15016 (buffer-substring-no-properties
15017 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15018 (match-end 1))
15019 ;; file name
15020 (file-relative-name
15021 (or (car (get-text-property (point) 'speedbar-token))
15022 "?")
15023 (vhdl-default-directory)))))
15024 (t (message "")))))
15025
15026 (defun vhdl-speedbar-line-text ()
15027 "Calls `speedbar-line-text' and removes text properties."
15028 (let ((string (speedbar-line-text)))
15029 (set-text-properties 0 (length string) nil string)
15030 string))
15031
15032 (defun vhdl-speedbar-higher-text ()
15033 "Get speedbar-line-text of higher level."
15034 (let (depth string)
15035 (save-excursion
15036 (beginning-of-line)
15037 (looking-at "^\\([0-9]+\\):")
15038 (setq depth (string-to-number (match-string 1)))
15039 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15040 (setq string (match-string 1))
15041 (set-text-properties 0 (length string) nil string)
15042 string))))
15043
15044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15045 ;; Help functions
15046
15047 (defun vhdl-speedbar-line-key (&optional indent)
15048 "Get currently displayed directory of project name."
15049 (if vhdl-speedbar-show-projects
15050 (vhdl-speedbar-line-project)
15051 (abbreviate-file-name
15052 (file-name-as-directory (speedbar-line-directory indent)))))
15053
15054 (defun vhdl-speedbar-line-project (&optional indent)
15055 "Get currently displayed project name."
15056 (and vhdl-speedbar-show-projects
15057 (save-excursion
15058 (end-of-line)
15059 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15060 (match-string-no-properties 1))))
15061
15062 (defun vhdl-add-modified-file ()
15063 "Add file to `vhdl-modified-file-list'."
15064 (when vhdl-file-alist
15065 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15066 nil)
15067
15068 (defun vhdl-resolve-paths (path-list)
15069 "Resolve path wildcards in PATH-LIST."
15070 (let (path-list-1 path-list-2 path-beg path-end dir)
15071 ;; eliminate non-existent directories
15072 (while path-list
15073 (setq dir (car path-list))
15074 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15075 (if (file-directory-p (match-string 2 dir))
15076 (setq path-list-1 (cons dir path-list-1))
15077 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15078 (setq path-list (cdr path-list)))
15079 ;; resolve path wildcards
15080 (while path-list-1
15081 (setq dir (car path-list-1))
15082 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15083 (progn
15084 (setq path-beg (match-string 1 dir)
15085 path-end (match-string 5 dir))
15086 (setq path-list-1
15087 (append
15088 (mapcar
15089 (function
15090 (lambda (var) (concat path-beg var path-end)))
15091 (let ((all-list (vhdl-directory-files
15092 (match-string 2 dir) t
15093 (concat "\\<" (wildcard-to-regexp
15094 (match-string 4 dir)))))
15095 dir-list)
15096 (while all-list
15097 (when (file-directory-p (car all-list))
15098 (setq dir-list (cons (car all-list) dir-list)))
15099 (setq all-list (cdr all-list)))
15100 dir-list))
15101 (cdr path-list-1))))
15102 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15103 (when (file-directory-p (match-string 2 dir))
15104 (setq path-list-2 (cons dir path-list-2)))
15105 (setq path-list-1 (cdr path-list-1))))
15106 (nreverse path-list-2)))
15107
15108 (defun vhdl-speedbar-goto-this-unit (directory unit)
15109 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15110 (let ((dest (point)))
15111 (if (and (if vhdl-speedbar-show-projects
15112 (progn (goto-char (point-min)) t)
15113 (speedbar-goto-this-file directory))
15114 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15115 (progn (speedbar-position-cursor-on-line)
15116 t)
15117 (goto-char dest)
15118 nil)))
15119
15120 (defun vhdl-speedbar-find-file (text token indent)
15121 "When user clicks on TEXT, load file with name and position in TOKEN.
15122 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15123 is already shown in a buffer."
15124 (if (not (car token))
15125 (error "ERROR: File cannot be found")
15126 (let ((buffer (get-file-buffer (car token))))
15127 (speedbar-find-file-in-frame (car token))
15128 (when (or vhdl-speedbar-jump-to-unit buffer)
15129 (goto-char (point-min))
15130 (forward-line (1- (cdr token)))
15131 (recenter))
15132 (vhdl-speedbar-update-current-unit t t)
15133 (speedbar-set-timer dframe-update-speed)
15134 (speedbar-maybee-jump-to-attached-frame))))
15135
15136 (defun vhdl-speedbar-port-copy ()
15137 "Copy the port of the entity/component or subprogram under the cursor."
15138 (interactive)
15139 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15140 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15141 (error "ERROR: No entity/component or subprogram under cursor")
15142 (beginning-of-line)
15143 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15144 (condition-case info
15145 (let ((token (get-text-property
15146 (match-beginning 3) 'speedbar-token)))
15147 (vhdl-visit-file (car token) t
15148 (progn (goto-char (point-min))
15149 (forward-line (1- (cdr token)))
15150 (end-of-line)
15151 (if is-entity
15152 (vhdl-port-copy)
15153 (vhdl-subprog-copy)))))
15154 (error (error "ERROR: %s not scanned successfully\n (%s)"
15155 (if is-entity "Port" "Interface") (cadr info))))
15156 (error "ERROR: No entity/component or subprogram on current line")))))
15157
15158 (defun vhdl-speedbar-place-component ()
15159 "Place the entity/component under the cursor as component."
15160 (interactive)
15161 (if (not (vhdl-speedbar-check-unit 'entity))
15162 (error "ERROR: No entity/component under cursor")
15163 (vhdl-speedbar-port-copy)
15164 (if (fboundp 'speedbar-select-attached-frame)
15165 (speedbar-select-attached-frame)
15166 (select-frame speedbar-attached-frame))
15167 (vhdl-compose-place-component)
15168 (select-frame speedbar-frame)))
15169
15170 (defun vhdl-speedbar-configuration ()
15171 "Generate configuration for the architecture under the cursor."
15172 (interactive)
15173 (if (not (vhdl-speedbar-check-unit 'architecture))
15174 (error "ERROR: No architecture under cursor")
15175 (let ((arch-name (vhdl-speedbar-line-text))
15176 (ent-name (vhdl-speedbar-higher-text)))
15177 (if (fboundp 'speedbar-select-attached-frame)
15178 (speedbar-select-attached-frame)
15179 (select-frame speedbar-attached-frame))
15180 (vhdl-compose-configuration ent-name arch-name))))
15181
15182 (defun vhdl-speedbar-select-mra ()
15183 "Select the architecture under the cursor as MRA."
15184 (interactive)
15185 (if (not (vhdl-speedbar-check-unit 'architecture))
15186 (error "ERROR: No architecture under cursor")
15187 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15188 (ent-key (downcase (vhdl-speedbar-higher-text)))
15189 (ent-alist (aget vhdl-entity-alist
15190 (or (vhdl-project-p) default-directory) t))
15191 (ent-entry (aget ent-alist ent-key t)))
15192 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15193 (speedbar-refresh))))
15194
15195 (defun vhdl-speedbar-make-design ()
15196 "Make (compile) design unit or directory/project under the cursor."
15197 (interactive)
15198 (if (not (save-excursion (beginning-of-line)
15199 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15200 (error "ERROR: No primary design unit or directory/project under cursor")
15201 (let ((is-unit (match-string 2))
15202 (unit-name (vhdl-speedbar-line-text))
15203 (vhdl-project (vhdl-speedbar-line-project))
15204 (directory (file-name-as-directory
15205 (or (speedbar-line-file) (speedbar-line-directory)))))
15206 (if (fboundp 'speedbar-select-attached-frame)
15207 (speedbar-select-attached-frame)
15208 (select-frame speedbar-attached-frame))
15209 (let ((default-directory directory))
15210 (vhdl-make (and is-unit unit-name))))))
15211
15212 (defun vhdl-speedbar-generate-makefile ()
15213 "Generate Makefile for directory/project under the cursor."
15214 (interactive)
15215 (let ((vhdl-project (vhdl-speedbar-line-project))
15216 (default-directory (file-name-as-directory
15217 (or (speedbar-line-file) (speedbar-line-directory)))))
15218 (vhdl-generate-makefile)))
15219
15220 (defun vhdl-speedbar-check-unit (design-unit)
15221 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15222 expansion function)."
15223 (save-excursion
15224 (speedbar-position-cursor-on-line)
15225 (cond ((eq design-unit 'entity)
15226 (memq (get-text-property (match-end 0) 'face)
15227 '(vhdl-speedbar-entity-face
15228 vhdl-speedbar-entity-selected-face)))
15229 ((eq design-unit 'architecture)
15230 (memq (get-text-property (match-end 0) 'face)
15231 '(vhdl-speedbar-architecture-face
15232 vhdl-speedbar-architecture-selected-face)))
15233 ((eq design-unit 'subprogram)
15234 (eq (get-text-property (match-end 0) 'face)
15235 'vhdl-speedbar-subprogram-face))
15236 (t nil))))
15237
15238 (defun vhdl-speedbar-set-depth (depth)
15239 "Set hierarchy display depth to DEPTH and refresh speedbar."
15240 (setq vhdl-speedbar-hierarchy-depth depth)
15241 (speedbar-refresh))
15242
15243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15244 ;; Fontification
15245
15246 (defface vhdl-speedbar-entity-face
15247 '((((class color) (background light)) (:foreground "ForestGreen"))
15248 (((class color) (background dark)) (:foreground "PaleGreen")))
15249 "Face used for displaying entity names."
15250 :group 'speedbar-faces)
15251
15252 (defface vhdl-speedbar-architecture-face
15253 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15254 (((class color) (background light)) (:foreground "Blue"))
15255
15256 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15257 "Face used for displaying architecture names."
15258 :group 'speedbar-faces)
15259
15260 (defface vhdl-speedbar-configuration-face
15261 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15262 (((class color) (background dark)) (:foreground "Salmon")))
15263 "Face used for displaying configuration names."
15264 :group 'speedbar-faces)
15265
15266 (defface vhdl-speedbar-package-face
15267 '((((class color) (background light)) (:foreground "Grey50"))
15268 (((class color) (background dark)) (:foreground "Grey80")))
15269 "Face used for displaying package names."
15270 :group 'speedbar-faces)
15271
15272 (defface vhdl-speedbar-library-face
15273 '((((class color) (background light)) (:foreground "Purple"))
15274 (((class color) (background dark)) (:foreground "Orchid1")))
15275 "Face used for displaying library names."
15276 :group 'speedbar-faces)
15277
15278 (defface vhdl-speedbar-instantiation-face
15279 '((((class color) (background light)) (:foreground "Brown"))
15280 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15281 (((class color) (background dark)) (:foreground "Yellow")))
15282 "Face used for displaying instantiation names."
15283 :group 'speedbar-faces)
15284
15285 (defface vhdl-speedbar-subprogram-face
15286 '((((class color) (background light)) (:foreground "Orchid4"))
15287 (((class color) (background dark)) (:foreground "BurlyWood2")))
15288 "Face used for displaying subprogram names."
15289 :group 'speedbar-faces)
15290
15291 (defface vhdl-speedbar-entity-selected-face
15292 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15293 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15294 "Face used for displaying entity names."
15295 :group 'speedbar-faces)
15296
15297 (defface vhdl-speedbar-architecture-selected-face
15298 '((((min-colors 88) (class color) (background light)) (:foreground
15299 "Blue1" :underline t))
15300 (((class color) (background light)) (:foreground "Blue" :underline t))
15301 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15302 "Face used for displaying architecture names."
15303 :group 'speedbar-faces)
15304
15305 (defface vhdl-speedbar-configuration-selected-face
15306 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15307 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15308 "Face used for displaying configuration names."
15309 :group 'speedbar-faces)
15310
15311 (defface vhdl-speedbar-package-selected-face
15312 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15313 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15314 "Face used for displaying package names."
15315 :group 'speedbar-faces)
15316
15317 (defface vhdl-speedbar-instantiation-selected-face
15318 '((((class color) (background light)) (:foreground "Brown" :underline t))
15319 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15320 "Face used for displaying instantiation names."
15321 :group 'speedbar-faces)
15322
15323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15324 ;; Initialization
15325
15326 ;; add speedbar
15327 (when (fboundp 'speedbar)
15328 (condition-case ()
15329 (when (and vhdl-speedbar-auto-open
15330 (not (and (boundp 'speedbar-frame)
15331 (frame-live-p speedbar-frame))))
15332 (speedbar-frame-mode 1)
15333 (if (fboundp 'speedbar-select-attached-frame)
15334 (speedbar-select-attached-frame)
15335 (select-frame speedbar-attached-frame)))
15336 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15337
15338 ;; initialize speedbar
15339 (if (not (boundp 'speedbar-frame))
15340 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15341 (vhdl-speedbar-initialize)
15342 (when speedbar-frame (vhdl-speedbar-refresh)))
15343
15344
15345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15346 ;;; Structural composition
15347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15348
15349 (defun vhdl-get-components-package-name ()
15350 "Return the name of the components package."
15351 (let ((project (vhdl-project-p)))
15352 (if project
15353 (vhdl-replace-string (car vhdl-components-package-name)
15354 (subst-char-in-string ? ?_ project))
15355 (cdr vhdl-components-package-name))))
15356
15357 (defun vhdl-compose-new-component ()
15358 "Create entity and architecture for new component."
15359 (interactive)
15360 (let* ((case-fold-search t)
15361 (ent-name (read-from-minibuffer "entity name: "
15362 nil vhdl-minibuffer-local-map))
15363 (arch-name
15364 (if (equal (cdr vhdl-compose-architecture-name) "")
15365 (read-from-minibuffer "architecture name: "
15366 nil vhdl-minibuffer-local-map)
15367 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15368 ent-file-name arch-file-name ent-buffer arch-buffer project)
15369 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15370 ;; open entity file
15371 (unless (eq vhdl-compose-create-files 'none)
15372 (setq ent-file-name
15373 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15374 "." (file-name-extension (buffer-file-name))))
15375 (when (and (file-exists-p ent-file-name)
15376 (not (y-or-n-p (concat "File \"" ent-file-name
15377 "\" exists; overwrite? "))))
15378 (error "ERROR: Creating component...aborted"))
15379 (find-file ent-file-name)
15380 (erase-buffer)
15381 (set-buffer-modified-p nil))
15382 ;; insert header
15383 (if vhdl-compose-include-header
15384 (progn (vhdl-template-header)
15385 (goto-char (point-max)))
15386 (vhdl-comment-display-line) (insert "\n\n"))
15387 ;; insert library clause
15388 (vhdl-template-package-std-logic-1164)
15389 (when vhdl-use-components-package
15390 (insert "\n")
15391 (vhdl-template-standard-package (vhdl-work-library)
15392 (vhdl-get-components-package-name)))
15393 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15394 ;; insert entity declaration
15395 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15396 (vhdl-insert-keyword " IS\n")
15397 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15398 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15399 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15400 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15401 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15402 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15403 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15404 (vhdl-insert-keyword "END ")
15405 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15406 (insert ent-name ";\n\n")
15407 (vhdl-comment-display-line) (insert "\n")
15408 ;; open architecture file
15409 (if (not (eq vhdl-compose-create-files 'separate))
15410 (insert "\n")
15411 (setq ent-buffer (current-buffer))
15412 (setq arch-file-name
15413 (concat (vhdl-replace-string vhdl-architecture-file-name
15414 (concat ent-name " " arch-name) t)
15415 "." (file-name-extension (buffer-file-name))))
15416 (when (and (file-exists-p arch-file-name)
15417 (not (y-or-n-p (concat "File \"" arch-file-name
15418 "\" exists; overwrite? "))))
15419 (error "ERROR: Creating component...aborted"))
15420 (find-file arch-file-name)
15421 (erase-buffer)
15422 (set-buffer-modified-p nil)
15423 ;; insert header
15424 (if vhdl-compose-include-header
15425 (progn (vhdl-template-header)
15426 (goto-char (point-max)))
15427 (vhdl-comment-display-line) (insert "\n\n")))
15428 ;; insert architecture body
15429 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15430 (vhdl-insert-keyword " OF ") (insert ent-name)
15431 (vhdl-insert-keyword " IS\n\n")
15432 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15433 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15434 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15435 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15436 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15437 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15438 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15439 (vhdl-insert-keyword "BEGIN")
15440 (when vhdl-self-insert-comments
15441 (insert " -- ")
15442 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15443 (insert arch-name))
15444 (insert "\n\n")
15445 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15446 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15447 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15448 (vhdl-insert-keyword "END ")
15449 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15450 (insert arch-name ";\n\n")
15451 ;; insert footer and save
15452 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15453 (vhdl-template-footer)
15454 (vhdl-comment-display-line) (insert "\n"))
15455 (goto-char (point-min))
15456 (setq arch-buffer (current-buffer))
15457 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15458 (set-buffer arch-buffer) (save-buffer)
15459 (message "%s"
15460 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15461 (and ent-file-name
15462 (format "\n File created: \"%s\"" ent-file-name))
15463 (and arch-file-name
15464 (format "\n File created: \"%s\"" arch-file-name))))))
15465
15466 (defun vhdl-compose-place-component ()
15467 "Place new component by pasting current port as component declaration and
15468 component instantiation."
15469 (interactive)
15470 (if (not vhdl-port-list)
15471 (error "ERROR: No port has been read")
15472 (save-excursion
15473 (vhdl-prepare-search-2
15474 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15475 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15476 (error "ERROR: No architecture found"))
15477 (let* ((ent-name (match-string 1))
15478 (ent-file-name
15479 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15480 "." (file-name-extension (buffer-file-name))))
15481 (orig-buffer (current-buffer)))
15482 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15483 ;; place component declaration
15484 (unless (or vhdl-use-components-package
15485 (vhdl-use-direct-instantiation)
15486 (save-excursion
15487 (re-search-forward
15488 (concat "^\\s-*component\\s-+"
15489 (car vhdl-port-list) "\\>") nil t)))
15490 (re-search-forward "^begin\\>" nil)
15491 (beginning-of-line)
15492 (skip-chars-backward " \t\n")
15493 (insert "\n\n") (indent-to vhdl-basic-offset)
15494 (vhdl-port-paste-component t))
15495 ;; place component instantiation
15496 (re-search-forward "^end\\>" nil)
15497 (beginning-of-line)
15498 (skip-chars-backward " \t\n")
15499 (insert "\n\n") (indent-to vhdl-basic-offset)
15500 (vhdl-port-paste-instance nil t t)
15501 ;; place use clause for used packages
15502 (when (nth 3 vhdl-port-list)
15503 ;; open entity file
15504 (when (file-exists-p ent-file-name)
15505 (find-file ent-file-name))
15506 (goto-char (point-min))
15507 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15508 (error "ERROR: Entity not found: \"%s\"" ent-name))
15509 (goto-char (match-beginning 0))
15510 (if (and (save-excursion
15511 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15512 (match-string 1))
15513 (progn (goto-char (match-end 0))
15514 (beginning-of-line 2))
15515 (insert "\n")
15516 (backward-char))
15517 (vhdl-port-paste-context-clause)
15518 (switch-to-buffer orig-buffer))
15519 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15520
15521 (defun vhdl-compose-wire-components ()
15522 "Connect components."
15523 (interactive)
15524 (save-excursion
15525 (vhdl-prepare-search-2
15526 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15527 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15528 (error "ERROR: No architecture found"))
15529 (let* ((ent-name (match-string 1))
15530 (ent-file-name
15531 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15532 "." (file-name-extension (buffer-file-name))))
15533 (arch-decl-pos (point-marker))
15534 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15535 (arch-end-pos (re-search-forward "^end\\>" nil))
15536 (pack-name (vhdl-get-components-package-name))
15537 (pack-file-name
15538 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15539 "." (file-name-extension (buffer-file-name))))
15540 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15541 port-alist generic-alist inst-alist
15542 signal-name signal-entry signal-alist local-list written-list
15543 single-in-list multi-in-list single-out-list multi-out-list
15544 constant-name constant-entry constant-alist single-list multi-list
15545 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15546 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15547 signal-beg-pos signal-pos
15548 constant-temp-pos port-temp-pos signal-temp-pos)
15549 (message "Wiring components...")
15550 ;; process all instances
15551 (goto-char arch-stat-pos)
15552 (while (re-search-forward
15553 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15554 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15555 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15556 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15557 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15558 (setq inst-name (match-string-no-properties 1)
15559 comp-name (match-string-no-properties 4)
15560 comp-ent-name (match-string-no-properties 12)
15561 has-generic (or (match-string 7) (match-string 17)))
15562 ;; get port ...
15563 (if comp-name
15564 ;; ... from component declaration
15565 (vhdl-visit-file
15566 (when vhdl-use-components-package pack-file-name) t
15567 (save-excursion
15568 (goto-char (point-min))
15569 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15570 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15571 (vhdl-port-copy)))
15572 ;; ... from entity declaration (direct instantiation)
15573 (setq comp-ent-file-name
15574 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15575 "." (file-name-extension (buffer-file-name))))
15576 (vhdl-visit-file
15577 comp-ent-file-name t
15578 (save-excursion
15579 (goto-char (point-min))
15580 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15581 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15582 (vhdl-port-copy))))
15583 (vhdl-port-flatten t)
15584 (setq generic-alist (nth 1 vhdl-port-list)
15585 port-alist (nth 2 vhdl-port-list)
15586 vhdl-port-list nil)
15587 (setq constant-alist nil
15588 signal-alist nil)
15589 (when has-generic
15590 ;; process all constants in generic map
15591 (vhdl-forward-syntactic-ws)
15592 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15593 (setq constant-name (match-string-no-properties 3))
15594 (setq constant-entry
15595 (cons constant-name
15596 (if (match-string 1)
15597 (or (aget generic-alist (match-string 2) t)
15598 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15599 (cdar generic-alist))))
15600 (setq constant-alist (cons constant-entry constant-alist))
15601 (setq constant-name (downcase constant-name))
15602 (if (or (member constant-name single-list)
15603 (member constant-name multi-list))
15604 (progn (setq single-list (delete constant-name single-list))
15605 (add-to-list 'multi-list constant-name))
15606 (add-to-list 'single-list constant-name))
15607 (unless (match-string 1)
15608 (setq generic-alist (cdr generic-alist)))
15609 (vhdl-forward-syntactic-ws))
15610 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15611 ;; process all signals in port map
15612 (vhdl-forward-syntactic-ws)
15613 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15614 (setq signal-name (match-string-no-properties 3))
15615 (setq signal-entry (cons signal-name
15616 (if (match-string 1)
15617 (or (aget port-alist (match-string 2) t)
15618 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15619 (cdar port-alist))))
15620 (setq signal-alist (cons signal-entry signal-alist))
15621 (setq signal-name (downcase signal-name))
15622 (if (equal (upcase (nth 2 signal-entry)) "IN")
15623 ;; input signal
15624 (cond
15625 ((member signal-name local-list)
15626 nil)
15627 ((or (member signal-name single-out-list)
15628 (member signal-name multi-out-list))
15629 (setq single-out-list (delete signal-name single-out-list))
15630 (setq multi-out-list (delete signal-name multi-out-list))
15631 (add-to-list 'local-list signal-name))
15632 ((member signal-name single-in-list)
15633 (setq single-in-list (delete signal-name single-in-list))
15634 (add-to-list 'multi-in-list signal-name))
15635 ((not (member signal-name multi-in-list))
15636 (add-to-list 'single-in-list signal-name)))
15637 ;; output signal
15638 (cond
15639 ((member signal-name local-list)
15640 nil)
15641 ((or (member signal-name single-in-list)
15642 (member signal-name multi-in-list))
15643 (setq single-in-list (delete signal-name single-in-list))
15644 (setq multi-in-list (delete signal-name multi-in-list))
15645 (add-to-list 'local-list signal-name))
15646 ((member signal-name single-out-list)
15647 (setq single-out-list (delete signal-name single-out-list))
15648 (add-to-list 'multi-out-list signal-name))
15649 ((not (member signal-name multi-out-list))
15650 (add-to-list 'single-out-list signal-name))))
15651 (unless (match-string 1)
15652 (setq port-alist (cdr port-alist)))
15653 (vhdl-forward-syntactic-ws))
15654 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15655 (nreverse signal-alist)) inst-alist)))
15656 ;; prepare signal insertion
15657 (vhdl-goto-marker arch-decl-pos)
15658 (forward-line 1)
15659 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15660 (setq signal-pos (point-marker))
15661 (while (progn (vhdl-forward-syntactic-ws)
15662 (looking-at "signal\\>"))
15663 (beginning-of-line 2)
15664 (delete-region signal-pos (point)))
15665 (setq signal-beg-pos signal-pos)
15666 ;; open entity file
15667 (when (file-exists-p ent-file-name)
15668 (find-file ent-file-name))
15669 (goto-char (point-min))
15670 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15671 (error "ERROR: Entity not found: \"%s\"" ent-name))
15672 ;; prepare generic clause insertion
15673 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15674 (match-string 1))
15675 (goto-char (match-beginning 0))
15676 (indent-to vhdl-basic-offset)
15677 (insert "generic ();\n\n")
15678 (backward-char 4))
15679 (backward-char)
15680 (setq generic-pos (point-marker))
15681 (forward-sexp) (end-of-line)
15682 (delete-region generic-pos (point)) (delete-char 1)
15683 (insert "(\n")
15684 (when multi-list
15685 (insert "\n")
15686 (indent-to (* 2 vhdl-basic-offset))
15687 (insert "-- global generics\n"))
15688 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15689 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15690 ;; prepare port clause insertion
15691 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15692 (match-string 1))
15693 (goto-char (match-beginning 0))
15694 (indent-to vhdl-basic-offset)
15695 (insert "port ();\n\n")
15696 (backward-char 4))
15697 (backward-char)
15698 (setq port-in-pos (point-marker))
15699 (forward-sexp) (end-of-line)
15700 (delete-region port-in-pos (point)) (delete-char 1)
15701 (insert "(\n")
15702 (when (or multi-in-list multi-out-list)
15703 (insert "\n")
15704 (indent-to (* 2 vhdl-basic-offset))
15705 (insert "-- global ports\n"))
15706 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15707 port-out-pos (point-marker) port-inst-pos (point-marker)
15708 port-end-pos (point-marker))
15709 ;; insert generics, ports and signals
15710 (setq inst-alist (nreverse inst-alist))
15711 (while inst-alist
15712 (setq inst-name (nth 0 (car inst-alist))
15713 constant-alist (nth 1 (car inst-alist))
15714 signal-alist (nth 2 (car inst-alist))
15715 constant-temp-pos generic-inst-pos
15716 port-temp-pos port-inst-pos
15717 signal-temp-pos signal-pos)
15718 ;; generics
15719 (while constant-alist
15720 (setq constant-name (downcase (caar constant-alist))
15721 constant-entry (car constant-alist))
15722 (cond ((member constant-name written-list)
15723 nil)
15724 ((member constant-name multi-list)
15725 (vhdl-goto-marker generic-pos)
15726 (setq generic-end-pos
15727 (vhdl-max-marker
15728 generic-end-pos
15729 (vhdl-compose-insert-generic constant-entry)))
15730 (setq generic-pos (point-marker))
15731 (add-to-list 'written-list constant-name))
15732 (t
15733 (vhdl-goto-marker
15734 (vhdl-max-marker generic-inst-pos generic-pos))
15735 (setq generic-end-pos
15736 (vhdl-compose-insert-generic constant-entry))
15737 (setq generic-inst-pos (point-marker))
15738 (add-to-list 'written-list constant-name)))
15739 (setq constant-alist (cdr constant-alist)))
15740 (when (/= constant-temp-pos generic-inst-pos)
15741 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15742 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15743 (insert "-- generics for \"" inst-name "\"\n")
15744 (vhdl-goto-marker generic-inst-pos))
15745 ;; ports and signals
15746 (while signal-alist
15747 (setq signal-name (downcase (caar signal-alist))
15748 signal-entry (car signal-alist))
15749 (cond ((member signal-name written-list)
15750 nil)
15751 ((member signal-name multi-in-list)
15752 (vhdl-goto-marker port-in-pos)
15753 (setq port-end-pos
15754 (vhdl-max-marker
15755 port-end-pos (vhdl-compose-insert-port signal-entry)))
15756 (setq port-in-pos (point-marker))
15757 (add-to-list 'written-list signal-name))
15758 ((member signal-name multi-out-list)
15759 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15760 (setq port-end-pos
15761 (vhdl-max-marker
15762 port-end-pos (vhdl-compose-insert-port signal-entry)))
15763 (setq port-out-pos (point-marker))
15764 (add-to-list 'written-list signal-name))
15765 ((or (member signal-name single-in-list)
15766 (member signal-name single-out-list))
15767 (vhdl-goto-marker
15768 (vhdl-max-marker
15769 port-inst-pos
15770 (vhdl-max-marker port-out-pos port-in-pos)))
15771 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15772 (setq port-inst-pos (point-marker))
15773 (add-to-list 'written-list signal-name))
15774 ((equal (upcase (nth 2 signal-entry)) "OUT")
15775 (vhdl-goto-marker signal-pos)
15776 (vhdl-compose-insert-signal signal-entry)
15777 (setq signal-pos (point-marker))
15778 (add-to-list 'written-list signal-name)))
15779 (setq signal-alist (cdr signal-alist)))
15780 (when (/= port-temp-pos port-inst-pos)
15781 (vhdl-goto-marker
15782 (vhdl-max-marker port-temp-pos
15783 (vhdl-max-marker port-in-pos port-out-pos)))
15784 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15785 (insert "-- ports to \"" inst-name "\"\n")
15786 (vhdl-goto-marker port-inst-pos))
15787 (when (/= signal-temp-pos signal-pos)
15788 (vhdl-goto-marker signal-temp-pos)
15789 (insert "\n") (indent-to vhdl-basic-offset)
15790 (insert "-- outputs of \"" inst-name "\"\n")
15791 (vhdl-goto-marker signal-pos))
15792 (setq inst-alist (cdr inst-alist)))
15793 ;; finalize generic/port clause
15794 (vhdl-goto-marker generic-end-pos) (backward-char)
15795 (when (= generic-beg-pos generic-end-pos)
15796 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15797 (insert ";") (backward-char))
15798 (insert ")")
15799 (vhdl-goto-marker port-end-pos) (backward-char)
15800 (when (= port-beg-pos port-end-pos)
15801 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15802 (insert ";") (backward-char))
15803 (insert ")")
15804 ;; align everything
15805 (when vhdl-auto-align
15806 (vhdl-goto-marker generic-beg-pos)
15807 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15808 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15809 (vhdl-goto-marker signal-beg-pos)
15810 (vhdl-align-region-groups signal-beg-pos signal-pos))
15811 (switch-to-buffer (marker-buffer signal-beg-pos))
15812 (message "Wiring components...done")))))
15813
15814 (defun vhdl-compose-insert-generic (entry)
15815 "Insert ENTRY as generic declaration."
15816 (let (pos)
15817 (indent-to (* 2 vhdl-basic-offset))
15818 (insert (nth 0 entry) " : " (nth 1 entry))
15819 (when (nth 2 entry)
15820 (insert " := " (nth 2 entry)))
15821 (insert ";")
15822 (setq pos (point-marker))
15823 (when (and vhdl-include-port-comments (nth 3 entry))
15824 (vhdl-comment-insert-inline (nth 3 entry) t))
15825 (insert "\n")
15826 pos))
15827
15828 (defun vhdl-compose-insert-port (entry)
15829 "Insert ENTRY as port declaration."
15830 (let (pos)
15831 (indent-to (* 2 vhdl-basic-offset))
15832 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15833 (setq pos (point-marker))
15834 (when (and vhdl-include-port-comments (nth 4 entry))
15835 (vhdl-comment-insert-inline (nth 4 entry) t))
15836 (insert "\n")
15837 pos))
15838
15839 (defun vhdl-compose-insert-signal (entry)
15840 "Insert ENTRY as signal declaration."
15841 (indent-to vhdl-basic-offset)
15842 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15843 (when (and vhdl-include-port-comments (nth 4 entry))
15844 (vhdl-comment-insert-inline (nth 4 entry) t))
15845 (insert "\n"))
15846
15847 (defun vhdl-compose-components-package ()
15848 "Generate a package containing component declarations for all entities in the
15849 current project/directory."
15850 (interactive)
15851 (vhdl-require-hierarchy-info)
15852 (let* ((project (vhdl-project-p))
15853 (pack-name (vhdl-get-components-package-name))
15854 (pack-file-name
15855 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15856 "." (file-name-extension (buffer-file-name))))
15857 (ent-alist (aget vhdl-entity-alist
15858 (or project default-directory) t))
15859 (lazy-lock-minimum-size 0)
15860 clause-pos component-pos)
15861 (message "Generating components package \"%s\"..." pack-name)
15862 ;; open package file
15863 (when (and (file-exists-p pack-file-name)
15864 (not (y-or-n-p (concat "File \"" pack-file-name
15865 "\" exists; overwrite? "))))
15866 (error "ERROR: Generating components package...aborted"))
15867 (find-file pack-file-name)
15868 (erase-buffer)
15869 ;; insert header
15870 (if vhdl-compose-include-header
15871 (progn (vhdl-template-header
15872 (concat "Components package (generated by Emacs VHDL Mode "
15873 vhdl-version ")"))
15874 (goto-char (point-max)))
15875 (vhdl-comment-display-line) (insert "\n\n"))
15876 ;; insert std_logic_1164 package
15877 (vhdl-template-package-std-logic-1164)
15878 (insert "\n") (setq clause-pos (point-marker))
15879 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15880 ;; insert package declaration
15881 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15882 (vhdl-insert-keyword " IS\n\n")
15883 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15884 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15885 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15886 (indent-to vhdl-basic-offset)
15887 (setq component-pos (point-marker))
15888 (insert "\n\n") (vhdl-insert-keyword "END ")
15889 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15890 (insert pack-name ";\n\n")
15891 ;; insert footer
15892 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15893 (vhdl-template-footer)
15894 (vhdl-comment-display-line) (insert "\n"))
15895 ;; insert component declarations
15896 (while ent-alist
15897 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15898 (progn (goto-char (point-min))
15899 (forward-line (1- (nth 3 (car ent-alist))))
15900 (end-of-line)
15901 (vhdl-port-copy)))
15902 (goto-char component-pos)
15903 (vhdl-port-paste-component t)
15904 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15905 (setq component-pos (point-marker))
15906 (goto-char clause-pos)
15907 (vhdl-port-paste-context-clause pack-name)
15908 (setq clause-pos (point-marker))
15909 (setq ent-alist (cdr ent-alist)))
15910 (goto-char (point-min))
15911 (save-buffer)
15912 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15913 pack-name pack-file-name)))
15914
15915 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15916 &optional insert-conf)
15917 "Generate block configuration for architecture."
15918 (let ((margin (current-indentation))
15919 (beg (point-at-bol))
15920 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15921 ;; insert block configuration (for architecture)
15922 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15923 (setq margin (+ margin vhdl-basic-offset))
15924 ;; process all instances
15925 (while inst-alist
15926 (setq inst-entry (car inst-alist))
15927 ;; is component?
15928 (when (nth 4 inst-entry)
15929 (setq insert-conf t)
15930 (setq inst-path (nth 9 inst-entry))
15931 ;; skip common path with previous instance
15932 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15933 (setq inst-path (cdr inst-path)
15934 inst-prev-path (cdr inst-prev-path)))
15935 ;; insert block configuration end (for previous block/generate)
15936 (while inst-prev-path
15937 (setq margin (- margin vhdl-basic-offset))
15938 (indent-to margin)
15939 (vhdl-insert-keyword "END FOR;\n")
15940 (setq inst-prev-path (cdr inst-prev-path)))
15941 ;; insert block configuration beginning (for current block/generate)
15942 (indent-to margin)
15943 (while inst-path
15944 (setq margin (+ margin vhdl-basic-offset))
15945 (vhdl-insert-keyword "FOR ")
15946 (insert (car inst-path) "\n")
15947 (indent-to margin)
15948 (setq inst-path (cdr inst-path)))
15949 ;; insert component configuration beginning
15950 (vhdl-insert-keyword "FOR ")
15951 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15952 ;; find subconfiguration
15953 (setq conf-key (nth 7 inst-entry))
15954 (setq tmp-alist conf-alist)
15955 ;; use first configuration found for instance's entity
15956 (while (and tmp-alist (null conf-key))
15957 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15958 (setq conf-key (nth 0 (car tmp-alist))))
15959 (setq tmp-alist (cdr tmp-alist)))
15960 (setq conf-entry (aget conf-alist conf-key t))
15961 ;; insert binding indication ...
15962 ;; ... with subconfiguration (if exists)
15963 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15964 (progn
15965 (indent-to (+ margin vhdl-basic-offset))
15966 (vhdl-insert-keyword "USE CONFIGURATION ")
15967 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15968 (insert ";\n"))
15969 ;; ... with entity (if exists)
15970 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15971 (when ent-entry
15972 (indent-to (+ margin vhdl-basic-offset))
15973 (vhdl-insert-keyword "USE ENTITY ")
15974 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15975 ;; insert architecture name (if architecture exists)
15976 (when (nth 3 ent-entry)
15977 (setq arch-name
15978 ;; choose architecture name a) from configuration,
15979 ;; b) from mra, or c) from first architecture
15980 (or (nth 0 (aget (nth 3 ent-entry)
15981 (or (nth 6 inst-entry)
15982 (nth 4 ent-entry)) t))
15983 (nth 1 (car (nth 3 ent-entry)))))
15984 (insert "(" arch-name ")"))
15985 (insert ";\n")
15986 ;; insert block configuration (for architecture of subcomponent)
15987 (when (and vhdl-compose-configuration-hierarchical
15988 (nth 3 ent-entry))
15989 (indent-to (+ margin vhdl-basic-offset))
15990 (vhdl-compose-configuration-architecture
15991 (nth 0 ent-entry) arch-name
15992 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15993 ;; insert component configuration end
15994 (indent-to margin)
15995 (vhdl-insert-keyword "END FOR;\n")
15996 (setq inst-prev-path (nth 9 inst-entry)))
15997 (setq inst-alist (cdr inst-alist)))
15998 ;; insert block configuration end (for block/generate)
15999 (while inst-prev-path
16000 (setq margin (- margin vhdl-basic-offset))
16001 (indent-to margin)
16002 (vhdl-insert-keyword "END FOR;\n")
16003 (setq inst-prev-path (cdr inst-prev-path)))
16004 (indent-to (- margin vhdl-basic-offset))
16005 ;; insert block configuration end or remove beginning (for architecture)
16006 (if insert-conf
16007 (vhdl-insert-keyword "END FOR;\n")
16008 (delete-region beg (point)))))
16009
16010 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16011 "Generate configuration declaration."
16012 (interactive)
16013 (vhdl-require-hierarchy-info)
16014 (let ((ent-alist (aget vhdl-entity-alist
16015 (or (vhdl-project-p) default-directory) t))
16016 (conf-alist (aget vhdl-config-alist
16017 (or (vhdl-project-p) default-directory) t))
16018 (from-speedbar ent-name)
16019 inst-alist conf-name conf-file-name pos)
16020 (vhdl-prepare-search-2
16021 ;; get entity and architecture name
16022 (unless ent-name
16023 (save-excursion
16024 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16025 (not (equal "END" (upcase (match-string 1))))
16026 (setq ent-name (match-string-no-properties 3))
16027 (setq arch-name (match-string-no-properties 2)))
16028 (error "ERROR: Not within an architecture"))))
16029 (setq conf-name (vhdl-replace-string
16030 vhdl-compose-configuration-name
16031 (concat ent-name " " arch-name)))
16032 (setq inst-alist
16033 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16034 (downcase arch-name) t))))
16035 (message "Generating configuration \"%s\"..." conf-name)
16036 (if vhdl-compose-configuration-create-file
16037 ;; open configuration file
16038 (progn
16039 (setq conf-file-name
16040 (concat (vhdl-replace-string vhdl-configuration-file-name
16041 conf-name t)
16042 "." (file-name-extension (buffer-file-name))))
16043 (when (and (file-exists-p conf-file-name)
16044 (not (y-or-n-p (concat "File \"" conf-file-name
16045 "\" exists; overwrite? "))))
16046 (error "ERROR: Creating configuration...aborted"))
16047 (find-file conf-file-name)
16048 (erase-buffer)
16049 (set-buffer-modified-p nil)
16050 ;; insert header
16051 (if vhdl-compose-include-header
16052 (progn (vhdl-template-header
16053 (concat "Configuration declaration for design \""
16054 ent-name "(" arch-name ")\""))
16055 (goto-char (point-max)))
16056 (vhdl-comment-display-line) (insert "\n\n")))
16057 ;; goto end of architecture
16058 (unless from-speedbar
16059 (re-search-forward "^end\\>" nil)
16060 (end-of-line) (insert "\n\n")
16061 (vhdl-comment-display-line) (insert "\n\n")))
16062 ;; insert library clause
16063 (setq pos (point))
16064 (vhdl-template-standard-package (vhdl-work-library) nil)
16065 (when (/= pos (point))
16066 (insert "\n\n"))
16067 ;; insert configuration
16068 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16069 (vhdl-insert-keyword " OF ") (insert ent-name)
16070 (vhdl-insert-keyword " IS\n")
16071 (indent-to vhdl-basic-offset)
16072 ;; insert block configuration (for architecture)
16073 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16074 (vhdl-insert-keyword "END ") (insert conf-name ";")
16075 (when conf-file-name
16076 ;; insert footer and save
16077 (insert "\n\n")
16078 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16079 (vhdl-template-footer)
16080 (vhdl-comment-display-line) (insert "\n"))
16081 (save-buffer))
16082 (message "%s"
16083 (concat (format "Generating configuration \"%s\"...done" conf-name)
16084 (and conf-file-name
16085 (format "\n File created: \"%s\"" conf-file-name))))))
16086
16087
16088 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16089 ;;; Compilation / Makefile generation
16090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16091 ;; (using `compile.el')
16092
16093 (defun vhdl-makefile-name ()
16094 "Return the Makefile name of the current project or the current compiler if
16095 no project is defined."
16096 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16097 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16098 (vhdl-replace-string
16099 (cons "\\(.*\\)\n\\(.*\\)"
16100 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16101 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16102
16103 (defun vhdl-compile-directory ()
16104 "Return the directory where compilation/make should be run."
16105 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16106 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16107 (directory (vhdl-resolve-env-variable
16108 (if project
16109 (vhdl-replace-string
16110 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16111 (nth 6 compiler)))))
16112 (file-name-as-directory
16113 (if (file-name-absolute-p directory)
16114 directory
16115 (expand-file-name directory (vhdl-default-directory))))))
16116
16117 (defun vhdl-uniquify (in-list)
16118 "Remove duplicate elements from IN-LIST."
16119 (let (out-list)
16120 (while in-list
16121 (add-to-list 'out-list (car in-list))
16122 (setq in-list (cdr in-list)))
16123 out-list))
16124
16125 (defun vhdl-set-compiler (name)
16126 "Set current compiler to NAME."
16127 (interactive
16128 (list (let ((completion-ignore-case t))
16129 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16130 (if (assoc name vhdl-compiler-alist)
16131 (progn (setq vhdl-compiler name)
16132 (message "Current compiler: \"%s\"" vhdl-compiler))
16133 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16134
16135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16136 ;; Compilation
16137
16138 (defun vhdl-compile-init ()
16139 "Initialize for compilation."
16140 (when (or (null compilation-error-regexp-alist)
16141 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16142 compilation-error-regexp-alist)))
16143 ;; `compilation-error-regexp-alist'
16144 (let ((commands-alist vhdl-compiler-alist)
16145 regexp-alist sublist)
16146 (while commands-alist
16147 (setq sublist (nth 11 (car commands-alist)))
16148 (unless (or (equal "" (car sublist))
16149 (assoc (car sublist) regexp-alist))
16150 (setq regexp-alist (cons (list (nth 0 sublist)
16151 (if (= 0 (nth 1 sublist))
16152 (if (featurep 'xemacs) 9 nil)
16153 (nth 1 sublist))
16154 (nth 2 sublist) (nth 3 sublist))
16155 regexp-alist)))
16156 (setq commands-alist (cdr commands-alist)))
16157 (setq compilation-error-regexp-alist
16158 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16159 ;; `compilation-file-regexp-alist'
16160 (let ((commands-alist vhdl-compiler-alist)
16161 regexp-alist sublist)
16162 ;; matches vhdl-mode file name output
16163 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16164 (while commands-alist
16165 (setq sublist (nth 12 (car commands-alist)))
16166 (unless (or (equal "" (car sublist))
16167 (assoc (car sublist) regexp-alist))
16168 (setq regexp-alist (cons sublist regexp-alist)))
16169 (setq commands-alist (cdr commands-alist)))
16170 (setq compilation-file-regexp-alist
16171 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16172
16173 (defvar vhdl-compile-file-name nil
16174 "Name of file to be compiled.")
16175
16176 (defun vhdl-compile-print-file-name ()
16177 "Function called within `compile' to print out file name for compilers that
16178 do not print any file names."
16179 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16180
16181 (defun vhdl-get-compile-options (project compiler file-name
16182 &optional file-options-only)
16183 "Get compiler options. Returning nil means do not compile this file."
16184 (let* ((compiler-options (nth 1 compiler))
16185 (project-entry (aget (nth 4 project) vhdl-compiler))
16186 (project-options (nth 0 project-entry))
16187 (exception-list (and file-name (nth 2 project-entry)))
16188 (work-library (vhdl-work-library))
16189 (case-fold-search nil)
16190 file-options)
16191 (while (and exception-list
16192 (not (string-match (caar exception-list) file-name)))
16193 (setq exception-list (cdr exception-list)))
16194 (if (and exception-list (not (cdar exception-list)))
16195 nil
16196 (if (and file-options-only (not exception-list))
16197 'default
16198 (setq file-options (cdar exception-list))
16199 ;; insert library name in compiler-specific options
16200 (setq compiler-options
16201 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16202 work-library))
16203 ;; insert compiler-specific options in project-specific options
16204 (when project-options
16205 (setq project-options
16206 (vhdl-replace-string
16207 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16208 (concat work-library "\n" compiler-options))))
16209 ;; insert project-specific options in file-specific options
16210 (when file-options
16211 (setq file-options
16212 (vhdl-replace-string
16213 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16214 (concat work-library "\n" compiler-options "\n"
16215 project-options))))
16216 ;; return options
16217 (or file-options project-options compiler-options)))))
16218
16219 (defun vhdl-get-make-options (project compiler)
16220 "Get make options."
16221 (let* ((compiler-options (nth 3 compiler))
16222 (project-entry (aget (nth 4 project) vhdl-compiler))
16223 (project-options (nth 1 project-entry))
16224 (makefile-name (vhdl-makefile-name)))
16225 ;; insert Makefile name in compiler-specific options
16226 (setq compiler-options
16227 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16228 makefile-name))
16229 ;; insert compiler-specific options in project-specific options
16230 (when project-options
16231 (setq project-options
16232 (vhdl-replace-string
16233 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16234 (concat makefile-name "\n" compiler-options))))
16235 ;; return options
16236 (or project-options compiler-options)))
16237
16238 (defun vhdl-compile ()
16239 "Compile current buffer using the VHDL compiler specified in
16240 `vhdl-compiler'."
16241 (interactive)
16242 (vhdl-compile-init)
16243 (let* ((project (aget vhdl-project-alist vhdl-project))
16244 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16245 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16246 (command (nth 0 compiler))
16247 (file-name (buffer-file-name))
16248 (options (vhdl-get-compile-options project compiler file-name))
16249 (default-directory (vhdl-compile-directory))
16250 compilation-process-setup-function)
16251 (unless (file-directory-p default-directory)
16252 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16253 ;; put file name into quotes if it contains spaces
16254 (when (string-match " " file-name)
16255 (setq file-name (concat "\"" file-name "\"")))
16256 ;; print out file name if compiler does not
16257 (setq vhdl-compile-file-name (buffer-file-name))
16258 (when (and (= 0 (nth 1 (nth 10 compiler)))
16259 (= 0 (nth 1 (nth 11 compiler))))
16260 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16261 ;; run compilation
16262 (if options
16263 (when command
16264 (compile (concat command " " options " " file-name)))
16265 (vhdl-warning "Your project settings tell me not to compile this file"))))
16266
16267 (defvar vhdl-make-target "all"
16268 "Default target for `vhdl-make' command.")
16269
16270 (defun vhdl-make (&optional target)
16271 "Call make command for compilation of all updated source files (requires
16272 `Makefile'). Optional argument TARGET allows to compile the design
16273 specified by a target."
16274 (interactive)
16275 (setq vhdl-make-target
16276 (or target (read-from-minibuffer "Target: " vhdl-make-target
16277 vhdl-minibuffer-local-map)))
16278 (vhdl-compile-init)
16279 (let* ((project (aget vhdl-project-alist vhdl-project))
16280 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16281 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16282 (command (nth 2 compiler))
16283 (options (vhdl-get-make-options project compiler))
16284 (default-directory (vhdl-compile-directory)))
16285 (unless (file-directory-p default-directory)
16286 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16287 ;; run make
16288 (compile (concat (if (equal command "") "make" command)
16289 " " options " " vhdl-make-target))))
16290
16291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16292 ;; Makefile generation
16293
16294 (defun vhdl-generate-makefile ()
16295 "Generate `Makefile'."
16296 (interactive)
16297 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16298 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16299 (command (nth 4 compiler)))
16300 ;; generate makefile
16301 (if command
16302 (let ((default-directory (vhdl-compile-directory)))
16303 (compile (vhdl-replace-string
16304 (cons "\\(.*\\) \\(.*\\)" command)
16305 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16306 (vhdl-generate-makefile-1))))
16307
16308 (defun vhdl-get-packages (lib-alist work-library)
16309 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16310 (let (pack-list)
16311 (while lib-alist
16312 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16313 (setq pack-list (cons (cdar lib-alist) pack-list)))
16314 (setq lib-alist (cdr lib-alist)))
16315 pack-list))
16316
16317 (defun vhdl-generate-makefile-1 ()
16318 "Generate Makefile for current project or directory."
16319 ;; scan hierarchy if required
16320 (if (vhdl-project-p)
16321 (unless (or (assoc vhdl-project vhdl-file-alist)
16322 (vhdl-load-cache vhdl-project))
16323 (vhdl-scan-project-contents vhdl-project))
16324 (let ((directory (abbreviate-file-name default-directory)))
16325 (unless (or (assoc directory vhdl-file-alist)
16326 (vhdl-load-cache directory))
16327 (vhdl-scan-directory-contents directory))))
16328 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16329 (project (vhdl-project-p))
16330 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16331 (conf-alist (aget vhdl-config-alist (or project directory) t))
16332 (pack-alist (aget vhdl-package-alist (or project directory) t))
16333 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16334 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16335 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16336 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16337 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16338 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16339 (adjust-case (nth 5 regexp-list))
16340 (work-library (downcase (vhdl-work-library)))
16341 (compile-directory (expand-file-name (vhdl-compile-directory)
16342 default-directory))
16343 (makefile-name (vhdl-makefile-name))
16344 rule-alist arch-alist inst-alist
16345 target-list depend-list unit-list prim-list second-list subcomp-list
16346 lib-alist lib-body-alist pack-list all-pack-list
16347 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16348 conf-key conf-file-name pack-key pack-file-name
16349 ent-entry arch-entry conf-entry pack-entry inst-entry
16350 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16351 tmp-key tmp-list rule)
16352 ;; check prerequisites
16353 (unless (file-exists-p compile-directory)
16354 (make-directory compile-directory t))
16355 (unless regexp-list
16356 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16357 vhdl-compiler))
16358 (message "Generating makefile \"%s\"..." makefile-name)
16359 ;; rules for all entities
16360 (setq tmp-list ent-alist)
16361 (while ent-alist
16362 (setq ent-entry (car ent-alist)
16363 ent-key (nth 0 ent-entry))
16364 (when (nth 2 ent-entry)
16365 (setq ent-file-name (file-relative-name
16366 (nth 2 ent-entry) compile-directory)
16367 arch-alist (nth 4 ent-entry)
16368 lib-alist (nth 6 ent-entry)
16369 rule (aget rule-alist ent-file-name)
16370 target-list (nth 0 rule)
16371 depend-list (nth 1 rule)
16372 second-list nil
16373 subcomp-list nil)
16374 (setq tmp-key (vhdl-replace-string
16375 ent-regexp (funcall adjust-case ent-key)))
16376 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16377 ;; rule target for this entity
16378 (setq target-list (cons ent-key target-list))
16379 ;; rule dependencies for all used packages
16380 (setq pack-list (vhdl-get-packages lib-alist work-library))
16381 (setq depend-list (append depend-list pack-list))
16382 (setq all-pack-list pack-list)
16383 ;; add rule
16384 (aput 'rule-alist ent-file-name (list target-list depend-list))
16385 ;; rules for all corresponding architectures
16386 (while arch-alist
16387 (setq arch-entry (car arch-alist)
16388 arch-key (nth 0 arch-entry)
16389 ent-arch-key (concat ent-key "-" arch-key)
16390 arch-file-name (file-relative-name (nth 2 arch-entry)
16391 compile-directory)
16392 inst-alist (nth 4 arch-entry)
16393 lib-alist (nth 5 arch-entry)
16394 rule (aget rule-alist arch-file-name)
16395 target-list (nth 0 rule)
16396 depend-list (nth 1 rule))
16397 (setq tmp-key (vhdl-replace-string
16398 arch-regexp
16399 (funcall adjust-case (concat arch-key " " ent-key))))
16400 (setq unit-list
16401 (cons (cons ent-arch-key tmp-key) unit-list))
16402 (setq second-list (cons ent-arch-key second-list))
16403 ;; rule target for this architecture
16404 (setq target-list (cons ent-arch-key target-list))
16405 ;; rule dependency for corresponding entity
16406 (setq depend-list (cons ent-key depend-list))
16407 ;; rule dependencies for contained component instantiations
16408 (while inst-alist
16409 (setq inst-entry (car inst-alist))
16410 (when (or (null (nth 8 inst-entry))
16411 (equal (downcase (nth 8 inst-entry)) work-library))
16412 (setq inst-ent-key (or (nth 7 inst-entry)
16413 (nth 5 inst-entry)))
16414 (setq depend-list (cons inst-ent-key depend-list)
16415 subcomp-list (cons inst-ent-key subcomp-list)))
16416 (setq inst-alist (cdr inst-alist)))
16417 ;; rule dependencies for all used packages
16418 (setq pack-list (vhdl-get-packages lib-alist work-library))
16419 (setq depend-list (append depend-list pack-list))
16420 (setq all-pack-list (append all-pack-list pack-list))
16421 ;; add rule
16422 (aput 'rule-alist arch-file-name (list target-list depend-list))
16423 (setq arch-alist (cdr arch-alist)))
16424 (setq prim-list (cons (list ent-key second-list
16425 (append subcomp-list all-pack-list))
16426 prim-list)))
16427 (setq ent-alist (cdr ent-alist)))
16428 (setq ent-alist tmp-list)
16429 ;; rules for all configurations
16430 (setq tmp-list conf-alist)
16431 (while conf-alist
16432 (setq conf-entry (car conf-alist)
16433 conf-key (nth 0 conf-entry)
16434 conf-file-name (file-relative-name
16435 (nth 2 conf-entry) compile-directory)
16436 ent-key (nth 4 conf-entry)
16437 arch-key (nth 5 conf-entry)
16438 inst-alist (nth 6 conf-entry)
16439 lib-alist (nth 7 conf-entry)
16440 rule (aget rule-alist conf-file-name)
16441 target-list (nth 0 rule)
16442 depend-list (nth 1 rule)
16443 subcomp-list (list ent-key))
16444 (setq tmp-key (vhdl-replace-string
16445 conf-regexp (funcall adjust-case conf-key)))
16446 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16447 ;; rule target for this configuration
16448 (setq target-list (cons conf-key target-list))
16449 ;; rule dependency for corresponding entity and architecture
16450 (setq depend-list
16451 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16452 ;; rule dependencies for used packages
16453 (setq pack-list (vhdl-get-packages lib-alist work-library))
16454 (setq depend-list (append depend-list pack-list))
16455 ;; rule dependencies for contained component configurations
16456 (while inst-alist
16457 (setq inst-entry (car inst-alist))
16458 (setq inst-ent-key (nth 2 inst-entry)
16459 ; comp-arch-key (nth 2 inst-entry))
16460 inst-conf-key (nth 4 inst-entry))
16461 (when (equal (downcase (nth 5 inst-entry)) work-library)
16462 (when inst-ent-key
16463 (setq depend-list (cons inst-ent-key depend-list)
16464 subcomp-list (cons inst-ent-key subcomp-list)))
16465 ; (when comp-arch-key
16466 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16467 ; depend-list)))
16468 (when inst-conf-key
16469 (setq depend-list (cons inst-conf-key depend-list)
16470 subcomp-list (cons inst-conf-key subcomp-list))))
16471 (setq inst-alist (cdr inst-alist)))
16472 ;; add rule
16473 (aput 'rule-alist conf-file-name (list target-list depend-list))
16474 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16475 prim-list))
16476 (setq conf-alist (cdr conf-alist)))
16477 (setq conf-alist tmp-list)
16478 ;; rules for all packages
16479 (setq tmp-list pack-alist)
16480 (while pack-alist
16481 (setq pack-entry (car pack-alist)
16482 pack-key (nth 0 pack-entry)
16483 pack-body-key nil)
16484 (when (nth 2 pack-entry)
16485 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16486 compile-directory)
16487 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16488 rule (aget rule-alist pack-file-name)
16489 target-list (nth 0 rule) depend-list (nth 1 rule))
16490 (setq tmp-key (vhdl-replace-string
16491 pack-regexp (funcall adjust-case pack-key)))
16492 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16493 ;; rule target for this package
16494 (setq target-list (cons pack-key target-list))
16495 ;; rule dependencies for all used packages
16496 (setq pack-list (vhdl-get-packages lib-alist work-library))
16497 (setq depend-list (append depend-list pack-list))
16498 (setq all-pack-list pack-list)
16499 ;; add rule
16500 (aput 'rule-alist pack-file-name (list target-list depend-list))
16501 ;; rules for this package's body
16502 (when (nth 7 pack-entry)
16503 (setq pack-body-key (concat pack-key "-body")
16504 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16505 compile-directory)
16506 rule (aget rule-alist pack-body-file-name)
16507 target-list (nth 0 rule)
16508 depend-list (nth 1 rule))
16509 (setq tmp-key (vhdl-replace-string
16510 pack-body-regexp (funcall adjust-case pack-key)))
16511 (setq unit-list
16512 (cons (cons pack-body-key tmp-key) unit-list))
16513 ;; rule target for this package's body
16514 (setq target-list (cons pack-body-key target-list))
16515 ;; rule dependency for corresponding package declaration
16516 (setq depend-list (cons pack-key depend-list))
16517 ;; rule dependencies for all used packages
16518 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16519 (setq depend-list (append depend-list pack-list))
16520 (setq all-pack-list (append all-pack-list pack-list))
16521 ;; add rule
16522 (aput 'rule-alist pack-body-file-name
16523 (list target-list depend-list)))
16524 (setq prim-list
16525 (cons (list pack-key (when pack-body-key (list pack-body-key))
16526 all-pack-list)
16527 prim-list)))
16528 (setq pack-alist (cdr pack-alist)))
16529 (setq pack-alist tmp-list)
16530 ;; generate Makefile
16531 (let* ((project (aget vhdl-project-alist project))
16532 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16533 (compiler-id (nth 9 compiler))
16534 (library-directory
16535 (vhdl-resolve-env-variable
16536 (vhdl-replace-string
16537 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16538 compiler-id)))
16539 (makefile-path-name (expand-file-name
16540 makefile-name compile-directory))
16541 (orig-buffer (current-buffer))
16542 cell second-list subcomp-list options unit-key unit-name)
16543 ;; sort lists
16544 (setq unit-list (vhdl-sort-alist unit-list))
16545 (setq prim-list (vhdl-sort-alist prim-list))
16546 (setq tmp-list rule-alist)
16547 (while tmp-list ; pre-sort rule targets
16548 (setq cell (cdar tmp-list))
16549 (setcar cell (sort (car cell) 'string<))
16550 (setq tmp-list (cdr tmp-list)))
16551 (setq rule-alist ; sort by first rule target
16552 (sort rule-alist
16553 (function (lambda (a b)
16554 (string< (car (cadr a)) (car (cadr b)))))))
16555 ;; open and clear Makefile
16556 (set-buffer (find-file-noselect makefile-path-name t t))
16557 (erase-buffer)
16558 (insert "# -*- Makefile -*-\n"
16559 "### " (file-name-nondirectory makefile-name)
16560 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16561 "\n")
16562 (if project
16563 (insert "\n# Project : " (nth 0 project))
16564 (insert "\n# Directory : \"" directory "\""))
16565 (insert "\n# Platform : " vhdl-compiler
16566 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16567 (user-login-name) "\n")
16568 ;; insert compile and option variable settings
16569 (insert "\n\n# Define compilation command and options\n"
16570 "\nCOMPILE = " (nth 0 compiler)
16571 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16572 "\n")
16573 ;; insert library paths
16574 (setq library-directory
16575 (directory-file-name
16576 (if (file-name-absolute-p library-directory)
16577 library-directory
16578 (file-relative-name
16579 (expand-file-name library-directory directory)
16580 compile-directory))))
16581 (insert "\n\n# Define library paths\n"
16582 "\nLIBRARY-" work-library " = " library-directory "\n")
16583 ;; insert variable definitions for all library unit files
16584 (insert "\n\n# Define library unit files\n")
16585 (setq tmp-list unit-list)
16586 (while unit-list
16587 (insert "\nUNIT-" work-library "-" (caar unit-list)
16588 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16589 (setq unit-list (cdr unit-list)))
16590 ;; insert variable definition for list of all library unit files
16591 (insert "\n\n\n# Define list of all library unit files\n"
16592 "\nALL_UNITS =")
16593 (setq unit-list tmp-list)
16594 (while unit-list
16595 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16596 (setq unit-list (cdr unit-list)))
16597 (insert "\n")
16598 (setq unit-list tmp-list)
16599 ;; insert `make all' rule
16600 (insert "\n\n\n# Rule for compiling entire design\n"
16601 "\nall :"
16602 " \\\n\t\tlibrary"
16603 " \\\n\t\t$(ALL_UNITS)\n")
16604 ;; insert `make clean' rule
16605 (insert "\n\n# Rule for cleaning entire design\n"
16606 "\nclean : "
16607 "\n\t-rm -f $(ALL_UNITS)\n")
16608 ;; insert `make library' rule
16609 (insert "\n\n# Rule for creating library directory\n"
16610 "\nlibrary :"
16611 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16612 "\n$(LIBRARY-" work-library ") :"
16613 "\n\t"
16614 (vhdl-replace-string
16615 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16616 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16617 "\n")
16618 ;; insert rule for each library unit
16619 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16620 (while prim-list
16621 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16622 (setq subcomp-list
16623 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16624 (setq unit-key (caar prim-list)
16625 unit-name (or (nth 0 (aget ent-alist unit-key t))
16626 (nth 0 (aget conf-alist unit-key t))
16627 (nth 0 (aget pack-alist unit-key t))))
16628 (insert "\n" unit-key)
16629 (unless (equal unit-key unit-name)
16630 (insert " \\\n" unit-name))
16631 (insert " :"
16632 " \\\n\t\tlibrary"
16633 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16634 (while second-list
16635 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16636 (setq second-list (cdr second-list)))
16637 (while subcomp-list
16638 (when (and (assoc (car subcomp-list) unit-list)
16639 (not (equal unit-key (car subcomp-list))))
16640 (insert " \\\n\t\t" (car subcomp-list)))
16641 (setq subcomp-list (cdr subcomp-list)))
16642 (insert "\n")
16643 (setq prim-list (cdr prim-list)))
16644 ;; insert rule for each library unit file
16645 (insert "\n\n# Rules for compiling single library unit files\n")
16646 (while rule-alist
16647 (setq rule (car rule-alist))
16648 ;; get compiler options for this file
16649 (setq options
16650 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16651 ;; insert rule if file is supposed to be compiled
16652 (setq target-list (nth 1 rule)
16653 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16654 ;; insert targets
16655 (setq tmp-list target-list)
16656 (while target-list
16657 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16658 (if (cdr target-list) " \\" " :"))
16659 (setq target-list (cdr target-list)))
16660 (setq target-list tmp-list)
16661 ;; insert file name as first dependency
16662 (insert " \\\n\t\t" (nth 0 rule))
16663 ;; insert dependencies (except if also target or unit does not exist)
16664 (while depend-list
16665 (when (and (not (member (car depend-list) target-list))
16666 (assoc (car depend-list) unit-list))
16667 (insert " \\\n\t\t"
16668 "$(UNIT-" work-library "-" (car depend-list) ")"))
16669 (setq depend-list (cdr depend-list)))
16670 ;; insert compile command
16671 (if options
16672 (insert "\n\t$(COMPILE) "
16673 (if (eq options 'default) "$(OPTIONS)" options) " "
16674 (nth 0 rule) "\n")
16675 (setq tmp-list target-list)
16676 (while target-list
16677 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16678 (if (cdr target-list) " \\" "\n"))
16679 (setq target-list (cdr target-list)))
16680 (setq target-list tmp-list))
16681 (setq rule-alist (cdr rule-alist)))
16682 (insert "\n\n### " makefile-name " ends here\n")
16683 ;; run Makefile generation hook
16684 (run-hooks 'vhdl-makefile-generation-hook)
16685 (message "Generating makefile \"%s\"...done" makefile-name)
16686 ;; save and close file
16687 (if (file-writable-p makefile-path-name)
16688 (progn (save-buffer)
16689 (kill-buffer (current-buffer))
16690 (set-buffer orig-buffer)
16691 (add-to-history 'file-name-history makefile-path-name))
16692 (vhdl-warning-when-idle
16693 (format "File not writable: \"%s\""
16694 (abbreviate-file-name makefile-path-name)))
16695 (switch-to-buffer (current-buffer))))))
16696
16697
16698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16699 ;;; Bug reports
16700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16701 ;; (using `reporter.el')
16702
16703 (defconst vhdl-mode-help-address
16704 "Reto Zimmermann <reto@gnu.org>"
16705 "Address for VHDL Mode bug reports.")
16706
16707 (defun vhdl-submit-bug-report ()
16708 "Submit via mail a bug report on VHDL Mode."
16709 (interactive)
16710 ;; load in reporter
16711 (and
16712 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16713 (let ((reporter-prompt-for-summary-p t))
16714 (reporter-submit-bug-report
16715 vhdl-mode-help-address
16716 (concat "VHDL Mode " vhdl-version)
16717 (list
16718 ;; report all important user options
16719 'vhdl-offsets-alist
16720 'vhdl-comment-only-line-offset
16721 'tab-width
16722 'vhdl-electric-mode
16723 'vhdl-stutter-mode
16724 'vhdl-indent-tabs-mode
16725 'vhdl-project-alist
16726 'vhdl-project
16727 'vhdl-project-file-name
16728 'vhdl-project-auto-load
16729 'vhdl-project-sort
16730 'vhdl-compiler-alist
16731 'vhdl-compiler
16732 'vhdl-compile-use-local-error-regexp
16733 'vhdl-makefile-generation-hook
16734 'vhdl-default-library
16735 'vhdl-standard
16736 'vhdl-basic-offset
16737 'vhdl-upper-case-keywords
16738 'vhdl-upper-case-types
16739 'vhdl-upper-case-attributes
16740 'vhdl-upper-case-enum-values
16741 'vhdl-upper-case-constants
16742 'vhdl-use-direct-instantiation
16743 'vhdl-compose-configuration-name
16744 'vhdl-entity-file-name
16745 'vhdl-architecture-file-name
16746 'vhdl-configuration-file-name
16747 'vhdl-package-file-name
16748 'vhdl-file-name-case
16749 'vhdl-electric-keywords
16750 'vhdl-optional-labels
16751 'vhdl-insert-empty-lines
16752 'vhdl-argument-list-indent
16753 'vhdl-association-list-with-formals
16754 'vhdl-conditions-in-parenthesis
16755 'vhdl-zero-string
16756 'vhdl-one-string
16757 'vhdl-file-header
16758 'vhdl-file-footer
16759 'vhdl-company-name
16760 'vhdl-copyright-string
16761 'vhdl-platform-spec
16762 'vhdl-date-format
16763 'vhdl-modify-date-prefix-string
16764 'vhdl-modify-date-on-saving
16765 'vhdl-reset-kind
16766 'vhdl-reset-active-high
16767 'vhdl-clock-rising-edge
16768 'vhdl-clock-edge-condition
16769 'vhdl-clock-name
16770 'vhdl-reset-name
16771 'vhdl-model-alist
16772 'vhdl-include-port-comments
16773 'vhdl-include-direction-comments
16774 'vhdl-include-type-comments
16775 'vhdl-include-group-comments
16776 'vhdl-actual-port-name
16777 'vhdl-instance-name
16778 'vhdl-testbench-entity-name
16779 'vhdl-testbench-architecture-name
16780 'vhdl-testbench-configuration-name
16781 'vhdl-testbench-dut-name
16782 'vhdl-testbench-include-header
16783 'vhdl-testbench-declarations
16784 'vhdl-testbench-statements
16785 'vhdl-testbench-initialize-signals
16786 'vhdl-testbench-include-library
16787 'vhdl-testbench-include-configuration
16788 'vhdl-testbench-create-files
16789 'vhdl-testbench-entity-file-name
16790 'vhdl-testbench-architecture-file-name
16791 'vhdl-compose-create-files
16792 'vhdl-compose-configuration-create-file
16793 'vhdl-compose-configuration-hierarchical
16794 'vhdl-compose-configuration-use-subconfiguration
16795 'vhdl-compose-include-header
16796 'vhdl-compose-architecture-name
16797 'vhdl-components-package-name
16798 'vhdl-use-components-package
16799 'vhdl-self-insert-comments
16800 'vhdl-prompt-for-comments
16801 'vhdl-inline-comment-column
16802 'vhdl-end-comment-column
16803 'vhdl-auto-align
16804 'vhdl-align-groups
16805 'vhdl-align-group-separate
16806 'vhdl-align-same-indent
16807 'vhdl-highlight-keywords
16808 'vhdl-highlight-names
16809 'vhdl-highlight-special-words
16810 'vhdl-highlight-forbidden-words
16811 'vhdl-highlight-verilog-keywords
16812 'vhdl-highlight-translate-off
16813 'vhdl-highlight-case-sensitive
16814 'vhdl-special-syntax-alist
16815 'vhdl-forbidden-words
16816 'vhdl-forbidden-syntax
16817 'vhdl-directive-keywords
16818 'vhdl-speedbar-auto-open
16819 'vhdl-speedbar-display-mode
16820 'vhdl-speedbar-scan-limit
16821 'vhdl-speedbar-jump-to-unit
16822 'vhdl-speedbar-update-on-saving
16823 'vhdl-speedbar-save-cache
16824 'vhdl-speedbar-cache-file-name
16825 'vhdl-index-menu
16826 'vhdl-source-file-menu
16827 'vhdl-hideshow-menu
16828 'vhdl-hide-all-init
16829 'vhdl-print-two-column
16830 'vhdl-print-customize-faces
16831 'vhdl-intelligent-tab
16832 'vhdl-indent-syntax-based
16833 'vhdl-word-completion-case-sensitive
16834 'vhdl-word-completion-in-minibuffer
16835 'vhdl-underscore-is-part-of-word
16836 'vhdl-mode-hook)
16837 (function
16838 (lambda ()
16839 (insert
16840 (if vhdl-special-indent-hook
16841 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16842 "vhdl-special-indent-hook is set to '"
16843 (format "%s" vhdl-special-indent-hook)
16844 ".\nPerhaps this is your problem?\n"
16845 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16846 "\n"))))
16847 nil
16848 "Hi Reto,"))))
16849
16850
16851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16852 ;;; Documentation
16853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16854
16855 (defconst vhdl-doc-release-notes nil
16856 "\
16857 Release Notes for VHDL Mode 3.33
16858 ================================
16859
16860 - New Features
16861 - User Options
16862
16863
16864 New Features
16865 ------------
16866
16867 CONFIGURATION DECLARATION GENERATION:
16868 - Automatic generation of a configuration declaration for a design.
16869 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16870
16871
16872 User Options
16873 ------------
16874
16875 `vhdl-configuration-file-name': (new)
16876 Specify how the configuration file name is obtained.
16877 `vhdl-compose-configuration-name': (new)
16878 Specify how the configuration name is optained.
16879 `vhdl-compose-configuration-create-file': (new)
16880 Specify whether a new file should be created for a configuration.
16881 `vhdl-compose-configuration-hierarchical': (new)
16882 Specify whether hierarchical configurations should be created.
16883 `vhdl-compose-configuration-use-subconfiguration': (new)
16884 Specify whether subconfigurations should be used inside configurations.
16885 ")
16886
16887
16888 (defconst vhdl-doc-keywords nil
16889 "\
16890 Reserved words in VHDL
16891 ----------------------
16892
16893 VHDL'93 (IEEE Std 1076-1993):
16894 `vhdl-93-keywords' : keywords
16895 `vhdl-93-types' : standardized types
16896 `vhdl-93-attributes' : standardized attributes
16897 `vhdl-93-enum-values' : standardized enumeration values
16898 `vhdl-93-functions' : standardized functions
16899 `vhdl-93-packages' : standardized packages and libraries
16900
16901 VHDL-AMS (IEEE Std 1076.1):
16902 `vhdl-ams-keywords' : keywords
16903 `vhdl-ams-types' : standardized types
16904 `vhdl-ams-attributes' : standardized attributes
16905 `vhdl-ams-enum-values' : standardized enumeration values
16906 `vhdl-ams-functions' : standardized functions
16907
16908 Math Packages (IEEE Std 1076.2):
16909 `vhdl-math-types' : standardized types
16910 `vhdl-math-constants' : standardized constants
16911 `vhdl-math-functions' : standardized functions
16912 `vhdl-math-packages' : standardized packages
16913
16914 Forbidden words:
16915 `vhdl-verilog-keywords' : Verilog reserved words
16916
16917 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16918
16919
16920 (defconst vhdl-doc-coding-style nil
16921 "\
16922 For VHDL coding style and naming convention guidelines, see the following
16923 references:
16924
16925 \[1] Ben Cohen.
16926 \"VHDL Coding Styles and Methodologies\".
16927 Kluwer Academic Publishers, 1999.
16928 http://members.aol.com/vhdlcohen/vhdl/
16929
16930 \[2] Michael Keating and Pierre Bricaud.
16931 \"Reuse Methodology Manual, Second Edition\".
16932 Kluwer Academic Publishers, 1999.
16933 http://www.openmore.com/openmore/rmm2.html
16934
16935 \[3] European Space Agency.
16936 \"VHDL Modelling Guidelines\".
16937 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16938
16939 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16940 to visually support naming conventions.")
16941
16942
16943 (defun vhdl-version ()
16944 "Echo the current version of VHDL Mode in the minibuffer."
16945 (interactive)
16946 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16947 (vhdl-keep-region-active))
16948
16949 (defun vhdl-doc-variable (variable)
16950 "Display VARIABLE's documentation in *Help* buffer."
16951 (interactive)
16952 (unless (featurep 'xemacs)
16953 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16954 (with-output-to-temp-buffer
16955 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16956 (princ (documentation-property variable 'variable-documentation))
16957 (with-current-buffer standard-output
16958 (help-mode))
16959 (help-print-return-message)))
16960
16961 (defun vhdl-doc-mode ()
16962 "Display VHDL Mode documentation in *Help* buffer."
16963 (interactive)
16964 (unless (featurep 'xemacs)
16965 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16966 (with-output-to-temp-buffer
16967 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16968 (princ mode-name)
16969 (princ " mode:\n")
16970 (princ (documentation 'vhdl-mode))
16971 (with-current-buffer standard-output
16972 (help-mode))
16973 (help-print-return-message)))
16974
16975
16976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16977
16978 (provide 'vhdl-mode)
16979
16980 ;;; vhdl-mode.el ends here