]> code.delx.au - gnu-emacs/blob - lisp/progmodes/vhdl-mode.el
(grep-mode-font-lock-keywords): Use the font-lock-face property to
[gnu-emacs] / lisp / progmodes / vhdl-mode.el
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
2
3 ;; Copyright (C) 1992-2003, 2005 Free Software Foundation, Inc.
4
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vhdl
9 ;; WWW: http://opensource.ethz.ch/emacs/vhdl-mode.html
10
11 (defconst vhdl-version "3.32.12"
12 "VHDL Mode version number.")
13
14 (defconst vhdl-time-stamp "2003-02-28"
15 "VHDL Mode time stamp for last update.")
16
17 ;; This file is part of GNU Emacs.
18
19 ;; GNU Emacs is free software; you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation; either version 2, or (at your option)
22 ;; any later version.
23
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
28
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs; see the file COPYING. If not, write to the
31 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
32 ;; Boston, MA 02111-1307, USA.
33
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;;; Commentary:
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37
38 ;; This package provides an Emacs major mode for editing VHDL code.
39 ;; It includes the following features:
40
41 ;; - Syntax highlighting
42 ;; - Indentation
43 ;; - Template insertion (electrification)
44 ;; - Insertion of file headers
45 ;; - Insertion of user-specified models
46 ;; - Port translation / testbench generation
47 ;; - Sensitivity list updating
48 ;; - File browser
49 ;; - Design hierarchy browser
50 ;; - Source file compilation (syntax analysis)
51 ;; - Makefile generation
52 ;; - Code hiding
53 ;; - Word/keyword completion
54 ;; - Block commenting
55 ;; - Code fixing/alignment/beautification
56 ;; - Postscript printing
57 ;; - VHDL'87/'93 and VHDL-AMS supported
58 ;; - Comprehensive menu
59 ;; - Fully customizable
60 ;; - Works under GNU Emacs (recommended) and XEmacs
61
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 ;; Documentation
64
65 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
66
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Emacs Versions
69
70 ;; supported: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
71 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
72
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 ;; Installation
75
76 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X.
77
78 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
79 ;; or into an arbitrary directory that is added to the load path by the
80 ;; following line in your Emacs start-up file `.emacs':
81
82 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
83
84 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
85 ;; directory. Otherwise, byte-compile the source file:
86 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
87 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
88
89 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
90 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
91 ;; (not required in Emacs 20.X):
92
93 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
94 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
95
96 ;; More detailed installation instructions are included in the official
97 ;; VHDL Mode distribution.
98
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 ;; Acknowledgements
101
102 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
103 ;; and Steve Grout.
104
105 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
106 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
107
108 ;; Many thanks to all the users who sent me bug reports and enhancement
109 ;; requests.
110 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
111 ;; enhancement suggestions and the fruitful discussions.
112 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
113 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
114
115 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
116 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
117 ;; giving me the opportunity to develop this code.
118 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
119 ;; of the Swiss Government.
120
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122
123 ;;; Code:
124
125 ;; XEmacs handling
126 (defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
127 "Non-nil if XEmacs is used.")
128 ;; Emacs 21 handling
129 (defconst vhdl-emacs-21 (and (= emacs-major-version 21) (not vhdl-xemacs))
130 "Non-nil if GNU Emacs 21 is used.")
131
132
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134 ;;; Variables
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136
137 ;; help function for user options
138 (defun vhdl-custom-set (variable value &rest functions)
139 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
140 (if (fboundp 'custom-set-default)
141 (custom-set-default variable value)
142 (set-default variable value))
143 (while functions
144 (when (fboundp (car functions)) (funcall (car functions)))
145 (setq functions (cdr functions))))
146
147 (defun vhdl-widget-directory-validate (widget)
148 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
149 '/' or is empty)."
150 (let ((val (widget-value widget)))
151 (unless (string-match "^\\(\\|.*/\\)$" val)
152 (widget-put widget :error "Invalid directory entry: must end with '/'")
153 widget)))
154
155 ;; help string for user options
156 (defconst vhdl-name-doc-string "
157
158 FROM REGEXP is a regular expression matching the original name:
159 \".*\" matches the entire string
160 \"\\(...\\)\" matches a substring
161 TO STRING specifies the string to be inserted as new name:
162 \"\\&\" means substitute entire matched text
163 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
164 Examples:
165 \".*\" \"\\&\" inserts original string
166 \".*\" \"\\&_i\" attaches \"_i\" to original string
167 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
168 \".*\" \"foo\" inserts constant string \"foo\"
169 \".*\" \"\" inserts empty string")
170
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 ;; User variables
173
174 (defgroup vhdl nil
175 "Customizations for VHDL Mode."
176 :prefix "vhdl-"
177 :group 'languages
178 ; :version "20.4" ; comment out for XEmacs
179 )
180
181 (defgroup vhdl-mode nil
182 "Customizations for modes."
183 :group 'vhdl)
184
185 (defcustom vhdl-electric-mode t
186 "*Non-nil enables electrification (automatic template generation).
187 If nil, template generators can still be invoked through key bindings and
188 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
189 toggled by `\\[vhdl-electric-mode]'."
190 :type 'boolean
191 :group 'vhdl-mode)
192
193 (defcustom vhdl-stutter-mode t
194 "*Non-nil enables stuttering.
195 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
196 by `\\[vhdl-stutter-mode]'."
197 :type 'boolean
198 :group 'vhdl-mode)
199
200 (defcustom vhdl-indent-tabs-mode nil
201 "*Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
205
206
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
210
211 (defcustom vhdl-compiler-alist
212 '(
213 ;; Cadence Leapfrog: cv -file test.vhd
214 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
215 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
216 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
217 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
218 ("\\1/entity" "\\2/\\1" "\\1/configuration"
219 "\\1/package" "\\1/body" downcase))
220 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
221 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
222 ;; (PLL_400X_TOP) is not declared [10.3].
223 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
224 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
225 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
226 nil)
227 ;; Ikos Voyager: analyze test.vhd
228 ;; analyze test.vhd
229 ;; E L4/C5: this library unit is inaccessible
230 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
231 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
232 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
233 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
234 nil)
235 ;; ModelSim, Model Technology: vcom test.vhd
236 ;; ERROR: test.vhd(14): Unknown identifier: positiv
237 ;; WARNING[2]: test.vhd(85): Possible infinite loop
238 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
239 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
240 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
241 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
242 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
243 "\\1/_primary.dat" "\\1/body.dat" downcase))
244 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
245 ;; test.vhd:34: error message
246 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
247 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
248 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
249 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
250 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
251 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
252 ;; ERROR: test.vhd(24): near "dnd": expecting: END
253 ;; WARNING[4]: test.vhd(30): A space is required between ...
254 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
255 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
256 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
257 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
258 "\\1/_primary.dat" "\\1/body.dat" downcase))
259 ;; Savant: scram -publish-cc test.vhd
260 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
261 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
262 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
263 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
264 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
265 "\\1_config.vhdl" "\\1_package.vhdl"
266 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
267 ;; Simili: vhdlp -work test.vhd
268 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
269 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
270 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
271 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
272 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
273 "\\1/prim.var" "\\1/_body.var" downcase))
274 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
275 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
276 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
277 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
278 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
279 nil)
280 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
281 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
282 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
283 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
284 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
285 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
286 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
287 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
288 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
289 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
290 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
291 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
292 ;; Synplify:
293 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
294 ("Synplify" "n/a" "n/a" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
296 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
297 nil)
298 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
299 ;; Compiling "test.vhd" line 1...
300 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
301 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
303 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
304 ("^ *Compiling \"\\(.+\\)\" " 1)
305 nil)
306 ;; VeriBest: vc vhdl test.vhd
307 ;; (no file name printed out!)
308 ;; 32: Z <= A and BitA ;
309 ;; ^^^^
310 ;; [Error] Name BITA is unknown
311 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
312 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
313 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
314 nil)
315 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
316 ;; Compiling "test.vhd" line 1...
317 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
318 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
319 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
320 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
321 ("^ *Compiling \"\\(.+\\)\" " 1)
322 nil)
323 )
324 "*List of available VHDL compilers and their properties.
325 Each list entry specifies the following items for a compiler:
326 Compiler:
327 Compiler name : name used in option `vhdl-compiler' to choose compiler
328 Compile command : command used for source file compilation
329 Compile options : compile options (\"\\1\" inserts library name)
330 Make command : command used for compilation using a Makefile
331 Make options : make options (\"\\1\" inserts Makefile name)
332 Generate Makefile: use built-in function or command to generate a Makefile
333 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
334 Library command : command to create library directory \(\"\\1\" inserts
335 library directory, \"\\2\" inserts library name)
336 Compile directory: where compilation is run and the Makefile is placed
337 Library directory: directory of default library
338 Makefile name : name of Makefile (default is \"Makefile\")
339 ID string : compiler identification string (see `vhdl-project-alist')
340 Error message:
341 Regexp : regular expression to match error messages
342 File subexp index: index of subexpression that matches the file name
343 Line subexp index: index of subexpression that matches the line number
344 Column subexp idx: index of subexpression that matches the column number
345 File message:
346 Regexp : regular expression to match a file name message
347 File subexp index: index of subexpression that matches the file name
348 Unit-to-file name mapping: mapping of library unit names to names of files
349 generated by the compiler (used for Makefile generation)
350 To string : string a name is mapped to (\"\\1\" inserts the unit name,
351 \"\\2\" inserts the entity name for architectures)
352 Case adjustment : adjust case of inserted unit names
353
354 Compile options allows insertion of the library name (see `vhdl-project-alist')
355 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
356
357 For Makefile generation, the built-in function can be used (requires
358 specification of the unit-to-file name mapping). Alternatively, an
359 external command can be specified. Work directory allows specification of
360 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
361 used for Makefile generation). To use another library name than \"work\",
362 customize `vhdl-project-alist'. The library command is inserted in Makefiles
363 to automatically create the library directory if not existent.
364
365 Compile options, compile directory, library directory, and Makefile name are
366 overwritten by the project settings if a project is defined (see
367 `vhdl-project-alist'). Directory paths are relative to the source file
368 directory.
369
370 Some compilers do not include the file name in the error message, but print
371 out a file name message in advance. In this case, set \"File Subexp Index\"
372 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
373 If no file name at all is printed out, set both \"File Message\" entries to 0
374 \(a default file name message will be printed out instead, does not work in
375 XEmacs).
376
377 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
378 assigning its name to option `vhdl-compiler'.
379
380 Please send any missing or erroneous compiler properties to the maintainer for
381 updating.
382
383 NOTE: Reflect the new setting in the choice list of option `vhdl-compiler'
384 by restarting Emacs."
385 :type '(repeat
386 (list :tag "Compiler" :indent 2
387 (string :tag "Compiler name ")
388 (string :tag "Compile command ")
389 (string :tag "Compile options " "-work \\1")
390 (string :tag "Make command " "make")
391 (string :tag "Make options " "-f \\1")
392 (choice :tag "Generate Makefile "
393 (const :tag "Built-in function" nil)
394 (string :tag "Command" "vmake \\2 > \\1"))
395 (string :tag "Library command " "mkdir \\1")
396 (directory :tag "Compile directory "
397 :validate vhdl-widget-directory-validate "./")
398 (directory :tag "Library directory "
399 :validate vhdl-widget-directory-validate "work/")
400 (file :tag "Makefile name " "Makefile")
401 (string :tag "ID string ")
402 (list :tag "Error message" :indent 4
403 (regexp :tag "Regexp ")
404 (integer :tag "File subexp index")
405 (integer :tag "Line subexp index")
406 (integer :tag "Column subexp idx"))
407 (list :tag "File message" :indent 4
408 (regexp :tag "Regexp ")
409 (integer :tag "File subexp index"))
410 (choice :tag "Unit-to-file name mapping"
411 :format "%t: %[Value Menu%] %v\n"
412 (const :tag "Not defined" nil)
413 (list :tag "To string" :indent 4
414 (string :tag "Entity " "\\1.vhd")
415 (string :tag "Architecture " "\\2_\\1.vhd")
416 (string :tag "Configuration " "\\1.vhd")
417 (string :tag "Package " "\\1.vhd")
418 (string :tag "Package Body " "\\1_body.vhd")
419 (choice :tag "Case adjustment "
420 (const :tag "None" identity)
421 (const :tag "Upcase" upcase)
422 (const :tag "Downcase" downcase))))))
423 :set (lambda (variable value)
424 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
425 :group 'vhdl-compile)
426
427 (defcustom vhdl-compiler "ModelSim"
428 "*Specifies the VHDL compiler to be used for syntax analysis.
429 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
430 :type (let ((alist vhdl-compiler-alist) list)
431 (while alist
432 (setq list (cons (list 'const (caar alist)) list))
433 (setq alist (cdr alist)))
434 (append '(choice) (nreverse list)))
435 :group 'vhdl-compile)
436
437 (defcustom vhdl-compile-use-local-error-regexp t
438 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
439 In this case, only error message regexps for VHDL compilers are active if
440 compilation is started from a VHDL buffer. Otherwise, the error message
441 regexps are appended to the predefined global regexps, and all regexps are
442 active all the time. Note that by doing that, the predefined global regexps
443 might result in erroneous parsing of error messages for some VHDL compilers.
444
445 NOTE: Activate the new setting by restarting Emacs."
446 :type 'boolean
447 :group 'vhdl-compile)
448
449 (defcustom vhdl-makefile-generation-hook nil
450 "*Functions to run at the end of Makefile generation.
451 Allows to insert user specific parts into a Makefile.
452
453 Example:
454 \(lambda nil
455 \(re-search-backward \"^# Rule for compiling entire design\")
456 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
457 :type 'hook
458 :group 'vhdl-compile)
459
460 (defcustom vhdl-default-library "work"
461 "*Name of default library.
462 Is overwritten by project settings if a project is active."
463 :type 'string
464 :group 'vhdl-compile)
465
466
467 (defgroup vhdl-project nil
468 "Customizations for projects."
469 :group 'vhdl)
470
471 (defcustom vhdl-project-alist
472 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
473 "~/example1/" ("src/system/" "src/components/") ""
474 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
475 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
476 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
477 ("Example 2" "Individual source files, multiple compilers in different directories"
478 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
479 nil "\\1/" "work" "\\1/work/" "Makefile" "")
480 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
481 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
482 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
483 -------------------------------------------------------------------------------
484 -- This is a multi-line project description
485 -- that can be used as a project dependent part of the file header.
486 "))
487 "*List of projects and their properties.
488 Name : name used in option `vhdl-project' to choose project
489 Title : title of project (single-line string)
490 Default directory: default project directory (absolute path)
491 Sources : a) source files : path + \"/\" + file name
492 b) directory : path + \"/\"
493 c) directory tree: \"-r \" + path + \"/\"
494 Exclude regexp : matches file/directory names to be excluded as sources
495 Compile options : project-specific options for each compiler
496 Compiler name : name of compiler for which these options are valid
497 Compile options: project-specific compiler options
498 (\"\\1\" inserts library name, \"\\2\" default options)
499 Make options: project-specific make options
500 (\"\\1\" inserts Makefile name, \"\\2\" default options)
501 Exceptions : file-specific exceptions
502 File name regexp: matches file names for which exceptions are valid
503 - Options : file-specific compiler options string
504 (\"\\1\" inserts library name, \"\\2\" default options,
505 \"\\3\" project-specific options)
506 - Do not compile: do not compile this file (in Makefile)
507 Compile directory: where compilation is run and the Makefile is placed
508 \(\"\\1\" inserts compiler ID string)
509 Library name : name of library (default is \"work\")
510 Library directory: path to library (\"\\1\" inserts compiler ID string)
511 Makefile name : name of Makefile
512 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
513 Description : description of project (multi-line string)
514
515 Project title and description are used to insert into the file header (see
516 option `vhdl-file-header').
517
518 The default directory must have an absolute path (use `M-TAB' for completion).
519 All other paths can be absolute or relative to the default directory. All
520 paths must end with '/'.
521
522 The design units found in the sources (files and directories) are shown in the
523 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
524 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
525 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
526 specified, the default directory is taken as source directory. Otherwise,
527 the default directory is only taken as source directory if there is a sources
528 entry with the empty string or \"./\". Exclude regexp allows to filter out
529 specific file and directory names from the list of sources (e.g. CVS
530 directories).
531
532 Files are compiled in the compile directory. Makefiles are also placed into
533 the compile directory. Library directory specifies which directory the
534 compiler compiles into (used to generate the Makefile).
535
536 Since different compile/library directories and Makefiles may exist for
537 different compilers within one project, these paths and names allow the
538 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
539 Compile options, compile directory, library directory, and Makefile name
540 overwrite the settings of the current compiler.
541
542 File-specific compiler options (highest priority) overwrite project-specific
543 options which overwrite default options (lowest priority). Lower priority
544 options can be inserted in higher priority options. This allows to reuse
545 default options (e.g. \"-file\") in project- or file-specific options (e.g.
546 \"-93 -file\").
547
548 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
549 by restarting Emacs."
550 :type `(repeat
551 (list :tag "Project" :indent 2
552 (string :tag "Name ")
553 (string :tag "Title ")
554 (directory :tag "Default directory"
555 :validate vhdl-widget-directory-validate
556 ,(abbreviate-file-name default-directory))
557 (repeat :tag "Sources " :indent 4
558 (directory :format " %v" "./"))
559 (regexp :tag "Exclude regexp ")
560 (repeat
561 :tag "Compile options " :indent 4
562 (list :tag "Compiler" :indent 6
563 ,(let ((alist vhdl-compiler-alist) list)
564 (while alist
565 (setq list (cons (list 'const (caar alist)) list))
566 (setq alist (cdr alist)))
567 (append '(choice :tag "Compiler name")
568 (nreverse list)))
569 (string :tag "Compile options" "\\2")
570 (string :tag "Make options " "\\2")
571 (repeat
572 :tag "Exceptions " :indent 8
573 (cons :format "%v"
574 (regexp :tag "File name regexp ")
575 (choice :format "%[Value Menu%] %v"
576 (string :tag "Options" "\\3")
577 (const :tag "Do not compile" nil))))))
578 (directory :tag "Compile directory"
579 :validate vhdl-widget-directory-validate "./")
580 (string :tag "Library name " "work")
581 (directory :tag "Library directory"
582 :validate vhdl-widget-directory-validate "work/")
583 (file :tag "Makefile name " "Makefile")
584 (string :tag "Description: (type `C-j' for newline)"
585 :format "%t\n%v\n")))
586 :set (lambda (variable value)
587 (vhdl-custom-set variable value
588 'vhdl-update-mode-menu
589 'vhdl-speedbar-refresh))
590 :group 'vhdl-project)
591
592 (defcustom vhdl-project nil
593 "*Specifies the default for the current project.
594 Select a project name from the ones defined in option `vhdl-project-alist'.
595 Is used to determine the project title and description to be inserted in file
596 headers and the source files/directories to be scanned in the hierarchy
597 browser. The current project can also be changed temporarily in the menu."
598 :type (let ((alist vhdl-project-alist) list)
599 (while alist
600 (setq list (cons (list 'const (caar alist)) list))
601 (setq alist (cdr alist)))
602 (append '(choice (const :tag "None" nil) (const :tag "--"))
603 (nreverse list)))
604 :group 'vhdl-project)
605
606 (defcustom vhdl-project-file-name '("\\1.prj")
607 "*List of file names/paths for importing/exporting project setups.
608 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
609 replaced by the user name (allows to have user-specific project setups).
610 The first entry is used as file name to import/export individual project
611 setups. All entries are used to automatically import project setups at
612 startup (see option `vhdl-project-auto-load'). Projects loaded from the
613 first entry are automatically made current. Hint: specify local project
614 setups in first entry, global setups in following entries; loading a local
615 project setup will make it current, while loading the global setups
616 is done without changing the current project.
617 Names can also have an absolute path (i.e. project setups can be stored
618 in global directories)."
619 :type '(repeat (string :tag "File name" "\\1.prj"))
620 :group 'vhdl-project)
621
622 (defcustom vhdl-project-auto-load '(startup)
623 "*Automatically load project setups from files.
624 All project setup files that match the file names specified in option
625 `vhdl-project-file-name' are automatically loaded. The project of the
626 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
627 entry is activated.
628 A project setup file can be obtained by exporting a project (see menu).
629 At startup: project setup file is loaded at Emacs startup"
630 :type '(set (const :tag "At startup" startup))
631 :group 'vhdl-project)
632
633 (defcustom vhdl-project-sort t
634 "*Non-nil means projects are displayed in alphabetical order."
635 :type 'boolean
636 :group 'vhdl-project)
637
638
639 (defgroup vhdl-style nil
640 "Customizations for coding styles."
641 :group 'vhdl
642 :group 'vhdl-template
643 :group 'vhdl-port
644 :group 'vhdl-compose)
645
646 (defcustom vhdl-standard '(87 nil)
647 "*VHDL standards used.
648 Basic standard:
649 VHDL'87 : IEEE Std 1076-1987
650 VHDL'93 : IEEE Std 1076-1993
651 Additional standards:
652 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
653 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
654
655 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
656 \"Activate Options\"."
657 :type '(list (choice :tag "Basic standard"
658 (const :tag "VHDL'87" 87)
659 (const :tag "VHDL'93" 93))
660 (set :tag "Additional standards" :indent 2
661 (const :tag "VHDL-AMS" ams)
662 (const :tag "Math packages" math)))
663 :set (lambda (variable value)
664 (vhdl-custom-set variable value
665 'vhdl-template-map-init
666 'vhdl-mode-abbrev-table-init
667 'vhdl-template-construct-alist-init
668 'vhdl-template-package-alist-init
669 'vhdl-update-mode-menu
670 'vhdl-words-init 'vhdl-font-lock-init))
671 :group 'vhdl-style)
672
673 (defcustom vhdl-basic-offset 2
674 "*Amount of basic offset used for indentation.
675 This value is used by + and - symbols in `vhdl-offsets-alist'."
676 :type 'integer
677 :group 'vhdl-style)
678
679 (defcustom vhdl-upper-case-keywords nil
680 "*Non-nil means convert keywords to upper case.
681 This is done when typed or expanded or by the fix case functions."
682 :type 'boolean
683 :set (lambda (variable value)
684 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
685 :group 'vhdl-style)
686
687 (defcustom vhdl-upper-case-types nil
688 "*Non-nil means convert standardized types to upper case.
689 This is done when expanded or by the fix case functions."
690 :type 'boolean
691 :set (lambda (variable value)
692 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
693 :group 'vhdl-style)
694
695 (defcustom vhdl-upper-case-attributes nil
696 "*Non-nil means convert standardized attributes to upper case.
697 This is done when expanded or by the fix case functions."
698 :type 'boolean
699 :set (lambda (variable value)
700 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
701 :group 'vhdl-style)
702
703 (defcustom vhdl-upper-case-enum-values nil
704 "*Non-nil means convert standardized enumeration values to upper case.
705 This is done when expanded or by the fix case functions."
706 :type 'boolean
707 :set (lambda (variable value)
708 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
709 :group 'vhdl-style)
710
711 (defcustom vhdl-upper-case-constants t
712 "*Non-nil means convert standardized constants to upper case.
713 This is done when expanded."
714 :type 'boolean
715 :set (lambda (variable value)
716 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
717 :group 'vhdl-style)
718
719 (defcustom vhdl-use-direct-instantiation 'standard
720 "*Non-nil means use VHDL'93 direct component instantiation.
721 Never : never
722 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
723 Always : always"
724 :type '(choice (const :tag "Never" never)
725 (const :tag "Standard" standard)
726 (const :tag "Always" always))
727 :group 'vhdl-style)
728
729
730 (defgroup vhdl-naming nil
731 "Customizations for naming conventions."
732 :group 'vhdl)
733
734 (defcustom vhdl-entity-file-name '(".*" . "\\&")
735 (concat
736 "*Specifies how the entity file name is obtained.
737 The entity file name can be obtained by modifying the entity name (e.g.
738 attaching or stripping off a substring). The file extension is automatically
739 taken from the file name of the current buffer."
740 vhdl-name-doc-string)
741 :type '(cons (regexp :tag "From regexp")
742 (string :tag "To string "))
743 :group 'vhdl-naming
744 :group 'vhdl-compose)
745
746 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
747 (concat
748 "*Specifies how the architecture file name is obtained.
749 The architecture file name can be obtained by modifying the entity
750 and/or architecture name (e.g. attaching or stripping off a substring). The
751 string that is matched against the regexp is the concatenation of the entity
752 and the architecture name separated by a space. This gives access to both
753 names (see default setting as example)."
754 vhdl-name-doc-string)
755 :type '(cons (regexp :tag "From regexp")
756 (string :tag "To string "))
757 :group 'vhdl-naming
758 :group 'vhdl-compose)
759
760 (defcustom vhdl-package-file-name '(".*" . "\\&")
761 (concat
762 "*Specifies how the package file name is obtained.
763 The package file name can be obtained by modifying the package name (e.g.
764 attaching or stripping off a substring). The file extension is automatically
765 taken from the file name of the current buffer."
766 vhdl-name-doc-string)
767 :type '(cons (regexp :tag "From regexp")
768 (string :tag "To string "))
769 :group 'vhdl-naming
770 :group 'vhdl-compose)
771
772 (defcustom vhdl-file-name-case 'identity
773 "*Specifies how to change case for obtaining file names.
774 When deriving a file name from a VHDL unit name, case can be changed as
775 follows:
776 As Is: case is not changed (taken as is)
777 Lower Case: whole name is changed to lower case
778 Upper Case: whole name is changed to upper case
779 Capitalize: first letter of each word in name is capitalized"
780 :type '(choice (const :tag "As Is" identity)
781 (const :tag "Lower Case" downcase)
782 (const :tag "Upper Case" upcase)
783 (const :tag "Capitalize" capitalize))
784 :group 'vhdl-naming
785 :group 'vhdl-compose)
786
787
788 (defgroup vhdl-template nil
789 "Customizations for electrification."
790 :group 'vhdl)
791
792 (defcustom vhdl-electric-keywords '(vhdl user)
793 "*Type of keywords for which electrification is enabled.
794 VHDL keywords: invoke built-in templates
795 User keywords: invoke user models (see option `vhdl-model-alist')"
796 :type '(set (const :tag "VHDL keywords" vhdl)
797 (const :tag "User model keywords" user))
798 :set (lambda (variable value)
799 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
800 :group 'vhdl-template)
801
802 (defcustom vhdl-optional-labels 'process
803 "*Constructs for which labels are to be queried.
804 Template generators prompt for optional labels for:
805 None : no constructs
806 Processes only: processes only (also procedurals in VHDL-AMS)
807 All constructs: all constructs with optional labels and keyword END"
808 :type '(choice (const :tag "None" none)
809 (const :tag "Processes only" process)
810 (const :tag "All constructs" all))
811 :group 'vhdl-template)
812
813 (defcustom vhdl-insert-empty-lines 'unit
814 "*Specifies whether to insert empty lines in some templates.
815 This improves readability of code. Empty lines are inserted in:
816 None : no constructs
817 Design units only: entities, architectures, configurations, packages only
818 All constructs : also all constructs with BEGIN...END parts
819
820 Replaces option `vhdl-additional-empty-lines'."
821 :type '(choice (const :tag "None" none)
822 (const :tag "Design units only" unit)
823 (const :tag "All constructs" all))
824 :group 'vhdl-template
825 :group 'vhdl-port
826 :group 'vhdl-compose)
827
828 (defcustom vhdl-argument-list-indent nil
829 "*Non-nil means indent argument lists relative to opening parenthesis.
830 That is, argument, association, and port lists start on the same line as the
831 opening parenthesis and subsequent lines are indented accordingly.
832 Otherwise, lists start on a new line and are indented as normal code."
833 :type 'boolean
834 :group 'vhdl-template
835 :group 'vhdl-port
836 :group 'vhdl-compose)
837
838 (defcustom vhdl-association-list-with-formals t
839 "*Non-nil means write association lists with formal parameters.
840 Templates prompt for formal and actual parameters (ports/generics).
841 When pasting component instantiations, formals are included.
842 If nil, only a list of actual parameters is entered."
843 :type 'boolean
844 :group 'vhdl-template
845 :group 'vhdl-port
846 :group 'vhdl-compose)
847
848 (defcustom vhdl-conditions-in-parenthesis nil
849 "*Non-nil means place parenthesis around condition expressions."
850 :type 'boolean
851 :group 'vhdl-template)
852
853 (defcustom vhdl-zero-string "'0'"
854 "*String to use for a logic zero."
855 :type 'string
856 :group 'vhdl-template)
857
858 (defcustom vhdl-one-string "'1'"
859 "*String to use for a logic one."
860 :type 'string
861 :group 'vhdl-template)
862
863
864 (defgroup vhdl-header nil
865 "Customizations for file header."
866 :group 'vhdl-template
867 :group 'vhdl-compose)
868
869 (defcustom vhdl-file-header "\
870 -------------------------------------------------------------------------------
871 -- Title : <title string>
872 -- Project : <project>
873 -------------------------------------------------------------------------------
874 -- File : <filename>
875 -- Author : <author>
876 -- Company : <company>
877 -- Created : <date>
878 -- Last update: <date>
879 -- Platform : <platform>
880 -- Standard : <standard>
881 <projectdesc>-------------------------------------------------------------------------------
882 -- Description: <cursor>
883 <copyright>-------------------------------------------------------------------------------
884 -- Revisions :
885 -- Date Version Author Description
886 -- <date> 1.0 <login>\tCreated
887 -------------------------------------------------------------------------------
888
889 "
890 "*String or file to insert as file header.
891 If the string specifies an existing file name, the contents of the file is
892 inserted, otherwise the string itself is inserted as file header.
893 Type `C-j' for newlines.
894 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
895 if the header needs to be version controlled.
896
897 The following keywords for template generation are supported:
898 <filename> : replaced by the name of the buffer
899 <author> : replaced by the user name and email address
900 \(`user-full-name',`mail-host-address', `user-mail-address')
901 <login> : replaced by user login name (`user-login-name')
902 <company> : replaced by contents of option `vhdl-company-name'
903 <date> : replaced by the current date
904 <year> : replaced by the current year
905 <project> : replaced by title of current project (`vhdl-project')
906 <projectdesc> : replaced by description of current project (`vhdl-project')
907 <copyright> : replaced by copyright string (`vhdl-copyright-string')
908 <platform> : replaced by contents of option `vhdl-platform-spec'
909 <standard> : replaced by the VHDL language standard(s) used
910 <... string> : replaced by a queried string (\"...\" is the prompt word)
911 <title string>: replaced by file title in automatically generated files
912 <cursor> : final cursor position
913
914 The (multi-line) project description <projectdesc> can be used as a project
915 dependent part of the file header and can also contain the above keywords."
916 :type 'string
917 :group 'vhdl-header)
918
919 (defcustom vhdl-file-footer ""
920 "*String or file to insert as file footer.
921 If the string specifies an existing file name, the contents of the file is
922 inserted, otherwise the string itself is inserted as file footer (i.e. at
923 the end of the file).
924 Type `C-j' for newlines.
925 The same keywords as in option `vhdl-file-header' can be used."
926 :type 'string
927 :group 'vhdl-header)
928
929 (defcustom vhdl-company-name ""
930 "*Name of company to insert in file header.
931 See option `vhdl-file-header'."
932 :type 'string
933 :group 'vhdl-header)
934
935 (defcustom vhdl-copyright-string "\
936 -------------------------------------------------------------------------------
937 -- Copyright (c) <year> <company>
938 "
939 "*Copyright string to insert in file header.
940 Can be multi-line string (type `C-j' for newline) and contain other file
941 header keywords (see option `vhdl-file-header')."
942 :type 'string
943 :group 'vhdl-header)
944
945 (defcustom vhdl-platform-spec ""
946 "*Specification of VHDL platform to insert in file header.
947 The platform specification should contain names and versions of the
948 simulation and synthesis tools used.
949 See option `vhdl-file-header'."
950 :type 'string
951 :group 'vhdl-header)
952
953 (defcustom vhdl-date-format "%Y-%m-%d"
954 "*Specifies the date format to use in the header.
955 This string is passed as argument to the command `format-time-string'.
956 For more information on format strings, see the documentation for the
957 `format-time-string' command (C-h f `format-time-string')."
958 :type 'string
959 :group 'vhdl-header)
960
961 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
962 "*Prefix string of modification date in VHDL file header.
963 If actualization of the modification date is called (menu,
964 `\\[vhdl-template-modify]'), this string is searched and the rest
965 of the line replaced by the current date."
966 :type 'string
967 :group 'vhdl-header)
968
969 (defcustom vhdl-modify-date-on-saving t
970 "*Non-nil means update the modification date when the buffer is saved.
971 Calls function `\\[vhdl-template-modify]').
972
973 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
974 \"Activate Options\"."
975 :type 'boolean
976 :group 'vhdl-header)
977
978
979 (defgroup vhdl-sequential-process nil
980 "Customizations for sequential processes."
981 :group 'vhdl-template)
982
983 (defcustom vhdl-reset-kind 'async
984 "*Specifies which kind of reset to use in sequential processes."
985 :type '(choice (const :tag "None" none)
986 (const :tag "Synchronous" sync)
987 (const :tag "Asynchronous" async))
988 :group 'vhdl-sequential-process)
989
990 (defcustom vhdl-reset-active-high nil
991 "*Non-nil means reset in sequential processes is active high.
992 Nil means active low."
993 :type 'boolean
994 :group 'vhdl-sequential-process)
995
996 (defcustom vhdl-clock-rising-edge t
997 "*Non-nil means rising edge of clock triggers sequential processes.
998 Nil means falling edge."
999 :type 'boolean
1000 :group 'vhdl-sequential-process)
1001
1002 (defcustom vhdl-clock-edge-condition 'standard
1003 "*Syntax of the clock edge condition.
1004 Standard: \"clk'event and clk = '1'\"
1005 Function: \"rising_edge(clk)\""
1006 :type '(choice (const :tag "Standard" standard)
1007 (const :tag "Function" function))
1008 :group 'vhdl-sequential-process)
1009
1010 (defcustom vhdl-clock-name ""
1011 "*Name of clock signal to use in templates."
1012 :type 'string
1013 :group 'vhdl-sequential-process)
1014
1015 (defcustom vhdl-reset-name ""
1016 "*Name of reset signal to use in templates."
1017 :type 'string
1018 :group 'vhdl-sequential-process)
1019
1020
1021 (defgroup vhdl-model nil
1022 "Customizations for user models."
1023 :group 'vhdl)
1024
1025 (defcustom vhdl-model-alist
1026 '(("Example Model"
1027 "<label> : process (<clock>, <reset>)
1028 begin -- process <label>
1029 if <reset> = '0' then -- asynchronous reset (active low)
1030 <cursor>
1031 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1032 if <enable> = '1' then -- synchronous load
1033
1034 end if;
1035 end if;
1036 end process <label>;"
1037 "e" ""))
1038 "*List of user models.
1039 VHDL models (templates) can be specified by the user in this list. They can be
1040 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1041 electrification (i.e. overriding existing or creating new keywords, see
1042 option `vhdl-electric-keywords').
1043 Name : name of model (string of words and spaces)
1044 String : string or name of file to be inserted as model (newline: `C-j')
1045 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1046 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1047 Keyword : keyword to invoke model
1048
1049 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1050 A prompt that appears several times is queried once and replaced throughout
1051 the model. Special prompts are:
1052 <clock> : name specified in `vhdl-clock-name' (if not empty)
1053 <reset> : name specified in `vhdl-reset-name' (if not empty)
1054 <cursor>: final cursor position
1055 File header prompts (see variable `vhdl-file-header') are automatically
1056 replaced, so that user models can also be used to insert different types of
1057 headers.
1058
1059 If the string specifies an existing file name, the contents of the file is
1060 inserted, otherwise the string itself is inserted.
1061 The code within the models should be correctly indented.
1062 Type `C-j' for newlines.
1063
1064 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1065 \"Activate Options\"."
1066 :type '(repeat (list :tag "Model" :indent 2
1067 (string :tag "Name ")
1068 (string :tag "String : (type `C-j' for newline)"
1069 :format "%t\n%v")
1070 (sexp :tag "Key binding" x)
1071 (string :tag "Keyword " :format "%t: %v\n")))
1072 :set (lambda (variable value)
1073 (vhdl-custom-set variable value
1074 'vhdl-model-map-init
1075 'vhdl-model-defun
1076 'vhdl-mode-abbrev-table-init
1077 'vhdl-update-mode-menu))
1078 :group 'vhdl-model)
1079
1080
1081 (defgroup vhdl-port nil
1082 "Customizations for port translation functions."
1083 :group 'vhdl
1084 :group 'vhdl-compose)
1085
1086 (defcustom vhdl-include-port-comments nil
1087 "*Non-nil means include port comments when a port is pasted."
1088 :type 'boolean
1089 :group 'vhdl-port)
1090
1091 (defcustom vhdl-include-direction-comments nil
1092 "*Non-nil means include port direction in instantiations as comments."
1093 :type 'boolean
1094 :group 'vhdl-port)
1095
1096 (defcustom vhdl-include-type-comments nil
1097 "*Non-nil means include generic/port type in instantiations as comments."
1098 :type 'boolean
1099 :group 'vhdl-port)
1100
1101 (defcustom vhdl-include-group-comments 'never
1102 "*Specifies whether to include group comments and spacings.
1103 The comments and empty lines between groups of ports are pasted:
1104 Never : never
1105 Declarations: in entity/component/constant/signal declarations only
1106 Always : also in generic/port maps"
1107 :type '(choice (const :tag "Never" never)
1108 (const :tag "Declarations" decl)
1109 (const :tag "Always" always))
1110 :group 'vhdl-port)
1111
1112 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1113 (concat
1114 "*Specifies how actual port names are obtained from formal port names.
1115 In a component instantiation, an actual port name can be obtained by
1116 modifying the formal port name (e.g. attaching or stripping off a substring)."
1117 vhdl-name-doc-string)
1118 :type '(cons (regexp :tag "From regexp")
1119 (string :tag "To string "))
1120 :group 'vhdl-port)
1121
1122 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1123 (concat
1124 "*Specifies how an instance name is obtained.
1125 The instance name can be obtained by modifying the name of the component to be
1126 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1127 by a unique number (starting with 1).
1128 If TO STRING is empty, the instance name is queried."
1129 vhdl-name-doc-string)
1130 :type '(cons (regexp :tag "From regexp")
1131 (string :tag "To string "))
1132 :group 'vhdl-port)
1133
1134
1135 (defgroup vhdl-testbench nil
1136 "Customizations for testbench generation ."
1137 :group 'vhdl-port)
1138
1139 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1140 (concat
1141 "*Specifies how the testbench entity name is obtained.
1142 The entity name of a testbench can be obtained by modifying the name of
1143 the component to be tested (e.g. attaching or stripping off a substring)."
1144 vhdl-name-doc-string)
1145 :type '(cons (regexp :tag "From regexp")
1146 (string :tag "To string "))
1147 :group 'vhdl-testbench)
1148
1149 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1150 (concat
1151 "*Specifies how the testbench architecture name is obtained.
1152 The testbench architecture name can be obtained by modifying the name of
1153 the component to be tested (e.g. attaching or stripping off a substring).
1154 If TO STRING is empty, the architecture name is queried."
1155 vhdl-name-doc-string)
1156 :type '(cons (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 :group 'vhdl-testbench)
1159
1160 (defcustom vhdl-testbench-configuration-name
1161 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1162 (concat
1163 "*Specifies how the testbench configuration name is obtained.
1164 The configuration name of a testbench can be obtained by modifying the entity
1165 and/or architecture name (e.g. attaching or stripping off a substring). The
1166 string that is matched against the regexp is the concatenation of the entity
1167 and the architecture name separated by a space. This gives access to both
1168 names (see default setting as example)."
1169 vhdl-name-doc-string)
1170 :type '(cons (regexp :tag "From regexp")
1171 (string :tag "To string "))
1172 :group 'vhdl-testbench)
1173
1174 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1175 (concat
1176 "*Specifies how a DUT instance name is obtained.
1177 The design-under-test instance name (i.e. the component instantiated in the
1178 testbench) can be obtained by modifying the component name (e.g. attaching
1179 or stripping off a substring)."
1180 vhdl-name-doc-string)
1181 :type '(cons (regexp :tag "From regexp")
1182 (string :tag "To string "))
1183 :group 'vhdl-testbench)
1184
1185 (defcustom vhdl-testbench-include-header t
1186 "*Non-nil means include a header in automatically generated files."
1187 :type 'boolean
1188 :group 'vhdl-testbench)
1189
1190 (defcustom vhdl-testbench-declarations "\
1191 -- clock
1192 signal Clk : std_logic := '1';
1193 "
1194 "*String or file to be inserted in the testbench declarative part.
1195 If the string specifies an existing file name, the contents of the file is
1196 inserted, otherwise the string itself is inserted in the testbench
1197 architecture before the BEGIN keyword.
1198 Type `C-j' for newlines."
1199 :type 'string
1200 :group 'vhdl-testbench)
1201
1202 (defcustom vhdl-testbench-statements "\
1203 -- clock generation
1204 Clk <= not Clk after 10 ns;
1205
1206 -- waveform generation
1207 WaveGen_Proc: process
1208 begin
1209 -- insert signal assignments here
1210
1211 wait until Clk = '1';
1212 end process WaveGen_Proc;
1213 "
1214 "*String or file to be inserted in the testbench statement part.
1215 If the string specifies an existing file name, the contents of the file is
1216 inserted, otherwise the string itself is inserted in the testbench
1217 architecture before the END keyword.
1218 Type `C-j' for newlines."
1219 :type 'string
1220 :group 'vhdl-testbench)
1221
1222 (defcustom vhdl-testbench-initialize-signals nil
1223 "*Non-nil means initialize signals with `0' when declared in testbench."
1224 :type 'boolean
1225 :group 'vhdl-testbench)
1226
1227 (defcustom vhdl-testbench-include-library t
1228 "*Non-nil means a library/use clause for std_logic_1164 is included."
1229 :type 'boolean
1230 :group 'vhdl-testbench)
1231
1232 (defcustom vhdl-testbench-include-configuration t
1233 "*Non-nil means a testbench configuration is attached at the end."
1234 :type 'boolean
1235 :group 'vhdl-testbench)
1236
1237 (defcustom vhdl-testbench-create-files 'single
1238 "*Specifies whether new files should be created for the testbench.
1239 testbench entity and architecture are inserted:
1240 None : in current buffer
1241 Single file : in new single file
1242 Separate files: in two separate files
1243 Note that the files have the same name as the contained design unit."
1244 :type '(choice (const :tag "None" none)
1245 (const :tag "Single file" single)
1246 (const :tag "Separate files" separate))
1247 :group 'vhdl-testbench)
1248
1249
1250 (defgroup vhdl-compose nil
1251 "Customizations for structural composition."
1252 :group 'vhdl)
1253
1254 (defcustom vhdl-compose-create-files 'single
1255 "*Specifies whether new files should be created for the new component.
1256 The component's entity and architecture are inserted:
1257 None : in current buffer
1258 Single file : in new single file
1259 Separate files: in two separate files
1260 The file names are obtained from variables `vhdl-entity-file-name' and
1261 `vhdl-architecture-file-name'."
1262 :type '(choice (const :tag "None" none)
1263 (const :tag "Single file" single)
1264 (const :tag "Separate files" separate))
1265 :group 'vhdl-compose)
1266
1267 (defcustom vhdl-compose-include-header t
1268 "*Non-nil means include a header in automatically generated files."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1271
1272 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1273 (concat
1274 "*Specifies how the component architecture name is obtained.
1275 The component architecture name can be obtained by modifying the entity name
1276 \(e.g. attaching or stripping off a substring).
1277 If TO STRING is empty, the architecture name is queried."
1278 vhdl-name-doc-string)
1279 :type '(cons (regexp :tag "From regexp")
1280 (string :tag "To string "))
1281 :group 'vhdl-compose)
1282
1283 (defcustom vhdl-components-package-name
1284 '((".*" . "\\&_components") . "components")
1285 (concat
1286 "*Specifies how the name for the components package is obtained.
1287 The components package is a package containing all component declarations for
1288 the current design. Its name can be obtained by modifying the project name
1289 \(e.g. attaching or stripping off a substring). If no project is defined, the
1290 DIRECTORY entry is chosen."
1291 vhdl-name-doc-string)
1292 :type '(cons (cons :tag "Project" :indent 2
1293 (regexp :tag "From regexp")
1294 (string :tag "To string "))
1295 (string :tag "Directory:\n String "))
1296 :group 'vhdl-compose)
1297
1298 (defcustom vhdl-use-components-package nil
1299 "*Non-nil means use a separate components package for component declarations.
1300 Otherwise, component declarations are inserted and searched for in the
1301 architecture declarative parts."
1302 :type 'boolean
1303 :group 'vhdl-compose)
1304
1305
1306 (defgroup vhdl-comment nil
1307 "Customizations for comments."
1308 :group 'vhdl)
1309
1310 (defcustom vhdl-self-insert-comments t
1311 "*Non-nil means various templates automatically insert help comments."
1312 :type 'boolean
1313 :group 'vhdl-comment)
1314
1315 (defcustom vhdl-prompt-for-comments t
1316 "*Non-nil means various templates prompt for user definable comments."
1317 :type 'boolean
1318 :group 'vhdl-comment)
1319
1320 (defcustom vhdl-inline-comment-column 40
1321 "*Column to indent and align inline comments to.
1322 Overrides local option `comment-column'.
1323
1324 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1325 \"Activate Options\"."
1326 :type 'integer
1327 :group 'vhdl-comment)
1328
1329 (defcustom vhdl-end-comment-column 79
1330 "*End of comment column.
1331 Comments that exceed this column number are wrapped.
1332
1333 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1334 \"Activate Options\"."
1335 :type 'integer
1336 :group 'vhdl-comment)
1337
1338 (defvar end-comment-column)
1339
1340
1341 (defgroup vhdl-align nil
1342 "Customizations for alignment."
1343 :group 'vhdl)
1344
1345 (defcustom vhdl-auto-align t
1346 "*Non-nil means align some templates automatically after generation."
1347 :type 'boolean
1348 :group 'vhdl-align)
1349
1350 (defcustom vhdl-align-groups t
1351 "*Non-nil means align groups of code lines separately.
1352 A group of code lines is a region of consecutive lines between two lines that
1353 match the regexp in option `vhdl-align-group-separate'."
1354 :type 'boolean
1355 :group 'vhdl-align)
1356
1357 (defcustom vhdl-align-group-separate "^\\s-*$"
1358 "*Regexp for matching a line that separates groups of lines for alignment.
1359 Examples:
1360 \"^\\s-*$\": matches an empty line
1361 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1362 :type 'regexp
1363 :group 'vhdl-align)
1364
1365 (defcustom vhdl-align-same-indent t
1366 "*Non-nil means align blocks with same indent separately.
1367 When a region or the entire buffer is aligned, the code is divided into
1368 blocks of same indent which are aligned separately (except for argument/port
1369 lists). This gives nicer alignment in most cases.
1370 Option `vhdl-align-groups' still applies within these blocks."
1371 :type 'boolean
1372 :group 'vhdl-align)
1373
1374
1375 (defgroup vhdl-highlight nil
1376 "Customizations for highlighting."
1377 :group 'vhdl)
1378
1379 (defcustom vhdl-highlight-keywords t
1380 "*Non-nil means highlight VHDL keywords and other standardized words.
1381 The following faces are used:
1382 `font-lock-keyword-face' : keywords
1383 `font-lock-type-face' : standardized types
1384 `vhdl-font-lock-attribute-face': standardized attributes
1385 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1386 `vhdl-font-lock-function-face' : standardized function and package names
1387
1388 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1389 entry \"Fontify Buffer\")."
1390 :type 'boolean
1391 :set (lambda (variable value)
1392 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1393 :group 'vhdl-highlight)
1394
1395 (defcustom vhdl-highlight-names t
1396 "*Non-nil means highlight declaration names and construct labels.
1397 The following faces are used:
1398 `font-lock-function-name-face' : names in declarations of units,
1399 subprograms, components, as well as labels of VHDL constructs
1400 `font-lock-type-face' : names in type/nature declarations
1401 `vhdl-font-lock-attribute-face': names in attribute declarations
1402 `font-lock-variable-name-face' : names in declarations of signals,
1403 variables, constants, subprogram parameters, generics, and ports
1404
1405 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1406 entry \"Fontify Buffer\")."
1407 :type 'boolean
1408 :set (lambda (variable value)
1409 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1410 :group 'vhdl-highlight)
1411
1412 (defcustom vhdl-highlight-special-words nil
1413 "*Non-nil means highlight words with special syntax.
1414 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1415 are highlighted accordingly.
1416 Can be used for visual support of naming conventions.
1417
1418 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1419 entry \"Fontify Buffer\")."
1420 :type 'boolean
1421 :set (lambda (variable value)
1422 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1423 :group 'vhdl-highlight)
1424
1425 (defcustom vhdl-highlight-forbidden-words nil
1426 "*Non-nil means highlight forbidden words.
1427 The reserved words specified in option `vhdl-forbidden-words' or having the
1428 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1429 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1430 use them.
1431
1432 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1433 entry \"Fontify Buffer\")."
1434 :type 'boolean
1435 :set (lambda (variable value)
1436 (vhdl-custom-set variable value
1437 'vhdl-words-init 'vhdl-font-lock-init))
1438 :group 'vhdl-highlight)
1439
1440 (defcustom vhdl-highlight-verilog-keywords nil
1441 "*Non-nil means highlight Verilog keywords as reserved words.
1442 Verilog keywords are highlighted in a warning color (face
1443 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1444
1445 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1446 entry \"Fontify Buffer\")."
1447 :type 'boolean
1448 :set (lambda (variable value)
1449 (vhdl-custom-set variable value
1450 'vhdl-words-init 'vhdl-font-lock-init))
1451 :group 'vhdl-highlight)
1452
1453 (defcustom vhdl-highlight-translate-off nil
1454 "*Non-nil means background-highlight code excluded from translation.
1455 That is, all code between \"-- pragma translate_off\" and
1456 \"-- pragma translate_on\" is highlighted using a different background color
1457 \(face `vhdl-font-lock-translate-off-face').
1458 Note: this might slow down on-the-fly fontification (and thus editing).
1459
1460 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1461 entry \"Fontify Buffer\")."
1462 :type 'boolean
1463 :set (lambda (variable value)
1464 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1465 :group 'vhdl-highlight)
1466
1467 (defcustom vhdl-highlight-case-sensitive nil
1468 "*Non-nil means consider case for highlighting.
1469 Possible trade-off:
1470 non-nil also upper-case VHDL words are highlighted, but case of words with
1471 special syntax is not considered
1472 nil only lower-case VHDL words are highlighted, but case of words with
1473 special syntax is considered
1474 Overrides local option `font-lock-keywords-case-fold-search'.
1475
1476 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1477 entry \"Fontify Buffer\")."
1478 :type 'boolean
1479 :group 'vhdl-highlight)
1480
1481 (defcustom vhdl-special-syntax-alist
1482 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1483 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1484 ("variable" "\\w+_v" "Grey50" "Grey80"))
1485 "*List of special syntax to be highlighted.
1486 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1487 syntax (as regular expression) are highlighted in the corresponding color.
1488
1489 Name : string of words and spaces
1490 Regexp : regular expression describing word syntax
1491 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1492 Color (light): foreground color for light background
1493 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1494 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1495 Color (dark) : foreground color for dark background
1496 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1497 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1498
1499 Can be used for visual support of naming conventions, such as highlighting
1500 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1501 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1502 common substrings or name suffices.
1503 For each entry, a new face is generated with the specified colors and name
1504 \"vhdl-font-lock-\" + name + \"-face\".
1505
1506 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1507 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1508 :type '(repeat (list :tag "Face" :indent 2
1509 (string :tag "Name ")
1510 (regexp :tag "Regexp " "\\w+_")
1511 (string :tag "Color (light)")
1512 (string :tag "Color (dark) ")))
1513 :set (lambda (variable value)
1514 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1515 :group 'vhdl-highlight)
1516
1517 (defcustom vhdl-forbidden-words '()
1518 "*List of forbidden words to be highlighted.
1519 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1520 words are highlighted in a warning color to indicate not to use them.
1521
1522 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1523 entry \"Fontify Buffer\")."
1524 :type '(repeat (string :format "%v"))
1525 :set (lambda (variable value)
1526 (vhdl-custom-set variable value
1527 'vhdl-words-init 'vhdl-font-lock-init))
1528 :group 'vhdl-highlight)
1529
1530 (defcustom vhdl-forbidden-syntax ""
1531 "*Syntax of forbidden words to be highlighted.
1532 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1533 syntax are highlighted in a warning color to indicate not to use them.
1534 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1535 highlights identifiers with 10 or more characters).
1536
1537 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1538 entry \"Fontify Buffer\")."
1539 :type 'regexp
1540 :set (lambda (variable value)
1541 (vhdl-custom-set variable value
1542 'vhdl-words-init 'vhdl-font-lock-init))
1543 :group 'vhdl-highlight)
1544
1545 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1546 "*List of compiler directive keywords recognized for highlighting.
1547
1548 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1549 entry \"Fontify Buffer\")."
1550 :type '(repeat (string :format "%v"))
1551 :set (lambda (variable value)
1552 (vhdl-custom-set variable value
1553 'vhdl-words-init 'vhdl-font-lock-init))
1554 :group 'vhdl-highlight)
1555
1556
1557 (defgroup vhdl-speedbar nil
1558 "Customizations for speedbar."
1559 :group 'vhdl)
1560
1561 (defcustom vhdl-speedbar-auto-open nil
1562 "*Non-nil means automatically open speedbar at startup.
1563 Alternatively, the speedbar can be opened from the VHDL menu."
1564 :type 'boolean
1565 :group 'vhdl-speedbar)
1566
1567 (defcustom vhdl-speedbar-display-mode 'files
1568 "*Specifies the default displaying mode when opening speedbar.
1569 Alternatively, the displaying mode can be selected from the speedbar menu or
1570 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1571 :type '(choice (const :tag "Files" files)
1572 (const :tag "Directory hierarchy" directory)
1573 (const :tag "Project hierarchy" project))
1574 :group 'vhdl-speedbar)
1575
1576 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1577 "*Limits scanning of large files and netlists.
1578 Design units: maximum file size to scan for design units
1579 Hierarchy (instances of subcomponents):
1580 File size: maximum file size to scan for instances (in bytes)
1581 Instances per arch: maximum number of instances to scan per architecture
1582
1583 \"None\" always means that there is no limit.
1584 In case of files not or incompletely scanned, a warning message and the file
1585 names are printed out.
1586 Background: scanning for instances is considerably slower than scanning for
1587 design units, especially when there are many instances. These limits should
1588 prevent the scanning of large netlists."
1589 :type '(list (choice :tag "Design units"
1590 :format "%t : %[Value Menu%] %v"
1591 (const :tag "None" nil)
1592 (integer :tag "File size"))
1593 (list :tag "Hierarchy" :indent 2
1594 (choice :tag "File size"
1595 :format "%t : %[Value Menu%] %v"
1596 (const :tag "None" nil)
1597 (integer :tag "Size "))
1598 (choice :tag "Instances per arch"
1599 (const :tag "None" nil)
1600 (integer :tag "Number "))))
1601 :group 'vhdl-speedbar)
1602
1603 (defcustom vhdl-speedbar-jump-to-unit t
1604 "*Non-nil means jump to the design unit code when opened in a buffer.
1605 The buffer cursor position is left unchanged otherwise."
1606 :type 'boolean
1607 :group 'vhdl-speedbar)
1608
1609 (defcustom vhdl-speedbar-update-on-saving t
1610 "*Automatically update design hierarchy when buffer is saved."
1611 :type 'boolean
1612 :group 'vhdl-speedbar)
1613
1614 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1615 "*Automatically save modified hierarchy caches when exiting Emacs.
1616 Hierarchy: design hierarchy information
1617 Display: displaying information (which design units to expand)"
1618 :type '(set (const :tag "Hierarchy" hierarchy)
1619 (const :tag "Display" display))
1620 :group 'vhdl-speedbar)
1621
1622 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1623 "*Name of file for saving hierarchy cache.
1624 \"\\1\" is replaced by the project name if a project is specified,
1625 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1626 different users to have cache files in the same directory). Can also have
1627 an absolute path (i.e. all caches can be stored in one global directory)."
1628 :type 'string
1629 :group 'vhdl-speedbar)
1630
1631
1632 (defgroup vhdl-menu nil
1633 "Customizations for menues."
1634 :group 'vhdl)
1635
1636 (defcustom vhdl-index-menu nil
1637 "*Non-nil means add an index menu for a source file when loading.
1638 Alternatively, the speedbar can be used. Note that the index menu scans a file
1639 when it is opened, while speedbar only scans the file upon request."
1640 :type 'boolean
1641 :group 'vhdl-menu)
1642
1643 (defcustom vhdl-source-file-menu nil
1644 "*Non-nil means add a menu of all source files in current directory.
1645 Alternatively, the speedbar can be used."
1646 :type 'boolean
1647 :group 'vhdl-menu)
1648
1649 (defcustom vhdl-hideshow-menu nil
1650 "*Non-nil means add hideshow menu and functionality at startup.
1651 Hideshow can also be enabled from the VHDL Mode menu.
1652 Hideshow allows hiding code of various VHDL constructs.
1653
1654 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1655 \"Activate Options\"."
1656 :type 'boolean
1657 :group 'vhdl-menu)
1658
1659 (defcustom vhdl-hide-all-init nil
1660 "*Non-nil means hide all design units initially after a file is loaded."
1661 :type 'boolean
1662 :group 'vhdl-menu)
1663
1664
1665 (defgroup vhdl-print nil
1666 "Customizations for printing."
1667 :group 'vhdl)
1668
1669 (defcustom vhdl-print-two-column t
1670 "*Non-nil means print code in two columns and landscape format.
1671 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1672 prints VHDL files in a nice two-column landscape style.
1673
1674 NOTE: Activate the new setting by restarting Emacs.
1675 Overrides `ps-print' settings locally."
1676 :type 'boolean
1677 :group 'vhdl-print)
1678
1679 (defcustom vhdl-print-customize-faces t
1680 "*Non-nil means use an optimized set of faces for postscript printing.
1681
1682 NOTE: Activate the new setting by restarting Emacs.
1683 Overrides `ps-print' settings locally."
1684 :type 'boolean
1685 :group 'vhdl-print)
1686
1687
1688 (defgroup vhdl-misc nil
1689 "Miscellaneous customizations."
1690 :group 'vhdl)
1691
1692 (defcustom vhdl-intelligent-tab t
1693 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1694 That is, if preceeding character is part of a word then complete word,
1695 else if not at beginning of line then insert tab,
1696 else if last command was a `TAB' or `RET' then dedent one step,
1697 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1698 If nil, TAB always indents current line (i.e. `TAB' is bound to
1699 `indent-according-to-mode').
1700
1701 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1702 \"Activate Options\"."
1703 :type 'boolean
1704 :group 'vhdl-misc)
1705
1706 (defcustom vhdl-indent-syntax-based t
1707 "*Non-nil means indent lines of code based on their syntactic context.
1708 Otherwise, a line is indented like the previous nonblank line. This can be
1709 useful in large files where syntax-based indentation gets very slow."
1710 :type 'boolean
1711 :group 'vhdl-misc)
1712
1713 (defcustom vhdl-word-completion-case-sensitive nil
1714 "*Non-nil means word completion using `TAB' is case sensitive.
1715 That is, `TAB' completes words that start with the same letters and case.
1716 Otherwise, case is ignored."
1717 :type 'boolean
1718 :group 'vhdl-misc)
1719
1720 (defcustom vhdl-word-completion-in-minibuffer t
1721 "*Non-nil enables word completion in minibuffer (for template prompts).
1722
1723 NOTE: Activate the new setting by restarting Emacs."
1724 :type 'boolean
1725 :group 'vhdl-misc)
1726
1727 (defcustom vhdl-underscore-is-part-of-word nil
1728 "*Non-nil means consider the underscore character `_' as part of word.
1729 An identifier containing underscores is then treated as a single word in
1730 select and move operations. All parts of an identifier separated by underscore
1731 are treated as single words otherwise.
1732
1733 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1734 \"Activate Options\"."
1735 :type 'boolean
1736 :set (lambda (variable value)
1737 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1738 :group 'vhdl-misc)
1739
1740
1741 (defgroup vhdl-related nil
1742 "Related general customizations."
1743 :group 'vhdl)
1744
1745 ;; add related general customizations
1746 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1747 (if vhdl-xemacs
1748 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1749 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1750 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1751 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1752 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1753 (unless vhdl-xemacs
1754 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1755 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1756 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1757 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1758
1759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1760 ;; Internal variables
1761
1762 (defvar vhdl-menu-max-size 20
1763 "*Specifies the maximum size of a menu before splitting it into submenues.")
1764
1765 (defvar vhdl-progress-interval 1
1766 "*Interval used to update progress status during long operations.
1767 If a number, percentage complete gets updated after each interval of
1768 that many seconds. To inhibit all messages, set this option to nil.")
1769
1770 (defvar vhdl-inhibit-startup-warnings-p nil
1771 "*If non-nil, inhibits start up compatibility warnings.")
1772
1773 (defvar vhdl-strict-syntax-p nil
1774 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1775 If the syntactic symbol for a particular line does not match a symbol
1776 in the offsets alist, an error is generated, otherwise no error is
1777 reported and the syntactic symbol is ignored.")
1778
1779 (defvar vhdl-echo-syntactic-information-p nil
1780 "*If non-nil, syntactic info is echoed when the line is indented.")
1781
1782 (defconst vhdl-offsets-alist-default
1783 '((string . -1000)
1784 (block-open . 0)
1785 (block-close . 0)
1786 (statement . 0)
1787 (statement-cont . vhdl-lineup-statement-cont)
1788 (statement-block-intro . +)
1789 (statement-case-intro . +)
1790 (case-alternative . +)
1791 (comment . vhdl-lineup-comment)
1792 (arglist-intro . +)
1793 (arglist-cont . 0)
1794 (arglist-cont-nonempty . vhdl-lineup-arglist)
1795 (arglist-close . vhdl-lineup-arglist)
1796 (entity . 0)
1797 (configuration . 0)
1798 (package . 0)
1799 (architecture . 0)
1800 (package-body . 0)
1801 )
1802 "Default settings for offsets of syntactic elements.
1803 Do not change this constant! See the variable `vhdl-offsets-alist' for
1804 more information.")
1805
1806 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1807 "*Association list of syntactic element symbols and indentation offsets.
1808 As described below, each cons cell in this list has the form:
1809
1810 (SYNTACTIC-SYMBOL . OFFSET)
1811
1812 When a line is indented, `vhdl-mode' first determines the syntactic
1813 context of the line by generating a list of symbols called syntactic
1814 elements. This list can contain more than one syntactic element and
1815 the global variable `vhdl-syntactic-context' contains the context list
1816 for the line being indented. Each element in this list is actually a
1817 cons cell of the syntactic symbol and a buffer position. This buffer
1818 position is call the relative indent point for the line. Some
1819 syntactic symbols may not have a relative indent point associated with
1820 them.
1821
1822 After the syntactic context list for a line is generated, `vhdl-mode'
1823 calculates the absolute indentation for the line by looking at each
1824 syntactic element in the list. First, it compares the syntactic
1825 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1826 finds a match, it adds the OFFSET to the column of the relative indent
1827 point. The sum of this calculation for each element in the syntactic
1828 list is the absolute offset for line being indented.
1829
1830 If the syntactic element does not match any in the `vhdl-offsets-alist',
1831 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1832 the element is ignored.
1833
1834 Actually, OFFSET can be an integer, a function, a variable, or one of
1835 the following symbols: `+', `-', `++', or `--'. These latter
1836 designate positive or negative multiples of `vhdl-basic-offset',
1837 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1838 called with a single argument containing the cons of the syntactic
1839 element symbol and the relative indent point. The function should
1840 return an integer offset.
1841
1842 Here is the current list of valid syntactic element symbols:
1843
1844 string -- inside multi-line string
1845 block-open -- statement block open
1846 block-close -- statement block close
1847 statement -- a VHDL statement
1848 statement-cont -- a continuation of a VHDL statement
1849 statement-block-intro -- the first line in a new statement block
1850 statement-case-intro -- the first line in a case alternative block
1851 case-alternative -- a case statement alternative clause
1852 comment -- a line containing only a comment
1853 arglist-intro -- the first line in an argument list
1854 arglist-cont -- subsequent argument list lines when no
1855 arguments follow on the same line as the
1856 the arglist opening paren
1857 arglist-cont-nonempty -- subsequent argument list lines when at
1858 least one argument follows on the same
1859 line as the arglist opening paren
1860 arglist-close -- the solo close paren of an argument list
1861 entity -- inside an entity declaration
1862 configuration -- inside a configuration declaration
1863 package -- inside a package declaration
1864 architecture -- inside an architecture body
1865 package-body -- inside a package body")
1866
1867 (defvar vhdl-comment-only-line-offset 0
1868 "*Extra offset for line which contains only the start of a comment.
1869 Can contain an integer or a cons cell of the form:
1870
1871 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1872
1873 Where NON-ANCHORED-OFFSET is the amount of offset given to
1874 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1875 the amount of offset to give column-zero anchored comment-only lines.
1876 Just an integer as value is equivalent to (<val> . 0)")
1877
1878 (defvar vhdl-special-indent-hook nil
1879 "*Hook for user defined special indentation adjustments.
1880 This hook gets called after a line is indented by the mode.")
1881
1882 (defvar vhdl-style-alist
1883 '(("IEEE"
1884 (vhdl-basic-offset . 4)
1885 (vhdl-offsets-alist . ())))
1886 "Styles of Indentation.
1887 Elements of this alist are of the form:
1888
1889 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1890
1891 where STYLE-STRING is a short descriptive string used to select a
1892 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1893 value for that variable when using the selected style.
1894
1895 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1896 case, the VALUE is a list containing elements of the form:
1897
1898 (SYNTACTIC-SYMBOL . VALUE)
1899
1900 as described in `vhdl-offsets-alist'. These are passed directly to
1901 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1902 your style, only those that are different from the default.")
1903
1904 ;; dynamically append the default value of most variables
1905 (or (assoc "Default" vhdl-style-alist)
1906 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1907 vhdl-strict-syntax-p
1908 vhdl-echo-syntactic-information-p
1909 vhdl-basic-offset
1910 vhdl-offsets-alist
1911 vhdl-comment-only-line-offset))
1912 (default (cons "Default"
1913 (mapcar
1914 (function
1915 (lambda (var)
1916 (cons var (symbol-value var))))
1917 varlist))))
1918 (setq vhdl-style-alist (cons default vhdl-style-alist))))
1919
1920 (defvar vhdl-mode-hook nil
1921 "*Hook called by `vhdl-mode'.")
1922
1923
1924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1925 ;;; Required packages
1926 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1927
1928 ;; mandatory
1929 (require 'assoc)
1930 (require 'compile) ; XEmacs
1931 (require 'easymenu)
1932 (require 'hippie-exp)
1933
1934 ;; optional (minimize warning messages during compile)
1935 (eval-when-compile
1936 (require 'font-lock)
1937 (require 'ps-print)
1938 (require 'speedbar))
1939
1940
1941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1942 ;;; Compatibility
1943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1944
1945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1946 ;; XEmacs compatibility
1947
1948 ;; active regions
1949 (defun vhdl-keep-region-active ()
1950 "Do whatever is necessary to keep the region active in XEmacs.
1951 Ignore byte-compiler warnings you might see."
1952 (and (boundp 'zmacs-region-stays)
1953 (setq zmacs-region-stays t)))
1954
1955 ;; `wildcard-to-regexp' is included only in XEmacs 21
1956 (unless (fboundp 'wildcard-to-regexp)
1957 (defun wildcard-to-regexp (wildcard)
1958 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
1959 (let* ((i (string-match "[*?]" wildcard))
1960 (result (substring wildcard 0 i))
1961 (len (length wildcard)))
1962 (when i
1963 (while (< i len)
1964 (let ((ch (aref wildcard i)))
1965 (setq result (concat result
1966 (cond ((eq ch ?*) "[^\000]*")
1967 ((eq ch ??) "[^\000]")
1968 (t (char-to-string ch)))))
1969 (setq i (1+ i)))))
1970 (concat "\\`" result "\\'"))))
1971
1972 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
1973 ;; `regexp-opt' accelerates fontification by 10-20%
1974 (unless (fboundp 'regexp-opt)
1975 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
1976 (defun regexp-opt (strings &optional paren)
1977 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
1978 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
1979
1980 ;; `match-string-no-properties' undefined (XEmacs, what else?)
1981 (unless (fboundp 'match-string-no-properties)
1982 (defalias 'match-string-no-properties 'match-string))
1983
1984 ;; `subst-char-in-string' undefined (XEmacs)
1985 (unless (fboundp 'subst-char-in-string)
1986 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1987 (let ((i (length string))
1988 (newstr (if inplace string (copy-sequence string))))
1989 (while (> i 0)
1990 (setq i (1- i))
1991 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
1992 newstr)))
1993
1994 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
1995 (when (and vhdl-xemacs (string< itimer-version "1.09")
1996 (not noninteractive))
1997 (load "itimer")
1998 (when (string< itimer-version "1.09")
1999 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2000 (beep) (sit-for 5)))
2001
2002 ;; `file-expand-wildcards' undefined (XEmacs)
2003 (unless (fboundp 'file-expand-wildcards)
2004 (defun file-expand-wildcards (pattern &optional full)
2005 "Taken from Emacs' `files.el'."
2006 (let* ((nondir (file-name-nondirectory pattern))
2007 (dirpart (file-name-directory pattern))
2008 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2009 (mapcar 'file-name-as-directory
2010 (file-expand-wildcards (directory-file-name dirpart)))
2011 (list dirpart)))
2012 contents)
2013 (while dirs
2014 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2015 (file-directory-p (directory-file-name (car dirs))))
2016 (let ((this-dir-contents
2017 (delq nil
2018 (mapcar #'(lambda (name)
2019 (unless (string-match "\\`\\.\\.?\\'"
2020 (file-name-nondirectory name))
2021 name))
2022 (directory-files (or (car dirs) ".") full
2023 (wildcard-to-regexp nondir))))))
2024 (setq contents
2025 (nconc
2026 (if (and (car dirs) (not full))
2027 (mapcar (function (lambda (name) (concat (car dirs) name)))
2028 this-dir-contents)
2029 this-dir-contents)
2030 contents))))
2031 (setq dirs (cdr dirs)))
2032 contents)))
2033
2034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2035 ;; Compatibility with older VHDL Mode versions
2036
2037 (defvar vhdl-warnings nil
2038 "Warnings to tell the user during start up.")
2039
2040 (defun vhdl-run-when-idle (secs repeat function)
2041 "Wait until idle, then run FUNCTION."
2042 (if (fboundp 'start-itimer)
2043 (start-itimer "vhdl-mode" function secs repeat t)
2044 ; (run-with-idle-timer secs repeat function)))
2045 ;; explicitely activate timer (necessary when Emacs is already idle)
2046 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2047
2048 (defun vhdl-warning-when-idle (&rest args)
2049 "Wait until idle, then print out warning STRING and beep."
2050 (if noninteractive
2051 (vhdl-warning (apply 'format args) t)
2052 (unless vhdl-warnings
2053 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2054 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2055
2056 (defun vhdl-warning (string &optional nobeep)
2057 "Print out warning STRING and beep."
2058 (message (concat "WARNING: " string))
2059 (unless (or nobeep noninteractive) (beep)))
2060
2061 (defun vhdl-print-warnings ()
2062 "Print out messages in variable `vhdl-warnings'."
2063 (let ((no-warnings (length vhdl-warnings)))
2064 (setq vhdl-warnings (nreverse vhdl-warnings))
2065 (while vhdl-warnings
2066 (message (concat "WARNING: " (car vhdl-warnings)))
2067 (setq vhdl-warnings (cdr vhdl-warnings)))
2068 (beep)
2069 (when (> no-warnings 1)
2070 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2071
2072 ;; Backward compatibility checks and fixes
2073 ;; option `vhdl-compiler' changed format
2074 (unless (stringp vhdl-compiler)
2075 (setq vhdl-compiler "ModelSim")
2076 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2077
2078 ;; option `vhdl-standard' changed format
2079 (unless (listp vhdl-standard)
2080 (setq vhdl-standard '(87 nil))
2081 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2082
2083 ;; option `vhdl-model-alist' changed format
2084 (when (= (length (car vhdl-model-alist)) 3)
2085 (let ((old-alist vhdl-model-alist)
2086 new-alist)
2087 (while old-alist
2088 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2089 (setq old-alist (cdr old-alist)))
2090 (setq vhdl-model-alist (nreverse new-alist)))
2091 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2092
2093 ;; option `vhdl-project-alist' changed format
2094 (when (= (length (car vhdl-project-alist)) 3)
2095 (let ((old-alist vhdl-project-alist)
2096 new-alist)
2097 (while old-alist
2098 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2099 (setq old-alist (cdr old-alist)))
2100 (setq vhdl-project-alist (nreverse new-alist)))
2101 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2102
2103 ;; option `vhdl-project-alist' changed format (3.31.1)
2104 (when (= (length (car vhdl-project-alist)) 4)
2105 (let ((old-alist vhdl-project-alist)
2106 new-alist elem)
2107 (while old-alist
2108 (setq elem (car old-alist))
2109 (setq new-alist
2110 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2111 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2112 new-alist))
2113 (setq old-alist (cdr old-alist)))
2114 (setq vhdl-project-alist (nreverse new-alist)))
2115 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2116
2117 ;; option `vhdl-project-alist' changed format (3.31.12)
2118 (when (= (length (car vhdl-project-alist)) 10)
2119 (let ((tmp-alist vhdl-project-alist))
2120 (while tmp-alist
2121 (setcdr (nthcdr 3 (car tmp-alist))
2122 (cons "" (nthcdr 4 (car tmp-alist))))
2123 (setq tmp-alist (cdr tmp-alist))))
2124 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2125
2126 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2127 (when (= (length (car vhdl-compiler-alist)) 7)
2128 (let ((old-alist vhdl-compiler-alist)
2129 new-alist elem)
2130 (while old-alist
2131 (setq elem (car old-alist))
2132 (setq new-alist
2133 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2134 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2135 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2136 (nth 5 elem) (nth 6 elem) nil)
2137 new-alist))
2138 (setq old-alist (cdr old-alist)))
2139 (setq vhdl-compiler-alist (nreverse new-alist)))
2140 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2141
2142 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2143 (when (= (length (car vhdl-compiler-alist)) 12)
2144 (let ((tmp-alist vhdl-compiler-alist))
2145 (while tmp-alist
2146 (setcdr (nthcdr 4 (car tmp-alist))
2147 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2148 (setq tmp-alist (cdr tmp-alist))))
2149 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2150
2151 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2152 (when (= (length (car vhdl-compiler-alist)) 13)
2153 (let ((tmp-alist vhdl-compiler-alist))
2154 (while tmp-alist
2155 (setcdr (nthcdr 3 (car tmp-alist))
2156 (cons "" (nthcdr 4 (car tmp-alist))))
2157 (setq tmp-alist (cdr tmp-alist))))
2158 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2159
2160 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2161 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2162 (let ((tmp-alist vhdl-compiler-alist))
2163 (while tmp-alist
2164 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2165 '(0 . nil))
2166 (setq tmp-alist (cdr tmp-alist))))
2167 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2168
2169 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2170 (when (equal vhdl-project "")
2171 (setq vhdl-project nil)
2172 (customize-save-variable 'vhdl-project vhdl-project))
2173
2174 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2175 (when (stringp vhdl-project-file-name)
2176 (setq vhdl-project-file-name (list vhdl-project-file-name))
2177 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2178
2179 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2180 (if (not (boundp 'speedbar-indentation-width))
2181 (defvar speedbar-indentation-width 2)
2182 ;; set default to 2 if not already customized
2183 (unless (get 'speedbar-indentation-width 'saved-value)
2184 (setq speedbar-indentation-width 2)))
2185
2186
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188 ;;; Help functions / inline substitutions / macros
2189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190
2191 (defun vhdl-standard-p (standard)
2192 "Check if STANDARD is specified as used standard."
2193 (or (eq standard (car vhdl-standard))
2194 (memq standard (cadr vhdl-standard))))
2195
2196 (defun vhdl-project-p (&optional warning)
2197 "Return non-nil if a project is displayed, i.e. directories or files are
2198 specified."
2199 (if (assoc vhdl-project vhdl-project-alist)
2200 vhdl-project
2201 (when (and vhdl-project warning)
2202 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2203 nil))
2204
2205 (defun vhdl-resolve-env-variable (string)
2206 "Resolve environment variables in STRING."
2207 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2208 (setq string (concat (match-string 1 string)
2209 (getenv (match-string 2 string))
2210 (match-string 4 string))))
2211 string)
2212
2213 (defun vhdl-default-directory ()
2214 "Return the default directory of the current project or the directory of the
2215 current buffer if no project is defined."
2216 (if (vhdl-project-p)
2217 (expand-file-name (vhdl-resolve-env-variable
2218 (nth 1 (aget vhdl-project-alist vhdl-project))))
2219 default-directory))
2220
2221 (defmacro vhdl-prepare-search-1 (&rest body)
2222 "Enable case insensitive search and switch to syntax table that includes '_',
2223 then execute BODY, and finally restore the old environment. Used for
2224 consistent searching."
2225 `(let ((case-fold-search t) ; case insensitive search
2226 (current-syntax-table (syntax-table))
2227 result
2228 (restore-prog ; program to restore enviroment
2229 '(progn
2230 ;; restore syntax table
2231 (set-syntax-table current-syntax-table))))
2232 ;; use extended syntax table
2233 (set-syntax-table vhdl-mode-ext-syntax-table)
2234 ;; execute BODY safely
2235 (setq result
2236 (condition-case info
2237 (progn ,@body)
2238 (error (eval restore-prog) ; restore environment on error
2239 (error (cadr info))))) ; pass error up
2240 ;; restore environment
2241 (eval restore-prog)
2242 result))
2243
2244 (defmacro vhdl-prepare-search-2 (&rest body)
2245 "Enable case insensitive search, switch to syntax table that includes '_',
2246 and remove `intangible' overlays, then execute BODY, and finally restore the
2247 old environment. Used for consistent searching."
2248 `(let ((case-fold-search t) ; case insensitive search
2249 (current-syntax-table (syntax-table))
2250 result overlay-all-list overlay-intangible-list overlay
2251 (restore-prog ; program to restore enviroment
2252 '(progn
2253 ;; restore syntax table
2254 (set-syntax-table current-syntax-table)
2255 ;; restore `intangible' overlays
2256 (when (fboundp 'overlay-lists)
2257 (while overlay-intangible-list
2258 (overlay-put (car overlay-intangible-list) 'intangible t)
2259 (setq overlay-intangible-list
2260 (cdr overlay-intangible-list)))))))
2261 ;; use extended syntax table
2262 (set-syntax-table vhdl-mode-ext-syntax-table)
2263 ;; remove `intangible' overlays
2264 (when (fboundp 'overlay-lists)
2265 (setq overlay-all-list (overlay-lists))
2266 (setq overlay-all-list
2267 (append (car overlay-all-list) (cdr overlay-all-list)))
2268 (while overlay-all-list
2269 (setq overlay (car overlay-all-list))
2270 (when (memq 'intangible (overlay-properties overlay))
2271 (setq overlay-intangible-list
2272 (cons overlay overlay-intangible-list))
2273 (overlay-put overlay 'intangible nil))
2274 (setq overlay-all-list (cdr overlay-all-list))))
2275 ;; execute BODY safely
2276 (setq result
2277 (condition-case info
2278 (progn ,@body)
2279 (error (eval restore-prog) ; restore environment on error
2280 (error (cadr info))))) ; pass error up
2281 ;; restore environment
2282 (eval restore-prog)
2283 result))
2284
2285 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2286 "Visit file FILE-NAME and execute BODY."
2287 `(if (null ,file-name)
2288 (progn ,@body)
2289 (unless (file-directory-p ,file-name)
2290 (let ((source-buffer (current-buffer))
2291 (visiting-buffer (find-buffer-visiting ,file-name))
2292 file-opened)
2293 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2294 (condition-case ()
2295 (progn (set-buffer (create-file-buffer ,file-name))
2296 (setq file-opened t)
2297 (vhdl-insert-file-contents ,file-name)
2298 (modify-syntax-entry ?\- ". 12" (syntax-table))
2299 (modify-syntax-entry ?\n ">" (syntax-table))
2300 (modify-syntax-entry ?\^M ">" (syntax-table))
2301 (modify-syntax-entry ?_ "w" (syntax-table))
2302 t)
2303 (error
2304 (if ,issue-error
2305 (progn
2306 (when file-opened (kill-buffer (current-buffer)))
2307 (set-buffer source-buffer)
2308 (error (format "ERROR: File cannot be opened: \"%s\"" ,file-name)))
2309 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2310 nil))))
2311 (condition-case info
2312 (progn ,@body)
2313 (error
2314 (if ,issue-error
2315 (progn
2316 (when file-opened (kill-buffer (current-buffer)))
2317 (set-buffer source-buffer)
2318 (error (cadr info)))
2319 (vhdl-warning (cadr info))))))
2320 (when file-opened (kill-buffer (current-buffer)))
2321 (set-buffer source-buffer)))))
2322
2323 (defun vhdl-insert-file-contents (filename)
2324 "Nicked from `insert-file-contents-literally', but allow coding system
2325 conversion."
2326 (let ((format-alist nil)
2327 (after-insert-file-functions nil)
2328 (jka-compr-compression-info-list nil))
2329 (insert-file-contents filename t)))
2330
2331 (defun vhdl-sort-alist (alist)
2332 "Sort alist."
2333 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2334
2335 (defun vhdl-get-subdirs (directory)
2336 "Recursively get subdirectories of DIRECTORY."
2337 (let ((dir-list (list (file-name-as-directory directory)))
2338 file-list)
2339 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2340 (while file-list
2341 (when (file-directory-p (car file-list))
2342 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2343 (setq file-list (cdr file-list)))
2344 dir-list))
2345
2346 (defun vhdl-aput (alist-symbol key &optional value)
2347 "As `aput', but delete key-value pair if VALUE is nil."
2348 (if value
2349 (aput alist-symbol key value)
2350 (adelete alist-symbol key)))
2351
2352 (defun vhdl-delete (elt list)
2353 "Delete by side effect the first occurrence of ELT as a member of LIST."
2354 (setq list (cons nil list))
2355 (let ((list1 list))
2356 (while (and (cdr list1) (not (equal elt (cadr list1))))
2357 (setq list1 (cdr list1)))
2358 (when list
2359 (setcdr list1 (cddr list1))))
2360 (cdr list))
2361
2362 (defun vhdl-speedbar-refresh (&optional key)
2363 "Refresh directory or project with name KEY."
2364 (when (and (boundp 'speedbar-frame)
2365 (frame-live-p speedbar-frame))
2366 (let ((pos (point))
2367 (last-frame (selected-frame)))
2368 (if (null key)
2369 (speedbar-refresh)
2370 (select-frame speedbar-frame)
2371 (when (save-excursion
2372 (goto-char (point-min))
2373 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2374 (goto-char (match-end 1))
2375 (speedbar-do-function-pointer)
2376 (backward-char 2)
2377 (speedbar-do-function-pointer)
2378 (message "Refreshing speedbar...done"))
2379 (select-frame last-frame)))))
2380
2381 (defun vhdl-show-messages ()
2382 "Get *Messages* buffer to show recent messages."
2383 (interactive)
2384 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2385
2386 (defun vhdl-use-direct-instantiation ()
2387 "Return whether direct instantiation is used."
2388 (or (eq vhdl-use-direct-instantiation 'always)
2389 (and (eq vhdl-use-direct-instantiation 'standard)
2390 (not (vhdl-standard-p '87)))))
2391
2392 (defun vhdl-max-marker (marker1 marker2)
2393 "Return larger marker."
2394 (if (> marker1 marker2) marker1 marker2))
2395
2396 (defun vhdl-goto-marker (marker)
2397 "Goto marker in appropriate buffer."
2398 (when (markerp marker)
2399 (set-buffer (marker-buffer marker)))
2400 (goto-char marker))
2401
2402 (defun vhdl-menu-split (list title)
2403 "Split menu LIST into several submenues, if number of
2404 elements > `vhdl-menu-max-size'."
2405 (if (> (length list) vhdl-menu-max-size)
2406 (let ((remain list)
2407 (result '())
2408 (sublist '())
2409 (menuno 1)
2410 (i 0))
2411 (while remain
2412 (setq sublist (cons (car remain) sublist))
2413 (setq remain (cdr remain))
2414 (setq i (+ i 1))
2415 (if (= i vhdl-menu-max-size)
2416 (progn
2417 (setq result (cons (cons (format "%s %s" title menuno)
2418 (nreverse sublist)) result))
2419 (setq i 0)
2420 (setq menuno (+ menuno 1))
2421 (setq sublist '()))))
2422 (and sublist
2423 (setq result (cons (cons (format "%s %s" title menuno)
2424 (nreverse sublist)) result)))
2425 (nreverse result))
2426 list))
2427
2428
2429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2430 ;;; Bindings
2431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2432
2433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2434 ;; Key bindings
2435
2436 (defvar vhdl-template-map nil
2437 "Keymap for VHDL templates.")
2438
2439 (defun vhdl-template-map-init ()
2440 "Initialize `vhdl-template-map'."
2441 (setq vhdl-template-map (make-sparse-keymap))
2442 ;; key bindings for VHDL templates
2443 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2444 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2445 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2446 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2447 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2448 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2449 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2450 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2451 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2452 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2453 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2454 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2455 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2456 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2457 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2458 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2459 (define-key vhdl-template-map "el" 'vhdl-template-else)
2460 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2461 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2462 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2463 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2464 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2465 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2466 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2467 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2468 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2469 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2470 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2471 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2472 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2473 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2474 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2475 (define-key vhdl-template-map "li" 'vhdl-template-library)
2476 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2477 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2478 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2479 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2480 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2481 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2482 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2483 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2484 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2485 (define-key vhdl-template-map "po" 'vhdl-template-port)
2486 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2487 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2488 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2489 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2490 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2491 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2492 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2493 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2494 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2495 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2496 (define-key vhdl-template-map "us" 'vhdl-template-use)
2497 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2498 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2499 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2500 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2501 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2502 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2503 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2504 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2505 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2506 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2507 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2508 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2509 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2510 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2511 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2512 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2513 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2514 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2515 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2516 (when (vhdl-standard-p 'ams)
2517 (define-key vhdl-template-map "br" 'vhdl-template-break)
2518 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2519 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2520 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2521 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2522 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2523 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2524 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2525 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2526 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2527 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2528 )
2529 (when (vhdl-standard-p 'math)
2530 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2531 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2532 ))
2533
2534 ;; initialize template map for VHDL Mode
2535 (vhdl-template-map-init)
2536
2537 (defun vhdl-function-name (prefix string &optional postfix)
2538 "Generate a Lisp function name.
2539 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2540 STRING are replaced by `-' and substrings are converted to lower case."
2541 (let ((name prefix))
2542 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2543 (setq name
2544 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2545 (setq string (substring string (match-beginning 2))))
2546 (when postfix (setq name (concat name "-" postfix)))
2547 (intern name)))
2548
2549 (defvar vhdl-model-map nil
2550 "Keymap for VHDL models.")
2551
2552 (defun vhdl-model-map-init ()
2553 "Initialize `vhdl-model-map'."
2554 (setq vhdl-model-map (make-sparse-keymap))
2555 ;; key bindings for VHDL models
2556 (let ((model-alist vhdl-model-alist) model)
2557 (while model-alist
2558 (setq model (car model-alist))
2559 (define-key vhdl-model-map (nth 2 model)
2560 (vhdl-function-name "vhdl-model" (nth 0 model)))
2561 (setq model-alist (cdr model-alist)))))
2562
2563 ;; initialize user model map for VHDL Mode
2564 (vhdl-model-map-init)
2565
2566 (defvar vhdl-mode-map nil
2567 "Keymap for VHDL Mode.")
2568
2569 (defun vhdl-mode-map-init ()
2570 "Initialize `vhdl-mode-map'."
2571 (setq vhdl-mode-map (make-sparse-keymap))
2572 ;; template key bindings
2573 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2574 ;; model key bindings
2575 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2576 ;; standard key bindings
2577 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2578 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2579 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2580 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2581 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2582 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2583 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2584 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
2585 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2586 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2587 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2588 ;; backspace/delete key bindings
2589 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2590 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2591 (define-key vhdl-mode-map [delete] 'delete-char)
2592 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2593 ;; mode specific key bindings
2594 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2595 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2596 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2597 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2598 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2599 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2600 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2601 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2602 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2603 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2604 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2605 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2606 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2607 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2608 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2609 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2610 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2611 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
2612 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2613 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2614 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2615 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2616 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2617 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2618 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2619 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2620 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2621 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2622 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2623 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2624 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2625 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2626 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2627 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2628 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
2629 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2630 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2631 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2632 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2633 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2634 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2635 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2636 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2637 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2638 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2639 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2640 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2641 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2642 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2643 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2644 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2645 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2646 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2647 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2648 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2649 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2650 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2651 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2652 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2653 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2654 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2655 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2656 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2657 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2658 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2659 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2660 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2661 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2662 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2663 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2664 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2665 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2666 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2667 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2668 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2669 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2670 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2671 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2672 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2673 ;; insert commands bindings
2674 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2675 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2676 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2677 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2678 ;; electric key bindings
2679 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2680 (if vhdl-intelligent-tab
2681 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab)
2682 ;; The default binding of TAB already calls `indent-according-to-mode'.
2683 ;; (define-key vhdl-mode-map "\t" 'indent-according-to-mode)
2684 )
2685 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2686 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2687 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2688 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2689 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2690 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2691 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2692 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2693 (when (vhdl-standard-p 'ams)
2694 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2695
2696 ;; initialize mode map for VHDL Mode
2697 (vhdl-mode-map-init)
2698
2699 ;; define special minibuffer keymap for enabling word completion in minibuffer
2700 ;; (useful in template generator prompts)
2701 (defvar vhdl-minibuffer-local-map
2702 (let ((map (make-sparse-keymap)))
2703 (set-keymap-parent map minibuffer-local-map)
2704 (when vhdl-word-completion-in-minibuffer
2705 (define-key map "\t" 'vhdl-minibuffer-tab))
2706 map)
2707 "Keymap for minibuffer used in VHDL Mode.")
2708
2709 ;; set up electric character functions to work with
2710 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2711 (mapcar
2712 (function
2713 (lambda (sym)
2714 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2715 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2716 '(vhdl-electric-space
2717 vhdl-electric-tab
2718 vhdl-electric-return
2719 vhdl-electric-dash
2720 vhdl-electric-open-bracket
2721 vhdl-electric-close-bracket
2722 vhdl-electric-quote
2723 vhdl-electric-semicolon
2724 vhdl-electric-comma
2725 vhdl-electric-period
2726 vhdl-electric-equal))
2727
2728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2729 ;; Syntax table
2730
2731 (defvar vhdl-mode-syntax-table nil
2732 "Syntax table used in `vhdl-mode' buffers.")
2733
2734 (defvar vhdl-mode-ext-syntax-table nil
2735 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2736
2737 (defun vhdl-mode-syntax-table-init ()
2738 "Initialize `vhdl-mode-syntax-table'."
2739 (setq vhdl-mode-syntax-table (make-syntax-table))
2740 ;; define punctuation
2741 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2742 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2743 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2744 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2745 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2746 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2747 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2748 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2749 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2750 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2751 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2752 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2753 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2754 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2755 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2756 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2757 ;; define string
2758 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2759 ;; define underscore
2760 (when vhdl-underscore-is-part-of-word
2761 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2762 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2763 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2764 ;; and \n and \^M end a comment
2765 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2766 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2767 ;; define parentheses to match
2768 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2769 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2770 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2771 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2772 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2773 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2774 ;; extended syntax table including '_' (for simpler search regexps)
2775 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2776 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2777
2778 ;; initialize syntax table for VHDL Mode
2779 (vhdl-mode-syntax-table-init)
2780
2781 (defvar vhdl-syntactic-context nil
2782 "Buffer local variable containing syntactic analysis list.")
2783 (make-variable-buffer-local 'vhdl-syntactic-context)
2784
2785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2786 ;; Abbrev ook bindings
2787
2788 (defvar vhdl-mode-abbrev-table nil
2789 "Abbrev table to use in `vhdl-mode' buffers.")
2790
2791 (defun vhdl-mode-abbrev-table-init ()
2792 "Initialize `vhdl-mode-abbrev-table'."
2793 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2794 (define-abbrev-table 'vhdl-mode-abbrev-table
2795 (append
2796 (when (memq 'vhdl vhdl-electric-keywords)
2797 ;; VHDL'93 keywords
2798 '(
2799 ("--" "" vhdl-template-display-comment-hook 0 t)
2800 ("abs" "" vhdl-template-default-hook 0 t)
2801 ("access" "" vhdl-template-default-hook 0 t)
2802 ("after" "" vhdl-template-default-hook 0 t)
2803 ("alias" "" vhdl-template-alias-hook 0 t)
2804 ("all" "" vhdl-template-default-hook 0 t)
2805 ("and" "" vhdl-template-default-hook 0 t)
2806 ("arch" "" vhdl-template-architecture-hook 0 t)
2807 ("architecture" "" vhdl-template-architecture-hook 0 t)
2808 ("array" "" vhdl-template-default-hook 0 t)
2809 ("assert" "" vhdl-template-assert-hook 0 t)
2810 ("attr" "" vhdl-template-attribute-hook 0 t)
2811 ("attribute" "" vhdl-template-attribute-hook 0 t)
2812 ("begin" "" vhdl-template-default-indent-hook 0 t)
2813 ("block" "" vhdl-template-block-hook 0 t)
2814 ("body" "" vhdl-template-default-hook 0 t)
2815 ("buffer" "" vhdl-template-default-hook 0 t)
2816 ("bus" "" vhdl-template-default-hook 0 t)
2817 ("case" "" vhdl-template-case-hook 0 t)
2818 ("comp" "" vhdl-template-component-hook 0 t)
2819 ("component" "" vhdl-template-component-hook 0 t)
2820 ("cond" "" vhdl-template-conditional-signal-asst-hook 0 t)
2821 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0 t)
2822 ("conf" "" vhdl-template-configuration-hook 0 t)
2823 ("configuration" "" vhdl-template-configuration-hook 0 t)
2824 ("cons" "" vhdl-template-constant-hook 0 t)
2825 ("constant" "" vhdl-template-constant-hook 0 t)
2826 ("disconnect" "" vhdl-template-disconnect-hook 0 t)
2827 ("downto" "" vhdl-template-default-hook 0 t)
2828 ("else" "" vhdl-template-else-hook 0 t)
2829 ("elseif" "" vhdl-template-elsif-hook 0 t)
2830 ("elsif" "" vhdl-template-elsif-hook 0 t)
2831 ("end" "" vhdl-template-default-indent-hook 0 t)
2832 ("entity" "" vhdl-template-entity-hook 0 t)
2833 ("exit" "" vhdl-template-exit-hook 0 t)
2834 ("file" "" vhdl-template-file-hook 0 t)
2835 ("for" "" vhdl-template-for-hook 0 t)
2836 ("func" "" vhdl-template-function-hook 0 t)
2837 ("function" "" vhdl-template-function-hook 0 t)
2838 ("generic" "" vhdl-template-generic-hook 0 t)
2839 ("group" "" vhdl-template-group-hook 0 t)
2840 ("guarded" "" vhdl-template-default-hook 0 t)
2841 ("if" "" vhdl-template-if-hook 0 t)
2842 ("impure" "" vhdl-template-default-hook 0 t)
2843 ("in" "" vhdl-template-default-hook 0 t)
2844 ("inertial" "" vhdl-template-default-hook 0 t)
2845 ("inout" "" vhdl-template-default-hook 0 t)
2846 ("inst" "" vhdl-template-instance-hook 0 t)
2847 ("instance" "" vhdl-template-instance-hook 0 t)
2848 ("is" "" vhdl-template-default-hook 0 t)
2849 ("label" "" vhdl-template-default-hook 0 t)
2850 ("library" "" vhdl-template-library-hook 0 t)
2851 ("linkage" "" vhdl-template-default-hook 0 t)
2852 ("literal" "" vhdl-template-default-hook 0 t)
2853 ("loop" "" vhdl-template-bare-loop-hook 0 t)
2854 ("map" "" vhdl-template-map-hook 0 t)
2855 ("mod" "" vhdl-template-default-hook 0 t)
2856 ("nand" "" vhdl-template-default-hook 0 t)
2857 ("new" "" vhdl-template-default-hook 0 t)
2858 ("next" "" vhdl-template-next-hook 0 t)
2859 ("nor" "" vhdl-template-default-hook 0 t)
2860 ("not" "" vhdl-template-default-hook 0 t)
2861 ("null" "" vhdl-template-default-hook 0 t)
2862 ("of" "" vhdl-template-default-hook 0 t)
2863 ("on" "" vhdl-template-default-hook 0 t)
2864 ("open" "" vhdl-template-default-hook 0 t)
2865 ("or" "" vhdl-template-default-hook 0 t)
2866 ("others" "" vhdl-template-others-hook 0 t)
2867 ("out" "" vhdl-template-default-hook 0 t)
2868 ("pack" "" vhdl-template-package-hook 0 t)
2869 ("package" "" vhdl-template-package-hook 0 t)
2870 ("port" "" vhdl-template-port-hook 0 t)
2871 ("postponed" "" vhdl-template-default-hook 0 t)
2872 ("procedure" "" vhdl-template-procedure-hook 0 t)
2873 ("process" "" vhdl-template-process-hook 0 t)
2874 ("pure" "" vhdl-template-default-hook 0 t)
2875 ("range" "" vhdl-template-default-hook 0 t)
2876 ("record" "" vhdl-template-default-hook 0 t)
2877 ("register" "" vhdl-template-default-hook 0 t)
2878 ("reject" "" vhdl-template-default-hook 0 t)
2879 ("rem" "" vhdl-template-default-hook 0 t)
2880 ("report" "" vhdl-template-report-hook 0 t)
2881 ("return" "" vhdl-template-return-hook 0 t)
2882 ("rol" "" vhdl-template-default-hook 0 t)
2883 ("ror" "" vhdl-template-default-hook 0 t)
2884 ("select" "" vhdl-template-selected-signal-asst-hook 0 t)
2885 ("severity" "" vhdl-template-default-hook 0 t)
2886 ("shared" "" vhdl-template-default-hook 0 t)
2887 ("sig" "" vhdl-template-signal-hook 0 t)
2888 ("signal" "" vhdl-template-signal-hook 0 t)
2889 ("sla" "" vhdl-template-default-hook 0 t)
2890 ("sll" "" vhdl-template-default-hook 0 t)
2891 ("sra" "" vhdl-template-default-hook 0 t)
2892 ("srl" "" vhdl-template-default-hook 0 t)
2893 ("subtype" "" vhdl-template-subtype-hook 0 t)
2894 ("then" "" vhdl-template-default-hook 0 t)
2895 ("to" "" vhdl-template-default-hook 0 t)
2896 ("transport" "" vhdl-template-default-hook 0 t)
2897 ("type" "" vhdl-template-type-hook 0 t)
2898 ("unaffected" "" vhdl-template-default-hook 0 t)
2899 ("units" "" vhdl-template-default-hook 0 t)
2900 ("until" "" vhdl-template-default-hook 0 t)
2901 ("use" "" vhdl-template-use-hook 0 t)
2902 ("var" "" vhdl-template-variable-hook 0 t)
2903 ("variable" "" vhdl-template-variable-hook 0 t)
2904 ("wait" "" vhdl-template-wait-hook 0 t)
2905 ("when" "" vhdl-template-when-hook 0 t)
2906 ("while" "" vhdl-template-while-loop-hook 0 t)
2907 ("with" "" vhdl-template-with-hook 0 t)
2908 ("xnor" "" vhdl-template-default-hook 0 t)
2909 ("xor" "" vhdl-template-default-hook 0 t)
2910 ))
2911 ;; VHDL-AMS keywords
2912 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2913 '(
2914 ("across" "" vhdl-template-default-hook 0 t)
2915 ("break" "" vhdl-template-break-hook 0 t)
2916 ("limit" "" vhdl-template-limit-hook 0 t)
2917 ("nature" "" vhdl-template-nature-hook 0 t)
2918 ("noise" "" vhdl-template-default-hook 0 t)
2919 ("procedural" "" vhdl-template-procedural-hook 0 t)
2920 ("quantity" "" vhdl-template-quantity-hook 0 t)
2921 ("reference" "" vhdl-template-default-hook 0 t)
2922 ("spectrum" "" vhdl-template-default-hook 0 t)
2923 ("subnature" "" vhdl-template-subnature-hook 0 t)
2924 ("terminal" "" vhdl-template-terminal-hook 0 t)
2925 ("through" "" vhdl-template-default-hook 0 t)
2926 ("tolerance" "" vhdl-template-default-hook 0 t)
2927 ))
2928 ;; user model keywords
2929 (when (memq 'user vhdl-electric-keywords)
2930 (let ((alist vhdl-model-alist)
2931 abbrev-list keyword)
2932 (while alist
2933 (setq keyword (nth 3 (car alist)))
2934 (unless (equal keyword "")
2935 (setq abbrev-list
2936 (cons (list keyword ""
2937 (vhdl-function-name
2938 "vhdl-model" (nth 0 (car alist)) "hook") 0 t)
2939 abbrev-list)))
2940 (setq alist (cdr alist)))
2941 abbrev-list)))))
2942
2943 ;; initialize abbrev table for VHDL Mode
2944 (vhdl-mode-abbrev-table-init)
2945
2946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2947 ;; Template completion lists
2948
2949 (defvar vhdl-template-construct-alist nil
2950 "List of built-in construct templates.")
2951
2952 (defun vhdl-template-construct-alist-init ()
2953 "Initialize `vhdl-template-construct-alist'."
2954 (setq
2955 vhdl-template-construct-alist
2956 (append
2957 '(
2958 ("alias declaration" vhdl-template-alias)
2959 ("architecture body" vhdl-template-architecture)
2960 ("assertion" vhdl-template-assert)
2961 ("attribute declaration" vhdl-template-attribute-decl)
2962 ("attribute specification" vhdl-template-attribute-spec)
2963 ("block configuration" vhdl-template-block-configuration)
2964 ("block statement" vhdl-template-block)
2965 ("case statement" vhdl-template-case-is)
2966 ("component configuration" vhdl-template-component-conf)
2967 ("component declaration" vhdl-template-component-decl)
2968 ("component instantiation statement" vhdl-template-component-inst)
2969 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2970 ("configuration declaration" vhdl-template-configuration-decl)
2971 ("configuration specification" vhdl-template-configuration-spec)
2972 ("constant declaration" vhdl-template-constant)
2973 ("disconnection specification" vhdl-template-disconnect)
2974 ("entity declaration" vhdl-template-entity)
2975 ("exit statement" vhdl-template-exit)
2976 ("file declaration" vhdl-template-file)
2977 ("generate statement" vhdl-template-generate)
2978 ("generic clause" vhdl-template-generic)
2979 ("group declaration" vhdl-template-group-decl)
2980 ("group template declaration" vhdl-template-group-template)
2981 ("if statement" vhdl-template-if-then)
2982 ("library clause" vhdl-template-library)
2983 ("loop statement" vhdl-template-loop)
2984 ("next statement" vhdl-template-next)
2985 ("package declaration" vhdl-template-package-decl)
2986 ("package body" vhdl-template-package-body)
2987 ("port clause" vhdl-template-port)
2988 ("process statement" vhdl-template-process)
2989 ("report statement" vhdl-template-report)
2990 ("return statement" vhdl-template-return)
2991 ("selected signal assignment" vhdl-template-selected-signal-asst)
2992 ("signal declaration" vhdl-template-signal)
2993 ("subprogram declaration" vhdl-template-subprogram-decl)
2994 ("subprogram body" vhdl-template-subprogram-body)
2995 ("subtype declaration" vhdl-template-subtype)
2996 ("type declaration" vhdl-template-type)
2997 ("use clause" vhdl-template-use)
2998 ("variable declaration" vhdl-template-variable)
2999 ("wait statement" vhdl-template-wait)
3000 )
3001 (when (vhdl-standard-p 'ams)
3002 '(
3003 ("break statement" vhdl-template-break)
3004 ("nature declaration" vhdl-template-nature)
3005 ("quantity declaration" vhdl-template-quantity)
3006 ("simultaneous case statement" vhdl-template-case-use)
3007 ("simultaneous if statement" vhdl-template-if-use)
3008 ("simultaneous procedural statement" vhdl-template-procedural)
3009 ("step limit specification" vhdl-template-limit)
3010 ("subnature declaration" vhdl-template-subnature)
3011 ("terminal declaration" vhdl-template-terminal)
3012 )))))
3013
3014 ;; initialize for VHDL Mode
3015 (vhdl-template-construct-alist-init)
3016
3017 (defvar vhdl-template-package-alist nil
3018 "List of built-in package templates.")
3019
3020 (defun vhdl-template-package-alist-init ()
3021 "Initialize `vhdl-template-package-alist'."
3022 (setq
3023 vhdl-template-package-alist
3024 (append
3025 '(
3026 ("numeric_bit" vhdl-template-package-numeric-bit)
3027 ("numeric_std" vhdl-template-package-numeric-std)
3028 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3029 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3030 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3031 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3032 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3033 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3034 ("textio" vhdl-template-package-textio)
3035 )
3036 (when (vhdl-standard-p 'math)
3037 '(
3038 ("math_complex" vhdl-template-package-math-complex)
3039 ("math_real" vhdl-template-package-math-real)
3040 )))))
3041
3042 ;; initialize for VHDL Mode
3043 (vhdl-template-package-alist-init)
3044
3045 (defvar vhdl-template-directive-alist
3046 '(
3047 ("translate_on" vhdl-template-directive-translate-on)
3048 ("translate_off" vhdl-template-directive-translate-off)
3049 ("synthesis_on" vhdl-template-directive-synthesis-on)
3050 ("synthesis_off" vhdl-template-directive-synthesis-off)
3051 )
3052 "List of built-in directive templates.")
3053
3054
3055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3056 ;;; Menues
3057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3058
3059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3060 ;; VHDL menu (using `easy-menu.el')
3061
3062 (defun vhdl-customize ()
3063 "Call the customize function with `vhdl' as argument."
3064 (interactive)
3065 (customize-browse 'vhdl))
3066
3067 (defun vhdl-create-mode-menu ()
3068 "Create VHDL Mode menu."
3069 `("VHDL"
3070 ,(append
3071 '("Project"
3072 ["None" (vhdl-set-project "")
3073 :style radio :selected (null vhdl-project)]
3074 "--")
3075 ;; add menu entries for defined projects
3076 (let ((project-alist vhdl-project-alist) menu-list name)
3077 (while project-alist
3078 (setq name (caar project-alist))
3079 (setq menu-list
3080 (cons `[,name (vhdl-set-project ,name)
3081 :style radio :selected (equal ,name vhdl-project)]
3082 menu-list))
3083 (setq project-alist (cdr project-alist)))
3084 (setq menu-list
3085 (if vhdl-project-sort
3086 (sort menu-list
3087 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3088 (nreverse menu-list)))
3089 (vhdl-menu-split menu-list "Project"))
3090 '("--" "--"
3091 ["Select Project..." vhdl-set-project t]
3092 "--"
3093 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3094 ["Import Project..." vhdl-import-project
3095 :keys "C-c C-p C-m" :active t]
3096 ["Export Project" vhdl-export-project vhdl-project]
3097 "--"
3098 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3099 "--"
3100 ("Compile"
3101 ["Compile Buffer" vhdl-compile t]
3102 ["Stop Compilation" kill-compilation t]
3103 "--"
3104 ["Make" vhdl-make t]
3105 ["Generate Makefile" vhdl-generate-makefile t]
3106 "--"
3107 ["Next Error" next-error t]
3108 ["Previous Error" previous-error t]
3109 ["First Error" first-error t]
3110 "--"
3111 ,(append
3112 '("Compiler")
3113 ;; add menu entries for defined compilers
3114 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3115 (while comp-alist
3116 (setq name (caar comp-alist))
3117 (setq menu-list
3118 (cons `[,name (setq vhdl-compiler ,name)
3119 :style radio :selected (equal ,name vhdl-compiler)]
3120 menu-list))
3121 (setq comp-alist (cdr comp-alist)))
3122 (setq menu-list (nreverse menu-list))
3123 (vhdl-menu-split menu-list "Compiler"))
3124 '("--" "--"
3125 ["Select Compiler..." vhdl-set-compiler t]
3126 "--"
3127 ["Customize Compiler..."
3128 (customize-option 'vhdl-compiler-alist) t])))
3129 "--"
3130 ,(append
3131 '("Template"
3132 ("VHDL Construct 1"
3133 ["Alias" vhdl-template-alias t]
3134 ["Architecture" vhdl-template-architecture t]
3135 ["Assert" vhdl-template-assert t]
3136 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3137 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3138 ["Block" vhdl-template-block t]
3139 ["Case" vhdl-template-case-is t]
3140 ["Component (Decl)" vhdl-template-component-decl t]
3141 ["(Component) Instance" vhdl-template-component-inst t]
3142 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3143 ["Configuration (Block)" vhdl-template-block-configuration t]
3144 ["Configuration (Comp)" vhdl-template-component-conf t]
3145 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3146 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3147 ["Constant" vhdl-template-constant t]
3148 ["Disconnect" vhdl-template-disconnect t]
3149 ["Else" vhdl-template-else t]
3150 ["Elsif" vhdl-template-elsif t]
3151 ["Entity" vhdl-template-entity t]
3152 ["Exit" vhdl-template-exit t]
3153 ["File" vhdl-template-file t]
3154 ["For (Generate)" vhdl-template-for-generate t]
3155 ["For (Loop)" vhdl-template-for-loop t]
3156 ["Function (Body)" vhdl-template-function-body t]
3157 ["Function (Decl)" vhdl-template-function-decl t]
3158 ["Generic" vhdl-template-generic t]
3159 ["Group (Decl)" vhdl-template-group-decl t]
3160 ["Group (Template)" vhdl-template-group-template t])
3161 ("VHDL Construct 2"
3162 ["If (Generate)" vhdl-template-if-generate t]
3163 ["If (Then)" vhdl-template-if-then t]
3164 ["Library" vhdl-template-library t]
3165 ["Loop" vhdl-template-bare-loop t]
3166 ["Map" vhdl-template-map t]
3167 ["Next" vhdl-template-next t]
3168 ["Others (Aggregate)" vhdl-template-others t]
3169 ["Package (Decl)" vhdl-template-package-decl t]
3170 ["Package (Body)" vhdl-template-package-body t]
3171 ["Port" vhdl-template-port t]
3172 ["Procedure (Body)" vhdl-template-procedure-body t]
3173 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3174 ["Process (Comb)" vhdl-template-process-comb t]
3175 ["Process (Seq)" vhdl-template-process-seq t]
3176 ["Report" vhdl-template-report t]
3177 ["Return" vhdl-template-return t]
3178 ["Select" vhdl-template-selected-signal-asst t]
3179 ["Signal" vhdl-template-signal t]
3180 ["Subtype" vhdl-template-subtype t]
3181 ["Type" vhdl-template-type t]
3182 ["Use" vhdl-template-use t]
3183 ["Variable" vhdl-template-variable t]
3184 ["Wait" vhdl-template-wait t]
3185 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3186 ["When" vhdl-template-when t]
3187 ["While (Loop)" vhdl-template-while-loop t]
3188 ["With" vhdl-template-with t]))
3189 (when (vhdl-standard-p 'ams)
3190 '(("VHDL-AMS Construct"
3191 ["Break" vhdl-template-break t]
3192 ["Case (Use)" vhdl-template-case-use t]
3193 ["If (Use)" vhdl-template-if-use t]
3194 ["Limit" vhdl-template-limit t]
3195 ["Nature" vhdl-template-nature t]
3196 ["Procedural" vhdl-template-procedural t]
3197 ["Quantity (Free)" vhdl-template-quantity-free t]
3198 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3199 ["Quantity (Source)" vhdl-template-quantity-source t]
3200 ["Subnature" vhdl-template-subnature t]
3201 ["Terminal" vhdl-template-terminal t])))
3202 '(["Insert Construct..." vhdl-template-insert-construct
3203 :keys "C-c C-i C-t"]
3204 "--")
3205 (list
3206 (append
3207 '("Package")
3208 (when (vhdl-standard-p 'math)
3209 '(["math_complex" vhdl-template-package-math-complex t]
3210 ["math_real" vhdl-template-package-math-real t]))
3211 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3212 ["numeric_std" vhdl-template-package-numeric-std t]
3213 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3214 ["textio" vhdl-template-package-textio t]
3215 "--"
3216 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3217 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3218 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3219 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3220 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3221 "--"
3222 ["Insert Package..." vhdl-template-insert-package
3223 :keys "C-c C-i C-p"])))
3224 '(("Directive"
3225 ["translate_on" vhdl-template-directive-translate-on t]
3226 ["translate_off" vhdl-template-directive-translate-off t]
3227 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3228 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3229 "--"
3230 ["Insert Directive..." vhdl-template-insert-directive
3231 :keys "C-c C-i C-d"])
3232 "--"
3233 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3234 ["Insert Footer" vhdl-template-footer t]
3235 ["Insert Date" vhdl-template-insert-date t]
3236 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3237 "--"
3238 ["Query Next Prompt" vhdl-template-search-prompt t]))
3239 ,(append
3240 '("Model")
3241 ;; add menu entries for defined models
3242 (let ((model-alist vhdl-model-alist) menu-list model)
3243 (while model-alist
3244 (setq model (car model-alist))
3245 (setq menu-list
3246 (cons
3247 (vector
3248 (nth 0 model)
3249 (vhdl-function-name "vhdl-model" (nth 0 model))
3250 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3251 menu-list))
3252 (setq model-alist (cdr model-alist)))
3253 (setq menu-list (nreverse menu-list))
3254 (vhdl-menu-split menu-list "Model"))
3255 '("--" "--"
3256 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3257 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3258 ("Port"
3259 ["Copy" vhdl-port-copy t]
3260 "--"
3261 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3262 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3263 ["Paste As Instance" vhdl-port-paste-instance
3264 :keys "C-c C-p C-i" :active vhdl-port-list]
3265 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3266 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3267 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3268 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3269 "--"
3270 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3271 "--"
3272 ["Flatten" vhdl-port-flatten
3273 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3274 ["Reverse Direction" vhdl-port-reverse-direction
3275 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3276 ("Compose"
3277 ["New Component" vhdl-compose-new-component t]
3278 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3279 ["Wire Components" vhdl-compose-wire-components t]
3280 "--"
3281 ["Generate Components Package" vhdl-compose-components-package t])
3282 ("Subprogram"
3283 ["Copy" vhdl-subprog-copy t]
3284 "--"
3285 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3286 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3287 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3288 "--"
3289 ["Flatten" vhdl-subprog-flatten
3290 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3291 "--"
3292 ("Comment"
3293 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3294 "--"
3295 ["Insert Inline Comment" vhdl-comment-append-inline t]
3296 ["Insert Horizontal Line" vhdl-comment-display-line t]
3297 ["Insert Display Comment" vhdl-comment-display t]
3298 "--"
3299 ["Fill Comment" fill-paragraph t]
3300 ["Fill Comment Region" fill-region (mark)]
3301 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3302 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3303 ("Line"
3304 ["Kill" vhdl-line-kill t]
3305 ["Copy" vhdl-line-copy t]
3306 ["Yank" vhdl-line-yank t]
3307 ["Expand" vhdl-line-expand t]
3308 "--"
3309 ["Transpose Next" vhdl-line-transpose-next t]
3310 ["Transpose Prev" vhdl-line-transpose-previous t]
3311 ["Open" vhdl-line-open t]
3312 ["Join" vhdl-delete-indentation t]
3313 "--"
3314 ["Goto" goto-line t]
3315 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3316 ("Move"
3317 ["Forward Statement" vhdl-end-of-statement t]
3318 ["Backward Statement" vhdl-beginning-of-statement t]
3319 ["Forward Expression" vhdl-forward-sexp t]
3320 ["Backward Expression" vhdl-backward-sexp t]
3321 ["Forward Same Indent" vhdl-forward-same-indent t]
3322 ["Backward Same Indent" vhdl-backward-same-indent t]
3323 ["Forward Function" vhdl-end-of-defun t]
3324 ["Backward Function" vhdl-beginning-of-defun t]
3325 ["Mark Function" vhdl-mark-defun t])
3326 "--"
3327 ("Indent"
3328 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3329 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3330 ["Region" vhdl-indent-region (mark)]
3331 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3332 ("Align"
3333 ["Group" vhdl-align-group t]
3334 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3335 ["List" vhdl-align-list t]
3336 ["Declarations" vhdl-align-declarations t]
3337 ["Region" vhdl-align-region (mark)]
3338 ["Buffer" vhdl-align-buffer t]
3339 "--"
3340 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3341 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3342 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3343 ("Fill"
3344 ["List" vhdl-fill-list t]
3345 ["Group" vhdl-fill-group t]
3346 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3347 ["Region" vhdl-fill-region (mark)])
3348 ("Beautify"
3349 ["Region" vhdl-beautify-region (mark)]
3350 ["Buffer" vhdl-beautify-buffer t])
3351 ("Fix"
3352 ["Generic/Port Clause" vhdl-fix-clause t]
3353 "--"
3354 ["Case Region" vhdl-fix-case-region (mark)]
3355 ["Case Buffer" vhdl-fix-case-buffer t]
3356 "--"
3357 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3358 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3359 "--"
3360 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3361 ("Update"
3362 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3363 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3364 "--"
3365 ["Fontify Buffer" vhdl-fontify-buffer t]
3366 ["Statistics Buffer" vhdl-statistics-buffer t]
3367 ["Show Messages" vhdl-show-messages t]
3368 ["Syntactic Info" vhdl-show-syntactic-information t]
3369 "--"
3370 ["Speedbar" vhdl-speedbar t]
3371 ["Hide/Show" vhdl-hs-minor-mode t]
3372 "--"
3373 ("Documentation"
3374 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3375 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3376 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3377 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3378 ["Version" vhdl-version t]
3379 ["Bug Report..." vhdl-submit-bug-report t]
3380 "--"
3381 ("Options"
3382 ("Mode"
3383 ["Electric Mode"
3384 (progn (customize-set-variable 'vhdl-electric-mode
3385 (not vhdl-electric-mode))
3386 (vhdl-mode-line-update))
3387 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3388 ["Stutter Mode"
3389 (progn (customize-set-variable 'vhdl-stutter-mode
3390 (not vhdl-stutter-mode))
3391 (vhdl-mode-line-update))
3392 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3393 ["Indent Tabs Mode"
3394 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3395 (not vhdl-indent-tabs-mode))
3396 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3397 :style toggle :selected vhdl-indent-tabs-mode]
3398 "--"
3399 ["Customize Group..." (customize-group 'vhdl-mode) t])
3400 ("Project"
3401 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3402 ,(append
3403 '("Selected Project at Startup"
3404 ["None" (progn (customize-set-variable 'vhdl-project nil)
3405 (vhdl-set-project ""))
3406 :style radio :selected (null vhdl-project)]
3407 "--")
3408 ;; add menu entries for defined projects
3409 (let ((project-alist vhdl-project-alist) menu-list name)
3410 (while project-alist
3411 (setq name (caar project-alist))
3412 (setq menu-list
3413 (cons `[,name (progn (customize-set-variable
3414 'vhdl-project ,name)
3415 (vhdl-set-project ,name))
3416 :style radio :selected (equal ,name vhdl-project)]
3417 menu-list))
3418 (setq project-alist (cdr project-alist)))
3419 (setq menu-list (nreverse menu-list))
3420 (vhdl-menu-split menu-list "Project")))
3421 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3422 ("Auto Load Setup File"
3423 ["At Startup"
3424 (customize-set-variable 'vhdl-project-auto-load
3425 (if (memq 'startup vhdl-project-auto-load)
3426 (delq 'startup vhdl-project-auto-load)
3427 (cons 'startup vhdl-project-auto-load)))
3428 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3429 ["Sort Projects"
3430 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3431 :style toggle :selected vhdl-project-sort]
3432 "--"
3433 ["Customize Group..." (customize-group 'vhdl-project) t])
3434 ("Compiler"
3435 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3436 ,(append
3437 '("Selected Compiler at Startup")
3438 ;; add menu entries for defined compilers
3439 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3440 (while comp-alist
3441 (setq name (caar comp-alist))
3442 (setq menu-list
3443 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3444 :style radio :selected (equal ,name vhdl-compiler)]
3445 menu-list))
3446 (setq comp-alist (cdr comp-alist)))
3447 (setq menu-list (nreverse menu-list))
3448 (vhdl-menu-split menu-list "Compler")))
3449 ["Use Local Error Regexp"
3450 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3451 (not vhdl-compile-use-local-error-regexp))
3452 :style toggle :selected vhdl-compile-use-local-error-regexp]
3453 ["Makefile Generation Hook..."
3454 (customize-option 'vhdl-makefile-generation-hook) t]
3455 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3456 "--"
3457 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3458 ("Style"
3459 ("VHDL Standard"
3460 ["VHDL'87"
3461 (progn (customize-set-variable 'vhdl-standard
3462 (list '87 (cadr vhdl-standard)))
3463 (vhdl-activate-customizations))
3464 :style radio :selected (eq '87 (car vhdl-standard))]
3465 ["VHDL'93"
3466 (progn (customize-set-variable 'vhdl-standard
3467 (list '93 (cadr vhdl-standard)))
3468 (vhdl-activate-customizations))
3469 :style radio :selected (eq '93 (car vhdl-standard))]
3470 "--"
3471 ["VHDL-AMS"
3472 (progn (customize-set-variable
3473 'vhdl-standard (list (car vhdl-standard)
3474 (if (memq 'ams (cadr vhdl-standard))
3475 (delq 'ams (cadr vhdl-standard))
3476 (cons 'ams (cadr vhdl-standard)))))
3477 (vhdl-activate-customizations))
3478 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3479 ["Math Packages"
3480 (progn (customize-set-variable
3481 'vhdl-standard (list (car vhdl-standard)
3482 (if (memq 'math (cadr vhdl-standard))
3483 (delq 'math (cadr vhdl-standard))
3484 (cons 'math (cadr vhdl-standard)))))
3485 (vhdl-activate-customizations))
3486 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3487 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3488 ["Upper Case Keywords"
3489 (customize-set-variable 'vhdl-upper-case-keywords
3490 (not vhdl-upper-case-keywords))
3491 :style toggle :selected vhdl-upper-case-keywords]
3492 ["Upper Case Types"
3493 (customize-set-variable 'vhdl-upper-case-types
3494 (not vhdl-upper-case-types))
3495 :style toggle :selected vhdl-upper-case-types]
3496 ["Upper Case Attributes"
3497 (customize-set-variable 'vhdl-upper-case-attributes
3498 (not vhdl-upper-case-attributes))
3499 :style toggle :selected vhdl-upper-case-attributes]
3500 ["Upper Case Enumeration Values"
3501 (customize-set-variable 'vhdl-upper-case-enum-values
3502 (not vhdl-upper-case-enum-values))
3503 :style toggle :selected vhdl-upper-case-enum-values]
3504 ["Upper Case Constants"
3505 (customize-set-variable 'vhdl-upper-case-constants
3506 (not vhdl-upper-case-constants))
3507 :style toggle :selected vhdl-upper-case-constants]
3508 ("Use Direct Instantiation"
3509 ["Never"
3510 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3511 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3512 ["Standard"
3513 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3514 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3515 ["Always"
3516 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3517 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3518 "--"
3519 ["Customize Group..." (customize-group 'vhdl-style) t])
3520 ("Naming"
3521 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3522 ["Architecture File Name..."
3523 (customize-option 'vhdl-architecture-file-name) t]
3524 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3525 ("File Name Case"
3526 ["As Is"
3527 (customize-set-variable 'vhdl-file-name-case 'identity)
3528 :style radio :selected (eq 'identity vhdl-file-name-case)]
3529 ["Lower Case"
3530 (customize-set-variable 'vhdl-file-name-case 'downcase)
3531 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3532 ["Upper Case"
3533 (customize-set-variable 'vhdl-file-name-case 'upcase)
3534 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3535 ["Capitalize"
3536 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3537 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3538 "--"
3539 ["Customize Group..." (customize-group 'vhdl-naming) t])
3540 ("Template"
3541 ("Electric Keywords"
3542 ["VHDL Keywords"
3543 (customize-set-variable 'vhdl-electric-keywords
3544 (if (memq 'vhdl vhdl-electric-keywords)
3545 (delq 'vhdl vhdl-electric-keywords)
3546 (cons 'vhdl vhdl-electric-keywords)))
3547 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3548 ["User Model Keywords"
3549 (customize-set-variable 'vhdl-electric-keywords
3550 (if (memq 'user vhdl-electric-keywords)
3551 (delq 'user vhdl-electric-keywords)
3552 (cons 'user vhdl-electric-keywords)))
3553 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3554 ("Insert Optional Labels"
3555 ["None"
3556 (customize-set-variable 'vhdl-optional-labels 'none)
3557 :style radio :selected (eq 'none vhdl-optional-labels)]
3558 ["Processes Only"
3559 (customize-set-variable 'vhdl-optional-labels 'process)
3560 :style radio :selected (eq 'process vhdl-optional-labels)]
3561 ["All Constructs"
3562 (customize-set-variable 'vhdl-optional-labels 'all)
3563 :style radio :selected (eq 'all vhdl-optional-labels)])
3564 ("Insert Empty Lines"
3565 ["None"
3566 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3567 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3568 ["Design Units Only"
3569 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3570 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3571 ["All Constructs"
3572 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3573 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3574 ["Argument List Indent"
3575 (customize-set-variable 'vhdl-argument-list-indent
3576 (not vhdl-argument-list-indent))
3577 :style toggle :selected vhdl-argument-list-indent]
3578 ["Association List with Formals"
3579 (customize-set-variable 'vhdl-association-list-with-formals
3580 (not vhdl-association-list-with-formals))
3581 :style toggle :selected vhdl-association-list-with-formals]
3582 ["Conditions in Parenthesis"
3583 (customize-set-variable 'vhdl-conditions-in-parenthesis
3584 (not vhdl-conditions-in-parenthesis))
3585 :style toggle :selected vhdl-conditions-in-parenthesis]
3586 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3587 ["One String..." (customize-option 'vhdl-one-string) t]
3588 ("File Header"
3589 ["Header String..." (customize-option 'vhdl-file-header) t]
3590 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3591 ["Company Name..." (customize-option 'vhdl-company-name) t]
3592 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3593 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3594 ["Date Format..." (customize-option 'vhdl-date-format) t]
3595 ["Modify Date Prefix String..."
3596 (customize-option 'vhdl-modify-date-prefix-string) t]
3597 ["Modify Date on Saving"
3598 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3599 (not vhdl-modify-date-on-saving))
3600 (vhdl-activate-customizations))
3601 :style toggle :selected vhdl-modify-date-on-saving])
3602 ("Sequential Process"
3603 ("Kind of Reset"
3604 ["None"
3605 (customize-set-variable 'vhdl-reset-kind 'none)
3606 :style radio :selected (eq 'none vhdl-reset-kind)]
3607 ["Synchronous"
3608 (customize-set-variable 'vhdl-reset-kind 'sync)
3609 :style radio :selected (eq 'sync vhdl-reset-kind)]
3610 ["Asynchronous"
3611 (customize-set-variable 'vhdl-reset-kind 'async)
3612 :style radio :selected (eq 'async vhdl-reset-kind)])
3613 ["Reset is Active High"
3614 (customize-set-variable 'vhdl-reset-active-high
3615 (not vhdl-reset-active-high))
3616 :style toggle :selected vhdl-reset-active-high]
3617 ["Use Rising Clock Edge"
3618 (customize-set-variable 'vhdl-clock-rising-edge
3619 (not vhdl-clock-rising-edge))
3620 :style toggle :selected vhdl-clock-rising-edge]
3621 ("Clock Edge Condition"
3622 ["Standard"
3623 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3624 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3625 ["Function \"rising_edge\""
3626 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3627 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3628 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3629 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3630 "--"
3631 ["Customize Group..." (customize-group 'vhdl-template) t])
3632 ("Model"
3633 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3634 ("Port"
3635 ["Include Port Comments"
3636 (customize-set-variable 'vhdl-include-port-comments
3637 (not vhdl-include-port-comments))
3638 :style toggle :selected vhdl-include-port-comments]
3639 ["Include Direction Comments"
3640 (customize-set-variable 'vhdl-include-direction-comments
3641 (not vhdl-include-direction-comments))
3642 :style toggle :selected vhdl-include-direction-comments]
3643 ["Include Type Comments"
3644 (customize-set-variable 'vhdl-include-type-comments
3645 (not vhdl-include-type-comments))
3646 :style toggle :selected vhdl-include-type-comments]
3647 ("Include Group Comments"
3648 ["Never"
3649 (customize-set-variable 'vhdl-include-group-comments 'never)
3650 :style radio :selected (eq 'never vhdl-include-group-comments)]
3651 ["Declarations"
3652 (customize-set-variable 'vhdl-include-group-comments 'decl)
3653 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3654 ["Always"
3655 (customize-set-variable 'vhdl-include-group-comments 'always)
3656 :style radio :selected (eq 'always vhdl-include-group-comments)])
3657 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3658 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3659 ("Testbench"
3660 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3661 ["Architecture Name..."
3662 (customize-option 'vhdl-testbench-architecture-name) t]
3663 ["Configuration Name..."
3664 (customize-option 'vhdl-testbench-configuration-name) t]
3665 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3666 ["Include Header"
3667 (customize-set-variable 'vhdl-testbench-include-header
3668 (not vhdl-testbench-include-header))
3669 :style toggle :selected vhdl-testbench-include-header]
3670 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3671 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3672 ["Initialize Signals"
3673 (customize-set-variable 'vhdl-testbench-initialize-signals
3674 (not vhdl-testbench-initialize-signals))
3675 :style toggle :selected vhdl-testbench-initialize-signals]
3676 ["Include Library Clause"
3677 (customize-set-variable 'vhdl-testbench-include-library
3678 (not vhdl-testbench-include-library))
3679 :style toggle :selected vhdl-testbench-include-library]
3680 ["Include Configuration"
3681 (customize-set-variable 'vhdl-testbench-include-configuration
3682 (not vhdl-testbench-include-configuration))
3683 :style toggle :selected vhdl-testbench-include-configuration]
3684 ("Create Files"
3685 ["None"
3686 (customize-set-variable 'vhdl-testbench-create-files 'none)
3687 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3688 ["Single"
3689 (customize-set-variable 'vhdl-testbench-create-files 'single)
3690 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3691 ["Separate"
3692 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3693 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3694 "--"
3695 ["Customize Group..." (customize-group 'vhdl-port) t])
3696 ("Compose"
3697 ("Create Files"
3698 ["None"
3699 (customize-set-variable 'vhdl-compose-create-files 'none)
3700 :style radio :selected (eq 'none vhdl-compose-create-files)]
3701 ["Single"
3702 (customize-set-variable 'vhdl-compose-create-files 'single)
3703 :style radio :selected (eq 'single vhdl-compose-create-files)]
3704 ["Separate"
3705 (customize-set-variable 'vhdl-compose-create-files 'separate)
3706 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3707 ["Include Header"
3708 (customize-set-variable 'vhdl-compose-include-header
3709 (not vhdl-compose-include-header))
3710 :style toggle :selected vhdl-compose-include-header]
3711 ["Architecture Name..."
3712 (customize-option 'vhdl-compose-architecture-name) t]
3713 ["Components Package Name..."
3714 (customize-option 'vhdl-components-package-name) t]
3715 ["Use Components Package"
3716 (customize-set-variable 'vhdl-use-components-package
3717 (not vhdl-use-components-package))
3718 :style toggle :selected vhdl-use-components-package]
3719 "--"
3720 ["Customize Group..." (customize-group 'vhdl-compose) t])
3721 ("Comment"
3722 ["Self Insert Comments"
3723 (customize-set-variable 'vhdl-self-insert-comments
3724 (not vhdl-self-insert-comments))
3725 :style toggle :selected vhdl-self-insert-comments]
3726 ["Prompt for Comments"
3727 (customize-set-variable 'vhdl-prompt-for-comments
3728 (not vhdl-prompt-for-comments))
3729 :style toggle :selected vhdl-prompt-for-comments]
3730 ["Inline Comment Column..."
3731 (customize-option 'vhdl-inline-comment-column) t]
3732 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3733 "--"
3734 ["Customize Group..." (customize-group 'vhdl-comment) t])
3735 ("Align"
3736 ["Auto Align Templates"
3737 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3738 :style toggle :selected vhdl-auto-align]
3739 ["Align Line Groups"
3740 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3741 :style toggle :selected vhdl-align-groups]
3742 ["Group Separation String..."
3743 (customize-set-variable 'vhdl-align-group-separate) t]
3744 ["Align Lines with Same Indent"
3745 (customize-set-variable 'vhdl-align-same-indent
3746 (not vhdl-align-same-indent))
3747 :style toggle :selected vhdl-align-same-indent]
3748 "--"
3749 ["Customize Group..." (customize-group 'vhdl-align) t])
3750 ("Highlight"
3751 ["Highlighting On/Off..."
3752 (customize-option
3753 (if (fboundp 'global-font-lock-mode)
3754 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3755 ["Highlight Keywords"
3756 (progn (customize-set-variable 'vhdl-highlight-keywords
3757 (not vhdl-highlight-keywords))
3758 (vhdl-fontify-buffer))
3759 :style toggle :selected vhdl-highlight-keywords]
3760 ["Highlight Names"
3761 (progn (customize-set-variable 'vhdl-highlight-names
3762 (not vhdl-highlight-names))
3763 (vhdl-fontify-buffer))
3764 :style toggle :selected vhdl-highlight-names]
3765 ["Highlight Special Words"
3766 (progn (customize-set-variable 'vhdl-highlight-special-words
3767 (not vhdl-highlight-special-words))
3768 (vhdl-fontify-buffer))
3769 :style toggle :selected vhdl-highlight-special-words]
3770 ["Highlight Forbidden Words"
3771 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3772 (not vhdl-highlight-forbidden-words))
3773 (vhdl-fontify-buffer))
3774 :style toggle :selected vhdl-highlight-forbidden-words]
3775 ["Highlight Verilog Keywords"
3776 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3777 (not vhdl-highlight-verilog-keywords))
3778 (vhdl-fontify-buffer))
3779 :style toggle :selected vhdl-highlight-verilog-keywords]
3780 ["Highlight \"translate_off\""
3781 (progn (customize-set-variable 'vhdl-highlight-translate-off
3782 (not vhdl-highlight-translate-off))
3783 (vhdl-fontify-buffer))
3784 :style toggle :selected vhdl-highlight-translate-off]
3785 ["Case Sensitive Highlighting"
3786 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3787 (not vhdl-highlight-case-sensitive))
3788 (vhdl-fontify-buffer))
3789 :style toggle :selected vhdl-highlight-case-sensitive]
3790 ["Special Syntax Definition..."
3791 (customize-option 'vhdl-special-syntax-alist) t]
3792 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3793 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3794 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3795 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3796 "--"
3797 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3798 ("Speedbar"
3799 ["Auto Open at Startup"
3800 (customize-set-variable 'vhdl-speedbar-auto-open
3801 (not vhdl-speedbar-auto-open))
3802 :style toggle :selected vhdl-speedbar-auto-open]
3803 ("Default Displaying Mode"
3804 ["Files"
3805 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3806 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3807 ["Directory Hierarchy"
3808 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3809 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3810 ["Project Hierarchy"
3811 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3812 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3813 ["Indentation Offset..."
3814 (customize-option 'speedbar-indentation-width) t]
3815 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3816 ["Jump to Unit when Opening"
3817 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3818 (not vhdl-speedbar-jump-to-unit))
3819 :style toggle :selected vhdl-speedbar-jump-to-unit]
3820 ["Update Hierarchy on File Saving"
3821 (customize-set-variable 'vhdl-speedbar-update-on-saving
3822 (not vhdl-speedbar-update-on-saving))
3823 :style toggle :selected vhdl-speedbar-update-on-saving]
3824 ("Save in Cache File"
3825 ["Hierarchy Information"
3826 (customize-set-variable 'vhdl-speedbar-save-cache
3827 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3828 (delq 'hierarchy vhdl-speedbar-save-cache)
3829 (cons 'hierarchy vhdl-speedbar-save-cache)))
3830 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3831 ["Displaying Status"
3832 (customize-set-variable 'vhdl-speedbar-save-cache
3833 (if (memq 'display vhdl-speedbar-save-cache)
3834 (delq 'display vhdl-speedbar-save-cache)
3835 (cons 'display vhdl-speedbar-save-cache)))
3836 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3837 ["Cache File Name..."
3838 (customize-option 'vhdl-speedbar-cache-file-name) t]
3839 "--"
3840 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3841 ("Menu"
3842 ["Add Index Menu when Loading File"
3843 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3844 (vhdl-index-menu-init))
3845 :style toggle :selected vhdl-index-menu]
3846 ["Add Source File Menu when Loading File"
3847 (progn (customize-set-variable 'vhdl-source-file-menu
3848 (not vhdl-source-file-menu))
3849 (vhdl-add-source-files-menu))
3850 :style toggle :selected vhdl-source-file-menu]
3851 ["Add Hideshow Menu at Startup"
3852 (progn (customize-set-variable 'vhdl-hideshow-menu
3853 (not vhdl-hideshow-menu))
3854 (vhdl-activate-customizations))
3855 :style toggle :selected vhdl-hideshow-menu]
3856 ["Hide Everything Initially"
3857 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3858 :style toggle :selected vhdl-hide-all-init]
3859 "--"
3860 ["Customize Group..." (customize-group 'vhdl-menu) t])
3861 ("Print"
3862 ["In Two Column Format"
3863 (progn (customize-set-variable 'vhdl-print-two-column
3864 (not vhdl-print-two-column))
3865 (message "Activate new setting by saving options and restarting Emacs"))
3866 :style toggle :selected vhdl-print-two-column]
3867 ["Use Customized Faces"
3868 (progn (customize-set-variable 'vhdl-print-customize-faces
3869 (not vhdl-print-customize-faces))
3870 (message "Activate new setting by saving options and restarting Emacs"))
3871 :style toggle :selected vhdl-print-customize-faces]
3872 "--"
3873 ["Customize Group..." (customize-group 'vhdl-print) t])
3874 ("Miscellaneous"
3875 ["Use Intelligent Tab"
3876 (progn (customize-set-variable 'vhdl-intelligent-tab
3877 (not vhdl-intelligent-tab))
3878 (vhdl-activate-customizations))
3879 :style toggle :selected vhdl-intelligent-tab]
3880 ["Indent Syntax-Based"
3881 (customize-set-variable 'vhdl-indent-syntax-based
3882 (not vhdl-indent-syntax-based))
3883 :style toggle :selected vhdl-indent-syntax-based]
3884 ["Word Completion is Case Sensitive"
3885 (customize-set-variable 'vhdl-word-completion-case-sensitive
3886 (not vhdl-word-completion-case-sensitive))
3887 :style toggle :selected vhdl-word-completion-case-sensitive]
3888 ["Word Completion in Minibuffer"
3889 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3890 (not vhdl-word-completion-in-minibuffer))
3891 (message "Activate new setting by saving options and restarting Emacs"))
3892 :style toggle :selected vhdl-word-completion-in-minibuffer]
3893 ["Underscore is Part of Word"
3894 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3895 (not vhdl-underscore-is-part-of-word))
3896 (vhdl-activate-customizations))
3897 :style toggle :selected vhdl-underscore-is-part-of-word]
3898 "--"
3899 ["Customize Group..." (customize-group 'vhdl-misc) t])
3900 ["Related..." (customize-browse 'vhdl-related) t]
3901 "--"
3902 ["Save Options" customize-save-customized t]
3903 ["Activate Options" vhdl-activate-customizations t]
3904 ["Browse Options..." vhdl-customize t])))
3905
3906 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3907 "VHDL Mode menu.")
3908
3909 (defun vhdl-update-mode-menu ()
3910 "Update VHDL Mode menu."
3911 (interactive)
3912 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3913 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3914 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3915 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3916 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
3917
3918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3919 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
3920
3921 (defconst vhdl-imenu-generic-expression
3922 '(
3923 ("Subprogram"
3924 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3925 4)
3926 ("Instance"
3927 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3928 1)
3929 ("Component"
3930 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3931 2)
3932 ("Procedural"
3933 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3934 1)
3935 ("Process"
3936 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3937 1)
3938 ("Block"
3939 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3940 1)
3941 ("Package"
3942 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3943 3)
3944 ("Configuration"
3945 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3946 2)
3947 ("Architecture"
3948 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3949 2)
3950 ("Entity"
3951 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3952 2)
3953 )
3954 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3955
3956 (defun vhdl-index-menu-init ()
3957 "Initialize index menu."
3958 (set (make-local-variable 'imenu-case-fold-search) t)
3959 (set (make-local-variable 'imenu-generic-expression)
3960 vhdl-imenu-generic-expression)
3961 (when (and vhdl-index-menu (fboundp 'imenu))
3962 (if (or (not (boundp 'font-lock-maximum-size))
3963 (> font-lock-maximum-size (buffer-size)))
3964 (imenu-add-to-menubar "Index")
3965 (message "Scanning buffer for index...buffer too big"))))
3966
3967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3968 ;; Source file menu (using `easy-menu.el')
3969
3970 (defvar vhdl-sources-menu nil)
3971
3972 (defun vhdl-directory-files (directory &optional full match)
3973 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3974 message."
3975 (if (not (file-directory-p directory))
3976 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3977 (let ((dir (directory-files directory full match)))
3978 (setq dir (delete "." dir))
3979 (setq dir (delete ".." dir))
3980 dir)))
3981
3982 (defun vhdl-get-source-files (&optional full directory)
3983 "Get list of VHDL source files in DIRECTORY or current directory."
3984 (let ((mode-alist auto-mode-alist)
3985 filename-regexp)
3986 ;; create regular expressions for matching file names
3987 (setq filename-regexp "\\`[^.].*\\(")
3988 (while mode-alist
3989 (when (eq (cdar mode-alist) 'vhdl-mode)
3990 (setq filename-regexp
3991 (concat filename-regexp (caar mode-alist) "\\|")))
3992 (setq mode-alist (cdr mode-alist)))
3993 (setq filename-regexp
3994 (concat (substring filename-regexp 0
3995 (string-match "\\\\|$" filename-regexp)) "\\)"))
3996 ;; find files
3997 (vhdl-directory-files
3998 (or directory default-directory) full filename-regexp)))
3999
4000 (defun vhdl-add-source-files-menu ()
4001 "Scan directory for all VHDL source files and generate menu.
4002 The directory of the current source file is scanned."
4003 (interactive)
4004 (message "Scanning directory for source files ...")
4005 (let ((newmap (current-local-map))
4006 (file-list (vhdl-get-source-files))
4007 menu-list found)
4008 ;; Create list for menu
4009 (setq found nil)
4010 (while file-list
4011 (setq found t)
4012 (setq menu-list (cons (vector (car file-list)
4013 (list 'find-file (car file-list)) t)
4014 menu-list))
4015 (setq file-list (cdr file-list)))
4016 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4017 (when found (setq menu-list (cons "--" menu-list)))
4018 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4019 (setq menu-list (cons "Sources" menu-list))
4020 ;; Create menu
4021 (easy-menu-add menu-list)
4022 (easy-menu-define vhdl-sources-menu newmap
4023 "VHDL source files menu" menu-list))
4024 (message ""))
4025
4026
4027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4028 ;;; Mode definition
4029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4030 ;; performs all buffer local initializations
4031
4032 ;;;###autoload
4033 (defun vhdl-mode ()
4034 "Major mode for editing VHDL code.
4035
4036 Usage:
4037 ------
4038
4039 TEMPLATE INSERTION (electrification):
4040 After typing a VHDL keyword and entering `SPC', you are prompted for
4041 arguments while a template is generated for that VHDL construct. Typing
4042 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4043 template generation. Optional arguments are indicated by square
4044 brackets and removed if the queried string is left empty. Prompts for
4045 mandatory arguments remain in the code if the queried string is left
4046 empty. They can be queried again by `C-c C-t C-q'. Enabled
4047 electrification is indicated by `/e' in the modeline.
4048
4049 Typing `M-SPC' after a keyword inserts a space without calling the
4050 template generator. Automatic template generation (i.e.
4051 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4052 setting option `vhdl-electric-mode' (see OPTIONS).
4053
4054 Template generators can be invoked from the VHDL menu, by key
4055 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4056 the keyword (i.e. first word of menu entry not in parenthesis) and
4057 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4058 conf, comp, cons, func, inst, pack, sig, var.
4059
4060 Template styles can be customized in customization group
4061 `vhdl-template' \(see OPTIONS).
4062
4063
4064 HEADER INSERTION:
4065 A file header can be inserted by `C-c C-t C-h'. A file footer
4066 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4067 See customization group `vhdl-header'.
4068
4069
4070 STUTTERING:
4071 Double striking of some keys inserts cumbersome VHDL syntax elements.
4072 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4073 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4074 the modeline. The stuttering keys and their effects are:
4075
4076 ;; --> \" : \" [ --> ( -- --> comment
4077 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4078 .. --> \" => \" ] --> ) --- --> horizontal line
4079 ,, --> \" <= \" ]] --> ] ---- --> display comment
4080 == --> \" == \" '' --> \\\"
4081
4082
4083 WORD COMPLETION:
4084 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4085 word in the buffer that starts alike, inserts it and adjusts case.
4086 Re-typing `TAB' toggles through alternative word completions. This also
4087 works in the minibuffer (i.e. in template generator prompts).
4088
4089 Typing `TAB' after `(' looks for and inserts complete parenthesized
4090 expressions (e.g. for array index ranges). All keywords as well as
4091 standard types and subprograms of VHDL have predefined abbreviations
4092 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4093 beginning with \"std\").
4094
4095 Typing `TAB' after a non-word character indents the line if at the
4096 beginning of a line (i.e. no preceding non-blank characters), and
4097 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4098 stop.
4099
4100
4101 COMMENTS:
4102 `--' puts a single comment.
4103 `---' draws a horizontal line for separating code segments.
4104 `----' inserts a display comment, i.e. two horizontal lines
4105 with a comment in between.
4106 `--CR' comments out code on that line. Re-hitting CR comments
4107 out following lines.
4108 `C-c c' comments out a region if not commented out,
4109 uncomments a region if already commented out.
4110
4111 You are prompted for comments after object definitions (i.e. signals,
4112 variables, constants, ports) and after subprogram and process
4113 specifications if option `vhdl-prompt-for-comments' is non-nil.
4114 Comments are automatically inserted as additional labels (e.g. after
4115 begin statements) and as help comments if `vhdl-self-insert-comments' is
4116 non-nil.
4117
4118 Inline comments (i.e. comments after a piece of code on the same line)
4119 are indented at least to `vhdl-inline-comment-column'. Comments go at
4120 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4121 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4122 in a comment automatically opens a new comment line. `M-q' re-fills
4123 multi-line comments.
4124
4125
4126 INDENTATION:
4127 `TAB' indents a line if at the beginning of the line. The amount of
4128 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4129 always indents the current line (is bound to `TAB' if option
4130 `vhdl-intelligent-tab' is nil).
4131
4132 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4133 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4134 indented normally (nil) or relative to the opening parenthesis (non-nil)
4135 according to option `vhdl-argument-list-indent'.
4136
4137 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4138 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4139 and vice versa.
4140
4141 Syntax-based indentation can be very slow in large files. Option
4142 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4143
4144
4145 ALIGNMENT:
4146 The alignment functions align operators, keywords, and inline comments
4147 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4148 separated by blank lines, `C-c C-a C-i' a block of lines with same
4149 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4150 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4151 C-a C-d' all lines within the declarative part of a design unit. `C-c
4152 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4153 for a group of lines, and `C-c C-a M-c' for a region.
4154
4155 If option `vhdl-align-groups' is non-nil, groups of code lines
4156 separated by special lines (see option `vhdl-align-group-separate') are
4157 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4158 blocks of lines with same indent are aligned separately. Some templates
4159 are automatically aligned after generation if option `vhdl-auto-align'
4160 is non-nil.
4161
4162 Alignment tries to align inline comments at
4163 `vhdl-inline-comment-column' and tries inline comment not to exceed
4164 `vhdl-end-comment-column'.
4165
4166 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4167 symbols are surrounded by one space, and multiple spaces are eliminated.
4168
4169
4170 | CODE FILLING:
4171 | Code filling allows to condens code (e.g. sensitivity lists or port
4172 | maps) by removing comments and newlines and re-wrapping so that all
4173 | lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4174 | enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4175 | blank lines, `C-c C-f C-i' a block of lines with same indent, and
4176 | `C-c C-f M-f' an entire region.
4177
4178
4179 CODE BEAUTIFICATION:
4180 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4181 buffer respectively. This inludes indentation, alignment, and case
4182 fixing. Code beautification can also be run non-interactively using the
4183 command:
4184
4185 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4186
4187
4188 PORT TRANSLATION:
4189 Generic and port clauses from entity or component declarations can be
4190 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4191 as component instantiations and corresponding internal constants and
4192 signals, as a generic map with constants as actual generics, and as
4193 internal signal initializations (menu).
4194
4195 To include formals in component instantiations, see option
4196 `vhdl-association-list-with-formals'. To include comments in pasting,
4197 see options `vhdl-include-...-comments'.
4198
4199 A clause with several generic/port names on the same line can be
4200 flattened (`C-c C-p C-f') so that only one name per line exists. The
4201 | direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4202 | outputs and vice versa, which can be useful in testbenches. (This
4203 | reversion is done on the internal data structure and is only reflected
4204 | in subsequent paste operations.)
4205
4206 Names for actual ports, instances, testbenches, and
4207 design-under-test instances can be derived from existing names according
4208 to options `vhdl-...-name'. See customization group `vhdl-port'.
4209
4210
4211 | SUBPROGRAM TRANSLATION:
4212 | Similar functionality exists for copying/pasting the interface of
4213 | subprograms (function/procedure). A subprogram interface can be copied
4214 | and then pasted as a subprogram declaration, body or call (uses
4215 | association list with formals).
4216
4217
4218 TESTBENCH GENERATION:
4219 A copied port can also be pasted as a testbench. The generated
4220 testbench includes an entity, an architecture, and an optional
4221 configuration. The architecture contains the component declaration and
4222 instantiation of the DUT as well as internal constant and signal
4223 declarations. Additional user-defined templates can be inserted. The
4224 names used for entity/architecture/configuration/DUT as well as the file
4225 structure to be generated can be customized. See customization group
4226 `vhdl-testbench'.
4227
4228
4229 KEY BINDINGS:
4230 Key bindings (`C-c ...') exist for most commands (see in menu).
4231
4232
4233 VHDL MENU:
4234 All commands can be found in the VHDL menu including their key bindings.
4235
4236
4237 FILE BROWSER:
4238 The speedbar allows browsing of directories and file contents. It can
4239 be accessed from the VHDL menu and is automatically opened if option
4240 `vhdl-speedbar-auto-open' is non-nil.
4241
4242 In speedbar, open files and directories with `mouse-2' on the name and
4243 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4244
4245
4246 DESIGN HIERARCHY BROWSER:
4247 The speedbar can also be used for browsing the hierarchy of design units
4248 contained in the source files of the current directory or the specified
4249 projects (see option `vhdl-project-alist').
4250
4251 The speedbar can be switched between file, directory hierarchy and
4252 project hierarchy browsing mode in the speedbar menu or by typing `f',
4253 `h' or `H' in speedbar.
4254
4255 In speedbar, open design units with `mouse-2' on the name and browse
4256 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4257 from entities and components (in packages). Individual design units and
4258 complete designs can directly be compiled (\"Make\" menu entry).
4259
4260 The hierarchy is automatically updated upon saving a modified source
4261 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4262 hierarchy is only updated for projects that have been opened once in the
4263 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4264 options in group `vhdl-speedbar').
4265
4266 Simple design consistency checks are done during scanning, such as
4267 multiple declarations of the same unit or missing primary units that are
4268 required by secondary units.
4269
4270
4271 | STRUCTURAL COMPOSITION:
4272 | Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4273 | for a new component. Subcomponents (i.e. component declaration and
4274 | instantiation) can be automatically placed from a previously read port
4275 | \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4276 | all subcomponents can be automatically connected using internal signals
4277 | and ports (`C-c C-c C-w') following these rules:
4278 | - subcomponent actual ports with same name are considered to be
4279 | connected by a signal (internal signal or port)
4280 | - signals that are only inputs to subcomponents are considered as
4281 | inputs to this component -> input port created
4282 | - signals that are only outputs from subcomponents are considered as
4283 | outputs from this component -> output port created
4284 | - signals that are inputs to AND outputs from subcomponents are
4285 | considered as internal connections -> internal signal created
4286 |
4287 | Component declarations can be placed in a components package (option
4288 | `vhdl-use-components-package') which can be automatically generated for
4289 | an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4290 | component instantiation is also supported (option
4291 | `vhdl-use-direct-instantiation').
4292 |
4293 | Purpose: With appropriate naming conventions it is possible to
4294 | create higher design levels with only a few mouse clicks or key
4295 | strokes. A new design level can be created by simply generating a new
4296 | component, placing the required subcomponents from the hierarchy
4297 | browser, and wiring everything automatically.
4298 |
4299 | Note: Automatic wiring only works reliably on templates of new
4300 | components and component instantiations that were created by VHDL mode.
4301 |
4302 | See the options group `vhdl-compose' for all relevant user options.
4303
4304
4305 SOURCE FILE COMPILATION:
4306 The syntax of the current buffer can be analyzed by calling a VHDL
4307 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4308 option `vhdl-compiler'. The available compilers are listed in option
4309 `vhdl-compiler-alist' including all required compilation command,
4310 command options, compilation directory, and error message syntax
4311 information. New compilers can be added.
4312
4313 All the source files of an entire design can be compiled by the `make'
4314 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4315
4316
4317 MAKEFILE GENERATION:
4318 Makefiles can be generated automatically by an internal generation
4319 routine (`C-c M-k'). The library unit dependency information is
4320 obtained from the hierarchy browser. Makefile generation can be
4321 customized for each compiler in option `vhdl-compiler-alist'.
4322
4323 Makefile generation can also be run non-interactively using the
4324 command:
4325
4326 emacs -batch -l ~/.emacs -l vhdl-mode
4327 [-compiler compilername] [-project projectname]
4328 -f vhdl-generate-makefile
4329
4330 The Makefile's default target \"all\" compiles the entire design, the
4331 target \"clean\" removes it and the target \"library\" creates the
4332 library directory if not existent. The Makefile also includes a target
4333 for each primary library unit which allows selective compilation of this
4334 unit, its secondary units and its subhierarchy (example: compilation of
4335 a design specified by a configuration). User specific parts can be
4336 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4337
4338 Limitations:
4339 - Only library units and dependencies within the current library are
4340 considered. Makefiles for designs that span multiple libraries are
4341 not (yet) supported.
4342 - Only one-level configurations are supported (also hierarchical),
4343 but configurations that go down several levels are not.
4344 - The \"others\" keyword in configurations is not supported.
4345
4346
4347 PROJECTS:
4348 Projects can be defined in option `vhdl-project-alist' and a current
4349 project be selected using option `vhdl-project' (permanently) or from
4350 the menu or speedbar (temporarily). For each project, title and
4351 description strings (for the file headers), source files/directories
4352 (for the hierarchy browser and Makefile generation), library name, and
4353 compiler-dependent options, exceptions and compilation directory can be
4354 specified. Compilation settings overwrite the settings of option
4355 `vhdl-compiler-alist'.
4356
4357 Project setups can be exported (i.e. written to a file) and imported.
4358 Imported setups are not automatically saved in `vhdl-project-alist' but
4359 can be saved afterwards in its customization buffer. When starting
4360 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4361 vhdl-mode\") in a directory with an existing project setup file, it is
4362 automatically loaded and its project activated if option
4363 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4364 files can be specified in option `vhdl-project-file-name'. Multiple
4365 project setups can be automatically loaded from global directories.
4366 This is an alternative to specifying project setups with option
4367 `vhdl-project-alist'.
4368
4369
4370 SPECIAL MENUES:
4371 As an alternative to the speedbar, an index menu can be added (set
4372 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4373 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4374 file) for browsing the file contents (is not populated if buffer is
4375 larger than `font-lock-maximum-size'). Also, a source file menu can be
4376 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4377 current directory for VHDL source files.
4378
4379
4380 VHDL STANDARDS:
4381 The VHDL standards to be used are specified in option `vhdl-standard'.
4382 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4383
4384
4385 KEYWORD CASE:
4386 Lower and upper case for keywords and standardized types, attributes,
4387 and enumeration values is supported. If the option
4388 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4389 lower case and are converted into upper case automatically (not for
4390 types, attributes, and enumeration values). The case of keywords,
4391 types, attributes,and enumeration values can be fixed for an entire
4392 region (menu) or buffer (`C-c C-x C-c') according to the options
4393 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4394
4395
4396 HIGHLIGHTING (fontification):
4397 Keywords and standardized types, attributes, enumeration values, and
4398 function names (controlled by option `vhdl-highlight-keywords'), as well
4399 as comments, strings, and template prompts are highlighted using
4400 different colors. Unit, subprogram, signal, variable, constant,
4401 parameter and generic/port names in declarations as well as labels are
4402 highlighted if option `vhdl-highlight-names' is non-nil.
4403
4404 Additional reserved words or words with a forbidden syntax (e.g. words
4405 that should be avoided) can be specified in option
4406 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4407 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4408 keywords are highlighted as forbidden words if option
4409 `vhdl-highlight-verilog-keywords' is non-nil.
4410
4411 Words with special syntax can be highlighted by specifying their
4412 syntax and color in option `vhdl-special-syntax-alist' and by setting
4413 option `vhdl-highlight-special-words' to non-nil. This allows to
4414 establish some naming conventions (e.g. to distinguish different kinds
4415 of signals or other objects by using name suffices) and to support them
4416 visually.
4417
4418 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4419 to support case-sensitive highlighting. However, keywords are then only
4420 highlighted if written in lower case.
4421
4422 Code between \"translate_off\" and \"translate_on\" pragmas is
4423 highlighted using a different background color if option
4424 `vhdl-highlight-translate-off' is non-nil.
4425
4426 For documentation and customization of the used colors see
4427 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4428 highlighting of matching parenthesis, see customization group
4429 `paren-showing'. Automatic buffer highlighting is turned on/off by
4430 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4431
4432
4433 USER MODELS:
4434 VHDL models (templates) can be specified by the user and made accessible
4435 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4436 electrification. See option `vhdl-model-alist'.
4437
4438
4439 HIDE/SHOW:
4440 The code of blocks, processes, subprograms, component declarations and
4441 instantiations, generic/port clauses, and configuration declarations can
4442 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4443 the code (see customization group `vhdl-menu'). XEmacs: limited
4444 functionality due to old `hideshow.el' package.
4445
4446
4447 CODE UPDATING:
4448 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4449 current process, `C-c C-u M-s' of all processes in the current buffer.
4450 Limitations:
4451 - Only declared local signals (ports, signals declared in
4452 architecture and blocks) are automatically inserted.
4453 - Global signals declared in packages are not automatically inserted.
4454 Insert them once manually (will be kept afterwards).
4455 - Out parameters of procedures are considered to be read.
4456 Use option `vhdl-entity-file-name' to specify the entity file name
4457 \(used to obtain the port names).
4458
4459
4460 CODE FIXING:
4461 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4462 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4463
4464
4465 PRINTING:
4466 Postscript printing with different faces (an optimized set of faces is
4467 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4468 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4469 postscript printing commands. Option `vhdl-print-two-column' defines
4470 appropriate default settings for nice landscape two-column printing.
4471 The paper format can be set by option `ps-paper-type'. Do not forget to
4472 switch `ps-print-color-p' to nil for printing on black-and-white
4473 printers.
4474
4475
4476 OPTIONS:
4477 User options allow customization of VHDL Mode. All options are
4478 accessible from the \"Options\" menu entry. Simple options (switches
4479 and choices) can directly be changed, while for complex options a
4480 customization buffer is opened. Changed options can be saved for future
4481 sessions using the \"Save Options\" menu entry.
4482
4483 Options and their detailed descriptions can also be accessed by using
4484 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4485 customize-group' for groups). Some customizations only take effect
4486 after some action (read the NOTE in the option documentation).
4487 Customization can also be done globally (i.e. site-wide, read the
4488 INSTALL file).
4489
4490 Not all options are described in this documentation, so go and see
4491 what other useful user options there are (`M-x vhdl-customize' or menu)!
4492
4493
4494 FILE EXTENSIONS:
4495 As default, files with extensions \".vhd\" and \".vhdl\" are
4496 automatically recognized as VHDL source files. To add an extension
4497 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4498
4499 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4500
4501
4502 HINTS:
4503 - To start Emacs with open VHDL hierarchy browser without having to load
4504 a VHDL file first, use the command:
4505
4506 emacs -l vhdl-mode -f speedbar-frame-mode
4507
4508 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4509
4510 - Some features only work on properly indented code.
4511
4512
4513 RELEASE NOTES:
4514 See also the release notes (menu) for added features in new releases.
4515
4516
4517 Maintenance:
4518 ------------
4519
4520 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4521 Add a description of the problem and include a reproducible test case.
4522
4523 Questions and enhancement requests can be sent to <reto@gnu.org>.
4524
4525 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4526 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4527 releases. You are kindly invited to participate in beta testing. Subscribe
4528 to above mailing lists by sending an email to <reto@gnu.org>.
4529
4530 VHDL Mode is officially distributed at
4531 http://opensource.ethz.ch/emacs/vhdl-mode.html
4532 where the latest version can be found.
4533
4534
4535 Known problems:
4536 ---------------
4537
4538 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4539 - XEmacs: Incorrect start-up when automatically opening speedbar.
4540 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4541
4542
4543 The VHDL Mode Authors
4544 Reto Zimmermann and Rod Whitby
4545
4546 Key bindings:
4547 -------------
4548
4549 \\{vhdl-mode-map}"
4550 (interactive)
4551 (kill-all-local-variables)
4552 (setq major-mode 'vhdl-mode)
4553 (setq mode-name "VHDL")
4554
4555 ;; set maps and tables
4556 (use-local-map vhdl-mode-map)
4557 (set-syntax-table vhdl-mode-syntax-table)
4558 (setq local-abbrev-table vhdl-mode-abbrev-table)
4559
4560 ;; set local variables
4561 (set (make-local-variable 'paragraph-start)
4562 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4563 (set (make-local-variable 'paragraph-separate) paragraph-start)
4564 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4565 (set (make-local-variable 'require-final-newline)
4566 mode-require-final-newline)
4567 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4568 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4569 (set (make-local-variable 'comment-start) "--")
4570 (set (make-local-variable 'comment-end) "")
4571 (when vhdl-emacs-21
4572 (set (make-local-variable 'comment-padding) ""))
4573 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4574 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4575 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4576 (set (make-local-variable 'comment-multi-line) nil)
4577 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4578 (set (make-local-variable 'hippie-expand-verbose) nil)
4579
4580 ;; setup the comment indent variable in a Emacs version portable way
4581 ;; ignore any byte compiler warnings you might get here
4582 (when (boundp 'comment-indent-function)
4583 (make-local-variable 'comment-indent-function)
4584 (setq comment-indent-function 'vhdl-comment-indent))
4585
4586 ;; initialize font locking
4587 (set (make-local-variable 'font-lock-defaults)
4588 (list
4589 '(nil vhdl-font-lock-keywords) nil
4590 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4591 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4592 (unless vhdl-emacs-21
4593 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4594 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4595 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4596 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4597 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4598 ; (turn-on-font-lock)
4599
4600 ;; variables for source file compilation
4601 (when vhdl-compile-use-local-error-regexp
4602 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4603 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4604
4605 ;; add index menu
4606 (vhdl-index-menu-init)
4607 ;; add source file menu
4608 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4609 ;; add VHDL menu
4610 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4611 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4612 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4613 ;; initialize hideshow and add menu
4614 (vhdl-hideshow-init)
4615 (run-hooks 'menu-bar-update-hook)
4616
4617 ;; miscellaneous
4618 (vhdl-ps-print-init)
4619 (vhdl-write-file-hooks-init)
4620 (vhdl-mode-line-update)
4621 (message "VHDL Mode %s.%s" vhdl-version
4622 (if noninteractive "" " See menu for documentation and release notes."))
4623
4624 ;; run hooks
4625 (run-hooks 'vhdl-mode-hook))
4626
4627 (defun vhdl-activate-customizations ()
4628 "Activate all customizations on local variables."
4629 (interactive)
4630 (vhdl-mode-map-init)
4631 (use-local-map vhdl-mode-map)
4632 (set-syntax-table vhdl-mode-syntax-table)
4633 (setq comment-column vhdl-inline-comment-column)
4634 (setq end-comment-column vhdl-end-comment-column)
4635 (vhdl-write-file-hooks-init)
4636 (vhdl-update-mode-menu)
4637 (vhdl-hideshow-init)
4638 (run-hooks 'menu-bar-update-hook)
4639 (vhdl-mode-line-update))
4640
4641 (defun vhdl-write-file-hooks-init ()
4642 "Add/remove hooks when buffer is saved."
4643 (if vhdl-modify-date-on-saving
4644 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4645 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4646 (make-local-variable 'after-save-hook)
4647 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4648
4649 (defun vhdl-process-command-line-option (option)
4650 "Process command line options for VHDL Mode."
4651 (cond
4652 ;; set compiler
4653 ((equal option "-compiler")
4654 (vhdl-set-compiler (car command-line-args-left))
4655 (setq command-line-args-left (cdr command-line-args-left)))
4656 ;; set project
4657 ((equal option "-project")
4658 (vhdl-set-project (car command-line-args-left))
4659 (setq command-line-args-left (cdr command-line-args-left)))))
4660
4661 ;; make Emacs process VHDL Mode options
4662 (setq command-switch-alist
4663 (append command-switch-alist
4664 '(("-compiler" . vhdl-process-command-line-option)
4665 ("-project" . vhdl-process-command-line-option))))
4666
4667
4668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4669 ;;; Keywords and standardized words
4670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4671
4672 (defconst vhdl-93-keywords
4673 '(
4674 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4675 "assert" "attribute"
4676 "begin" "block" "body" "buffer" "bus"
4677 "case" "component" "configuration" "constant"
4678 "disconnect" "downto"
4679 "else" "elsif" "end" "entity" "exit"
4680 "file" "for" "function"
4681 "generate" "generic" "group" "guarded"
4682 "if" "impure" "in" "inertial" "inout" "is"
4683 "label" "library" "linkage" "literal" "loop"
4684 "map" "mod"
4685 "nand" "new" "next" "nor" "not" "null"
4686 "of" "on" "open" "or" "others" "out"
4687 "package" "port" "postponed" "procedure" "process" "pure"
4688 "range" "record" "register" "reject" "rem" "report" "return"
4689 "rol" "ror"
4690 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4691 "then" "to" "transport" "type"
4692 "unaffected" "units" "until" "use"
4693 "variable"
4694 "wait" "when" "while" "with"
4695 "xnor" "xor"
4696 )
4697 "List of VHDL'93 keywords.")
4698
4699 (defconst vhdl-ams-keywords
4700 '(
4701 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4702 "reference" "spectrum" "subnature" "terminal" "through"
4703 "tolerance"
4704 )
4705 "List of VHDL-AMS keywords.")
4706
4707 (defconst vhdl-verilog-keywords
4708 '(
4709 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4710 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4711 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4712 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4713 "endprimitive" "endspecify" "endtable" "endtask" "event"
4714 "for" "force" "forever" "fork" "function"
4715 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4716 "macromodule" "makefile" "medium" "module"
4717 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4718 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4719 "pullup"
4720 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4721 "rtranif0" "rtranif1"
4722 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4723 "strong1" "supply" "supply0" "supply1"
4724 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4725 "triand" "trior" "trireg"
4726 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4727 )
4728 "List of Verilog keywords as candidate for additional reserved words.")
4729
4730 (defconst vhdl-93-types
4731 '(
4732 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4733 "real" "time" "natural" "positive" "string" "line" "text" "side"
4734 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4735 "std_logic" "std_logic_vector"
4736 "std_ulogic" "std_ulogic_vector"
4737 )
4738 "List of VHDL'93 standardized types.")
4739
4740 (defconst vhdl-ams-types
4741 '(
4742 "domain_type" "real_vector"
4743 ;; from `nature_pkg' package
4744 "voltage" "current" "electrical" "position" "velocity" "force"
4745 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4746 "pressure" "flowrate" "fluid"
4747 )
4748 "List of VHDL-AMS standardized types.")
4749
4750 (defconst vhdl-math-types
4751 '(
4752 "complex" "complex_polar"
4753 )
4754 "List of Math Packages standardized types.")
4755
4756 (defconst vhdl-93-attributes
4757 '(
4758 "base" "left" "right" "high" "low" "pos" "val" "succ"
4759 "pred" "leftof" "rightof" "range" "reverse_range"
4760 "length" "delayed" "stable" "quiet" "transaction"
4761 "event" "active" "last_event" "last_active" "last_value"
4762 "driving" "driving_value" "ascending" "value" "image"
4763 "simple_name" "instance_name" "path_name"
4764 "foreign"
4765 )
4766 "List of VHDL'93 standardized attributes.")
4767
4768 (defconst vhdl-ams-attributes
4769 '(
4770 "across" "through"
4771 "reference" "contribution" "tolerance"
4772 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4773 "ramp" "slew"
4774 )
4775 "List of VHDL-AMS standardized attributes.")
4776
4777 (defconst vhdl-93-enum-values
4778 '(
4779 "true" "false"
4780 "note" "warning" "error" "failure"
4781 "read_mode" "write_mode" "append_mode"
4782 "open_ok" "status_error" "name_error" "mode_error"
4783 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4784 "right" "left"
4785 )
4786 "List of VHDL'93 standardized enumeration values.")
4787
4788 (defconst vhdl-ams-enum-values
4789 '(
4790 "quiescent_domain" "time_domain" "frequency_domain"
4791 ;; from `nature_pkg' package
4792 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4793 )
4794 "List of VHDL-AMS standardized enumeration values.")
4795
4796 (defconst vhdl-math-constants
4797 '(
4798 "math_e" "math_1_over_e"
4799 "math_pi" "math_two_pi" "math_1_over_pi"
4800 "math_half_pi" "math_q_pi" "math_3_half_pi"
4801 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4802 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4803 "math_deg_to_rad" "math_rad_to_deg"
4804 "cbase_1" "cbase_j" "czero"
4805 )
4806 "List of Math Packages standardized constants.")
4807
4808 (defconst vhdl-93-functions
4809 '(
4810 "now" "resolved" "rising_edge" "falling_edge"
4811 "read" "readline" "write" "writeline" "endfile"
4812 "resize" "is_X" "std_match"
4813 "shift_left" "shift_right" "rotate_left" "rotate_right"
4814 "to_unsigned" "to_signed" "to_integer"
4815 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4816 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4817 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4818 "shl" "shr" "ext" "sxt"
4819 "deallocate"
4820 )
4821 "List of VHDL'93 standardized functions.")
4822
4823 (defconst vhdl-ams-functions
4824 '(
4825 "frequency"
4826 )
4827 "List of VHDL-AMS standardized functions.")
4828
4829 (defconst vhdl-math-functions
4830 '(
4831 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4832 "sqrt" "cbrt" "exp" "log"
4833 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4834 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4835 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4836 )
4837 "List of Math Packages standardized functions.")
4838
4839 (defconst vhdl-93-packages
4840 '(
4841 "std_logic_1164" "numeric_std" "numeric_bit"
4842 "standard" "textio"
4843 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4844 "std_logic_misc" "std_logic_textio"
4845 "ieee" "std" "work"
4846 )
4847 "List of VHDL'93 standardized packages and libraries.")
4848
4849 (defconst vhdl-ams-packages
4850 '(
4851 ;; from `nature_pkg' package
4852 "nature_pkg"
4853 )
4854 "List of VHDL-AMS standardized packages and libraries.")
4855
4856 (defconst vhdl-math-packages
4857 '(
4858 "math_real" "math_complex"
4859 )
4860 "List of Math Packages standardized packages and libraries.")
4861
4862 (defvar vhdl-keywords nil
4863 "List of VHDL keywords.")
4864
4865 (defvar vhdl-types nil
4866 "List of VHDL standardized types.")
4867
4868 (defvar vhdl-attributes nil
4869 "List of VHDL standardized attributes.")
4870
4871 (defvar vhdl-enum-values nil
4872 "List of VHDL standardized enumeration values.")
4873
4874 (defvar vhdl-constants nil
4875 "List of VHDL standardized constants.")
4876
4877 (defvar vhdl-functions nil
4878 "List of VHDL standardized functions.")
4879
4880 (defvar vhdl-packages nil
4881 "List of VHDL standardized packages and libraries.")
4882
4883 (defvar vhdl-reserved-words nil
4884 "List of additional reserved words.")
4885
4886 (defvar vhdl-keywords-regexp nil
4887 "Regexp for VHDL keywords.")
4888
4889 (defvar vhdl-types-regexp nil
4890 "Regexp for VHDL standardized types.")
4891
4892 (defvar vhdl-attributes-regexp nil
4893 "Regexp for VHDL standardized attributes.")
4894
4895 (defvar vhdl-enum-values-regexp nil
4896 "Regexp for VHDL standardized enumeration values.")
4897
4898 (defvar vhdl-functions-regexp nil
4899 "Regexp for VHDL standardized functions.")
4900
4901 (defvar vhdl-packages-regexp nil
4902 "Regexp for VHDL standardized packages and libraries.")
4903
4904 (defvar vhdl-reserved-words-regexp nil
4905 "Regexp for additional reserved words.")
4906
4907 (defvar vhdl-directive-keywords-regexp nil
4908 "Regexp for compiler directive keywords.")
4909
4910 (defun vhdl-words-init ()
4911 "Initialize reserved words."
4912 (setq vhdl-keywords
4913 (append vhdl-93-keywords
4914 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4915 (setq vhdl-types
4916 (append vhdl-93-types
4917 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4918 (when (vhdl-standard-p 'math) vhdl-math-types)))
4919 (setq vhdl-attributes
4920 (append vhdl-93-attributes
4921 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4922 (setq vhdl-enum-values
4923 (append vhdl-93-enum-values
4924 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4925 (setq vhdl-constants
4926 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4927 (setq vhdl-functions
4928 (append vhdl-93-functions
4929 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4930 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4931 (setq vhdl-packages
4932 (append vhdl-93-packages
4933 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
4934 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4935 (setq vhdl-reserved-words
4936 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4937 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4938 '("")))
4939 (setq vhdl-keywords-regexp
4940 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4941 (setq vhdl-types-regexp
4942 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4943 (setq vhdl-attributes-regexp
4944 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4945 (setq vhdl-enum-values-regexp
4946 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4947 (setq vhdl-functions-regexp
4948 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4949 (setq vhdl-packages-regexp
4950 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4951 (setq vhdl-reserved-words-regexp
4952 (concat "\\<\\("
4953 (unless (equal vhdl-forbidden-syntax "")
4954 (concat vhdl-forbidden-syntax "\\|"))
4955 (regexp-opt vhdl-reserved-words)
4956 "\\)\\>"))
4957 (setq vhdl-directive-keywords-regexp
4958 (concat "\\<\\(" (mapconcat 'regexp-quote
4959 vhdl-directive-keywords "\\|") "\\)\\>"))
4960 (vhdl-abbrev-list-init))
4961
4962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4963 ;; Words to expand
4964
4965 (defvar vhdl-abbrev-list nil
4966 "Predefined abbreviations for VHDL.")
4967
4968 (defun vhdl-abbrev-list-init ()
4969 (setq vhdl-abbrev-list
4970 (append
4971 (list vhdl-upper-case-keywords) vhdl-keywords
4972 (list vhdl-upper-case-types) vhdl-types
4973 (list vhdl-upper-case-attributes) vhdl-attributes
4974 (list vhdl-upper-case-enum-values) vhdl-enum-values
4975 (list vhdl-upper-case-constants) vhdl-constants
4976 (list nil) vhdl-functions
4977 (list nil) vhdl-packages)))
4978
4979 ;; initialize reserved words for VHDL Mode
4980 (vhdl-words-init)
4981
4982
4983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4984 ;;; Indentation
4985 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4986
4987 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4988 ;; Syntax analysis
4989
4990 ;; constant regular expressions for looking at various constructs
4991
4992 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4993 "Regexp describing a VHDL symbol.
4994 We cannot use just `word' syntax class since `_' cannot be in word
4995 class. Putting underscore in word class breaks forward word movement
4996 behavior that users are familiar with.")
4997
4998 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4999 "Regexp describing a case statement header key.")
5000
5001 (defconst vhdl-label-key
5002 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5003 "Regexp describing a VHDL label.")
5004
5005 ;; Macro definitions:
5006
5007 (defmacro vhdl-point (position)
5008 "Return the value of point at certain commonly referenced POSITIONs.
5009 POSITION can be one of the following symbols:
5010
5011 bol -- beginning of line
5012 eol -- end of line
5013 bod -- beginning of defun
5014 boi -- back to indentation
5015 eoi -- last whitespace on line
5016 ionl -- indentation of next line
5017 iopl -- indentation of previous line
5018 bonl -- beginning of next line
5019 bopl -- beginning of previous line
5020
5021 This function does not modify point or mark."
5022 (or (and (eq 'quote (car-safe position))
5023 (null (cddr position)))
5024 (error "ERROR: Bad buffer position requested: %s" position))
5025 (setq position (nth 1 position))
5026 `(let ((here (point)))
5027 ,@(cond
5028 ((eq position 'bol) '((beginning-of-line)))
5029 ((eq position 'eol) '((end-of-line)))
5030 ((eq position 'bod) '((save-match-data
5031 (vhdl-beginning-of-defun))))
5032 ((eq position 'boi) '((back-to-indentation)))
5033 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5034 ((eq position 'bonl) '((forward-line 1)))
5035 ((eq position 'bopl) '((forward-line -1)))
5036 ((eq position 'iopl)
5037 '((forward-line -1)
5038 (back-to-indentation)))
5039 ((eq position 'ionl)
5040 '((forward-line 1)
5041 (back-to-indentation)))
5042 (t (error "ERROR: Unknown buffer position requested: %s" position))
5043 )
5044 (prog1
5045 (point)
5046 (goto-char here))
5047 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5048 ;; doesn't hurt for v19
5049 ,@nil
5050 ))
5051
5052 (defmacro vhdl-safe (&rest body)
5053 "Safely execute BODY, return nil if an error occurred."
5054 `(condition-case nil
5055 (progn ,@body)
5056 (error nil)))
5057
5058 (defmacro vhdl-add-syntax (symbol &optional relpos)
5059 "A simple macro to append the syntax in SYMBOL to the syntax list.
5060 Try to increase performance by using this macro."
5061 `(setq vhdl-syntactic-context
5062 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5063
5064 (defmacro vhdl-has-syntax (symbol)
5065 "A simple macro to return check the syntax list.
5066 Try to increase performance by using this macro."
5067 `(assoc ,symbol vhdl-syntactic-context))
5068
5069 ;; Syntactic element offset manipulation:
5070
5071 (defun vhdl-read-offset (langelem)
5072 "Read new offset value for LANGELEM from minibuffer.
5073 Return a valid value only."
5074 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5075 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5076 (prompt "Offset: ")
5077 offset input interned)
5078 (while (not offset)
5079 (setq input (read-string prompt oldoff)
5080 offset (cond ((string-equal "+" input) '+)
5081 ((string-equal "-" input) '-)
5082 ((string-equal "++" input) '++)
5083 ((string-equal "--" input) '--)
5084 ((string-match "^-?[0-9]+$" input)
5085 (string-to-int input))
5086 ((fboundp (setq interned (intern input)))
5087 interned)
5088 ((boundp interned) interned)
5089 ;; error, but don't signal one, keep trying
5090 ;; to read an input value
5091 (t (ding)
5092 (setq prompt errmsg)
5093 nil))))
5094 offset))
5095
5096 (defun vhdl-set-offset (symbol offset &optional add-p)
5097 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5098 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5099 offset for that syntactic element. Optional ADD says to add SYMBOL to
5100 `vhdl-offsets-alist' if it doesn't already appear there."
5101 (interactive
5102 (let* ((langelem
5103 (intern (completing-read
5104 (concat "Syntactic symbol to change"
5105 (if current-prefix-arg " or add" "")
5106 ": ")
5107 (mapcar
5108 (function
5109 (lambda (langelem)
5110 (cons (format "%s" (car langelem)) nil)))
5111 vhdl-offsets-alist)
5112 nil (not current-prefix-arg)
5113 ;; initial contents tries to be the last element
5114 ;; on the syntactic analysis list for the current
5115 ;; line
5116 (let* ((syntax (vhdl-get-syntactic-context))
5117 (len (length syntax))
5118 (ic (format "%s" (car (nth (1- len) syntax)))))
5119 ic)
5120 )))
5121 (offset (vhdl-read-offset langelem)))
5122 (list langelem offset current-prefix-arg)))
5123 ;; sanity check offset
5124 (or (eq offset '+)
5125 (eq offset '-)
5126 (eq offset '++)
5127 (eq offset '--)
5128 (integerp offset)
5129 (fboundp offset)
5130 (boundp offset)
5131 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5132 offset))
5133 (let ((entry (assq symbol vhdl-offsets-alist)))
5134 (if entry
5135 (setcdr entry offset)
5136 (if add-p
5137 (setq vhdl-offsets-alist
5138 (cons (cons symbol offset) vhdl-offsets-alist))
5139 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5140 (vhdl-keep-region-active))
5141
5142 (defun vhdl-set-style (style &optional local)
5143 "Set `vhdl-mode' variables to use one of several different indentation styles.
5144 STYLE is a string representing the desired style and optional LOCAL is
5145 a flag which, if non-nil, means to make the style variables being
5146 changed buffer local, instead of the default, which is to set the
5147 global variables. Interactively, the flag comes from the prefix
5148 argument. The styles are chosen from the `vhdl-style-alist' variable."
5149 (interactive (list (completing-read "Use which VHDL indentation style? "
5150 vhdl-style-alist nil t)
5151 current-prefix-arg))
5152 (let ((vars (cdr (assoc style vhdl-style-alist))))
5153 (or vars
5154 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5155 ;; set all the variables
5156 (mapcar
5157 (function
5158 (lambda (varentry)
5159 (let ((var (car varentry))
5160 (val (cdr varentry)))
5161 (and local
5162 (make-local-variable var))
5163 ;; special case for vhdl-offsets-alist
5164 (if (not (eq var 'vhdl-offsets-alist))
5165 (set var val)
5166 ;; reset vhdl-offsets-alist to the default value first
5167 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5168 ;; now set the langelems that are different
5169 (mapcar
5170 (function
5171 (lambda (langentry)
5172 (let ((langelem (car langentry))
5173 (offset (cdr langentry)))
5174 (vhdl-set-offset langelem offset)
5175 )))
5176 val))
5177 )))
5178 vars))
5179 (vhdl-keep-region-active))
5180
5181 (defun vhdl-get-offset (langelem)
5182 "Get offset from LANGELEM which is a cons cell of the form:
5183 \(SYMBOL . RELPOS). The symbol is matched against
5184 vhdl-offsets-alist and the offset found there is either returned,
5185 or added to the indentation at RELPOS. If RELPOS is nil, then
5186 the offset is simply returned."
5187 (let* ((symbol (car langelem))
5188 (relpos (cdr langelem))
5189 (match (assq symbol vhdl-offsets-alist))
5190 (offset (cdr-safe match)))
5191 ;; offset can be a number, a function, a variable, or one of the
5192 ;; symbols + or -
5193 (cond
5194 ((not match)
5195 (if vhdl-strict-syntax-p
5196 (error "ERROR: Don't know how to indent a %s" symbol)
5197 (setq offset 0
5198 relpos 0)))
5199 ((eq offset '+) (setq offset vhdl-basic-offset))
5200 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5201 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5202 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5203 ((and (not (numberp offset))
5204 (fboundp offset))
5205 (setq offset (funcall offset langelem)))
5206 ((not (numberp offset))
5207 (setq offset (eval offset)))
5208 )
5209 (+ (if (and relpos
5210 (< relpos (vhdl-point 'bol)))
5211 (save-excursion
5212 (goto-char relpos)
5213 (current-column))
5214 0)
5215 offset)))
5216
5217 ;; Syntactic support functions:
5218
5219 (defun vhdl-in-comment-p ()
5220 "Check if point is in a comment."
5221 (eq (vhdl-in-literal) 'comment))
5222
5223 (defun vhdl-in-string-p ()
5224 "Check if point is in a string."
5225 (eq (vhdl-in-literal) 'string))
5226
5227 (defun vhdl-in-literal ()
5228 "Determine if point is in a VHDL literal."
5229 (save-excursion
5230 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5231 (cond
5232 ((nth 3 state) 'string)
5233 ((nth 4 state) 'comment)
5234 (t nil)))))
5235
5236 (defun vhdl-forward-comment (&optional direction)
5237 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5238 negative, skip forward otherwise."
5239 (interactive "p")
5240 (if (and direction (< direction 0))
5241 ;; skip backwards
5242 (progn
5243 (skip-chars-backward " \t\n")
5244 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5245 (goto-char (match-beginning 3))
5246 (skip-chars-backward " \t\n")))
5247 ;; skip forwards
5248 (skip-chars-forward " \t\n")
5249 (while (looking-at "--.*")
5250 (goto-char (match-end 0))
5251 (skip-chars-forward " \t\n"))))
5252
5253 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5254 (unless (and vhdl-xemacs (string< "21.2" emacs-version))
5255 (defalias 'vhdl-forward-comment 'forward-comment))
5256
5257 ;; This is the best we can do in Win-Emacs.
5258 (defun vhdl-win-il (&optional lim)
5259 "Determine if point is in a VHDL literal."
5260 (save-excursion
5261 (let* ((here (point))
5262 (state nil)
5263 (match nil)
5264 (lim (or lim (vhdl-point 'bod))))
5265 (goto-char lim )
5266 (while (< (point) here)
5267 (setq match
5268 (and (re-search-forward "--\\|[\"']"
5269 here 'move)
5270 (buffer-substring (match-beginning 0) (match-end 0))))
5271 (setq state
5272 (cond
5273 ;; no match
5274 ((null match) nil)
5275 ;; looking at the opening of a VHDL style comment
5276 ((string= "--" match)
5277 (if (<= here (progn (end-of-line) (point))) 'comment))
5278 ;; looking at the opening of a double quote string
5279 ((string= "\"" match)
5280 (if (not (save-restriction
5281 ;; this seems to be necessary since the
5282 ;; re-search-forward will not work without it
5283 (narrow-to-region (point) here)
5284 (re-search-forward
5285 ;; this regexp matches a double quote
5286 ;; which is preceded by an even number
5287 ;; of backslashes, including zero
5288 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5289 'string))
5290 ;; looking at the opening of a single quote string
5291 ((string= "'" match)
5292 (if (not (save-restriction
5293 ;; see comments from above
5294 (narrow-to-region (point) here)
5295 (re-search-forward
5296 ;; this matches a single quote which is
5297 ;; preceded by zero or two backslashes.
5298 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5299 here 'move)))
5300 'string))
5301 (t nil)))
5302 ) ; end-while
5303 state)))
5304
5305 (and (string-match "Win-Emacs" emacs-version)
5306 (fset 'vhdl-in-literal 'vhdl-win-il))
5307
5308 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5309 ;; defined as lexical whitespace or comments. Search no farther back
5310 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5311 ;; used for backward skipping, (point-max) is used for forward
5312 ;; skipping.
5313
5314 (defun vhdl-forward-syntactic-ws (&optional lim)
5315 "Forward skip of syntactic whitespace."
5316 (save-restriction
5317 (let* ((lim (or lim (point-max)))
5318 (here lim)
5319 (hugenum (point-max)))
5320 (narrow-to-region lim (point))
5321 (while (/= here (point))
5322 (setq here (point))
5323 (vhdl-forward-comment hugenum)))))
5324
5325 ;; This is the best we can do in Win-Emacs.
5326 (defun vhdl-win-fsws (&optional lim)
5327 "Forward skip syntactic whitespace for Win-Emacs."
5328 (let ((lim (or lim (point-max)))
5329 stop)
5330 (while (not stop)
5331 (skip-chars-forward " \t\n\r\f" lim)
5332 (cond
5333 ;; vhdl comment
5334 ((looking-at "--") (end-of-line))
5335 ;; none of the above
5336 (t (setq stop t))))))
5337
5338 (and (string-match "Win-Emacs" emacs-version)
5339 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5340
5341 (defun vhdl-backward-syntactic-ws (&optional lim)
5342 "Backward skip over syntactic whitespace."
5343 (save-restriction
5344 (let* ((lim (or lim (point-min)))
5345 (here lim)
5346 (hugenum (- (point-max))))
5347 (if (< lim (point))
5348 (progn
5349 (narrow-to-region lim (point))
5350 (while (/= here (point))
5351 (setq here (point))
5352 (vhdl-forward-comment hugenum)))))))
5353
5354 ;; This is the best we can do in Win-Emacs.
5355 (defun vhdl-win-bsws (&optional lim)
5356 "Backward skip syntactic whitespace for Win-Emacs."
5357 (let ((lim (or lim (vhdl-point 'bod)))
5358 stop)
5359 (while (not stop)
5360 (skip-chars-backward " \t\n\r\f" lim)
5361 (cond
5362 ;; vhdl comment
5363 ((eq (vhdl-in-literal) 'comment)
5364 (skip-chars-backward "^-" lim)
5365 (skip-chars-backward "-" lim)
5366 (while (not (or (and (= (following-char) ?-)
5367 (= (char-after (1+ (point))) ?-))
5368 (<= (point) lim)))
5369 (skip-chars-backward "^-" lim)
5370 (skip-chars-backward "-" lim)))
5371 ;; none of the above
5372 (t (setq stop t))))))
5373
5374 (and (string-match "Win-Emacs" emacs-version)
5375 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5376
5377 ;; Functions to help finding the correct indentation column:
5378
5379 (defun vhdl-first-word (point)
5380 "If the keyword at POINT is at boi, then return (current-column) at
5381 that point, else nil."
5382 (save-excursion
5383 (and (goto-char point)
5384 (eq (point) (vhdl-point 'boi))
5385 (current-column))))
5386
5387 (defun vhdl-last-word (point)
5388 "If the keyword at POINT is at eoi, then return (current-column) at
5389 that point, else nil."
5390 (save-excursion
5391 (and (goto-char point)
5392 (save-excursion (or (eq (progn (forward-sexp) (point))
5393 (vhdl-point 'eoi))
5394 (looking-at "\\s-*\\(--\\)?")))
5395 (current-column))))
5396
5397 ;; Core syntactic evaluation functions:
5398
5399 (defconst vhdl-libunit-re
5400 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5401
5402 (defun vhdl-libunit-p ()
5403 (and
5404 (save-excursion
5405 (forward-sexp)
5406 (skip-chars-forward " \t\n")
5407 (not (looking-at "is\\b[^_]")))
5408 (save-excursion
5409 (backward-sexp)
5410 (and (not (looking-at "use\\b[^_]"))
5411 (progn
5412 (forward-sexp)
5413 (vhdl-forward-syntactic-ws)
5414 (/= (following-char) ?:))))
5415 ))
5416
5417 (defconst vhdl-defun-re
5418 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5419
5420 (defun vhdl-defun-p ()
5421 (save-excursion
5422 (if (looking-at "block\\|process\\|procedural")
5423 ;; "block", "process", "procedural":
5424 (save-excursion
5425 (backward-sexp)
5426 (not (looking-at "end\\s-+\\w")))
5427 ;; "architecture", "configuration", "entity",
5428 ;; "package", "procedure", "function":
5429 t)))
5430
5431 (defun vhdl-corresponding-defun ()
5432 "If the word at the current position corresponds to a \"defun\"
5433 keyword, then return a string that can be used to find the
5434 corresponding \"begin\" keyword, else return nil."
5435 (save-excursion
5436 (and (looking-at vhdl-defun-re)
5437 (vhdl-defun-p)
5438 (if (looking-at "block\\|process\\|procedural")
5439 ;; "block", "process". "procedural:
5440 (buffer-substring (match-beginning 0) (match-end 0))
5441 ;; "architecture", "configuration", "entity", "package",
5442 ;; "procedure", "function":
5443 "is"))))
5444
5445 (defconst vhdl-begin-fwd-re
5446 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5447 "A regular expression for searching forward that matches all known
5448 \"begin\" keywords.")
5449
5450 (defconst vhdl-begin-bwd-re
5451 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5452 "A regular expression for searching backward that matches all known
5453 \"begin\" keywords.")
5454
5455 (defun vhdl-begin-p (&optional lim)
5456 "Return t if we are looking at a real \"begin\" keyword.
5457 Assumes that the caller will make sure that we are looking at
5458 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5459 the middle of an identifier that just happens to contain a \"begin\"
5460 keyword."
5461 (cond
5462 ;; "[architecture|case|configuration|entity|package|
5463 ;; procedure|function] ... is":
5464 ((and (looking-at "i")
5465 (save-excursion
5466 ;; Skip backward over first sexp (needed to skip over a
5467 ;; procedure interface list, and is harmless in other
5468 ;; situations). Note that we need "return" in the
5469 ;; following search list so that we don't run into
5470 ;; semicolons in the function interface list.
5471 (backward-sexp)
5472 (let (foundp)
5473 (while (and (not foundp)
5474 (re-search-backward
5475 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5476 lim 'move))
5477 (if (or (= (preceding-char) ?_)
5478 (vhdl-in-literal))
5479 (backward-char)
5480 (setq foundp t))))
5481 (and (/= (following-char) ?\;)
5482 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5483 t)
5484 ;; "begin", "then":
5485 ((looking-at "be\\|t")
5486 t)
5487 ;; "else":
5488 ((and (looking-at "e")
5489 ;; make sure that the "else" isn't inside a
5490 ;; conditional signal assignment.
5491 (save-excursion
5492 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5493 (or (eq (following-char) ?\;)
5494 (eq (point) lim))))
5495 t)
5496 ;; "block", "generate", "loop", "process", "procedural",
5497 ;; "units", "record":
5498 ((and (looking-at "bl\\|[glpur]")
5499 (save-excursion
5500 (backward-sexp)
5501 (not (looking-at "end\\s-+\\w"))))
5502 t)
5503 ;; "component":
5504 ((and (looking-at "c")
5505 (save-excursion
5506 (backward-sexp)
5507 (not (looking-at "end\\s-+\\w")))
5508 ;; look out for the dreaded entity class in an attribute
5509 (save-excursion
5510 (vhdl-backward-syntactic-ws lim)
5511 (/= (preceding-char) ?:)))
5512 t)
5513 ;; "for" (inside configuration declaration):
5514 ((and (looking-at "f")
5515 (save-excursion
5516 (backward-sexp)
5517 (not (looking-at "end\\s-+\\w")))
5518 (vhdl-has-syntax 'configuration))
5519 t)
5520 ))
5521
5522 (defun vhdl-corresponding-mid (&optional lim)
5523 (cond
5524 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5525 "begin")
5526 ((looking-at "then")
5527 "<else>")
5528 (t
5529 "end")))
5530
5531 (defun vhdl-corresponding-end (&optional lim)
5532 "If the word at the current position corresponds to a \"begin\"
5533 keyword, then return a vector containing enough information to find
5534 the corresponding \"end\" keyword, else return nil. The keyword to
5535 search forward for is aref 0. The column in which the keyword must
5536 appear is aref 1 or nil if any column is suitable.
5537 Assumes that the caller will make sure that we are not in the middle
5538 of an identifier that just happens to contain a \"begin\" keyword."
5539 (save-excursion
5540 (and (looking-at vhdl-begin-fwd-re)
5541 (/= (preceding-char) ?_)
5542 (not (vhdl-in-literal))
5543 (vhdl-begin-p lim)
5544 (cond
5545 ;; "is", "generate", "loop":
5546 ((looking-at "[igl]")
5547 (vector "end"
5548 (and (vhdl-last-word (point))
5549 (or (vhdl-first-word (point))
5550 (save-excursion
5551 (vhdl-beginning-of-statement-1 lim)
5552 (vhdl-backward-skip-label lim)
5553 (vhdl-first-word (point)))))))
5554 ;; "begin", "else", "for":
5555 ((looking-at "be\\|[ef]")
5556 (vector "end"
5557 (and (vhdl-last-word (point))
5558 (or (vhdl-first-word (point))
5559 (save-excursion
5560 (vhdl-beginning-of-statement-1 lim)
5561 (vhdl-backward-skip-label lim)
5562 (vhdl-first-word (point)))))))
5563 ;; "component", "units", "record":
5564 ((looking-at "[cur]")
5565 ;; The first end found will close the block
5566 (vector "end" nil))
5567 ;; "block", "process", "procedural":
5568 ((looking-at "bl\\|p")
5569 (vector "end"
5570 (or (vhdl-first-word (point))
5571 (save-excursion
5572 (vhdl-beginning-of-statement-1 lim)
5573 (vhdl-backward-skip-label lim)
5574 (vhdl-first-word (point))))))
5575 ;; "then":
5576 ((looking-at "t")
5577 (vector "elsif\\|else\\|end\\s-+if"
5578 (and (vhdl-last-word (point))
5579 (or (vhdl-first-word (point))
5580 (save-excursion
5581 (vhdl-beginning-of-statement-1 lim)
5582 (vhdl-backward-skip-label lim)
5583 (vhdl-first-word (point)))))))
5584 ))))
5585
5586 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5587
5588 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5589
5590 (defun vhdl-end-p (&optional lim)
5591 "Return t if we are looking at a real \"end\" keyword.
5592 Assumes that the caller will make sure that we are looking at
5593 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5594 the middle of an identifier that just happens to contain an \"end\"
5595 keyword."
5596 (or (not (looking-at "else"))
5597 ;; make sure that the "else" isn't inside a conditional signal
5598 ;; assignment.
5599 (save-excursion
5600 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5601 (or (eq (following-char) ?\;)
5602 (eq (point) lim)))))
5603
5604 (defun vhdl-corresponding-begin (&optional lim)
5605 "If the word at the current position corresponds to an \"end\"
5606 keyword, then return a vector containing enough information to find
5607 the corresponding \"begin\" keyword, else return nil. The keyword to
5608 search backward for is aref 0. The column in which the keyword must
5609 appear is aref 1 or nil if any column is suitable. The supplementary
5610 keyword to search forward for is aref 2 or nil if this is not
5611 required. If aref 3 is t, then the \"begin\" keyword may be found in
5612 the middle of a statement.
5613 Assumes that the caller will make sure that we are not in the middle
5614 of an identifier that just happens to contain an \"end\" keyword."
5615 (save-excursion
5616 (let (pos)
5617 (if (and (looking-at vhdl-end-fwd-re)
5618 (not (vhdl-in-literal))
5619 (vhdl-end-p lim))
5620 (if (looking-at "el")
5621 ;; "else", "elsif":
5622 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5623 ;; "end ...":
5624 (setq pos (point))
5625 (forward-sexp)
5626 (skip-chars-forward " \t\n")
5627 (cond
5628 ;; "end if":
5629 ((looking-at "if\\b[^_]")
5630 (vector "else\\|elsif\\|if"
5631 (vhdl-first-word pos)
5632 "else\\|then" nil))
5633 ;; "end component":
5634 ((looking-at "component\\b[^_]")
5635 (vector (buffer-substring (match-beginning 1)
5636 (match-end 1))
5637 (vhdl-first-word pos)
5638 nil nil))
5639 ;; "end units", "end record":
5640 ((looking-at "\\(units\\|record\\)\\b[^_]")
5641 (vector (buffer-substring (match-beginning 1)
5642 (match-end 1))
5643 (vhdl-first-word pos)
5644 nil t))
5645 ;; "end block", "end process", "end procedural":
5646 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5647 (vector "begin" (vhdl-first-word pos) nil nil))
5648 ;; "end case":
5649 ((looking-at "case\\b[^_]")
5650 (vector "case" (vhdl-first-word pos) "is" nil))
5651 ;; "end generate":
5652 ((looking-at "generate\\b[^_]")
5653 (vector "generate\\|for\\|if"
5654 (vhdl-first-word pos)
5655 "generate" nil))
5656 ;; "end loop":
5657 ((looking-at "loop\\b[^_]")
5658 (vector "loop\\|while\\|for"
5659 (vhdl-first-word pos)
5660 "loop" nil))
5661 ;; "end for" (inside configuration declaration):
5662 ((looking-at "for\\b[^_]")
5663 (vector "for" (vhdl-first-word pos) nil nil))
5664 ;; "end [id]":
5665 (t
5666 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5667 (vhdl-first-word pos)
5668 ;; return an alist of (statement . keyword) mappings
5669 '(
5670 ;; "begin ... end [id]":
5671 ("begin" . nil)
5672 ;; "architecture ... is ... begin ... end [id]":
5673 ("architecture" . "is")
5674 ;; "configuration ... is ... end [id]":
5675 ("configuration" . "is")
5676 ;; "entity ... is ... end [id]":
5677 ("entity" . "is")
5678 ;; "package ... is ... end [id]":
5679 ("package" . "is")
5680 ;; "procedure ... is ... begin ... end [id]":
5681 ("procedure" . "is")
5682 ;; "function ... is ... begin ... end [id]":
5683 ("function" . "is")
5684 )
5685 nil))
5686 ))) ; "end ..."
5687 )))
5688
5689 (defconst vhdl-leader-re
5690 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5691
5692 (defun vhdl-end-of-leader ()
5693 (save-excursion
5694 (cond ((looking-at "block\\|process\\|procedural")
5695 (if (save-excursion
5696 (forward-sexp)
5697 (skip-chars-forward " \t\n")
5698 (= (following-char) ?\())
5699 (forward-sexp 2)
5700 (forward-sexp))
5701 (when (looking-at "[ \t\n]*is")
5702 (goto-char (match-end 0)))
5703 (point))
5704 ((looking-at "component")
5705 (forward-sexp 2)
5706 (when (looking-at "[ \t\n]*is")
5707 (goto-char (match-end 0)))
5708 (point))
5709 ((looking-at "for")
5710 (forward-sexp 2)
5711 (skip-chars-forward " \t\n")
5712 (while (looking-at "[,:(]")
5713 (forward-sexp)
5714 (skip-chars-forward " \t\n"))
5715 (point))
5716 (t nil)
5717 )))
5718
5719 (defconst vhdl-trailer-re
5720 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5721
5722 (defconst vhdl-statement-fwd-re
5723 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5724 "A regular expression for searching forward that matches all known
5725 \"statement\" keywords.")
5726
5727 (defconst vhdl-statement-bwd-re
5728 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5729 "A regular expression for searching backward that matches all known
5730 \"statement\" keywords.")
5731
5732 (defun vhdl-statement-p (&optional lim)
5733 "Return t if we are looking at a real \"statement\" keyword.
5734 Assumes that the caller will make sure that we are looking at
5735 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5736 in the middle of an identifier that just happens to contain a
5737 \"statement\" keyword."
5738 (cond
5739 ;; "for" ... "generate":
5740 ((and (looking-at "f")
5741 ;; Make sure it's the start of a parameter specification.
5742 (save-excursion
5743 (forward-sexp 2)
5744 (skip-chars-forward " \t\n")
5745 (looking-at "in\\b[^_]"))
5746 ;; Make sure it's not an "end for".
5747 (save-excursion
5748 (backward-sexp)
5749 (not (looking-at "end\\s-+\\w"))))
5750 t)
5751 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5752 ((and (looking-at "i")
5753 ;; Make sure it's not an "end if".
5754 (save-excursion
5755 (backward-sexp)
5756 (not (looking-at "end\\s-+\\w"))))
5757 t)
5758 ;; "while" ... "loop":
5759 ((looking-at "w")
5760 t)
5761 ))
5762
5763 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5764 "Regexp describing a case statement alternative key.")
5765
5766 (defun vhdl-case-alternative-p (&optional lim)
5767 "Return t if we are looking at a real case alternative.
5768 Assumes that the caller will make sure that we are looking at
5769 vhdl-case-alternative-re, and are not inside a literal, and that
5770 we are not in the middle of an identifier that just happens to
5771 contain a \"when\" keyword."
5772 (save-excursion
5773 (let (foundp)
5774 (while (and (not foundp)
5775 (re-search-backward ";\\|<=" lim 'move))
5776 (if (or (= (preceding-char) ?_)
5777 (vhdl-in-literal))
5778 (backward-char)
5779 (setq foundp t)))
5780 (or (eq (following-char) ?\;)
5781 (eq (point) lim)))
5782 ))
5783
5784 ;; Core syntactic movement functions:
5785
5786 (defconst vhdl-b-t-b-re
5787 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5788
5789 (defun vhdl-backward-to-block (&optional lim)
5790 "Move backward to the previous \"begin\" or \"end\" keyword."
5791 (let (foundp)
5792 (while (and (not foundp)
5793 (re-search-backward vhdl-b-t-b-re lim 'move))
5794 (if (or (= (preceding-char) ?_)
5795 (vhdl-in-literal))
5796 (backward-char)
5797 (cond
5798 ;; "begin" keyword:
5799 ((and (looking-at vhdl-begin-fwd-re)
5800 (/= (preceding-char) ?_)
5801 (vhdl-begin-p lim))
5802 (setq foundp 'begin))
5803 ;; "end" keyword:
5804 ((and (looking-at vhdl-end-fwd-re)
5805 (/= (preceding-char) ?_)
5806 (vhdl-end-p lim))
5807 (setq foundp 'end))
5808 ))
5809 )
5810 foundp
5811 ))
5812
5813 (defun vhdl-forward-sexp (&optional count lim)
5814 "Move forward across one balanced expression (sexp).
5815 With COUNT, do it that many times."
5816 (interactive "p")
5817 (let ((count (or count 1))
5818 (case-fold-search t)
5819 end-vec target)
5820 (save-excursion
5821 (while (> count 0)
5822 ;; skip whitespace
5823 (skip-chars-forward " \t\n")
5824 ;; Check for an unbalanced "end" keyword
5825 (if (and (looking-at vhdl-end-fwd-re)
5826 (/= (preceding-char) ?_)
5827 (not (vhdl-in-literal))
5828 (vhdl-end-p lim)
5829 (not (looking-at "else")))
5830 (error
5831 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5832 ;; If the current keyword is a "begin" keyword, then find the
5833 ;; corresponding "end" keyword.
5834 (if (setq end-vec (vhdl-corresponding-end lim))
5835 (let (
5836 ;; end-re is the statement keyword to search for
5837 (end-re
5838 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5839 ;; column is either the statement keyword target column
5840 ;; or nil
5841 (column (aref end-vec 1))
5842 (eol (vhdl-point 'eol))
5843 foundp literal placeholder)
5844 ;; Look for the statement keyword.
5845 (while (and (not foundp)
5846 (re-search-forward end-re nil t)
5847 (setq placeholder (match-end 1))
5848 (goto-char (match-beginning 0)))
5849 ;; If we are in a literal, or not in the right target
5850 ;; column and not on the same line as the begin, then
5851 ;; try again.
5852 (if (or (and column
5853 (/= (current-indentation) column)
5854 (> (point) eol))
5855 (= (preceding-char) ?_)
5856 (setq literal (vhdl-in-literal)))
5857 (if (eq literal 'comment)
5858 (end-of-line)
5859 (forward-char))
5860 ;; An "else" keyword corresponds to both the opening brace
5861 ;; of the following sexp and the closing brace of the
5862 ;; previous sexp.
5863 (if (not (looking-at "else"))
5864 (goto-char placeholder))
5865 (setq foundp t))
5866 )
5867 (if (not foundp)
5868 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5869 )
5870 ;; If the current keyword is not a "begin" keyword, then just
5871 ;; perform the normal forward-sexp.
5872 (forward-sexp)
5873 )
5874 (setq count (1- count))
5875 )
5876 (setq target (point)))
5877 (goto-char target)
5878 nil))
5879
5880 (defun vhdl-backward-sexp (&optional count lim)
5881 "Move backward across one balanced expression (sexp).
5882 With COUNT, do it that many times. LIM bounds any required backward
5883 searches."
5884 (interactive "p")
5885 (let ((count (or count 1))
5886 (case-fold-search t)
5887 begin-vec target)
5888 (save-excursion
5889 (while (> count 0)
5890 ;; Perform the normal backward-sexp, unless we are looking at
5891 ;; "else" - an "else" keyword corresponds to both the opening brace
5892 ;; of the following sexp and the closing brace of the previous sexp.
5893 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5894 (/= (preceding-char) ?_)
5895 (not (vhdl-in-literal)))
5896 nil
5897 (backward-sexp)
5898 (if (and (looking-at vhdl-begin-fwd-re)
5899 (/= (preceding-char) ?_)
5900 (not (vhdl-in-literal))
5901 (vhdl-begin-p lim))
5902 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
5903 ;; If the current keyword is an "end" keyword, then find the
5904 ;; corresponding "begin" keyword.
5905 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5906 (/= (preceding-char) ?_))
5907 (let (
5908 ;; begin-re is the statement keyword to search for
5909 (begin-re
5910 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5911 ;; column is either the statement keyword target column
5912 ;; or nil
5913 (column (aref begin-vec 1))
5914 ;; internal-p controls where the statement keyword can
5915 ;; be found.
5916 (internal-p (aref begin-vec 3))
5917 (last-backward (point)) last-forward
5918 foundp literal keyword)
5919 ;; Look for the statement keyword.
5920 (while (and (not foundp)
5921 (re-search-backward begin-re lim t)
5922 (setq keyword
5923 (buffer-substring (match-beginning 1)
5924 (match-end 1))))
5925 ;; If we are in a literal or in the wrong column,
5926 ;; then try again.
5927 (if (or (and column
5928 (and (/= (current-indentation) column)
5929 ;; possibly accept current-column as
5930 ;; well as current-indentation.
5931 (or (not internal-p)
5932 (/= (current-column) column))))
5933 (= (preceding-char) ?_)
5934 (vhdl-in-literal))
5935 (backward-char)
5936 ;; If there is a supplementary keyword, then
5937 ;; search forward for it.
5938 (if (and (setq begin-re (aref begin-vec 2))
5939 (or (not (listp begin-re))
5940 ;; If begin-re is an alist, then find the
5941 ;; element corresponding to the actual
5942 ;; keyword that we found.
5943 (progn
5944 (setq begin-re
5945 (assoc keyword begin-re))
5946 (and begin-re
5947 (setq begin-re (cdr begin-re))))))
5948 (and
5949 (setq begin-re
5950 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5951 (save-excursion
5952 (setq last-forward (point))
5953 ;; Look for the supplementary keyword
5954 ;; (bounded by the backward search start
5955 ;; point).
5956 (while (and (not foundp)
5957 (re-search-forward begin-re
5958 last-backward t)
5959 (goto-char (match-beginning 1)))
5960 ;; If we are in a literal, then try again.
5961 (if (or (= (preceding-char) ?_)
5962 (setq literal
5963 (vhdl-in-literal)))
5964 (if (eq literal 'comment)
5965 (goto-char
5966 (min (vhdl-point 'eol) last-backward))
5967 (forward-char))
5968 ;; We have found the supplementary keyword.
5969 ;; Save the position of the keyword in foundp.
5970 (setq foundp (point)))
5971 )
5972 foundp)
5973 ;; If the supplementary keyword was found, then
5974 ;; move point to the supplementary keyword.
5975 (goto-char foundp))
5976 ;; If there was no supplementary keyword, then
5977 ;; point is already at the statement keyword.
5978 (setq foundp t)))
5979 ) ; end of the search for the statement keyword
5980 (if (not foundp)
5981 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
5982 ))
5983 (setq count (1- count))
5984 )
5985 (setq target (point)))
5986 (goto-char target)
5987 nil))
5988
5989 (defun vhdl-backward-up-list (&optional count limit)
5990 "Move backward out of one level of blocks.
5991 With argument, do this that many times."
5992 (interactive "p")
5993 (let ((count (or count 1))
5994 target)
5995 (save-excursion
5996 (while (> count 0)
5997 (if (looking-at vhdl-defun-re)
5998 (error "ERROR: Unbalanced blocks"))
5999 (vhdl-backward-to-block limit)
6000 (setq count (1- count)))
6001 (setq target (point)))
6002 (goto-char target)))
6003
6004 (defun vhdl-end-of-defun (&optional count)
6005 "Move forward to the end of a VHDL defun."
6006 (interactive)
6007 (let ((case-fold-search t))
6008 (vhdl-beginning-of-defun)
6009 (if (not (looking-at "block\\|process\\|procedural"))
6010 (re-search-forward "\\bis\\b"))
6011 (vhdl-forward-sexp)))
6012
6013 (defun vhdl-mark-defun ()
6014 "Put mark at end of this \"defun\", point at beginning."
6015 (interactive)
6016 (let ((case-fold-search t))
6017 (push-mark)
6018 (vhdl-beginning-of-defun)
6019 (push-mark)
6020 (if (not (looking-at "block\\|process\\|procedural"))
6021 (re-search-forward "\\bis\\b"))
6022 (vhdl-forward-sexp)
6023 (exchange-point-and-mark)))
6024
6025 (defun vhdl-beginning-of-libunit ()
6026 "Move backward to the beginning of a VHDL library unit.
6027 Returns the location of the corresponding begin keyword, unless search
6028 stops due to beginning or end of buffer.
6029 Note that if point is between the \"libunit\" keyword and the
6030 corresponding \"begin\" keyword, then that libunit will not be
6031 recognised, and the search will continue backwards. If point is
6032 at the \"begin\" keyword, then the defun will be recognised. The
6033 returned point is at the first character of the \"libunit\" keyword."
6034 (let ((last-forward (point))
6035 (last-backward
6036 ;; Just in case we are actually sitting on the "begin"
6037 ;; keyword, allow for the keyword and an extra character,
6038 ;; as this will be used when looking forward for the
6039 ;; "begin" keyword.
6040 (save-excursion (forward-word 1) (1+ (point))))
6041 foundp literal placeholder)
6042 ;; Find the "libunit" keyword.
6043 (while (and (not foundp)
6044 (re-search-backward vhdl-libunit-re nil 'move))
6045 ;; If we are in a literal, or not at a real libunit, then try again.
6046 (if (or (= (preceding-char) ?_)
6047 (vhdl-in-literal)
6048 (not (vhdl-libunit-p)))
6049 (backward-char)
6050 ;; Find the corresponding "begin" keyword.
6051 (setq last-forward (point))
6052 (while (and (not foundp)
6053 (re-search-forward "\\bis\\b[^_]" last-backward t)
6054 (setq placeholder (match-beginning 0)))
6055 (if (or (= (preceding-char) ?_)
6056 (setq literal (vhdl-in-literal)))
6057 ;; It wasn't a real keyword, so keep searching.
6058 (if (eq literal 'comment)
6059 (goto-char
6060 (min (vhdl-point 'eol) last-backward))
6061 (forward-char))
6062 ;; We have found the begin keyword, loop will exit.
6063 (setq foundp placeholder)))
6064 ;; Go back to the libunit keyword
6065 (goto-char last-forward)))
6066 foundp))
6067
6068 (defun vhdl-beginning-of-defun (&optional count)
6069 "Move backward to the beginning of a VHDL defun.
6070 With argument, do it that many times.
6071 Returns the location of the corresponding begin keyword, unless search
6072 stops due to beginning or end of buffer."
6073 ;; Note that if point is between the "defun" keyword and the
6074 ;; corresponding "begin" keyword, then that defun will not be
6075 ;; recognised, and the search will continue backwards. If point is
6076 ;; at the "begin" keyword, then the defun will be recognised. The
6077 ;; returned point is at the first character of the "defun" keyword.
6078 (interactive "p")
6079 (let ((count (or count 1))
6080 (case-fold-search t)
6081 (last-forward (point))
6082 foundp)
6083 (while (> count 0)
6084 (setq foundp nil)
6085 (goto-char last-forward)
6086 (let ((last-backward
6087 ;; Just in case we are actually sitting on the "begin"
6088 ;; keyword, allow for the keyword and an extra character,
6089 ;; as this will be used when looking forward for the
6090 ;; "begin" keyword.
6091 (save-excursion (forward-word 1) (1+ (point))))
6092 begin-string literal)
6093 (while (and (not foundp)
6094 (re-search-backward vhdl-defun-re nil 'move))
6095 ;; If we are in a literal, then try again.
6096 (if (or (= (preceding-char) ?_)
6097 (vhdl-in-literal))
6098 (backward-char)
6099 (if (setq begin-string (vhdl-corresponding-defun))
6100 ;; This is a real defun keyword.
6101 ;; Find the corresponding "begin" keyword.
6102 ;; Look for the begin keyword.
6103 (progn
6104 ;; Save the search start point.
6105 (setq last-forward (point))
6106 (while (and (not foundp)
6107 (search-forward begin-string last-backward t))
6108 (if (or (= (preceding-char) ?_)
6109 (save-match-data
6110 (setq literal (vhdl-in-literal))))
6111 ;; It wasn't a real keyword, so keep searching.
6112 (if (eq literal 'comment)
6113 (goto-char
6114 (min (vhdl-point 'eol) last-backward))
6115 (forward-char))
6116 ;; We have found the begin keyword, loop will exit.
6117 (setq foundp (match-beginning 0)))
6118 )
6119 ;; Go back to the defun keyword
6120 (goto-char last-forward)) ; end search for begin keyword
6121 ))
6122 ) ; end of the search for the defun keyword
6123 )
6124 (setq count (1- count))
6125 )
6126 (vhdl-keep-region-active)
6127 foundp))
6128
6129 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6130 "Go to the beginning of the innermost VHDL statement.
6131 With prefix arg, go back N - 1 statements. If already at the
6132 beginning of a statement then go to the beginning of the preceding
6133 one. If within a string or comment, or next to a comment (only
6134 whitespace between), move by sentences instead of statements.
6135
6136 When called from a program, this function takes 3 optional args: the
6137 prefix arg, and a buffer position limit which is the farthest back to
6138 search, and something whose meaning I don't understand."
6139 (interactive "p\np")
6140 (let ((count (or count 1))
6141 (case-fold-search t)
6142 (lim (or lim (point-min)))
6143 (here (point))
6144 state)
6145 (save-excursion
6146 (goto-char lim)
6147 (setq state (parse-partial-sexp (point) here nil nil)))
6148 (if (and interactive
6149 (or (nth 3 state)
6150 (nth 4 state)
6151 (looking-at (concat "[ \t]*" comment-start-skip))))
6152 (forward-sentence (- count))
6153 (while (> count 0)
6154 (vhdl-beginning-of-statement-1 lim)
6155 (setq count (1- count))))
6156 ;; its possible we've been left up-buf of lim
6157 (goto-char (max (point) lim))
6158 )
6159 (vhdl-keep-region-active))
6160
6161 (defconst vhdl-e-o-s-re
6162 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6163
6164 (defun vhdl-end-of-statement ()
6165 "Very simple implementation."
6166 (interactive)
6167 (re-search-forward vhdl-e-o-s-re))
6168
6169 (defconst vhdl-b-o-s-re
6170 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6171 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6172
6173 (defun vhdl-beginning-of-statement-1 (&optional lim)
6174 "Move to the start of the current statement, or the previous
6175 statement if already at the beginning of one."
6176 (let ((lim (or lim (point-min)))
6177 (here (point))
6178 (pos (point))
6179 donep)
6180 ;; go backwards one balanced expression, but be careful of
6181 ;; unbalanced paren being reached
6182 (if (not (vhdl-safe (progn (backward-sexp) t)))
6183 (progn
6184 (backward-up-list 1)
6185 (forward-char)
6186 (vhdl-forward-syntactic-ws here)
6187 (setq donep t)))
6188 (while (and (not donep)
6189 (not (bobp))
6190 ;; look backwards for a statement boundary
6191 (re-search-backward vhdl-b-o-s-re lim 'move))
6192 (if (or (= (preceding-char) ?_)
6193 (vhdl-in-literal))
6194 (backward-char)
6195 (cond
6196 ;; If we are looking at an open paren, then stop after it
6197 ((eq (following-char) ?\()
6198 (forward-char)
6199 (vhdl-forward-syntactic-ws here)
6200 (setq donep t))
6201 ;; If we are looking at a close paren, then skip it
6202 ((eq (following-char) ?\))
6203 (forward-char)
6204 (setq pos (point))
6205 (backward-sexp)
6206 (if (< (point) lim)
6207 (progn (goto-char pos)
6208 (vhdl-forward-syntactic-ws here)
6209 (setq donep t))))
6210 ;; If we are looking at a semicolon, then stop
6211 ((eq (following-char) ?\;)
6212 (progn
6213 (forward-char)
6214 (vhdl-forward-syntactic-ws here)
6215 (setq donep t)))
6216 ;; If we are looking at a "begin", then stop
6217 ((and (looking-at vhdl-begin-fwd-re)
6218 (/= (preceding-char) ?_)
6219 (vhdl-begin-p nil))
6220 ;; If it's a leader "begin", then find the
6221 ;; right place
6222 (if (looking-at vhdl-leader-re)
6223 (save-excursion
6224 ;; set a default stop point at the begin
6225 (setq pos (point))
6226 ;; is the start point inside the leader area ?
6227 (goto-char (vhdl-end-of-leader))
6228 (vhdl-forward-syntactic-ws here)
6229 (if (< (point) here)
6230 ;; start point was not inside leader area
6231 ;; set stop point at word after leader
6232 (setq pos (point))))
6233 (forward-word 1)
6234 (vhdl-forward-syntactic-ws here)
6235 (setq pos (point)))
6236 (goto-char pos)
6237 (setq donep t))
6238 ;; If we are looking at a "statement", then stop
6239 ((and (looking-at vhdl-statement-fwd-re)
6240 (/= (preceding-char) ?_)
6241 (vhdl-statement-p nil))
6242 (setq donep t))
6243 ;; If we are looking at a case alternative key, then stop
6244 ((and (looking-at vhdl-case-alternative-re)
6245 (vhdl-case-alternative-p lim))
6246 (save-excursion
6247 ;; set a default stop point at the when
6248 (setq pos (point))
6249 ;; is the start point inside the case alternative key ?
6250 (looking-at vhdl-case-alternative-re)
6251 (goto-char (match-end 0))
6252 (vhdl-forward-syntactic-ws here)
6253 (if (< (point) here)
6254 ;; start point was not inside the case alternative key
6255 ;; set stop point at word after case alternative keyleader
6256 (setq pos (point))))
6257 (goto-char pos)
6258 (setq donep t))
6259 ;; Bogus find, continue
6260 (t
6261 (backward-char)))))
6262 ))
6263
6264 ;; Defuns for calculating the current syntactic state:
6265
6266 (defun vhdl-get-library-unit (bod placeholder)
6267 "If there is an enclosing library unit at bod, with it's \"begin\"
6268 keyword at placeholder, then return the library unit type."
6269 (let ((here (vhdl-point 'bol)))
6270 (if (save-excursion
6271 (goto-char placeholder)
6272 (vhdl-safe (vhdl-forward-sexp 1 bod))
6273 (<= here (point)))
6274 (save-excursion
6275 (goto-char bod)
6276 (cond
6277 ((looking-at "e") 'entity)
6278 ((looking-at "a") 'architecture)
6279 ((looking-at "c") 'configuration)
6280 ((looking-at "p")
6281 (save-excursion
6282 (goto-char bod)
6283 (forward-sexp)
6284 (vhdl-forward-syntactic-ws here)
6285 (if (looking-at "body\\b[^_]")
6286 'package-body 'package))))))
6287 ))
6288
6289 (defun vhdl-get-block-state (&optional lim)
6290 "Finds and records all the closest opens.
6291 lim is the furthest back we need to search (it should be the
6292 previous libunit keyword)."
6293 (let ((here (point))
6294 (lim (or lim (point-min)))
6295 keyword sexp-start sexp-mid sexp-end
6296 preceding-sexp containing-sexp
6297 containing-begin containing-mid containing-paren)
6298 (save-excursion
6299 ;; Find the containing-paren, and use that as the limit
6300 (if (setq containing-paren
6301 (save-restriction
6302 (narrow-to-region lim (point))
6303 (vhdl-safe (scan-lists (point) -1 1))))
6304 (setq lim containing-paren))
6305 ;; Look backwards for "begin" and "end" keywords.
6306 (while (and (> (point) lim)
6307 (not containing-sexp))
6308 (setq keyword (vhdl-backward-to-block lim))
6309 (cond
6310 ((eq keyword 'begin)
6311 ;; Found a "begin" keyword
6312 (setq sexp-start (point))
6313 (setq sexp-mid (vhdl-corresponding-mid lim))
6314 (setq sexp-end (vhdl-safe
6315 (save-excursion
6316 (vhdl-forward-sexp 1 lim) (point))))
6317 (if (and sexp-end (<= sexp-end here))
6318 ;; we want to record this sexp, but we only want to
6319 ;; record the last-most of any of them before here
6320 (or preceding-sexp
6321 (setq preceding-sexp sexp-start))
6322 ;; we're contained in this sexp so put sexp-start on
6323 ;; front of list
6324 (setq containing-sexp sexp-start)
6325 (setq containing-mid sexp-mid)
6326 (setq containing-begin t)))
6327 ((eq keyword 'end)
6328 ;; Found an "end" keyword
6329 (forward-sexp)
6330 (setq sexp-end (point))
6331 (setq sexp-mid nil)
6332 (setq sexp-start
6333 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6334 (progn (backward-sexp) (point))))
6335 ;; we want to record this sexp, but we only want to
6336 ;; record the last-most of any of them before here
6337 (or preceding-sexp
6338 (setq preceding-sexp sexp-start)))
6339 )))
6340 ;; Check if the containing-paren should be the containing-sexp
6341 (if (and containing-paren
6342 (or (null containing-sexp)
6343 (< containing-sexp containing-paren)))
6344 (setq containing-sexp containing-paren
6345 preceding-sexp nil
6346 containing-begin nil
6347 containing-mid nil))
6348 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6349 ))
6350
6351
6352 (defconst vhdl-s-c-a-re
6353 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6354
6355 (defun vhdl-skip-case-alternative (&optional lim)
6356 "Skip forward over case/when bodies, with optional maximal
6357 limit. If no next case alternative is found, nil is returned and point
6358 is not moved."
6359 (let ((lim (or lim (point-max)))
6360 (here (point))
6361 donep foundp)
6362 (while (and (< (point) lim)
6363 (not donep))
6364 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6365 (save-match-data
6366 (not (vhdl-in-literal)))
6367 (/= (match-beginning 0) here))
6368 (progn
6369 (goto-char (match-beginning 0))
6370 (cond
6371 ((and (looking-at "case")
6372 (re-search-forward "\\bis[^_]" lim t))
6373 (backward-sexp)
6374 (vhdl-forward-sexp))
6375 (t
6376 (setq donep t
6377 foundp t))))))
6378 (if (not foundp)
6379 (goto-char here))
6380 foundp))
6381
6382 (defun vhdl-backward-skip-label (&optional lim)
6383 "Skip backward over a label, with optional maximal
6384 limit. If label is not found, nil is returned and point
6385 is not moved."
6386 (let ((lim (or lim (point-min)))
6387 placeholder)
6388 (if (save-excursion
6389 (vhdl-backward-syntactic-ws lim)
6390 (and (eq (preceding-char) ?:)
6391 (progn
6392 (backward-sexp)
6393 (setq placeholder (point))
6394 (looking-at vhdl-label-key))))
6395 (goto-char placeholder))
6396 ))
6397
6398 (defun vhdl-forward-skip-label (&optional lim)
6399 "Skip forward over a label, with optional maximal
6400 limit. If label is not found, nil is returned and point
6401 is not moved."
6402 (let ((lim (or lim (point-max))))
6403 (if (looking-at vhdl-label-key)
6404 (progn
6405 (goto-char (match-end 0))
6406 (vhdl-forward-syntactic-ws lim)))
6407 ))
6408
6409 (defun vhdl-get-syntactic-context ()
6410 "Guess the syntactic description of the current line of VHDL code."
6411 (save-excursion
6412 (save-restriction
6413 (beginning-of-line)
6414 (let* ((indent-point (point))
6415 (case-fold-search t)
6416 vec literal containing-sexp preceding-sexp
6417 containing-begin containing-mid containing-leader
6418 char-before-ip char-after-ip begin-after-ip end-after-ip
6419 placeholder lim library-unit
6420 )
6421
6422 ;; Reset the syntactic context
6423 (setq vhdl-syntactic-context nil)
6424
6425 (save-excursion
6426 ;; Move to the start of the previous library unit, and
6427 ;; record the position of the "begin" keyword.
6428 (setq placeholder (vhdl-beginning-of-libunit))
6429 ;; The position of the "libunit" keyword gives us a gross
6430 ;; limit point.
6431 (setq lim (point))
6432 )
6433
6434 ;; If there is a previous library unit, and we are enclosed by
6435 ;; it, then set the syntax accordingly.
6436 (and placeholder
6437 (setq library-unit (vhdl-get-library-unit lim placeholder))
6438 (vhdl-add-syntax library-unit lim))
6439
6440 ;; Find the surrounding state.
6441 (if (setq vec (vhdl-get-block-state lim))
6442 (progn
6443 (setq containing-sexp (aref vec 0))
6444 (setq preceding-sexp (aref vec 1))
6445 (setq containing-begin (aref vec 2))
6446 (setq containing-mid (aref vec 3))
6447 ))
6448
6449 ;; set the limit on the farthest back we need to search
6450 (setq lim (if containing-sexp
6451 (save-excursion
6452 (goto-char containing-sexp)
6453 ;; set containing-leader if required
6454 (if (looking-at vhdl-leader-re)
6455 (setq containing-leader (vhdl-end-of-leader)))
6456 (vhdl-point 'bol))
6457 (point-min)))
6458
6459 ;; cache char before and after indent point, and move point to
6460 ;; the most likely position to perform the majority of tests
6461 (goto-char indent-point)
6462 (skip-chars-forward " \t")
6463 (setq literal (vhdl-in-literal))
6464 (setq char-after-ip (following-char))
6465 (setq begin-after-ip (and
6466 (not literal)
6467 (looking-at vhdl-begin-fwd-re)
6468 (vhdl-begin-p)))
6469 (setq end-after-ip (and
6470 (not literal)
6471 (looking-at vhdl-end-fwd-re)
6472 (vhdl-end-p)))
6473 (vhdl-backward-syntactic-ws lim)
6474 (setq char-before-ip (preceding-char))
6475 (goto-char indent-point)
6476 (skip-chars-forward " \t")
6477
6478 ;; now figure out syntactic qualities of the current line
6479 (cond
6480 ;; CASE 1: in a string or comment.
6481 ((memq literal '(string comment))
6482 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6483 ;; CASE 2: Line is at top level.
6484 ((null containing-sexp)
6485 ;; Find the point to which indentation will be relative
6486 (save-excursion
6487 (if (null preceding-sexp)
6488 ;; CASE 2X.1
6489 ;; no preceding-sexp -> use the preceding statement
6490 (vhdl-beginning-of-statement-1 lim)
6491 ;; CASE 2X.2
6492 ;; if there is a preceding-sexp then indent relative to it
6493 (goto-char preceding-sexp)
6494 ;; if not at boi, then the block-opening keyword is
6495 ;; probably following a label, so we need a different
6496 ;; relpos
6497 (if (/= (point) (vhdl-point 'boi))
6498 ;; CASE 2X.3
6499 (vhdl-beginning-of-statement-1 lim)))
6500 ;; v-b-o-s could have left us at point-min
6501 (and (bobp)
6502 ;; CASE 2X.4
6503 (vhdl-forward-syntactic-ws indent-point))
6504 (setq placeholder (point)))
6505 (cond
6506 ;; CASE 2A : we are looking at a block-open
6507 (begin-after-ip
6508 (vhdl-add-syntax 'block-open placeholder))
6509 ;; CASE 2B: we are looking at a block-close
6510 (end-after-ip
6511 (vhdl-add-syntax 'block-close placeholder))
6512 ;; CASE 2C: we are looking at a top-level statement
6513 ((progn
6514 (vhdl-backward-syntactic-ws lim)
6515 (or (bobp)
6516 (= (preceding-char) ?\;)))
6517 (vhdl-add-syntax 'statement placeholder))
6518 ;; CASE 2D: we are looking at a top-level statement-cont
6519 (t
6520 (vhdl-beginning-of-statement-1 lim)
6521 ;; v-b-o-s could have left us at point-min
6522 (and (bobp)
6523 ;; CASE 2D.1
6524 (vhdl-forward-syntactic-ws indent-point))
6525 (vhdl-add-syntax 'statement-cont (point)))
6526 )) ; end CASE 2
6527 ;; CASE 3: line is inside parentheses. Most likely we are
6528 ;; either in a subprogram argument (interface) list, or a
6529 ;; continued expression containing parentheses.
6530 ((null containing-begin)
6531 (vhdl-backward-syntactic-ws containing-sexp)
6532 (cond
6533 ;; CASE 3A: we are looking at the arglist closing paren
6534 ((eq char-after-ip ?\))
6535 (goto-char containing-sexp)
6536 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6537 ;; CASE 3B: we are looking at the first argument in an empty
6538 ;; argument list.
6539 ((eq char-before-ip ?\()
6540 (goto-char containing-sexp)
6541 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6542 ;; CASE 3C: we are looking at an arglist continuation line,
6543 ;; but the preceding argument is on the same line as the
6544 ;; opening paren. This case includes multi-line
6545 ;; expression paren groupings.
6546 ((and (save-excursion
6547 (goto-char (1+ containing-sexp))
6548 (skip-chars-forward " \t")
6549 (not (eolp))
6550 (not (looking-at "--")))
6551 (save-excursion
6552 (vhdl-beginning-of-statement-1 containing-sexp)
6553 (skip-chars-backward " \t(")
6554 (<= (point) containing-sexp)))
6555 (goto-char containing-sexp)
6556 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6557 ;; CASE 3D: we are looking at just a normal arglist
6558 ;; continuation line
6559 (t (vhdl-beginning-of-statement-1 containing-sexp)
6560 (vhdl-forward-syntactic-ws indent-point)
6561 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6562 ))
6563 ;; CASE 4: A block mid open
6564 ((and begin-after-ip
6565 (looking-at containing-mid))
6566 (goto-char containing-sexp)
6567 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6568 (if (looking-at vhdl-trailer-re)
6569 ;; CASE 4.1
6570 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6571 (vhdl-backward-skip-label (vhdl-point 'boi))
6572 (vhdl-add-syntax 'block-open (point)))
6573 ;; CASE 5: block close brace
6574 (end-after-ip
6575 (goto-char containing-sexp)
6576 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6577 (if (looking-at vhdl-trailer-re)
6578 ;; CASE 5.1
6579 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6580 (vhdl-backward-skip-label (vhdl-point 'boi))
6581 (vhdl-add-syntax 'block-close (point)))
6582 ;; CASE 6: A continued statement
6583 ((and (/= char-before-ip ?\;)
6584 ;; check it's not a trailer begin keyword, or a begin
6585 ;; keyword immediately following a label.
6586 (not (and begin-after-ip
6587 (or (looking-at vhdl-trailer-re)
6588 (save-excursion
6589 (vhdl-backward-skip-label containing-sexp)))))
6590 ;; check it's not a statement keyword
6591 (not (and (looking-at vhdl-statement-fwd-re)
6592 (vhdl-statement-p)))
6593 ;; see if the b-o-s is before the indent point
6594 (> indent-point
6595 (save-excursion
6596 (vhdl-beginning-of-statement-1 containing-sexp)
6597 ;; If we ended up after a leader, then this will
6598 ;; move us forward to the start of the first
6599 ;; statement. Note that a containing sexp here is
6600 ;; always a keyword, not a paren, so this will
6601 ;; have no effect if we hit the containing-sexp.
6602 (vhdl-forward-syntactic-ws indent-point)
6603 (setq placeholder (point))))
6604 ;; check it's not a block-intro
6605 (/= placeholder containing-sexp)
6606 ;; check it's not a case block-intro
6607 (save-excursion
6608 (goto-char placeholder)
6609 (or (not (looking-at vhdl-case-alternative-re))
6610 (> (match-end 0) indent-point))))
6611 ;; Make placeholder skip a label, but only if it puts us
6612 ;; before the indent point at the start of a line.
6613 (let ((new placeholder))
6614 (if (and (> indent-point
6615 (save-excursion
6616 (goto-char placeholder)
6617 (vhdl-forward-skip-label indent-point)
6618 (setq new (point))))
6619 (save-excursion
6620 (goto-char new)
6621 (eq new (progn (back-to-indentation) (point)))))
6622 (setq placeholder new)))
6623 (vhdl-add-syntax 'statement-cont placeholder)
6624 (if begin-after-ip
6625 (vhdl-add-syntax 'block-open)))
6626 ;; Statement. But what kind?
6627 ;; CASE 7: A case alternative key
6628 ((and (looking-at vhdl-case-alternative-re)
6629 (vhdl-case-alternative-p containing-sexp))
6630 ;; for a case alternative key, we set relpos to the first
6631 ;; non-whitespace char on the line containing the "case"
6632 ;; keyword.
6633 (goto-char containing-sexp)
6634 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6635 (if (looking-at vhdl-trailer-re)
6636 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6637 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6638 ;; CASE 8: statement catchall
6639 (t
6640 ;; we know its a statement, but we need to find out if it is
6641 ;; the first statement in a block
6642 (if containing-leader
6643 (goto-char containing-leader)
6644 (goto-char containing-sexp)
6645 ;; Note that a containing sexp here is always a keyword,
6646 ;; not a paren, so skip over the keyword.
6647 (forward-sexp))
6648 ;; move to the start of the first statement
6649 (vhdl-forward-syntactic-ws indent-point)
6650 (setq placeholder (point))
6651 ;; we want to ignore case alternatives keys when skipping forward
6652 (let (incase-p)
6653 (while (looking-at vhdl-case-alternative-re)
6654 (setq incase-p (point))
6655 ;; we also want to skip over the body of the
6656 ;; case/when statement if that doesn't put us at
6657 ;; after the indent-point
6658 (while (vhdl-skip-case-alternative indent-point))
6659 ;; set up the match end
6660 (looking-at vhdl-case-alternative-re)
6661 (goto-char (match-end 0))
6662 ;; move to the start of the first case alternative statement
6663 (vhdl-forward-syntactic-ws indent-point)
6664 (setq placeholder (point)))
6665 (cond
6666 ;; CASE 8A: we saw a case/when statement so we must be
6667 ;; in a switch statement. find out if we are at the
6668 ;; statement just after a case alternative key
6669 ((and incase-p
6670 (= (point) indent-point))
6671 ;; relpos is the "when" keyword
6672 (vhdl-add-syntax 'statement-case-intro incase-p))
6673 ;; CASE 8B: any old statement
6674 ((< (point) indent-point)
6675 ;; relpos is the first statement of the block
6676 (vhdl-add-syntax 'statement placeholder)
6677 (if begin-after-ip
6678 (vhdl-add-syntax 'block-open)))
6679 ;; CASE 8C: first statement in a block
6680 (t
6681 (goto-char containing-sexp)
6682 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6683 (if (looking-at vhdl-trailer-re)
6684 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6685 (vhdl-backward-skip-label (vhdl-point 'boi))
6686 (vhdl-add-syntax 'statement-block-intro (point))
6687 (if begin-after-ip
6688 (vhdl-add-syntax 'block-open)))
6689 )))
6690 )
6691
6692 ;; now we need to look at any modifiers
6693 (goto-char indent-point)
6694 (skip-chars-forward " \t")
6695 (if (looking-at "--")
6696 (vhdl-add-syntax 'comment))
6697 ;; return the syntax
6698 vhdl-syntactic-context))))
6699
6700 ;; Standard indentation line-ups:
6701
6702 (defun vhdl-lineup-arglist (langelem)
6703 "Lineup the current arglist line with the arglist appearing just
6704 after the containing paren which starts the arglist."
6705 (save-excursion
6706 (let* ((containing-sexp
6707 (save-excursion
6708 ;; arglist-cont-nonempty gives relpos ==
6709 ;; to boi of containing-sexp paren. This
6710 ;; is good when offset is +, but bad
6711 ;; when it is vhdl-lineup-arglist, so we
6712 ;; have to special case a kludge here.
6713 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6714 (progn
6715 (beginning-of-line)
6716 (backward-up-list 1)
6717 (skip-chars-forward " \t" (vhdl-point 'eol)))
6718 (goto-char (cdr langelem)))
6719 (point)))
6720 (cs-curcol (save-excursion
6721 (goto-char (cdr langelem))
6722 (current-column))))
6723 (if (save-excursion
6724 (beginning-of-line)
6725 (looking-at "[ \t]*)"))
6726 (progn (goto-char (match-end 0))
6727 (backward-sexp)
6728 (forward-char)
6729 (vhdl-forward-syntactic-ws)
6730 (- (current-column) cs-curcol))
6731 (goto-char containing-sexp)
6732 (or (eolp)
6733 (let ((eol (vhdl-point 'eol))
6734 (here (progn
6735 (forward-char)
6736 (skip-chars-forward " \t")
6737 (point))))
6738 (vhdl-forward-syntactic-ws)
6739 (if (< (point) eol)
6740 (goto-char here))))
6741 (- (current-column) cs-curcol)
6742 ))))
6743
6744 (defun vhdl-lineup-arglist-intro (langelem)
6745 "Lineup an arglist-intro line to just after the open paren."
6746 (save-excursion
6747 (let ((cs-curcol (save-excursion
6748 (goto-char (cdr langelem))
6749 (current-column)))
6750 (ce-curcol (save-excursion
6751 (beginning-of-line)
6752 (backward-up-list 1)
6753 (skip-chars-forward " \t" (vhdl-point 'eol))
6754 (current-column))))
6755 (- ce-curcol cs-curcol -1))))
6756
6757 (defun vhdl-lineup-comment (langelem)
6758 "Support old behavior for comment indentation. We look at
6759 vhdl-comment-only-line-offset to decide how to indent comment
6760 only-lines."
6761 (save-excursion
6762 (back-to-indentation)
6763 ;; at or to the right of comment-column
6764 (if (>= (current-column) comment-column)
6765 (vhdl-comment-indent)
6766 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6767 (if (not (bolp))
6768 (or (car-safe vhdl-comment-only-line-offset)
6769 vhdl-comment-only-line-offset)
6770 (or (cdr-safe vhdl-comment-only-line-offset)
6771 (car-safe vhdl-comment-only-line-offset)
6772 -1000 ;jam it against the left side
6773 )))))
6774
6775 (defun vhdl-lineup-statement-cont (langelem)
6776 "Line up statement-cont after the assignment operator."
6777 (save-excursion
6778 (let* ((relpos (cdr langelem))
6779 (assignp (save-excursion
6780 (goto-char (vhdl-point 'boi))
6781 (and (re-search-forward "\\(<\\|:\\)="
6782 (vhdl-point 'eol) t)
6783 (- (point) (vhdl-point 'boi)))))
6784 (curcol (progn
6785 (goto-char relpos)
6786 (current-column)))
6787 foundp)
6788 (while (and (not foundp)
6789 (< (point) (vhdl-point 'eol)))
6790 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6791 (if (vhdl-in-literal)
6792 (forward-char)
6793 (if (= (preceding-char) ?\()
6794 ;; skip over any parenthesized expressions
6795 (goto-char (min (vhdl-point 'eol)
6796 (scan-lists (point) 1 1)))
6797 ;; found an assignment operator (not at eol)
6798 (setq foundp (not (looking-at "\\s-*$"))))))
6799 (if (not foundp)
6800 ;; there's no assignment operator on the line
6801 vhdl-basic-offset
6802 ;; calculate indentation column after assign and ws, unless
6803 ;; our line contains an assignment operator
6804 (if (not assignp)
6805 (progn
6806 (forward-char)
6807 (skip-chars-forward " \t")
6808 (setq assignp 0)))
6809 (- (current-column) assignp curcol))
6810 )))
6811
6812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6813 ;; Progress reporting
6814
6815 (defvar vhdl-progress-info nil
6816 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6817
6818 (defun vhdl-update-progress-info (string pos)
6819 "Update progress information."
6820 (when (and vhdl-progress-info (not noninteractive)
6821 (< vhdl-progress-interval
6822 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6823 (message (concat string "... (%2d%s)")
6824 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6825 (- (aref vhdl-progress-info 1)
6826 (aref vhdl-progress-info 0))) "%")
6827 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6828
6829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6830 ;; Indentation commands
6831
6832 (defun vhdl-electric-tab (&optional prefix-arg)
6833 "If preceeding character is part of a word or a paren then hippie-expand,
6834 else if right of non whitespace on line then insert tab,
6835 else if last command was a tab or return then dedent one step or if a comment
6836 toggle between normal indent and inline comment indent,
6837 else indent `correctly'."
6838 (interactive "*P")
6839 (vhdl-prepare-search-2
6840 (cond
6841 ;; expand word
6842 ((= (char-syntax (preceding-char)) ?w)
6843 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6844 (case-replace nil)
6845 (hippie-expand-only-buffers
6846 (or (and (boundp 'hippie-expand-only-buffers)
6847 hippie-expand-only-buffers)
6848 '(vhdl-mode))))
6849 (vhdl-expand-abbrev prefix-arg)))
6850 ;; expand parenthesis
6851 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6852 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6853 (case-replace nil))
6854 (vhdl-expand-paren prefix-arg)))
6855 ;; insert tab
6856 ((> (current-column) (current-indentation))
6857 (insert-tab))
6858 ;; toggle comment indent
6859 ((and (looking-at "--")
6860 (or (eq last-command 'vhdl-electric-tab)
6861 (eq last-command 'vhdl-electric-return)))
6862 (cond ((= (current-indentation) 0) ; no indent
6863 (indent-to 1)
6864 (indent-according-to-mode))
6865 ((< (current-indentation) comment-column) ; normal indent
6866 (indent-to comment-column)
6867 (indent-according-to-mode))
6868 (t ; inline comment indent
6869 (kill-line -0))))
6870 ;; dedent
6871 ((and (>= (current-indentation) vhdl-basic-offset)
6872 (or (eq last-command 'vhdl-electric-tab)
6873 (eq last-command 'vhdl-electric-return)))
6874 (backward-delete-char-untabify vhdl-basic-offset nil))
6875 ;; indent line
6876 (t (indent-according-to-mode)))
6877 (setq this-command 'vhdl-electric-tab)))
6878
6879 (defun vhdl-electric-return ()
6880 "newline-and-indent or indent-new-comment-line if in comment and preceding
6881 character is a space."
6882 (interactive)
6883 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6884 (indent-new-comment-line)
6885 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6886 (vhdl-fix-case-word -1))
6887 (newline-and-indent)))
6888
6889 (defun vhdl-indent-line ()
6890 "Indent the current line as VHDL code. Returns the amount of
6891 indentation change."
6892 (interactive)
6893 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
6894 (pos (- (point-max) (point)))
6895 (indent
6896 (if syntax
6897 ;; indent syntax-based
6898 (if (and (eq (caar syntax) 'comment)
6899 (>= (vhdl-get-offset (car syntax)) comment-column))
6900 ;; special case: comments at or right of comment-column
6901 (vhdl-get-offset (car syntax))
6902 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6903 ;; indent like previous nonblank line
6904 (save-excursion (beginning-of-line)
6905 (re-search-backward "^[^\n]" nil t)
6906 (current-indentation))))
6907 (shift-amt (- indent (current-indentation))))
6908 (and vhdl-echo-syntactic-information-p
6909 (message "syntax: %s, indent= %d" syntax indent))
6910 (unless (zerop shift-amt)
6911 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6912 (beginning-of-line)
6913 (indent-to indent))
6914 (if (< (point) (vhdl-point 'boi))
6915 (back-to-indentation)
6916 ;; If initial point was within line's indentation, position after
6917 ;; the indentation. Else stay at same point in text.
6918 (when (> (- (point-max) pos) (point))
6919 (goto-char (- (point-max) pos))))
6920 (run-hooks 'vhdl-special-indent-hook)
6921 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
6922 shift-amt))
6923
6924 (defun vhdl-indent-region (beg end column)
6925 "Indent region as VHDL code.
6926 Adds progress reporting to `indent-region'."
6927 (interactive "r\nP")
6928 (when vhdl-progress-interval
6929 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6930 (count-lines (point-min) end) 0)))
6931 (indent-region beg end column)
6932 (when vhdl-progress-interval (message "Indenting...done"))
6933 (setq vhdl-progress-info nil))
6934
6935 (defun vhdl-indent-buffer ()
6936 "Indent whole buffer as VHDL code.
6937 Calls `indent-region' for whole buffer and adds progress reporting."
6938 (interactive)
6939 (vhdl-indent-region (point-min) (point-max) nil))
6940
6941 (defun vhdl-indent-group ()
6942 "Indent group of lines between empty lines."
6943 (interactive)
6944 (let ((beg (save-excursion
6945 (if (re-search-backward vhdl-align-group-separate nil t)
6946 (point-marker)
6947 (point-min-marker))))
6948 (end (save-excursion
6949 (if (re-search-forward vhdl-align-group-separate nil t)
6950 (point-marker)
6951 (point-max-marker)))))
6952 (vhdl-indent-region beg end nil)))
6953
6954 (defun vhdl-indent-sexp (&optional endpos)
6955 "Indent each line of the list starting just after point.
6956 If optional arg ENDPOS is given, indent each line, stopping when
6957 ENDPOS is encountered."
6958 (interactive)
6959 (save-excursion
6960 (let ((beg (point))
6961 (end (progn (vhdl-forward-sexp nil endpos) (point))))
6962 (indent-region beg end nil))))
6963
6964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6965 ;; Miscellaneous commands
6966
6967 (defun vhdl-show-syntactic-information ()
6968 "Show syntactic information for current line."
6969 (interactive)
6970 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
6971 (vhdl-keep-region-active))
6972
6973 ;; Verification and regression functions:
6974
6975 (defun vhdl-regress-line (&optional arg)
6976 "Check syntactic information for current line."
6977 (interactive "P")
6978 (let ((expected (save-excursion
6979 (end-of-line)
6980 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6981 (forward-char 4)
6982 (read (current-buffer)))))
6983 (actual (vhdl-get-syntactic-context))
6984 (expurgated))
6985 ;; remove the library unit symbols
6986 (mapcar
6987 (function
6988 (lambda (elt)
6989 (if (memq (car elt) '(entity configuration package
6990 package-body architecture))
6991 nil
6992 (setq expurgated (append expurgated (list elt))))))
6993 actual)
6994 (if (and (not arg) expected (listp expected))
6995 (if (not (equal expected expurgated))
6996 (error "ERROR: Should be: %s, is: %s" expected expurgated))
6997 (save-excursion
6998 (beginning-of-line)
6999 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7000 (end-of-line)
7001 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7002 (kill-line))
7003 (insert " -- ")
7004 (insert (format "%s" expurgated))))))
7005 (vhdl-keep-region-active))
7006
7007
7008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7009 ;;; Alignment, whitespace fixup, beautifying
7010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7011
7012 (defconst vhdl-align-alist
7013 '(
7014 ;; after some keywords
7015 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7016 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7017 ;; before ':'
7018 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7019 ;; after direction specifications
7020 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7021 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7022 ;; before "==", ":=", "=>", and "<="
7023 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7024 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7025 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7026 ;; before some keywords
7027 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7028 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7029 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7030 ;; before "=>" since "when/else ... =>" can occur
7031 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7032 )
7033 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7034 It is searched in order. If REGEXP is found anywhere in the first
7035 line of a region to be aligned, ALIGN-PATTERN will be used for that
7036 region. ALIGN-PATTERN must include the whitespace to be expanded or
7037 contracted. It may also provide regexps for the text surrounding the
7038 whitespace. SUBEXP specifies which sub-expression of
7039 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7040
7041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7042 ;; Align code
7043
7044 (defvar vhdl-align-try-all-clauses t
7045 "If REGEXP is not found on the first line of the region that clause
7046 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7047
7048 (defun vhdl-do-group (function &optional spacing)
7049 "Apply FUNCTION on group of lines between empty lines."
7050 (let
7051 ;; search for group beginning
7052 ((beg (save-excursion
7053 (if (re-search-backward vhdl-align-group-separate nil t)
7054 (progn (beginning-of-line 2) (back-to-indentation) (point))
7055 (point-min))))
7056 ;; search for group end
7057 (end (save-excursion
7058 (if (re-search-forward vhdl-align-group-separate nil t)
7059 (progn (beginning-of-line) (point))
7060 (point-max)))))
7061 ;; run FUNCTION
7062 (funcall function beg end spacing)))
7063
7064 (defun vhdl-do-list (function &optional spacing)
7065 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7066 parentheses."
7067 (let (beg end)
7068 (save-excursion
7069 ;; search for beginning of balanced group of parentheses
7070 (setq beg (vhdl-re-search-backward "[()]" nil t))
7071 (while (looking-at ")")
7072 (forward-char) (backward-sexp)
7073 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7074 ;; search for end of balanced group of parentheses
7075 (when beg
7076 (forward-list)
7077 (setq end (point))
7078 (goto-char (1+ beg))
7079 (skip-chars-forward " \t\n")
7080 (setq beg (point))))
7081 ;; run FUNCTION
7082 (if beg
7083 (funcall function beg end spacing)
7084 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7085
7086 (defun vhdl-do-same-indent (function &optional spacing)
7087 "Apply FUNCTION to block of lines with same indent."
7088 (let ((indent (current-indentation))
7089 beg end)
7090 ;; search for first line with same indent
7091 (save-excursion
7092 (while (and (not (bobp))
7093 (or (looking-at "^\\s-*\\(--.*\\)?$")
7094 (= (current-indentation) indent)))
7095 (unless (looking-at "^\\s-*$")
7096 (back-to-indentation) (setq beg (point)))
7097 (beginning-of-line -0)))
7098 ;; search for last line with same indent
7099 (save-excursion
7100 (while (and (not (eobp))
7101 (or (looking-at "^\\s-*\\(--.*\\)?$")
7102 (= (current-indentation) indent)))
7103 (if (looking-at "^\\s-*$")
7104 (beginning-of-line 2)
7105 (beginning-of-line 2)
7106 (setq end (point)))))
7107 ;; run FUNCTION
7108 (funcall function beg end spacing)))
7109
7110 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7111 "Attempt to align a range of lines based on the content of the
7112 lines. The definition of `alignment-list' determines the matching
7113 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7114 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7115 indentation is done before aligning."
7116 (interactive "r\np")
7117 (setq alignment-list (or alignment-list vhdl-align-alist))
7118 (setq spacing (or spacing 1))
7119 (save-excursion
7120 (let (bol indent)
7121 (goto-char end)
7122 (setq end (point-marker))
7123 (goto-char begin)
7124 (setq bol (setq begin (progn (beginning-of-line) (point))))
7125 ; (untabify bol end)
7126 (when indent
7127 (indent-region bol end nil))))
7128 (let ((copy (copy-alist alignment-list)))
7129 (vhdl-prepare-search-2
7130 (while copy
7131 (save-excursion
7132 (goto-char begin)
7133 (let (element
7134 (eol (save-excursion (progn (end-of-line) (point)))))
7135 (setq element (nth 0 copy))
7136 (when (and (or (and (listp (car element))
7137 (memq major-mode (car element)))
7138 (eq major-mode (car element)))
7139 (or vhdl-align-try-all-clauses
7140 (re-search-forward (car (cdr element)) eol t)))
7141 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7142 (car (cdr (cdr (cdr element)))) spacing))
7143 (setq copy (cdr copy))))))))
7144
7145 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7146 "Align a range of lines from BEGIN to END. The regular expression
7147 MATCH must match exactly one fields: the whitespace to be
7148 contracted/expanded. The alignment column will equal the
7149 rightmost column of the widest whitespace block. SPACING is
7150 the amount of extra spaces to add to the calculated maximum required.
7151 SPACING defaults to 1 so that at least one space is inserted after
7152 the token in MATCH."
7153 (setq spacing (or spacing 1))
7154 (setq substr (or substr 1))
7155 (save-excursion
7156 (let (distance (max 0) (lines 0) bol eol width)
7157 ;; Determine the greatest whitespace distance to the alignment
7158 ;; character
7159 (goto-char begin)
7160 (setq eol (progn (end-of-line) (point))
7161 bol (setq begin (progn (beginning-of-line) (point))))
7162 (while (< bol end)
7163 (save-excursion
7164 (when (and (re-search-forward match eol t)
7165 (not (vhdl-in-literal)))
7166 (setq distance (- (match-beginning substr) bol))
7167 (when (> distance max)
7168 (setq max distance))))
7169 (forward-line)
7170 (setq bol (point)
7171 eol (save-excursion (end-of-line) (point)))
7172 (setq lines (1+ lines)))
7173 ;; Now insert enough maxs to push each assignment operator to
7174 ;; the same column. We need to use 'lines' as a counter, since
7175 ;; the location of the mark may change
7176 (goto-char (setq bol begin))
7177 (setq eol (save-excursion (end-of-line) (point)))
7178 (while (> lines 0)
7179 (when (and (re-search-forward match eol t)
7180 (not (vhdl-in-literal)))
7181 (setq width (- (match-end substr) (match-beginning substr)))
7182 (setq distance (- (match-beginning substr) bol))
7183 (goto-char (match-beginning substr))
7184 (delete-char width)
7185 (insert-char ? (+ (- max distance) spacing)))
7186 (beginning-of-line)
7187 (forward-line)
7188 (setq bol (point)
7189 eol (save-excursion (end-of-line) (point)))
7190 (setq lines (1- lines))))))
7191
7192 (defun vhdl-align-region-groups (beg end &optional spacing
7193 no-message no-comments)
7194 "Align region, treat groups of lines separately."
7195 (interactive "r\nP")
7196 (save-excursion
7197 (let (orig pos)
7198 (goto-char beg)
7199 (beginning-of-line)
7200 (setq orig (point-marker))
7201 (setq beg (point))
7202 (goto-char end)
7203 (setq end (point-marker))
7204 (untabify beg end)
7205 (unless no-message
7206 (when vhdl-progress-interval
7207 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7208 (count-lines (point-min) end) 0))))
7209 (vhdl-fixup-whitespace-region beg end t)
7210 (goto-char beg)
7211 (if (not vhdl-align-groups)
7212 ;; align entire region
7213 (progn (vhdl-align-region-1 beg end spacing)
7214 (unless no-comments
7215 (vhdl-align-inline-comment-region-1 beg end)))
7216 ;; align groups
7217 (while (and (< beg end)
7218 (re-search-forward vhdl-align-group-separate end t))
7219 (setq pos (point-marker))
7220 (vhdl-align-region-1 beg pos spacing)
7221 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7222 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7223 (setq beg (1+ pos))
7224 (goto-char beg))
7225 ;; align last group
7226 (when (< beg end)
7227 (vhdl-align-region-1 beg end spacing)
7228 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7229 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7230 (when vhdl-indent-tabs-mode
7231 (tabify orig end))
7232 (unless no-message
7233 (when vhdl-progress-interval (message "Aligning...done"))
7234 (setq vhdl-progress-info nil)))))
7235
7236 (defun vhdl-align-region (beg end &optional spacing)
7237 "Align region, treat blocks with same indent and argument lists separately."
7238 (interactive "r\nP")
7239 (if (not vhdl-align-same-indent)
7240 ;; align entire region
7241 (vhdl-align-region-groups beg end spacing)
7242 ;; align blocks with same indent and argument lists
7243 (save-excursion
7244 (let ((cur-beg beg)
7245 indent cur-end)
7246 (when vhdl-progress-interval
7247 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7248 (count-lines (point-min) end) 0)))
7249 (goto-char end)
7250 (setq end (point-marker))
7251 (goto-char cur-beg)
7252 (while (< (point) end)
7253 ;; is argument list opening?
7254 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7255 (point) (vhdl-point 'eol)))))
7256 ;; determine region for argument list
7257 (progn (goto-char cur-beg)
7258 (forward-sexp)
7259 (setq cur-end (point))
7260 (beginning-of-line 2))
7261 ;; determine region with same indent
7262 (setq indent (current-indentation))
7263 (setq cur-beg (point))
7264 (setq cur-end (vhdl-point 'bonl))
7265 (beginning-of-line 2)
7266 (while (and (< (point) end)
7267 (or (looking-at "^\\s-*\\(--.*\\)?$")
7268 (= (current-indentation) indent))
7269 (<= (save-excursion
7270 (nth 0 (parse-partial-sexp
7271 (point) (vhdl-point 'eol)))) 0))
7272 (unless (looking-at "^\\s-*$")
7273 (setq cur-end (vhdl-point 'bonl)))
7274 (beginning-of-line 2)))
7275 ;; align region
7276 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7277 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7278 (when vhdl-progress-interval (message "Aligning...done"))
7279 (setq vhdl-progress-info nil)))))
7280
7281 (defun vhdl-align-group (&optional spacing)
7282 "Align group of lines between empty lines."
7283 (interactive)
7284 (vhdl-do-group 'vhdl-align-region spacing))
7285
7286 (defun vhdl-align-list (&optional spacing)
7287 "Align the lines of a list surrounded by a balanced group of parentheses."
7288 (interactive)
7289 (vhdl-do-list 'vhdl-align-region-groups spacing))
7290
7291 (defun vhdl-align-same-indent (&optional spacing)
7292 "Align block of lines with same indent."
7293 (interactive)
7294 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7295
7296 (defun vhdl-align-declarations (&optional spacing)
7297 "Align the lines within the declarative part of a design unit."
7298 (interactive)
7299 (let (beg end)
7300 (vhdl-prepare-search-2
7301 (save-excursion
7302 ;; search for declarative part
7303 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7304 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7305 (setq beg (point))
7306 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7307 (setq end (point)))))
7308 (if beg
7309 (vhdl-align-region-groups beg end spacing)
7310 (error "ERROR: Not within the declarative part of a design unit"))))
7311
7312 (defun vhdl-align-buffer ()
7313 "Align buffer."
7314 (interactive)
7315 (vhdl-align-region (point-min) (point-max)))
7316
7317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7318 ;; Align inline comments
7319
7320 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7321 "Align inline comments in region."
7322 (save-excursion
7323 (let ((start-max comment-column)
7324 (length-max 0)
7325 comment-list start-list tmp-list start length
7326 cur-start prev-start no-code)
7327 (setq spacing (or spacing 2))
7328 (vhdl-prepare-search-2
7329 (goto-char beg)
7330 ;; search for comment start positions and lengths
7331 (while (< (point) end)
7332 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7333 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7334 (not (save-excursion (goto-char (match-beginning 2))
7335 (vhdl-in-literal))))
7336 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7337 (setq length (- (match-end 2) (match-beginning 2)))
7338 (setq start-max (max start start-max))
7339 (setq length-max (max length length-max))
7340 (setq comment-list (cons (cons start length) comment-list)))
7341 (beginning-of-line 2))
7342 (setq comment-list
7343 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7344 ;; reduce start positions
7345 (setq start-list (list (caar comment-list)))
7346 (setq comment-list (cdr comment-list))
7347 (while comment-list
7348 (unless (or (= (caar comment-list) (car start-list))
7349 (<= (+ (car start-list) (cdar comment-list))
7350 end-comment-column))
7351 (setq start-list (cons (caar comment-list) start-list)))
7352 (setq comment-list (cdr comment-list)))
7353 ;; align lines as nicely as possible
7354 (goto-char beg)
7355 (while (< (point) end)
7356 (setq cur-start nil)
7357 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7358 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7359 (not (save-excursion
7360 (goto-char (match-beginning 3))
7361 (vhdl-in-literal))))
7362 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7363 (>= (- (match-end 2) (match-beginning 2))
7364 comment-column))))
7365 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7366 (setq length (- (match-end 3) (match-beginning 3)))
7367 (setq no-code (= (match-beginning 1) (match-end 1)))
7368 ;; insert minimum whitespace
7369 (goto-char (match-end 2))
7370 (delete-region (match-beginning 2) (match-end 2))
7371 (insert-char ?\ spacing)
7372 (setq tmp-list start-list)
7373 ;; insert additional whitespace to align
7374 (setq cur-start
7375 (cond
7376 ;; align comment-only line to inline comment of previous line
7377 ((and no-code prev-start
7378 (<= length (- end-comment-column prev-start)))
7379 prev-start)
7380 ;; align all comments at `start-max' if this is possible
7381 ((<= (+ start-max length-max) end-comment-column)
7382 start-max)
7383 ;; align at `comment-column' if possible
7384 ((and (<= start comment-column)
7385 (<= length (- end-comment-column comment-column)))
7386 comment-column)
7387 ;; align at left-most possible start position otherwise
7388 (t
7389 (while (and tmp-list (< (car tmp-list) start))
7390 (setq tmp-list (cdr tmp-list)))
7391 (car tmp-list))))
7392 (indent-to cur-start))
7393 (setq prev-start cur-start)
7394 (beginning-of-line 2))))))
7395
7396 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7397 "Align inline comments within a region. Groups of code lines separated by
7398 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7399 (interactive "r\nP")
7400 (save-excursion
7401 (let (orig pos)
7402 (goto-char beg)
7403 (beginning-of-line)
7404 (setq orig (point-marker))
7405 (setq beg (point))
7406 (goto-char end)
7407 (setq end (point-marker))
7408 (untabify beg end)
7409 (unless no-message (message "Aligning inline comments..."))
7410 (goto-char beg)
7411 (if (not vhdl-align-groups)
7412 ;; align entire region
7413 (vhdl-align-inline-comment-region-1 beg end spacing)
7414 ;; align groups
7415 (while (and (< beg end)
7416 (re-search-forward vhdl-align-group-separate end t))
7417 (setq pos (point-marker))
7418 (vhdl-align-inline-comment-region-1 beg pos spacing)
7419 (setq beg (1+ pos))
7420 (goto-char beg))
7421 ;; align last group
7422 (when (< beg end)
7423 (vhdl-align-inline-comment-region-1 beg end spacing)))
7424 (when vhdl-indent-tabs-mode
7425 (tabify orig end))
7426 (unless no-message (message "Aligning inline comments...done")))))
7427
7428 (defun vhdl-align-inline-comment-group (&optional spacing)
7429 "Align inline comments within a group of lines between empty lines."
7430 (interactive)
7431 (save-excursion
7432 (let ((start (point))
7433 beg end)
7434 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7435 (point-marker) (point-max)))
7436 (goto-char start)
7437 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7438 (point) (point-min)))
7439 (untabify beg end)
7440 (message "Aligning inline comments...")
7441 (vhdl-align-inline-comment-region-1 beg end)
7442 (when vhdl-indent-tabs-mode
7443 (tabify beg end))
7444 (message "Aligning inline comments...done"))))
7445
7446 (defun vhdl-align-inline-comment-buffer ()
7447 "Align inline comments within buffer. Groups of code lines separated by
7448 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7449 (interactive)
7450 (vhdl-align-inline-comment-region (point-min) (point-max)))
7451
7452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7453 ;; Fixup whitespace
7454
7455 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7456 "Fixup whitespace in region. Surround operator symbols by one space,
7457 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7458 end of line, do nothing in comments and strings."
7459 (interactive "r")
7460 (unless no-message (message "Fixing up whitespace..."))
7461 (save-excursion
7462 (goto-char end)
7463 (setq end (point-marker))
7464 ;; have no space before and one space after `,' and ';'
7465 (goto-char beg)
7466 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7467 (if (match-string 1)
7468 (goto-char (match-end 1))
7469 (replace-match "\\3 " nil nil nil 3)))
7470 ;; have no space after `('
7471 (goto-char beg)
7472 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7473 (if (match-string 1)
7474 (goto-char (match-end 1))
7475 (replace-match "\\2")))
7476 ;; have no space before `)'
7477 (goto-char beg)
7478 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7479 (if (match-string 1)
7480 (goto-char (match-end 1))
7481 (replace-match "\\2")))
7482 ;; surround operator symbols by one space
7483 (goto-char beg)
7484 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7485 (if (match-string 1)
7486 (goto-char (match-end 1))
7487 (replace-match "\\3 \\4 \\5")
7488 (goto-char (match-end 4))))
7489 ;; eliminate multiple spaces and spaces at end of line
7490 (goto-char beg)
7491 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7492 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7493 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7494 (progn (replace-match "" nil nil) t))
7495 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7496 (progn (replace-match ";" nil nil) t))
7497 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7498 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7499 (progn (replace-match " " nil nil) t))
7500 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7501 (progn (replace-match " " nil nil) t))
7502 (re-search-forward "[^ \t-]+" end t))))
7503 (unless no-message (message "Fixing up whitespace...done")))
7504
7505 (defun vhdl-fixup-whitespace-buffer ()
7506 "Fixup whitespace in buffer. Surround operator symbols by one space,
7507 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7508 end of line, do nothing in comments."
7509 (interactive)
7510 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7511
7512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7513 ;; Beautify
7514
7515 (defun vhdl-beautify-region (beg end)
7516 "Beautify region by applying indentation, whitespace fixup, alignment, and
7517 case fixing to a region. Calls functions `vhdl-indent-buffer',
7518 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7519 `vhdl-fix-case-buffer'."
7520 (interactive "r")
7521 (setq end (save-excursion (goto-char end) (point-marker)))
7522 (vhdl-indent-region beg end nil)
7523 (let ((vhdl-align-groups t))
7524 (vhdl-align-region beg end))
7525 (vhdl-fix-case-region beg end))
7526
7527 (defun vhdl-beautify-buffer ()
7528 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7529 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7530 buffer."
7531 (interactive)
7532 (vhdl-beautify-region (point-min) (point-max))
7533 (when noninteractive (save-buffer)))
7534
7535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7536 ;; Code filling
7537
7538 (defun vhdl-fill-region (beg end &optional arg)
7539 "Fill lines for a region of code."
7540 (interactive "r\np")
7541 (save-excursion
7542 (goto-char beg)
7543 (let ((margin (if interactive (current-indentation) (current-column))))
7544 (goto-char end)
7545 (setq end (point-marker))
7546 ;; remove inline comments, newlines and whitespace
7547 (vhdl-comment-kill-region beg end)
7548 (vhdl-comment-kill-inline-region beg end)
7549 (subst-char-in-region beg (1- end) ?\n ?\ )
7550 (vhdl-fixup-whitespace-region beg end)
7551 ;; wrap and end-comment-column
7552 (goto-char beg)
7553 (while (re-search-forward "\\s-" end t)
7554 (when(> (current-column) vhdl-end-comment-column)
7555 (backward-char)
7556 (when (re-search-backward "\\s-" beg t)
7557 (replace-match "\n")
7558 (indent-to margin)))))))
7559
7560 (defun vhdl-fill-group ()
7561 "Fill group of lines between empty lines."
7562 (interactive)
7563 (vhdl-do-group 'vhdl-fill-region))
7564
7565 (defun vhdl-fill-list ()
7566 "Fill the lines of a list surrounded by a balanced group of parentheses."
7567 (interactive)
7568 (vhdl-do-list 'vhdl-fill-region))
7569
7570 (defun vhdl-fill-same-indent ()
7571 "Fill the lines of block of lines with same indent."
7572 (interactive)
7573 (vhdl-do-same-indent 'vhdl-fill-region))
7574
7575
7576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7577 ;;; Code updating/fixing
7578 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7579
7580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7581 ;; Sensitivity list update
7582
7583 ;; Strategy:
7584 ;; - no sensitivity list is generated for processes with wait statements
7585 ;; - otherwise, do the following:
7586 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7587 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7588 ;; manually entered global signals)
7589 ;; 3. signals from 1. and 2. form the list of visible signals
7590 ;; 4. search for if/elsif conditions containing an event (sequential code)
7591 ;; 5. scan for strings that are within syntactical regions where signals are
7592 ;; read but not within sequential code, and that correspond to visible
7593 ;; signals
7594 ;; 6. replace sensitivity list by list of signals from 5.
7595
7596 (defun vhdl-update-sensitivity-list-process ()
7597 "Update sensitivity list of current process."
7598 (interactive)
7599 (save-excursion
7600 (vhdl-prepare-search-2
7601 (end-of-line)
7602 ;; look whether in process
7603 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7604 (equal (upcase (match-string 2)) "PROCESS")
7605 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7606 (error "ERROR: Not within a process")
7607 (message "Updating sensitivity list...")
7608 (vhdl-update-sensitivity-list)
7609 (message "Updating sensitivity list...done")))))
7610
7611 (defun vhdl-update-sensitivity-list-buffer ()
7612 "Update sensitivity list of all processes in current buffer."
7613 (interactive)
7614 (save-excursion
7615 (vhdl-prepare-search-2
7616 (goto-char (point-min))
7617 (message "Updating sensitivity lists...")
7618 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7619 (goto-char (match-beginning 0))
7620 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7621 (message "Updating sensitivity lists...done"))))
7622
7623 (defun vhdl-update-sensitivity-list ()
7624 "Update sensitivity list."
7625 (let ((proc-beg (point))
7626 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7627 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7628 seq-region-list)
7629 (cond
7630 ;; search for wait statement (no sensitivity list allowed)
7631 ((progn (goto-char proc-mid)
7632 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7633 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7634 ;; combinational process (update sensitivity list)
7635 (t
7636 (let
7637 ;; scan for visible signals
7638 ((visible-list (vhdl-get-visible-signals))
7639 ;; define syntactic regions where signals are read
7640 (scan-regions-list
7641 '(;; right-hand side of signal/variable assignment
7642 ;; (special case: "<=" is relational operator in a condition)
7643 ((re-search-forward "[<:]=" proc-end t)
7644 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7645 ;; if condition
7646 ((re-search-forward "^\\s-*if\\>" proc-end t)
7647 (re-search-forward "\\<then\\>" proc-end t))
7648 ;; elsif condition
7649 ((re-search-forward "\\<elsif\\>" proc-end t)
7650 (re-search-forward "\\<then\\>" proc-end t))
7651 ;; while loop condition
7652 ((re-search-forward "^\\s-*while\\>" proc-end t)
7653 (re-search-forward "\\<loop\\>" proc-end t))
7654 ;; exit/next condition
7655 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7656 (re-search-forward ";" proc-end t))
7657 ;; assert condition
7658 ((re-search-forward "\\<assert\\>" proc-end t)
7659 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7660 ;; case expression
7661 ((re-search-forward "^\\s-*case\\>" proc-end t)
7662 (re-search-forward "\\<is\\>" proc-end t))
7663 ;; parameter list of procedure call
7664 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7665 (progn (backward-char) (forward-sexp) (point)))))
7666 name read-list sens-list signal-list
7667 sens-beg sens-end beg end margin)
7668 ;; scan for signals in old sensitivity list
7669 (goto-char proc-beg)
7670 (re-search-forward "\\<process\\>" proc-mid t)
7671 (if (not (looking-at "[ \t\n]*("))
7672 (setq sens-beg (point))
7673 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7674 (goto-char (match-end 1))
7675 (forward-sexp)
7676 (setq sens-end (1- (point)))
7677 (goto-char sens-beg)
7678 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7679 (setq sens-list
7680 (cons (downcase (match-string 0)) sens-list))
7681 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7682 (setq signal-list (append visible-list sens-list))
7683 ;; search for sequential parts
7684 (goto-char proc-mid)
7685 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7686 (setq end (re-search-forward "\\<then\\>" proc-end t))
7687 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7688 (goto-char end)
7689 (backward-word 1)
7690 (vhdl-forward-sexp)
7691 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7692 (beginning-of-line)))
7693 ;; scan for signals read in process
7694 (while scan-regions-list
7695 (goto-char proc-mid)
7696 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7697 (setq end (eval (nth 1 (car scan-regions-list)))))
7698 (goto-char beg)
7699 (unless (or (vhdl-in-literal)
7700 (and seq-region-list
7701 (let ((tmp-list seq-region-list))
7702 (while (and tmp-list
7703 (< (point) (caar tmp-list)))
7704 (setq tmp-list (cdr tmp-list)))
7705 (and tmp-list (< (point) (cdar tmp-list))))))
7706 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7707 (setq name (match-string 1))
7708 (when (member (downcase name) signal-list)
7709 (add-to-list 'read-list name)))))
7710 (setq scan-regions-list (cdr scan-regions-list)))
7711 ;; update sensitivity list
7712 (goto-char sens-beg)
7713 (if sens-end
7714 (delete-region sens-beg sens-end)
7715 (when read-list
7716 (insert " ()") (backward-char)))
7717 (setq read-list (sort read-list 'string<))
7718 (when read-list
7719 (setq margin (current-column))
7720 (insert (car read-list))
7721 (setq read-list (cdr read-list))
7722 (while read-list
7723 (insert ",")
7724 (if (<= (+ (current-column) (length (car read-list)) 2)
7725 end-comment-column)
7726 (insert " ")
7727 (insert "\n") (indent-to margin))
7728 (insert (car read-list))
7729 (setq read-list (cdr read-list)))))))))
7730
7731 (defun vhdl-get-visible-signals ()
7732 "Get all signals visible in the current block."
7733 (save-excursion
7734 (let (beg end signal-list entity-name file-name)
7735 ;; search for signals declared in surrounding block declarative parts
7736 (save-excursion
7737 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7738 (match-string 2))
7739 (goto-char (match-end 2))
7740 (vhdl-backward-sexp)
7741 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7742 beg)
7743 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7744 ;; scan for all declared signal names
7745 (goto-char beg)
7746 (while (re-search-forward "^\\s-*signal\\>" end t)
7747 (while (and (not (looking-at "[ \t\n]*:"))
7748 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7749 (setq signal-list
7750 (cons (downcase (match-string 1)) signal-list))))
7751 (goto-char beg)))
7752 ;; search for signals declared in architecture declarative part
7753 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7754 (not (equal "END" (upcase (match-string 1))))
7755 (setq entity-name (match-string 2))
7756 (setq end (re-search-forward "^begin\\>" nil t))))
7757 (error "ERROR: No architecture declarative part found")
7758 ;; scan for all declared signal names
7759 (goto-char beg)
7760 (while (re-search-forward "^\\s-*signal\\>" end t)
7761 (while (and (not (looking-at "[ \t\n]*:"))
7762 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7763 (setq signal-list
7764 (cons (downcase (match-string 1)) signal-list)))))
7765 ;; search for signals declared in entity port clause
7766 (goto-char (point-min))
7767 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7768 (setq file-name
7769 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7770 "." (file-name-extension (buffer-file-name)))))
7771 (vhdl-visit-file
7772 file-name t
7773 (vhdl-prepare-search-2
7774 (goto-char (point-min))
7775 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7776 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7777 (when (setq beg (re-search-forward
7778 "^\\s-*port[ \t\n]*("
7779 (save-excursion
7780 (re-search-forward "^end\\>" nil t)) t))
7781 (setq end (save-excursion
7782 (backward-char) (forward-sexp) (point)))
7783 (vhdl-forward-syntactic-ws)
7784 (while (< (point) end)
7785 (while (and (not (looking-at "[ \t\n]*:"))
7786 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7787 (setq signal-list
7788 (cons (downcase (match-string 1)) signal-list)))
7789 (re-search-forward ";" end 1)
7790 (vhdl-forward-syntactic-ws))))))
7791 signal-list)))
7792
7793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7794 ;; Generic/port clause fixing
7795
7796 (defun vhdl-fix-clause ()
7797 "Fix closing parenthesis within generic/port clause."
7798 (interactive)
7799 (save-excursion
7800 (vhdl-prepare-search-2
7801 (let ((pos (point))
7802 beg end)
7803 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7804 (error "ERROR: Not within a generic/port clause")
7805 ;; search for end of clause
7806 (goto-char (match-end 0))
7807 (setq beg (1- (point)))
7808 (vhdl-forward-syntactic-ws)
7809 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7810 (goto-char (1- (match-end 0)))
7811 (setq end (point-marker))
7812 (forward-char)
7813 (vhdl-forward-syntactic-ws))
7814 (goto-char end)
7815 (when (> pos (save-excursion (end-of-line) (point)))
7816 (error "ERROR: Not within a generic/port clause"))
7817 ;; delete closing parenthesis on separate line (not supported style)
7818 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7819 (vhdl-line-kill)
7820 (vhdl-backward-syntactic-ws)
7821 (setq end (point-marker))
7822 (insert ";"))
7823 ;; delete superfluous parentheses
7824 (while (progn (goto-char beg)
7825 (condition-case () (forward-sexp)
7826 (error (goto-char (point-max))))
7827 (< (point) end))
7828 (delete-backward-char 1))
7829 ;; add closing parenthesis
7830 (when (> (point) end)
7831 (goto-char end)
7832 (insert ")")))))))
7833
7834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7835 ;; Miscellaneous
7836
7837 (defun vhdl-remove-trailing-spaces ()
7838 "Remove trailing spaces in the whole buffer."
7839 (interactive)
7840 (save-match-data
7841 (save-excursion
7842 (goto-char (point-min))
7843 (while (re-search-forward "[ \t]+$" (point-max) t)
7844 (unless (vhdl-in-literal)
7845 (replace-match "" nil nil))))))
7846
7847
7848 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7849 ;;; Electrification
7850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7851
7852 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7853 "Syntax of prompt inserted by template generators.")
7854
7855 (defvar vhdl-template-invoked-by-hook nil
7856 "Indicates whether a template has been invoked by a hook or by key or menu.
7857 Used for undoing after template abortion.")
7858
7859 ;; correct different behavior of function `unread-command-events' in XEmacs
7860 (defun vhdl-character-to-event (arg))
7861 (defalias 'vhdl-character-to-event
7862 (if (fboundp 'character-to-event) 'character-to-event 'identity))
7863
7864 (defun vhdl-work-library ()
7865 "Return the working library name of the current project or \"work\" if no
7866 project is defined."
7867 (vhdl-resolve-env-variable
7868 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
7869
7870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7871 ;; Enabling/disabling
7872
7873 (defun vhdl-mode-line-update ()
7874 "Update the modeline string for VHDL major mode."
7875 (setq mode-name (concat "VHDL"
7876 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7877 (and vhdl-electric-mode "e")
7878 (and vhdl-stutter-mode "s")))
7879 (force-mode-line-update t))
7880
7881 (defun vhdl-electric-mode (arg)
7882 "Toggle VHDL electric mode.
7883 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7884 (interactive "P")
7885 (setq vhdl-electric-mode
7886 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7887 ((> arg 0) t) (t nil)))
7888 (vhdl-mode-line-update))
7889
7890 (defun vhdl-stutter-mode (arg)
7891 "Toggle VHDL stuttering mode.
7892 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7893 (interactive "P")
7894 (setq vhdl-stutter-mode
7895 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7896 ((> arg 0) t) (t nil)))
7897 (vhdl-mode-line-update))
7898
7899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7900 ;; Stuttering
7901
7902 (defun vhdl-electric-dash (count)
7903 "-- starts a comment, --- draws a horizontal line,
7904 ---- starts a display comment"
7905 (interactive "p")
7906 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
7907 (cond
7908 ((and abbrev-start-location (= abbrev-start-location (point)))
7909 (setq abbrev-start-location nil)
7910 (goto-char last-abbrev-location)
7911 (beginning-of-line nil)
7912 (vhdl-comment-display))
7913 ((/= (preceding-char) ?-) ; standard dash (minus)
7914 (self-insert-command count))
7915 (t (self-insert-command count)
7916 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7917 (let ((next-input (read-char)))
7918 (if (= next-input ?-) ; triple dash
7919 (progn
7920 (vhdl-comment-display-line)
7921 (message
7922 "Enter '-' for display comment, else continue coding")
7923 (let ((next-input (read-char)))
7924 (if (= next-input ?-) ; four dashes
7925 (vhdl-comment-display t)
7926 (setq unread-command-events ; pushback the char
7927 (list (vhdl-character-to-event next-input))))))
7928 (setq unread-command-events ; pushback the char
7929 (list (vhdl-character-to-event next-input)))
7930 (vhdl-comment-insert)))))
7931 (self-insert-command count)))
7932
7933 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
7934 (interactive "p")
7935 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7936 (if (= (preceding-char) ?\()
7937 (progn (delete-char -1) (insert-char ?\[ 1))
7938 (insert-char ?\( 1))
7939 (self-insert-command count)))
7940
7941 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
7942 (interactive "p")
7943 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7944 (progn
7945 (if (= (preceding-char) ?\))
7946 (progn (delete-char -1) (insert-char ?\] 1))
7947 (insert-char ?\) 1))
7948 (blink-matching-open))
7949 (self-insert-command count)))
7950
7951 (defun vhdl-electric-quote (count) "'' --> \""
7952 (interactive "p")
7953 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7954 (if (= (preceding-char) last-input-char)
7955 (progn (delete-backward-char 1) (insert-char ?\" 1))
7956 (insert-char ?\' 1))
7957 (self-insert-command count)))
7958
7959 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
7960 (interactive "p")
7961 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7962 (cond ((= (preceding-char) last-input-char)
7963 (progn (delete-char -1)
7964 (unless (eq (preceding-char) ? ) (insert " "))
7965 (insert ": ")
7966 (setq this-command 'vhdl-electric-colon)))
7967 ((and
7968 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7969 (progn (delete-char -1) (insert "= ")))
7970 (t (insert-char ?\; 1)))
7971 (self-insert-command count)))
7972
7973 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
7974 (interactive "p")
7975 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7976 (cond ((= (preceding-char) last-input-char)
7977 (progn (delete-char -1)
7978 (unless (eq (preceding-char) ? ) (insert " "))
7979 (insert "<= ")))
7980 (t (insert-char ?\, 1)))
7981 (self-insert-command count)))
7982
7983 (defun vhdl-electric-period (count) "'..' --> ' => '"
7984 (interactive "p")
7985 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7986 (cond ((= (preceding-char) last-input-char)
7987 (progn (delete-char -1)
7988 (unless (eq (preceding-char) ? ) (insert " "))
7989 (insert "=> ")))
7990 (t (insert-char ?\. 1)))
7991 (self-insert-command count)))
7992
7993 (defun vhdl-electric-equal (count) "'==' --> ' == '"
7994 (interactive "p")
7995 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7996 (cond ((= (preceding-char) last-input-char)
7997 (progn (delete-char -1)
7998 (unless (eq (preceding-char) ? ) (insert " "))
7999 (insert "== ")))
8000 (t (insert-char ?\= 1)))
8001 (self-insert-command count)))
8002
8003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8004 ;; VHDL templates
8005
8006 (defun vhdl-template-paired-parens ()
8007 "Insert a pair of round parentheses, placing point between them."
8008 (interactive)
8009 (insert "()")
8010 (backward-char))
8011
8012 (defun vhdl-template-alias ()
8013 "Insert alias declaration."
8014 (interactive)
8015 (let ((start (point)))
8016 (vhdl-insert-keyword "ALIAS ")
8017 (when (vhdl-template-field "name" nil t start (point))
8018 (insert " : ")
8019 (unless (vhdl-template-field
8020 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8021 nil t)
8022 (delete-backward-char 3))
8023 (vhdl-insert-keyword " IS ")
8024 (vhdl-template-field "name" ";")
8025 (vhdl-comment-insert-inline))))
8026
8027 (defun vhdl-template-architecture ()
8028 "Insert architecture."
8029 (interactive)
8030 (let ((margin (current-indentation))
8031 (start (point))
8032 arch-name)
8033 (vhdl-insert-keyword "ARCHITECTURE ")
8034 (when (setq arch-name
8035 (vhdl-template-field "name" nil t start (point)))
8036 (vhdl-insert-keyword " OF ")
8037 (if (save-excursion
8038 (vhdl-prepare-search-1
8039 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8040 (insert (match-string 1))
8041 (vhdl-template-field "entity name"))
8042 (vhdl-insert-keyword " IS\n")
8043 (vhdl-template-begin-end
8044 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8045 (memq vhdl-insert-empty-lines '(unit all))))))
8046
8047 (defun vhdl-template-array (kind &optional secondary)
8048 "Insert array type definition."
8049 (interactive)
8050 (let ((start (point)))
8051 (vhdl-insert-keyword "ARRAY (")
8052 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8053 secondary)
8054 (vhdl-insert-keyword ") OF ")
8055 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8056 (vhdl-insert-keyword ";"))))
8057
8058 (defun vhdl-template-assert ()
8059 "Insert an assertion statement."
8060 (interactive)
8061 (let ((start (point)))
8062 (vhdl-insert-keyword "ASSERT ")
8063 (when vhdl-conditions-in-parenthesis (insert "("))
8064 (when (vhdl-template-field "condition (negated)" nil t start (point))
8065 (when vhdl-conditions-in-parenthesis (insert ")"))
8066 (setq start (point))
8067 (vhdl-insert-keyword " REPORT ")
8068 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8069 (delete-region start (point)))
8070 (setq start (point))
8071 (vhdl-insert-keyword " SEVERITY ")
8072 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8073 (delete-region start (point)))
8074 (insert ";"))))
8075
8076 (defun vhdl-template-attribute ()
8077 "Insert an attribute declaration or specification."
8078 (interactive)
8079 (if (eq (vhdl-decision-query
8080 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8081 (vhdl-template-attribute-spec)
8082 (vhdl-template-attribute-decl)))
8083
8084 (defun vhdl-template-attribute-decl ()
8085 "Insert an attribute declaration."
8086 (interactive)
8087 (let ((start (point)))
8088 (vhdl-insert-keyword "ATTRIBUTE ")
8089 (when (vhdl-template-field "name" " : " t start (point))
8090 (vhdl-template-field "type" ";")
8091 (vhdl-comment-insert-inline))))
8092
8093 (defun vhdl-template-attribute-spec ()
8094 "Insert an attribute specification."
8095 (interactive)
8096 (let ((start (point)))
8097 (vhdl-insert-keyword "ATTRIBUTE ")
8098 (when (vhdl-template-field "name" nil t start (point))
8099 (vhdl-insert-keyword " OF ")
8100 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8101 (vhdl-template-field "entity class")
8102 (vhdl-insert-keyword " IS ")
8103 (vhdl-template-field "expression" ";"))))
8104
8105 (defun vhdl-template-block ()
8106 "Insert a block."
8107 (interactive)
8108 (let ((margin (current-indentation))
8109 (start (point))
8110 label)
8111 (vhdl-insert-keyword ": BLOCK ")
8112 (goto-char start)
8113 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8114 (forward-word 1)
8115 (forward-char 1)
8116 (insert "(")
8117 (if (vhdl-template-field "[guard expression]" nil t)
8118 (insert ")")
8119 (delete-char -2))
8120 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8121 (insert "\n")
8122 (vhdl-template-begin-end "BLOCK" label margin)
8123 (vhdl-comment-block))))
8124
8125 (defun vhdl-template-block-configuration ()
8126 "Insert a block configuration statement."
8127 (interactive)
8128 (let ((margin (current-indentation))
8129 (start (point)))
8130 (vhdl-insert-keyword "FOR ")
8131 (when (vhdl-template-field "block name" nil t start (point))
8132 (vhdl-insert-keyword "\n\n")
8133 (indent-to margin)
8134 (vhdl-insert-keyword "END FOR;")
8135 (end-of-line 0)
8136 (indent-to (+ margin vhdl-basic-offset)))))
8137
8138 (defun vhdl-template-break ()
8139 "Insert a break statement."
8140 (interactive)
8141 (let (position)
8142 (vhdl-insert-keyword "BREAK")
8143 (setq position (point))
8144 (insert " ")
8145 (while (or
8146 (progn (vhdl-insert-keyword "FOR ")
8147 (if (vhdl-template-field "[quantity name]" " USE " t)
8148 (progn (vhdl-template-field "quantity name" " => ") t)
8149 (kill-word -1) nil))
8150 (vhdl-template-field "[quantity name]" " => " t))
8151 (vhdl-template-field "expression")
8152 (setq position (point))
8153 (insert ", "))
8154 (delete-region position (point))
8155 (unless (vhdl-sequential-statement-p)
8156 (vhdl-insert-keyword " ON ")
8157 (if (vhdl-template-field "[sensitivity list]" nil t)
8158 (setq position (point))
8159 (delete-region position (point))))
8160 (vhdl-insert-keyword " WHEN ")
8161 (when vhdl-conditions-in-parenthesis (insert "("))
8162 (if (vhdl-template-field "[condition]" nil t)
8163 (when vhdl-conditions-in-parenthesis (insert ")"))
8164 (delete-region position (point)))
8165 (insert ";")))
8166
8167 (defun vhdl-template-case (&optional kind)
8168 "Insert a case statement."
8169 (interactive)
8170 (let ((margin (current-indentation))
8171 (start (point))
8172 label)
8173 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8174 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8175 (vhdl-insert-keyword "CASE ")
8176 (vhdl-insert-keyword ": CASE ")
8177 (goto-char start)
8178 (setq label (vhdl-template-field "[label]" nil t))
8179 (unless label (delete-char 2))
8180 (forward-word 1)
8181 (forward-char 1))
8182 (when (vhdl-template-field "expression" nil t start (point))
8183 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8184 (indent-to margin)
8185 (vhdl-insert-keyword "END CASE")
8186 (when label (insert " " label))
8187 (insert ";")
8188 (forward-line -1)
8189 (indent-to (+ margin vhdl-basic-offset))
8190 (vhdl-insert-keyword "WHEN ")
8191 (let ((position (point)))
8192 (insert " => ;\n")
8193 (indent-to (+ margin vhdl-basic-offset))
8194 (vhdl-insert-keyword "WHEN OTHERS => null;")
8195 (goto-char position)))))
8196
8197 (defun vhdl-template-case-is ()
8198 "Insert a sequential case statement."
8199 (interactive)
8200 (vhdl-template-case 'is))
8201
8202 (defun vhdl-template-case-use ()
8203 "Insert a simultaneous case statement."
8204 (interactive)
8205 (vhdl-template-case 'use))
8206
8207 (defun vhdl-template-component ()
8208 "Insert a component declaration."
8209 (interactive)
8210 (vhdl-template-component-decl))
8211
8212 (defun vhdl-template-component-conf ()
8213 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8214 since these are almost equivalent)."
8215 (interactive)
8216 (let ((margin (current-indentation))
8217 (result (vhdl-template-configuration-spec t)))
8218 (when result
8219 (insert "\n")
8220 (indent-to margin)
8221 (vhdl-insert-keyword "END FOR;")
8222 (when (eq result 'no-use)
8223 (end-of-line -0)))))
8224
8225 (defun vhdl-template-component-decl ()
8226 "Insert a component declaration."
8227 (interactive)
8228 (let ((margin (current-indentation))
8229 (start (point))
8230 name end-column)
8231 (vhdl-insert-keyword "COMPONENT ")
8232 (when (setq name (vhdl-template-field "name" nil t start (point)))
8233 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8234 (insert "\n\n")
8235 (indent-to margin)
8236 (vhdl-insert-keyword "END COMPONENT")
8237 (unless (vhdl-standard-p '87) (insert " " name))
8238 (insert ";")
8239 (setq end-column (current-column))
8240 (end-of-line -0)
8241 (indent-to (+ margin vhdl-basic-offset))
8242 (vhdl-template-generic-list t t)
8243 (insert "\n")
8244 (indent-to (+ margin vhdl-basic-offset))
8245 (vhdl-template-port-list t)
8246 (beginning-of-line 2)
8247 (forward-char end-column))))
8248
8249 (defun vhdl-template-component-inst ()
8250 "Insert a component instantiation statement."
8251 (interactive)
8252 (let ((margin (current-indentation))
8253 (start (point))
8254 unit position)
8255 (when (vhdl-template-field "instance label" nil t start (point))
8256 (insert ": ")
8257 (if (not (vhdl-use-direct-instantiation))
8258 (vhdl-template-field "component name")
8259 ;; direct instantiation
8260 (setq unit (vhdl-template-field
8261 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8262 (setq unit (upcase (or unit "")))
8263 (cond ((equal unit "ENTITY")
8264 (vhdl-template-field "library name" "." nil nil nil nil
8265 (vhdl-work-library))
8266 (vhdl-template-field "entity name" "(")
8267 (if (vhdl-template-field "[architecture name]" nil t)
8268 (insert ")")
8269 (delete-char -1)))
8270 ((equal unit "CONFIGURATION")
8271 (vhdl-template-field "library name" "." nil nil nil nil
8272 (vhdl-work-library))
8273 (vhdl-template-field "configuration name"))
8274 (t (vhdl-template-field "component name"))))
8275 (insert "\n")
8276 (indent-to (+ margin vhdl-basic-offset))
8277 (setq position (point))
8278 (vhdl-insert-keyword "GENERIC ")
8279 (when (vhdl-template-map position t t)
8280 (insert "\n")
8281 (indent-to (+ margin vhdl-basic-offset)))
8282 (setq position (point))
8283 (vhdl-insert-keyword "PORT ")
8284 (unless (vhdl-template-map position t t)
8285 (kill-line -0)
8286 (delete-char -1))
8287 (insert ";"))))
8288
8289 (defun vhdl-template-conditional-signal-asst ()
8290 "Insert a conditional signal assignment."
8291 (interactive)
8292 (when (vhdl-template-field "target signal")
8293 (insert " <= ")
8294 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8295 ; (insert " "))
8296 (let ((margin (current-column))
8297 (start (point))
8298 position)
8299 (vhdl-template-field "waveform")
8300 (setq position (point))
8301 (vhdl-insert-keyword " WHEN ")
8302 (when vhdl-conditions-in-parenthesis (insert "("))
8303 (while (and (vhdl-template-field "[condition]" nil t)
8304 (progn
8305 (when vhdl-conditions-in-parenthesis (insert ")"))
8306 (setq position (point))
8307 (vhdl-insert-keyword " ELSE")
8308 (insert "\n")
8309 (indent-to margin)
8310 (vhdl-template-field "[waveform]" nil t)))
8311 (setq position (point))
8312 (vhdl-insert-keyword " WHEN ")
8313 (when vhdl-conditions-in-parenthesis (insert "(")))
8314 (delete-region position (point))
8315 (insert ";")
8316 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8317
8318 (defun vhdl-template-configuration ()
8319 "Insert a configuration specification if within an architecture,
8320 a block or component configuration if within a configuration declaration,
8321 a configuration declaration if not within a design unit."
8322 (interactive)
8323 (vhdl-prepare-search-1
8324 (cond
8325 ((and (save-excursion ; architecture body
8326 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8327 (equal "ARCHITECTURE" (upcase (match-string 1))))
8328 (vhdl-template-configuration-spec))
8329 ((and (save-excursion ; configuration declaration
8330 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8331 (equal "CONFIGURATION" (upcase (match-string 1))))
8332 (if (eq (vhdl-decision-query
8333 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8334 (vhdl-template-component-conf)
8335 (vhdl-template-block-configuration)))
8336 (t (vhdl-template-configuration-decl))))) ; otherwise
8337
8338 (defun vhdl-template-configuration-spec (&optional optional-use)
8339 "Insert a configuration specification."
8340 (interactive)
8341 (let ((margin (current-indentation))
8342 (start (point))
8343 aspect position)
8344 (vhdl-insert-keyword "FOR ")
8345 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8346 t start (point))
8347 (vhdl-template-field "component name" "\n")
8348 (indent-to (+ margin vhdl-basic-offset))
8349 (setq start (point))
8350 (vhdl-insert-keyword "USE ")
8351 (if (and optional-use
8352 (not (setq aspect (vhdl-template-field
8353 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8354 (progn (delete-region start (point)) 'no-use)
8355 (unless optional-use
8356 (setq aspect (vhdl-template-field
8357 "ENTITY | CONFIGURATION | OPEN" " ")))
8358 (setq aspect (upcase (or aspect "")))
8359 (cond ((equal aspect "ENTITY")
8360 (vhdl-template-field "library name" "." nil nil nil nil
8361 (vhdl-work-library))
8362 (vhdl-template-field "entity name" "(")
8363 (if (vhdl-template-field "[architecture name]" nil t)
8364 (insert ")")
8365 (delete-char -1))
8366 (insert "\n")
8367 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8368 (setq position (point))
8369 (vhdl-insert-keyword "GENERIC ")
8370 (when (vhdl-template-map position t t)
8371 (insert "\n")
8372 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8373 (setq position (point))
8374 (vhdl-insert-keyword "PORT ")
8375 (unless (vhdl-template-map position t t)
8376 (kill-line -0)
8377 (delete-char -1))
8378 (insert ";")
8379 t)
8380 ((equal aspect "CONFIGURATION")
8381 (vhdl-template-field "library name" "." nil nil nil nil
8382 (vhdl-work-library))
8383 (vhdl-template-field "configuration name" ";"))
8384 (t (delete-backward-char 1) (insert ";") t))))))
8385
8386
8387 (defun vhdl-template-configuration-decl ()
8388 "Insert a configuration declaration."
8389 (interactive)
8390 (let ((margin (current-indentation))
8391 (start (point))
8392 entity-exists string name position)
8393 (vhdl-insert-keyword "CONFIGURATION ")
8394 (when (setq name (vhdl-template-field "name" nil t start (point)))
8395 (vhdl-insert-keyword " OF ")
8396 (save-excursion
8397 (vhdl-prepare-search-1
8398 (setq entity-exists (vhdl-re-search-backward
8399 "\\<entity \\(\\w*\\) is\\>" nil t))
8400 (setq string (match-string 1))))
8401 (if (and entity-exists (not (equal string "")))
8402 (insert string)
8403 (vhdl-template-field "entity name"))
8404 (vhdl-insert-keyword " IS\n")
8405 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8406 (indent-to (+ margin vhdl-basic-offset))
8407 (setq position (point))
8408 (insert "\n")
8409 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8410 (indent-to margin)
8411 (vhdl-insert-keyword "END ")
8412 (unless (vhdl-standard-p '87)
8413 (vhdl-insert-keyword "CONFIGURATION "))
8414 (insert name ";")
8415 (goto-char position))))
8416
8417 (defun vhdl-template-constant ()
8418 "Insert a constant declaration."
8419 (interactive)
8420 (let ((start (point))
8421 (in-arglist (vhdl-in-argument-list-p)))
8422 (vhdl-insert-keyword "CONSTANT ")
8423 (when (vhdl-template-field "name" nil t start (point))
8424 (insert " : ")
8425 (when in-arglist (vhdl-insert-keyword "IN "))
8426 (vhdl-template-field "type")
8427 (if in-arglist
8428 (progn (insert ";")
8429 (vhdl-comment-insert-inline))
8430 (let ((position (point)))
8431 (insert " := ")
8432 (unless (vhdl-template-field "[initialization]" nil t)
8433 (delete-region position (point)))
8434 (insert ";")
8435 (vhdl-comment-insert-inline))))))
8436
8437 (defun vhdl-template-default ()
8438 "Insert nothing."
8439 (interactive)
8440 (insert " ")
8441 (unexpand-abbrev)
8442 (backward-word 1)
8443 (vhdl-case-word 1)
8444 (forward-char 1))
8445
8446 (defun vhdl-template-default-indent ()
8447 "Insert nothing and indent."
8448 (interactive)
8449 (insert " ")
8450 (unexpand-abbrev)
8451 (backward-word 1)
8452 (vhdl-case-word 1)
8453 (forward-char 1)
8454 (indent-according-to-mode))
8455
8456 (defun vhdl-template-disconnect ()
8457 "Insert a disconnect statement."
8458 (interactive)
8459 (let ((start (point)))
8460 (vhdl-insert-keyword "DISCONNECT ")
8461 (when (vhdl-template-field "signal names | OTHERS | ALL"
8462 " : " t start (point))
8463 (vhdl-template-field "type")
8464 (vhdl-insert-keyword " AFTER ")
8465 (vhdl-template-field "time expression" ";"))))
8466
8467 (defun vhdl-template-else ()
8468 "Insert an else statement."
8469 (interactive)
8470 (let (margin)
8471 (vhdl-prepare-search-1
8472 (vhdl-insert-keyword "ELSE")
8473 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8474 (equal "WHEN" (upcase (match-string 1))))
8475 (insert " ")
8476 (indent-according-to-mode)
8477 (setq margin (current-indentation))
8478 (insert "\n")
8479 (indent-to (+ margin vhdl-basic-offset))))))
8480
8481 (defun vhdl-template-elsif ()
8482 "Insert an elsif statement."
8483 (interactive)
8484 (let ((start (point))
8485 margin)
8486 (vhdl-insert-keyword "ELSIF ")
8487 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8488 (when vhdl-conditions-in-parenthesis (insert "("))
8489 (when (vhdl-template-field "condition" nil t start (point))
8490 (when vhdl-conditions-in-parenthesis (insert ")"))
8491 (indent-according-to-mode)
8492 (setq margin (current-indentation))
8493 (vhdl-insert-keyword
8494 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8495 (indent-to (+ margin vhdl-basic-offset))))))
8496
8497 (defun vhdl-template-entity ()
8498 "Insert an entity."
8499 (interactive)
8500 (let ((margin (current-indentation))
8501 (start (point))
8502 name end-column)
8503 (vhdl-insert-keyword "ENTITY ")
8504 (when (setq name (vhdl-template-field "name" nil t start (point)))
8505 (vhdl-insert-keyword " IS\n\n")
8506 (indent-to margin)
8507 (vhdl-insert-keyword "END ")
8508 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8509 (insert name ";")
8510 (setq end-column (current-column))
8511 (end-of-line -0)
8512 (indent-to (+ margin vhdl-basic-offset))
8513 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8514 (indent-to (+ margin vhdl-basic-offset))
8515 (when (vhdl-template-generic-list t)
8516 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8517 (insert "\n")
8518 (indent-to (+ margin vhdl-basic-offset))
8519 (when (vhdl-template-port-list t)
8520 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8521 (beginning-of-line 2)
8522 (forward-char end-column))))
8523
8524 (defun vhdl-template-exit ()
8525 "Insert an exit statement."
8526 (interactive)
8527 (let ((start (point)))
8528 (vhdl-insert-keyword "EXIT ")
8529 (if (vhdl-template-field "[loop label]" nil t start (point))
8530 (let ((position (point)))
8531 (vhdl-insert-keyword " WHEN ")
8532 (when vhdl-conditions-in-parenthesis (insert "("))
8533 (if (vhdl-template-field "[condition]" nil t)
8534 (when vhdl-conditions-in-parenthesis (insert ")"))
8535 (delete-region position (point))))
8536 (delete-char -1))
8537 (insert ";")))
8538
8539 (defun vhdl-template-file ()
8540 "Insert a file declaration."
8541 (interactive)
8542 (let ((start (point)))
8543 (vhdl-insert-keyword "FILE ")
8544 (when (vhdl-template-field "name" nil t start (point))
8545 (insert " : ")
8546 (vhdl-template-field "type")
8547 (unless (vhdl-standard-p '87)
8548 (vhdl-insert-keyword " OPEN ")
8549 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8550 nil t)
8551 (delete-backward-char 6)))
8552 (vhdl-insert-keyword " IS ")
8553 (when (vhdl-standard-p '87)
8554 (vhdl-template-field "[IN | OUT]" " " t))
8555 (vhdl-template-field "filename-string" nil nil nil nil t)
8556 (insert ";")
8557 (vhdl-comment-insert-inline))))
8558
8559 (defun vhdl-template-for ()
8560 "Insert a block or component configuration if within a configuration
8561 declaration, a configuration specification if within an architecture
8562 declarative part (and not within a subprogram), a for-loop if within a
8563 sequential statement part (subprogram or process), and a for-generate
8564 otherwise."
8565 (interactive)
8566 (vhdl-prepare-search-1
8567 (cond
8568 ((vhdl-sequential-statement-p) ; sequential statement
8569 (vhdl-template-for-loop))
8570 ((and (save-excursion ; configuration declaration
8571 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8572 (equal "CONFIGURATION" (upcase (match-string 1))))
8573 (if (eq (vhdl-decision-query
8574 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8575 (vhdl-template-component-conf)
8576 (vhdl-template-block-configuration)))
8577 ((and (save-excursion
8578 (re-search-backward ; architecture declarative part
8579 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8580 (equal "ARCHITECTURE" (upcase (match-string 1))))
8581 (vhdl-template-configuration-spec))
8582 (t (vhdl-template-for-generate))))) ; concurrent statement
8583
8584 (defun vhdl-template-for-generate ()
8585 "Insert a for-generate."
8586 (interactive)
8587 (let ((margin (current-indentation))
8588 (start (point))
8589 label position)
8590 (vhdl-insert-keyword ": FOR ")
8591 (setq position (point-marker))
8592 (goto-char start)
8593 (when (setq label (vhdl-template-field "label" nil t start position))
8594 (goto-char position)
8595 (vhdl-template-field "loop variable")
8596 (vhdl-insert-keyword " IN ")
8597 (vhdl-template-field "range")
8598 (vhdl-template-generate-body margin label))))
8599
8600 (defun vhdl-template-for-loop ()
8601 "Insert a for loop."
8602 (interactive)
8603 (let ((margin (current-indentation))
8604 (start (point))
8605 label index)
8606 (if (not (eq vhdl-optional-labels 'all))
8607 (vhdl-insert-keyword "FOR ")
8608 (vhdl-insert-keyword ": FOR ")
8609 (goto-char start)
8610 (setq label (vhdl-template-field "[label]" nil t))
8611 (unless label (delete-char 2))
8612 (forward-word 1)
8613 (forward-char 1))
8614 (when (setq index (vhdl-template-field "loop variable"
8615 nil t start (point)))
8616 (vhdl-insert-keyword " IN ")
8617 (vhdl-template-field "range")
8618 (vhdl-insert-keyword " LOOP\n\n")
8619 (indent-to margin)
8620 (vhdl-insert-keyword "END LOOP")
8621 (if label
8622 (insert " " label ";")
8623 (insert ";")
8624 (when vhdl-self-insert-comments (insert " -- " index)))
8625 (forward-line -1)
8626 (indent-to (+ margin vhdl-basic-offset)))))
8627
8628 (defun vhdl-template-function (&optional kind)
8629 "Insert a function declaration or body."
8630 (interactive)
8631 (let ((margin (current-indentation))
8632 (start (point))
8633 name)
8634 (vhdl-insert-keyword "FUNCTION ")
8635 (when (setq name (vhdl-template-field "name" nil t start (point)))
8636 (vhdl-template-argument-list t)
8637 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8638 (end-of-line)
8639 (insert "\n")
8640 (indent-to (+ margin vhdl-basic-offset))
8641 (vhdl-insert-keyword "RETURN ")
8642 (vhdl-template-field "type")
8643 (if (if kind (eq kind 'body)
8644 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8645 (progn (vhdl-insert-keyword " IS\n")
8646 (vhdl-template-begin-end
8647 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8648 (vhdl-comment-block))
8649 (insert ";")))))
8650
8651 (defun vhdl-template-function-decl ()
8652 "Insert a function declaration."
8653 (interactive)
8654 (vhdl-template-function 'decl))
8655
8656 (defun vhdl-template-function-body ()
8657 "Insert a function declaration."
8658 (interactive)
8659 (vhdl-template-function 'body))
8660
8661 (defun vhdl-template-generate ()
8662 "Insert a generation scheme."
8663 (interactive)
8664 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8665 (vhdl-template-if-generate)
8666 (vhdl-template-for-generate)))
8667
8668 (defun vhdl-template-generic ()
8669 "Insert generic declaration, or generic map in instantiation statements."
8670 (interactive)
8671 (let ((start (point)))
8672 (vhdl-prepare-search-1
8673 (cond
8674 ((and (save-excursion ; entity declaration
8675 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8676 (equal "ENTITY" (upcase (match-string 1))))
8677 (vhdl-template-generic-list nil))
8678 ((or (save-excursion
8679 (or (beginning-of-line)
8680 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8681 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8682 (vhdl-insert-keyword "GENERIC ")
8683 (vhdl-template-map start))
8684 (t (vhdl-template-generic-list nil t))))))
8685
8686 (defun vhdl-template-group ()
8687 "Insert group or group template declaration."
8688 (interactive)
8689 (let ((start (point)))
8690 (if (eq (vhdl-decision-query
8691 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8692 (vhdl-template-group-template)
8693 (vhdl-template-group-decl))))
8694
8695 (defun vhdl-template-group-decl ()
8696 "Insert group declaration."
8697 (interactive)
8698 (let ((start (point)))
8699 (vhdl-insert-keyword "GROUP ")
8700 (when (vhdl-template-field "name" " : " t start (point))
8701 (vhdl-template-field "template name" " (")
8702 (vhdl-template-field "constituent list" ");")
8703 (vhdl-comment-insert-inline))))
8704
8705 (defun vhdl-template-group-template ()
8706 "Insert group template declaration."
8707 (interactive)
8708 (let ((start (point)))
8709 (vhdl-insert-keyword "GROUP ")
8710 (when (vhdl-template-field "template name" nil t start (point))
8711 (vhdl-insert-keyword " IS (")
8712 (vhdl-template-field "entity class list" ");")
8713 (vhdl-comment-insert-inline))))
8714
8715 (defun vhdl-template-if ()
8716 "Insert a sequential if statement or an if-generate statement."
8717 (interactive)
8718 (if (vhdl-sequential-statement-p)
8719 (vhdl-template-if-then)
8720 (if (and (vhdl-standard-p 'ams)
8721 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8722 (vhdl-template-if-use)
8723 (vhdl-template-if-generate))))
8724
8725 (defun vhdl-template-if-generate ()
8726 "Insert an if-generate."
8727 (interactive)
8728 (let ((margin (current-indentation))
8729 (start (point))
8730 label position)
8731 (vhdl-insert-keyword ": IF ")
8732 (setq position (point-marker))
8733 (goto-char start)
8734 (when (setq label (vhdl-template-field "label" nil t start position))
8735 (goto-char position)
8736 (when vhdl-conditions-in-parenthesis (insert "("))
8737 (vhdl-template-field "condition")
8738 (when vhdl-conditions-in-parenthesis (insert ")"))
8739 (vhdl-template-generate-body margin label))))
8740
8741 (defun vhdl-template-if-then-use (kind)
8742 "Insert a sequential if statement."
8743 (interactive)
8744 (let ((margin (current-indentation))
8745 (start (point))
8746 label)
8747 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8748 (vhdl-insert-keyword "IF ")
8749 (vhdl-insert-keyword ": IF ")
8750 (goto-char start)
8751 (setq label (vhdl-template-field "[label]" nil t))
8752 (unless label (delete-char 2))
8753 (forward-word 1)
8754 (forward-char 1))
8755 (when vhdl-conditions-in-parenthesis (insert "("))
8756 (when (vhdl-template-field "condition" nil t start (point))
8757 (when vhdl-conditions-in-parenthesis (insert ")"))
8758 (vhdl-insert-keyword
8759 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8760 (indent-to margin)
8761 (vhdl-insert-keyword "END IF")
8762 (when label (insert " " label))
8763 (insert ";")
8764 (forward-line -1)
8765 (indent-to (+ margin vhdl-basic-offset)))))
8766
8767 (defun vhdl-template-if-then ()
8768 "Insert a sequential if statement."
8769 (interactive)
8770 (vhdl-template-if-then-use 'then))
8771
8772 (defun vhdl-template-if-use ()
8773 "Insert a simultaneous if statement."
8774 (interactive)
8775 (vhdl-template-if-then-use 'use))
8776
8777 (defun vhdl-template-instance ()
8778 "Insert a component instantiation statement."
8779 (interactive)
8780 (vhdl-template-component-inst))
8781
8782 (defun vhdl-template-library ()
8783 "Insert a library specification."
8784 (interactive)
8785 (let ((margin (current-indentation))
8786 (start (point))
8787 name end-pos)
8788 (vhdl-insert-keyword "LIBRARY ")
8789 (when (setq name (vhdl-template-field "names" nil t start (point)))
8790 (insert ";")
8791 (unless (string-match "," name)
8792 (setq end-pos (point))
8793 (insert "\n")
8794 (indent-to margin)
8795 (vhdl-insert-keyword "USE ")
8796 (insert name)
8797 (vhdl-insert-keyword "..ALL;")
8798 (backward-char 5)
8799 (if (vhdl-template-field "package name")
8800 (forward-char 5)
8801 (delete-region end-pos (+ (point) 5)))))))
8802
8803 (defun vhdl-template-limit ()
8804 "Insert a limit."
8805 (interactive)
8806 (let ((start (point)))
8807 (vhdl-insert-keyword "LIMIT ")
8808 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8809 t start (point))
8810 (vhdl-template-field "type")
8811 (vhdl-insert-keyword " WITH ")
8812 (vhdl-template-field "real expression" ";"))))
8813
8814 (defun vhdl-template-loop ()
8815 "Insert a loop."
8816 (interactive)
8817 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8818 (cond ((eq char ?w)
8819 (vhdl-template-while-loop))
8820 ((eq char ?f)
8821 (vhdl-template-for-loop))
8822 (t (vhdl-template-bare-loop)))))
8823
8824 (defun vhdl-template-bare-loop ()
8825 "Insert a loop."
8826 (interactive)
8827 (let ((margin (current-indentation))
8828 (start (point))
8829 label)
8830 (if (not (eq vhdl-optional-labels 'all))
8831 (vhdl-insert-keyword "LOOP ")
8832 (vhdl-insert-keyword ": LOOP ")
8833 (goto-char start)
8834 (setq label (vhdl-template-field "[label]" nil t))
8835 (unless label (delete-char 2))
8836 (forward-word 1)
8837 (delete-char 1))
8838 (insert "\n\n")
8839 (indent-to margin)
8840 (vhdl-insert-keyword "END LOOP")
8841 (insert (if label (concat " " label ";") ";"))
8842 (forward-line -1)
8843 (indent-to (+ margin vhdl-basic-offset))))
8844
8845 (defun vhdl-template-map (&optional start optional secondary)
8846 "Insert a map specification with association list."
8847 (interactive)
8848 (let ((start (or start (point)))
8849 margin end-pos)
8850 (vhdl-insert-keyword "MAP (")
8851 (if (not vhdl-association-list-with-formals)
8852 (if (vhdl-template-field
8853 (concat (and optional "[") "association list" (and optional "]"))
8854 ")" (or (not secondary) optional)
8855 (and (not secondary) start) (point))
8856 t
8857 (if (and optional secondary) (delete-region start (point)))
8858 nil)
8859 (if vhdl-argument-list-indent
8860 (setq margin (current-column))
8861 (setq margin (+ (current-indentation) vhdl-basic-offset))
8862 (insert "\n")
8863 (indent-to margin))
8864 (if (vhdl-template-field
8865 (concat (and optional "[") "formal" (and optional "]"))
8866 " => " (or (not secondary) optional)
8867 (and (not secondary) start) (point))
8868 (progn
8869 (vhdl-template-field "actual" ",")
8870 (setq end-pos (point))
8871 (insert "\n")
8872 (indent-to margin)
8873 (while (vhdl-template-field "[formal]" " => " t)
8874 (vhdl-template-field "actual" ",")
8875 (setq end-pos (point))
8876 (insert "\n")
8877 (indent-to margin))
8878 (delete-region end-pos (point))
8879 (delete-backward-char 1)
8880 (insert ")")
8881 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8882 t)
8883 (when (and optional secondary) (delete-region start (point)))
8884 nil))))
8885
8886 (defun vhdl-template-modify (&optional noerror)
8887 "Actualize modification date."
8888 (interactive)
8889 (vhdl-prepare-search-2
8890 (save-excursion
8891 (goto-char (point-min))
8892 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8893 (progn (delete-region (point) (progn (end-of-line) (point)))
8894 (vhdl-template-insert-date))
8895 (unless noerror
8896 (error (concat "ERROR: Modification date prefix string \""
8897 vhdl-modify-date-prefix-string "\" not found")))))))
8898
8899 (defun vhdl-template-modify-noerror ()
8900 "Call `vhdl-template-modify' with NOERROR non-nil."
8901 (vhdl-template-modify t))
8902
8903 (defun vhdl-template-nature ()
8904 "Insert a nature declaration."
8905 (interactive)
8906 (let ((start (point))
8907 name mid-pos end-pos)
8908 (vhdl-insert-keyword "NATURE ")
8909 (when (setq name (vhdl-template-field "name" nil t start (point)))
8910 (vhdl-insert-keyword " IS ")
8911 (let ((definition
8912 (upcase
8913 (or (vhdl-template-field
8914 "across type | ARRAY | RECORD")
8915 ""))))
8916 (cond ((equal definition "")
8917 (insert ";"))
8918 ((equal definition "ARRAY")
8919 (kill-word -1)
8920 (vhdl-template-array 'nature t))
8921 ((equal definition "RECORD")
8922 (setq mid-pos (point-marker))
8923 (kill-word -1)
8924 (vhdl-template-record 'nature name t))
8925 (t
8926 (vhdl-insert-keyword " ACROSS ")
8927 (vhdl-template-field "through type")
8928 (vhdl-insert-keyword " THROUGH ")
8929 (vhdl-template-field "reference name")
8930 (vhdl-insert-keyword " REFERENCE;")))
8931 (when mid-pos
8932 (setq end-pos (point-marker))
8933 (goto-char mid-pos)
8934 (end-of-line))
8935 (vhdl-comment-insert-inline)
8936 (when end-pos (goto-char end-pos))))))
8937
8938 (defun vhdl-template-next ()
8939 "Insert a next statement."
8940 (interactive)
8941 (let ((start (point)))
8942 (vhdl-insert-keyword "NEXT ")
8943 (if (vhdl-template-field "[loop label]" nil t start (point))
8944 (let ((position (point)))
8945 (vhdl-insert-keyword " WHEN ")
8946 (when vhdl-conditions-in-parenthesis (insert "("))
8947 (if (vhdl-template-field "[condition]" nil t)
8948 (when vhdl-conditions-in-parenthesis (insert ")"))
8949 (delete-region position (point))))
8950 (delete-char -1))
8951 (insert ";")))
8952
8953 (defun vhdl-template-others ()
8954 "Insert an others aggregate."
8955 (interactive)
8956 (let ((start (point)))
8957 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8958 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8959 (vhdl-insert-keyword "OTHERS => '")
8960 (when (vhdl-template-field "value" nil t start (point))
8961 (insert "')")))
8962 (vhdl-insert-keyword "OTHERS "))))
8963
8964 (defun vhdl-template-package (&optional kind)
8965 "Insert a package specification or body."
8966 (interactive)
8967 (let ((margin (current-indentation))
8968 (start (point))
8969 name body position)
8970 (vhdl-insert-keyword "PACKAGE ")
8971 (setq body (if kind (eq kind 'body)
8972 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
8973 (when body
8974 (vhdl-insert-keyword "BODY ")
8975 (when (save-excursion
8976 (vhdl-prepare-search-1
8977 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8978 (insert (setq name (match-string 1)))))
8979 (when (or name
8980 (setq name (vhdl-template-field "name" nil t start (point))))
8981 (vhdl-insert-keyword " IS\n")
8982 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8983 (indent-to (+ margin vhdl-basic-offset))
8984 (setq position (point))
8985 (insert "\n")
8986 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8987 (indent-to margin)
8988 (vhdl-insert-keyword "END ")
8989 (unless (vhdl-standard-p '87)
8990 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8991 (insert (or name "") ";")
8992 (goto-char position))))
8993
8994 (defun vhdl-template-package-decl ()
8995 "Insert a package specification."
8996 (interactive)
8997 (vhdl-template-package 'decl))
8998
8999 (defun vhdl-template-package-body ()
9000 "Insert a package body."
9001 (interactive)
9002 (vhdl-template-package 'body))
9003
9004 (defun vhdl-template-port ()
9005 "Insert a port declaration, or port map in instantiation statements."
9006 (interactive)
9007 (let ((start (point)))
9008 (vhdl-prepare-search-1
9009 (cond
9010 ((and (save-excursion ; entity declaration
9011 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9012 (equal "ENTITY" (upcase (match-string 1))))
9013 (vhdl-template-port-list nil))
9014 ((or (save-excursion
9015 (or (beginning-of-line)
9016 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9017 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9018 (vhdl-insert-keyword "PORT ")
9019 (vhdl-template-map start))
9020 (t (vhdl-template-port-list nil))))))
9021
9022 (defun vhdl-template-procedural ()
9023 "Insert a procedural."
9024 (interactive)
9025 (let ((margin (current-indentation))
9026 (start (point))
9027 (case-fold-search t)
9028 label)
9029 (vhdl-insert-keyword "PROCEDURAL ")
9030 (when (memq vhdl-optional-labels '(process all))
9031 (goto-char start)
9032 (insert ": ")
9033 (goto-char start)
9034 (setq label (vhdl-template-field "[label]" nil t))
9035 (unless label (delete-char 2))
9036 (forward-word 1)
9037 (forward-char 1))
9038 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9039 (insert "\n")
9040 (vhdl-template-begin-end "PROCEDURAL" label margin)
9041 (vhdl-comment-block)))
9042
9043 (defun vhdl-template-procedure (&optional kind)
9044 "Insert a procedure declaration or body."
9045 (interactive)
9046 (let ((margin (current-indentation))
9047 (start (point))
9048 name)
9049 (vhdl-insert-keyword "PROCEDURE ")
9050 (when (setq name (vhdl-template-field "name" nil t start (point)))
9051 (vhdl-template-argument-list)
9052 (if (if kind (eq kind 'body)
9053 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9054 (progn (vhdl-insert-keyword " IS")
9055 (when vhdl-auto-align
9056 (vhdl-align-region-groups start (point) 1))
9057 (end-of-line) (insert "\n")
9058 (vhdl-template-begin-end
9059 (unless (vhdl-standard-p '87) "PROCEDURE")
9060 name margin)
9061 (vhdl-comment-block))
9062 (insert ";")
9063 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9064 (end-of-line)))))
9065
9066 (defun vhdl-template-procedure-decl ()
9067 "Insert a procedure declaration."
9068 (interactive)
9069 (vhdl-template-procedure 'decl))
9070
9071 (defun vhdl-template-procedure-body ()
9072 "Insert a procedure body."
9073 (interactive)
9074 (vhdl-template-procedure 'body))
9075
9076 (defun vhdl-template-process (&optional kind)
9077 "Insert a process."
9078 (interactive)
9079 (let ((margin (current-indentation))
9080 (start (point))
9081 label seq input-signals clock reset final-pos)
9082 (setq seq (if kind (eq kind 'seq)
9083 (eq (vhdl-decision-query
9084 "process" "(c)ombinational or (s)equential?" t) ?s)))
9085 (vhdl-insert-keyword "PROCESS ")
9086 (when (memq vhdl-optional-labels '(process all))
9087 (goto-char start)
9088 (insert ": ")
9089 (goto-char start)
9090 (setq label (vhdl-template-field "[label]" nil t))
9091 (unless label (delete-char 2))
9092 (forward-word 1)
9093 (forward-char 1))
9094 (insert "(")
9095 (if (not seq)
9096 (unless (setq input-signals
9097 (vhdl-template-field "[sensitivity list]" ")" t))
9098 (setq input-signals "")
9099 (delete-char -2))
9100 (setq clock (or (and (not (equal "" vhdl-clock-name))
9101 (progn (insert vhdl-clock-name) vhdl-clock-name))
9102 (vhdl-template-field "clock name") "<clock>"))
9103 (when (eq vhdl-reset-kind 'async)
9104 (insert ", ")
9105 (setq reset (or (and (not (equal "" vhdl-reset-name))
9106 (progn (insert vhdl-reset-name) vhdl-reset-name))
9107 (vhdl-template-field "reset name") "<reset>")))
9108 (insert ")"))
9109 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9110 (insert "\n")
9111 (vhdl-template-begin-end "PROCESS" label margin)
9112 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9113 (when vhdl-prompt-for-comments
9114 (setq final-pos (point-marker))
9115 (vhdl-prepare-search-2
9116 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9117 (vhdl-re-search-backward "\\<process\\>" nil t))
9118 (end-of-line -0)
9119 (if (bobp)
9120 (progn (insert "\n") (forward-line -1))
9121 (insert "\n"))
9122 (indent-to margin)
9123 (insert "-- purpose: ")
9124 (if (not (vhdl-template-field "[description]" nil t))
9125 (vhdl-line-kill-entire)
9126 (insert "\n")
9127 (indent-to margin)
9128 (insert "-- type : ")
9129 (insert (if seq "sequential" "combinational") "\n")
9130 (indent-to margin)
9131 (insert "-- inputs : ")
9132 (if (not seq)
9133 (insert input-signals)
9134 (insert clock ", ")
9135 (when reset (insert reset ", "))
9136 (unless (vhdl-template-field "[signal names]" nil t)
9137 (delete-char -2)))
9138 (insert "\n")
9139 (indent-to margin)
9140 (insert "-- outputs: ")
9141 (vhdl-template-field "[signal names]" nil t))))
9142 (goto-char final-pos))))
9143
9144 (defun vhdl-template-process-comb ()
9145 "Insert a combinational process."
9146 (interactive)
9147 (vhdl-template-process 'comb))
9148
9149 (defun vhdl-template-process-seq ()
9150 "Insert a sequential process."
9151 (interactive)
9152 (vhdl-template-process 'seq))
9153
9154 (defun vhdl-template-quantity ()
9155 "Insert a quantity declaration."
9156 (interactive)
9157 (if (vhdl-in-argument-list-p)
9158 (let ((start (point)))
9159 (vhdl-insert-keyword "QUANTITY ")
9160 (when (vhdl-template-field "names" nil t start (point))
9161 (insert " : ")
9162 (vhdl-template-field "[IN | OUT]" " " t)
9163 (vhdl-template-field "type")
9164 (insert ";")
9165 (vhdl-comment-insert-inline)))
9166 (let ((char (vhdl-decision-query
9167 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9168 (cond ((eq char ?f) (vhdl-template-quantity-free))
9169 ((eq char ?b) (vhdl-template-quantity-branch))
9170 ((eq char ?s) (vhdl-template-quantity-source))
9171 (t (vhdl-template-undo (point) (point)))))))
9172
9173 (defun vhdl-template-quantity-free ()
9174 "Insert a free quantity declaration."
9175 (interactive)
9176 (vhdl-insert-keyword "QUANTITY ")
9177 (vhdl-template-field "names")
9178 (insert " : ")
9179 (vhdl-template-field "type")
9180 (let ((position (point)))
9181 (insert " := ")
9182 (unless (vhdl-template-field "[initialization]" nil t)
9183 (delete-region position (point)))
9184 (insert ";")
9185 (vhdl-comment-insert-inline)))
9186
9187 (defun vhdl-template-quantity-branch ()
9188 "Insert a branch quantity declaration."
9189 (interactive)
9190 (let (position)
9191 (vhdl-insert-keyword "QUANTITY ")
9192 (when (vhdl-template-field "[across names]" " " t)
9193 (vhdl-insert-keyword "ACROSS "))
9194 (when (vhdl-template-field "[through names]" " " t)
9195 (vhdl-insert-keyword "THROUGH "))
9196 (vhdl-template-field "plus terminal name")
9197 (setq position (point))
9198 (vhdl-insert-keyword " TO ")
9199 (unless (vhdl-template-field "[minus terminal name]" nil t)
9200 (delete-region position (point)))
9201 (insert ";")
9202 (vhdl-comment-insert-inline)))
9203
9204 (defun vhdl-template-quantity-source ()
9205 "Insert a source quantity declaration."
9206 (interactive)
9207 (vhdl-insert-keyword "QUANTITY ")
9208 (vhdl-template-field "names")
9209 (insert " : ")
9210 (vhdl-template-field "type" " ")
9211 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9212 (progn (vhdl-insert-keyword "NOISE ")
9213 (vhdl-template-field "power expression"))
9214 (vhdl-insert-keyword "SPECTRUM ")
9215 (vhdl-template-field "magnitude expression" ", ")
9216 (vhdl-template-field "phase expression"))
9217 (insert ";")
9218 (vhdl-comment-insert-inline))
9219
9220 (defun vhdl-template-record (kind &optional name secondary)
9221 "Insert a record type declaration."
9222 (interactive)
9223 (let ((margin (current-column))
9224 (start (point))
9225 (first t))
9226 (vhdl-insert-keyword "RECORD\n")
9227 (indent-to (+ margin vhdl-basic-offset))
9228 (when (or (vhdl-template-field "element names"
9229 nil (not secondary) start (point))
9230 secondary)
9231 (while (or first (vhdl-template-field "[element names]" nil t))
9232 (insert " : ")
9233 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9234 (vhdl-comment-insert-inline)
9235 (insert "\n")
9236 (indent-to (+ margin vhdl-basic-offset))
9237 (setq first nil))
9238 (kill-line -0)
9239 (indent-to margin)
9240 (vhdl-insert-keyword "END RECORD")
9241 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9242 (insert ";")
9243 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9244
9245 (defun vhdl-template-report ()
9246 "Insert a report statement."
9247 (interactive)
9248 (let ((start (point)))
9249 (vhdl-insert-keyword "REPORT ")
9250 (if (equal "\"\"" (vhdl-template-field
9251 "string expression" nil t start (point) t))
9252 (delete-backward-char 2)
9253 (setq start (point))
9254 (vhdl-insert-keyword " SEVERITY ")
9255 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9256 (delete-region start (point)))
9257 (insert ";"))))
9258
9259 (defun vhdl-template-return ()
9260 "Insert a return statement."
9261 (interactive)
9262 (let ((start (point)))
9263 (vhdl-insert-keyword "RETURN ")
9264 (unless (vhdl-template-field "[expression]" nil t start (point))
9265 (delete-char -1))
9266 (insert ";")))
9267
9268 (defun vhdl-template-selected-signal-asst ()
9269 "Insert a selected signal assignment."
9270 (interactive)
9271 (let ((margin (current-indentation))
9272 (start (point))
9273 (choices t))
9274 (let ((position (point)))
9275 (vhdl-insert-keyword " SELECT ")
9276 (goto-char position))
9277 (vhdl-insert-keyword "WITH ")
9278 (when (vhdl-template-field "selector expression"
9279 nil t start (+ (point) 7))
9280 (forward-word 1)
9281 (delete-char 1)
9282 (insert "\n")
9283 (indent-to (+ margin vhdl-basic-offset))
9284 (vhdl-template-field "target signal" " <= ")
9285 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9286 (insert "\n")
9287 (indent-to (+ margin vhdl-basic-offset))
9288 (vhdl-template-field "waveform")
9289 (vhdl-insert-keyword " WHEN ")
9290 (vhdl-template-field "choices" ",")
9291 (insert "\n")
9292 (indent-to (+ margin vhdl-basic-offset))
9293 (while (and choices (vhdl-template-field "[waveform]" nil t))
9294 (vhdl-insert-keyword " WHEN ")
9295 (if (setq choices (vhdl-template-field "[choices]" "," t))
9296 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9297 (vhdl-insert-keyword "OTHERS")))
9298 (when choices
9299 (fixup-whitespace)
9300 (delete-char -2))
9301 (insert ";")
9302 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9303
9304 (defun vhdl-template-signal ()
9305 "Insert a signal declaration."
9306 (interactive)
9307 (let ((start (point))
9308 (in-arglist (vhdl-in-argument-list-p)))
9309 (vhdl-insert-keyword "SIGNAL ")
9310 (when (vhdl-template-field "names" nil t start (point))
9311 (insert " : ")
9312 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9313 (vhdl-template-field "type")
9314 (if in-arglist
9315 (progn (insert ";")
9316 (vhdl-comment-insert-inline))
9317 (let ((position (point)))
9318 (insert " := ")
9319 (unless (vhdl-template-field "[initialization]" nil t)
9320 (delete-region position (point)))
9321 (insert ";")
9322 (vhdl-comment-insert-inline))))))
9323
9324 (defun vhdl-template-subnature ()
9325 "Insert a subnature declaration."
9326 (interactive)
9327 (let ((start (point))
9328 position)
9329 (vhdl-insert-keyword "SUBNATURE ")
9330 (when (vhdl-template-field "name" nil t start (point))
9331 (vhdl-insert-keyword " IS ")
9332 (vhdl-template-field "nature" " (")
9333 (if (vhdl-template-field "[index range]" nil t)
9334 (insert ")")
9335 (delete-char -2))
9336 (setq position (point))
9337 (vhdl-insert-keyword " TOLERANCE ")
9338 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9339 nil t nil nil t))
9340 (delete-region position (point))
9341 (vhdl-insert-keyword " ACROSS ")
9342 (vhdl-template-field "string expression" nil nil nil nil t)
9343 (vhdl-insert-keyword " THROUGH"))
9344 (insert ";")
9345 (vhdl-comment-insert-inline))))
9346
9347 (defun vhdl-template-subprogram-body ()
9348 "Insert a subprogram body."
9349 (interactive)
9350 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9351 (vhdl-template-function-body)
9352 (vhdl-template-procedure-body)))
9353
9354 (defun vhdl-template-subprogram-decl ()
9355 "Insert a subprogram declaration."
9356 (interactive)
9357 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9358 (vhdl-template-function-decl)
9359 (vhdl-template-procedure-decl)))
9360
9361 (defun vhdl-template-subtype ()
9362 "Insert a subtype declaration."
9363 (interactive)
9364 (let ((start (point)))
9365 (vhdl-insert-keyword "SUBTYPE ")
9366 (when (vhdl-template-field "name" nil t start (point))
9367 (vhdl-insert-keyword " IS ")
9368 (vhdl-template-field "type" " ")
9369 (unless
9370 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9371 (delete-char -1))
9372 (insert ";")
9373 (vhdl-comment-insert-inline))))
9374
9375 (defun vhdl-template-terminal ()
9376 "Insert a terminal declaration."
9377 (interactive)
9378 (let ((start (point)))
9379 (vhdl-insert-keyword "TERMINAL ")
9380 (when (vhdl-template-field "names" nil t start (point))
9381 (insert " : ")
9382 (vhdl-template-field "nature")
9383 (insert ";")
9384 (vhdl-comment-insert-inline))))
9385
9386 (defun vhdl-template-type ()
9387 "Insert a type declaration."
9388 (interactive)
9389 (let ((start (point))
9390 name mid-pos end-pos)
9391 (vhdl-insert-keyword "TYPE ")
9392 (when (setq name (vhdl-template-field "name" nil t start (point)))
9393 (vhdl-insert-keyword " IS ")
9394 (let ((definition
9395 (upcase
9396 (or (vhdl-template-field
9397 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9398 ""))))
9399 (cond ((equal definition "")
9400 (delete-backward-char 4)
9401 (insert ";"))
9402 ((equal definition "ARRAY")
9403 (kill-word -1)
9404 (vhdl-template-array 'type t))
9405 ((equal definition "RECORD")
9406 (setq mid-pos (point-marker))
9407 (kill-word -1)
9408 (vhdl-template-record 'type name t))
9409 ((equal definition "ACCESS")
9410 (insert " ")
9411 (vhdl-template-field "type" ";"))
9412 ((equal definition "FILE")
9413 (vhdl-insert-keyword " OF ")
9414 (vhdl-template-field "type" ";"))
9415 (t (insert ";")))
9416 (when mid-pos
9417 (setq end-pos (point-marker))
9418 (goto-char mid-pos)
9419 (end-of-line))
9420 (vhdl-comment-insert-inline)
9421 (when end-pos (goto-char end-pos))))))
9422
9423 (defun vhdl-template-use ()
9424 "Insert a use clause."
9425 (interactive)
9426 (let ((start (point)))
9427 (vhdl-prepare-search-1
9428 (vhdl-insert-keyword "USE ")
9429 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9430 (vhdl-insert-keyword "..ALL;")
9431 (backward-char 6)
9432 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9433 (forward-char 1)
9434 (vhdl-template-field "package name")
9435 (forward-char 5))))))
9436
9437 (defun vhdl-template-variable ()
9438 "Insert a variable declaration."
9439 (interactive)
9440 (let ((start (point))
9441 (in-arglist (vhdl-in-argument-list-p)))
9442 (vhdl-prepare-search-2
9443 (if (or (save-excursion
9444 (and (vhdl-re-search-backward
9445 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9446 nil t)
9447 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9448 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9449 (vhdl-insert-keyword "VARIABLE ")
9450 (vhdl-insert-keyword "SHARED VARIABLE ")))
9451 (when (vhdl-template-field "names" nil t start (point))
9452 (insert " : ")
9453 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9454 (vhdl-template-field "type")
9455 (if in-arglist
9456 (progn (insert ";")
9457 (vhdl-comment-insert-inline))
9458 (let ((position (point)))
9459 (insert " := ")
9460 (unless (vhdl-template-field "[initialization]" nil t)
9461 (delete-region position (point)))
9462 (insert ";")
9463 (vhdl-comment-insert-inline))))))
9464
9465 (defun vhdl-template-wait ()
9466 "Insert a wait statement."
9467 (interactive)
9468 (vhdl-insert-keyword "WAIT ")
9469 (unless (vhdl-template-field
9470 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9471 nil t)
9472 (delete-char -1))
9473 (insert ";"))
9474
9475 (defun vhdl-template-when ()
9476 "Indent correctly if within a case statement."
9477 (interactive)
9478 (let ((position (point))
9479 margin)
9480 (vhdl-prepare-search-2
9481 (if (and (= (current-column) (current-indentation))
9482 (vhdl-re-search-forward "\\<end\\>" nil t)
9483 (looking-at "\\s-*\\<case\\>"))
9484 (progn
9485 (setq margin (current-indentation))
9486 (goto-char position)
9487 (delete-horizontal-space)
9488 (indent-to (+ margin vhdl-basic-offset)))
9489 (goto-char position)))
9490 (vhdl-insert-keyword "WHEN ")))
9491
9492 (defun vhdl-template-while-loop ()
9493 "Insert a while loop."
9494 (interactive)
9495 (let* ((margin (current-indentation))
9496 (start (point))
9497 label)
9498 (if (not (eq vhdl-optional-labels 'all))
9499 (vhdl-insert-keyword "WHILE ")
9500 (vhdl-insert-keyword ": WHILE ")
9501 (goto-char start)
9502 (setq label (vhdl-template-field "[label]" nil t))
9503 (unless label (delete-char 2))
9504 (forward-word 1)
9505 (forward-char 1))
9506 (when vhdl-conditions-in-parenthesis (insert "("))
9507 (when (vhdl-template-field "condition" nil t start (point))
9508 (when vhdl-conditions-in-parenthesis (insert ")"))
9509 (vhdl-insert-keyword " LOOP\n\n")
9510 (indent-to margin)
9511 (vhdl-insert-keyword "END LOOP")
9512 (insert (if label (concat " " label ";") ";"))
9513 (forward-line -1)
9514 (indent-to (+ margin vhdl-basic-offset)))))
9515
9516 (defun vhdl-template-with ()
9517 "Insert a with statement (i.e. selected signal assignment)."
9518 (interactive)
9519 (vhdl-prepare-search-1
9520 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9521 (equal ";" (match-string 1)))
9522 (vhdl-template-selected-signal-asst)
9523 (vhdl-insert-keyword "WITH "))))
9524
9525 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9526 ;; Special templates
9527
9528 (defun vhdl-template-clocked-wait ()
9529 "Insert a wait statement for rising/falling clock edge."
9530 (interactive)
9531 (let ((start (point))
9532 clock)
9533 (vhdl-insert-keyword "WAIT UNTIL ")
9534 (when (setq clock
9535 (or (and (not (equal "" vhdl-clock-name))
9536 (progn (insert vhdl-clock-name) vhdl-clock-name))
9537 (vhdl-template-field "clock name" nil t start (point))))
9538 (insert "'event")
9539 (vhdl-insert-keyword " AND ")
9540 (insert clock)
9541 (insert
9542 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9543 (vhdl-comment-insert-inline
9544 (concat (if vhdl-clock-rising-edge "rising" "falling")
9545 " clock edge")))))
9546
9547 (defun vhdl-template-seq-process (clock reset)
9548 "Insert a template for the body of a sequential process."
9549 (let ((margin (current-indentation))
9550 position)
9551 (vhdl-insert-keyword "IF ")
9552 (when (eq vhdl-reset-kind 'async)
9553 (insert reset " = "
9554 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9555 (vhdl-insert-keyword " THEN")
9556 (vhdl-comment-insert-inline
9557 (concat "asynchronous reset (active "
9558 (if vhdl-reset-active-high "high" "low") ")"))
9559 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9560 (setq position (point))
9561 (insert "\n") (indent-to margin)
9562 (vhdl-insert-keyword "ELSIF "))
9563 (if (eq vhdl-clock-edge-condition 'function)
9564 (insert (if vhdl-clock-rising-edge "rising" "falling")
9565 "_edge(" clock ")")
9566 (insert clock "'event")
9567 (vhdl-insert-keyword " AND ")
9568 (insert clock " = "
9569 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9570 (vhdl-insert-keyword " THEN")
9571 (vhdl-comment-insert-inline
9572 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9573 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9574 (when (eq vhdl-reset-kind 'sync)
9575 (vhdl-insert-keyword "IF ")
9576 (setq reset (or (and (not (equal "" vhdl-reset-name))
9577 (progn (insert vhdl-reset-name) vhdl-reset-name))
9578 (vhdl-template-field "reset name") "<reset>"))
9579 (insert " = "
9580 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9581 (vhdl-insert-keyword " THEN")
9582 (vhdl-comment-insert-inline
9583 (concat "synchronous reset (active "
9584 (if vhdl-reset-active-high "high" "low") ")"))
9585 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9586 (setq position (point))
9587 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9588 (vhdl-insert-keyword "ELSE")
9589 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9590 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9591 (vhdl-insert-keyword "END IF;"))
9592 (when (eq vhdl-reset-kind 'none)
9593 (setq position (point)))
9594 (insert "\n") (indent-to margin)
9595 (vhdl-insert-keyword "END IF;")
9596 (goto-char position)
9597 reset))
9598
9599 (defun vhdl-template-standard-package (library package)
9600 "Insert specification of a standard package. Include a library
9601 specification, if not already there."
9602 (let ((margin (current-indentation)))
9603 (unless (equal library "std")
9604 (unless (or (save-excursion
9605 (vhdl-prepare-search-1
9606 (and (not (bobp))
9607 (re-search-backward
9608 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9609 library "\\|end\\)\\>") nil t)
9610 (match-string 2))))
9611 (equal (downcase library) "work"))
9612 (vhdl-insert-keyword "LIBRARY ")
9613 (insert library ";\n")
9614 (indent-to margin))
9615 (vhdl-insert-keyword "USE ")
9616 (insert library "." package)
9617 (vhdl-insert-keyword ".ALL;"))))
9618
9619 (defun vhdl-template-package-math-complex ()
9620 "Insert specification of `math_complex' package."
9621 (interactive)
9622 (vhdl-template-standard-package "ieee" "math_complex"))
9623
9624 (defun vhdl-template-package-math-real ()
9625 "Insert specification of `math_real' package."
9626 (interactive)
9627 (vhdl-template-standard-package "ieee" "math_real"))
9628
9629 (defun vhdl-template-package-numeric-bit ()
9630 "Insert specification of `numeric_bit' package."
9631 (interactive)
9632 (vhdl-template-standard-package "ieee" "numeric_bit"))
9633
9634 (defun vhdl-template-package-numeric-std ()
9635 "Insert specification of `numeric_std' package."
9636 (interactive)
9637 (vhdl-template-standard-package "ieee" "numeric_std"))
9638
9639 (defun vhdl-template-package-std-logic-1164 ()
9640 "Insert specification of `std_logic_1164' package."
9641 (interactive)
9642 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9643
9644 (defun vhdl-template-package-std-logic-arith ()
9645 "Insert specification of `std_logic_arith' package."
9646 (interactive)
9647 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9648
9649 (defun vhdl-template-package-std-logic-misc ()
9650 "Insert specification of `std_logic_misc' package."
9651 (interactive)
9652 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9653
9654 (defun vhdl-template-package-std-logic-signed ()
9655 "Insert specification of `std_logic_signed' package."
9656 (interactive)
9657 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9658
9659 (defun vhdl-template-package-std-logic-textio ()
9660 "Insert specification of `std_logic_textio' package."
9661 (interactive)
9662 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9663
9664 (defun vhdl-template-package-std-logic-unsigned ()
9665 "Insert specification of `std_logic_unsigned' package."
9666 (interactive)
9667 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9668
9669 (defun vhdl-template-package-textio ()
9670 "Insert specification of `textio' package."
9671 (interactive)
9672 (vhdl-template-standard-package "std" "textio"))
9673
9674 (defun vhdl-template-directive (directive)
9675 "Insert directive."
9676 (unless (= (current-indentation) (current-column))
9677 (delete-horizontal-space)
9678 (insert " "))
9679 (insert "-- pragma " directive))
9680
9681 (defun vhdl-template-directive-translate-on ()
9682 "Insert directive 'translate_on'."
9683 (interactive)
9684 (vhdl-template-directive "translate_on"))
9685
9686 (defun vhdl-template-directive-translate-off ()
9687 "Insert directive 'translate_off'."
9688 (interactive)
9689 (vhdl-template-directive "translate_off"))
9690
9691 (defun vhdl-template-directive-synthesis-on ()
9692 "Insert directive 'synthesis_on'."
9693 (interactive)
9694 (vhdl-template-directive "synthesis_on"))
9695
9696 (defun vhdl-template-directive-synthesis-off ()
9697 "Insert directive 'synthesis_off'."
9698 (interactive)
9699 (vhdl-template-directive "synthesis_off"))
9700
9701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9702 ;; Header and footer templates
9703
9704 (defun vhdl-template-header (&optional file-title)
9705 "Insert a VHDL file header."
9706 (interactive)
9707 (unless (equal vhdl-file-header "")
9708 (let (pos)
9709 (save-excursion
9710 (goto-char (point-min))
9711 (vhdl-insert-string-or-file vhdl-file-header)
9712 (setq pos (point-marker)))
9713 (vhdl-template-replace-header-keywords
9714 (point-min-marker) pos file-title))))
9715
9716 (defun vhdl-template-footer ()
9717 "Insert a VHDL file footer."
9718 (interactive)
9719 (unless (equal vhdl-file-footer "")
9720 (let (pos)
9721 (save-excursion
9722 (goto-char (point-max))
9723 (setq pos (point-marker))
9724 (vhdl-insert-string-or-file vhdl-file-footer)
9725 (unless (= (preceding-char) ?\n)
9726 (insert "\n")))
9727 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9728
9729 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9730 is-model)
9731 "Replace keywords in header and footer."
9732 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9733 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9734 pos)
9735 (vhdl-prepare-search-2
9736 (save-excursion
9737 (goto-char beg)
9738 (while (search-forward "<projectdesc>" end t)
9739 (replace-match project-desc t t))
9740 (goto-char beg)
9741 (while (search-forward "<filename>" end t)
9742 (replace-match (buffer-name) t t))
9743 (goto-char beg)
9744 (while (search-forward "<copyright>" end t)
9745 (replace-match vhdl-copyright-string t t))
9746 (goto-char beg)
9747 (while (search-forward "<author>" end t)
9748 (replace-match "" t t)
9749 (insert (user-full-name))
9750 (when user-mail-address (insert " <" user-mail-address ">")))
9751 (goto-char beg)
9752 (while (search-forward "<login>" end t)
9753 (replace-match (user-login-name) t t))
9754 (goto-char beg)
9755 (while (search-forward "<project>" end t)
9756 (replace-match project-title t t))
9757 (goto-char beg)
9758 (while (search-forward "<company>" end t)
9759 (replace-match vhdl-company-name t t))
9760 (goto-char beg)
9761 (while (search-forward "<platform>" end t)
9762 (replace-match vhdl-platform-spec t t))
9763 (goto-char beg)
9764 (while (search-forward "<standard>" end t)
9765 (replace-match
9766 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9767 ((vhdl-standard-p '93) "'93"))
9768 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9769 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9770 (goto-char beg)
9771 ;; Replace <RCS> with $, so that RCS for the source is
9772 ;; not over-enthusiastic with replacements
9773 (while (search-forward "<RCS>" end t)
9774 (replace-match "$" nil t))
9775 (goto-char beg)
9776 (while (search-forward "<date>" end t)
9777 (replace-match "" t t)
9778 (vhdl-template-insert-date))
9779 (goto-char beg)
9780 (while (search-forward "<year>" end t)
9781 (replace-match (format-time-string "%Y" nil) t t))
9782 (goto-char beg)
9783 (when file-title
9784 (while (search-forward "<title string>" end t)
9785 (replace-match file-title t t))
9786 (goto-char beg))
9787 (let (string)
9788 (while
9789 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9790 (setq string (read-string (concat (match-string 1) ": ")))
9791 (replace-match string t t)))
9792 (goto-char beg)
9793 (when (and (not is-model) (search-forward "<cursor>" end t))
9794 (replace-match "" t t)
9795 (setq pos (point))))
9796 (when pos (goto-char pos))
9797 (unless is-model
9798 (when (or (not project-title) (equal project-title ""))
9799 (message "You can specify a project title in user option `vhdl-project-alist'"))
9800 (when (or (not project-desc) (equal project-desc ""))
9801 (message "You can specify a project description in user option `vhdl-project-alist'"))
9802 (when (equal vhdl-platform-spec "")
9803 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9804 (when (equal vhdl-company-name "")
9805 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9806
9807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9808 ;; Comment templates and functions
9809
9810 (defun vhdl-comment-indent ()
9811 "Indent comments."
9812 (let* ((position (point))
9813 (col
9814 (progn
9815 (forward-line -1)
9816 (if (re-search-forward "--" position t)
9817 (- (current-column) 2) ; existing comment at bol stays there
9818 (goto-char position)
9819 (skip-chars-backward " \t")
9820 (max comment-column ; else indent to comment column
9821 (1+ (current-column))))))) ; except leave at least one space
9822 (goto-char position)
9823 col))
9824
9825 (defun vhdl-comment-insert ()
9826 "Start a comment at the end of the line.
9827 If on line with code, indent at least `comment-column'.
9828 If starting after end-comment-column, start a new line."
9829 (interactive)
9830 (when (> (current-column) end-comment-column) (newline-and-indent))
9831 (if (or (looking-at "\\s-*$") ; end of line
9832 (and (not unread-command-events) ; called with key binding or menu
9833 (not (end-of-line))))
9834 (let (margin)
9835 (while (= (preceding-char) ?-) (delete-char -1))
9836 (setq margin (current-column))
9837 (delete-horizontal-space)
9838 (if (bolp)
9839 (progn (indent-to margin) (insert "--"))
9840 (insert " ")
9841 (indent-to comment-column)
9842 (insert "--"))
9843 (if (not unread-command-events) (insert " ")))
9844 ;; else code following current point implies commenting out code
9845 (let (next-input code)
9846 (while (= (preceding-char) ?-) (delete-char -2))
9847 (while (= (setq next-input (read-char)) 13) ; CR
9848 (insert "--") ; or have a space after it?
9849 (forward-char -2)
9850 (forward-line 1)
9851 (message "Enter CR if commenting out a line of code.")
9852 (setq code t))
9853 (unless code
9854 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
9855 (setq unread-command-events
9856 (list (vhdl-character-to-event next-input)))))) ; pushback the char
9857
9858 (defun vhdl-comment-display (&optional line-exists)
9859 "Add 2 comment lines at the current indent, making a display comment."
9860 (interactive)
9861 (let ((margin (current-indentation)))
9862 (unless line-exists (vhdl-comment-display-line))
9863 (insert "\n") (indent-to margin)
9864 (insert "\n") (indent-to margin)
9865 (vhdl-comment-display-line)
9866 (end-of-line -0)
9867 (insert "-- ")))
9868
9869 (defun vhdl-comment-display-line ()
9870 "Displays one line of dashes."
9871 (interactive)
9872 (while (= (preceding-char) ?-) (delete-char -2))
9873 (let* ((col (current-column))
9874 (len (- end-comment-column col)))
9875 (insert-char ?- len)))
9876
9877 (defun vhdl-comment-append-inline ()
9878 "Append empty inline comment to current line."
9879 (interactive)
9880 (end-of-line)
9881 (delete-horizontal-space)
9882 (insert " ")
9883 (indent-to comment-column)
9884 (insert "-- "))
9885
9886 (defun vhdl-comment-insert-inline (&optional string always-insert)
9887 "Insert inline comment."
9888 (when (or (and string (or vhdl-self-insert-comments always-insert))
9889 (and (not string) vhdl-prompt-for-comments))
9890 (let ((position (point)))
9891 (insert " ")
9892 (indent-to comment-column)
9893 (insert "-- ")
9894 (if (not (or (and string (progn (insert string) t))
9895 (vhdl-template-field "[comment]" nil t)))
9896 (delete-region position (point))
9897 (while (= (preceding-char) ? ) (delete-backward-char 1))
9898 ; (when (> (current-column) end-comment-column)
9899 ; (setq position (point-marker))
9900 ; (re-search-backward "-- ")
9901 ; (insert "\n")
9902 ; (indent-to comment-column)
9903 ; (goto-char position))
9904 ))))
9905
9906 (defun vhdl-comment-block ()
9907 "Insert comment for code block."
9908 (when vhdl-prompt-for-comments
9909 (let ((final-pos (point-marker)))
9910 (vhdl-prepare-search-2
9911 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
9912 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
9913 (let (margin)
9914 (back-to-indentation)
9915 (setq margin (current-column))
9916 (end-of-line -0)
9917 (if (bobp)
9918 (progn (insert "\n") (forward-line -1))
9919 (insert "\n"))
9920 (indent-to margin)
9921 (insert "-- purpose: ")
9922 (unless (vhdl-template-field "[description]" nil t)
9923 (vhdl-line-kill-entire)))))
9924 (goto-char final-pos))))
9925
9926 (defun vhdl-comment-uncomment-region (beg end &optional arg)
9927 "Comment out region if not commented out, uncomment otherwise."
9928 (interactive "r\nP")
9929 (save-excursion
9930 (goto-char (1- end))
9931 (end-of-line)
9932 (setq end (point-marker))
9933 (goto-char beg)
9934 (beginning-of-line)
9935 (setq beg (point))
9936 (if (looking-at comment-start)
9937 (comment-region beg end '(4))
9938 (comment-region beg end))))
9939
9940 (defun vhdl-comment-uncomment-line (&optional arg)
9941 "Comment out line if not commented out, uncomment otherwise."
9942 (interactive "p")
9943 (save-excursion
9944 (beginning-of-line)
9945 (let ((position (point)))
9946 (forward-line (or arg 1))
9947 (vhdl-comment-uncomment-region position (point)))))
9948
9949 (defun vhdl-comment-kill-region (beg end)
9950 "Kill comments in region."
9951 (interactive "r")
9952 (save-excursion
9953 (goto-char end)
9954 (setq end (point-marker))
9955 (goto-char beg)
9956 (beginning-of-line)
9957 (while (< (point) end)
9958 (if (looking-at "^\\(\\s-*--.*\n\\)")
9959 (progn (delete-region (match-beginning 1) (match-end 1)))
9960 (beginning-of-line 2)))))
9961
9962 (defun vhdl-comment-kill-inline-region (beg end)
9963 "Kill inline comments in region."
9964 (interactive "r")
9965 (save-excursion
9966 (goto-char end)
9967 (setq end (point-marker))
9968 (goto-char beg)
9969 (beginning-of-line)
9970 (while (< (point) end)
9971 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9972 (delete-region (match-beginning 1) (match-end 1)))
9973 (beginning-of-line 2))))
9974
9975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9976 ;; Subtemplates
9977
9978 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
9979 "Insert a begin ... end pair with optional name after the end.
9980 Point is left between them."
9981 (let (position)
9982 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9983 (indent-to margin)
9984 (vhdl-insert-keyword "BEGIN")
9985 (when (and (or construct name) vhdl-self-insert-comments)
9986 (insert " --")
9987 (when construct (insert " ") (vhdl-insert-keyword construct))
9988 (when name (insert " " name)))
9989 (insert "\n")
9990 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9991 (indent-to (+ margin vhdl-basic-offset))
9992 (setq position (point))
9993 (insert "\n")
9994 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9995 (indent-to margin)
9996 (vhdl-insert-keyword "END")
9997 (when construct (insert " ") (vhdl-insert-keyword construct))
9998 (insert (if name (concat " " name) "") ";")
9999 (goto-char position)))
10000
10001 (defun vhdl-template-argument-list (&optional is-function)
10002 "Read from user a procedure or function argument list."
10003 (insert " (")
10004 (let ((margin (current-column))
10005 (start (point))
10006 (end-pos (point))
10007 not-empty interface semicolon-pos)
10008 (unless vhdl-argument-list-indent
10009 (setq margin (+ (current-indentation) vhdl-basic-offset))
10010 (insert "\n")
10011 (indent-to margin))
10012 (setq interface (vhdl-template-field
10013 (concat "[CONSTANT | SIGNAL"
10014 (unless is-function " | VARIABLE") "]") " " t))
10015 (while (vhdl-template-field "[names]" nil t)
10016 (setq not-empty t)
10017 (insert " : ")
10018 (unless is-function
10019 (if (and interface (equal (upcase interface) "CONSTANT"))
10020 (vhdl-insert-keyword "IN ")
10021 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10022 (vhdl-template-field "type")
10023 (setq semicolon-pos (point))
10024 (insert ";")
10025 (vhdl-comment-insert-inline)
10026 (setq end-pos (point))
10027 (insert "\n")
10028 (indent-to margin)
10029 (setq interface (vhdl-template-field
10030 (concat "[CONSTANT | SIGNAL"
10031 (unless is-function " | VARIABLE") "]") " " t)))
10032 (delete-region end-pos (point))
10033 (when semicolon-pos (goto-char semicolon-pos))
10034 (if not-empty
10035 (progn (delete-char 1) (insert ")"))
10036 (delete-backward-char 2))))
10037
10038 (defun vhdl-template-generic-list (optional &optional no-value)
10039 "Read from user a generic spec argument list."
10040 (let (margin
10041 (start (point)))
10042 (vhdl-insert-keyword "GENERIC (")
10043 (setq margin (current-column))
10044 (unless vhdl-argument-list-indent
10045 (let ((position (point)))
10046 (back-to-indentation)
10047 (setq margin (+ (current-column) vhdl-basic-offset))
10048 (goto-char position)
10049 (insert "\n")
10050 (indent-to margin)))
10051 (let ((vhdl-generics (vhdl-template-field
10052 (concat (and optional "[") "name"
10053 (and no-value "s") (and optional "]"))
10054 nil optional)))
10055 (if (not vhdl-generics)
10056 (if optional
10057 (progn (vhdl-line-kill-entire) (end-of-line -0)
10058 (unless vhdl-argument-list-indent
10059 (vhdl-line-kill-entire) (end-of-line -0)))
10060 (vhdl-template-undo start (point))
10061 nil )
10062 (insert " : ")
10063 (let (semicolon-pos end-pos)
10064 (while vhdl-generics
10065 (vhdl-template-field "type")
10066 (if no-value
10067 (progn (setq semicolon-pos (point))
10068 (insert ";"))
10069 (insert " := ")
10070 (unless (vhdl-template-field "[value]" nil t)
10071 (delete-char -4))
10072 (setq semicolon-pos (point))
10073 (insert ";"))
10074 (vhdl-comment-insert-inline)
10075 (setq end-pos (point))
10076 (insert "\n")
10077 (indent-to margin)
10078 (setq vhdl-generics (vhdl-template-field
10079 (concat "[name" (and no-value "s") "]")
10080 " : " t)))
10081 (delete-region end-pos (point))
10082 (goto-char semicolon-pos)
10083 (insert ")")
10084 (end-of-line)
10085 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10086 t)))))
10087
10088 (defun vhdl-template-port-list (optional)
10089 "Read from user a port spec argument list."
10090 (let ((start (point))
10091 margin vhdl-ports object)
10092 (vhdl-insert-keyword "PORT (")
10093 (setq margin (current-column))
10094 (unless vhdl-argument-list-indent
10095 (let ((position (point)))
10096 (back-to-indentation)
10097 (setq margin (+ (current-column) vhdl-basic-offset))
10098 (goto-char position)
10099 (insert "\n")
10100 (indent-to margin)))
10101 (when (vhdl-standard-p 'ams)
10102 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10103 " " t)))
10104 (setq vhdl-ports (vhdl-template-field
10105 (concat (and optional "[") "names" (and optional "]"))
10106 nil optional))
10107 (if (not vhdl-ports)
10108 (if optional
10109 (progn (vhdl-line-kill-entire) (end-of-line -0)
10110 (unless vhdl-argument-list-indent
10111 (vhdl-line-kill-entire) (end-of-line -0)))
10112 (vhdl-template-undo start (point))
10113 nil)
10114 (insert " : ")
10115 (let (semicolon-pos end-pos)
10116 (while vhdl-ports
10117 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10118 (vhdl-template-field "IN | OUT | INOUT" " "))
10119 ((equal "QUANTITY" (upcase object))
10120 (vhdl-template-field "[IN | OUT]" " " t)))
10121 (vhdl-template-field
10122 (if (and object (equal "TERMINAL" (upcase object)))
10123 "nature" "type"))
10124 (setq semicolon-pos (point))
10125 (insert ";")
10126 (vhdl-comment-insert-inline)
10127 (setq end-pos (point))
10128 (insert "\n")
10129 (indent-to margin)
10130 (when (vhdl-standard-p 'ams)
10131 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10132 " " t)))
10133 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10134 (delete-region end-pos (point))
10135 (goto-char semicolon-pos)
10136 (insert ")")
10137 (end-of-line)
10138 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10139 t))))
10140
10141 (defun vhdl-template-generate-body (margin label)
10142 "Insert body for generate template."
10143 (vhdl-insert-keyword " GENERATE")
10144 ; (if (not (vhdl-standard-p '87))
10145 ; (vhdl-template-begin-end "GENERATE" label margin)
10146 (insert "\n\n")
10147 (indent-to margin)
10148 (vhdl-insert-keyword "END GENERATE ")
10149 (insert label ";")
10150 (end-of-line 0)
10151 (indent-to (+ margin vhdl-basic-offset)))
10152
10153 (defun vhdl-template-insert-date ()
10154 "Insert date in appropriate format."
10155 (interactive)
10156 (insert
10157 (cond
10158 ;; 'american, 'european, 'scientific kept for backward compatibility
10159 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10160 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10161 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10162 (t (format-time-string vhdl-date-format nil)))))
10163
10164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10165 ;; Help functions
10166
10167 (defun vhdl-electric-space (count)
10168 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10169 if in comment and past end-comment-column."
10170 (interactive "p")
10171 (cond ((vhdl-in-comment-p)
10172 (self-insert-command count)
10173 (cond ((>= (current-column) (+ 2 end-comment-column))
10174 (backward-char 1)
10175 (skip-chars-backward "^ \t\n")
10176 (indent-new-comment-line)
10177 (skip-chars-forward "^ \t\n")
10178 (forward-char 1))
10179 ((>= (current-column) end-comment-column)
10180 (indent-new-comment-line))
10181 (t nil)))
10182 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10183 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10184 (vhdl-prepare-search-1
10185 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10186 (self-insert-command count))
10187 (t (self-insert-command count))))
10188
10189 (defun vhdl-template-field (prompt &optional follow-string optional
10190 begin end is-string default)
10191 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10192 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10193 an empty string is inserted, return nil and call `vhdl-template-undo' for
10194 the region between BEGIN and END. IS-STRING indicates whether a string
10195 with double-quotes is to be inserted. DEFAULT specifies a default string."
10196 (let ((position (point))
10197 string)
10198 (insert "<" prompt ">")
10199 (setq string
10200 (condition-case ()
10201 (read-from-minibuffer (concat prompt ": ")
10202 (or (and is-string '("\"\"" . 2)) default)
10203 vhdl-minibuffer-local-map)
10204 (quit (if (and optional begin end)
10205 (progn (beep) "")
10206 (keyboard-quit)))))
10207 (when (or (not (equal string "")) optional)
10208 (delete-region position (point)))
10209 (when (and (equal string "") optional begin end)
10210 (vhdl-template-undo begin end)
10211 (message "Template aborted"))
10212 (unless (equal string "")
10213 (insert string)
10214 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10215 vhdl-keywords-regexp)
10216 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10217 vhdl-types-regexp)
10218 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10219 (concat "'" vhdl-attributes-regexp))
10220 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10221 vhdl-enum-values-regexp))
10222 (when (or (not (equal string "")) (not optional))
10223 (insert (or follow-string "")))
10224 (if (equal string "") nil string)))
10225
10226 (defun vhdl-decision-query (string prompt &optional optional)
10227 "Query a decision from the user."
10228 (let ((start (point)))
10229 (when string (vhdl-insert-keyword (concat string " ")))
10230 (message prompt)
10231 (let ((char (read-char)))
10232 (delete-region start (point))
10233 (if (and optional (eq char ?\r))
10234 (progn (insert " ")
10235 (unexpand-abbrev)
10236 (throw 'abort "ERROR: Template aborted"))
10237 char))))
10238
10239 (defun vhdl-insert-keyword (keyword)
10240 "Insert KEYWORD and adjust case."
10241 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10242
10243 (defun vhdl-case-keyword (keyword)
10244 "Adjust case of KEYWORD."
10245 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10246
10247 (defun vhdl-case-word (num)
10248 "Adjust case or following NUM words."
10249 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10250
10251 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10252 "If preceeding character is part of a word or a paren then hippie-expand,
10253 else insert tab (used for word completion in VHDL minibuffer)."
10254 (interactive "P")
10255 (cond
10256 ;; expand word
10257 ((= (char-syntax (preceding-char)) ?w)
10258 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10259 (case-replace nil)
10260 (hippie-expand-only-buffers
10261 (or (and (boundp 'hippie-expand-only-buffers)
10262 hippie-expand-only-buffers)
10263 '(vhdl-mode))))
10264 (vhdl-expand-abbrev prefix-arg)))
10265 ;; expand parenthesis
10266 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10267 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10268 (case-replace nil))
10269 (vhdl-expand-paren prefix-arg)))
10270 ;; insert tab
10271 (t (insert-tab))))
10272
10273 (defun vhdl-template-search-prompt ()
10274 "Search for left out template prompts and query again."
10275 (interactive)
10276 (vhdl-prepare-search-2
10277 (when (or (re-search-forward
10278 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10279 (re-search-backward
10280 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10281 (let ((string (match-string 1)))
10282 (replace-match "")
10283 (vhdl-template-field string)))))
10284
10285 (defun vhdl-template-undo (begin end)
10286 "Undo aborted template by deleting region and unexpanding the keyword."
10287 (cond (vhdl-template-invoked-by-hook
10288 (goto-char end)
10289 (insert " ")
10290 (delete-region begin end)
10291 (unexpand-abbrev))
10292 (t (delete-region begin end))))
10293
10294 (defun vhdl-insert-string-or-file (string)
10295 "Insert STRING or file contents if STRING is an existing file name."
10296 (unless (equal string "")
10297 (let ((file-name
10298 (progn (string-match "^\\([^\n]+\\)" string)
10299 (vhdl-resolve-env-variable (match-string 1 string)))))
10300 (if (file-exists-p file-name)
10301 (forward-char (cadr (insert-file-contents file-name)))
10302 (insert string)))))
10303
10304 (defun vhdl-beginning-of-block ()
10305 "Move cursor to the beginning of the enclosing block."
10306 (let (pos)
10307 (save-excursion
10308 (beginning-of-line)
10309 ;; search backward for block beginning or end
10310 (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))
10311 ;; not consider subprogram declarations
10312 (or (and (match-string 5)
10313 (save-match-data
10314 (save-excursion
10315 (goto-char (match-end 5))
10316 (forward-word 1) (forward-sexp)
10317 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10318 (match-string 1)))
10319 ;; not consider configuration specifications
10320 (and (match-string 6)
10321 (save-match-data
10322 (save-excursion
10323 (vhdl-end-of-block)
10324 (beginning-of-line)
10325 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10326 (match-string 2))
10327 ;; skip subblock if block end found
10328 (vhdl-beginning-of-block)))
10329 (when pos (goto-char pos))))
10330
10331 (defun vhdl-end-of-block ()
10332 "Move cursor to the end of the enclosing block."
10333 (let (pos)
10334 (save-excursion
10335 (end-of-line)
10336 ;; search forward for block beginning or end
10337 (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))
10338 ;; not consider subprogram declarations
10339 (or (and (match-string 5)
10340 (save-match-data
10341 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10342 (match-string 1)))
10343 ;; not consider configuration specifications
10344 (and (match-string 6)
10345 (save-match-data
10346 (save-excursion
10347 (vhdl-end-of-block)
10348 (beginning-of-line)
10349 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10350 (not (match-string 2)))
10351 ;; skip subblock if block beginning found
10352 (vhdl-end-of-block)))
10353 (when pos (goto-char pos))))
10354
10355 (defun vhdl-sequential-statement-p ()
10356 "Check if point is within sequential statement part."
10357 (let ((start (point)))
10358 (save-excursion
10359 (vhdl-prepare-search-2
10360 ;; is sequential statement if ...
10361 (and (re-search-backward "^\\s-*begin\\>" nil t)
10362 ;; ... point is between "begin" and "end" of ...
10363 (progn (vhdl-end-of-block)
10364 (< start (point)))
10365 ;; ... a sequential block
10366 (progn (vhdl-beginning-of-block)
10367 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10368
10369 (defun vhdl-in-argument-list-p ()
10370 "Check if within an argument list."
10371 (save-excursion
10372 (vhdl-prepare-search-2
10373 (or (string-match "arglist"
10374 (format "%s" (caar (vhdl-get-syntactic-context))))
10375 (progn (beginning-of-line)
10376 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10377
10378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10379 ;; Abbrev hooks
10380
10381 (defun vhdl-hooked-abbrev (func)
10382 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10383 but not if inside a comment or quote)."
10384 (if (or (vhdl-in-literal)
10385 (save-excursion
10386 (forward-word -1)
10387 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10388 (progn
10389 (insert " ")
10390 (unexpand-abbrev)
10391 (delete-char -1))
10392 (if (not vhdl-electric-mode)
10393 (progn
10394 (insert " ")
10395 (unexpand-abbrev)
10396 (backward-word 1)
10397 (vhdl-case-word 1)
10398 (delete-char 1))
10399 (let ((invoke-char last-command-char)
10400 (abbrev-mode -1)
10401 (vhdl-template-invoked-by-hook t))
10402 (let ((caught (catch 'abort
10403 (funcall func))))
10404 (when (stringp caught) (message caught)))
10405 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10406 ;; delete CR which is still in event queue
10407 (if (fboundp 'enqueue-eval-event)
10408 (enqueue-eval-event 'delete-char -1)
10409 (setq unread-command-events ; push back a delete char
10410 (list (vhdl-character-to-event ?\177))))))))
10411
10412 (defun vhdl-template-alias-hook ()
10413 (vhdl-hooked-abbrev 'vhdl-template-alias))
10414 (defun vhdl-template-architecture-hook ()
10415 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10416 (defun vhdl-template-assert-hook ()
10417 (vhdl-hooked-abbrev 'vhdl-template-assert))
10418 (defun vhdl-template-attribute-hook ()
10419 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10420 (defun vhdl-template-block-hook ()
10421 (vhdl-hooked-abbrev 'vhdl-template-block))
10422 (defun vhdl-template-break-hook ()
10423 (vhdl-hooked-abbrev 'vhdl-template-break))
10424 (defun vhdl-template-case-hook ()
10425 (vhdl-hooked-abbrev 'vhdl-template-case))
10426 (defun vhdl-template-component-hook ()
10427 (vhdl-hooked-abbrev 'vhdl-template-component))
10428 (defun vhdl-template-instance-hook ()
10429 (vhdl-hooked-abbrev 'vhdl-template-instance))
10430 (defun vhdl-template-conditional-signal-asst-hook ()
10431 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10432 (defun vhdl-template-configuration-hook ()
10433 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10434 (defun vhdl-template-constant-hook ()
10435 (vhdl-hooked-abbrev 'vhdl-template-constant))
10436 (defun vhdl-template-disconnect-hook ()
10437 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10438 (defun vhdl-template-display-comment-hook ()
10439 (vhdl-hooked-abbrev 'vhdl-comment-display))
10440 (defun vhdl-template-else-hook ()
10441 (vhdl-hooked-abbrev 'vhdl-template-else))
10442 (defun vhdl-template-elsif-hook ()
10443 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10444 (defun vhdl-template-entity-hook ()
10445 (vhdl-hooked-abbrev 'vhdl-template-entity))
10446 (defun vhdl-template-exit-hook ()
10447 (vhdl-hooked-abbrev 'vhdl-template-exit))
10448 (defun vhdl-template-file-hook ()
10449 (vhdl-hooked-abbrev 'vhdl-template-file))
10450 (defun vhdl-template-for-hook ()
10451 (vhdl-hooked-abbrev 'vhdl-template-for))
10452 (defun vhdl-template-function-hook ()
10453 (vhdl-hooked-abbrev 'vhdl-template-function))
10454 (defun vhdl-template-generic-hook ()
10455 (vhdl-hooked-abbrev 'vhdl-template-generic))
10456 (defun vhdl-template-group-hook ()
10457 (vhdl-hooked-abbrev 'vhdl-template-group))
10458 (defun vhdl-template-library-hook ()
10459 (vhdl-hooked-abbrev 'vhdl-template-library))
10460 (defun vhdl-template-limit-hook ()
10461 (vhdl-hooked-abbrev 'vhdl-template-limit))
10462 (defun vhdl-template-if-hook ()
10463 (vhdl-hooked-abbrev 'vhdl-template-if))
10464 (defun vhdl-template-bare-loop-hook ()
10465 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10466 (defun vhdl-template-map-hook ()
10467 (vhdl-hooked-abbrev 'vhdl-template-map))
10468 (defun vhdl-template-nature-hook ()
10469 (vhdl-hooked-abbrev 'vhdl-template-nature))
10470 (defun vhdl-template-next-hook ()
10471 (vhdl-hooked-abbrev 'vhdl-template-next))
10472 (defun vhdl-template-others-hook ()
10473 (vhdl-hooked-abbrev 'vhdl-template-others))
10474 (defun vhdl-template-package-hook ()
10475 (vhdl-hooked-abbrev 'vhdl-template-package))
10476 (defun vhdl-template-port-hook ()
10477 (vhdl-hooked-abbrev 'vhdl-template-port))
10478 (defun vhdl-template-procedural-hook ()
10479 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10480 (defun vhdl-template-procedure-hook ()
10481 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10482 (defun vhdl-template-process-hook ()
10483 (vhdl-hooked-abbrev 'vhdl-template-process))
10484 (defun vhdl-template-quantity-hook ()
10485 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10486 (defun vhdl-template-report-hook ()
10487 (vhdl-hooked-abbrev 'vhdl-template-report))
10488 (defun vhdl-template-return-hook ()
10489 (vhdl-hooked-abbrev 'vhdl-template-return))
10490 (defun vhdl-template-selected-signal-asst-hook ()
10491 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10492 (defun vhdl-template-signal-hook ()
10493 (vhdl-hooked-abbrev 'vhdl-template-signal))
10494 (defun vhdl-template-subnature-hook ()
10495 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10496 (defun vhdl-template-subtype-hook ()
10497 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10498 (defun vhdl-template-terminal-hook ()
10499 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10500 (defun vhdl-template-type-hook ()
10501 (vhdl-hooked-abbrev 'vhdl-template-type))
10502 (defun vhdl-template-use-hook ()
10503 (vhdl-hooked-abbrev 'vhdl-template-use))
10504 (defun vhdl-template-variable-hook ()
10505 (vhdl-hooked-abbrev 'vhdl-template-variable))
10506 (defun vhdl-template-wait-hook ()
10507 (vhdl-hooked-abbrev 'vhdl-template-wait))
10508 (defun vhdl-template-when-hook ()
10509 (vhdl-hooked-abbrev 'vhdl-template-when))
10510 (defun vhdl-template-while-loop-hook ()
10511 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10512 (defun vhdl-template-with-hook ()
10513 (vhdl-hooked-abbrev 'vhdl-template-with))
10514 (defun vhdl-template-and-hook ()
10515 (vhdl-hooked-abbrev 'vhdl-template-and))
10516 (defun vhdl-template-or-hook ()
10517 (vhdl-hooked-abbrev 'vhdl-template-or))
10518 (defun vhdl-template-nand-hook ()
10519 (vhdl-hooked-abbrev 'vhdl-template-nand))
10520 (defun vhdl-template-nor-hook ()
10521 (vhdl-hooked-abbrev 'vhdl-template-nor))
10522 (defun vhdl-template-xor-hook ()
10523 (vhdl-hooked-abbrev 'vhdl-template-xor))
10524 (defun vhdl-template-xnor-hook ()
10525 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10526 (defun vhdl-template-not-hook ()
10527 (vhdl-hooked-abbrev 'vhdl-template-not))
10528
10529 (defun vhdl-template-default-hook ()
10530 (vhdl-hooked-abbrev 'vhdl-template-default))
10531 (defun vhdl-template-default-indent-hook ()
10532 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10533
10534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10535 ;; Template insertion from completion list
10536
10537 (defun vhdl-template-insert-construct (name)
10538 "Insert the built-in construct template with NAME."
10539 (interactive
10540 (list (let ((completion-ignore-case t))
10541 (completing-read "Construct name: "
10542 vhdl-template-construct-alist nil t))))
10543 (vhdl-template-insert-fun
10544 (cadr (assoc name vhdl-template-construct-alist))))
10545
10546 (defun vhdl-template-insert-package (name)
10547 "Insert the built-in package template with NAME."
10548 (interactive
10549 (list (let ((completion-ignore-case t))
10550 (completing-read "Package name: "
10551 vhdl-template-package-alist nil t))))
10552 (vhdl-template-insert-fun
10553 (cadr (assoc name vhdl-template-package-alist))))
10554
10555 (defun vhdl-template-insert-directive (name)
10556 "Insert the built-in directive template with NAME."
10557 (interactive
10558 (list (let ((completion-ignore-case t))
10559 (completing-read "Directive name: "
10560 vhdl-template-directive-alist nil t))))
10561 (vhdl-template-insert-fun
10562 (cadr (assoc name vhdl-template-directive-alist))))
10563
10564 (defun vhdl-template-insert-fun (fun)
10565 "Call FUN to insert a built-in template."
10566 (let ((caught (catch 'abort (when fun (funcall fun)))))
10567 (when (stringp caught) (message caught))))
10568
10569
10570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10571 ;;; Models
10572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10573
10574 (defun vhdl-model-insert (model-name)
10575 "Insert the user model with name MODEL-NAME."
10576 (interactive
10577 (let ((completion-ignore-case t))
10578 (list (completing-read "Model name: " vhdl-model-alist))))
10579 (indent-according-to-mode)
10580 (let ((start (point-marker))
10581 (margin (current-indentation))
10582 model position prompt string end)
10583 (vhdl-prepare-search-2
10584 (when (setq model (assoc model-name vhdl-model-alist))
10585 ;; insert model
10586 (beginning-of-line)
10587 (delete-horizontal-space)
10588 (goto-char start)
10589 (vhdl-insert-string-or-file (nth 1 model))
10590 (setq end (point-marker))
10591 ;; indent code
10592 (goto-char start)
10593 (beginning-of-line)
10594 (while (< (point) end)
10595 (unless (looking-at "^$")
10596 (insert-char ? margin))
10597 (beginning-of-line 2))
10598 (goto-char start)
10599 ;; insert clock
10600 (unless (equal "" vhdl-clock-name)
10601 (while (re-search-forward "<clock>" end t)
10602 (replace-match vhdl-clock-name)))
10603 (goto-char start)
10604 ;; insert reset
10605 (unless (equal "" vhdl-reset-name)
10606 (while (re-search-forward "<reset>" end t)
10607 (replace-match vhdl-reset-name)))
10608 ;; replace header prompts
10609 (vhdl-template-replace-header-keywords start end nil t)
10610 (goto-char start)
10611 ;; query other prompts
10612 (while (re-search-forward
10613 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10614 (unless (equal "cursor" (match-string 1))
10615 (setq position (match-beginning 1))
10616 (setq prompt (match-string 1))
10617 (replace-match "")
10618 (setq string (vhdl-template-field prompt nil t))
10619 ;; replace occurrences of same prompt
10620 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10621 (replace-match (or string "")))
10622 (goto-char position)))
10623 (goto-char start)
10624 ;; goto final position
10625 (if (re-search-forward "<cursor>" end t)
10626 (replace-match "")
10627 (goto-char end))))))
10628
10629 (defun vhdl-model-defun ()
10630 "Define help and hook functions for user models."
10631 (let ((model-alist vhdl-model-alist)
10632 model-name model-keyword)
10633 (while model-alist
10634 ;; define functions for user models that can be invoked from menu and key
10635 ;; bindings and which themselves call `vhdl-model-insert' with the model
10636 ;; name as argument
10637 (setq model-name (nth 0 (car model-alist)))
10638 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10639 ,(concat "Insert model for \"" model-name "\".")
10640 (interactive)
10641 (vhdl-model-insert ,model-name)))
10642 ;; define hooks for user models that are invoked from keyword abbrevs
10643 (setq model-keyword (nth 3 (car model-alist)))
10644 (unless (equal model-keyword "")
10645 (eval `(defun
10646 ,(vhdl-function-name
10647 "vhdl-model" model-name "hook") ()
10648 (vhdl-hooked-abbrev
10649 ',(vhdl-function-name "vhdl-model" model-name)))))
10650 (setq model-alist (cdr model-alist)))))
10651
10652 (vhdl-model-defun)
10653
10654
10655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10656 ;;; Port translation
10657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10658
10659 (defvar vhdl-port-list nil
10660 "Variable to hold last port map parsed.")
10661 ;; structure: (parenthesised expression means list of such entries)
10662 ;; (ent-name
10663 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10664 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10665 ;; (lib-name pack-key))
10666
10667 (defun vhdl-parse-string (string &optional optional)
10668 "Check that the text following point matches the regexp in STRING."
10669 (if (looking-at string)
10670 (goto-char (match-end 0))
10671 (unless optional
10672 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10673 (vhdl-current-line) string)))
10674 nil))
10675
10676 (defun vhdl-replace-string (regexp-cons string)
10677 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10678 (vhdl-prepare-search-1
10679 (if (string-match (car regexp-cons) string)
10680 (funcall vhdl-file-name-case
10681 (replace-match (cdr regexp-cons) t nil string))
10682 string)))
10683
10684 (defun vhdl-parse-group-comment ()
10685 "Parse comment and empty lines between groups of lines."
10686 (let ((start (point))
10687 string)
10688 (vhdl-forward-comment (point-max))
10689 (setq string (buffer-substring-no-properties start (point)))
10690 ;; strip off leading blanks and first newline
10691 (while (string-match "^\\(\\s-+\\)" string)
10692 (setq string (concat (substring string 0 (match-beginning 1))
10693 (substring string (match-end 1)))))
10694 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10695 (substring string 1)
10696 string)))
10697
10698 (defun vhdl-paste-group-comment (string indent)
10699 "Paste comment and empty lines from STRING between groups of lines
10700 with INDENT."
10701 (let ((pos (point-marker)))
10702 (when (> indent 0)
10703 (while (string-match "^\\(--\\)" string)
10704 (setq string (concat (substring string 0 (match-beginning 1))
10705 (make-string indent ? )
10706 (substring string (match-beginning 1))))))
10707 (beginning-of-line)
10708 (insert string)
10709 (goto-char pos)))
10710
10711 (defvar vhdl-port-flattened nil
10712 "Indicates whether a port has been flattened.")
10713
10714 (defun vhdl-port-flatten (&optional as-alist)
10715 "Flatten port list so that only one generic/port exists per line."
10716 (interactive)
10717 (if (not vhdl-port-list)
10718 (error "ERROR: No port has been read")
10719 (message "Flattening port...")
10720 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10721 (old-vhdl-port-list (cdr vhdl-port-list))
10722 old-port-list new-port-list old-port new-port names)
10723 ;; traverse port list and flatten entries
10724 (while (cdr old-vhdl-port-list)
10725 (setq old-port-list (car old-vhdl-port-list))
10726 (setq new-port-list nil)
10727 (while old-port-list
10728 (setq old-port (car old-port-list))
10729 (setq names (car old-port))
10730 (while names
10731 (setq new-port (cons (if as-alist (car names) (list (car names)))
10732 (cdr old-port)))
10733 (setq new-port-list (append new-port-list (list new-port)))
10734 (setq names (cdr names)))
10735 (setq old-port-list (cdr old-port-list)))
10736 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10737 (setq new-vhdl-port-list (append new-vhdl-port-list
10738 (list new-port-list))))
10739 (setq vhdl-port-list
10740 (append new-vhdl-port-list (list old-vhdl-port-list))
10741 vhdl-port-flattened t)
10742 (message "Flattening port...done"))))
10743
10744 (defvar vhdl-port-reversed-direction nil
10745 "Indicates whether port directions are reversed.")
10746
10747 (defun vhdl-port-reverse-direction ()
10748 "Reverse direction for all ports (useful in testbenches)."
10749 (interactive)
10750 (if (not vhdl-port-list)
10751 (error "ERROR: No port has been read")
10752 (message "Reversing port directions...")
10753 (let ((port-list (nth 2 vhdl-port-list))
10754 port-dir-car port-dir)
10755 ;; traverse port list and reverse directions
10756 (while port-list
10757 (setq port-dir-car (cddr (car port-list))
10758 port-dir (car port-dir-car))
10759 (setcar port-dir-car
10760 (cond ((equal port-dir "in") "out")
10761 ((equal port-dir "out") "in")
10762 (t port-dir)))
10763 (setq port-list (cdr port-list)))
10764 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10765 (message "Reversing port directions...done"))))
10766
10767 (defun vhdl-port-copy ()
10768 "Get generic and port information from an entity or component declaration."
10769 (interactive)
10770 (save-excursion
10771 (let (parse-error end-of-list
10772 decl-type name generic-list port-list context-clause
10773 object names direct type init comment group-comment)
10774 (vhdl-prepare-search-2
10775 (setq
10776 parse-error
10777 (catch 'parse
10778 ;; check if within entity or component declaration
10779 (end-of-line)
10780 (when (or (not (re-search-backward
10781 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10782 (equal "END" (upcase (match-string 1))))
10783 (throw 'parse "ERROR: Not within an entity or component declaration"))
10784 (setq decl-type (downcase (match-string-no-properties 1)))
10785 (forward-word 1)
10786 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10787 (setq name (match-string-no-properties 1))
10788 (message "Reading port of %s \"%s\"..." decl-type name)
10789 (vhdl-forward-syntactic-ws)
10790 ;; parse generic clause
10791 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10792 ;; parse group comment and spacing
10793 (setq group-comment (vhdl-parse-group-comment))
10794 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10795 (while (not end-of-list)
10796 ;; parse names
10797 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
10798 (setq names (list (match-string-no-properties 1)))
10799 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10800 (setq names
10801 (append names (list (match-string-no-properties 1)))))
10802 ;; parse type
10803 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10804 (setq type (match-string-no-properties 1))
10805 (setq comment nil)
10806 (while (looking-at "(")
10807 (setq type
10808 (concat type
10809 (buffer-substring-no-properties
10810 (point) (progn (forward-sexp) (point)))
10811 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10812 (match-string-no-properties 1)))))
10813 ;; special case: closing parenthesis is on separate line
10814 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10815 (setq comment (substring type (match-beginning 2)))
10816 (setq type (substring type 0 (match-beginning 1))))
10817 ;; strip of trailing group-comment
10818 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10819 (setq type (substring type 0 (match-end 1)))
10820 ;; parse initialization expression
10821 (setq init nil)
10822 (when (vhdl-parse-string ":=[ \t\n]*" t)
10823 (vhdl-parse-string "\\([^();\n]*\\)")
10824 (setq init (match-string-no-properties 1))
10825 (while (looking-at "(")
10826 (setq init
10827 (concat init
10828 (buffer-substring-no-properties
10829 (point) (progn (forward-sexp) (point)))
10830 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10831 (match-string-no-properties 1))))))
10832 ;; special case: closing parenthesis is on separate line
10833 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10834 (setq comment (substring init (match-beginning 2)))
10835 (setq init (substring init 0 (match-beginning 1)))
10836 (vhdl-forward-syntactic-ws))
10837 (skip-chars-forward " \t")
10838 ;; parse inline comment, special case: as above, no initial.
10839 (unless comment
10840 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10841 (match-string-no-properties 1))))
10842 (vhdl-forward-syntactic-ws)
10843 (setq end-of-list (vhdl-parse-string ")" t))
10844 (vhdl-parse-string "\\s-*;\\s-*")
10845 ;; parse inline comment
10846 (unless comment
10847 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10848 (match-string-no-properties 1))))
10849 ;; save everything in list
10850 (setq generic-list (append generic-list
10851 (list (list names type init
10852 comment group-comment))))
10853 ;; parse group comment and spacing
10854 (setq group-comment (vhdl-parse-group-comment))))
10855 ;; parse port clause
10856 (when (vhdl-parse-string "port[ \t\n]*(" t)
10857 ;; parse group comment and spacing
10858 (setq group-comment (vhdl-parse-group-comment))
10859 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10860 (while (not end-of-list)
10861 ;; parse object
10862 (setq object
10863 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10864 (match-string-no-properties 1)))
10865 ;; parse names (accept extended identifiers)
10866 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10867 (setq names (list (match-string-no-properties 1)))
10868 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10869 (setq names (append names (list (match-string-no-properties 1)))))
10870 ;; parse direction
10871 (vhdl-parse-string ":[ \t\n]*")
10872 (setq direct
10873 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10874 (match-string-no-properties 1)))
10875 ;; parse type
10876 (vhdl-parse-string "\\([^();\n]+\\)")
10877 (setq type (match-string-no-properties 1))
10878 (setq comment nil)
10879 (while (looking-at "(")
10880 (setq type (concat type
10881 (buffer-substring-no-properties
10882 (point) (progn (forward-sexp) (point)))
10883 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10884 (match-string-no-properties 1)))))
10885 ;; special case: closing parenthesis is on separate line
10886 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10887 (setq comment (substring type (match-beginning 2)))
10888 (setq type (substring type 0 (match-beginning 1))))
10889 ;; strip of trailing group-comment
10890 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10891 (setq type (substring type 0 (match-end 1)))
10892 (vhdl-forward-syntactic-ws)
10893 (setq end-of-list (vhdl-parse-string ")" t))
10894 (vhdl-parse-string "\\s-*;\\s-*")
10895 ;; parse inline comment
10896 (unless comment
10897 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10898 (match-string-no-properties 1))))
10899 ;; save everything in list
10900 (setq port-list (append port-list
10901 (list (list names object direct type
10902 comment group-comment))))
10903 ;; parse group comment and spacing
10904 (setq group-comment (vhdl-parse-group-comment))))
10905 ; (vhdl-parse-string "end\\>")
10906 ;; parse context clause
10907 (setq context-clause (vhdl-scan-context-clause))
10908 ; ;; add surrounding package to context clause
10909 ; (when (and (equal decl-type "component")
10910 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10911 ; (setq context-clause
10912 ; (append context-clause
10913 ; (list (cons (vhdl-work-library)
10914 ; (match-string-no-properties 1))))))
10915 (message "Reading port of %s \"%s\"...done" decl-type name)
10916 nil)))
10917 ;; finish parsing
10918 (if parse-error
10919 (error parse-error)
10920 (setq vhdl-port-list (list name generic-list port-list context-clause)
10921 vhdl-port-reversed-direction nil
10922 vhdl-port-flattened nil)))))
10923
10924 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10925 "Paste a context clause."
10926 (let ((margin (current-indentation))
10927 (clause-list (nth 3 vhdl-port-list))
10928 clause)
10929 (while clause-list
10930 (setq clause (car clause-list))
10931 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10932 (downcase exclude-pack-name)))
10933 (save-excursion
10934 (re-search-backward
10935 (concat "^\\s-*use\\s-+" (car clause)
10936 "\." (cdr clause) "\\>") nil t)))
10937 (vhdl-template-standard-package (car clause) (cdr clause))
10938 (insert "\n"))
10939 (setq clause-list (cdr clause-list)))))
10940
10941 (defun vhdl-port-paste-generic (&optional no-init)
10942 "Paste a generic clause."
10943 (let ((margin (current-indentation))
10944 (generic-list (nth 1 vhdl-port-list))
10945 list-margin start names generic)
10946 ;; paste generic clause
10947 (when generic-list
10948 (setq start (point))
10949 (vhdl-insert-keyword "GENERIC (")
10950 (unless vhdl-argument-list-indent
10951 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10952 (setq list-margin (current-column))
10953 (while generic-list
10954 (setq generic (car generic-list))
10955 ;; paste group comment and spacing
10956 (when (memq vhdl-include-group-comments '(decl always))
10957 (vhdl-paste-group-comment (nth 4 generic) list-margin))
10958 ;; paste names
10959 (setq names (nth 0 generic))
10960 (while names
10961 (insert (car names))
10962 (setq names (cdr names))
10963 (when names (insert ", ")))
10964 ;; paste type
10965 (insert " : " (nth 1 generic))
10966 ;; paste initialization
10967 (when (and (not no-init) (nth 2 generic))
10968 (insert " := " (nth 2 generic)))
10969 (unless (cdr generic-list) (insert ")"))
10970 (insert ";")
10971 ;; paste comment
10972 (when (and vhdl-include-port-comments (nth 3 generic))
10973 (vhdl-comment-insert-inline (nth 3 generic) t))
10974 (setq generic-list (cdr generic-list))
10975 (when generic-list (insert "\n") (indent-to list-margin)))
10976 ;; align generic clause
10977 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
10978
10979 (defun vhdl-port-paste-port ()
10980 "Paste a port clause."
10981 (let ((margin (current-indentation))
10982 (port-list (nth 2 vhdl-port-list))
10983 list-margin start names port)
10984 ;; paste port clause
10985 (when port-list
10986 (setq start (point))
10987 (vhdl-insert-keyword "PORT (")
10988 (unless vhdl-argument-list-indent
10989 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10990 (setq list-margin (current-column))
10991 (while port-list
10992 (setq port (car port-list))
10993 ;; paste group comment and spacing
10994 (when (memq vhdl-include-group-comments '(decl always))
10995 (vhdl-paste-group-comment (nth 5 port) list-margin))
10996 ;; paste object
10997 (when (nth 1 port) (insert (nth 1 port) " "))
10998 ;; paste names
10999 (setq names (nth 0 port))
11000 (while names
11001 (insert (car names))
11002 (setq names (cdr names))
11003 (when names (insert ", ")))
11004 ;; paste direction
11005 (insert " : ")
11006 (when (nth 2 port) (insert (nth 2 port) " "))
11007 ;; paste type
11008 (insert (nth 3 port))
11009 (unless (cdr port-list) (insert ")"))
11010 (insert ";")
11011 ;; paste comment
11012 (when (and vhdl-include-port-comments (nth 4 port))
11013 (vhdl-comment-insert-inline (nth 4 port) t))
11014 (setq port-list (cdr port-list))
11015 (when port-list (insert "\n") (indent-to list-margin)))
11016 ;; align port clause
11017 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11018
11019 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11020 "Paste as an entity or component declaration."
11021 (unless no-indent (indent-according-to-mode))
11022 (let ((margin (current-indentation))
11023 (name (nth 0 vhdl-port-list)))
11024 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11025 (insert name)
11026 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11027 (vhdl-insert-keyword " IS"))
11028 ;; paste generic and port clause
11029 (when (nth 1 vhdl-port-list)
11030 (insert "\n")
11031 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11032 (insert "\n"))
11033 (indent-to (+ margin vhdl-basic-offset))
11034 (vhdl-port-paste-generic (eq kind 'component)))
11035 (when (nth 2 vhdl-port-list)
11036 (insert "\n")
11037 (when (and (memq vhdl-insert-empty-lines '(unit all))
11038 (eq kind 'entity))
11039 (insert "\n"))
11040 (indent-to (+ margin vhdl-basic-offset)))
11041 (vhdl-port-paste-port)
11042 (insert "\n")
11043 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11044 (insert "\n"))
11045 (indent-to margin)
11046 (vhdl-insert-keyword "END")
11047 (if (eq kind 'entity)
11048 (progn
11049 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11050 (insert " " name))
11051 (vhdl-insert-keyword " COMPONENT")
11052 (unless (vhdl-standard-p '87) (insert " " name)))
11053 (insert ";")))
11054
11055 (defun vhdl-port-paste-entity (&optional no-indent)
11056 "Paste as an entity declaration."
11057 (interactive)
11058 (if (not vhdl-port-list)
11059 (error "ERROR: No port read")
11060 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11061 (vhdl-port-paste-declaration 'entity no-indent)
11062 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11063
11064 (defun vhdl-port-paste-component (&optional no-indent)
11065 "Paste as a component declaration."
11066 (interactive)
11067 (if (not vhdl-port-list)
11068 (error "ERROR: No port read")
11069 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11070 (vhdl-port-paste-declaration 'component no-indent)
11071 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11072
11073 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11074 "Paste as a generic map."
11075 (interactive)
11076 (unless secondary (indent-according-to-mode))
11077 (let ((margin (current-indentation))
11078 list-margin start generic
11079 (generic-list (nth 1 vhdl-port-list)))
11080 (when generic-list
11081 (setq start (point))
11082 (vhdl-insert-keyword "GENERIC MAP (")
11083 (if (not vhdl-association-list-with-formals)
11084 ;; paste list of actual generics
11085 (while generic-list
11086 (insert (if no-constants
11087 (car (nth 0 (car generic-list)))
11088 (or (nth 2 (car generic-list)) " ")))
11089 (setq generic-list (cdr generic-list))
11090 (insert (if generic-list ", " ")")))
11091 (unless vhdl-argument-list-indent
11092 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11093 (setq list-margin (current-column))
11094 (while generic-list
11095 (setq generic (car generic-list))
11096 ;; paste group comment and spacing
11097 (when (eq vhdl-include-group-comments 'always)
11098 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11099 ;; paste formal and actual generic
11100 (insert (car (nth 0 generic)) " => "
11101 (if no-constants
11102 (car (nth 0 generic))
11103 (or (nth 2 generic) "")))
11104 (setq generic-list (cdr generic-list))
11105 (insert (if generic-list "," ")"))
11106 ;; paste comment
11107 (when (or vhdl-include-type-comments
11108 (and vhdl-include-port-comments (nth 3 generic)))
11109 (vhdl-comment-insert-inline
11110 (concat
11111 (when vhdl-include-type-comments
11112 (concat "[" (nth 1 generic) "] "))
11113 (when vhdl-include-port-comments (nth 3 generic))) t))
11114 (when generic-list (insert "\n") (indent-to list-margin)))
11115 ;; align generic map
11116 (when vhdl-auto-align
11117 (vhdl-align-region-groups start (point) 1 t))))))
11118
11119 (defun vhdl-port-paste-port-map ()
11120 "Paste as a port map."
11121 (let ((margin (current-indentation))
11122 list-margin start port
11123 (port-list (nth 2 vhdl-port-list)))
11124 (when port-list
11125 (setq start (point))
11126 (vhdl-insert-keyword "PORT MAP (")
11127 (if (not vhdl-association-list-with-formals)
11128 ;; paste list of actual ports
11129 (while port-list
11130 (insert (vhdl-replace-string vhdl-actual-port-name
11131 (car (nth 0 (car port-list)))))
11132 (setq port-list (cdr port-list))
11133 (insert (if port-list ", " ");")))
11134 (unless vhdl-argument-list-indent
11135 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11136 (setq list-margin (current-column))
11137 (while port-list
11138 (setq port (car port-list))
11139 ;; paste group comment and spacing
11140 (when (eq vhdl-include-group-comments 'always)
11141 (vhdl-paste-group-comment (nth 5 port) list-margin))
11142 ;; paste formal and actual port
11143 (insert (car (nth 0 port)) " => ")
11144 (insert (vhdl-replace-string vhdl-actual-port-name
11145 (car (nth 0 port))))
11146 (setq port-list (cdr port-list))
11147 (insert (if port-list "," ");"))
11148 ;; paste comment
11149 (when (or vhdl-include-direction-comments
11150 vhdl-include-type-comments
11151 (and vhdl-include-port-comments (nth 4 port)))
11152 (vhdl-comment-insert-inline
11153 (concat
11154 (cond ((and vhdl-include-direction-comments
11155 vhdl-include-type-comments)
11156 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11157 (nth 3 port) "] "))
11158 ((and vhdl-include-direction-comments (nth 2 port))
11159 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11160 (vhdl-include-direction-comments " ")
11161 (vhdl-include-type-comments
11162 (concat "[" (nth 3 port) "] ")))
11163 (when vhdl-include-port-comments (nth 4 port))) t))
11164 (when port-list (insert "\n") (indent-to list-margin)))
11165 ;; align port clause
11166 (when vhdl-auto-align
11167 (vhdl-align-region-groups start (point) 1))))))
11168
11169 (defun vhdl-port-paste-instance (&optional name no-indent title)
11170 "Paste as an instantiation."
11171 (interactive)
11172 (if (not vhdl-port-list)
11173 (error "ERROR: No port read")
11174 (let ((orig-vhdl-port-list vhdl-port-list))
11175 ;; flatten local copy of port list (must be flat for port mapping)
11176 (vhdl-port-flatten)
11177 (unless no-indent (indent-according-to-mode))
11178 (let ((margin (current-indentation)))
11179 ;; paste instantiation
11180 (cond (name
11181 (insert name))
11182 ((equal (cdr vhdl-instance-name) "")
11183 (setq name (vhdl-template-field "instance name")))
11184 ((string-match "\%d" (cdr vhdl-instance-name))
11185 (let ((n 1))
11186 (while (save-excursion
11187 (setq name (format (vhdl-replace-string
11188 vhdl-instance-name
11189 (nth 0 vhdl-port-list)) n))
11190 (goto-char (point-min))
11191 (vhdl-re-search-forward name nil t))
11192 (setq n (1+ n)))
11193 (insert name)))
11194 (t (insert (vhdl-replace-string vhdl-instance-name
11195 (nth 0 vhdl-port-list)))))
11196 (message "Pasting port as instantiation \"%s\"..." name)
11197 (insert ": ")
11198 (when title
11199 (save-excursion
11200 (beginning-of-line)
11201 (indent-to vhdl-basic-offset)
11202 (insert "-- instance \"" name "\"\n")))
11203 (if (not (vhdl-use-direct-instantiation))
11204 (insert (nth 0 vhdl-port-list))
11205 (vhdl-insert-keyword "ENTITY ")
11206 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11207 (when (nth 1 vhdl-port-list)
11208 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11209 (vhdl-port-paste-generic-map t t))
11210 (when (nth 2 vhdl-port-list)
11211 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11212 (vhdl-port-paste-port-map))
11213 (message "Pasting port as instantiation \"%s\"...done" name))
11214 (setq vhdl-port-list orig-vhdl-port-list))))
11215
11216 (defun vhdl-port-paste-constants (&optional no-indent)
11217 "Paste generics as constants."
11218 (interactive)
11219 (if (not vhdl-port-list)
11220 (error "ERROR: No port read")
11221 (let ((orig-vhdl-port-list vhdl-port-list))
11222 (message "Pasting port as constants...")
11223 ;; flatten local copy of port list (must be flat for constant initial.)
11224 (vhdl-port-flatten)
11225 (unless no-indent (indent-according-to-mode))
11226 (let ((margin (current-indentation))
11227 start generic name
11228 (generic-list (nth 1 vhdl-port-list)))
11229 (when generic-list
11230 (setq start (point))
11231 (while generic-list
11232 (setq generic (car generic-list))
11233 ;; paste group comment and spacing
11234 (when (memq vhdl-include-group-comments '(decl always))
11235 (vhdl-paste-group-comment (nth 4 generic) margin))
11236 (vhdl-insert-keyword "CONSTANT ")
11237 ;; paste generic constants
11238 (setq name (nth 0 generic))
11239 (when name
11240 (insert (car name))
11241 ;; paste type
11242 (insert " : " (nth 1 generic))
11243 ;; paste initialization
11244 (when (nth 2 generic)
11245 (insert " := " (nth 2 generic)))
11246 (insert ";")
11247 ;; paste comment
11248 (when (and vhdl-include-port-comments (nth 3 generic))
11249 (vhdl-comment-insert-inline (nth 3 generic) t))
11250 (setq generic-list (cdr generic-list))
11251 (when generic-list (insert "\n") (indent-to margin))))
11252 ;; align signal list
11253 (when vhdl-auto-align
11254 (vhdl-align-region-groups start (point) 1))))
11255 (message "Pasting port as constants...done")
11256 (setq vhdl-port-list orig-vhdl-port-list))))
11257
11258 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11259 "Paste ports as internal signals."
11260 (interactive)
11261 (if (not vhdl-port-list)
11262 (error "ERROR: No port read")
11263 (message "Pasting port as signals...")
11264 (unless no-indent (indent-according-to-mode))
11265 (let ((margin (current-indentation))
11266 start port names
11267 (port-list (nth 2 vhdl-port-list)))
11268 (when port-list
11269 (setq start (point))
11270 (while port-list
11271 (setq port (car port-list))
11272 ;; paste group comment and spacing
11273 (when (memq vhdl-include-group-comments '(decl always))
11274 (vhdl-paste-group-comment (nth 5 port) margin))
11275 ;; paste object
11276 (if (nth 1 port)
11277 (insert (nth 1 port) " ")
11278 (vhdl-insert-keyword "SIGNAL "))
11279 ;; paste actual port signals
11280 (setq names (nth 0 port))
11281 (while names
11282 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11283 (setq names (cdr names))
11284 (when names (insert ", ")))
11285 ;; paste type
11286 (insert " : " (nth 3 port))
11287 ;; paste initialization (inputs only)
11288 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11289 (insert " := " (if (string-match "(.+)" (nth 3 port))
11290 "(others => '0')" "'0'")))
11291 (insert ";")
11292 ;; paste comment
11293 (when (or vhdl-include-direction-comments
11294 (and vhdl-include-port-comments (nth 4 port)))
11295 (vhdl-comment-insert-inline
11296 (concat
11297 (cond ((and vhdl-include-direction-comments (nth 2 port))
11298 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11299 (vhdl-include-direction-comments " "))
11300 (when vhdl-include-port-comments (nth 4 port))) t))
11301 (setq port-list (cdr port-list))
11302 (when port-list (insert "\n") (indent-to margin)))
11303 ;; align signal list
11304 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11305 (message "Pasting port as signals...done")))
11306
11307 (defun vhdl-port-paste-initializations (&optional no-indent)
11308 "Paste ports as signal initializations."
11309 (interactive)
11310 (if (not vhdl-port-list)
11311 (error "ERROR: No port read")
11312 (let ((orig-vhdl-port-list vhdl-port-list))
11313 (message "Pasting port as initializations...")
11314 ;; flatten local copy of port list (must be flat for signal initial.)
11315 (vhdl-port-flatten)
11316 (unless no-indent (indent-according-to-mode))
11317 (let ((margin (current-indentation))
11318 start port name
11319 (port-list (nth 2 vhdl-port-list)))
11320 (when port-list
11321 (setq start (point))
11322 (while port-list
11323 (setq port (car port-list))
11324 ;; paste actual port signal (inputs only)
11325 (when (equal "IN" (upcase (nth 2 port)))
11326 (setq name (car (nth 0 port)))
11327 (insert (vhdl-replace-string vhdl-actual-port-name name))
11328 ;; paste initialization
11329 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11330 "(others => '0')" "'0'") ";"))
11331 (setq port-list (cdr port-list))
11332 (when (and port-list
11333 (equal "IN" (upcase (nth 2 (car port-list)))))
11334 (insert "\n") (indent-to margin)))
11335 ;; align signal list
11336 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11337 (message "Pasting port as initializations...done")
11338 (setq vhdl-port-list orig-vhdl-port-list))))
11339
11340 (defun vhdl-port-paste-testbench ()
11341 "Paste as a bare-bones testbench."
11342 (interactive)
11343 (if (not vhdl-port-list)
11344 (error "ERROR: No port read")
11345 (let ((case-fold-search t)
11346 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11347 (nth 0 vhdl-port-list)))
11348 (source-buffer (current-buffer))
11349 arch-name config-name ent-file-name arch-file-name
11350 ent-buffer arch-buffer position)
11351 ;; open entity file
11352 (unless (eq vhdl-testbench-create-files 'none)
11353 (setq ent-file-name
11354 (concat ent-name "." (file-name-extension (buffer-file-name))))
11355 (if (file-exists-p ent-file-name)
11356 (if (y-or-n-p
11357 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11358 (progn (find-file ent-file-name)
11359 (erase-buffer)
11360 (set-buffer-modified-p nil))
11361 (if (eq vhdl-testbench-create-files 'separate)
11362 (setq ent-file-name nil)
11363 (error "ERROR: Pasting port as testbench...aborted")))
11364 (find-file ent-file-name)))
11365 (unless (and (eq vhdl-testbench-create-files 'separate)
11366 (null ent-file-name))
11367 ;; paste entity header
11368 (if vhdl-testbench-include-header
11369 (progn (vhdl-template-header
11370 (concat "Testbench for design \""
11371 (nth 0 vhdl-port-list) "\""))
11372 (goto-char (point-max)))
11373 (vhdl-comment-display-line) (insert "\n\n"))
11374 ;; paste std_logic_1164 package
11375 (when vhdl-testbench-include-library
11376 (vhdl-template-package-std-logic-1164)
11377 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11378 ;; paste entity declaration
11379 (vhdl-insert-keyword "ENTITY ")
11380 (insert ent-name)
11381 (vhdl-insert-keyword " IS")
11382 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11383 (insert "\n")
11384 (vhdl-insert-keyword "END ")
11385 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11386 (insert ent-name ";")
11387 (insert "\n\n")
11388 (vhdl-comment-display-line) (insert "\n"))
11389 ;; get architecture name
11390 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11391 (read-from-minibuffer "architecture name: "
11392 nil vhdl-minibuffer-local-map)
11393 (vhdl-replace-string vhdl-testbench-architecture-name
11394 (nth 0 vhdl-port-list))))
11395 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11396 ;; open architecture file
11397 (if (not (eq vhdl-testbench-create-files 'separate))
11398 (insert "\n")
11399 (setq ent-buffer (current-buffer))
11400 (setq arch-file-name
11401 (concat ent-name "_" arch-name "."
11402 (file-name-extension (buffer-file-name))))
11403 (when (and (file-exists-p arch-file-name)
11404 (not (y-or-n-p (concat "File \"" arch-file-name
11405 "\" exists; overwrite? "))))
11406 (error "ERROR: Pasting port as testbench...aborted"))
11407 (find-file arch-file-name)
11408 (erase-buffer)
11409 (set-buffer-modified-p nil)
11410 ;; paste architecture header
11411 (if vhdl-testbench-include-header
11412 (progn (vhdl-template-header
11413 (concat "Testbench architecture for design \""
11414 (nth 0 vhdl-port-list) "\""))
11415 (goto-char (point-max)))
11416 (vhdl-comment-display-line) (insert "\n\n")))
11417 ;; paste architecture body
11418 (vhdl-insert-keyword "ARCHITECTURE ")
11419 (insert arch-name)
11420 (vhdl-insert-keyword " OF ")
11421 (insert ent-name)
11422 (vhdl-insert-keyword " IS")
11423 (insert "\n\n") (indent-to vhdl-basic-offset)
11424 ;; paste component declaration
11425 (unless (vhdl-use-direct-instantiation)
11426 (vhdl-port-paste-component t)
11427 (insert "\n\n") (indent-to vhdl-basic-offset))
11428 ;; paste constants
11429 (when (nth 1 vhdl-port-list)
11430 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11431 (vhdl-port-paste-constants t)
11432 (insert "\n\n") (indent-to vhdl-basic-offset))
11433 ;; paste internal signals
11434 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11435 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11436 (insert "\n")
11437 ;; paste custom declarations
11438 (unless (equal "" vhdl-testbench-declarations)
11439 (insert "\n")
11440 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11441 (setq position (point))
11442 (insert "\n\n")
11443 (vhdl-comment-display-line) (insert "\n")
11444 (when vhdl-testbench-include-configuration
11445 (setq config-name (vhdl-replace-string
11446 vhdl-testbench-configuration-name
11447 (concat ent-name " " arch-name)))
11448 (insert "\n")
11449 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11450 (vhdl-insert-keyword " OF ") (insert ent-name)
11451 (vhdl-insert-keyword " IS\n")
11452 (indent-to vhdl-basic-offset)
11453 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11454 (indent-to vhdl-basic-offset)
11455 (vhdl-insert-keyword "END FOR;\n")
11456 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11457 (vhdl-comment-display-line) (insert "\n"))
11458 (goto-char position)
11459 (vhdl-template-begin-end
11460 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11461 ;; paste instantiation
11462 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11463 (vhdl-port-paste-instance
11464 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11465 (insert "\n")
11466 ;; paste custom statements
11467 (unless (equal "" vhdl-testbench-statements)
11468 (insert "\n")
11469 (vhdl-insert-string-or-file vhdl-testbench-statements))
11470 (insert "\n")
11471 (indent-to vhdl-basic-offset)
11472 (unless (eq vhdl-testbench-create-files 'none)
11473 (setq arch-buffer (current-buffer))
11474 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11475 (set-buffer arch-buffer) (save-buffer))
11476 (message
11477 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11478 ent-name arch-name)
11479 (and ent-file-name
11480 (format "\n File created: \"%s\"" ent-file-name))
11481 (and arch-file-name
11482 (format "\n File created: \"%s\"" arch-file-name)))))))
11483
11484
11485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11486 ;;; Subprogram interface translation
11487 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11488
11489 (defvar vhdl-subprog-list nil
11490 "Variable to hold last subprogram interface parsed.")
11491 ;; structure: (parenthesised expression means list of such entries)
11492 ;; (subprog-name kind
11493 ;; ((names) object direct type init comment group-comment)
11494 ;; return-type return-comment group-comment)
11495
11496 (defvar vhdl-subprog-flattened nil
11497 "Indicates whether an subprogram interface has been flattened.")
11498
11499 (defun vhdl-subprog-flatten ()
11500 "Flatten interface list so that only one parameter exists per line."
11501 (interactive)
11502 (if (not vhdl-subprog-list)
11503 (error "ERROR: No subprogram interface has been read")
11504 (message "Flattening subprogram interface...")
11505 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11506 new-subprog-list old-subprog new-subprog names)
11507 ;; traverse parameter list and flatten entries
11508 (while old-subprog-list
11509 (setq old-subprog (car old-subprog-list))
11510 (setq names (car old-subprog))
11511 (while names
11512 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11513 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11514 (setq names (cdr names)))
11515 (setq old-subprog-list (cdr old-subprog-list)))
11516 (setq vhdl-subprog-list
11517 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11518 new-subprog-list (nth 3 vhdl-subprog-list)
11519 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11520 vhdl-subprog-flattened t)
11521 (message "Flattening subprogram interface...done"))))
11522
11523 (defun vhdl-subprog-copy ()
11524 "Get interface information from a subprogram specification."
11525 (interactive)
11526 (save-excursion
11527 (let (parse-error pos end-of-list
11528 name kind param-list object names direct type init
11529 comment group-comment
11530 return-type return-comment return-group-comment)
11531 (vhdl-prepare-search-2
11532 (setq
11533 parse-error
11534 (catch 'parse
11535 ;; check if within function declaration
11536 (setq pos (point))
11537 (end-of-line)
11538 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11539 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11540 (goto-char (match-end 0))
11541 (save-excursion (backward-char)
11542 (forward-sexp)
11543 (<= pos (point))))
11544 (throw 'parse "ERROR: Not within a subprogram specification"))
11545 (setq name (match-string-no-properties 5))
11546 (setq kind (if (match-string 2) 'procedure 'function))
11547 (setq end-of-list (not (match-string 7)))
11548 (message "Reading interface of subprogram \"%s\"..." name)
11549 ;; parse parameter list
11550 (setq group-comment (vhdl-parse-group-comment))
11551 (setq end-of-list (or end-of-list
11552 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11553 (while (not end-of-list)
11554 ;; parse object
11555 (setq object
11556 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11557 (match-string-no-properties 1)))
11558 ;; parse names (accept extended identifiers)
11559 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11560 (setq names (list (match-string-no-properties 1)))
11561 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11562 (setq names (append names (list (match-string-no-properties 1)))))
11563 ;; parse direction
11564 (vhdl-parse-string ":[ \t\n]*")
11565 (setq direct
11566 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11567 (match-string-no-properties 1)))
11568 ;; parse type
11569 (vhdl-parse-string "\\([^():;\n]+\\)")
11570 (setq type (match-string-no-properties 1))
11571 (setq comment nil)
11572 (while (looking-at "(")
11573 (setq type
11574 (concat type
11575 (buffer-substring-no-properties
11576 (point) (progn (forward-sexp) (point)))
11577 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11578 (match-string-no-properties 1)))))
11579 ;; special case: closing parenthesis is on separate line
11580 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11581 (setq comment (substring type (match-beginning 2)))
11582 (setq type (substring type 0 (match-beginning 1))))
11583 ;; strip off trailing group-comment
11584 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11585 (setq type (substring type 0 (match-end 1)))
11586 ;; parse initialization expression
11587 (setq init nil)
11588 (when (vhdl-parse-string ":=[ \t\n]*" t)
11589 (vhdl-parse-string "\\([^();\n]*\\)")
11590 (setq init (match-string-no-properties 1))
11591 (while (looking-at "(")
11592 (setq init
11593 (concat init
11594 (buffer-substring-no-properties
11595 (point) (progn (forward-sexp) (point)))
11596 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11597 (match-string-no-properties 1))))))
11598 ;; special case: closing parenthesis is on separate line
11599 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11600 (setq comment (substring init (match-beginning 2)))
11601 (setq init (substring init 0 (match-beginning 1)))
11602 (vhdl-forward-syntactic-ws))
11603 (skip-chars-forward " \t")
11604 ;; parse inline comment, special case: as above, no initial.
11605 (unless comment
11606 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11607 (match-string-no-properties 1))))
11608 (vhdl-forward-syntactic-ws)
11609 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11610 ;; parse inline comment
11611 (unless comment
11612 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11613 (match-string-no-properties 1))))
11614 (setq return-group-comment (vhdl-parse-group-comment))
11615 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11616 ;; parse return type
11617 (when (match-string 3)
11618 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11619 (setq return-type (match-string-no-properties 1))
11620 (when (and return-type
11621 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11622 (setq return-comment (substring return-type (match-beginning 2)))
11623 (setq return-type (substring return-type 0 (match-beginning 1))))
11624 ;; strip of trailing group-comment
11625 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11626 (setq return-type (substring return-type 0 (match-end 1)))
11627 ;; parse return comment
11628 (unless return-comment
11629 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11630 (match-string-no-properties 1)))))
11631 ;; parse inline comment
11632 (unless comment
11633 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11634 (match-string-no-properties 1))))
11635 ;; save everything in list
11636 (setq param-list (append param-list
11637 (list (list names object direct type init
11638 comment group-comment))))
11639 ;; parse group comment and spacing
11640 (setq group-comment (vhdl-parse-group-comment)))
11641 (message "Reading interface of subprogram \"%s\"...done" name)
11642 nil)))
11643 ;; finish parsing
11644 (if parse-error
11645 (error parse-error)
11646 (setq vhdl-subprog-list
11647 (list name kind param-list return-type return-comment
11648 return-group-comment)
11649 vhdl-subprog-flattened nil)))))
11650
11651 (defun vhdl-subprog-paste-specification (kind)
11652 "Paste as a subprogram specification."
11653 (indent-according-to-mode)
11654 (let ((margin (current-column))
11655 (param-list (nth 2 vhdl-subprog-list))
11656 list-margin start names param)
11657 ;; paste keyword and name
11658 (vhdl-insert-keyword
11659 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11660 (insert (nth 0 vhdl-subprog-list))
11661 (if (not param-list)
11662 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11663 (setq start (point))
11664 ;; paste parameter list
11665 (insert " (")
11666 (unless vhdl-argument-list-indent
11667 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11668 (setq list-margin (current-column))
11669 (while param-list
11670 (setq param (car param-list))
11671 ;; paste group comment and spacing
11672 (when (memq vhdl-include-group-comments (list kind 'always))
11673 (vhdl-paste-group-comment (nth 6 param) list-margin))
11674 ;; paste object
11675 (when (nth 1 param) (insert (nth 1 param) " "))
11676 ;; paste names
11677 (setq names (nth 0 param))
11678 (while names
11679 (insert (car names))
11680 (setq names (cdr names))
11681 (when names (insert ", ")))
11682 ;; paste direction
11683 (insert " : ")
11684 (when (nth 2 param) (insert (nth 2 param) " "))
11685 ;; paste type
11686 (insert (nth 3 param))
11687 ;; paste initialization
11688 (when (nth 4 param) (insert " := " (nth 4 param)))
11689 ;; terminate line
11690 (if (cdr param-list)
11691 (insert ";")
11692 (insert ")")
11693 (when (null (nth 3 vhdl-subprog-list))
11694 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11695 ;; paste comment
11696 (when (and vhdl-include-port-comments (nth 5 param))
11697 (vhdl-comment-insert-inline (nth 5 param) t))
11698 (setq param-list (cdr param-list))
11699 (when param-list (insert "\n") (indent-to list-margin)))
11700 (when (nth 3 vhdl-subprog-list)
11701 (insert "\n") (indent-to list-margin)
11702 ;; paste group comment and spacing
11703 (when (memq vhdl-include-group-comments (list kind 'always))
11704 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11705 ;; paste return type
11706 (insert "return " (nth 3 vhdl-subprog-list))
11707 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11708 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11709 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11710 ;; align parameter list
11711 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11712 ;; paste body
11713 (when (eq kind 'body)
11714 (insert "\n")
11715 (vhdl-template-begin-end
11716 (unless (vhdl-standard-p '87)
11717 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11718 (nth 0 vhdl-subprog-list) margin))))
11719
11720 (defun vhdl-subprog-paste-declaration ()
11721 "Paste as a subprogram declaration."
11722 (interactive)
11723 (if (not vhdl-subprog-list)
11724 (error "ERROR: No subprogram interface read")
11725 (message "Pasting interface as subprogram declaration \"%s\"..."
11726 (car vhdl-subprog-list))
11727 ;; paste specification
11728 (vhdl-subprog-paste-specification 'decl)
11729 (message "Pasting interface as subprogram declaration \"%s\"...done"
11730 (car vhdl-subprog-list))))
11731
11732 (defun vhdl-subprog-paste-body ()
11733 "Paste as a subprogram body."
11734 (interactive)
11735 (if (not vhdl-subprog-list)
11736 (error "ERROR: No subprogram interface read")
11737 (message "Pasting interface as subprogram body \"%s\"..."
11738 (car vhdl-subprog-list))
11739 ;; paste specification and body
11740 (vhdl-subprog-paste-specification 'body)
11741 (message "Pasting interface as subprogram body \"%s\"...done"
11742 (car vhdl-subprog-list))))
11743
11744 (defun vhdl-subprog-paste-call ()
11745 "Paste as a subprogram call."
11746 (interactive)
11747 (if (not vhdl-subprog-list)
11748 (error "ERROR: No subprogram interface read")
11749 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11750 param-list margin list-margin param start)
11751 ;; flatten local copy of interface list (must be flat for parameter mapping)
11752 (vhdl-subprog-flatten)
11753 (setq param-list (nth 2 vhdl-subprog-list))
11754 (indent-according-to-mode)
11755 (setq margin (current-indentation))
11756 (message "Pasting interface as subprogram call \"%s\"..."
11757 (car vhdl-subprog-list))
11758 ;; paste name
11759 (insert (nth 0 vhdl-subprog-list))
11760 (if (not param-list)
11761 (insert ";")
11762 (setq start (point))
11763 ;; paste parameter list
11764 (insert " (")
11765 (unless vhdl-argument-list-indent
11766 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11767 (setq list-margin (current-column))
11768 (while param-list
11769 (setq param (car param-list))
11770 ;; paste group comment and spacing
11771 (when (eq vhdl-include-group-comments 'always)
11772 (vhdl-paste-group-comment (nth 6 param) list-margin))
11773 ;; paste formal port
11774 (insert (car (nth 0 param)) " => ")
11775 (setq param-list (cdr param-list))
11776 (insert (if param-list "," ");"))
11777 ;; paste comment
11778 (when (and vhdl-include-port-comments (nth 5 param))
11779 (vhdl-comment-insert-inline (nth 5 param)))
11780 (when param-list (insert "\n") (indent-to list-margin)))
11781 ;; align parameter list
11782 (when vhdl-auto-align
11783 (vhdl-align-region-groups start (point) 1)))
11784 (message "Pasting interface as subprogram call \"%s\"...done"
11785 (car vhdl-subprog-list))
11786 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11787
11788
11789 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11790 ;;; Miscellaneous
11791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11792
11793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11794 ;; Hippie expand customization
11795
11796 (defvar vhdl-expand-upper-case nil)
11797
11798 (defun vhdl-try-expand-abbrev (old)
11799 "Try expanding abbreviations from `vhdl-abbrev-list'."
11800 (unless old
11801 (he-init-string (he-dabbrev-beg) (point))
11802 (setq he-expand-list
11803 (let ((abbrev-list vhdl-abbrev-list)
11804 (sel-abbrev-list '()))
11805 (while abbrev-list
11806 (when (or (not (stringp (car abbrev-list)))
11807 (string-match
11808 (concat "^" he-search-string) (car abbrev-list)))
11809 (setq sel-abbrev-list
11810 (cons (car abbrev-list) sel-abbrev-list)))
11811 (setq abbrev-list (cdr abbrev-list)))
11812 (nreverse sel-abbrev-list))))
11813 (while (and he-expand-list
11814 (or (not (stringp (car he-expand-list)))
11815 (he-string-member (car he-expand-list) he-tried-table t)))
11816 ; (equal (car he-expand-list) he-search-string)))
11817 (unless (stringp (car he-expand-list))
11818 (setq vhdl-expand-upper-case (car he-expand-list)))
11819 (setq he-expand-list (cdr he-expand-list)))
11820 (if (null he-expand-list)
11821 (progn (when old (he-reset-string))
11822 nil)
11823 (he-substitute-string
11824 (if vhdl-expand-upper-case
11825 (upcase (car he-expand-list))
11826 (car he-expand-list))
11827 t)
11828 (setq he-expand-list (cdr he-expand-list))
11829 t))
11830
11831 (defun vhdl-he-list-beg ()
11832 "Also looks at the word before `(' in order to better match parenthesized
11833 expressions (e.g. for index ranges of types and signals)."
11834 (save-excursion
11835 (condition-case ()
11836 (progn (backward-up-list 1)
11837 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11838 (error ()))
11839 (point)))
11840
11841 ;; override `he-list-beg' from `hippie-exp'
11842 (unless (and (boundp 'viper-mode) viper-mode)
11843 (defalias 'he-list-beg 'vhdl-he-list-beg))
11844
11845 ;; function for expanding abbrevs and dabbrevs
11846 (defun vhdl-expand-abbrev (arg))
11847 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
11848 '(try-expand-dabbrev
11849 try-expand-dabbrev-all-buffers
11850 vhdl-try-expand-abbrev)))
11851
11852 ;; function for expanding parenthesis
11853 (defun vhdl-expand-paren (arg))
11854 (fset 'vhdl-expand-paren (make-hippie-expand-function
11855 '(try-expand-list
11856 try-expand-list-all-buffers)))
11857
11858 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11859 ;; Case fixing
11860
11861 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11862 "Convert all words matching word-regexp in region to lower or upper case,
11863 depending on parameter upper-case."
11864 (let ((case-replace nil)
11865 (last-update 0))
11866 (vhdl-prepare-search-2
11867 (save-excursion
11868 (goto-char end)
11869 (setq end (point-marker))
11870 (goto-char beg)
11871 (while (re-search-forward word-regexp end t)
11872 (or (vhdl-in-literal)
11873 (if upper-case
11874 (upcase-word -1)
11875 (downcase-word -1)))
11876 (when (and count vhdl-progress-interval (not noninteractive)
11877 (< vhdl-progress-interval
11878 (- (nth 1 (current-time)) last-update)))
11879 (message "Fixing case... (%2d%s)"
11880 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11881 "%")
11882 (setq last-update (nth 1 (current-time)))))
11883 (goto-char end)))))
11884
11885 (defun vhdl-fix-case-region (beg end &optional arg)
11886 "Convert all VHDL words in region to lower or upper case, depending on
11887 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11888 (interactive "r\nP")
11889 (vhdl-fix-case-region-1
11890 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
11891 (vhdl-fix-case-region-1
11892 beg end vhdl-upper-case-types vhdl-types-regexp 1)
11893 (vhdl-fix-case-region-1
11894 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11895 (vhdl-fix-case-region-1
11896 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11897 (when vhdl-progress-interval (message "Fixing case...done")))
11898
11899 (defun vhdl-fix-case-buffer ()
11900 "Convert all VHDL words in buffer to lower or upper case, depending on
11901 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11902 (interactive)
11903 (vhdl-fix-case-region (point-min) (point-max)))
11904
11905 (defun vhdl-fix-case-word (&optional arg)
11906 "Convert word after cursor to upper case if necessary."
11907 (interactive "p")
11908 (save-excursion
11909 (when arg (backward-word 1))
11910 (vhdl-prepare-search-1
11911 (when (and vhdl-upper-case-keywords
11912 (looking-at vhdl-keywords-regexp))
11913 (upcase-word 1))
11914 (when (and vhdl-upper-case-types
11915 (looking-at vhdl-types-regexp))
11916 (upcase-word 1))
11917 (when (and vhdl-upper-case-attributes
11918 (looking-at vhdl-attributes-regexp))
11919 (upcase-word 1))
11920 (when (and vhdl-upper-case-enum-values
11921 (looking-at vhdl-enum-values-regexp))
11922 (upcase-word 1)))))
11923
11924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11925 ;; Line handling functions
11926
11927 (defun vhdl-current-line ()
11928 "Return the line number of the line containing point."
11929 (save-restriction
11930 (widen)
11931 (1+ (count-lines (point-min) (line-beginning-position)))))
11932
11933 (defun vhdl-line-kill-entire (&optional arg)
11934 "Delete entire line."
11935 (interactive "p")
11936 (beginning-of-line)
11937 (kill-line (or arg 1)))
11938
11939 (defun vhdl-line-kill (&optional arg)
11940 "Kill current line."
11941 (interactive "p")
11942 (vhdl-line-kill-entire arg))
11943
11944 (defun vhdl-line-copy (&optional arg)
11945 "Copy current line."
11946 (interactive "p")
11947 (save-excursion
11948 (beginning-of-line)
11949 (let ((position (point)))
11950 (forward-line (or arg 1))
11951 (copy-region-as-kill position (point)))))
11952
11953 (defun vhdl-line-yank ()
11954 "Yank entire line."
11955 (interactive)
11956 (beginning-of-line)
11957 (yank))
11958
11959 (defun vhdl-line-expand (&optional prefix-arg)
11960 "Hippie-expand current line."
11961 (interactive "P")
11962 (let ((case-fold-search t) (case-replace nil)
11963 (hippie-expand-try-functions-list
11964 '(try-expand-line try-expand-line-all-buffers)))
11965 (hippie-expand prefix-arg)))
11966
11967 (defun vhdl-line-transpose-next (&optional arg)
11968 "Interchange this line with next line."
11969 (interactive "p")
11970 (forward-line 1)
11971 (transpose-lines (or arg 1))
11972 (forward-line -1))
11973
11974 (defun vhdl-line-transpose-previous (&optional arg)
11975 "Interchange this line with previous line."
11976 (interactive "p")
11977 (forward-line 1)
11978 (transpose-lines (- 0 (or arg 0)))
11979 (forward-line -1))
11980
11981 (defun vhdl-line-open ()
11982 "Open a new line and indent."
11983 (interactive)
11984 (end-of-line -0)
11985 (newline-and-indent))
11986
11987 (defun vhdl-delete-indentation ()
11988 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11989 it works within comments too."
11990 (interactive)
11991 (let ((fill-prefix "-- "))
11992 (delete-indentation)))
11993
11994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11995 ;; Move functions
11996
11997 (defun vhdl-forward-same-indent ()
11998 "Move forward to next line with same indent."
11999 (interactive)
12000 (let ((pos (point))
12001 (indent (current-indentation)))
12002 (beginning-of-line 2)
12003 (while (and (not (eobp))
12004 (or (looking-at "^\\s-*\\(--.*\\)?$")
12005 (> (current-indentation) indent)))
12006 (beginning-of-line 2))
12007 (if (= (current-indentation) indent)
12008 (back-to-indentation)
12009 (message "No following line with same indent found in this block")
12010 (goto-char pos)
12011 nil)))
12012
12013 (defun vhdl-backward-same-indent ()
12014 "Move backward to previous line with same indent."
12015 (interactive)
12016 (let ((pos (point))
12017 (indent (current-indentation)))
12018 (beginning-of-line -0)
12019 (while (and (not (bobp))
12020 (or (looking-at "^\\s-*\\(--.*\\)?$")
12021 (> (current-indentation) indent)))
12022 (beginning-of-line -0))
12023 (if (= (current-indentation) indent)
12024 (back-to-indentation)
12025 (message "No preceding line with same indent found in this block")
12026 (goto-char pos)
12027 nil)))
12028
12029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12030 ;; Statistics
12031
12032 (defun vhdl-statistics-buffer ()
12033 "Get some file statistics."
12034 (interactive)
12035 (let ((no-stats 0)
12036 (no-code-lines 0)
12037 (no-lines (count-lines (point-min) (point-max))))
12038 (save-excursion
12039 ;; count statements
12040 (goto-char (point-min))
12041 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12042 (if (match-string 1)
12043 (goto-char (match-end 1))
12044 (setq no-stats (1+ no-stats))))
12045 ;; count code lines
12046 (goto-char (point-min))
12047 (while (not (eobp))
12048 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12049 (setq no-code-lines (1+ no-code-lines)))
12050 (beginning-of-line 2)))
12051 ;; print results
12052 (message "\n\
12053 File statistics: \"%s\"\n\
12054 ---------------------\n\
12055 # statements : %5d\n\
12056 # code lines : %5d\n\
12057 # total lines : %5d\n\ "
12058 (buffer-file-name) no-stats no-code-lines no-lines)
12059 (unless vhdl-emacs-21 (vhdl-show-messages))))
12060
12061 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12062 ;; Help functions
12063
12064 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12065 "Like `re-search-forward', but does not match within literals."
12066 (let (pos)
12067 (save-excursion
12068 (while (and (setq pos (re-search-forward regexp bound noerror count))
12069 (vhdl-in-literal))))
12070 (when pos (goto-char pos))
12071 pos))
12072
12073 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12074 "Like `re-search-backward', but does not match within literals."
12075 (let (pos)
12076 (save-excursion
12077 (while (and (setq pos (re-search-backward regexp bound noerror count))
12078 (vhdl-in-literal))))
12079 (when pos (goto-char pos))
12080 pos))
12081
12082
12083 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12084 ;;; Project
12085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12086
12087 (defun vhdl-set-project (name)
12088 "Set current project to NAME."
12089 (interactive
12090 (list (let ((completion-ignore-case t))
12091 (completing-read "Project name: " vhdl-project-alist nil t))))
12092 (cond ((equal name "")
12093 (setq vhdl-project nil)
12094 (message "Current VHDL project: None"))
12095 ((assoc name vhdl-project-alist)
12096 (setq vhdl-project name)
12097 (message "Current VHDL project: \"%s\"" name))
12098 (t
12099 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12100 (vhdl-speedbar-update-current-project))
12101
12102 (defun vhdl-toggle-project (name token indent)
12103 "Set current project to NAME or unset if NAME is current project."
12104 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12105
12106 (defun vhdl-export-project (file-name)
12107 "Write project setup for current project."
12108 (interactive
12109 (let ((name (vhdl-resolve-env-variable
12110 (vhdl-replace-string
12111 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12112 (concat (subst-char-in-string
12113 ? ?_ (or (vhdl-project-p)
12114 (error "ERROR: No current project")))
12115 " " (user-login-name))))))
12116 (list (read-file-name
12117 "Write project file: "
12118 (when (file-name-absolute-p name) "") nil nil name))))
12119 (setq file-name (abbreviate-file-name file-name))
12120 (let ((orig-buffer (current-buffer)))
12121 (unless (file-exists-p (file-name-directory file-name))
12122 (make-directory (file-name-directory file-name) t))
12123 (if (not (file-writable-p file-name))
12124 (error "ERROR: File not writable: \"%s\"" file-name)
12125 (set-buffer (find-file-noselect file-name t t))
12126 (erase-buffer)
12127 (insert ";; -*- Emacs-Lisp -*-\n\n"
12128 ";;; " (file-name-nondirectory file-name)
12129 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12130 ";; Project : " vhdl-project "\n"
12131 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12132 (user-login-name) "\n\n\n"
12133 ";; project name\n"
12134 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12135 ";; project setup\n"
12136 "(aput 'vhdl-project-alist vhdl-project\n'")
12137 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12138 (insert ")\n")
12139 (save-buffer)
12140 (kill-buffer (current-buffer))
12141 (set-buffer orig-buffer))))
12142
12143 (defun vhdl-import-project (file-name &optional auto not-make-current)
12144 "Read project setup and set current project."
12145 (interactive
12146 (let ((name (vhdl-resolve-env-variable
12147 (vhdl-replace-string
12148 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12149 (concat "" " " (user-login-name))))))
12150 (list (read-file-name
12151 "Read project file: " (when (file-name-absolute-p name) "") nil t
12152 (file-name-directory name)))))
12153 (when (file-exists-p file-name)
12154 (condition-case ()
12155 (let ((current-project vhdl-project))
12156 (load-file file-name)
12157 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12158 (adelete 'vhdl-project-alist vhdl-project)
12159 (error))
12160 (when not-make-current
12161 (setq vhdl-project current-project))
12162 (vhdl-update-mode-menu)
12163 (vhdl-speedbar-refresh)
12164 (unless not-make-current
12165 (message "Current VHDL project: \"%s\"%s"
12166 vhdl-project (if auto " (auto-loaded)" ""))))
12167 (error (vhdl-warning
12168 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12169
12170 (defun vhdl-duplicate-project ()
12171 "Duplicate setup of current project."
12172 (interactive)
12173 (let ((new-name (read-from-minibuffer "New project name: "))
12174 (project-entry (aget vhdl-project-alist vhdl-project t)))
12175 (setq vhdl-project-alist
12176 (append vhdl-project-alist
12177 (list (cons new-name project-entry))))
12178 (vhdl-update-mode-menu)))
12179
12180 (defun vhdl-auto-load-project ()
12181 "Automatically load project setup at startup."
12182 (let ((file-name-list vhdl-project-file-name)
12183 file-list list-length)
12184 (while file-name-list
12185 (setq file-list
12186 (append file-list
12187 (file-expand-wildcards
12188 (vhdl-resolve-env-variable
12189 (vhdl-replace-string
12190 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12191 (concat "\*" " " (user-login-name)))))))
12192 (setq list-length (or list-length (length file-list)))
12193 (setq file-name-list (cdr file-name-list)))
12194 (while file-list
12195 (vhdl-import-project (expand-file-name (car file-list)) t
12196 (not (> list-length 0)))
12197 (setq list-length (1- list-length))
12198 (setq file-list (cdr file-list)))))
12199
12200 ;; automatically load project setup when idle after startup
12201 (when (memq 'startup vhdl-project-auto-load)
12202 (if noninteractive
12203 (vhdl-auto-load-project)
12204 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12205
12206
12207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12208 ;;; Hideshow
12209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12210 ;; (using `hideshow.el')
12211
12212 (defconst vhdl-hs-start-regexp
12213 (concat
12214 "\\(^\\)\\s-*\\("
12215 ;; generic/port clause
12216 "\\(generic\\|port\\)[ \t\n]*(\\|"
12217 ;; component
12218 "component\\>\\|"
12219 ;; component instantiation
12220 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12221 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12222 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12223 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12224 ;; subprogram
12225 "\\(function\\|procedure\\)\\>\\|"
12226 ;; process, block
12227 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12228 ;; configuration declaration
12229 "configuration\\>"
12230 "\\)")
12231 "Regexp to match start of construct to hide.")
12232
12233 (defun vhdl-hs-forward-sexp-func (count)
12234 "Find end of construct to hide (for hideshow). Only searches forward."
12235 (let ((pos (point)))
12236 (vhdl-prepare-search-2
12237 (beginning-of-line)
12238 (cond
12239 ;; generic/port clause
12240 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12241 (goto-char (match-end 0))
12242 (backward-char)
12243 (forward-sexp))
12244 ;; component declaration
12245 ((looking-at "^\\s-*component\\>")
12246 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12247 ;; component instantiation
12248 ((looking-at
12249 (concat
12250 "^\\s-*\\w+\\s-*:[ \t\n]*"
12251 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12252 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12253 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12254 (goto-char (match-end 0))
12255 (backward-char)
12256 (forward-sexp)
12257 (setq pos (point))
12258 (vhdl-forward-syntactic-ws)
12259 (when (looking-at "port\\s-+map[ \t\n]*(")
12260 (goto-char (match-end 0))
12261 (backward-char)
12262 (forward-sexp)
12263 (setq pos (point)))
12264 (goto-char pos))
12265 ;; subprogram declaration/body
12266 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12267 (goto-char (match-end 0))
12268 (vhdl-forward-syntactic-ws)
12269 (when (looking-at "(")
12270 (forward-sexp))
12271 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12272 (vhdl-in-literal)))
12273 ;; subprogram body
12274 (when (match-string 2)
12275 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12276 (backward-word 1)
12277 (vhdl-forward-sexp)))
12278 ;; block (recursive)
12279 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12280 (goto-char (match-end 0))
12281 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12282 (match-beginning 2))
12283 (vhdl-hs-forward-sexp-func count)))
12284 ;; process
12285 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12286 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12287 ;; configuration declaration
12288 ((looking-at "^\\s-*configuration\\>")
12289 (forward-word 4)
12290 (vhdl-forward-sexp))
12291 (t (goto-char pos))))))
12292
12293 (defun vhdl-hideshow-init ()
12294 "Initialize `hideshow'."
12295 (when vhdl-hideshow-menu
12296 (vhdl-hs-minor-mode 1)))
12297
12298 (defun vhdl-hs-minor-mode (&optional arg)
12299 "Toggle hideshow minor mode and update menu bar."
12300 (interactive "P")
12301 (require 'hideshow)
12302 ;; check for hideshow version 5.x
12303 (if (not (boundp 'hs-block-start-mdata-select))
12304 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12305 ;; initialize hideshow
12306 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12307 (setq hs-special-modes-alist
12308 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12309 'vhdl-hs-forward-sexp-func nil)
12310 hs-special-modes-alist)))
12311 (make-local-variable 'hs-minor-mode-hook)
12312 (if vhdl-hide-all-init
12313 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12314 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12315 (hs-minor-mode arg)
12316 (vhdl-mode-line-update))) ; hack to update menu bar
12317
12318
12319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12320 ;;; Font locking
12321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12322 ;; (using `font-lock.el')
12323
12324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12325 ;; Help functions
12326
12327 (defun vhdl-within-translate-off ()
12328 "Return point if within translate-off region, else nil."
12329 (and (save-excursion
12330 (re-search-backward
12331 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12332 (equal "off" (match-string 1))
12333 (point)))
12334
12335 (defun vhdl-start-translate-off (limit)
12336 "Return point before translate-off pragma if before LIMIT, else nil."
12337 (when (re-search-forward
12338 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12339 (match-beginning 0)))
12340
12341 (defun vhdl-end-translate-off (limit)
12342 "Return point after translate-on pragma if before LIMIT, else nil."
12343 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12344
12345 (defun vhdl-match-translate-off (limit)
12346 "Match a translate-off block, setting match-data and returning t, else nil."
12347 (when (< (point) limit)
12348 (let ((start (or (vhdl-within-translate-off)
12349 (vhdl-start-translate-off limit)))
12350 (case-fold-search t))
12351 (when start
12352 (let ((end (or (vhdl-end-translate-off limit) limit)))
12353 (set-match-data (list start end))
12354 (goto-char end))))))
12355
12356 (defun vhdl-font-lock-match-item (limit)
12357 "Match, and move over, any declaration item after point. Adapted from
12358 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12359 (condition-case nil
12360 (save-restriction
12361 (narrow-to-region (point-min) limit)
12362 ;; match item
12363 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12364 (save-match-data
12365 (goto-char (match-end 1))
12366 ;; move to next item
12367 (if (looking-at "\\(\\s-*,\\)")
12368 (goto-char (match-end 1))
12369 (end-of-line) t))))
12370 (error t)))
12371
12372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12373 ;; Syntax definitions
12374
12375 (defconst vhdl-font-lock-syntactic-keywords
12376 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12377 "Mark single quotes as having string quote syntax in 'c' instances.")
12378
12379 (defvar vhdl-font-lock-keywords nil
12380 "Regular expressions to highlight in VHDL Mode.")
12381
12382 (defvar vhdl-font-lock-keywords-0
12383 ;; set in `vhdl-font-lock-init' because dependent on user options
12384 "For consideration as a value of `vhdl-font-lock-keywords'.
12385 This does highlighting of template prompts and directives (pragmas).")
12386
12387 (defvar vhdl-font-lock-keywords-1 nil
12388 ;; set in `vhdl-font-lock-init' because dependent on user options
12389 "For consideration as a value of `vhdl-font-lock-keywords'.
12390 This does highlighting of keywords and standard identifiers.")
12391
12392 (defconst vhdl-font-lock-keywords-2
12393 (list
12394 ;; highlight names of units, subprograms, and components when declared
12395 (list
12396 (concat
12397 "^\\s-*\\("
12398 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12399 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12400 "\\)\\s-+\\(\\w+\\)")
12401 5 'font-lock-function-name-face)
12402
12403 ;; highlight entity names of architectures and configurations
12404 (list
12405 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12406 2 'font-lock-function-name-face)
12407
12408 ;; highlight labels of common constructs
12409 (list
12410 (concat
12411 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12412 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12413 "postponed\\|process\\|"
12414 (when (vhdl-standard-p 'ams) "procedural\\|")
12415 "with\\|while"
12416 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
12417 1 'font-lock-function-name-face)
12418
12419 ;; highlight label and component name of component instantiations
12420 (list
12421 (concat
12422 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12423 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12424 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12425
12426 ;; highlight label and instantiated unit of component instantiations
12427 (list
12428 (concat
12429 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12430 "\\(component\\|configuration\\|entity\\)\\s-+"
12431 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12432 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12433 '(5 font-lock-function-name-face nil t)
12434 '(7 font-lock-function-name-face nil t))
12435
12436 ;; highlight names and labels at end of constructs
12437 (list
12438 (concat
12439 "^\\s-*end\\s-+\\(\\("
12440 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12441 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12442 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12443 (when (vhdl-standard-p 'ams) "procedural\\|")
12444 "units"
12445 "\\)\\s-+\\)?\\(\\w*\\)")
12446 5 'font-lock-function-name-face)
12447
12448 ;; highlight labels in exit and next statements
12449 (list
12450 (concat
12451 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12452 3 'font-lock-function-name-face)
12453
12454 ;; highlight entity name in attribute specifications
12455 (list
12456 (concat
12457 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12458 1 'font-lock-function-name-face)
12459
12460 ;; highlight labels in block and component specifications
12461 (list
12462 (concat
12463 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12464 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12465 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12466
12467 ;; highlight names in library clauses
12468 (list "^\\s-*library\\>"
12469 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12470
12471 ;; highlight names in use clauses
12472 (list
12473 (concat
12474 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12475 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12476 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12477 '(7 font-lock-function-name-face nil t))
12478
12479 ;; highlight attribute name in attribute declarations/specifications
12480 (list
12481 (concat
12482 "^\\s-*attribute\\s-+\\(\\w+\\)")
12483 1 'vhdl-font-lock-attribute-face)
12484
12485 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12486 (list
12487 (concat
12488 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12489 3 'font-lock-type-face)
12490
12491 ;; highlight signal/variable/constant declaration names
12492 (list "\\(:[^=]\\)"
12493 '(vhdl-font-lock-match-item
12494 (progn (goto-char (match-beginning 1))
12495 (skip-syntax-backward " ")
12496 (skip-syntax-backward "w_")
12497 (skip-syntax-backward " ")
12498 (while (= (preceding-char) ?,)
12499 (backward-char 1)
12500 (skip-syntax-backward " ")
12501 (skip-syntax-backward "w_")
12502 (skip-syntax-backward " ")))
12503 ; (skip-chars-backward "^-(\n\";")
12504 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12505
12506 ;; highlight formal parameters in component instantiations and subprogram
12507 ;; calls
12508 (list "\\(=>\\)"
12509 '(vhdl-font-lock-match-item
12510 (progn (goto-char (match-beginning 1))
12511 (skip-syntax-backward " ")
12512 (while (= (preceding-char) ?\)) (backward-sexp))
12513 (skip-syntax-backward "w_")
12514 (skip-syntax-backward " ")
12515 (when (memq (preceding-char) '(?n ?N))
12516 (goto-char (point-max))))
12517 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12518
12519 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12520 ;; variables
12521 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12522 '(vhdl-font-lock-match-item
12523 (progn (goto-char (match-end 1)) (match-beginning 2))
12524 nil (1 font-lock-variable-name-face)))
12525 )
12526 "For consideration as a value of `vhdl-font-lock-keywords'.
12527 This does context sensitive highlighting of names and labels.")
12528
12529 (defvar vhdl-font-lock-keywords-3 nil
12530 ;; set in `vhdl-font-lock-init' because dependent on user options
12531 "For consideration as a value of `vhdl-font-lock-keywords'.
12532 This does highlighting of words with special syntax.")
12533
12534 (defvar vhdl-font-lock-keywords-4 nil
12535 ;; set in `vhdl-font-lock-init' because dependent on user options
12536 "For consideration as a value of `vhdl-font-lock-keywords'.
12537 This does highlighting of additional reserved words.")
12538
12539 (defconst vhdl-font-lock-keywords-5
12540 ;; background highlight translate-off regions
12541 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12542 "For consideration as a value of `vhdl-font-lock-keywords'.
12543 This does background highlighting of translate-off regions.")
12544
12545 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12546 ;; Font and color definitions
12547
12548 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12549 "Face name to use for prompts.")
12550
12551 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12552 "Face name to use for standardized attributes.")
12553
12554 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12555 "Face name to use for standardized enumeration values.")
12556
12557 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12558 "Face name to use for standardized functions and packages.")
12559
12560 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12561 "Face name to use for directives.")
12562
12563 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12564 "Face name to use for additional reserved words.")
12565
12566 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12567 "Face name to use for translate-off regions.")
12568
12569 ;; face names to use for words with special syntax.
12570 (let ((syntax-alist vhdl-special-syntax-alist)
12571 name)
12572 (while syntax-alist
12573 (setq name (vhdl-function-name
12574 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12575 (eval `(defvar ,name ',name
12576 ,(concat "Face name to use for "
12577 (nth 0 (car syntax-alist)) ".")))
12578 (setq syntax-alist (cdr syntax-alist))))
12579
12580 (defgroup vhdl-highlight-faces nil
12581 "Faces for highlighting."
12582 :group 'vhdl-highlight)
12583
12584 ;; add faces used from `font-lock'
12585 (custom-add-to-group
12586 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12587 (custom-add-to-group
12588 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12589 (custom-add-to-group
12590 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12591 (custom-add-to-group
12592 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12593 (custom-add-to-group
12594 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12595 (custom-add-to-group
12596 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12597
12598 (defface vhdl-font-lock-prompt-face
12599 '((((min-colors 88) (class color) (background light))
12600 (:foreground "Red1" :bold t))
12601 (((class color) (background light)) (:foreground "Red" :bold t))
12602 (((class color) (background dark)) (:foreground "Pink" :bold t))
12603 (t (:inverse-video t)))
12604 "Font lock mode face used to highlight prompts."
12605 :group 'vhdl-highlight-faces
12606 :group 'font-lock-highlighting-faces)
12607
12608 (defface vhdl-font-lock-attribute-face
12609 '((((class color) (background light)) (:foreground "Orchid"))
12610 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12611 (t (:italic t :bold t)))
12612 "Font lock mode face used to highlight standardized attributes."
12613 :group 'vhdl-highlight-faces
12614 :group 'font-lock-highlighting-faces)
12615
12616 (defface vhdl-font-lock-enumvalue-face
12617 '((((class color) (background light)) (:foreground "SaddleBrown"))
12618 (((class color) (background dark)) (:foreground "BurlyWood"))
12619 (t (:italic t :bold t)))
12620 "Font lock mode face used to highlight standardized enumeration values."
12621 :group 'vhdl-highlight-faces
12622 :group 'font-lock-highlighting-faces)
12623
12624 (defface vhdl-font-lock-function-face
12625 '((((class color) (background light)) (:foreground "Cyan4"))
12626 (((class color) (background dark)) (:foreground "Orchid1"))
12627 (t (:italic t :bold t)))
12628 "Font lock mode face used to highlight standardized functions and packages."
12629 :group 'vhdl-highlight-faces
12630 :group 'font-lock-highlighting-faces)
12631
12632 (defface vhdl-font-lock-directive-face
12633 '((((class color) (background light)) (:foreground "CadetBlue"))
12634 (((class color) (background dark)) (:foreground "Aquamarine"))
12635 (t (:italic t :bold t)))
12636 "Font lock mode face used to highlight directives."
12637 :group 'vhdl-highlight-faces
12638 :group 'font-lock-highlighting-faces)
12639
12640 (defface vhdl-font-lock-reserved-words-face
12641 '((((class color) (background light)) (:foreground "Orange" :bold t))
12642 (((min-colors 88) (class color) (background dark))
12643 (:foreground "Yellow1" :bold t))
12644 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12645 (t ()))
12646 "Font lock mode face used to highlight additional reserved words."
12647 :group 'vhdl-highlight-faces
12648 :group 'font-lock-highlighting-faces)
12649
12650 (defface vhdl-font-lock-translate-off-face
12651 '((((class color) (background light)) (:background "LightGray"))
12652 (((class color) (background dark)) (:background "DimGray"))
12653 (t ()))
12654 "Font lock mode face used to background highlight translate-off regions."
12655 :group 'vhdl-highlight-faces
12656 :group 'font-lock-highlighting-faces)
12657
12658 ;; font lock mode faces used to highlight words with special syntax.
12659 (let ((syntax-alist vhdl-special-syntax-alist))
12660 (while syntax-alist
12661 (eval `(defface ,(vhdl-function-name
12662 "vhdl-font-lock" (caar syntax-alist) "face")
12663 '((((class color) (background light))
12664 (:foreground ,(nth 2 (car syntax-alist))))
12665 (((class color) (background dark))
12666 (:foreground ,(nth 3 (car syntax-alist))))
12667 (t ()))
12668 ,(concat "Font lock mode face used to highlight "
12669 (nth 0 (car syntax-alist)) ".")
12670 :group 'vhdl-highlight-faces
12671 :group 'font-lock-highlighting-faces))
12672 (setq syntax-alist (cdr syntax-alist))))
12673
12674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12675 ;; Font lock initialization
12676
12677 (defun vhdl-font-lock-init ()
12678 "Initialize fontification."
12679 ;; highlight template prompts and directives
12680 (setq vhdl-font-lock-keywords-0
12681 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12682 vhdl-template-prompt-syntax ">\\)")
12683 2 'vhdl-font-lock-prompt-face t)
12684 (list (concat "--\\s-*"
12685 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12686 2 'vhdl-font-lock-directive-face t)))
12687 ;; highlight keywords and standardized types, attributes, enumeration
12688 ;; values, and subprograms
12689 (setq vhdl-font-lock-keywords-1
12690 (list
12691 (list (concat "'" vhdl-attributes-regexp)
12692 1 'vhdl-font-lock-attribute-face)
12693 (list vhdl-types-regexp 1 'font-lock-type-face)
12694 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12695 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12696 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12697 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12698 ;; highlight words with special syntax.
12699 (setq vhdl-font-lock-keywords-3
12700 (let ((syntax-alist vhdl-special-syntax-alist)
12701 keywords)
12702 (while syntax-alist
12703 (setq keywords
12704 (cons
12705 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12706 (vhdl-function-name
12707 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12708 keywords))
12709 (setq syntax-alist (cdr syntax-alist)))
12710 keywords))
12711 ;; highlight additional reserved words
12712 (setq vhdl-font-lock-keywords-4
12713 (list (list vhdl-reserved-words-regexp 1
12714 'vhdl-font-lock-reserved-words-face)))
12715 ;; highlight everything together
12716 (setq vhdl-font-lock-keywords
12717 (append
12718 vhdl-font-lock-keywords-0
12719 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12720 (when (or vhdl-highlight-forbidden-words
12721 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12722 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12723 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12724 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12725
12726 ;; initialize fontification for VHDL Mode
12727 (vhdl-font-lock-init)
12728
12729 (defun vhdl-fontify-buffer ()
12730 "Re-initialize fontification and fontify buffer."
12731 (interactive)
12732 (setq font-lock-defaults
12733 (list
12734 'vhdl-font-lock-keywords nil
12735 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12736 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12737 (when (fboundp 'font-lock-unset-defaults)
12738 (font-lock-unset-defaults)) ; not implemented in XEmacs
12739 (font-lock-set-defaults)
12740 (font-lock-mode nil)
12741 (font-lock-mode t))
12742
12743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12744 ;; Initialization for postscript printing
12745
12746 (defun vhdl-ps-print-settings ()
12747 "Initialize custom face and page settings for postscript printing."
12748 ;; define custom face settings
12749 (unless (or (not vhdl-print-customize-faces)
12750 ps-print-color-p)
12751 (set (make-local-variable 'ps-bold-faces)
12752 '(font-lock-keyword-face
12753 font-lock-type-face
12754 vhdl-font-lock-attribute-face
12755 vhdl-font-lock-enumvalue-face
12756 vhdl-font-lock-directive-face))
12757 (set (make-local-variable 'ps-italic-faces)
12758 '(font-lock-comment-face
12759 font-lock-function-name-face
12760 font-lock-type-face
12761 vhdl-font-lock-attribute-face
12762 vhdl-font-lock-enumvalue-face
12763 vhdl-font-lock-directive-face))
12764 (set (make-local-variable 'ps-underlined-faces)
12765 '(font-lock-string-face))
12766 (setq ps-always-build-face-reference t))
12767 ;; define page settings, so that a line containing 79 characters (default)
12768 ;; fits into one column
12769 (when vhdl-print-two-column
12770 (set (make-local-variable 'ps-landscape-mode) t)
12771 (set (make-local-variable 'ps-number-of-columns) 2)
12772 (set (make-local-variable 'ps-font-size) 7.0)
12773 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12774 (set (make-local-variable 'ps-header-font-size) 9.0)
12775 (set (make-local-variable 'ps-header-offset) 12.0)
12776 (when (eq ps-paper-type 'letter)
12777 (set (make-local-variable 'ps-inter-column) 40.0)
12778 (set (make-local-variable 'ps-left-margin) 40.0)
12779 (set (make-local-variable 'ps-right-margin) 40.0))))
12780
12781 (defun vhdl-ps-print-init ()
12782 "Initialize postscript printing."
12783 (if vhdl-xemacs
12784 (when (boundp 'ps-print-color-p)
12785 (vhdl-ps-print-settings))
12786 (make-local-variable 'ps-print-hook)
12787 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12788
12789
12790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12791 ;;; Hierarchy browser (using `speedbar.el')
12792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12793 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12794 ;; directory by using the speedbar.
12795
12796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12797 ;; Variables
12798
12799 (defvar vhdl-entity-alist nil
12800 "Cache with entities and corresponding architectures for each
12801 project/directory.")
12802 ;; structure: (parenthesised expression means list of such entries)
12803 ;; (cache-key
12804 ;; (ent-key ent-name ent-file ent-line
12805 ;; (arch-key arch-name arch-file arch-line
12806 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12807 ;; inst-arch-key inst-conf-key inst-lib-key)
12808 ;; (lib-name pack-key))
12809 ;; (lib-name pack-key))
12810
12811 (defvar vhdl-config-alist nil
12812 "Cache with configurations for each project/directory.")
12813 ;; structure: (parenthesised expression means list of such entries)
12814 ;; (cache-key
12815 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12816 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12817 ;; inst-conf-key inst-lib-key)
12818 ;; (lib-name pack-key)))
12819
12820 (defvar vhdl-package-alist nil
12821 "Cache with packages for each project/directory.")
12822 ;; structure: (parenthesised expression means list of such entries)
12823 ;; (cache-key
12824 ;; (pack-key pack-name pack-file pack-line
12825 ;; (comp-key comp-name comp-file comp-line)
12826 ;; (func-key func-name func-file func-line)
12827 ;; (lib-name pack-key)
12828 ;; pack-body-file pack-body-line
12829 ;; (func-key func-name func-body-file func-body-line)
12830 ;; (lib-name pack-key)))
12831
12832 (defvar vhdl-ent-inst-alist nil
12833 "Cache with instantiated entities for each project/directory.")
12834 ;; structure: (parenthesised expression means list of such entries)
12835 ;; (cache-key (inst-ent-key))
12836
12837 (defvar vhdl-file-alist nil
12838 "Cache with design units in each file for each project/directory.")
12839 ;; structure: (parenthesised expression means list of such entries)
12840 ;; (cache-key
12841 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12842 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
12843
12844 (defvar vhdl-directory-alist nil
12845 "Cache with source directories for each project.")
12846 ;; structure: (parenthesised expression means list of such entries)
12847 ;; (cache-key (directory))
12848
12849 (defvar vhdl-speedbar-shown-unit-alist nil
12850 "Alist of design units simultaneously open in the current speedbar for each
12851 directory and project.")
12852
12853 (defvar vhdl-speedbar-shown-project-list nil
12854 "List of projects simultaneously open in the current speedbar.")
12855
12856 (defvar vhdl-updated-project-list nil
12857 "List of projects and directories with updated files.")
12858
12859 (defvar vhdl-modified-file-list nil
12860 "List of modified files to be rescanned for hierarchy updating.")
12861
12862 (defvar vhdl-speedbar-hierarchy-depth 0
12863 "Depth of instantiation hierarchy to display.")
12864
12865 (defvar vhdl-speedbar-show-projects nil
12866 "Non-nil means project hierarchy is displayed in speedbar, directory
12867 hierarchy otherwise.")
12868
12869 (defun vhdl-get-end-of-unit ()
12870 "Return position of end of current unit."
12871 (let ((pos (point)))
12872 (save-excursion
12873 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12874 (save-excursion
12875 (goto-char (match-beginning 0))
12876 (vhdl-backward-syntactic-ws)
12877 (and (/= (preceding-char) ?\;) (not (bobp))))))
12878 (re-search-backward "^[ \t]*end\\>" pos 1)
12879 (point))))
12880
12881 (defun vhdl-match-string-downcase (num &optional string)
12882 "Like `match-string-no-properties' with down-casing."
12883 (let ((match (match-string-no-properties num string)))
12884 (and match (downcase match))))
12885
12886
12887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12888 ;; Scan functions
12889
12890 (defun vhdl-scan-context-clause ()
12891 "Scan the context clause that preceeds a design unit."
12892 (let (lib-alist)
12893 (save-excursion
12894 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12895 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12896 (equal "USE" (upcase (match-string 1))))
12897 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12898 (setq lib-alist (cons (cons (match-string-no-properties 1)
12899 (vhdl-match-string-downcase 2))
12900 lib-alist))))))
12901 lib-alist))
12902
12903 (defun vhdl-scan-directory-contents (name &optional project update num-string
12904 non-final)
12905 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12906 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
12907 ; (unless (file-directory-p (match-string 1 name))
12908 ; (message "No such directory: \"%s\"" (match-string 1 name)))
12909 (let* ((dir-name (match-string 1 name))
12910 (file-pattern (match-string 2 name))
12911 (is-directory (= 0 (length file-pattern)))
12912 (file-list
12913 (if update
12914 (list name)
12915 (if is-directory
12916 (vhdl-get-source-files t dir-name)
12917 (vhdl-directory-files
12918 dir-name t (wildcard-to-regexp file-pattern)))))
12919 (key (or project dir-name))
12920 (file-exclude-regexp
12921 (or (nth 3 (aget vhdl-project-alist project)) ""))
12922 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12923 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12924 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12925 ent-alist conf-alist pack-alist ent-inst-list file-alist
12926 tmp-list tmp-entry no-files files-exist big-files)
12927 (when (or project update)
12928 (setq ent-alist (aget vhdl-entity-alist key t)
12929 conf-alist (aget vhdl-config-alist key t)
12930 pack-alist (aget vhdl-package-alist key t)
12931 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12932 file-alist (aget vhdl-file-alist key t)))
12933 (when (and (not is-directory) (null file-list))
12934 (message "No such file: \"%s\"" name))
12935 (setq files-exist file-list)
12936 (when file-list
12937 (setq no-files (length file-list))
12938 (message "Scanning %s %s\"%s\"..."
12939 (if is-directory "directory" "files") (or num-string "") name)
12940 ;; exclude files
12941 (unless (equal file-exclude-regexp "")
12942 (let ((case-fold-search nil)
12943 file-tmp-list)
12944 (while file-list
12945 (unless (string-match file-exclude-regexp (car file-list))
12946 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12947 (setq file-list (cdr file-list)))
12948 (setq file-list (nreverse file-tmp-list))))
12949 ;; do for all files
12950 (while file-list
12951 (unless noninteractive
12952 (message "Scanning %s %s\"%s\"... (%2d%s)"
12953 (if is-directory "directory" "files")
12954 (or num-string "") name
12955 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12956 (let ((file-name (abbreviate-file-name (car file-list)))
12957 ent-list arch-list arch-ent-list conf-list
12958 pack-list pack-body-list inst-list inst-ent-list)
12959 ;; scan file
12960 (vhdl-visit-file
12961 file-name nil
12962 (vhdl-prepare-search-2
12963 (save-excursion
12964 ;; scan for design units
12965 (if (and limit-design-file-size
12966 (< limit-design-file-size (buffer-size)))
12967 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12968 (setq big-files t))
12969 ;; scan for entities
12970 (goto-char (point-min))
12971 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12972 (let* ((ent-name (match-string-no-properties 1))
12973 (ent-key (downcase ent-name))
12974 (ent-entry (aget ent-alist ent-key t))
12975 (arch-alist (nth 3 ent-entry))
12976 (lib-alist (vhdl-scan-context-clause)))
12977 (if (nth 1 ent-entry)
12978 (vhdl-warning-when-idle
12979 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12980 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12981 file-name (vhdl-current-line))
12982 (setq ent-list (cons ent-key ent-list))
12983 (aput 'ent-alist ent-key
12984 (list ent-name file-name (vhdl-current-line)
12985 arch-alist lib-alist)))))
12986 ;; scan for architectures
12987 (goto-char (point-min))
12988 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12989 (let* ((arch-name (match-string-no-properties 1))
12990 (arch-key (downcase arch-name))
12991 (ent-name (match-string-no-properties 2))
12992 (ent-key (downcase ent-name))
12993 (ent-entry (aget ent-alist ent-key t))
12994 (arch-alist (nth 3 ent-entry))
12995 (arch-entry (aget arch-alist arch-key t))
12996 (lib-arch-alist (vhdl-scan-context-clause)))
12997 (if arch-entry
12998 (vhdl-warning-when-idle
12999 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13000 arch-name ent-name (nth 1 arch-entry)
13001 (nth 2 arch-entry) file-name (vhdl-current-line))
13002 (setq arch-list (cons arch-key arch-list)
13003 arch-ent-list (cons ent-key arch-ent-list))
13004 (aput 'arch-alist arch-key
13005 (list arch-name file-name (vhdl-current-line) nil
13006 lib-arch-alist))
13007 (aput 'ent-alist ent-key
13008 (list (or (nth 0 ent-entry) ent-name)
13009 (nth 1 ent-entry) (nth 2 ent-entry)
13010 (vhdl-sort-alist arch-alist)
13011 (nth 4 ent-entry))))))
13012 ;; scan for configurations
13013 (goto-char (point-min))
13014 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13015 (let* ((conf-name (match-string-no-properties 1))
13016 (conf-key (downcase conf-name))
13017 (conf-entry (aget conf-alist conf-key t))
13018 (ent-name (match-string-no-properties 2))
13019 (ent-key (downcase ent-name))
13020 (lib-alist (vhdl-scan-context-clause))
13021 (conf-line (vhdl-current-line))
13022 (end-of-unit (vhdl-get-end-of-unit))
13023 arch-key comp-conf-list inst-key-list
13024 inst-comp-key inst-ent-key inst-arch-key
13025 inst-conf-key inst-lib-key)
13026 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13027 (setq arch-key (vhdl-match-string-downcase 1)))
13028 (if conf-entry
13029 (vhdl-warning-when-idle
13030 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13031 conf-name ent-name (nth 1 conf-entry)
13032 (nth 2 conf-entry) file-name conf-line)
13033 (setq conf-list (cons conf-key conf-list))
13034 ;; scan for subconfigurations and subentities
13035 (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)
13036 (setq inst-comp-key (vhdl-match-string-downcase 3)
13037 inst-key-list (split-string
13038 (vhdl-match-string-downcase 1)
13039 "[ \t\n]*,[ \t\n]*"))
13040 (vhdl-forward-syntactic-ws)
13041 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13042 (setq
13043 inst-lib-key (vhdl-match-string-downcase 3)
13044 inst-ent-key (and (match-string 2)
13045 (vhdl-match-string-downcase 4))
13046 inst-arch-key (and (match-string 2)
13047 (vhdl-match-string-downcase 6))
13048 inst-conf-key (and (not (match-string 2))
13049 (vhdl-match-string-downcase 4)))
13050 (while inst-key-list
13051 (setq comp-conf-list
13052 (cons (list (car inst-key-list)
13053 inst-comp-key inst-ent-key
13054 inst-arch-key inst-conf-key
13055 inst-lib-key)
13056 comp-conf-list))
13057 (setq inst-key-list (cdr inst-key-list)))))
13058 (aput 'conf-alist conf-key
13059 (list conf-name file-name conf-line ent-key
13060 arch-key comp-conf-list lib-alist)))))
13061 ;; scan for packages
13062 (goto-char (point-min))
13063 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13064 (let* ((pack-name (match-string-no-properties 2))
13065 (pack-key (downcase pack-name))
13066 (is-body (match-string-no-properties 1))
13067 (pack-entry (aget pack-alist pack-key t))
13068 (pack-line (vhdl-current-line))
13069 (end-of-unit (vhdl-get-end-of-unit))
13070 comp-name func-name comp-alist func-alist lib-alist)
13071 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13072 (vhdl-warning-when-idle
13073 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13074 (if is-body " body" "") pack-name
13075 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13076 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13077 file-name (vhdl-current-line))
13078 ;; scan for context clauses
13079 (setq lib-alist (vhdl-scan-context-clause))
13080 ;; scan for component and subprogram declarations/bodies
13081 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13082 (if (equal (upcase (match-string 1)) "COMPONENT")
13083 (setq comp-name (match-string-no-properties 2)
13084 comp-alist
13085 (cons (list (downcase comp-name) comp-name
13086 file-name (vhdl-current-line))
13087 comp-alist))
13088 (setq func-name (match-string-no-properties 2)
13089 func-alist
13090 (cons (list (downcase func-name) func-name
13091 file-name (vhdl-current-line))
13092 func-alist))))
13093 (setq func-alist (nreverse func-alist))
13094 (setq comp-alist (nreverse comp-alist))
13095 (if is-body
13096 (setq pack-body-list (cons pack-key pack-body-list))
13097 (setq pack-list (cons pack-key pack-list)))
13098 (aput
13099 'pack-alist pack-key
13100 (if is-body
13101 (list (or (nth 0 pack-entry) pack-name)
13102 (nth 1 pack-entry) (nth 2 pack-entry)
13103 (nth 3 pack-entry) (nth 4 pack-entry)
13104 (nth 5 pack-entry)
13105 file-name pack-line func-alist lib-alist)
13106 (list pack-name file-name pack-line
13107 comp-alist func-alist lib-alist
13108 (nth 6 pack-entry) (nth 7 pack-entry)
13109 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13110 ;; scan for hierarchy
13111 (if (and limit-hier-file-size
13112 (< limit-hier-file-size (buffer-size)))
13113 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13114 (setq big-files t))
13115 ;; scan for architectures
13116 (goto-char (point-min))
13117 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13118 (let* ((ent-name (match-string-no-properties 2))
13119 (ent-key (downcase ent-name))
13120 (arch-name (match-string-no-properties 1))
13121 (arch-key (downcase arch-name))
13122 (ent-entry (aget ent-alist ent-key t))
13123 (arch-alist (nth 3 ent-entry))
13124 (arch-entry (aget arch-alist arch-key t))
13125 (beg-of-unit (point))
13126 (end-of-unit (vhdl-get-end-of-unit))
13127 (inst-no 0)
13128 inst-alist)
13129 ;; scan for contained instantiations
13130 (while (and (re-search-forward
13131 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13132 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13133 "component[ \t\n]+\\(\\w+\\)\\|"
13134 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13135 (or (not limit-hier-inst-no)
13136 (<= (setq inst-no (1+ inst-no))
13137 limit-hier-inst-no)))
13138 (let* ((inst-name (match-string-no-properties 1))
13139 (inst-key (downcase inst-name))
13140 (inst-comp-name
13141 (or (match-string-no-properties 3)
13142 (match-string-no-properties 6)))
13143 (inst-ent-key
13144 (or (and (match-string 8)
13145 (vhdl-match-string-downcase 11))
13146 (and inst-comp-name
13147 (downcase inst-comp-name))))
13148 (inst-arch-key (vhdl-match-string-downcase 13))
13149 (inst-conf-key
13150 (and (not (match-string 8))
13151 (vhdl-match-string-downcase 11)))
13152 (inst-lib-key (vhdl-match-string-downcase 10)))
13153 (goto-char (match-end 1))
13154 (setq inst-list (cons inst-key inst-list)
13155 inst-ent-list (cons inst-ent-key inst-ent-list))
13156 (setq inst-alist
13157 (append
13158 inst-alist
13159 (list (list inst-key inst-name file-name
13160 (vhdl-current-line) inst-comp-name
13161 inst-ent-key inst-arch-key
13162 inst-conf-key inst-lib-key))))))
13163 ;; scan for contained configuration specifications
13164 (goto-char beg-of-unit)
13165 (while (re-search-forward
13166 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13167 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13168 (let* ((inst-comp-name (match-string-no-properties 3))
13169 (inst-ent-key
13170 (and (match-string 6)
13171 (vhdl-match-string-downcase 9)))
13172 (inst-arch-key (vhdl-match-string-downcase 11))
13173 (inst-conf-key
13174 (and (not (match-string 6))
13175 (vhdl-match-string-downcase 9)))
13176 (inst-lib-key (vhdl-match-string-downcase 8))
13177 (inst-key-list
13178 (split-string (vhdl-match-string-downcase 1)
13179 "[ \t\n]*,[ \t\n]*"))
13180 (tmp-inst-alist inst-alist)
13181 inst-entry)
13182 (while tmp-inst-alist
13183 (when (and (or (equal "all" (car inst-key-list))
13184 (member (nth 0 (car tmp-inst-alist))
13185 inst-key-list))
13186 (equal
13187 (downcase
13188 (or (nth 4 (car tmp-inst-alist)) ""))
13189 (downcase inst-comp-name)))
13190 (setq inst-entry (car tmp-inst-alist))
13191 (setq inst-ent-list
13192 (cons (or inst-ent-key (nth 5 inst-entry))
13193 (vhdl-delete
13194 (nth 5 inst-entry) inst-ent-list)))
13195 (setq inst-entry
13196 (list (nth 0 inst-entry) (nth 1 inst-entry)
13197 (nth 2 inst-entry) (nth 3 inst-entry)
13198 (nth 4 inst-entry)
13199 (or inst-ent-key (nth 5 inst-entry))
13200 (or inst-arch-key (nth 6 inst-entry))
13201 inst-conf-key inst-lib-key))
13202 (setcar tmp-inst-alist inst-entry))
13203 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13204 ;; save in cache
13205 (aput 'arch-alist arch-key
13206 (list (nth 0 arch-entry) (nth 1 arch-entry)
13207 (nth 2 arch-entry) inst-alist
13208 (nth 4 arch-entry)))
13209 (aput 'ent-alist ent-key
13210 (list (nth 0 ent-entry) (nth 1 ent-entry)
13211 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13212 (nth 4 ent-entry)))
13213 (when (and limit-hier-inst-no
13214 (> inst-no limit-hier-inst-no))
13215 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13216 (setq big-files t))
13217 (goto-char end-of-unit))))
13218 ;; remember design units for this file
13219 (aput 'file-alist file-name
13220 (list ent-list arch-list arch-ent-list conf-list
13221 pack-list pack-body-list inst-list inst-ent-list))
13222 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13223 (setq file-list (cdr file-list))))
13224 (when (or (and (not project) files-exist)
13225 (and project (not non-final)))
13226 ;; consistency checks:
13227 ;; check whether each architecture has a corresponding entity
13228 (setq tmp-list ent-alist)
13229 (while tmp-list
13230 (when (null (nth 2 (car tmp-list)))
13231 (setq tmp-entry (car (nth 4 (car tmp-list))))
13232 (vhdl-warning-when-idle
13233 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13234 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13235 (nth 3 tmp-entry)))
13236 (setq tmp-list (cdr tmp-list)))
13237 ;; check whether configuration has a corresponding entity/architecture
13238 (setq tmp-list conf-alist)
13239 (while tmp-list
13240 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13241 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13242 (setq tmp-entry (car tmp-list))
13243 (vhdl-warning-when-idle
13244 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13245 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13246 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13247 (setq tmp-entry (car tmp-list))
13248 (vhdl-warning-when-idle
13249 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13250 (nth 1 tmp-entry) (nth 4 tmp-entry)
13251 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13252 (setq tmp-list (cdr tmp-list)))
13253 ;; check whether each package body has a package declaration
13254 (setq tmp-list pack-alist)
13255 (while tmp-list
13256 (when (null (nth 2 (car tmp-list)))
13257 (setq tmp-entry (car tmp-list))
13258 (vhdl-warning-when-idle
13259 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13260 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13261 (setq tmp-list (cdr tmp-list)))
13262 ;; sort lists
13263 (setq ent-alist (vhdl-sort-alist ent-alist))
13264 (setq conf-alist (vhdl-sort-alist conf-alist))
13265 (setq pack-alist (vhdl-sort-alist pack-alist))
13266 ;; remember updated directory/project
13267 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13268 ;; clear directory alists
13269 (unless project
13270 (adelete 'vhdl-entity-alist key)
13271 (adelete 'vhdl-config-alist key)
13272 (adelete 'vhdl-package-alist key)
13273 (adelete 'vhdl-ent-inst-alist key)
13274 (adelete 'vhdl-file-alist key))
13275 ;; put directory contents into cache
13276 (aput 'vhdl-entity-alist key ent-alist)
13277 (aput 'vhdl-config-alist key conf-alist)
13278 (aput 'vhdl-package-alist key pack-alist)
13279 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13280 (aput 'vhdl-file-alist key file-alist)
13281 ;; final messages
13282 (message "Scanning %s %s\"%s\"...done"
13283 (if is-directory "directory" "files") (or num-string "") name)
13284 (unless project (message "Scanning directory...done"))
13285 (when big-files
13286 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13287 ;; save cache when scanned non-interactively
13288 (when (or (not project) (not non-final))
13289 (when (and noninteractive vhdl-speedbar-save-cache)
13290 (vhdl-save-cache key)))
13291 t))
13292
13293 (defun vhdl-scan-project-contents (project)
13294 "Scan the contents of all VHDL files found in the directories and files
13295 of PROJECT."
13296 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13297 (default-dir (vhdl-resolve-env-variable
13298 (nth 1 (aget vhdl-project-alist project))))
13299 (file-exclude-regexp
13300 (or (nth 3 (aget vhdl-project-alist project)) ""))
13301 dir-list-tmp dir dir-name num-dir act-dir recursive)
13302 ;; clear project alists
13303 (adelete 'vhdl-entity-alist project)
13304 (adelete 'vhdl-config-alist project)
13305 (adelete 'vhdl-package-alist project)
13306 (adelete 'vhdl-ent-inst-alist project)
13307 (adelete 'vhdl-file-alist project)
13308 ;; expand directory names by default-directory
13309 (message "Collecting source files...")
13310 (while dir-list
13311 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13312 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13313 (setq recursive (match-string 1 dir)
13314 dir-name (match-string 3 dir))
13315 (setq dir-list-tmp
13316 (cons (concat recursive
13317 (if (file-name-absolute-p dir-name) "" default-dir)
13318 dir-name)
13319 dir-list-tmp))
13320 (setq dir-list (cdr dir-list)))
13321 ;; resolve path wildcards
13322 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13323 ;; expand directories
13324 (while dir-list-tmp
13325 (setq dir (car dir-list-tmp))
13326 ;; get subdirectories
13327 (if (string-match "-r \\(.*[/\\]\\)" dir)
13328 (setq dir-list (append dir-list (vhdl-get-subdirs
13329 (match-string 1 dir))))
13330 (setq dir-list (append dir-list (list dir))))
13331 (setq dir-list-tmp (cdr dir-list-tmp)))
13332 ;; exclude files
13333 (unless (equal file-exclude-regexp "")
13334 (let ((case-fold-search nil))
13335 (while dir-list
13336 (unless (string-match file-exclude-regexp (car dir-list))
13337 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13338 (setq dir-list (cdr dir-list)))
13339 (setq dir-list (nreverse dir-list-tmp))))
13340 (message "Collecting source files...done")
13341 ;; scan for design units for each directory in DIR-LIST
13342 (setq dir-list-tmp nil
13343 num-dir (length dir-list)
13344 act-dir 1)
13345 (while dir-list
13346 (setq dir-name (abbreviate-file-name
13347 (expand-file-name (car dir-list))))
13348 (vhdl-scan-directory-contents dir-name project nil
13349 (format "(%s/%s) " act-dir num-dir)
13350 (cdr dir-list))
13351 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13352 (setq dir-list (cdr dir-list)
13353 act-dir (1+ act-dir)))
13354 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13355 (message "Scanning project \"%s\"...done" project)))
13356
13357 (defun vhdl-update-file-contents (file-name)
13358 "Update hierarchy information by contents of current buffer."
13359 (setq file-name (abbreviate-file-name file-name))
13360 (let* ((dir-name (file-name-directory file-name))
13361 (directory-alist vhdl-directory-alist)
13362 updated)
13363 (while directory-alist
13364 (when (member dir-name (nth 1 (car directory-alist)))
13365 (let* ((vhdl-project (nth 0 (car directory-alist)))
13366 (project (vhdl-project-p))
13367 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13368 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13369 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13370 (ent-inst-list (car (aget vhdl-ent-inst-alist
13371 (or project dir-name) t)))
13372 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13373 (file-entry (aget file-alist file-name t))
13374 (ent-list (nth 0 file-entry))
13375 (arch-list (nth 1 file-entry))
13376 (arch-ent-list (nth 2 file-entry))
13377 (conf-list (nth 3 file-entry))
13378 (pack-list (nth 4 file-entry))
13379 (pack-body-list (nth 5 file-entry))
13380 (inst-ent-list (nth 7 file-entry))
13381 (cache-key (or project dir-name))
13382 arch-alist key ent-key entry)
13383 ;; delete design units previously contained in this file:
13384 ;; entities
13385 (while ent-list
13386 (setq key (car ent-list)
13387 entry (aget ent-alist key t))
13388 (when (equal file-name (nth 1 entry))
13389 (if (nth 3 entry)
13390 (aput 'ent-alist key
13391 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13392 (adelete 'ent-alist key)))
13393 (setq ent-list (cdr ent-list)))
13394 ;; architectures
13395 (while arch-list
13396 (setq key (car arch-list)
13397 ent-key (car arch-ent-list)
13398 entry (aget ent-alist ent-key t)
13399 arch-alist (nth 3 entry))
13400 (when (equal file-name (nth 1 (aget arch-alist key t)))
13401 (adelete 'arch-alist key)
13402 (if (or (nth 1 entry) arch-alist)
13403 (aput 'ent-alist ent-key
13404 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13405 arch-alist (nth 4 entry)))
13406 (adelete 'ent-alist ent-key)))
13407 (setq arch-list (cdr arch-list)
13408 arch-ent-list (cdr arch-ent-list)))
13409 ;; configurations
13410 (while conf-list
13411 (setq key (car conf-list))
13412 (when (equal file-name (nth 1 (aget conf-alist key t)))
13413 (adelete 'conf-alist key))
13414 (setq conf-list (cdr conf-list)))
13415 ;; package declarations
13416 (while pack-list
13417 (setq key (car pack-list)
13418 entry (aget pack-alist key t))
13419 (when (equal file-name (nth 1 entry))
13420 (if (nth 6 entry)
13421 (aput 'pack-alist key
13422 (list (nth 0 entry) nil nil nil nil nil
13423 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13424 (nth 9 entry)))
13425 (adelete 'pack-alist key)))
13426 (setq pack-list (cdr pack-list)))
13427 ;; package bodies
13428 (while pack-body-list
13429 (setq key (car pack-body-list)
13430 entry (aget pack-alist key t))
13431 (when (equal file-name (nth 6 entry))
13432 (if (nth 1 entry)
13433 (aput 'pack-alist key
13434 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13435 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13436 nil nil nil nil))
13437 (adelete 'pack-alist key)))
13438 (setq pack-body-list (cdr pack-body-list)))
13439 ;; instantiated entities
13440 (while inst-ent-list
13441 (setq ent-inst-list
13442 (vhdl-delete (car inst-ent-list) ent-inst-list))
13443 (setq inst-ent-list (cdr inst-ent-list)))
13444 ;; update caches
13445 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13446 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13447 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13448 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13449 ;; scan file
13450 (vhdl-scan-directory-contents file-name project t)
13451 (when (or (and vhdl-speedbar-show-projects project)
13452 (and (not vhdl-speedbar-show-projects) (not project)))
13453 (vhdl-speedbar-refresh project))
13454 (setq updated t)))
13455 (setq directory-alist (cdr directory-alist)))
13456 updated))
13457
13458 (defun vhdl-update-hierarchy ()
13459 "Update directory and hierarchy information in speedbar."
13460 (let ((file-list (reverse vhdl-modified-file-list))
13461 updated)
13462 (when (and vhdl-speedbar-update-on-saving file-list)
13463 (while file-list
13464 (setq updated
13465 (or (vhdl-update-file-contents (car file-list))
13466 updated))
13467 (setq file-list (cdr file-list)))
13468 (setq vhdl-modified-file-list nil)
13469 (when updated (message "Updating hierarchy...done")))))
13470
13471 ;; structure (parenthesised expression means list of such entries)
13472 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13473 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13474 ;; comp-lib-name level)
13475 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13476 conf-inst-alist level indent
13477 &optional include-top ent-hier)
13478 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13479 entity ENT-KEY."
13480 (let* ((ent-entry (aget ent-alist ent-key t))
13481 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13482 (cdar (last (nth 3 ent-entry)))))
13483 (inst-alist (nth 3 arch-entry))
13484 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13485 hier-list subcomp-list tmp-list inst-key inst-comp-name
13486 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13487 (when (= level 0) (message "Extract design hierarchy..."))
13488 (when include-top
13489 (setq level (1+ level)))
13490 (when (member ent-key ent-hier)
13491 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13492 ;; check configured architecture (already checked during scanning)
13493 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13494 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13495 ;; process all instances
13496 (while inst-alist
13497 (setq inst-entry (car inst-alist)
13498 inst-key (nth 0 inst-entry)
13499 inst-comp-name (nth 4 inst-entry)
13500 inst-conf-key (nth 7 inst-entry))
13501 ;; search entry in configuration's instantiations list
13502 (setq tmp-list conf-inst-alist)
13503 (while (and tmp-list
13504 (not (and (member (nth 0 (car tmp-list))
13505 (list "all" inst-key))
13506 (equal (nth 1 (car tmp-list))
13507 (downcase (or inst-comp-name ""))))))
13508 (setq tmp-list (cdr tmp-list)))
13509 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13510 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13511 (when (and inst-conf-key (not inst-conf-entry))
13512 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13513 ;; determine entity
13514 (setq inst-ent-key
13515 (or (nth 2 (car tmp-list)) ; from configuration
13516 (nth 3 inst-conf-entry) ; from subconfiguration
13517 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13518 ; from configuration spec.
13519 (nth 5 inst-entry))) ; from direct instantiation
13520 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13521 ;; determine architecture
13522 (setq inst-arch-key
13523 (or (nth 3 (car tmp-list)) ; from configuration
13524 (nth 4 inst-conf-entry) ; from subconfiguration
13525 (nth 6 inst-entry) ; from direct instantiation
13526 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13527 ; from configuration spec.
13528 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13529 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13530 ;; set library
13531 (setq inst-lib-key
13532 (or (nth 5 (car tmp-list)) ; from configuration
13533 (nth 8 inst-entry))) ; from direct instantiation
13534 ;; gather information for this instance
13535 (setq comp-entry
13536 (list (nth 1 inst-entry)
13537 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13538 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13539 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13540 (or (nth 0 inst-arch-entry) inst-arch-key)
13541 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13542 (or (nth 0 inst-conf-entry) inst-conf-key)
13543 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13544 inst-lib-key level))
13545 ;; get subcomponent hierarchy
13546 (setq subcomp-list (vhdl-get-hierarchy
13547 ent-alist conf-alist
13548 inst-ent-key inst-arch-key inst-conf-key
13549 (nth 5 inst-conf-entry)
13550 (1+ level) indent nil (cons ent-key ent-hier)))
13551 ;; add to list
13552 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13553 (setq inst-alist (cdr inst-alist)))
13554 (when include-top
13555 (setq hier-list
13556 (cons (list nil nil (nth 0 ent-entry)
13557 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13558 (nth 0 arch-entry)
13559 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13560 nil nil
13561 nil (1- level))
13562 hier-list)))
13563 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13564 hier-list))
13565
13566 (defun vhdl-get-instantiations (ent-key indent)
13567 "Get all instantiations of entity ENT-KEY."
13568 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13569 arch-alist inst-alist ent-inst-list
13570 ent-entry arch-entry inst-entry)
13571 (while ent-alist
13572 (setq ent-entry (car ent-alist))
13573 (setq arch-alist (nth 4 ent-entry))
13574 (while arch-alist
13575 (setq arch-entry (car arch-alist))
13576 (setq inst-alist (nth 4 arch-entry))
13577 (while inst-alist
13578 (setq inst-entry (car inst-alist))
13579 (when (equal ent-key (nth 5 inst-entry))
13580 (setq ent-inst-list
13581 (cons (list (nth 1 inst-entry)
13582 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13583 (nth 1 ent-entry)
13584 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13585 (nth 1 arch-entry)
13586 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13587 ent-inst-list)))
13588 (setq inst-alist (cdr inst-alist)))
13589 (setq arch-alist (cdr arch-alist)))
13590 (setq ent-alist (cdr ent-alist)))
13591 (nreverse ent-inst-list)))
13592
13593 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13594 ;; Caching in file
13595
13596 (defun vhdl-save-caches ()
13597 "Save all updated hierarchy caches to file."
13598 (interactive)
13599 (condition-case nil
13600 (when vhdl-speedbar-save-cache
13601 ;; update hierarchy
13602 (vhdl-update-hierarchy)
13603 (let ((project-list vhdl-updated-project-list))
13604 (message "Saving hierarchy caches...")
13605 ;; write updated project caches
13606 (while project-list
13607 (vhdl-save-cache (car project-list))
13608 (setq project-list (cdr project-list)))
13609 (message "Saving hierarchy caches...done")))
13610 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13611 (sit-for 2)))))
13612
13613 (defun vhdl-save-cache (key)
13614 "Save current hierarchy cache to file."
13615 (let* ((orig-buffer (current-buffer))
13616 (vhdl-project key)
13617 (project (vhdl-project-p))
13618 (default-directory key)
13619 (directory (abbreviate-file-name (vhdl-default-directory)))
13620 (file-name (vhdl-resolve-env-variable
13621 (vhdl-replace-string
13622 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13623 (concat
13624 (subst-char-in-string ? ?_ (or project "dir"))
13625 " " (user-login-name)))))
13626 (file-dir-name (expand-file-name file-name directory))
13627 (cache-key (or project directory))
13628 (key (if project "project" "directory")))
13629 (unless (file-exists-p (file-name-directory file-dir-name))
13630 (make-directory (file-name-directory file-dir-name) t))
13631 (if (not (file-writable-p file-dir-name))
13632 (progn (vhdl-warning (format "File not writable: \"%s\""
13633 (abbreviate-file-name file-dir-name)))
13634 (sit-for 2))
13635 (message "Saving cache: \"%s\"" file-dir-name)
13636 (set-buffer (find-file-noselect file-dir-name t t))
13637 (erase-buffer)
13638 (insert ";; -*- Emacs-Lisp -*-\n\n"
13639 ";;; " (file-name-nondirectory file-name)
13640 " - design hierarchy cache file for Emacs VHDL Mode "
13641 vhdl-version "\n")
13642 (insert "\n;; " (if project "Project " "Directory") " : ")
13643 (if project (insert project) (prin1 directory (current-buffer)))
13644 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13645 (user-login-name) "\n\n"
13646 "\n;; version number\n"
13647 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13648 "\n;; " (if project "project" "directory") " name"
13649 "\n(setq " key " ")
13650 (prin1 (or project directory) (current-buffer))
13651 (insert ")\n")
13652 (when (member 'hierarchy vhdl-speedbar-save-cache)
13653 (insert "\n;; entity and architecture cache\n"
13654 "(aput 'vhdl-entity-alist " key " '")
13655 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13656 (insert ")\n\n;; configuration cache\n"
13657 "(aput 'vhdl-config-alist " key " '")
13658 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13659 (insert ")\n\n;; package cache\n"
13660 "(aput 'vhdl-package-alist " key " '")
13661 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13662 (insert ")\n\n;; instantiated entities cache\n"
13663 "(aput 'vhdl-ent-inst-alist " key " '")
13664 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13665 (insert ")\n\n;; design units per file cache\n"
13666 "(aput 'vhdl-file-alist " key " '")
13667 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13668 (when project
13669 (insert ")\n\n;; source directories in project cache\n"
13670 "(aput 'vhdl-directory-alist " key " '")
13671 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13672 (insert ")\n"))
13673 (when (member 'display vhdl-speedbar-save-cache)
13674 (insert "\n;; shown design units cache\n"
13675 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13676 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13677 (current-buffer))
13678 (insert ")\n"))
13679 (setq vhdl-updated-project-list
13680 (delete cache-key vhdl-updated-project-list))
13681 (save-buffer)
13682 (kill-buffer (current-buffer))
13683 (set-buffer orig-buffer))))
13684
13685 (defun vhdl-load-cache (key)
13686 "Load hierarchy cache information from file."
13687 (let* ((vhdl-project key)
13688 (default-directory key)
13689 (directory (vhdl-default-directory))
13690 (file-name (vhdl-resolve-env-variable
13691 (vhdl-replace-string
13692 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13693 (concat
13694 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13695 " " (user-login-name)))))
13696 (file-dir-name (expand-file-name file-name directory))
13697 vhdl-cache-version)
13698 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13699 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13700 (when (file-exists-p file-dir-name)
13701 (condition-case ()
13702 (progn (load-file file-dir-name)
13703 (string< (mapconcat
13704 (lambda (a) (format "%3d" (string-to-int a)))
13705 (split-string "3.31.14" "\\.") "")
13706 (mapconcat
13707 (lambda (a) (format "%3d" (string-to-int a)))
13708 (split-string vhdl-cache-version "\\.") "")))
13709 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13710 nil))))))
13711
13712 (defun vhdl-require-hierarchy-info ()
13713 "Make sure that hierarchy information is available. Load cache or scan files
13714 if required."
13715 (if (vhdl-project-p)
13716 (unless (or (assoc vhdl-project vhdl-file-alist)
13717 (vhdl-load-cache vhdl-project))
13718 (vhdl-scan-project-contents vhdl-project))
13719 (let ((directory (abbreviate-file-name default-directory)))
13720 (unless (or (assoc directory vhdl-file-alist)
13721 (vhdl-load-cache directory))
13722 (vhdl-scan-directory-contents directory)))))
13723
13724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13725 ;; Add hierarchy browser functionality to speedbar
13726
13727 (defvar vhdl-speedbar-key-map nil
13728 "Keymap used when in the VHDL hierarchy browser mode.")
13729
13730 (defvar vhdl-speedbar-menu-items nil
13731 "Additional menu-items to add to speedbar frame.")
13732
13733 (defun vhdl-speedbar-initialize ()
13734 "Initialize speedbar."
13735 ;; general settings
13736 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13737 ;; VHDL file extensions (extracted from `auto-mode-alist')
13738 (let ((mode-alist auto-mode-alist))
13739 (while mode-alist
13740 (when (eq (cdar mode-alist) 'vhdl-mode)
13741 (speedbar-add-supported-extension (caar mode-alist)))
13742 (setq mode-alist (cdr mode-alist))))
13743 ;; hierarchy browser settings
13744 (when (boundp 'speedbar-mode-functions-list)
13745 ;; special functions
13746 (speedbar-add-mode-functions-list
13747 '("vhdl directory"
13748 (speedbar-item-info . vhdl-speedbar-item-info)
13749 (speedbar-line-path . speedbar-files-line-path)))
13750 (speedbar-add-mode-functions-list
13751 '("vhdl project"
13752 (speedbar-item-info . vhdl-speedbar-item-info)
13753 (speedbar-line-path . vhdl-speedbar-line-project)))
13754 ;; keymap
13755 (unless vhdl-speedbar-key-map
13756 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13757 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13758 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13759 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13760 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13761 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13762 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13763 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13764 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13765 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13766 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13767 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13768 (let ((key 0))
13769 (while (<= key 9)
13770 (define-key vhdl-speedbar-key-map (int-to-string key)
13771 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13772 (setq key (1+ key)))))
13773 (define-key speedbar-key-map "h"
13774 (lambda () (interactive)
13775 (speedbar-change-initial-expansion-list "vhdl directory")))
13776 (define-key speedbar-key-map "H"
13777 (lambda () (interactive)
13778 (speedbar-change-initial-expansion-list "vhdl project")))
13779 ;; menu
13780 (unless vhdl-speedbar-menu-items
13781 (setq
13782 vhdl-speedbar-menu-items
13783 `(["Edit" speedbar-edit-line t]
13784 ["Expand" speedbar-expand-line
13785 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13786 ["Contract" vhdl-speedbar-contract-level t]
13787 ["Expand All" vhdl-speedbar-expand-all t]
13788 ["Contract All" vhdl-speedbar-contract-all t]
13789 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13790 (while (<= key 9)
13791 (setq menu-list
13792 (cons `[,(if (= key 0) "All" (int-to-string key))
13793 (vhdl-speedbar-set-depth ,key)
13794 :style radio
13795 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13796 :keys ,(int-to-string key)]
13797 menu-list))
13798 (setq key (1+ key)))
13799 (nreverse menu-list))
13800 "--"
13801 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13802 (or (vhdl-speedbar-check-unit 'entity)
13803 (vhdl-speedbar-check-unit 'subprogram))]
13804 ["Place Component" vhdl-speedbar-place-component
13805 (vhdl-speedbar-check-unit 'entity)]
13806 ["Make" vhdl-speedbar-make-design
13807 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13808 ["Generate Makefile" vhdl-speedbar-generate-makefile
13809 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13810 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13811 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13812 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13813 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13814 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13815 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13816 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13817 ;; hook-ups
13818 (speedbar-add-expansion-list
13819 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13820 vhdl-speedbar-display-directory))
13821 (speedbar-add-expansion-list
13822 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13823 vhdl-speedbar-display-projects))
13824 (setq speedbar-stealthy-function-list
13825 (append
13826 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13827 ("vhdl project" vhdl-speedbar-update-current-project
13828 vhdl-speedbar-update-current-unit)
13829 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
13830 ; (speedbar-extension-list-to-regex
13831 ; speedbar-ignored-path-expressions))))
13832 )
13833 speedbar-stealthy-function-list))
13834 (when (eq vhdl-speedbar-display-mode 'directory)
13835 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13836 (when (eq vhdl-speedbar-display-mode 'project)
13837 (setq speedbar-initial-expansion-list-name "vhdl project"))
13838 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
13839
13840 (defun vhdl-speedbar (&optional arg)
13841 "Open/close speedbar."
13842 (interactive)
13843 (if (not (fboundp 'speedbar))
13844 (error "WARNING: Speedbar is not available or not installed")
13845 (condition-case ()
13846 (speedbar-frame-mode arg)
13847 (error (error "WARNING: An error occurred while opening speedbar")))))
13848
13849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13850 ;; Display functions
13851
13852 (defvar vhdl-speedbar-last-selected-project nil
13853 "Name of last selected project.")
13854
13855 ;; macros must be defined in the file they are used (copied from `speedbar.el')
13856 (defmacro speedbar-with-writable (&rest forms)
13857 "Allow the buffer to be writable and evaluate FORMS."
13858 (list 'let '((inhibit-read-only t))
13859 (cons 'progn forms)))
13860 (put 'speedbar-with-writable 'lisp-indent-function 0)
13861
13862 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
13863 "Display directory and hierarchy information in speedbar."
13864 (setq vhdl-speedbar-show-projects nil)
13865 (setq speedbar-ignored-path-regexp
13866 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
13867 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13868 (setq speedbar-last-selected-file nil)
13869 (speedbar-with-writable
13870 (condition-case nil
13871 (progn
13872 ;; insert directory path
13873 (speedbar-directory-buttons directory depth)
13874 ;; insert subdirectories
13875 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13876 ;; scan and insert hierarchy of current directory
13877 (vhdl-speedbar-insert-dir-hierarchy directory depth
13878 speedbar-power-click)
13879 ;; expand subdirectories
13880 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13881 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13882
13883 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
13884 "Display projects and hierarchy information in speedbar."
13885 (setq vhdl-speedbar-show-projects t)
13886 (setq speedbar-ignored-path-regexp ".")
13887 (setq speedbar-last-selected-file nil)
13888 (setq vhdl-speedbar-last-selected-project nil)
13889 (speedbar-with-writable
13890 (condition-case nil
13891 ;; insert projects
13892 (vhdl-speedbar-insert-projects)
13893 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13894 (setq speedbar-full-text-cache nil)) ; prevent caching
13895
13896 (defun vhdl-speedbar-insert-projects ()
13897 "Insert all projects in speedbar."
13898 (vhdl-speedbar-make-title-line "Projects:")
13899 (let ((project-alist (if vhdl-project-sort
13900 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13901 vhdl-project-alist))
13902 (vhdl-speedbar-update-current-unit nil))
13903 ;; insert projects
13904 (while project-alist
13905 (speedbar-make-tag-line
13906 'angle ?+ 'vhdl-speedbar-expand-project
13907 (caar project-alist) (caar project-alist)
13908 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13909 (setq project-alist (cdr project-alist)))
13910 (setq project-alist vhdl-project-alist)
13911 ;; expand projects
13912 (while project-alist
13913 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13914 (goto-char (point-min))
13915 (when (re-search-forward
13916 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13917 (goto-char (match-end 1))
13918 (speedbar-do-function-pointer)))
13919 (setq project-alist (cdr project-alist))))
13920 ; (vhdl-speedbar-update-current-project)
13921 ; (vhdl-speedbar-update-current-unit nil t)
13922 )
13923
13924 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13925 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13926 otherwise use cached data."
13927 (when (or rescan (and (not (assoc project vhdl-file-alist))
13928 (not (vhdl-load-cache project))))
13929 (vhdl-scan-project-contents project))
13930 ;; insert design hierarchy
13931 (vhdl-speedbar-insert-hierarchy
13932 (aget vhdl-entity-alist project t)
13933 (aget vhdl-config-alist project t)
13934 (aget vhdl-package-alist project t)
13935 (car (aget vhdl-ent-inst-alist project t)) indent)
13936 (insert (int-to-string indent) ":\n")
13937 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13938 (put-text-property (1- (point)) (point) 'invisible nil)
13939 ;; expand design units
13940 (vhdl-speedbar-expand-units project))
13941
13942 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13943 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13944 otherwise use cached data."
13945 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13946 (not (vhdl-load-cache directory))))
13947 (vhdl-scan-directory-contents directory))
13948 ;; insert design hierarchy
13949 (vhdl-speedbar-insert-hierarchy
13950 (aget vhdl-entity-alist directory t)
13951 (aget vhdl-config-alist directory t)
13952 (aget vhdl-package-alist directory t)
13953 (car (aget vhdl-ent-inst-alist directory t)) depth)
13954 ;; expand design units
13955 (vhdl-speedbar-expand-units directory)
13956 (aput 'vhdl-directory-alist directory (list (list directory))))
13957
13958 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
13959 ent-inst-list depth)
13960 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13961 (if (not (or ent-alist conf-alist pack-alist))
13962 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13963 (let (ent-entry conf-entry pack-entry)
13964 ;; insert entities
13965 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13966 (while ent-alist
13967 (setq ent-entry (car ent-alist))
13968 (speedbar-make-tag-line
13969 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
13970 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13971 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13972 'vhdl-speedbar-entity-face depth)
13973 (unless (nth 2 ent-entry)
13974 (end-of-line 0) (insert "!") (forward-char 1))
13975 (unless (member (nth 0 ent-entry) ent-inst-list)
13976 (end-of-line 0) (insert " (top)") (forward-char 1))
13977 (setq ent-alist (cdr ent-alist)))
13978 ;; insert configurations
13979 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13980 (while conf-alist
13981 (setq conf-entry (car conf-alist))
13982 (speedbar-make-tag-line
13983 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13984 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13985 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13986 'vhdl-speedbar-configuration-face depth)
13987 (setq conf-alist (cdr conf-alist)))
13988 ;; insert packages
13989 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13990 (while pack-alist
13991 (setq pack-entry (car pack-alist))
13992 (vhdl-speedbar-make-pack-line
13993 (nth 0 pack-entry) (nth 1 pack-entry)
13994 (cons (nth 2 pack-entry) (nth 3 pack-entry))
13995 (cons (nth 7 pack-entry) (nth 8 pack-entry))
13996 depth)
13997 (setq pack-alist (cdr pack-alist))))))
13998
13999 (defun vhdl-speedbar-rescan-hierarchy ()
14000 "Rescan hierarchy for the directory or project under the cursor."
14001 (interactive)
14002 (let (key path)
14003 (cond
14004 ;; current project
14005 (vhdl-speedbar-show-projects
14006 (setq key (vhdl-speedbar-line-project))
14007 (vhdl-scan-project-contents key))
14008 ;; top-level directory
14009 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14010 (re-search-forward "[0-9]+:" nil t)
14011 (vhdl-scan-directory-contents
14012 (abbreviate-file-name (speedbar-line-path))))
14013 ;; current directory
14014 (t (setq path (speedbar-line-path))
14015 (string-match "^\\(.+[/\\]\\)" path)
14016 (vhdl-scan-directory-contents
14017 (abbreviate-file-name (match-string 1 path)))))
14018 (vhdl-speedbar-refresh key)))
14019
14020 (defun vhdl-speedbar-expand-dirs (directory)
14021 "Expand subdirectories in DIRECTORY according to
14022 `speedbar-shown-directories'."
14023 ;; (nicked from `speedbar-default-directory-list')
14024 (let ((sf (cdr (reverse speedbar-shown-directories)))
14025 (vhdl-speedbar-update-current-unit nil))
14026 (setq speedbar-shown-directories
14027 (list (expand-file-name default-directory)))
14028 (while sf
14029 (when (speedbar-goto-this-file (car sf))
14030 (beginning-of-line)
14031 (when (looking-at "[0-9]+:\\s-*<")
14032 (goto-char (match-end 0))
14033 (speedbar-do-function-pointer)))
14034 (setq sf (cdr sf))))
14035 (vhdl-speedbar-update-current-unit nil t))
14036
14037 (defun vhdl-speedbar-expand-units (key)
14038 "Expand design units in directory/project KEY according to
14039 `vhdl-speedbar-shown-unit-alist'."
14040 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14041 (vhdl-speedbar-update-current-unit nil)
14042 vhdl-updated-project-list)
14043 (adelete 'vhdl-speedbar-shown-unit-alist key)
14044 (vhdl-prepare-search-1
14045 (while unit-alist ; expand units
14046 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14047 (beginning-of-line)
14048 (let ((arch-alist (nth 1 (car unit-alist)))
14049 position)
14050 (when (looking-at "^[0-9]+:\\s-*\\[")
14051 (goto-char (match-end 0))
14052 (setq position (point))
14053 (speedbar-do-function-pointer)
14054 (select-frame speedbar-frame)
14055 (while arch-alist ; expand architectures
14056 (goto-char position)
14057 (when (re-search-forward
14058 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14059 (car arch-alist) "\\>\\)") nil t)
14060 (beginning-of-line)
14061 (when (looking-at "^[0-9]+:\\s-*{")
14062 (goto-char (match-end 0))
14063 (speedbar-do-function-pointer)
14064 (select-frame speedbar-frame)))
14065 (setq arch-alist (cdr arch-alist))))
14066 (setq unit-alist (cdr unit-alist))))))
14067 (vhdl-speedbar-update-current-unit nil t))
14068
14069 (defun vhdl-speedbar-contract-level ()
14070 "Contract current level in current directory/project."
14071 (interactive)
14072 (when (or (save-excursion
14073 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14074 (and (save-excursion
14075 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14076 (re-search-backward
14077 (format "^[0-%d]:\\s-*[[{<]-"
14078 (max (1- (string-to-int (match-string 1))) 0)) nil t)))
14079 (goto-char (match-end 0))
14080 (speedbar-do-function-pointer)
14081 (speedbar-center-buffer-smartly)))
14082
14083 (defun vhdl-speedbar-contract-all ()
14084 "Contract all expanded design units in current directory/project."
14085 (interactive)
14086 (if (and vhdl-speedbar-show-projects
14087 (save-excursion (beginning-of-line) (looking-at "^0:")))
14088 (progn (setq vhdl-speedbar-shown-project-list nil)
14089 (vhdl-speedbar-refresh))
14090 (let ((key (vhdl-speedbar-line-key)))
14091 (adelete 'vhdl-speedbar-shown-unit-alist key)
14092 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14093 (when (memq 'display vhdl-speedbar-save-cache)
14094 (add-to-list 'vhdl-updated-project-list key)))))
14095
14096 (defun vhdl-speedbar-expand-all ()
14097 "Expand all design units in current directory/project."
14098 (interactive)
14099 (let* ((key (vhdl-speedbar-line-key))
14100 (ent-alist (aget vhdl-entity-alist key t))
14101 (conf-alist (aget vhdl-config-alist key t))
14102 (pack-alist (aget vhdl-package-alist key t))
14103 arch-alist unit-alist subunit-alist)
14104 (add-to-list 'vhdl-speedbar-shown-project-list key)
14105 (while ent-alist
14106 (setq arch-alist (nth 4 (car ent-alist)))
14107 (setq subunit-alist nil)
14108 (while arch-alist
14109 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14110 (setq arch-alist (cdr arch-alist)))
14111 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14112 (setq ent-alist (cdr ent-alist)))
14113 (while conf-alist
14114 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14115 (setq conf-alist (cdr conf-alist)))
14116 (while pack-alist
14117 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14118 (setq pack-alist (cdr pack-alist)))
14119 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14120 (vhdl-speedbar-refresh)
14121 (when (memq 'display vhdl-speedbar-save-cache)
14122 (add-to-list 'vhdl-updated-project-list key))))
14123
14124 (defun vhdl-speedbar-expand-project (text token indent)
14125 "Expand/contract the project under the cursor."
14126 (cond
14127 ((string-match "+" text) ; expand project
14128 (speedbar-change-expand-button-char ?-)
14129 (unless (member token vhdl-speedbar-shown-project-list)
14130 (setq vhdl-speedbar-shown-project-list
14131 (cons token vhdl-speedbar-shown-project-list)))
14132 (speedbar-with-writable
14133 (save-excursion
14134 (end-of-line) (forward-char 1)
14135 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14136 speedbar-power-click))))
14137 ((string-match "-" text) ; contract project
14138 (speedbar-change-expand-button-char ?+)
14139 (setq vhdl-speedbar-shown-project-list
14140 (delete token vhdl-speedbar-shown-project-list))
14141 (speedbar-delete-subblock indent))
14142 (t (error "Nothing to display")))
14143 (when (equal (selected-frame) speedbar-frame)
14144 (speedbar-center-buffer-smartly)))
14145
14146 (defun vhdl-speedbar-expand-entity (text token indent)
14147 "Expand/contract the entity under the cursor."
14148 (cond
14149 ((string-match "+" text) ; expand entity
14150 (let* ((key (vhdl-speedbar-line-key indent))
14151 (ent-alist (aget vhdl-entity-alist key t))
14152 (ent-entry (aget ent-alist token t))
14153 (arch-alist (nth 3 ent-entry))
14154 (inst-alist (vhdl-get-instantiations token indent))
14155 (subpack-alist (nth 4 ent-entry))
14156 arch-entry inst-entry)
14157 (if (not (or arch-alist inst-alist subpack-alist))
14158 (speedbar-change-expand-button-char ??)
14159 (speedbar-change-expand-button-char ?-)
14160 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14161 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14162 (aput 'unit-alist token nil)
14163 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14164 (speedbar-with-writable
14165 (save-excursion
14166 (end-of-line) (forward-char 1)
14167 ;; insert architectures
14168 (when arch-alist
14169 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14170 (while arch-alist
14171 (setq arch-entry (car arch-alist))
14172 (speedbar-make-tag-line
14173 'curly ?+ 'vhdl-speedbar-expand-architecture
14174 (cons token (nth 0 arch-entry))
14175 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14176 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14177 'vhdl-speedbar-architecture-face (1+ indent))
14178 (setq arch-alist (cdr arch-alist)))
14179 ;; insert instantiations
14180 (when inst-alist
14181 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14182 (while inst-alist
14183 (setq inst-entry (car inst-alist))
14184 (vhdl-speedbar-make-inst-line
14185 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14186 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14187 nil nil nil (1+ indent) 0 " in ")
14188 (setq inst-alist (cdr inst-alist)))
14189 ;; insert required packages
14190 (vhdl-speedbar-insert-subpackages
14191 subpack-alist (1+ indent) indent)))
14192 (when (memq 'display vhdl-speedbar-save-cache)
14193 (add-to-list 'vhdl-updated-project-list key))
14194 (vhdl-speedbar-update-current-unit t t))))
14195 ((string-match "-" text) ; contract entity
14196 (speedbar-change-expand-button-char ?+)
14197 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14198 (let* ((key (vhdl-speedbar-line-key indent))
14199 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14200 (adelete 'unit-alist token)
14201 (if unit-alist
14202 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14203 (adelete 'vhdl-speedbar-shown-unit-alist key))
14204 (speedbar-delete-subblock indent)
14205 (when (memq 'display vhdl-speedbar-save-cache)
14206 (add-to-list 'vhdl-updated-project-list key))))
14207 (t (error "Nothing to display")))
14208 (when (equal (selected-frame) speedbar-frame)
14209 (speedbar-center-buffer-smartly)))
14210
14211 (defun vhdl-speedbar-expand-architecture (text token indent)
14212 "Expand/contract the architecture under the cursor."
14213 (cond
14214 ((string-match "+" text) ; expand architecture
14215 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14216 (ent-alist (aget vhdl-entity-alist key t))
14217 (conf-alist (aget vhdl-config-alist key t))
14218 (hier-alist (vhdl-get-hierarchy
14219 ent-alist conf-alist (car token) (cdr token) nil nil
14220 0 (1- indent)))
14221 (ent-entry (aget ent-alist (car token) t))
14222 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14223 (subpack-alist (nth 4 arch-entry))
14224 entry)
14225 (if (not (or hier-alist subpack-alist))
14226 (speedbar-change-expand-button-char ??)
14227 (speedbar-change-expand-button-char ?-)
14228 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14229 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14230 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14231 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14232 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14233 (speedbar-with-writable
14234 (save-excursion
14235 (end-of-line) (forward-char 1)
14236 ;; insert instance hierarchy
14237 (when hier-alist
14238 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14239 (1+ indent)))
14240 (while hier-alist
14241 (setq entry (car hier-alist))
14242 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14243 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14244 (vhdl-speedbar-make-inst-line
14245 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14246 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14247 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14248 (setq hier-alist (cdr hier-alist)))
14249 ;; insert required packages
14250 (vhdl-speedbar-insert-subpackages
14251 subpack-alist (1+ indent) (1- indent))))
14252 (when (memq 'display vhdl-speedbar-save-cache)
14253 (add-to-list 'vhdl-updated-project-list key))
14254 (vhdl-speedbar-update-current-unit t t))))
14255 ((string-match "-" text) ; contract architecture
14256 (speedbar-change-expand-button-char ?+)
14257 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14258 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14259 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14260 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14261 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14262 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14263 (speedbar-delete-subblock indent)
14264 (when (memq 'display vhdl-speedbar-save-cache)
14265 (add-to-list 'vhdl-updated-project-list key))))
14266 (t (error "Nothing to display")))
14267 (when (equal (selected-frame) speedbar-frame)
14268 (speedbar-center-buffer-smartly)))
14269
14270 (defun vhdl-speedbar-expand-config (text token indent)
14271 "Expand/contract the configuration under the cursor."
14272 (cond
14273 ((string-match "+" text) ; expand configuration
14274 (let* ((key (vhdl-speedbar-line-key indent))
14275 (conf-alist (aget vhdl-config-alist key t))
14276 (conf-entry (aget conf-alist token))
14277 (ent-alist (aget vhdl-entity-alist key t))
14278 (hier-alist (vhdl-get-hierarchy
14279 ent-alist conf-alist (nth 3 conf-entry)
14280 (nth 4 conf-entry) token (nth 5 conf-entry)
14281 0 indent t))
14282 (subpack-alist (nth 6 conf-entry))
14283 entry)
14284 (if (not (or hier-alist subpack-alist))
14285 (speedbar-change-expand-button-char ??)
14286 (speedbar-change-expand-button-char ?-)
14287 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14288 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14289 (aput 'unit-alist token nil)
14290 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14291 (speedbar-with-writable
14292 (save-excursion
14293 (end-of-line) (forward-char 1)
14294 ;; insert instance hierarchy
14295 (when hier-alist
14296 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14297 (while hier-alist
14298 (setq entry (car hier-alist))
14299 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14300 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14301 (vhdl-speedbar-make-inst-line
14302 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14303 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14304 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14305 (setq hier-alist (cdr hier-alist)))
14306 ;; insert required packages
14307 (vhdl-speedbar-insert-subpackages
14308 subpack-alist (1+ indent) indent)))
14309 (when (memq 'display vhdl-speedbar-save-cache)
14310 (add-to-list 'vhdl-updated-project-list key))
14311 (vhdl-speedbar-update-current-unit t t))))
14312 ((string-match "-" text) ; contract configuration
14313 (speedbar-change-expand-button-char ?+)
14314 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14315 (let* ((key (vhdl-speedbar-line-key indent))
14316 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14317 (adelete 'unit-alist token)
14318 (if unit-alist
14319 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14320 (adelete 'vhdl-speedbar-shown-unit-alist key))
14321 (speedbar-delete-subblock indent)
14322 (when (memq 'display vhdl-speedbar-save-cache)
14323 (add-to-list 'vhdl-updated-project-list key))))
14324 (t (error "Nothing to display")))
14325 (when (equal (selected-frame) speedbar-frame)
14326 (speedbar-center-buffer-smartly)))
14327
14328 (defun vhdl-speedbar-expand-package (text token indent)
14329 "Expand/contract the package under the cursor."
14330 (cond
14331 ((string-match "+" text) ; expand package
14332 (let* ((key (vhdl-speedbar-line-key indent))
14333 (pack-alist (aget vhdl-package-alist key t))
14334 (pack-entry (aget pack-alist token t))
14335 (comp-alist (nth 3 pack-entry))
14336 (func-alist (nth 4 pack-entry))
14337 (func-body-alist (nth 8 pack-entry))
14338 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14339 comp-entry func-entry func-body-entry)
14340 (if (not (or comp-alist func-alist subpack-alist))
14341 (speedbar-change-expand-button-char ??)
14342 (speedbar-change-expand-button-char ?-)
14343 ;; add package to `vhdl-speedbar-shown-unit-alist'
14344 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14345 (aput 'unit-alist token nil)
14346 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14347 (speedbar-with-writable
14348 (save-excursion
14349 (end-of-line) (forward-char 1)
14350 ;; insert components
14351 (when comp-alist
14352 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14353 (while comp-alist
14354 (setq comp-entry (car comp-alist))
14355 (speedbar-make-tag-line
14356 nil nil nil
14357 (cons token (nth 0 comp-entry))
14358 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14359 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14360 'vhdl-speedbar-entity-face (1+ indent))
14361 (setq comp-alist (cdr comp-alist)))
14362 ;; insert subprograms
14363 (when func-alist
14364 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14365 (while func-alist
14366 (setq func-entry (car func-alist)
14367 func-body-entry (aget func-body-alist (car func-entry) t))
14368 (when (nth 2 func-entry)
14369 (vhdl-speedbar-make-subprogram-line
14370 (nth 1 func-entry)
14371 (cons (nth 2 func-entry) (nth 3 func-entry))
14372 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14373 (1+ indent)))
14374 (setq func-alist (cdr func-alist)))
14375 ;; insert required packages
14376 (vhdl-speedbar-insert-subpackages
14377 subpack-alist (1+ indent) indent)))
14378 (when (memq 'display vhdl-speedbar-save-cache)
14379 (add-to-list 'vhdl-updated-project-list key))
14380 (vhdl-speedbar-update-current-unit t t))))
14381 ((string-match "-" text) ; contract package
14382 (speedbar-change-expand-button-char ?+)
14383 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14384 (let* ((key (vhdl-speedbar-line-key indent))
14385 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14386 (adelete 'unit-alist token)
14387 (if unit-alist
14388 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14389 (adelete 'vhdl-speedbar-shown-unit-alist key))
14390 (speedbar-delete-subblock indent)
14391 (when (memq 'display vhdl-speedbar-save-cache)
14392 (add-to-list 'vhdl-updated-project-list key))))
14393 (t (error "Nothing to display")))
14394 (when (equal (selected-frame) speedbar-frame)
14395 (speedbar-center-buffer-smartly)))
14396
14397 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14398 "Insert required packages."
14399 (let* ((pack-alist (aget vhdl-package-alist
14400 (vhdl-speedbar-line-key dir-indent) t))
14401 pack-key lib-name pack-entry)
14402 (when subpack-alist
14403 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14404 (while subpack-alist
14405 (setq pack-key (cdar subpack-alist)
14406 lib-name (caar subpack-alist))
14407 (setq pack-entry (aget pack-alist pack-key t))
14408 (vhdl-speedbar-make-subpack-line
14409 (or (nth 0 pack-entry) pack-key) lib-name
14410 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14411 (setq subpack-alist (cdr subpack-alist)))))
14412
14413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14414 ;; Display help functions
14415
14416 (defvar vhdl-speedbar-update-current-unit t
14417 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14418
14419 (defun vhdl-speedbar-update-current-project ()
14420 "Highlight project that is currently active."
14421 (when (and vhdl-speedbar-show-projects
14422 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14423 (and (boundp 'speedbar-frame)
14424 (frame-live-p speedbar-frame)))
14425 (let ((last-frame (selected-frame))
14426 (project-alist vhdl-project-alist)
14427 pos)
14428 (select-frame speedbar-frame)
14429 (speedbar-with-writable
14430 (save-excursion
14431 (while project-alist
14432 (goto-char (point-min))
14433 (when (re-search-forward
14434 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14435 (put-text-property (match-beginning 1) (match-end 1) 'face
14436 (if (equal (caar project-alist) vhdl-project)
14437 'speedbar-selected-face
14438 'speedbar-directory-face))
14439 (when (equal (caar project-alist) vhdl-project)
14440 (setq pos (1- (match-beginning 1)))))
14441 (setq project-alist (cdr project-alist))))
14442 (when pos (goto-char pos)))
14443 (select-frame last-frame)
14444 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14445 t)
14446
14447 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14448 "Highlight all design units that are contained in the current file.
14449 NO-POSITION non-nil means do not re-position cursor."
14450 (let ((last-frame (selected-frame))
14451 (project-list vhdl-speedbar-shown-project-list)
14452 file-alist pos file-name)
14453 ;; get current file name
14454 (if (fboundp 'speedbar-select-attached-frame)
14455 (speedbar-select-attached-frame)
14456 (select-frame speedbar-attached-frame))
14457 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14458 (when (and vhdl-speedbar-update-current-unit
14459 (or always (not (equal file-name speedbar-last-selected-file))))
14460 (if vhdl-speedbar-show-projects
14461 (while project-list
14462 (setq file-alist (append file-alist (aget vhdl-file-alist
14463 (car project-list) t)))
14464 (setq project-list (cdr project-list)))
14465 (setq file-alist (aget vhdl-file-alist
14466 (abbreviate-file-name default-directory) t)))
14467 (select-frame speedbar-frame)
14468 (set-buffer speedbar-buffer)
14469 (speedbar-with-writable
14470 (vhdl-prepare-search-1
14471 (save-excursion
14472 ;; unhighlight last units
14473 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14474 (vhdl-speedbar-update-units
14475 "\\[.\\] " (nth 0 file-entry)
14476 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14477 (vhdl-speedbar-update-units
14478 "{.} " (nth 1 file-entry)
14479 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14480 (vhdl-speedbar-update-units
14481 "\\[.\\] " (nth 3 file-entry)
14482 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14483 (vhdl-speedbar-update-units
14484 "[]>] " (nth 4 file-entry)
14485 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14486 (vhdl-speedbar-update-units
14487 "\\[.\\].+(" '("body")
14488 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14489 (vhdl-speedbar-update-units
14490 "> " (nth 6 file-entry)
14491 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14492 ;; highlight current units
14493 (let* ((file-entry (aget file-alist file-name t)))
14494 (setq
14495 pos (vhdl-speedbar-update-units
14496 "\\[.\\] " (nth 0 file-entry)
14497 file-name 'vhdl-speedbar-entity-selected-face pos)
14498 pos (vhdl-speedbar-update-units
14499 "{.} " (nth 1 file-entry)
14500 file-name 'vhdl-speedbar-architecture-selected-face pos)
14501 pos (vhdl-speedbar-update-units
14502 "\\[.\\] " (nth 3 file-entry)
14503 file-name 'vhdl-speedbar-configuration-selected-face pos)
14504 pos (vhdl-speedbar-update-units
14505 "[]>] " (nth 4 file-entry)
14506 file-name 'vhdl-speedbar-package-selected-face pos)
14507 pos (vhdl-speedbar-update-units
14508 "\\[.\\].+(" '("body")
14509 file-name 'vhdl-speedbar-package-selected-face pos)
14510 pos (vhdl-speedbar-update-units
14511 "> " (nth 6 file-entry)
14512 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14513 ;; move speedbar so the first highlighted unit is visible
14514 (when (and pos (not no-position))
14515 (goto-char pos)
14516 (speedbar-center-buffer-smartly)
14517 (speedbar-position-cursor-on-line))
14518 (setq speedbar-last-selected-file file-name))
14519 (select-frame last-frame)
14520 t))
14521
14522 (defun vhdl-speedbar-update-units (text unit-list file-name face
14523 &optional pos)
14524 "Help function to highlight design units."
14525 (while unit-list
14526 (goto-char (point-min))
14527 (while (re-search-forward
14528 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14529 (when (equal file-name (car (get-text-property
14530 (match-beginning 1) 'speedbar-token)))
14531 (setq pos (or pos (point-marker)))
14532 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14533 (setq unit-list (cdr unit-list)))
14534 pos)
14535
14536 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14537 ent-name ent-file-marker
14538 arch-name arch-file-marker
14539 conf-name conf-file-marker
14540 lib-name depth offset delimiter)
14541 "Insert instantiation entry."
14542 (let ((start (point))
14543 visible-start)
14544 (insert (int-to-string depth) ":")
14545 (put-text-property start (point) 'invisible t)
14546 (setq visible-start (point))
14547 (insert-char ? (* depth speedbar-indentation-width))
14548 (while (> offset 0)
14549 (insert "|")
14550 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14551 (setq offset (1- offset)))
14552 (put-text-property visible-start (point) 'invisible nil)
14553 (setq start (point))
14554 (insert ">")
14555 (speedbar-make-button start (point) nil nil nil)
14556 (setq visible-start (point))
14557 (insert " ")
14558 (setq start (point))
14559 (if (not inst-name)
14560 (insert "(top)")
14561 (insert inst-name)
14562 (speedbar-make-button
14563 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14564 'vhdl-speedbar-find-file inst-file-marker))
14565 (insert delimiter)
14566 (when ent-name
14567 (setq start (point))
14568 (insert ent-name)
14569 (speedbar-make-button
14570 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14571 'vhdl-speedbar-find-file ent-file-marker)
14572 (when arch-name
14573 (insert " (")
14574 (setq start (point))
14575 (insert arch-name)
14576 (speedbar-make-button
14577 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14578 'vhdl-speedbar-find-file arch-file-marker)
14579 (insert ")"))
14580 (when conf-name
14581 (insert " (")
14582 (setq start (point))
14583 (insert conf-name)
14584 (speedbar-make-button
14585 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14586 'vhdl-speedbar-find-file conf-file-marker)
14587 (insert ")")))
14588 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14589 (setq start (point))
14590 (insert " (" lib-name ")")
14591 (put-text-property (+ 2 start) (1- (point)) 'face
14592 'vhdl-speedbar-library-face))
14593 (insert-char ?\n 1)
14594 (put-text-property visible-start (point) 'invisible nil)))
14595
14596 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14597 body-file-marker depth)
14598 "Insert package entry."
14599 (let ((start (point))
14600 visible-start)
14601 (insert (int-to-string depth) ":")
14602 (put-text-property start (point) 'invisible t)
14603 (setq visible-start (point))
14604 (insert-char ? (* depth speedbar-indentation-width))
14605 (put-text-property visible-start (point) 'invisible nil)
14606 (setq start (point))
14607 (insert "[+]")
14608 (speedbar-make-button
14609 start (point) 'speedbar-button-face 'speedbar-highlight-face
14610 'vhdl-speedbar-expand-package pack-key)
14611 (setq visible-start (point))
14612 (insert-char ? 1 nil)
14613 (setq start (point))
14614 (insert pack-name)
14615 (speedbar-make-button
14616 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14617 'vhdl-speedbar-find-file pack-file-marker)
14618 (unless (car pack-file-marker)
14619 (insert "!"))
14620 (when (car body-file-marker)
14621 (insert " (")
14622 (setq start (point))
14623 (insert "body")
14624 (speedbar-make-button
14625 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14626 'vhdl-speedbar-find-file body-file-marker)
14627 (insert ")"))
14628 (insert-char ?\n 1)
14629 (put-text-property visible-start (point) 'invisible nil)))
14630
14631 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14632 depth)
14633 "Insert used package entry."
14634 (let ((start (point))
14635 visible-start)
14636 (insert (int-to-string depth) ":")
14637 (put-text-property start (point) 'invisible t)
14638 (setq visible-start (point))
14639 (insert-char ? (* depth speedbar-indentation-width))
14640 (put-text-property visible-start (point) 'invisible nil)
14641 (setq start (point))
14642 (insert ">")
14643 (speedbar-make-button start (point) nil nil nil)
14644 (setq visible-start (point))
14645 (insert " ")
14646 (setq start (point))
14647 (insert pack-name)
14648 (speedbar-make-button
14649 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14650 'vhdl-speedbar-find-file pack-file-marker)
14651 (setq start (point))
14652 (insert " (" lib-name ")")
14653 (put-text-property (+ 2 start) (1- (point)) 'face
14654 'vhdl-speedbar-library-face)
14655 (insert-char ?\n 1)
14656 (put-text-property visible-start (point) 'invisible nil)))
14657
14658 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14659 func-body-file-marker
14660 depth)
14661 "Insert subprogram entry."
14662 (let ((start (point))
14663 visible-start)
14664 (insert (int-to-string depth) ":")
14665 (put-text-property start (point) 'invisible t)
14666 (setq visible-start (point))
14667 (insert-char ? (* depth speedbar-indentation-width))
14668 (put-text-property visible-start (point) 'invisible nil)
14669 (setq start (point))
14670 (insert ">")
14671 (speedbar-make-button start (point) nil nil nil)
14672 (setq visible-start (point))
14673 (insert " ")
14674 (setq start (point))
14675 (insert func-name)
14676 (speedbar-make-button
14677 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14678 'vhdl-speedbar-find-file func-file-marker)
14679 (when (car func-body-file-marker)
14680 (insert " (")
14681 (setq start (point))
14682 (insert "body")
14683 (speedbar-make-button
14684 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14685 'vhdl-speedbar-find-file func-body-file-marker)
14686 (insert ")"))
14687 (insert-char ?\n 1)
14688 (put-text-property visible-start (point) 'invisible nil)))
14689
14690 (defun vhdl-speedbar-make-title-line (text &optional depth)
14691 "Insert design unit title entry."
14692 (let ((start (point))
14693 visible-start)
14694 (when depth
14695 (insert (int-to-string depth) ":")
14696 (put-text-property start (point) 'invisible t))
14697 (setq visible-start (point))
14698 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14699 (setq start (point))
14700 (insert text)
14701 (speedbar-make-button start (point) nil nil nil nil)
14702 (insert-char ?\n 1)
14703 (put-text-property visible-start (point) 'invisible nil)))
14704
14705 (defun vhdl-speedbar-insert-dirs (files level)
14706 "Insert subdirectories."
14707 (let ((dirs (car files)))
14708 (while dirs
14709 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14710 (car dirs) 'speedbar-dir-follow nil
14711 'speedbar-directory-face level)
14712 (setq dirs (cdr dirs)))))
14713
14714 (defun vhdl-speedbar-dired (text token indent)
14715 "Speedbar click handler for directory expand button in hierarchy mode."
14716 (cond ((string-match "+" text) ; we have to expand this dir
14717 (setq speedbar-shown-directories
14718 (cons (expand-file-name
14719 (concat (speedbar-line-path indent) token "/"))
14720 speedbar-shown-directories))
14721 (speedbar-change-expand-button-char ?-)
14722 (speedbar-reset-scanners)
14723 (speedbar-with-writable
14724 (save-excursion
14725 (end-of-line) (forward-char 1)
14726 (vhdl-speedbar-insert-dirs
14727 (speedbar-file-lists
14728 (concat (speedbar-line-path indent) token "/"))
14729 (1+ indent))
14730 (speedbar-reset-scanners)
14731 (vhdl-speedbar-insert-dir-hierarchy
14732 (abbreviate-file-name
14733 (concat (speedbar-line-path indent) token "/"))
14734 (1+ indent) speedbar-power-click)))
14735 (vhdl-speedbar-update-current-unit t t))
14736 ((string-match "-" text) ; we have to contract this node
14737 (speedbar-reset-scanners)
14738 (let ((oldl speedbar-shown-directories)
14739 (newl nil)
14740 (td (expand-file-name
14741 (concat (speedbar-line-path indent) token))))
14742 (while oldl
14743 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14744 (setq newl (cons (car oldl) newl)))
14745 (setq oldl (cdr oldl)))
14746 (setq speedbar-shown-directories (nreverse newl)))
14747 (speedbar-change-expand-button-char ?+)
14748 (speedbar-delete-subblock indent))
14749 (t (error "Nothing to display")))
14750 (when (equal (selected-frame) speedbar-frame)
14751 (speedbar-center-buffer-smartly)))
14752
14753 (defun vhdl-speedbar-item-info ()
14754 "Derive and display information about this line item."
14755 (save-excursion
14756 (beginning-of-line)
14757 ;; skip invisible number info
14758 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14759 (cond
14760 ;; project/directory entry
14761 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14762 (if vhdl-speedbar-show-projects
14763 (message "Project \"%s\"" (match-string-no-properties 1))
14764 (speedbar-files-item-info)))
14765 ;; design unit entry
14766 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14767 (goto-char (match-end 1))
14768 (let ((face (get-text-property (point) 'face)))
14769 (message
14770 "%s \"%s\" in \"%s\""
14771 ;; design unit kind
14772 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14773 (eq face 'vhdl-speedbar-entity-selected-face))
14774 (if (equal (match-string 2) ">") "Component" "Entity"))
14775 ((or (eq face 'vhdl-speedbar-architecture-face)
14776 (eq face 'vhdl-speedbar-architecture-selected-face))
14777 "Architecture")
14778 ((or (eq face 'vhdl-speedbar-configuration-face)
14779 (eq face 'vhdl-speedbar-configuration-selected-face))
14780 "Configuration")
14781 ((or (eq face 'vhdl-speedbar-package-face)
14782 (eq face 'vhdl-speedbar-package-selected-face))
14783 "Package")
14784 ((or (eq face 'vhdl-speedbar-instantiation-face)
14785 (eq face 'vhdl-speedbar-instantiation-selected-face))
14786 "Instantiation")
14787 ((eq face 'vhdl-speedbar-subprogram-face)
14788 "Subprogram")
14789 (t ""))
14790 ;; design unit name
14791 (buffer-substring-no-properties
14792 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14793 (match-end 1))
14794 ;; file name
14795 (file-relative-name
14796 (or (car (get-text-property (point) 'speedbar-token))
14797 "?")
14798 (vhdl-default-directory)))))
14799 (t (message "")))))
14800
14801 (defun vhdl-speedbar-line-text ()
14802 "Calls `speedbar-line-text' and removes text properties."
14803 (let ((string (speedbar-line-text)))
14804 (set-text-properties 0 (length string) nil string)
14805 string))
14806
14807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14808 ;; Help functions
14809
14810 (defun vhdl-speedbar-line-key (&optional indent)
14811 "Get currently displayed directory of project name."
14812 (if vhdl-speedbar-show-projects
14813 (vhdl-speedbar-line-project)
14814 (abbreviate-file-name
14815 (file-name-as-directory (speedbar-line-path indent)))))
14816
14817 (defun vhdl-speedbar-line-project (&optional indent)
14818 "Get currently displayed project name."
14819 (and vhdl-speedbar-show-projects
14820 (save-excursion
14821 (end-of-line)
14822 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14823 (match-string-no-properties 1))))
14824
14825 (defun vhdl-add-modified-file ()
14826 "Add file to `vhdl-modified-file-list'."
14827 (when vhdl-file-alist
14828 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14829 nil)
14830
14831 (defun vhdl-resolve-paths (path-list)
14832 "Resolve path wildcards in PATH-LIST."
14833 (let (path-list-1 path-list-2 path-beg path-end dir)
14834 ;; eliminate non-existent directories
14835 (while path-list
14836 (setq dir (car path-list))
14837 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14838 (if (file-directory-p (match-string 2 dir))
14839 (setq path-list-1 (cons dir path-list-1))
14840 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
14841 (setq path-list (cdr path-list)))
14842 ;; resolve path wildcards
14843 (while path-list-1
14844 (setq dir (car path-list-1))
14845 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
14846 (progn
14847 (setq path-beg (match-string 1 dir)
14848 path-end (match-string 5 dir))
14849 (setq path-list-1
14850 (append
14851 (mapcar
14852 (function
14853 (lambda (var) (concat path-beg var path-end)))
14854 (let ((all-list (vhdl-directory-files
14855 (match-string 2 dir) t
14856 (concat "\\<" (wildcard-to-regexp
14857 (match-string 4 dir)))))
14858 dir-list)
14859 (while all-list
14860 (when (file-directory-p (car all-list))
14861 (setq dir-list (cons (car all-list) dir-list)))
14862 (setq all-list (cdr all-list)))
14863 dir-list))
14864 (cdr path-list-1))))
14865 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
14866 (when (file-directory-p (match-string 2 dir))
14867 (setq path-list-2 (cons dir path-list-2)))
14868 (setq path-list-1 (cdr path-list-1))))
14869 (nreverse path-list-2)))
14870
14871 (defun vhdl-speedbar-goto-this-unit (directory unit)
14872 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14873 (let ((dest (point)))
14874 (if (and (if vhdl-speedbar-show-projects
14875 (progn (goto-char (point-min)) t)
14876 (speedbar-goto-this-file directory))
14877 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14878 (progn (speedbar-position-cursor-on-line)
14879 t)
14880 (goto-char dest)
14881 nil)))
14882
14883 (defun vhdl-speedbar-find-file (text token indent)
14884 "When user clicks on TEXT, load file with name and position in TOKEN.
14885 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14886 is already shown in a buffer."
14887 (if (not (car token))
14888 (error "ERROR: File cannot be found")
14889 (let ((buffer (get-file-buffer (car token))))
14890 (speedbar-find-file-in-frame (car token))
14891 (when (or vhdl-speedbar-jump-to-unit buffer)
14892 (goto-line (cdr token))
14893 (recenter))
14894 (vhdl-speedbar-update-current-unit t t)
14895 (speedbar-set-timer speedbar-update-speed)
14896 (speedbar-maybee-jump-to-attached-frame))))
14897
14898 (defun vhdl-speedbar-port-copy ()
14899 "Copy the port of the entity/component or subprogram under the cursor."
14900 (interactive)
14901 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14902 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14903 (error "ERROR: No entity/component or subprogram under cursor")
14904 (beginning-of-line)
14905 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14906 (condition-case info
14907 (let ((token (get-text-property
14908 (match-beginning 3) 'speedbar-token)))
14909 (vhdl-visit-file (car token) t
14910 (progn (goto-line (cdr token))
14911 (end-of-line)
14912 (if is-entity
14913 (vhdl-port-copy)
14914 (vhdl-subprog-copy)))))
14915 (error (error "ERROR: %s not scanned successfully\n (%s)"
14916 (if is-entity "Port" "Interface") (cadr info))))
14917 (error "ERROR: No entity/component or subprogram on current line")))))
14918
14919 (defun vhdl-speedbar-place-component ()
14920 "Place the entity/component under the cursor as component."
14921 (interactive)
14922 (if (not (vhdl-speedbar-check-unit 'entity))
14923 (error "ERROR: No entity/component under cursor.")
14924 (vhdl-speedbar-port-copy)
14925 (if (fboundp 'speedbar-select-attached-frame)
14926 (speedbar-select-attached-frame)
14927 (select-frame speedbar-attached-frame))
14928 (vhdl-compose-place-component)
14929 (select-frame speedbar-frame)))
14930
14931 (defun vhdl-speedbar-make-design ()
14932 "Make (compile) design unit or directory/project under the cursor."
14933 (interactive)
14934 (if (not (save-excursion (beginning-of-line)
14935 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14936 (error "ERROR: No primary design unit or directory/project under cursor")
14937 (let ((is-unit (match-string 2))
14938 (unit-name (vhdl-speedbar-line-text))
14939 (vhdl-project (vhdl-speedbar-line-project))
14940 (directory (file-name-as-directory
14941 (or (speedbar-line-file) (speedbar-line-path)))))
14942 (if (fboundp 'speedbar-select-attached-frame)
14943 (speedbar-select-attached-frame)
14944 (select-frame speedbar-attached-frame))
14945 (let ((default-directory directory))
14946 (vhdl-make (and is-unit unit-name))))))
14947
14948 (defun vhdl-speedbar-generate-makefile ()
14949 "Generate Makefile for directory/project under the cursor."
14950 (interactive)
14951 (let ((vhdl-project (vhdl-speedbar-line-project))
14952 (default-directory (file-name-as-directory
14953 (or (speedbar-line-file) (speedbar-line-path)))))
14954 (vhdl-generate-makefile)))
14955
14956 (defun vhdl-speedbar-check-unit (design-unit)
14957 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14958 expansion function)."
14959 (save-excursion
14960 (speedbar-position-cursor-on-line)
14961 (cond ((eq design-unit 'entity)
14962 (memq (get-text-property (match-end 0) 'face)
14963 '(vhdl-speedbar-entity-face
14964 vhdl-speedbar-entity-selected-face)))
14965 ((eq design-unit 'subprogram)
14966 (eq (get-text-property (match-end 0) 'face)
14967 'vhdl-speedbar-subprogram-face))
14968 (t nil))))
14969
14970 (defun vhdl-speedbar-set-depth (depth)
14971 "Set hierarchy display depth to DEPTH and refresh speedbar."
14972 (setq vhdl-speedbar-hierarchy-depth depth)
14973 (speedbar-refresh))
14974
14975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14976 ;; Fontification
14977
14978 (defface vhdl-speedbar-entity-face
14979 '((((class color) (background light)) (:foreground "ForestGreen"))
14980 (((class color) (background dark)) (:foreground "PaleGreen")))
14981 "Face used for displaying entity names."
14982 :group 'speedbar-faces)
14983
14984 (defface vhdl-speedbar-architecture-face
14985 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
14986 (((class color) (background light)) (:foreground "Blue"))
14987 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14988 "Face used for displaying architecture names."
14989 :group 'speedbar-faces)
14990
14991 (defface vhdl-speedbar-configuration-face
14992 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
14993 (((class color) (background dark)) (:foreground "Salmon")))
14994 "Face used for displaying configuration names."
14995 :group 'speedbar-faces)
14996
14997 (defface vhdl-speedbar-package-face
14998 '((((class color) (background light)) (:foreground "Grey50"))
14999 (((class color) (background dark)) (:foreground "Grey80")))
15000 "Face used for displaying package names."
15001 :group 'speedbar-faces)
15002
15003 (defface vhdl-speedbar-library-face
15004 '((((class color) (background light)) (:foreground "Purple"))
15005 (((class color) (background dark)) (:foreground "Orchid1")))
15006 "Face used for displaying library names."
15007 :group 'speedbar-faces)
15008
15009 (defface vhdl-speedbar-instantiation-face
15010 '((((class color) (background light)) (:foreground "Brown"))
15011 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15012 (((class color) (background dark)) (:foreground "Yellow")))
15013 "Face used for displaying instantiation names."
15014 :group 'speedbar-faces)
15015
15016 (defface vhdl-speedbar-subprogram-face
15017 '((((class color) (background light)) (:foreground "Orchid4"))
15018 (((class color) (background dark)) (:foreground "BurlyWood2")))
15019 "Face used for displaying subprogram names."
15020 :group 'speedbar-faces)
15021
15022 (defface vhdl-speedbar-entity-selected-face
15023 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15024 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15025 "Face used for displaying entity names."
15026 :group 'speedbar-faces)
15027
15028 (defface vhdl-speedbar-architecture-selected-face
15029 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15030 (((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15031 (((class color) (background light)) (:foreground "Blue" :underline t))
15032 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15033 "Face used for displaying architecture names."
15034 :group 'speedbar-faces)
15035
15036 (defface vhdl-speedbar-configuration-selected-face
15037 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15038 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15039 "Face used for displaying configuration names."
15040 :group 'speedbar-faces)
15041
15042 (defface vhdl-speedbar-package-selected-face
15043 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15044 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15045 "Face used for displaying package names."
15046 :group 'speedbar-faces)
15047
15048 (defface vhdl-speedbar-instantiation-selected-face
15049 '((((class color) (background light)) (:foreground "Brown" :underline t))
15050 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1" :underline t))
15051 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15052 "Face used for displaying instantiation names."
15053 :group 'speedbar-faces)
15054
15055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15056 ;; Initialization
15057
15058 ;; add speedbar
15059 (when (fboundp 'speedbar)
15060 (condition-case ()
15061 (when (and vhdl-speedbar-auto-open
15062 (not (and (boundp 'speedbar-frame)
15063 (frame-live-p speedbar-frame))))
15064 (speedbar-frame-mode 1)
15065 (if (fboundp 'speedbar-select-attached-frame)
15066 (speedbar-select-attached-frame)
15067 (select-frame speedbar-attached-frame)))
15068 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15069
15070 ;; initialize speedbar
15071 (if (not (boundp 'speedbar-frame))
15072 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15073 (vhdl-speedbar-initialize)
15074 (when speedbar-frame (vhdl-speedbar-refresh)))
15075
15076
15077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15078 ;;; Structural composition
15079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15080
15081 (defun vhdl-get-components-package-name ()
15082 "Return the name of the components package."
15083 (let ((project (vhdl-project-p)))
15084 (if project
15085 (vhdl-replace-string (car vhdl-components-package-name)
15086 (subst-char-in-string ? ?_ project))
15087 (cdr vhdl-components-package-name))))
15088
15089 (defun vhdl-compose-new-component ()
15090 "Create entity and architecture for new component."
15091 (interactive)
15092 (let* ((case-fold-search t)
15093 (ent-name (read-from-minibuffer "entity name: "
15094 nil vhdl-minibuffer-local-map))
15095 (arch-name
15096 (if (equal (cdr vhdl-compose-architecture-name) "")
15097 (read-from-minibuffer "architecture name: "
15098 nil vhdl-minibuffer-local-map)
15099 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15100 ent-file-name arch-file-name ent-buffer arch-buffer project)
15101 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15102 ;; open entity file
15103 (unless (eq vhdl-compose-create-files 'none)
15104 (setq ent-file-name
15105 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15106 "." (file-name-extension (buffer-file-name))))
15107 (when (and (file-exists-p ent-file-name)
15108 (not (y-or-n-p (concat "File \"" ent-file-name
15109 "\" exists; overwrite? "))))
15110 (error "ERROR: Creating component...aborted"))
15111 (find-file ent-file-name)
15112 (erase-buffer)
15113 (set-buffer-modified-p nil))
15114 ;; insert header
15115 (if vhdl-compose-include-header
15116 (progn (vhdl-template-header)
15117 (goto-char (point-max)))
15118 (vhdl-comment-display-line) (insert "\n\n"))
15119 ;; insert library clause
15120 (vhdl-template-package-std-logic-1164)
15121 (when vhdl-use-components-package
15122 (insert "\n")
15123 (vhdl-template-standard-package (vhdl-work-library)
15124 (vhdl-get-components-package-name)))
15125 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15126 ;; insert entity declaration
15127 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15128 (vhdl-insert-keyword " IS\n")
15129 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15130 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15131 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15132 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15133 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15134 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15135 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15136 (vhdl-insert-keyword "END ")
15137 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15138 (insert ent-name ";\n\n")
15139 (vhdl-comment-display-line) (insert "\n")
15140 ;; open architecture file
15141 (if (not (eq vhdl-compose-create-files 'separate))
15142 (insert "\n")
15143 (setq ent-buffer (current-buffer))
15144 (setq arch-file-name
15145 (concat (vhdl-replace-string vhdl-architecture-file-name
15146 (concat ent-name " " arch-name))
15147 "." (file-name-extension (buffer-file-name))))
15148 (when (and (file-exists-p arch-file-name)
15149 (not (y-or-n-p (concat "File \"" arch-file-name
15150 "\" exists; overwrite? "))))
15151 (error "ERROR: Creating component...aborted"))
15152 (find-file arch-file-name)
15153 (erase-buffer)
15154 (set-buffer-modified-p nil)
15155 ;; insert header
15156 (if vhdl-compose-include-header
15157 (progn (vhdl-template-header)
15158 (goto-char (point-max)))
15159 (vhdl-comment-display-line) (insert "\n\n")))
15160 ;; insert architecture body
15161 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15162 (vhdl-insert-keyword " OF ") (insert ent-name)
15163 (vhdl-insert-keyword " IS\n\n")
15164 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15165 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15166 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15167 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15168 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15169 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15170 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15171 (vhdl-insert-keyword "BEGIN")
15172 (when vhdl-self-insert-comments
15173 (insert " -- ")
15174 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15175 (insert arch-name))
15176 (insert "\n\n")
15177 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15178 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15179 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15180 (vhdl-insert-keyword "END ")
15181 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15182 (insert arch-name ";\n\n")
15183 ;; insert footer
15184 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15185 (vhdl-template-footer)
15186 (vhdl-comment-display-line) (insert "\n"))
15187 (goto-char (point-min))
15188 (setq arch-buffer (current-buffer))
15189 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15190 (set-buffer arch-buffer) (save-buffer)
15191 (message
15192 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15193 (and ent-file-name
15194 (format "\n File created: \"%s\"" ent-file-name))
15195 (and arch-file-name
15196 (format "\n File created: \"%s\"" arch-file-name))))))
15197
15198 (defun vhdl-compose-place-component ()
15199 "Place new component by pasting current port as component declaration and
15200 component instantiation."
15201 (interactive)
15202 (if (not vhdl-port-list)
15203 (error "ERROR: No port has been read")
15204 (save-excursion
15205 (vhdl-prepare-search-2
15206 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15207 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15208 (error "ERROR: No architecture found"))
15209 (let* ((ent-name (match-string 1))
15210 (ent-file-name
15211 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15212 "." (file-name-extension (buffer-file-name))))
15213 (orig-buffer (current-buffer)))
15214 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15215 ;; place component declaration
15216 (unless (or vhdl-use-components-package
15217 (vhdl-use-direct-instantiation)
15218 (save-excursion
15219 (re-search-forward
15220 (concat "^\\s-*component\\s-+"
15221 (car vhdl-port-list) "\\>") nil t)))
15222 (re-search-forward "^begin\\>" nil)
15223 (beginning-of-line)
15224 (skip-chars-backward " \t\n")
15225 (insert "\n\n") (indent-to vhdl-basic-offset)
15226 (vhdl-port-paste-component t))
15227 ;; place component instantiation
15228 (re-search-forward "^end\\>" nil)
15229 (beginning-of-line)
15230 (skip-chars-backward " \t\n")
15231 (insert "\n\n") (indent-to vhdl-basic-offset)
15232 (vhdl-port-paste-instance nil t t)
15233 ;; place use clause for used packages
15234 (when (nth 3 vhdl-port-list)
15235 ;; open entity file
15236 (when (file-exists-p ent-file-name)
15237 (find-file ent-file-name))
15238 (goto-char (point-min))
15239 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15240 (error "ERROR: Entity not found: \"%s\"" ent-name))
15241 (goto-char (match-beginning 0))
15242 (if (and (save-excursion
15243 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15244 (match-string 1))
15245 (progn (goto-char (match-end 0))
15246 (beginning-of-line 2))
15247 (insert "\n")
15248 (backward-char))
15249 (vhdl-port-paste-context-clause)
15250 (switch-to-buffer orig-buffer))
15251 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15252
15253 (defun vhdl-compose-wire-components ()
15254 "Connect components."
15255 (interactive)
15256 (save-excursion
15257 (vhdl-prepare-search-2
15258 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15259 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15260 (error "ERROR: No architecture found"))
15261 (let* ((ent-name (match-string 1))
15262 (ent-file-name
15263 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15264 "." (file-name-extension (buffer-file-name))))
15265 (arch-decl-pos (point-marker))
15266 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15267 (arch-end-pos (re-search-forward "^end\\>" nil))
15268 (pack-name (vhdl-get-components-package-name))
15269 (pack-file-name
15270 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15271 "." (file-name-extension (buffer-file-name))))
15272 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15273 port-alist generic-alist inst-alist
15274 signal-name signal-entry signal-alist local-list written-list
15275 single-in-list multi-in-list single-out-list multi-out-list
15276 constant-name constant-entry constant-alist single-list multi-list
15277 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15278 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15279 signal-beg-pos signal-pos
15280 constant-temp-pos port-temp-pos signal-temp-pos)
15281 (message "Wiring components...")
15282 ;; process all instances
15283 (goto-char arch-stat-pos)
15284 (while (re-search-forward
15285 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15286 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15287 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15288 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15289 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15290 (setq inst-name (match-string-no-properties 1)
15291 comp-name (match-string-no-properties 4)
15292 comp-ent-name (match-string-no-properties 12)
15293 has-generic (or (match-string 7) (match-string 17)))
15294 ;; get port ...
15295 (if comp-name
15296 ;; ... from component declaration
15297 (vhdl-visit-file
15298 (when vhdl-use-components-package pack-file-name) t
15299 (save-excursion
15300 (goto-char (point-min))
15301 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15302 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15303 (vhdl-port-copy)))
15304 ;; ... from entity declaration (direct instantiation)
15305 (setq comp-ent-file-name
15306 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15307 "." (file-name-extension (buffer-file-name))))
15308 (vhdl-visit-file
15309 comp-ent-file-name t
15310 (save-excursion
15311 (goto-char (point-min))
15312 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15313 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15314 (vhdl-port-copy))))
15315 (vhdl-port-flatten t)
15316 (setq generic-alist (nth 1 vhdl-port-list)
15317 port-alist (nth 2 vhdl-port-list))
15318 (setq constant-alist nil
15319 signal-alist nil)
15320 (when has-generic
15321 ;; process all constants in generic map
15322 (vhdl-forward-syntactic-ws)
15323 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15324 (setq constant-name (match-string-no-properties 3))
15325 (setq constant-entry
15326 (cons constant-name
15327 (if (match-string 1)
15328 (or (aget generic-alist (match-string 2) t)
15329 (error (format "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15330 (cdar generic-alist))))
15331 (setq constant-alist (cons constant-entry constant-alist))
15332 (setq constant-name (downcase constant-name))
15333 (if (or (member constant-name single-list)
15334 (member constant-name multi-list))
15335 (progn (setq single-list (delete constant-name single-list))
15336 (add-to-list 'multi-list constant-name))
15337 (add-to-list 'single-list constant-name))
15338 (unless (match-string 1)
15339 (setq generic-alist (cdr generic-alist)))
15340 (vhdl-forward-syntactic-ws))
15341 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15342 ;; process all signals in port map
15343 (vhdl-forward-syntactic-ws)
15344 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15345 (setq signal-name (match-string-no-properties 3))
15346 (setq signal-entry (cons signal-name
15347 (if (match-string 1)
15348 (or (aget port-alist (match-string 2) t)
15349 (error (format "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15350 (cdar port-alist))))
15351 (setq signal-alist (cons signal-entry signal-alist))
15352 (setq signal-name (downcase signal-name))
15353 (if (equal (upcase (nth 2 signal-entry)) "IN")
15354 ;; input signal
15355 (cond
15356 ((member signal-name local-list)
15357 nil)
15358 ((or (member signal-name single-out-list)
15359 (member signal-name multi-out-list))
15360 (setq single-out-list (delete signal-name single-out-list))
15361 (setq multi-out-list (delete signal-name multi-out-list))
15362 (add-to-list 'local-list signal-name))
15363 ((member signal-name single-in-list)
15364 (setq single-in-list (delete signal-name single-in-list))
15365 (add-to-list 'multi-in-list signal-name))
15366 ((not (member signal-name multi-in-list))
15367 (add-to-list 'single-in-list signal-name)))
15368 ;; output signal
15369 (cond
15370 ((member signal-name local-list)
15371 nil)
15372 ((or (member signal-name single-in-list)
15373 (member signal-name multi-in-list))
15374 (setq single-in-list (delete signal-name single-in-list))
15375 (setq multi-in-list (delete signal-name multi-in-list))
15376 (add-to-list 'local-list signal-name))
15377 ((member signal-name single-out-list)
15378 (setq single-out-list (delete signal-name single-out-list))
15379 (add-to-list 'multi-out-list signal-name))
15380 ((not (member signal-name multi-out-list))
15381 (add-to-list 'single-out-list signal-name))))
15382 (unless (match-string 1)
15383 (setq port-alist (cdr port-alist)))
15384 (vhdl-forward-syntactic-ws))
15385 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15386 (nreverse signal-alist)) inst-alist)))
15387 ;; prepare signal insertion
15388 (vhdl-goto-marker arch-decl-pos)
15389 (forward-line 1)
15390 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15391 (setq signal-pos (point-marker))
15392 (while (progn (vhdl-forward-syntactic-ws)
15393 (looking-at "signal\\>"))
15394 (beginning-of-line 2)
15395 (delete-region signal-pos (point)))
15396 (setq signal-beg-pos signal-pos)
15397 ;; open entity file
15398 (when (file-exists-p ent-file-name)
15399 (find-file ent-file-name))
15400 (goto-char (point-min))
15401 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15402 (error "ERROR: Entity not found: \"%s\"" ent-name))
15403 ;; prepare generic clause insertion
15404 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15405 (match-string 1))
15406 (goto-char (match-beginning 0))
15407 (indent-to vhdl-basic-offset)
15408 (insert "generic ();\n\n")
15409 (backward-char 4))
15410 (backward-char)
15411 (setq generic-pos (point-marker))
15412 (forward-sexp) (end-of-line)
15413 (delete-region generic-pos (point)) (delete-char 1)
15414 (insert "(\n")
15415 (when multi-list
15416 (insert "\n")
15417 (indent-to (* 2 vhdl-basic-offset))
15418 (insert "-- global generics\n"))
15419 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15420 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15421 ;; prepare port clause insertion
15422 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15423 (match-string 1))
15424 (goto-char (match-beginning 0))
15425 (indent-to vhdl-basic-offset)
15426 (insert "port ();\n\n")
15427 (backward-char 4))
15428 (backward-char)
15429 (setq port-in-pos (point-marker))
15430 (forward-sexp) (end-of-line)
15431 (delete-region port-in-pos (point)) (delete-char 1)
15432 (insert "(\n")
15433 (when (or multi-in-list multi-out-list)
15434 (insert "\n")
15435 (indent-to (* 2 vhdl-basic-offset))
15436 (insert "-- global ports\n"))
15437 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15438 port-out-pos (point-marker) port-inst-pos (point-marker)
15439 port-end-pos (point-marker))
15440 ;; insert generics, ports and signals
15441 (setq inst-alist (nreverse inst-alist))
15442 (while inst-alist
15443 (setq inst-name (nth 0 (car inst-alist))
15444 constant-alist (nth 1 (car inst-alist))
15445 signal-alist (nth 2 (car inst-alist))
15446 constant-temp-pos generic-inst-pos
15447 port-temp-pos port-inst-pos
15448 signal-temp-pos signal-pos)
15449 ;; generics
15450 (while constant-alist
15451 (setq constant-name (downcase (caar constant-alist))
15452 constant-entry (car constant-alist))
15453 (cond ((member constant-name written-list)
15454 nil)
15455 ((member constant-name multi-list)
15456 (vhdl-goto-marker generic-pos)
15457 (setq generic-end-pos
15458 (vhdl-max-marker
15459 generic-end-pos
15460 (vhdl-compose-insert-generic constant-entry)))
15461 (setq generic-pos (point-marker))
15462 (add-to-list 'written-list constant-name))
15463 (t
15464 (vhdl-goto-marker
15465 (vhdl-max-marker generic-inst-pos generic-pos))
15466 (setq generic-end-pos
15467 (vhdl-compose-insert-generic constant-entry))
15468 (setq generic-inst-pos (point-marker))
15469 (add-to-list 'written-list constant-name)))
15470 (setq constant-alist (cdr constant-alist)))
15471 (when (/= constant-temp-pos generic-inst-pos)
15472 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15473 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15474 (insert "-- generics for \"" inst-name "\"\n")
15475 (vhdl-goto-marker generic-inst-pos))
15476 ;; ports and signals
15477 (while signal-alist
15478 (setq signal-name (downcase (caar signal-alist))
15479 signal-entry (car signal-alist))
15480 (cond ((member signal-name written-list)
15481 nil)
15482 ((member signal-name multi-in-list)
15483 (vhdl-goto-marker port-in-pos)
15484 (setq port-end-pos
15485 (vhdl-max-marker
15486 port-end-pos (vhdl-compose-insert-port signal-entry)))
15487 (setq port-in-pos (point-marker))
15488 (add-to-list 'written-list signal-name))
15489 ((member signal-name multi-out-list)
15490 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15491 (setq port-end-pos
15492 (vhdl-max-marker
15493 port-end-pos (vhdl-compose-insert-port signal-entry)))
15494 (setq port-out-pos (point-marker))
15495 (add-to-list 'written-list signal-name))
15496 ((or (member signal-name single-in-list)
15497 (member signal-name single-out-list))
15498 (vhdl-goto-marker
15499 (vhdl-max-marker
15500 port-inst-pos
15501 (vhdl-max-marker port-out-pos port-in-pos)))
15502 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15503 (setq port-inst-pos (point-marker))
15504 (add-to-list 'written-list signal-name))
15505 ((equal (upcase (nth 2 signal-entry)) "OUT")
15506 (vhdl-goto-marker signal-pos)
15507 (vhdl-compose-insert-signal signal-entry)
15508 (setq signal-pos (point-marker))
15509 (add-to-list 'written-list signal-name)))
15510 (setq signal-alist (cdr signal-alist)))
15511 (when (/= port-temp-pos port-inst-pos)
15512 (vhdl-goto-marker
15513 (vhdl-max-marker port-temp-pos
15514 (vhdl-max-marker port-in-pos port-out-pos)))
15515 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15516 (insert "-- ports to \"" inst-name "\"\n")
15517 (vhdl-goto-marker port-inst-pos))
15518 (when (/= signal-temp-pos signal-pos)
15519 (vhdl-goto-marker signal-temp-pos)
15520 (insert "\n") (indent-to vhdl-basic-offset)
15521 (insert "-- outputs of \"" inst-name "\"\n")
15522 (vhdl-goto-marker signal-pos))
15523 (setq inst-alist (cdr inst-alist)))
15524 ;; finalize generic/port clause
15525 (vhdl-goto-marker generic-end-pos) (backward-char)
15526 (when (= generic-beg-pos generic-end-pos)
15527 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15528 (insert ";") (backward-char))
15529 (insert ")")
15530 (vhdl-goto-marker port-end-pos) (backward-char)
15531 (when (= port-beg-pos port-end-pos)
15532 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15533 (insert ";") (backward-char))
15534 (insert ")")
15535 ;; align everything
15536 (when vhdl-auto-align
15537 (vhdl-goto-marker generic-beg-pos)
15538 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15539 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15540 (vhdl-goto-marker signal-beg-pos)
15541 (vhdl-align-region-groups signal-beg-pos signal-pos))
15542 (switch-to-buffer (marker-buffer signal-beg-pos))
15543 (message "Wiring components...done")))))
15544
15545 (defun vhdl-compose-insert-generic (entry)
15546 "Insert ENTRY as generic declaration."
15547 (let (pos)
15548 (indent-to (* 2 vhdl-basic-offset))
15549 (insert (nth 0 entry) " : " (nth 1 entry))
15550 (when (nth 2 entry)
15551 (insert " := " (nth 2 entry)))
15552 (insert ";")
15553 (setq pos (point-marker))
15554 (when (and vhdl-include-port-comments (nth 3 entry))
15555 (vhdl-comment-insert-inline (nth 3 entry) t))
15556 (insert "\n")
15557 pos))
15558
15559 (defun vhdl-compose-insert-port (entry)
15560 "Insert ENTRY as port declaration."
15561 (let (pos)
15562 (indent-to (* 2 vhdl-basic-offset))
15563 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15564 (setq pos (point-marker))
15565 (when (and vhdl-include-port-comments (nth 4 entry))
15566 (vhdl-comment-insert-inline (nth 4 entry) t))
15567 (insert "\n")
15568 pos))
15569
15570 (defun vhdl-compose-insert-signal (entry)
15571 "Insert ENTRY as signal declaration."
15572 (indent-to vhdl-basic-offset)
15573 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15574 (when (and vhdl-include-port-comments (nth 4 entry))
15575 (vhdl-comment-insert-inline (nth 4 entry) t))
15576 (insert "\n"))
15577
15578 (defun vhdl-compose-components-package ()
15579 "Generate a package containing component declarations for all entities in the
15580 current project/directory."
15581 (interactive)
15582 (vhdl-require-hierarchy-info)
15583 (let* ((project (vhdl-project-p))
15584 (pack-name (vhdl-get-components-package-name))
15585 (pack-file-name
15586 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15587 "." (file-name-extension (buffer-file-name))))
15588 (ent-alist (aget vhdl-entity-alist
15589 (or project default-directory) t))
15590 (lazy-lock-minimum-size 0)
15591 clause-pos component-pos)
15592 (message "Generating components package \"%s\"..." pack-name)
15593 ;; open package file
15594 (when (and (file-exists-p pack-file-name)
15595 (not (y-or-n-p (concat "File \"" pack-file-name
15596 "\" exists; overwrite? "))))
15597 (error "ERROR: Generating components package...aborted"))
15598 (find-file pack-file-name)
15599 (erase-buffer)
15600 ;; insert header
15601 (if vhdl-compose-include-header
15602 (progn (vhdl-template-header
15603 (concat "Components package (generated by Emacs VHDL Mode "
15604 vhdl-version ")"))
15605 (goto-char (point-max)))
15606 (vhdl-comment-display-line) (insert "\n\n"))
15607 ;; insert std_logic_1164 package
15608 (vhdl-template-package-std-logic-1164)
15609 (insert "\n") (setq clause-pos (point-marker))
15610 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15611 ;; insert package declaration
15612 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15613 (vhdl-insert-keyword " IS\n\n")
15614 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15615 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15616 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15617 (indent-to vhdl-basic-offset)
15618 (setq component-pos (point-marker))
15619 (insert "\n\n") (vhdl-insert-keyword "END ")
15620 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15621 (insert pack-name ";\n\n")
15622 ;; insert footer
15623 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15624 (vhdl-template-footer)
15625 (vhdl-comment-display-line) (insert "\n"))
15626 ;; insert component declarations
15627 (while ent-alist
15628 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15629 (progn (goto-line (nth 3 (car ent-alist)))
15630 (end-of-line)
15631 (vhdl-port-copy)))
15632 (goto-char component-pos)
15633 (vhdl-port-paste-component t)
15634 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15635 (setq component-pos (point-marker))
15636 (goto-char clause-pos)
15637 (vhdl-port-paste-context-clause pack-name)
15638 (setq clause-pos (point-marker))
15639 (setq ent-alist (cdr ent-alist)))
15640 (goto-char (point-min))
15641 (save-buffer)
15642 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15643 pack-name pack-file-name)))
15644
15645
15646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15647 ;;; Compilation / Makefile generation
15648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15649 ;; (using `compile.el')
15650
15651 (defun vhdl-makefile-name ()
15652 "Return the Makefile name of the current project or the current compiler if
15653 no project is defined."
15654 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15655 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15656 (vhdl-replace-string
15657 (cons "\\(.*\\)\n\\(.*\\)"
15658 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15659 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15660
15661 (defun vhdl-compile-directory ()
15662 "Return the directory where compilation/make should be run."
15663 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15664 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15665 (directory (vhdl-resolve-env-variable
15666 (if project
15667 (vhdl-replace-string
15668 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15669 (nth 6 compiler)))))
15670 (file-name-as-directory
15671 (if (file-name-absolute-p directory)
15672 directory
15673 (expand-file-name directory (vhdl-default-directory))))))
15674
15675 (defun vhdl-uniquify (in-list)
15676 "Remove duplicate elements from IN-LIST."
15677 (let (out-list)
15678 (while in-list
15679 (add-to-list 'out-list (car in-list))
15680 (setq in-list (cdr in-list)))
15681 out-list))
15682
15683 (defun vhdl-set-compiler (name)
15684 "Set current compiler to NAME."
15685 (interactive
15686 (list (let ((completion-ignore-case t))
15687 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15688 (if (assoc name vhdl-compiler-alist)
15689 (progn (setq vhdl-compiler name)
15690 (message "Current compiler: \"%s\"" vhdl-compiler))
15691 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15692
15693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15694 ;; Compilation
15695
15696 (defun vhdl-compile-init ()
15697 "Initialize for compilation."
15698 (when (or (null compilation-error-regexp-alist)
15699 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15700 compilation-error-regexp-alist)))
15701 ;; `compilation-error-regexp-alist'
15702 (let ((commands-alist vhdl-compiler-alist)
15703 regexp-alist sublist)
15704 (while commands-alist
15705 (setq sublist (nth 11 (car commands-alist)))
15706 (unless (or (equal "" (car sublist))
15707 (assoc (car sublist) regexp-alist))
15708 (setq regexp-alist (cons (list (nth 0 sublist)
15709 (if (= 0 (nth 1 sublist))
15710 (if vhdl-xemacs 9 nil)
15711 (nth 1 sublist))
15712 (nth 2 sublist) (nth 3 sublist))
15713 regexp-alist)))
15714 (setq commands-alist (cdr commands-alist)))
15715 (setq compilation-error-regexp-alist
15716 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15717 ;; `compilation-file-regexp-alist'
15718 (let ((commands-alist vhdl-compiler-alist)
15719 regexp-alist sublist)
15720 ;; matches vhdl-mode file name output
15721 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15722 (while commands-alist
15723 (setq sublist (nth 12 (car commands-alist)))
15724 (unless (or (equal "" (car sublist))
15725 (assoc (car sublist) regexp-alist))
15726 (setq regexp-alist (cons sublist regexp-alist)))
15727 (setq commands-alist (cdr commands-alist)))
15728 (setq compilation-file-regexp-alist
15729 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15730
15731 (defvar vhdl-compile-file-name nil
15732 "Name of file to be compiled.")
15733
15734 (defun vhdl-compile-print-file-name ()
15735 "Function called within `compile' to print out file name for compilers that
15736 do not print any file names."
15737 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15738
15739 (defun vhdl-get-compile-options (project compiler file-name
15740 &optional file-options-only)
15741 "Get compiler options. Returning nil means do not compile this file."
15742 (let* ((compiler-options (nth 1 compiler))
15743 (project-entry (aget (nth 4 project) vhdl-compiler))
15744 (project-options (nth 0 project-entry))
15745 (exception-list (and file-name (nth 2 project-entry)))
15746 (work-library (vhdl-work-library))
15747 (case-fold-search nil)
15748 file-options)
15749 (while (and exception-list
15750 (not (string-match (caar exception-list) file-name)))
15751 (setq exception-list (cdr exception-list)))
15752 (if (and exception-list (not (cdar exception-list)))
15753 nil
15754 (if (and file-options-only (not exception-list))
15755 'default
15756 (setq file-options (cdar exception-list))
15757 ;; insert library name in compiler-specific options
15758 (setq compiler-options
15759 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15760 work-library))
15761 ;; insert compiler-specific options in project-specific options
15762 (when project-options
15763 (setq project-options
15764 (vhdl-replace-string
15765 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15766 (concat work-library "\n" compiler-options))))
15767 ;; insert project-specific options in file-specific options
15768 (when file-options
15769 (setq file-options
15770 (vhdl-replace-string
15771 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15772 (concat work-library "\n" compiler-options "\n"
15773 project-options))))
15774 ;; return options
15775 (or file-options project-options compiler-options)))))
15776
15777 (defun vhdl-get-make-options (project compiler)
15778 "Get make options."
15779 (let* ((compiler-options (nth 3 compiler))
15780 (project-entry (aget (nth 4 project) vhdl-compiler))
15781 (project-options (nth 1 project-entry))
15782 (makefile-name (vhdl-makefile-name)))
15783 ;; insert Makefile name in compiler-specific options
15784 (setq compiler-options
15785 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15786 makefile-name))
15787 ;; insert compiler-specific options in project-specific options
15788 (when project-options
15789 (setq project-options
15790 (vhdl-replace-string
15791 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15792 (concat makefile-name "\n" compiler-options))))
15793 ;; return options
15794 (or project-options compiler-options)))
15795
15796 (defun vhdl-compile ()
15797 "Compile current buffer using the VHDL compiler specified in
15798 `vhdl-compiler'."
15799 (interactive)
15800 (vhdl-compile-init)
15801 (let* ((project (aget vhdl-project-alist vhdl-project))
15802 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15803 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15804 (command (nth 0 compiler))
15805 (file-name (buffer-file-name))
15806 (options (vhdl-get-compile-options project compiler file-name))
15807 (default-directory (vhdl-compile-directory))
15808 compilation-process-setup-function)
15809 (unless (file-directory-p default-directory)
15810 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15811 ;; put file name into quotes if it contains spaces
15812 (when (string-match " " file-name)
15813 (setq file-name (concat "\"" file-name "\"")))
15814 ;; print out file name if compiler does not
15815 (setq vhdl-compile-file-name (buffer-file-name))
15816 (when (and (= 0 (nth 1 (nth 10 compiler)))
15817 (= 0 (nth 1 (nth 11 compiler))))
15818 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15819 ;; run compilation
15820 (if options
15821 (when command
15822 (compile (concat command " " options " " file-name)))
15823 (vhdl-warning "Your project settings tell me not to compile this file"))))
15824
15825 (defun vhdl-make (&optional target)
15826 "Call make command for compilation of all updated source files (requires
15827 `Makefile'). Optional argument TARGET allows to compile the design
15828 specified by a target."
15829 (interactive)
15830 (vhdl-compile-init)
15831 (let* ((project (aget vhdl-project-alist vhdl-project))
15832 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15833 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15834 (command (nth 2 compiler))
15835 (options (vhdl-get-make-options project compiler))
15836 (default-directory (vhdl-compile-directory)))
15837 (unless (file-directory-p default-directory)
15838 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15839 ;; run make
15840 (compile (concat (if (equal command "") "make" command)
15841 " " options " " target))))
15842
15843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15844 ;; Makefile generation
15845
15846 (defun vhdl-generate-makefile ()
15847 "Generate `Makefile'."
15848 (interactive)
15849 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15850 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15851 (command (nth 4 compiler)))
15852 ;; generate makefile
15853 (if command
15854 (let ((default-directory (vhdl-compile-directory)))
15855 (compile (vhdl-replace-string
15856 (cons "\\(.*\\) \\(.*\\)" command)
15857 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15858 (vhdl-generate-makefile-1))))
15859
15860 (defun vhdl-get-packages (lib-alist work-library)
15861 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15862 (let (pack-list)
15863 (while lib-alist
15864 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15865 (setq pack-list (cons (cdar lib-alist) pack-list)))
15866 (setq lib-alist (cdr lib-alist)))
15867 pack-list))
15868
15869 (defun vhdl-generate-makefile-1 ()
15870 "Generate Makefile for current project or directory."
15871 ;; scan hierarchy if required
15872 (if (vhdl-project-p)
15873 (unless (or (assoc vhdl-project vhdl-file-alist)
15874 (vhdl-load-cache vhdl-project))
15875 (vhdl-scan-project-contents vhdl-project))
15876 (let ((directory (abbreviate-file-name default-directory)))
15877 (unless (or (assoc directory vhdl-file-alist)
15878 (vhdl-load-cache directory))
15879 (vhdl-scan-directory-contents directory))))
15880 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15881 (project (vhdl-project-p))
15882 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15883 (conf-alist (aget vhdl-config-alist (or project directory) t))
15884 (pack-alist (aget vhdl-package-alist (or project directory) t))
15885 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15886 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15887 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15888 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15889 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15890 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15891 (adjust-case (nth 5 regexp-list))
15892 (work-library (downcase (vhdl-work-library)))
15893 (compile-directory (expand-file-name (vhdl-compile-directory)
15894 default-directory))
15895 (makefile-name (vhdl-makefile-name))
15896 rule-alist arch-alist inst-alist
15897 target-list depend-list unit-list prim-list second-list subcomp-list
15898 lib-alist lib-body-alist pack-list all-pack-list
15899 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15900 conf-key conf-file-name pack-key pack-file-name
15901 ent-entry arch-entry conf-entry pack-entry inst-entry
15902 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15903 tmp-key tmp-list rule)
15904 ;; check prerequisites
15905 (unless (file-exists-p compile-directory)
15906 (make-directory compile-directory t))
15907 (unless regexp-list
15908 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15909 vhdl-compiler))
15910 (message "Generating makefile \"%s\"..." makefile-name)
15911 ;; rules for all entities
15912 (setq tmp-list ent-alist)
15913 (while ent-alist
15914 (setq ent-entry (car ent-alist)
15915 ent-key (nth 0 ent-entry))
15916 (when (nth 2 ent-entry)
15917 (setq ent-file-name (file-relative-name
15918 (nth 2 ent-entry) compile-directory)
15919 arch-alist (nth 4 ent-entry)
15920 lib-alist (nth 5 ent-entry)
15921 rule (aget rule-alist ent-file-name)
15922 target-list (nth 0 rule)
15923 depend-list (nth 1 rule)
15924 second-list nil
15925 subcomp-list nil)
15926 (setq tmp-key (vhdl-replace-string
15927 ent-regexp (funcall adjust-case ent-key)))
15928 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15929 ;; rule target for this entity
15930 (setq target-list (cons ent-key target-list))
15931 ;; rule dependencies for all used packages
15932 (setq pack-list (vhdl-get-packages lib-alist work-library))
15933 (setq depend-list (append depend-list pack-list))
15934 (setq all-pack-list pack-list)
15935 ;; add rule
15936 (aput 'rule-alist ent-file-name (list target-list depend-list))
15937 ;; rules for all corresponding architectures
15938 (while arch-alist
15939 (setq arch-entry (car arch-alist)
15940 arch-key (nth 0 arch-entry)
15941 ent-arch-key (concat ent-key "-" arch-key)
15942 arch-file-name (file-relative-name (nth 2 arch-entry)
15943 compile-directory)
15944 inst-alist (nth 4 arch-entry)
15945 lib-alist (nth 5 arch-entry)
15946 rule (aget rule-alist arch-file-name)
15947 target-list (nth 0 rule)
15948 depend-list (nth 1 rule))
15949 (setq tmp-key (vhdl-replace-string
15950 arch-regexp
15951 (funcall adjust-case (concat arch-key " " ent-key))))
15952 (setq unit-list
15953 (cons (cons ent-arch-key tmp-key) unit-list))
15954 (setq second-list (cons ent-arch-key second-list))
15955 ;; rule target for this architecture
15956 (setq target-list (cons ent-arch-key target-list))
15957 ;; rule dependency for corresponding entity
15958 (setq depend-list (cons ent-key depend-list))
15959 ;; rule dependencies for contained component instantiations
15960 (while inst-alist
15961 (setq inst-entry (car inst-alist))
15962 (when (or (null (nth 8 inst-entry))
15963 (equal (downcase (nth 8 inst-entry)) work-library))
15964 (setq inst-ent-key (or (nth 7 inst-entry)
15965 (nth 5 inst-entry)))
15966 (setq depend-list (cons inst-ent-key depend-list)
15967 subcomp-list (cons inst-ent-key subcomp-list)))
15968 (setq inst-alist (cdr inst-alist)))
15969 ;; rule dependencies for all used packages
15970 (setq pack-list (vhdl-get-packages lib-alist work-library))
15971 (setq depend-list (append depend-list pack-list))
15972 (setq all-pack-list (append all-pack-list pack-list))
15973 ;; add rule
15974 (aput 'rule-alist arch-file-name (list target-list depend-list))
15975 (setq arch-alist (cdr arch-alist)))
15976 (setq prim-list (cons (list ent-key second-list
15977 (append subcomp-list all-pack-list))
15978 prim-list)))
15979 (setq ent-alist (cdr ent-alist)))
15980 (setq ent-alist tmp-list)
15981 ;; rules for all configurations
15982 (setq tmp-list conf-alist)
15983 (while conf-alist
15984 (setq conf-entry (car conf-alist)
15985 conf-key (nth 0 conf-entry)
15986 conf-file-name (file-relative-name
15987 (nth 2 conf-entry) compile-directory)
15988 ent-key (nth 4 conf-entry)
15989 arch-key (nth 5 conf-entry)
15990 inst-alist (nth 6 conf-entry)
15991 lib-alist (nth 7 conf-entry)
15992 rule (aget rule-alist conf-file-name)
15993 target-list (nth 0 rule)
15994 depend-list (nth 1 rule)
15995 subcomp-list (list ent-key))
15996 (setq tmp-key (vhdl-replace-string
15997 conf-regexp (funcall adjust-case conf-key)))
15998 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
15999 ;; rule target for this configuration
16000 (setq target-list (cons conf-key target-list))
16001 ;; rule dependency for corresponding entity and architecture
16002 (setq depend-list
16003 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16004 ;; rule dependencies for used packages
16005 (setq pack-list (vhdl-get-packages lib-alist work-library))
16006 (setq depend-list (append depend-list pack-list))
16007 ;; rule dependencies for contained component configurations
16008 (while inst-alist
16009 (setq inst-entry (car inst-alist))
16010 (setq inst-ent-key (nth 2 inst-entry)
16011 ; comp-arch-key (nth 2 inst-entry))
16012 inst-conf-key (nth 4 inst-entry))
16013 (when (equal (downcase (nth 5 inst-entry)) work-library)
16014 (when inst-ent-key
16015 (setq depend-list (cons inst-ent-key depend-list)
16016 subcomp-list (cons inst-ent-key subcomp-list)))
16017 ; (when comp-arch-key
16018 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16019 ; depend-list)))
16020 (when inst-conf-key
16021 (setq depend-list (cons inst-conf-key depend-list)
16022 subcomp-list (cons inst-conf-key subcomp-list))))
16023 (setq inst-alist (cdr inst-alist)))
16024 ;; add rule
16025 (aput 'rule-alist conf-file-name (list target-list depend-list))
16026 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16027 prim-list))
16028 (setq conf-alist (cdr conf-alist)))
16029 (setq conf-alist tmp-list)
16030 ;; rules for all packages
16031 (setq tmp-list pack-alist)
16032 (while pack-alist
16033 (setq pack-entry (car pack-alist)
16034 pack-key (nth 0 pack-entry)
16035 pack-body-key nil)
16036 (when (nth 2 pack-entry)
16037 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16038 compile-directory)
16039 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16040 rule (aget rule-alist pack-file-name)
16041 target-list (nth 0 rule) depend-list (nth 1 rule))
16042 (setq tmp-key (vhdl-replace-string
16043 pack-regexp (funcall adjust-case pack-key)))
16044 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16045 ;; rule target for this package
16046 (setq target-list (cons pack-key target-list))
16047 ;; rule dependencies for all used packages
16048 (setq pack-list (vhdl-get-packages lib-alist work-library))
16049 (setq depend-list (append depend-list pack-list))
16050 (setq all-pack-list pack-list)
16051 ;; add rule
16052 (aput 'rule-alist pack-file-name (list target-list depend-list))
16053 ;; rules for this package's body
16054 (when (nth 7 pack-entry)
16055 (setq pack-body-key (concat pack-key "-body")
16056 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16057 compile-directory)
16058 rule (aget rule-alist pack-body-file-name)
16059 target-list (nth 0 rule)
16060 depend-list (nth 1 rule))
16061 (setq tmp-key (vhdl-replace-string
16062 pack-body-regexp (funcall adjust-case pack-key)))
16063 (setq unit-list
16064 (cons (cons pack-body-key tmp-key) unit-list))
16065 ;; rule target for this package's body
16066 (setq target-list (cons pack-body-key target-list))
16067 ;; rule dependency for corresponding package declaration
16068 (setq depend-list (cons pack-key depend-list))
16069 ;; rule dependencies for all used packages
16070 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16071 (setq depend-list (append depend-list pack-list))
16072 (setq all-pack-list (append all-pack-list pack-list))
16073 ;; add rule
16074 (aput 'rule-alist pack-body-file-name
16075 (list target-list depend-list)))
16076 (setq prim-list
16077 (cons (list pack-key (when pack-body-key (list pack-body-key))
16078 all-pack-list)
16079 prim-list)))
16080 (setq pack-alist (cdr pack-alist)))
16081 (setq pack-alist tmp-list)
16082 ;; generate Makefile
16083 (let* ((project (aget vhdl-project-alist project))
16084 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16085 (compiler-id (nth 9 compiler))
16086 (library-directory
16087 (vhdl-resolve-env-variable
16088 (vhdl-replace-string
16089 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16090 compiler-id)))
16091 (makefile-path-name (expand-file-name
16092 makefile-name compile-directory))
16093 (orig-buffer (current-buffer))
16094 cell second-list subcomp-list options unit-key unit-name)
16095 ;; sort lists
16096 (setq unit-list (vhdl-sort-alist unit-list))
16097 (setq prim-list (vhdl-sort-alist prim-list))
16098 (setq tmp-list rule-alist)
16099 (while tmp-list ; pre-sort rule targets
16100 (setq cell (cdar tmp-list))
16101 (setcar cell (sort (car cell) 'string<))
16102 (setq tmp-list (cdr tmp-list)))
16103 (setq rule-alist ; sort by first rule target
16104 (sort rule-alist
16105 (function (lambda (a b)
16106 (string< (car (cadr a)) (car (cadr b)))))))
16107 ;; open and clear Makefile
16108 (set-buffer (find-file-noselect makefile-path-name t t))
16109 (erase-buffer)
16110 (insert "# -*- Makefile -*-\n"
16111 "### " (file-name-nondirectory makefile-name)
16112 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16113 "\n")
16114 (if project
16115 (insert "\n# Project : " (nth 0 project))
16116 (insert "\n# Directory : \"" directory "\""))
16117 (insert "\n# Platform : " vhdl-compiler
16118 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16119 (user-login-name) "\n")
16120 ;; insert compile and option variable settings
16121 (insert "\n\n# Define compilation command and options\n"
16122 "\nCOMPILE = " (nth 0 compiler)
16123 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16124 "\n")
16125 ;; insert library paths
16126 (setq library-directory
16127 (directory-file-name
16128 (if (file-name-absolute-p library-directory)
16129 library-directory
16130 (file-relative-name
16131 (expand-file-name library-directory directory)
16132 compile-directory))))
16133 (insert "\n\n# Define library paths\n"
16134 "\nLIBRARY-" work-library " = " library-directory "\n")
16135 ;; insert variable definitions for all library unit files
16136 (insert "\n\n# Define library unit files\n")
16137 (setq tmp-list unit-list)
16138 (while unit-list
16139 (insert "\nUNIT-" work-library "-" (caar unit-list)
16140 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16141 (setq unit-list (cdr unit-list)))
16142 ;; insert variable definition for list of all library unit files
16143 (insert "\n\n\n# Define list of all library unit files\n"
16144 "\nALL_UNITS =")
16145 (setq unit-list tmp-list)
16146 (while unit-list
16147 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16148 (setq unit-list (cdr unit-list)))
16149 (insert "\n")
16150 (setq unit-list tmp-list)
16151 ;; insert `make all' rule
16152 (insert "\n\n\n# Rule for compiling entire design\n"
16153 "\nall :"
16154 " \\\n\t\tlibrary"
16155 " \\\n\t\t$(ALL_UNITS)\n")
16156 ;; insert `make clean' rule
16157 (insert "\n\n# Rule for cleaning entire design\n"
16158 "\nclean : "
16159 "\n\t-rm -f $(ALL_UNITS)\n")
16160 ;; insert `make library' rule
16161 (insert "\n\n# Rule for creating library directory\n"
16162 "\nlibrary :"
16163 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16164 "\n$(LIBRARY-" work-library ") :"
16165 "\n\t"
16166 (vhdl-replace-string
16167 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16168 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16169 "\n")
16170 ;; insert rule for each library unit
16171 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16172 (while prim-list
16173 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16174 (setq subcomp-list
16175 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16176 (setq unit-key (caar prim-list)
16177 unit-name (or (nth 0 (aget ent-alist unit-key t))
16178 (nth 0 (aget conf-alist unit-key t))
16179 (nth 0 (aget pack-alist unit-key t))))
16180 (insert "\n" unit-key)
16181 (unless (equal unit-key unit-name)
16182 (insert " \\\n" unit-name))
16183 (insert " :"
16184 " \\\n\t\tlibrary"
16185 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16186 (while second-list
16187 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16188 (setq second-list (cdr second-list)))
16189 (while subcomp-list
16190 (when (assoc (car subcomp-list) unit-list)
16191 (insert " \\\n\t\t" (car subcomp-list)))
16192 (setq subcomp-list (cdr subcomp-list)))
16193 (insert "\n")
16194 (setq prim-list (cdr prim-list)))
16195 ;; insert rule for each library unit file
16196 (insert "\n\n# Rules for compiling single library unit files\n")
16197 (while rule-alist
16198 (setq rule (car rule-alist))
16199 ;; get compiler options for this file
16200 (setq options
16201 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16202 ;; insert rule if file is supposed to be compiled
16203 (setq target-list (nth 1 rule)
16204 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16205 ;; insert targets
16206 (setq tmp-list target-list)
16207 (while target-list
16208 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16209 (if (cdr target-list) " \\" " :"))
16210 (setq target-list (cdr target-list)))
16211 (setq target-list tmp-list)
16212 ;; insert file name as first dependency
16213 (insert " \\\n\t\t" (nth 0 rule))
16214 ;; insert dependencies (except if also target or unit does not exist)
16215 (while depend-list
16216 (when (and (not (member (car depend-list) target-list))
16217 (assoc (car depend-list) unit-list))
16218 (insert " \\\n\t\t"
16219 "$(UNIT-" work-library "-" (car depend-list) ")"))
16220 (setq depend-list (cdr depend-list)))
16221 ;; insert compile command
16222 (if options
16223 (insert "\n\t$(COMPILE) "
16224 (if (eq options 'default) "$(OPTIONS)" options) " "
16225 (nth 0 rule) "\n")
16226 (setq tmp-list target-list)
16227 (while target-list
16228 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16229 (if (cdr target-list) " \\" "\n"))
16230 (setq target-list (cdr target-list)))
16231 (setq target-list tmp-list))
16232 (setq rule-alist (cdr rule-alist)))
16233 (insert "\n\n### " makefile-name " ends here\n")
16234 ;; run Makefile generation hook
16235 (run-hooks 'vhdl-makefile-generation-hook)
16236 (message "Generating makefile \"%s\"...done" makefile-name)
16237 ;; save and close file
16238 (if (file-writable-p makefile-path-name)
16239 (progn (save-buffer)
16240 (kill-buffer (current-buffer))
16241 (set-buffer orig-buffer)
16242 (setq file-name-history
16243 (cons makefile-path-name file-name-history)))
16244 (vhdl-warning-when-idle
16245 (format "File not writable: \"%s\""
16246 (abbreviate-file-name makefile-path-name)))
16247 (switch-to-buffer (current-buffer))))))
16248
16249
16250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16251 ;;; Bug reports
16252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16253 ;; (using `reporter.el')
16254
16255 (defconst vhdl-mode-help-address
16256 "Reto Zimmermann <reto@gnu.org>"
16257 "Address for VHDL Mode bug reports.")
16258
16259 (defun vhdl-submit-bug-report ()
16260 "Submit via mail a bug report on VHDL Mode."
16261 (interactive)
16262 ;; load in reporter
16263 (and
16264 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16265 (let ((reporter-prompt-for-summary-p t))
16266 (reporter-submit-bug-report
16267 vhdl-mode-help-address
16268 (concat "VHDL Mode " vhdl-version)
16269 (list
16270 ;; report all important user options
16271 'vhdl-offsets-alist
16272 'vhdl-comment-only-line-offset
16273 'tab-width
16274 'vhdl-electric-mode
16275 'vhdl-stutter-mode
16276 'vhdl-indent-tabs-mode
16277 'vhdl-project-alist
16278 'vhdl-project
16279 'vhdl-project-file-name
16280 'vhdl-project-auto-load
16281 'vhdl-project-sort
16282 'vhdl-compiler-alist
16283 'vhdl-compiler
16284 'vhdl-compile-use-local-error-regexp
16285 'vhdl-makefile-generation-hook
16286 'vhdl-default-library
16287 'vhdl-standard
16288 'vhdl-basic-offset
16289 'vhdl-upper-case-keywords
16290 'vhdl-upper-case-types
16291 'vhdl-upper-case-attributes
16292 'vhdl-upper-case-enum-values
16293 'vhdl-upper-case-constants
16294 'vhdl-use-direct-instantiation
16295 'vhdl-entity-file-name
16296 'vhdl-architecture-file-name
16297 'vhdl-package-file-name
16298 'vhdl-file-name-case
16299 'vhdl-electric-keywords
16300 'vhdl-optional-labels
16301 'vhdl-insert-empty-lines
16302 'vhdl-argument-list-indent
16303 'vhdl-association-list-with-formals
16304 'vhdl-conditions-in-parenthesis
16305 'vhdl-zero-string
16306 'vhdl-one-string
16307 'vhdl-file-header
16308 'vhdl-file-footer
16309 'vhdl-company-name
16310 'vhdl-copyright-string
16311 'vhdl-platform-spec
16312 'vhdl-date-format
16313 'vhdl-modify-date-prefix-string
16314 'vhdl-modify-date-on-saving
16315 'vhdl-reset-kind
16316 'vhdl-reset-active-high
16317 'vhdl-clock-rising-edge
16318 'vhdl-clock-edge-condition
16319 'vhdl-clock-name
16320 'vhdl-reset-name
16321 'vhdl-model-alist
16322 'vhdl-include-port-comments
16323 'vhdl-include-direction-comments
16324 'vhdl-include-type-comments
16325 'vhdl-include-group-comments
16326 'vhdl-actual-port-name
16327 'vhdl-instance-name
16328 'vhdl-testbench-entity-name
16329 'vhdl-testbench-architecture-name
16330 'vhdl-testbench-configuration-name
16331 'vhdl-testbench-dut-name
16332 'vhdl-testbench-include-header
16333 'vhdl-testbench-declarations
16334 'vhdl-testbench-statements
16335 'vhdl-testbench-initialize-signals
16336 'vhdl-testbench-include-library
16337 'vhdl-testbench-include-configuration
16338 'vhdl-testbench-create-files
16339 'vhdl-compose-create-files
16340 'vhdl-compose-include-header
16341 'vhdl-compose-architecture-name
16342 'vhdl-components-package-name
16343 'vhdl-use-components-package
16344 'vhdl-self-insert-comments
16345 'vhdl-prompt-for-comments
16346 'vhdl-inline-comment-column
16347 'vhdl-end-comment-column
16348 'vhdl-auto-align
16349 'vhdl-align-groups
16350 'vhdl-align-group-separate
16351 'vhdl-align-same-indent
16352 'vhdl-highlight-keywords
16353 'vhdl-highlight-names
16354 'vhdl-highlight-special-words
16355 'vhdl-highlight-forbidden-words
16356 'vhdl-highlight-verilog-keywords
16357 'vhdl-highlight-translate-off
16358 'vhdl-highlight-case-sensitive
16359 'vhdl-special-syntax-alist
16360 'vhdl-forbidden-words
16361 'vhdl-forbidden-syntax
16362 'vhdl-directive-keywords
16363 'vhdl-speedbar-auto-open
16364 'vhdl-speedbar-display-mode
16365 'vhdl-speedbar-scan-limit
16366 'vhdl-speedbar-jump-to-unit
16367 'vhdl-speedbar-update-on-saving
16368 'vhdl-speedbar-save-cache
16369 'vhdl-speedbar-cache-file-name
16370 'vhdl-index-menu
16371 'vhdl-source-file-menu
16372 'vhdl-hideshow-menu
16373 'vhdl-hide-all-init
16374 'vhdl-print-two-column
16375 'vhdl-print-customize-faces
16376 'vhdl-intelligent-tab
16377 'vhdl-indent-syntax-based
16378 'vhdl-word-completion-case-sensitive
16379 'vhdl-word-completion-in-minibuffer
16380 'vhdl-underscore-is-part-of-word
16381 'vhdl-mode-hook)
16382 (function
16383 (lambda ()
16384 (insert
16385 (if vhdl-special-indent-hook
16386 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16387 "vhdl-special-indent-hook is set to '"
16388 (format "%s" vhdl-special-indent-hook)
16389 ".\nPerhaps this is your problem?\n"
16390 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16391 "\n"))))
16392 nil
16393 "Hi Reto,"))))
16394
16395
16396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16397 ;;; Documentation
16398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16399
16400 (defconst vhdl-doc-release-notes nil
16401 "\
16402 Release Notes for VHDL Mode 3.32
16403 ================================
16404
16405 - New Features
16406 - Enhanced Features
16407 - User Options
16408 - Remarks
16409
16410
16411 New Features
16412 ------------
16413
16414 STRUCTURAL COMPOSITION:
16415 - Enables simple structural composition similar to graphical editors.
16416 Simplifies the creation of higher design levels where subcomponents
16417 are simply sticked together:
16418 1. Create a skeleton for a new component
16419 2. Place subcomponents in it directly from the hierarchy browser
16420 3. Automatically connect all subcomponents and create the ports
16421 for the new component (based on names of actual ports)
16422 - Automatic generation of a components package (package containing
16423 component declarations for all entities).
16424 - Find more information in the online documentation (`C-c C-h').
16425
16426 PORT TRANSLATION:
16427 - Reverse direction of ports (useful for testbenches).
16428
16429 SUBPROGRAM TRANSLATION:
16430 - Copy/paste of subprogram interfaces (similar to port translation).
16431
16432 CODE FILLING:
16433 - Condense code using code-sensitive block filling.
16434
16435 CODE STATISTICS:
16436 - Calculate number of code lines and statements in a buffer.
16437
16438
16439 Enhanced Features
16440 -----------------
16441
16442 TESTBENCH GENERATION:
16443 - Enhanced templates and user option default values.
16444
16445 Emacs 21 compatibility/enhancements:
16446 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16447
16448 And many other minor fixes and enhancements.
16449
16450
16451 User Options
16452 ------------
16453
16454 `vhdl-project-file-name': (enhanced)
16455 Include user name in project setup file name.
16456 `vhdl-speedbar-cache-file-name': (enhanced, changed default)
16457 Include user name in cache file name.
16458 `vhdl-default-library': (new)
16459 Default working library if no project is active.
16460 `vhdl-architecture-file-name': (new)
16461 Specify how the architecture file name is obtained.
16462 `vhdl-package-file-name': (new)
16463 Specify how the package file name is obtained.
16464 `vhdl-file-name-case': (new)
16465 Allows to change case when deriving file names.
16466 `vhdl-compose-create-files': (new)
16467 Specify whether new files should be created for a new component.
16468 `vhdl-compose-include-header': (new)
16469 Specify whether a header is included in a new component's file.
16470 `vhdl-compose-architecture-name': (new)
16471 Specify how a new component's architecture name is obtained.
16472 `vhdl-components-package-name': (new)
16473 Specify how the name for the components package is obtained.
16474 `vhdl-use-components-package': (new)
16475 Specify whether component declarations go in a components package.
16476 `vhdl-use-direct-instantiation': (new)
16477 Specify whether to use VHDL'93 direct component instantiation.
16478 `vhdl-instance-name': (changed default)
16479 Allows insertion of a running number to generate unique instance names.
16480 `vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16481 Headers are now automatically derived from the standard header.
16482 `vhdl-testbench-include-header': (new)
16483 Specify whether a header is included in testbench files.
16484 `vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16485 Non-empty default values for more complete testbench templates.
16486
16487
16488 Remarks
16489 -------
16490
16491 - Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16492 (`C-c C-c ...' is now used for structural composition).
16493
16494 - Automatic buffer highlighting (font-lock) is now controlled by option
16495 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16496 \(Important: You MUST customize this option in order to turn automatic
16497 buffer highlighting on.)
16498 ")
16499
16500
16501 (defconst vhdl-doc-keywords nil
16502 "\
16503 Reserved words in VHDL
16504 ----------------------
16505
16506 VHDL'93 (IEEE Std 1076-1993):
16507 `vhdl-93-keywords' : keywords
16508 `vhdl-93-types' : standardized types
16509 `vhdl-93-attributes' : standardized attributes
16510 `vhdl-93-enum-values' : standardized enumeration values
16511 `vhdl-93-functions' : standardized functions
16512 `vhdl-93-packages' : standardized packages and libraries
16513
16514 VHDL-AMS (IEEE Std 1076.1):
16515 `vhdl-ams-keywords' : keywords
16516 `vhdl-ams-types' : standardized types
16517 `vhdl-ams-attributes' : standardized attributes
16518 `vhdl-ams-enum-values' : standardized enumeration values
16519 `vhdl-ams-functions' : standardized functions
16520
16521 Math Packages (IEEE Std 1076.2):
16522 `vhdl-math-types' : standardized types
16523 `vhdl-math-constants' : standardized constants
16524 `vhdl-math-functions' : standardized functions
16525 `vhdl-math-packages' : standardized packages
16526
16527 Forbidden words:
16528 `vhdl-verilog-keywords' : Verilog reserved words
16529
16530 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16531
16532
16533 (defconst vhdl-doc-coding-style nil
16534 "\
16535 For VHDL coding style and naming convention guidelines, see the following
16536 references:
16537
16538 \[1] Ben Cohen.
16539 \"VHDL Coding Styles and Methodologies\".
16540 Kluwer Academic Publishers, 1999.
16541 http://members.aol.com/vhdlcohen/vhdl/
16542
16543 \[2] Michael Keating and Pierre Bricaud.
16544 \"Reuse Methodology Manual, Second Edition\".
16545 Kluwer Academic Publishers, 1999.
16546 http://www.openmore.com/openmore/rmm2.html
16547
16548 \[3] European Space Agency.
16549 \"VHDL Modelling Guidelines\".
16550 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16551
16552 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16553 to visually support naming conventions.")
16554
16555
16556 (defun vhdl-version ()
16557 "Echo the current version of VHDL Mode in the minibuffer."
16558 (interactive)
16559 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16560 (vhdl-keep-region-active))
16561
16562 (defun vhdl-doc-variable (variable)
16563 "Display VARIABLE's documentation in *Help* buffer."
16564 (interactive)
16565 (unless vhdl-xemacs
16566 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16567 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16568 (princ (documentation-property variable 'variable-documentation))
16569 (with-current-buffer standard-output
16570 (help-mode))
16571 (print-help-return-message)))
16572
16573 (defun vhdl-doc-mode ()
16574 "Display VHDL Mode documentation in *Help* buffer."
16575 (interactive)
16576 (unless vhdl-xemacs
16577 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16578 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16579 (princ mode-name)
16580 (princ " mode:\n")
16581 (princ (documentation 'vhdl-mode))
16582 (with-current-buffer standard-output
16583 (help-mode))
16584 (print-help-return-message)))
16585
16586
16587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16588
16589 (provide 'vhdl-mode)
16590
16591 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
16592 ;;; vhdl-mode.el ends here